plugins/PunBB.php
changeset 6 5e1f1e916419
parent 5 e3d7322305bf
child 8 8baccbad4a55
equal deleted inserted replaced
5:e3d7322305bf 6:5e1f1e916419
     2 /*
     2 /*
     3 Plugin Name: PunBB forum integration
     3 Plugin Name: PunBB forum integration
     4 Plugin URI: http://enanocms.org/PunBB_plugin
     4 Plugin URI: http://enanocms.org/PunBB_plugin
     5 Description: Provides a complete forum solution in PunBB, a separately maintained and very lightweight GPL forum.
     5 Description: Provides a complete forum solution in PunBB, a separately maintained and very lightweight GPL forum.
     6 Author: Dan Fuhry
     6 Author: Dan Fuhry
     7 Version: 0.1.12.15
     7 Version: 1.3-beta
     8 Author URI: http://enanocms.org/
     8 Author URI: http://enanocms.org/
     9 */
     9 */
    10 
    10 
    11 /*
    11 /*
    12  * PunBB Plugin for Enano CMS
    12  * PunBB Plugin for Enano CMS
    13  * Version 0.1.12.15
    13  * Version 1.3-beta
    14  * Copyright (C) 2006-2007 Dan Fuhry
    14  * Copyright (C) 2006-2008 Dan Fuhry
    15  * Copyright (C) 2002-2007 Rickard Andersson
    15  * Copyright (C) 2002-2008 Rickard Andersson
    16  *
    16  *
    17  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
    17  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
    18  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    18  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    19  *
    19  *
    20  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
    20  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
    34   ');
    34   ');
    35 
    35 
    36 $plugins->attachHook('session_started', '
    36 $plugins->attachHook('session_started', '
    37     $pid = RenderMan::strToPageId($paths->get_pageid_from_url());
    37     $pid = RenderMan::strToPageId($paths->get_pageid_from_url());
    38 
    38 
    39     if ( getConfig("punbb_installed") == "yes" && getConfig("punbb_version") == PUNANO_VERSION && $pid[0] == "Forum" && $pid[1] == "Special" )
    39     $is_style_or_script = ( strpos($_SERVER["REQUEST_URI"], "/style/") || strpos($_SERVER["REQUEST_URI"], "/include/js/") );
       
    40     if ( getConfig("punbb_installed") == "yes" && getConfig("punbb_version") == PUNANO_VERSION && $pid[0] == "Forum" && $pid[1] == "Special" && !$is_style_or_script )
    40     {
    41     {
    41       require( "punbb/include/common.php" );
    42       require( "punbb/include/common.php" );
    42     }
    43     }
    43     ');
    44     ');
    44 
    45 
    45 define('PUNANO_VERSION', '0.1.12.15');
    46 define('PUNANO_VERSION', '0.1.3-beta');
    46 define('PUNBB_VERSION',  '1.2.15');
    47 define('PUNBB_VERSION',  '1.3-beta');
    47 define('PUN_ROOT', ENANO_ROOT . '/punbb/');
    48 define('PUN_ROOT', ENANO_ROOT . '/punbb/');
    48 define('PUN', '');
    49 define('PUN', '');
    49 define('PUN_DISABLE_BUFFERING', '');
    50 define('PUN_DISABLE_BUFFERING', '');
       
    51 // define('PUN_SHOW_QUERIES', '');
    50 
    52 
    51 function page_Special_Forum()
    53 function page_Special_Forum()
    52 {
    54 {
    53   global $db, $session, $paths, $template, $plugins; // Common objects
    55   global $db, $session, $paths, $template, $plugins; // Common objects
    54   if ( getConfig('punbb_installed') != 'yes' )
    56   if ( getConfig('punbb_installed') != 'yes' )
    57   }
    59   }
    58   else if ( getConfig('punbb_version') != PUNANO_VERSION )
    60   else if ( getConfig('punbb_version') != PUNANO_VERSION )
    59   {
    61   {
    60     punano_upgrade();
    62     punano_upgrade();
    61   }
    63   }
    62   else if ( preg_match('/^admin_/i', $paths->getParam(0)) )
    64   else if ( $paths->getParam(0) == 'admin' )
    63   {
    65   {
    64     punano_admin_console();
    66     punano_admin_console();
       
    67   }
       
    68   else if ( $paths->getParam(0) == 'style' )
       
    69   {
       
    70     $path = $paths->getAllParams();
       
    71     header('Location: ' . scriptPath . '/punbb/' . $path);
       
    72     exit();
       
    73   }
       
    74   else if ( $paths->getParam(0) == 'include' && $paths->getParam(1) == 'js' )
       
    75   {
       
    76     $path = $paths->getAllParams();
       
    77     header('Location: ' . scriptPath . '/punbb/' . $path);
       
    78     exit();
    65   }
    79   }
    66   else
    80   else
    67   {
    81   {
    68     punano_main();
    82     punano_main();
    69   }
    83   }
    78     die_friendly('Punano initialization error', '<p>The Punano plugin doesn\'t have its database schema installed yet, and your user account doesn\'t have permission to install it. Please ask the administrator of this site to set up Punano.</p>');
    92     die_friendly('Punano initialization error', '<p>The Punano plugin doesn\'t have its database schema installed yet, and your user account doesn\'t have permission to install it. Please ask the administrator of this site to set up Punano.</p>');
    79   }
    93   }
    80   else if ( $session->auth_level < USER_LEVEL_ADMIN )
    94   else if ( $session->auth_level < USER_LEVEL_ADMIN )
    81   {
    95   {
    82     $url = makeUrlNS('Special', 'Login/' . $paths->page, 'level=' . USER_LEVEL_ADMIN, true);
    96     $url = makeUrlNS('Special', 'Login/' . $paths->page, 'level=' . USER_LEVEL_ADMIN, true);
    83     redirect($url, 'Permission denied', 'You need to have an active high-privilege session to set up Punano.', 4);
    97     pun_redirect($url, 'Permission denied', 'You need to have an active high-privilege session to set up Punano.', 4);
    84   }
    98   }
    85   
    99   
    86   $template->header();
   100   $template->header();
    87   
   101   
    88   // Permissions are good
   102   // Permissions are good
   113 }
   127 }
   114 
   128 
   115 function _punano_perform_install()
   129 function _punano_perform_install()
   116 {
   130 {
   117   global $db, $session, $paths, $template, $plugins; // Common objects
   131   global $db, $session, $paths, $template, $plugins; // Common objects
       
   132   global $dbdriver;
       
   133   
   118   $db_prefix = table_prefix . 'pun_';
   134   $db_prefix = table_prefix . 'pun_';
   119   $admin_email = getConfig('contact_email');
   135   $admin_email = getConfig('contact_email');
   120   $pun_version = PUNBB_VERSION;
   136   $pun_version = PUNBB_VERSION;
   121   
   137   
   122   $schema = file_get_contents( ENANO_ROOT . '/punbb/schema.sql' );
   138   $schema = file_get_contents( ENANO_ROOT . "/punbb/install-$dbdriver.sql" );
   123   if ( empty($schema) )
   139   if ( empty($schema) )
   124   {
   140   {
   125     echo 'ERROR: cannot load schema file!';
   141     echo 'ERROR: cannot load schema file!';
   126     return false;
   142     return false;
   127   }
   143   }
   128   
   144   
   129   $replace = array(
   145   $replace = array(
   130       '{{TABLE_PREFIX}}' => $db_prefix,
   146       '{{TABLE_PREFIX}}' => $db_prefix,
   131       '{{ENANO_ADMIN_EMAIL}}' => $admin_email,
   147       '{{ENANO_ADMIN_EMAIL}}' => $admin_email,
   132       '{{PUN_VERSION}}' => $pun_version
   148       '{{PUN_VERSION}}' => $pun_version,
       
   149       '{{NOW}}' => strval(time())
   133     );
   150     );
   134   
   151   
   135   $schema = strtr($schema, $replace);
   152   $schema = strtr($schema, $replace);
   136   
   153   
   137   // Build an array of queries (from Enano's install.php)
   154   // Build an array of queries (from Enano's install.php)
   212   global $db, $session, $paths, $template, $plugins; // Common objects
   229   global $db, $session, $paths, $template, $plugins; // Common objects
   213   
   230   
   214   // At this point, the PunBB API is already loaded
   231   // At this point, the PunBB API is already loaded
   215   // So we'll include one of the Pun frontend files
   232   // So we'll include one of the Pun frontend files
   216   
   233   
       
   234   /*
   217   $valid = array('delete', 'edit', 'extern', 'help', 'index', 'misc', 'moderate', 'post', 'profile', 'search', 'userlist', 'viewforum', 'viewtopic');
   235   $valid = array('delete', 'edit', 'extern', 'help', 'index', 'misc', 'moderate', 'post', 'profile', 'search', 'userlist', 'viewforum', 'viewtopic');
   218   
   236   
   219   $file = 'index';
   237   $file = 'index';
   220   if ( $x = $paths->getParam(0) )
   238   if ( $x = $paths->getParam(0) )
   221   {
   239   {
   223     if ( in_array(strtolower($x), $valid) )
   241     if ( in_array(strtolower($x), $valid) )
   224     {
   242     {
   225       $file = strtolower($x);
   243       $file = strtolower($x);
   226     }
   244     }
   227   }
   245   }
       
   246   */
       
   247   $file = 'rewrite';
   228   
   248   
   229   // Don't worry. This is sanitized.
   249   // Don't worry. This is sanitized.
   230   require PUN_ROOT . $file . '.php';
   250   $file = PUN_ROOT . $file . '.php';
   231   
   251   require $file;
   232 }
   252 }
   233 
   253 
   234 function punano_admin_console()
   254 function punano_admin_console()
   235 {
   255 {
   236   global $db, $session, $paths, $template, $plugins; // Common objects
   256   global $db, $session, $paths, $template, $plugins; // Common objects
   237   
   257   
   238   $valid = array('categories', 'censoring', 'forums', 'groups', 'index', 'loader', 'maintenance', 'options', 'permissions', 'prune', 'ranks', 'reports', 'users');
   258   $valid = array('bans', 'categories', 'censoring', 'extensions', 'forums', 'groups', 'index', 'options', 'prune', 'ranks', 'reindex', 'reports', 'users');
   239   $mod = array('bans', 'censoring', 'index', 'loader', 'reports', 'users');
   259   $mod   = array();
   240 
   260 
   241   $file = 'index';
   261   $file = 'index';
   242   
   262   
   243   if ( $x = $paths->getParam(0) )
   263   if ( $x = $paths->getParam(1) )
   244   {
   264   {
   245     $x = preg_replace('/\.php$/', '', $x);
   265     $x = preg_replace('/\.php$/', '', $x);
   246     $x = preg_replace('/^admin_/i', '', $x);
   266     $x = preg_replace('/^admin_/i', '', $x);
   247     if ( in_array(strtolower($x), $valid) )
   267     if ( in_array(strtolower($x), $valid) || in_array(strtolower($x), $mod) )
   248     {
   268     {
   249       $file = strtolower($x);
   269       $file = strtolower($x);
   250     }
   270     }
   251   }
   271   }
   252   
   272   
   263   {
   283   {
   264     redirect( makeUrlNS('Special', 'Login/' . $paths->fullpage, 'level=' . $session->user_level, false), 'Permission denied', 'You need to have permission level ' . $session->userlevel_to_string($need_level) . ' to use the PunBB administration console.', 2);
   284     redirect( makeUrlNS('Special', 'Login/' . $paths->fullpage, 'level=' . $session->user_level, false), 'Permission denied', 'You need to have permission level ' . $session->userlevel_to_string($need_level) . ' to use the PunBB administration console.', 2);
   265   }
   285   }
   266   
   286   
   267   // Don't worry. This is sanitized.
   287   // Don't worry. This is sanitized.
   268   require PUN_ROOT . 'admin_' . $file . '.php';
   288   require PUN_ROOT . 'admin/' . $file . '.php';
   269   
   289   
   270 }
   290 }
   271 
   291 
   272 ?>
   292 ?>