| 1 | 2 | Manuela | <?php
 | 
      
        | 2 |  |  | /**
 | 
      
        | 3 |  |  |  *
 | 
      
        | 4 |  |  |  * @category        admin
 | 
      
        | 5 |  |  |  * @package         addons
 | 
      
        | 6 |  |  |  * @author          WebsiteBaker Project
 | 
      
        | 7 |  |  |  * @copyright       Ryan Djurovich
 | 
      
        | 8 |  |  |  * @copyright       WebsiteBaker Org. e.V.
 | 
      
        | 9 |  |  |  * @link            http://websitebaker.org/
 | 
      
        | 10 |  |  |  * @license         http://www.gnu.org/licenses/gpl.html
 | 
      
        | 11 |  |  |  * @platform        WebsiteBaker 2.8.3
 | 
      
        | 12 |  |  |  * @requirements    PHP 5.3.6 and higher
 | 
      
        | 13 |  |  |  * @version         $Id$
 | 
      
        | 14 |  |  |  * @filesource        $HeadURL$
 | 
      
        | 15 |  |  |  * @lastmodified    $Date$
 | 
      
        | 16 |  |  |  *
 | 
      
        | 17 |  |  |  */
 | 
      
        | 18 |  |  | 
 | 
      
        | 19 |  |  | /**
 | 
      
        | 20 |  |  |  * check if there is anything to do
 | 
      
        | 21 |  |  |  */
 | 
      
        | 22 |  |  | $post_check = array('reload_modules', 'reload_templates', 'reload_languages');
 | 
      
        | 23 |  |  | foreach ($post_check as $index => $key) {
 | 
      
        | 24 |  |  |     if (!isset($_POST[$key])) unset($post_check[$index]);
 | 
      
        | 25 |  |  | }
 | 
      
        | 26 |  |  | if (count($post_check) == 0) die(header('Location: index.php?advanced'));
 | 
      
        | 27 |  |  | 
 | 
      
        | 28 |  |  | /**
 | 
      
        | 29 |  |  |  * check if user has permissions to access this file
 | 
      
        | 30 |  |  |  */
 | 
      
        | 31 |  |  | // include WB configuration file and WB admin class
 | 
      
        | 32 |  |  | if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname((__DIR__))).'/config.php' ); }
 | 
      
        | 33 |  |  | if ( !class_exists('admin', false) ) { require(WB_PATH.'/framework/class.admin.php'); }
 | 
      
        | 34 |  |  | // check user permissions for admintools (redirect users with wrong permissions)
 | 
      
        | 35 |  |  | $admin = new admin('Admintools', 'admintools', false, false);
 | 
      
        | 36 |  |  | 
 | 
      
        | 37 |  |  | if ($admin->get_permission('admintools') == false) die(header('Location: ../../index.php'));
 | 
      
        | 38 |  |  | 
 | 
      
        | 39 |  |  | // check if the referer URL if available
 | 
      
        | 40 |  |  | $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] :
 | 
      
        | 41 |  |  |     (isset($HTTP_SERVER_VARS['HTTP_REFERER']) ? $HTTP_SERVER_VARS['HTTP_REFERER'] : '');
 | 
      
        | 42 |  |  | $referer = '';
 | 
      
        | 43 |  |  | // if referer is set, check if script was invoked from "admin/modules/index.php"
 | 
      
        | 44 |  |  | $required_url = ADMIN_URL . '/addons/index.php';
 | 
      
        | 45 |  |  | if ($referer != '' && (!(strpos($referer, $required_url) !== false || strpos($referer, $required_url) !== false)))
 | 
      
        | 46 |  |  |     die(header('Location: ../../index.php'));
 | 
      
        | 47 |  |  | 
 | 
      
        | 48 |  |  | // include WB functions file
 | 
      
        | 49 |  |  | require_once(WB_PATH . '/framework/functions.php');
 | 
      
        | 50 |  |  | 
 | 
      
        | 51 |  |  | // load WB language file
 | 
      
        | 52 |  |  | require_once(WB_PATH . '/languages/' . LANGUAGE .'.php');
 | 
      
        | 53 |  |  | 
 | 
      
        | 54 |  |  | // create Admin object with admin header
 | 
      
        | 55 |  |  | $admin = new admin('Addons', '', false, false);
 | 
      
        | 56 |  |  | $js_back = ADMIN_URL . '/addons/index.php?advanced';
 | 
      
        | 57 |  |  | 
 | 
      
        | 58 |  |  | if (!$admin->checkFTAN())
 | 
      
        | 59 |  |  | {
 | 
      
        | 60 |  |  |     $admin->print_header();
 | 
      
        | 61 |  |  |     $admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL);
 | 
      
        | 62 |  |  | }
 | 
      
        | 63 |  |  | 
 | 
      
        | 64 |  |  | /**
 | 
      
        | 65 |  |  |  * delete no existing addons in table
 | 
      
        | 66 |  |  |  */
 | 
      
        | 67 |  |  | $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'addons` '
 | 
      
        | 68 |  |  |       . 'ORDER BY `type`, `directory` ';
 | 
      
        | 69 |  |  | if ( $oAddons = $database->query( $sql ) ) {
 | 
      
        | 70 |  |  |     while ( $aAddon = $oAddons->fetchRow( MYSQLI_ASSOC ) ) {
 | 
      
        | 71 |  |  |         $delAddon = 'DELETE  FROM `'.TABLE_PREFIX.'addons` WHERE `addon_id`='.(int)$aAddon['addon_id'];
 | 
      
        | 72 |  |  |         $sAddonFile = WB_PATH.'/'.$aAddon['type'].'s/'.$aAddon['directory'];
 | 
      
        | 73 |  |  |         switch ($aAddon['type']):
 | 
      
        | 74 |  |  |             case 'language':
 | 
      
        | 75 |  |  |                 if ( !file_exists( $sAddonFile.'.php' ) )
 | 
      
        | 76 |  |  |                 {
 | 
      
        | 77 |  |  |                     $oDelResult = $database->query( $delAddon );
 | 
      
        | 78 |  |  |                 }
 | 
      
        | 79 |  |  |                 break;
 | 
      
        | 80 |  |  |             default:
 | 
      
        | 81 |  |  |                 if ( !file_exists( $sAddonFile ) )
 | 
      
        | 82 |  |  |                 {
 | 
      
        | 83 |  |  |                     $oDelResult = $database->query( $delAddon );
 | 
      
        | 84 |  |  | //                    echo $sAddonFile.'<br />';
 | 
      
        | 85 |  |  |                 }
 | 
      
        | 86 |  |  |             break;
 | 
      
        | 87 |  |  |         endswitch;
 | 
      
        | 88 |  |  |     }
 | 
      
        | 89 |  |  | }
 | 
      
        | 90 |  |  | /**
 | 
      
        | 91 |  |  |  *
 | 
      
        | 92 |  |  |  * Reload all specified Addons
 | 
      
        | 93 |  |  |  */
 | 
      
        | 94 |  |  | $msg = array();
 | 
      
        | 95 |  |  | $table = TABLE_PREFIX . 'addons';
 | 
      
        | 96 |  |  | 
 | 
      
        | 97 |  |  | foreach ($post_check as $key) {
 | 
      
        | 98 |  |  |     switch ($key) {
 | 
      
        | 99 |  |  |         case 'reload_modules':
 | 
      
        | 100 |  |  |             $aAddonList = glob(WB_PATH.'/modules/*', GLOB_ONLYDIR );
 | 
      
        | 101 |  |  |             foreach( $aAddonList as $sAddonFile ) {
 | 
      
        | 102 |  |  |                 if (is_readable( $sAddonFile )) {
 | 
      
        | 103 |  |  |                     load_module( $sAddonFile );
 | 
      
        | 104 |  |  |                 }
 | 
      
        | 105 |  |  |             }
 | 
      
        | 106 |  |  |             // add success message
 | 
      
        | 107 |  |  |             $msg[] = $MESSAGE['ADDON_MODULES_RELOADED'];
 | 
      
        | 108 |  |  |             unset($aAddonList);
 | 
      
        | 109 |  |  |             break;
 | 
      
        | 110 |  |  | 
 | 
      
        | 111 |  |  |         case 'reload_templates':
 | 
      
        | 112 |  |  |             $aAddonList = glob(WB_PATH.'/templates/*', GLOB_ONLYDIR );
 | 
      
        | 113 |  |  |             foreach( $aAddonList as $sAddonFile ) {
 | 
      
        | 114 |  |  |                 if (is_readable( $sAddonFile )) {
 | 
      
        | 115 |  |  |                     load_template( $sAddonFile );
 | 
      
        | 116 |  |  |                 }
 | 
      
        | 117 |  |  |             }
 | 
      
        | 118 |  |  |             // add success message
 | 
      
        | 119 |  |  |             $msg[] = $MESSAGE['ADDON_TEMPLATES_RELOADED'];
 | 
      
        | 120 |  |  |             unset($aAddonList);
 | 
      
        | 121 |  |  |             break;
 | 
      
        | 122 |  |  | 
 | 
      
        | 123 |  |  |         case 'reload_languages':
 | 
      
        | 124 |  |  |             $aAddonList = glob(WB_PATH.'/languages/*.php' );
 | 
      
        | 125 |  |  |             foreach( $aAddonList as $sAddonFile ) {
 | 
      
        | 126 |  |  |                 if (is_readable( $sAddonFile )) {
 | 
      
        | 127 |  |  |                     load_language( $sAddonFile );
 | 
      
        | 128 |  |  |                 }
 | 
      
        | 129 |  |  |             }
 | 
      
        | 130 |  |  |             // add success message
 | 
      
        | 131 |  |  |             $msg[] = $MESSAGE['ADDON_LANGUAGES_RELOADED'];
 | 
      
        | 132 |  |  |             unset($aAddonList);
 | 
      
        | 133 |  |  |             break;
 | 
      
        | 134 |  |  | 
 | 
      
        | 135 |  |  |     }
 | 
      
        | 136 |  |  | }
 | 
      
        | 137 |  |  | 
 | 
      
        | 138 |  |  | // output success message
 | 
      
        | 139 |  |  | $admin->print_header();
 | 
      
        | 140 |  |  | $admin->print_success(implode($msg, '<br />'), $js_back);
 | 
      
        | 141 |  |  | $admin->print_footer();
 |