Example #1
0
 function main()
 {
     // Start the page
     global $config, $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx, $phpbb_log, $cache;
     $this->db = $db;
     $this->config = $config;
     $this->template = $template;
     $this->user = $user;
     $this->cache = $cache;
     $this->request = $request;
     $this->log = $phpbb_log;
     $user->add_lang(array('install', 'acp/extensions', 'migrator'));
     $this->page_title = 'ACP_EXTENSIONS';
     $action = $request->variable('action', 'list');
     $ext_name = $request->variable('ext_name', '');
     // What is a safe limit of execution time? Half the max execution time should be safe.
     $safe_time_limit = ini_get('max_execution_time') / 2;
     $start_time = time();
     // Cancel action
     if ($request->is_set_post('cancel')) {
         $action = 'list';
         $ext_name = '';
     }
     if (in_array($action, array('enable', 'disable', 'delete_data')) && !check_link_hash($request->variable('hash', ''), $action . '.' . $ext_name)) {
         trigger_error('FORM_INVALID', E_USER_WARNING);
     }
     // If they've specified an extension, let's load the metadata manager and validate it.
     if ($ext_name) {
         $md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $user, $phpbb_root_path);
         try {
             $md_manager->get_metadata('all');
         } catch (\phpbb\extension\exception $e) {
             trigger_error($e, E_USER_WARNING);
         }
     }
     // What are we doing?
     switch ($action) {
         case 'set_config_version_check_force_unstable':
             $force_unstable = $this->request->variable('force_unstable', false);
             if ($force_unstable) {
                 $s_hidden_fields = build_hidden_fields(array('force_unstable' => $force_unstable));
                 confirm_box(false, $user->lang('EXTENSION_FORCE_UNSTABLE_CONFIRM'), $s_hidden_fields);
             } else {
                 $config->set('extension_force_unstable', false);
                 trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
             }
             break;
         case 'list':
         default:
             if (confirm_box(true)) {
                 $config->set('extension_force_unstable', true);
                 trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
             }
             $this->list_enabled_exts($phpbb_extension_manager);
             $this->list_disabled_exts($phpbb_extension_manager);
             $this->list_available_exts($phpbb_extension_manager);
             $this->template->assign_vars(array('U_VERSIONCHECK_FORCE' => $this->u_action . '&action=list&versioncheck_force=1', 'FORCE_UNSTABLE' => $config['extension_force_unstable'], 'U_ACTION' => $this->u_action));
             add_form_key('version_check_settings');
             $this->tpl_name = 'acp_ext_list';
             break;
         case 'enable_pre':
             if (!$md_manager->validate_dir()) {
                 trigger_error($user->lang['EXTENSION_DIR_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
             }
             if (!$md_manager->validate_enable()) {
                 trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
             }
             $extension = $phpbb_extension_manager->get_extension($ext_name);
             if (!$extension->is_enableable()) {
                 trigger_error($user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
             }
             if ($phpbb_extension_manager->is_enabled($ext_name)) {
                 redirect($this->u_action);
             }
             $this->tpl_name = 'acp_ext_enable';
             $template->assign_vars(array('PRE' => true, 'L_CONFIRM_MESSAGE' => $this->user->lang('EXTENSION_ENABLE_CONFIRM', $md_manager->get_metadata('display-name')), 'U_ENABLE' => $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('enable.' . $ext_name)));
             break;
         case 'enable':
             if (!$md_manager->validate_dir()) {
                 trigger_error($user->lang['EXTENSION_DIR_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
             }
             if (!$md_manager->validate_enable()) {
                 trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
             }
             $extension = $phpbb_extension_manager->get_extension($ext_name);
             if (!$extension->is_enableable()) {
                 trigger_error($user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
             }
             if ($phpbb_extension_manager->is_enabled($ext_name)) {
                 redirect($this->u_action);
             }
             try {
                 while ($phpbb_extension_manager->enable_step($ext_name)) {
                     // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
                     if (time() - $start_time >= $safe_time_limit) {
                         $template->assign_var('S_NEXT_STEP', true);
                         meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('enable.' . $ext_name));
                     }
                 }
                 $this->log->add('admin', $user->data['user_id'], $user->ip, 'LOG_EXT_ENABLE', time(), array($ext_name));
             } catch (\phpbb\db\migration\exception $e) {
                 $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user));
             }
             $this->tpl_name = 'acp_ext_enable';
             $template->assign_vars(array('U_RETURN' => $this->u_action . '&action=list'));
             break;
         case 'disable_pre':
             if (!$phpbb_extension_manager->is_enabled($ext_name)) {
                 redirect($this->u_action);
             }
             $this->tpl_name = 'acp_ext_disable';
             $template->assign_vars(array('PRE' => true, 'L_CONFIRM_MESSAGE' => $this->user->lang('EXTENSION_DISABLE_CONFIRM', $md_manager->get_metadata('display-name')), 'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('disable.' . $ext_name)));
             break;
         case 'disable':
             if (!$phpbb_extension_manager->is_enabled($ext_name)) {
                 redirect($this->u_action);
             }
             while ($phpbb_extension_manager->disable_step($ext_name)) {
                 // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
                 if (time() - $start_time >= $safe_time_limit) {
                     $template->assign_var('S_NEXT_STEP', true);
                     meta_refresh(0, $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('disable.' . $ext_name));
                 }
             }
             $this->log->add('admin', $user->data['user_id'], $user->ip, 'LOG_EXT_DISABLE', time(), array($ext_name));
             $this->tpl_name = 'acp_ext_disable';
             $template->assign_vars(array('U_RETURN' => $this->u_action . '&action=list'));
             break;
         case 'delete_data_pre':
             if ($phpbb_extension_manager->is_enabled($ext_name)) {
                 redirect($this->u_action);
             }
             $this->tpl_name = 'acp_ext_delete_data';
             $template->assign_vars(array('PRE' => true, 'L_CONFIRM_MESSAGE' => $this->user->lang('EXTENSION_DELETE_DATA_CONFIRM', $md_manager->get_metadata('display-name')), 'U_PURGE' => $this->u_action . '&action=delete_data&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('delete_data.' . $ext_name)));
             break;
         case 'delete_data':
             if ($phpbb_extension_manager->is_enabled($ext_name)) {
                 redirect($this->u_action);
             }
             try {
                 while ($phpbb_extension_manager->purge_step($ext_name)) {
                     // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
                     if (time() - $start_time >= $safe_time_limit) {
                         $template->assign_var('S_NEXT_STEP', true);
                         meta_refresh(0, $this->u_action . '&action=delete_data&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('delete_data.' . $ext_name));
                     }
                 }
                 $this->log->add('admin', $user->data['user_id'], $user->ip, 'LOG_EXT_PURGE', time(), array($ext_name));
             } catch (\phpbb\db\migration\exception $e) {
                 $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user));
             }
             $this->tpl_name = 'acp_ext_delete_data';
             $template->assign_vars(array('U_RETURN' => $this->u_action . '&action=list'));
             break;
         case 'details':
             // Output it to the template
             $md_manager->output_template_data();
             try {
                 $updates_available = $this->version_check($md_manager, $request->variable('versioncheck_force', false));
                 $template->assign_vars(array('S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name'))));
                 foreach ($updates_available as $branch => $version_data) {
                     $template->assign_block_vars('updates_available', $version_data);
                 }
             } catch (\RuntimeException $e) {
                 $template->assign_vars(array('S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : ''));
             }
             $template->assign_vars(array('U_BACK' => $this->u_action . '&action=list', 'U_VERSIONCHECK_FORCE' => $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name'))));
             $this->tpl_name = 'acp_ext_details';
             break;
     }
 }
 /**
  * Load metadata for this extension
  *
  * @return array
  * @access public
  */
 public function load_metadata()
 {
     // Retrieve the extension name based on the namespace of this file
     $this->retrieve_ext_name();
     // If they've specified an extension, let's load the metadata manager and validate it.
     if ($this->ext_name) {
         $md_manager = new \phpbb\extension\metadata_manager($this->ext_name, $this->config, $this->extension_manager, $this->template, $this->user, $this->root_path);
         try {
             $this->ext_meta = $md_manager->get_metadata('all');
         } catch (\phpbb\extension\exception $e) {
             trigger_error($e, E_USER_WARNING);
         }
     }
     return $this->ext_meta;
 }
Example #3
0
 /**
  * The function that gets the manager for the specified extension.
  * @param string $ext_name The name of the extension.
  * @return \phpbb\extension\metadata_manager|bool
  */
 public static function get_manager($ext_name)
 {
     // If they've specified an extension, let's load the metadata manager and validate it.
     if ($ext_name && $ext_name !== objects::$upload_ext_name) {
         $md_manager = new \phpbb\extension\metadata_manager($ext_name, objects::$config, objects::$phpbb_extension_manager, objects::$template, objects::$user, objects::$phpbb_root_path);
         try {
             $md_manager->get_metadata('all');
         } catch (\phpbb\extension\exception $e) {
             self::response(array('ext_name' => $ext_name, 'status' => 'error', 'error' => $e));
             return false;
         }
         return $md_manager;
     }
     self::response(array('ext_name' => $ext_name, 'status' => 'error', 'error' => objects::$user->lang['EXT_ACTION_ERROR']));
     return false;
 }
 function main($id, $mode)
 {
     global $db, $config, $sconfig, $phpbb_root_path, $user, $template, $request, $phpbb_extension_manager, $phpbb_container, $phpbb_path_helper, $tables;
     $user->add_lang_ext('forumhulp/statistics', 'statistics');
     function __construct(\phpbb\user $user, \phpbb\controller\provider $controller_provider, \phpbb\extension\manager $extension_manager, $phpbb_root_path)
     {
         $this->controller_provider = $controller_provider;
         $this->extension_manager = $extension_manager;
         $this->phpbb_root_path = $phpbb_root_path;
         //		parent::__construct($user);
     }
     $tables['config'] = $phpbb_container->getParameter('tables.config_table');
     $tables['online'] = $phpbb_container->getParameter('tables.online_table');
     $tables['domain'] = $phpbb_container->getParameter('tables.domain_table');
     $tables['se'] = $phpbb_container->getParameter('tables.se_table');
     $tables['archive'] = $phpbb_container->getParameter('tables.archive_table');
     $tables['stats'] = $phpbb_container->getParameter('tables.stats_table');
     include $phpbb_root_path . 'ext/forumhulp/statistics/vendor/stat_functions.php';
     \stat_functions::get_config();
     $action = $request->variable('action', '');
     $screen = $request->variable('screen', $sconfig['statistics_start_screen']);
     $start = $request->variable('start', 0);
     $overall = (int) $request->variable('overall', $config['statistics_archive']);
     if ($overall != (int) $config['statistics_archive']) {
         $config->set('statistics_archive', (int) $overall);
     }
     $this->tpl_name = 'acp_statistics';
     $this->page_title = 'ACP_STATISTICS';
     $template->assign_vars(array('EXT_PATH' => $phpbb_path_helper->update_web_root_path($phpbb_extension_manager->get_extension_path('forumhulp/statistics', true)), 'U_ACTION' => $this->u_action, 'ACT' => $screen));
     switch ($screen) {
         case 'info':
             $user->add_lang(array('install', 'acp/extensions', 'migrator'));
             $ext_name = 'forumhulp/statistics';
             $md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $user, $phpbb_root_path);
             try {
                 $this->metadata = $md_manager->get_metadata('all');
             } catch (\phpbb\extension\exception $e) {
                 trigger_error($e, E_USER_WARNING);
             }
             $md_manager->output_template_data();
             try {
                 $updates_available = $this->version_check($md_manager, $request->variable('versioncheck_force', false));
                 $template->assign_vars(array('S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name'))));
                 foreach ($updates_available as $branch => $version_data) {
                     $template->assign_block_vars('updates_available', $version_data);
                 }
             } catch (\RuntimeException $e) {
                 $template->assign_vars(array('S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : ''));
             }
             $template->assign_vars(array('U_BACK' => $this->u_action));
             $this->tpl_name = 'acp_ext_details';
             break;
         case 'nyi':
             \stat_functions::nyi($start, $this->u_action, $overall);
             break;
         case 'countries':
             \stat_functions::countries($start, $this->u_action, $overall);
             break;
         case 'browsers':
             \stat_functions::browsers($start, $this->u_action, $overall);
             break;
         case 'os':
             \stat_functions::os($start, $this->u_action, $overall);
             break;
         case 'referrals':
             \stat_functions::referrals($start, $this->u_action, $overall);
             break;
         case 'se':
             \stat_functions::se($start, $this->u_action, $overall);
             break;
         case 'ese':
             $this->tpl_name = 'subdisplays/ese';
             \stat_functions::ese($this->u_action, $action);
             break;
         case 'se_terms':
             \stat_functions::se_terms($start, $this->u_action, $overall);
             break;
         case 'crawl':
             \stat_functions::crawl($start, $this->u_action, $overall);
             break;
         case 'modules':
             \stat_functions::modules($start, $this->u_action, $overall);
             break;
         case 'screens':
             \stat_functions::screens($start, $this->u_action, $overall);
             break;
         case 'stats':
             \stat_functions::stats($start, $this->u_action);
             break;
         case 'ustats':
             \stat_functions::ustats($start, $this->u_action);
             break;
         case 'users':
             \stat_functions::users($start, $this->u_action, $overall);
             break;
         case 'config':
             \stat_functions::config($start, $this->u_action);
             break;
         case 'top10':
             \stat_functions::top10($start, $this->u_action);
             break;
         default:
             \stat_functions::online($start, $this->u_action);
             break;
     }
 }
 function main($id, $mode)
 {
     global $db, $config, $user, $phpbb_root_path, $phpEx, $cache, $template, $request, $phpbb_extension_manager, $phpbb_container;
     $this->db = $db;
     $this->user = $user;
     $this->template = $template;
     $this->request = $request;
     $this->cache = $cache;
     $this->config = $config;
     $this->phpbb_root_path = $phpbb_root_path;
     $this->php_ext = $phpEx;
     $this->user->add_lang_ext('forumhulp/uploadstyle', 'upload');
     $this->page_title = $this->user->lang['ACP_UPLOAD_STYLE_TITLE'];
     $this->tpl_name = 'acp_upload';
     $this->default_style = $this->config['default_style'];
     $this->styles_path = $this->phpbb_root_path . $this->styles_path_absolute . '/';
     $this->ext_dir = $this->phpbb_root_path . 'ext';
     $action = $this->request->variable('action', '');
     // if 'i' is a number - continue displaying a number
     $mode = $this->request->variable('mode', $mode);
     $id = $this->request->variable('i', $id);
     $this->main_link = $this->phpbb_root_path . 'adm/index.php?i=' . $id . '&sid=' . $this->user->session_id . '&mode=' . $mode;
     $this->back_link = $this->request->is_ajax() ? adm_back_link($this->u_action) : '';
     include $this->phpbb_root_path . 'ext/forumhulp/uploadstyle/vendor/filetree/filetree.' . $this->php_ext;
     $file = $this->request->variable('file', '');
     if ($file != '') {
         \filetree::get_file($file);
     }
     switch ($action) {
         case 'details':
             $this->user->add_lang(array('install', 'acp/extensions', 'migrator'));
             $ext_name = 'forumhulp/uploadstyle';
             $md_manager = new \phpbb\extension\metadata_manager($ext_name, $this->config, $phpbb_extension_manager, $this->template, $this->user, $this->phpbb_root_path);
             try {
                 $this->metadata = $md_manager->get_metadata('all');
             } catch (\phpbb\extension\exception $e) {
                 trigger_error($e, E_USER_WARNING);
             }
             $md_manager->output_template_data();
             try {
                 $updates_available = $this->version_check($md_manager, $this->request->variable('versioncheck_force', false));
                 $this->template->assign_vars(array('S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name'))));
                 foreach ($updates_available as $branch => $version_data) {
                     $this->template->assign_block_vars('updates_available', $version_data);
                 }
             } catch (\RuntimeException $e) {
                 $this->template->assign_vars(array('S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $this->user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : ''));
             }
             $this->template->assign_vars(array('U_BACK' => $this->u_action . '&action=list'));
             $this->tpl_name = 'acp_ext_details';
             break;
         case 'upload':
             if ($this->request->variable('local_upload', '') != '') {
                 $action = 'upload_local';
             } else {
                 if (strpos($this->request->variable('remote_upload', ''), 'http://') !== false || strpos($this->request->variable('remote_upload', ''), 'https://') !== false) {
                     $action = 'upload_remote';
                 }
             }
         case 'upload_remote':
             if (!is_writable($this->ext_dir)) {
                 $this->trigger_error($this->user->lang('EXT_NOT_WRITABLE'), E_USER_WARNING);
             } else {
                 if (!$this->upload_ext($action)) {
                     //$this->trigger_error($this->user->lang('EXT_UPLOAD_ERROR'), E_USER_WARNING);
                 }
             }
             $this->list_available_styles($phpbb_extension_manager);
             $this->template->assign_vars(array('U_ACTION' => $this->u_action, 'U_UPLOAD' => $this->main_link . '&action=upload', 'U_UPLOAD_REMOTE' => $this->main_link . '&action=upload_remote', 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"'));
             break;
         case 'delete':
             $ext_name = $this->request->variable('ext_name', '');
             $zip_name = $this->request->variable('zip_name', '');
             if ($ext_name != '') {
                 if (confirm_box(true)) {
                     $dir = substr($ext_name, 0, strpos($ext_name, '/'));
                     $extensions = sizeof(array_filter(glob($this->phpbb_root_path . 'styles/' . $dir . '/*'), 'is_dir'));
                     $dir = $extensions == 1 ? $dir : $ext_name;
                     $this->rrmdir($this->phpbb_root_path . 'styles/' . $dir);
                     if ($this->request->is_ajax()) {
                         trigger_error($this->user->lang('STYLE_DELETE_SUCCESS'), E_USER_WARNING);
                     } else {
                         redirect($this->phpbb_root_path . 'adm/index.php?i=' . $id . '&sid=' . $this->user->session_id . '&mode=' . $mode);
                     }
                 } else {
                     confirm_box(false, $this->user->lang('STYLE_DELETE_CONFIRM', $ext_name), build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action)));
                 }
             } else {
                 if ($zip_name != '') {
                     if (confirm_box(true)) {
                         $this->rrmdir($this->phpbb_root_path . 'ext/' . $zip_name);
                         if ($this->request->is_ajax()) {
                             trigger_error($this->user->lang('STYLE_ZIP_DELETE_SUCCESS'), E_USER_WARNING);
                         } else {
                             redirect($this->phpbb_root_path . 'adm/index.php?i=' . $id . '&sid=' . $this->user->session_id . '&mode=' . $mode);
                         }
                     } else {
                         confirm_box(false, $this->user->lang('STYLE_ZIP_DELETE_CONFIRM', $zip_name), build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action)));
                     }
                 }
             }
             break;
         default:
             $this->listzip();
             $this->list_available_styles();
             $this->template->assign_vars(array('U_ACTION' => $this->u_action, 'U_UPLOAD' => $this->main_link . '&action=upload', 'U_UPLOAD_REMOTE' => $this->main_link . '&action=upload_remote', 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"'));
             break;
     }
 }
 /**
  * Display the options a user can configure for this extension
  *
  * @return null
  * @access public
  */
 public function display_options()
 {
     add_form_key('acp_mchat');
     $mchat_config = array('mchat_archive_limit' => array('default' => 25, 'validation' => array('num', false, 25, 50)), 'mchat_avatars' => array('default' => 1, 'validation' => array()), 'mchat_bbcode_disallowed' => array('default' => '', 'validation' => array('string', false, 0, 255)), 'mchat_custom_height' => array('default' => 350, 'validation' => array('num', false, 50, 1000)), 'mchat_custom_page' => array('default' => 1, 'validation' => array()), 'mchat_date' => array('default' => 'D M d, Y g:i a', 'validation' => array('string', false, 0, 255)), 'mchat_edit_delete_limit' => array('default' => 0, 'validation' => array()), 'mchat_flood_time' => array('default' => 0, 'validation' => array('num', false, 0, 30)), 'mchat_index_height' => array('default' => 250, 'validation' => array('num', false, 50, 1000)), 'mchat_live_updates' => array('default' => 1, 'validation' => array()), 'mchat_location' => array('default' => 0, 'validation' => array()), 'mchat_max_message_lngth' => array('default' => 500, 'validation' => array('num', false, 0, 500)), 'mchat_message_limit' => array('default' => 10, 'validation' => array('num', false, 10, 30)), 'mchat_message_num' => array('default' => 10, 'validation' => array('num', false, 10, 50)), 'mchat_message_top' => array('default' => 1, 'validation' => array()), 'mchat_new_posts_edit' => array('default' => 0, 'validation' => array()), 'mchat_new_posts_quote' => array('default' => 0, 'validation' => array()), 'mchat_new_posts_reply' => array('default' => 0, 'validation' => array()), 'mchat_new_posts_topic' => array('default' => 0, 'validation' => array()), 'mchat_on_index' => array('default' => 1, 'validation' => array()), 'mchat_override_min_post_chars' => array('default' => 0, 'validation' => array()), 'mchat_override_smilie_limit' => array('default' => 0, 'validation' => array()), 'mchat_pause_on_input' => array('default' => 0, 'validation' => array()), 'mchat_prune' => array('default' => 0, 'validation' => array()), 'mchat_prune_num' => array('default' => 0, 'validation' => array()), 'mchat_refresh' => array('default' => 10, 'validation' => array('num', false, 5, 60)), 'mchat_rules' => array('default' => '', 'validation' => array('string', false, 0, 255)), 'mchat_static_message' => array('default' => '', 'validation' => array('string', false, 0, 255)), 'mchat_stats_index' => array('default' => 0, 'validation' => array()), 'mchat_timeout' => array('default' => 0, 'validation' => array('num', false, 0, (int) $this->config['session_length'])), 'mchat_whois' => array('default' => 1, 'validation' => array()), 'mchat_whois_refresh' => array('default' => 60, 'validation' => array('num', false, 30, 300)), 'mchat_simple_msg' => array('default' => 0, 'validation' => array()), 'mchat_on_viewforum' => array('default' => 0, 'validation' => array()), 'mchat_on_viewtopic' => array('default' => 0, 'validation' => array()));
     if ($this->request->is_set_post('submit')) {
         if (!function_exists('validate_data')) {
             include $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext;
         }
         $mchat_new_config = array();
         $validation = array();
         foreach ($mchat_config as $key => $value) {
             $mchat_new_config[$key] = $this->request->variable($key, $value['default'], is_string($value['default']));
             if (!empty($value['validation'])) {
                 $validation[$key] = $value['validation'];
             }
         }
         $error = validate_data($mchat_new_config, $validation);
         if (!check_form_key('acp_mchat')) {
             $error[] = 'FORM_INVALID';
         }
         // Replace "error" strings with their real, localised form
         // The /e modifier is deprecated since PHP 5.5.0
         //$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$this->user->lang('\\1'))) ? \$this->user->lang('\\1') : '\\1'", $error);
         foreach ($error as $i => $err) {
             $lang = $this->user->lang($err);
             if (!empty($lang)) {
                 $error[$i] = $lang;
             }
         }
         if (empty($error)) {
             // Set the options the user configured
             foreach ($mchat_new_config as $config_name => $config_value) {
                 $this->config->set($config_name, $config_value);
             }
             // Add an entry into the log table
             $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE');
             trigger_error($this->user->lang('MCHAT_CONFIG_SAVED') . adm_back_link($this->u_action));
         }
     }
     $dateformat_options = '';
     foreach ($this->user->lang['dateformats'] as $format => $null) {
         $dateformat_options .= '<option value="' . $format . '"' . ($format == $this->config['mchat_date'] ? ' selected="selected"' : '') . '>';
         $dateformat_options .= $this->user->format_date(time(), $format, false) . (strpos($format, '|') !== false ? $this->user->lang('VARIANT_DATE_SEPARATOR') . $this->user->format_date(time(), $format, true) : '');
         $dateformat_options .= '</option>';
     }
     $s_custom = false;
     $dateformat_options .= '<option value="custom"';
     if (!isset($this->user->lang['dateformats'][$this->config['mchat_date']])) {
         $dateformat_options .= ' selected="selected"';
         $s_custom = true;
     }
     $dateformat_options .= '>' . $this->user->lang('MCHAT_CUSTOM_DATEFORMAT') . '</option>';
     $template_variables = array();
     foreach ($mchat_config as $key => $value) {
         $template_variables[strtoupper($key)] = $this->config[$key];
     }
     $this->template->assign_vars(array_merge($template_variables, array('MCHAT_ERROR' => !empty($error) ? implode('<br />', $error) : '', 'MCHAT_VERSION' => $this->config['mchat_version'], 'L_MCHAT_BBCODES_DISALLOWED_EXPLAIN' => sprintf($this->user->lang('MCHAT_BBCODES_DISALLOWED_EXPLAIN'), '<a href="' . append_sid("{$this->phpbb_root_path}adm/index.{$this->php_ext}", 'i=bbcodes', true, $this->user->session_id) . '">', '</a>'), 'L_MCHAT_TIMEOUT_EXPLAIN' => sprintf($this->user->lang('MCHAT_USER_TIMEOUT_EXPLAIN'), '<a href="' . append_sid("{$this->phpbb_root_path}adm/index.{$this->php_ext}", 'i=board&amp;mode=load', true, $this->user->session_id) . '">', '</a>', $this->config['session_length']), 'S_MCHAT_DATEFORMAT_OPTIONS' => $dateformat_options, 'S_CUSTOM_DATEFORMAT' => $s_custom, 'U_ACTION' => $this->u_action)));
     // Version check
     $this->user->add_lang(array('install', 'acp/extensions', 'migrator'));
     $ext_name = 'dmzx/mchat';
     $md_manager = new \phpbb\extension\metadata_manager($ext_name, $this->config, $this->phpbb_extension_manager, $this->template, $this->user, $this->phpbb_root_path);
     try {
         $this->metadata = $md_manager->get_metadata('all');
     } catch (\phpbb\extension\exception $e) {
         trigger_error($e, E_USER_WARNING);
     }
     $md_manager->output_template_data();
     try {
         $updates_available = $this->version_check($md_manager, $this->request->variable('versioncheck_force', false));
         $this->template->assign_vars(array('S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name'))));
         foreach ($updates_available as $branch => $version_data) {
             $this->template->assign_block_vars('updates_available', $version_data);
         }
     } catch (\RuntimeException $e) {
         $this->template->assign_vars(array('S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $this->user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : ''));
     }
 }
Example #7
0
 /**
  * The function that displays the details page.
  * @param string $ext_name The name of the extension.
  * @param string $ext_show The section that we need to display.
  */
 public static function details($ext_name, $ext_show)
 {
     if (!$ext_name) {
         redirect(objects::$u_action . '&amp;action=list');
     }
     $show_lang_page = false;
     $load_full_page = objects::$request->variable('ajax', 0) === 1;
     // If they've specified an extension, let's load the metadata manager and validate it.
     if ($ext_name !== objects::$upload_ext_name) {
         $ext_md_manager = new \phpbb\extension\metadata_manager($ext_name, objects::$config, objects::$phpbb_extension_manager, objects::$template, objects::$user, objects::$phpbb_root_path);
         try {
             $ext_md_manager->get_metadata('all');
             $ext_name = $ext_md_manager->get_metadata('name');
             // Just to be sure of the name.
             $display_name = $ext_md_manager->get_metadata('display-name');
             // Output it to the template
             $ext_md_manager->output_template_data();
             try {
                 $updates_available = extensions::version_check($ext_md_manager, objects::$request->variable('versioncheck_force', false));
                 objects::$template->assign_vars(array('S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => objects::$user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $ext_md_manager->get_metadata('display-name'))));
                 foreach ($updates_available as $branch => $version_data) {
                     objects::$template->assign_block_vars('updates_available', $version_data);
                 }
             } catch (\RuntimeException $e) {
                 objects::$template->assign_vars(array('S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== objects::$user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : ''));
             }
         } catch (\phpbb\extension\exception $e) {
             // Display errors in the details tab.
             objects::$template->assign_vars(array('META_NAME' => $ext_name, 'NOT_AVAILABLE' => $e));
             $display_name = $ext_name;
         }
         objects::$template->assign_vars(array('S_IS_ENABLED' => objects::$phpbb_extension_manager->is_enabled($ext_name), 'S_IS_DISABLED' => objects::$phpbb_extension_manager->is_disabled($ext_name)));
         if (!objects::$is_ajax) {
             objects::$template->assign_var('S_DETAILS', true);
             // We output everything if required.
             if ($load_full_page) {
                 $ext_show = 'readme';
             }
         }
     } else {
         $display_name = objects::$md_manager->get_metadata('display-name');
         objects::$md_manager->output_template_data();
         // Output update link to the template if Upload Extensions Updater is installed and updates are available.
         updater::set_update_link();
         // We output everything if this is an ajax request or if we load languages page for Upload Extensions.
         if ($ext_show == 'languages' && $load_full_page) {
             objects::$template->assign_var('S_EXT_DETAILS_SHOW_LANGUAGES', "true");
             // "true" is the specially handled text
             $show_lang_page = true;
             $ext_show = 'readme';
         }
         if (objects::$is_ajax || $ext_show == 'faq' || $load_full_page) {
             objects::$user->add_lang_ext('boardtools/upload', 'upload', false, true);
             $faq_sections = 0;
             foreach (objects::$user->help as $help_ary) {
                 if ($help_ary[0] == '--') {
                     $faq_sections++;
                     objects::$template->assign_block_vars('upload_ext_faq_block', array('BLOCK_TITLE' => $help_ary[1], 'SECTION_NUMBER' => $faq_sections));
                     continue;
                 }
                 objects::$template->assign_block_vars('upload_ext_faq_block.faq_row', array('FAQ_QUESTION' => $help_ary[0], 'FAQ_ANSWER' => $help_ary[1]));
             }
             if (!objects::$is_ajax && !$show_lang_page) {
                 objects::$template->assign_vars(array('SHOW_DETAILS_TAB' => 'faq'));
             }
             if ($ext_show == 'faq') {
                 objects::$template->assign_var('S_EXT_DETAILS_SHOW_FAQ', "true");
                 // "true" is the specially handled text
             }
         }
         if (!objects::$is_ajax) {
             objects::$template->assign_var('S_UPLOAD_DETAILS', true);
             // We output everything if required.
             if ($load_full_page) {
                 $ext_show = 'readme';
             }
         } else {
             objects::$tpl_name = 'acp_ext_details';
         }
     }
     if (file_exists(objects::$phpbb_root_path . 'ext/' . $ext_name . '/README.md') && !objects::$request->is_ajax()) {
         objects::$template->assign_var('EXT_DETAILS_README', true);
     }
     if (file_exists(objects::$phpbb_root_path . 'ext/' . $ext_name . '/CHANGELOG.md') && !objects::$request->is_ajax()) {
         objects::$template->assign_var('EXT_DETAILS_CHANGELOG', true);
     }
     switch ($ext_show) {
         case 'uploaded':
             objects::$template->assign_var('EXT_UPLOADED', true);
             break;
         case 'updated':
             objects::$template->assign_var('EXT_UPDATED', true);
             break;
         case 'enabled':
             objects::$template->assign_var('EXT_ENABLE_STATUS', objects::$user->lang['EXT_ENABLED']);
             break;
         case 'disabled':
             objects::$template->assign_var('EXT_ENABLE_STATUS', objects::$user->lang['EXT_DISABLED']);
             break;
         case 'purged':
             objects::$template->assign_var('EXT_ENABLE_STATUS', objects::$user->lang['EXT_PURGED']);
             break;
         case 'update':
             objects::$template->assign_vars(array('EXT_DETAILS_UPDATE' => true, 'SHOW_DETAILS_TAB' => 'update'));
             break;
     }
     // We output everything if this is an ajax request or if we load languages page for Upload Extensions.
     if (objects::$is_ajax) {
         if ($ext_show == 'languages') {
             objects::$template->assign_var('S_EXT_DETAILS_SHOW_LANGUAGES', "true");
             // "true" is the specially handled text
         }
         $ext_show = 'readme';
     }
     switch ($ext_show) {
         case 'faq':
         case 'update':
             break;
         case 'readme':
             $string = @file_get_contents(objects::$phpbb_root_path . 'ext/' . $ext_name . '/README.md');
             if ($string !== false) {
                 $readme = \Michelf\MarkdownExtra::defaultTransform($string);
                 if (!objects::$is_ajax && !$load_full_page) {
                     objects::$template->assign_vars(array('SHOW_DETAILS_TAB' => 'readme', 'EXT_DETAILS_MARKDOWN' => $readme));
                 } else {
                     objects::$template->assign_var('EXT_DETAILS_README', $readme);
                 }
             }
             if (!objects::$is_ajax && !$load_full_page) {
                 break;
             }
         case 'changelog':
             $string = @file_get_contents(objects::$phpbb_root_path . 'ext/' . $ext_name . '/CHANGELOG.md');
             if ($string !== false) {
                 $changelog = \Michelf\MarkdownExtra::defaultTransform($string);
                 if (!objects::$is_ajax && !$load_full_page) {
                     objects::$template->assign_vars(array('SHOW_DETAILS_TAB' => 'changelog', 'EXT_DETAILS_MARKDOWN' => $changelog));
                 } else {
                     objects::$template->assign_var('EXT_DETAILS_CHANGELOG', $changelog);
                 }
             }
             if (!objects::$is_ajax && !$load_full_page) {
                 break;
             }
         case 'languages':
             if (($result = objects::$request->variable('result', '')) == 'deleted' || $result == 'deleted1') {
                 objects::$template->assign_var('EXT_LANGUAGE_UPLOADED', objects::$user->lang('EXT_LANGUAGE' . ($result == 'deleted' ? 'S' : '') . '_DELETE_SUCCESS'));
             } else {
                 if ($result == 'language_uploaded') {
                     $load_lang = objects::$request->variable('lang', '');
                     objects::$template->assign_vars(array('EXT_LOAD_LANG' => $load_lang, 'EXT_LANGUAGE_UPLOADED' => objects::$user->lang('EXT_LANGUAGE_UPLOADED', $load_lang)));
                 }
             }
             $language_directory = objects::$phpbb_root_path . 'ext/' . $ext_name . '/language';
             $langs = files::get_languages($language_directory);
             $default_lang = in_array(objects::$config['default_lang'], $langs) ? objects::$config['default_lang'] : 'en';
             foreach ($langs as $lang) {
                 $lang_info = languages::details($language_directory, $lang);
                 objects::$template->assign_block_vars('ext_languages', array('NAME' => $lang_info['name'] . ($lang === $default_lang ? ' (' . objects::$user->lang('DEFAULT') . ')' : '')));
             }
             objects::$template->assign_vars(array('EXT_DETAILS_LANGUAGES' => true));
             if (!objects::$is_ajax && (!$load_full_page || $show_lang_page)) {
                 objects::$template->assign_var('SHOW_DETAILS_TAB', 'languages');
                 if (!$load_full_page) {
                     break;
                 }
             }
         case 'filetree':
             filetree::$ext_name = $ext_name;
             $ext_file = objects::$request->variable('ext_file', '/composer.json');
             objects::$template->assign_vars(array('EXT_DETAILS_FILETREE' => true, 'FILETREE' => filetree::php_file_tree(objects::$phpbb_root_path . 'ext/' . $ext_name, objects::$user->lang('ACP_UPLOAD_EXT_CONT', $display_name), objects::$u_action), 'FILENAME' => substr($ext_file, strrpos($ext_file, '/') + 1), 'CONTENT' => highlight_string(@file_get_contents(objects::$phpbb_root_path . 'ext/' . $ext_name . $ext_file), true)));
             if (!objects::$is_ajax && !$load_full_page) {
                 objects::$template->assign_var('SHOW_DETAILS_TAB', 'filetree');
                 break;
             }
         case 'tools':
             objects::$template->assign_vars(array('EXT_DETAILS_TOOLS' => true));
             if (!objects::$is_ajax && !$load_full_page) {
                 objects::$template->assign_var('SHOW_DETAILS_TAB', 'tools');
                 break;
             }
         default:
             if (!$show_lang_page) {
                 objects::$template->assign_vars(array('SHOW_DETAILS_TAB' => 'details'));
             }
             break;
     }
     objects::$template->assign_vars(array('U_ACTION_LIST' => objects::$u_action . '&amp;action=list', 'U_UPLOAD' => objects::$u_action . '&amp;action=upload_language', 'U_DELETE_ACTION' => objects::$u_action . '&amp;action=delete_language&amp;ext_name=' . urlencode($ext_name), 'U_BACK' => objects::$u_action . '&amp;action=list', 'U_EXT_DETAILS' => objects::$u_action . '&amp;action=details&amp;ext_name=' . urlencode($ext_name), 'U_VERSIONCHECK_FORCE' => objects::$u_action . '&amp;action=details&amp;versioncheck_force=1&amp;ext_name=' . urlencode($ext_name), 'UPDATE_EXT_PURGE_DATA' => objects::$user->lang('EXTENSION_DELETE_DATA_CONFIRM', $display_name), 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', 'S_LOAD_FULL_PAGE' => $load_full_page));
 }
Example #8
0
 protected function get_updater_metadata()
 {
     global $config, $template, $request, $user, $phpbb_root_path, $phpbb_extension_manager;
     $md_manager = new \phpbb\extension\metadata_manager($this->updater_ext_name, $config, $phpbb_extension_manager, $template, $user, $phpbb_root_path);
     try {
         $metadata = $md_manager->get_metadata('all');
         $template->assign_var('META_VERSION', $metadata['version']);
     } catch (\phpbb\extension\exception $e) {
         files::catch_errors($e);
     }
     try {
         $updates_available = extensions::version_check($md_manager, $request->variable('versioncheck_force', false));
         $template->assign_vars(array('UPDATER_EXT_NEW_UPDATE' => !empty($updates_available), 'S_UPDATER_UP_TO_DATE' => empty($updates_available), 'S_UPDATER_VERSIONCHECK' => true, 'UPDATER_UP_TO_DATE_MSG' => $user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name'))));
         foreach ($updates_available as $branch => $version_data) {
             $template->assign_block_vars('updater_updates_available', $version_data);
         }
     } catch (\RuntimeException $e) {
         $template->assign_vars(array('S_UPDATER_VERSIONCHECK_STATUS' => $e->getCode(), 'UPDATER_VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : ''));
     }
 }
Example #9
0
 function main($id, $mode)
 {
     global $db, $config, $user, $cache, $template, $request, $phpbb_root_path, $phpEx, $phpbb_log, $phpbb_extension_manager, $phpbb_container;
     $this->page_title = $user->lang['ACP_UPLOAD_EXT_TITLE'];
     $this->tpl_name = 'acp_upload';
     // This is the dir where we will store zip files of extensions.
     $this->zip_dir = $phpbb_root_path . $config['upload_ext_dir'];
     $user->add_lang(array('install', 'acp/extensions', 'migrator'));
     $user->add_lang_ext('boardtools/upload', 'upload');
     // get any url vars
     $action = $request->variable('action', '');
     // if 'i' is a number - continue displaying a number
     $mode = $request->variable('mode', $mode);
     $id = $request->variable('i', $id);
     $this->main_link = $this->u_action;
     $this->back_link = $request->is_ajax() ? '' : adm_back_link($this->u_action);
     $this->phpbb_link_template = '#^(https://)www.phpbb.com/customise/db/download/([0-9]*?)(\\?sid\\=[a-zA-Z0-9]*?)?$#i';
     include $phpbb_root_path . 'ext/boardtools/upload/includes/filetree/filetree.' . $phpEx;
     $file = $request->variable('file', '');
     if ($file != '') {
         \boardtools\upload\filetree\filetree::get_file($file);
     }
     $this->upload_ext_name = 'boardtools/upload';
     $md_manager = new \phpbb\extension\metadata_manager($this->upload_ext_name, $config, $phpbb_extension_manager, $template, $user, $phpbb_root_path);
     try {
         $this->metadata = $md_manager->get_metadata('all');
     } catch (\phpbb\extension\exception $e) {
         $this->trigger_error($e, E_USER_WARNING);
     }
     $upload_extensions_download = false;
     try {
         $updates_available = $this->version_check($md_manager, $request->variable('versioncheck_force', false));
         $template->assign_vars(array('UPLOAD_EXT_NEW_UPDATE' => !empty($updates_available), 'S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name'))));
         foreach ($updates_available as $branch => $version_data) {
             $template->assign_block_vars('updates_available', $version_data);
             $upload_extensions_download = $version_data['download'];
         }
     } catch (\RuntimeException $e) {
         $template->assign_vars(array('S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : ''));
     }
     $this->self_update = $upload_extensions_download;
     switch ($action) {
         case 'details':
             $md_manager->output_template_data();
             if ($this->self_update !== false && preg_match($this->phpbb_link_template, $this->self_update)) {
                 $template->assign_vars(array('U_UPLOAD_EXT_UPDATE' => $this->main_link . '&amp;action=upload_self_confirm'));
             }
             if ($request->is_ajax()) {
                 $template->assign_vars(array('IS_AJAX' => true));
             } else {
                 $template->assign_vars(array('U_BACK' => $this->main_link));
             }
             $this->tpl_name = 'acp_ext_details';
             break;
         case 'upload':
             /* If we unpack a zip file - ensure that we work locally */
             if ($request->variable('local_upload', '') != '') {
                 $action = 'upload_local';
             } else {
                 if (strpos($request->variable('remote_upload', ''), 'http://') === 0 || strpos($request->variable('remote_upload', ''), 'https://') === 0) {
                     $action = 'upload_remote';
                 } else {
                     if (strpos($request->variable('valid_phpbb_ext', ''), 'http://') === 0 || strpos($request->variable('valid_phpbb_ext', ''), 'https://') === 0) {
                         $action = 'upload_from_phpbb';
                     }
                 }
             }
         case 'upload_remote':
         case 'force_update':
         case 'upload_self':
         case 'upload_self_update':
             $this->upload_ext($action);
             $this->listzip();
             $this->get_valid_extensions();
             $this->list_available_exts($phpbb_extension_manager);
             $template->assign_vars(array('U_ACTION' => $this->u_action, 'U_UPLOAD' => $this->main_link . '&amp;action=upload', 'U_UPLOAD_REMOTE' => $this->main_link . '&amp;action=upload_remote', 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"'));
             break;
         case 'upload_self_confirm':
             $template->assign_vars(array('U_ACTION' => $this->u_action, 'U_UPLOAD' => $this->main_link . '&amp;action=upload_self', 'U_UPLOAD_EXT_SELF' => $this->self_update, 'S_UPLOAD_EXT_SELF' => true, 'S_HIDDEN_FIELDS' => build_hidden_fields(array('self_update' => $this->self_update)), 'S_FORM_ENCTYPE' => ''));
             break;
         case 'download':
             $zip_name = $request->variable('zip_name', '');
             if ($zip_name != '') {
                 $download_name = substr($zip_name, 0, -4);
                 $filename = $this->zip_dir . '/' . $download_name;
                 $mimetype = 'application/zip';
                 include $phpbb_root_path . 'ext/boardtools/upload/includes/filetree/filedownload.' . $phpEx;
                 if (!\boardtools\upload\filetree\filedownload::download_file($filename, $download_name, $mimetype)) {
                     redirect($this->main_link);
                 }
             } else {
                 redirect($this->main_link);
             }
             break;
         case 'delete':
             $ext_name = $request->variable('ext_name', '');
             $zip_name = $request->variable('zip_name', '');
             if ($ext_name != '') {
                 if (confirm_box(true)) {
                     // Ensure that we can delete extensions only in ext/ directory.
                     $ext_name = str_replace('.', '', $ext_name);
                     $no_errors = true;
                     if (substr_count($ext_name, '/') === 1 && is_dir($phpbb_root_path . 'ext/' . $ext_name)) {
                         $dir = substr($ext_name, 0, strpos($ext_name, '/'));
                         $extensions = sizeof(glob($phpbb_root_path . 'ext/' . $dir . '/*'));
                         $dir = $extensions === 1 ? $dir : $ext_name;
                         $no_errors = $this->rrmdir($phpbb_root_path . 'ext/' . $dir, true);
                     }
                     if ($no_errors) {
                         if ($request->is_ajax()) {
                             trigger_error($user->lang('EXT_DELETE_SUCCESS'));
                         } else {
                             redirect($this->main_link);
                         }
                     } else {
                         trigger_error($user->lang['EXT_DELETE_ERROR'] . $this->back_link, E_USER_WARNING);
                     }
                 } else {
                     confirm_box(false, $user->lang('EXTENSION_DELETE_CONFIRM', $ext_name), build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action, 'ext_name' => $ext_name)));
                 }
             } else {
                 if ($zip_name != '') {
                     if (confirm_box(true)) {
                         $no_errors = $this->rrmdir($this->zip_dir . '/' . substr($zip_name, 0, -4) . '.zip', true);
                         if ($no_errors) {
                             if ($request->is_ajax()) {
                                 trigger_error($user->lang('EXT_ZIP_DELETE_SUCCESS'));
                             } else {
                                 redirect($this->main_link);
                             }
                         } else {
                             trigger_error($user->lang['EXT_ZIP_DELETE_ERROR'] . $this->back_link, E_USER_WARNING);
                         }
                     } else {
                         confirm_box(false, $user->lang('EXTENSION_ZIP_DELETE_CONFIRM', $zip_name), build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action, 'zip_name' => $zip_name)));
                     }
                 }
             }
             // no break
         // no break
         default:
             $this->listzip();
             $this->get_valid_extensions();
             $this->list_available_exts($phpbb_extension_manager);
             $template->assign_vars(array('U_ACTION' => $this->u_action, 'U_UPLOAD' => $this->main_link . '&amp;action=upload', 'U_UPLOAD_REMOTE' => $this->main_link . '&amp;action=upload_remote', 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"'));
             break;
     }
 }
Example #10
0
 function main()
 {
     // Start the page
     global $config, $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx, $phpbb_log, $cache;
     $this->db = $db;
     $this->config = $config;
     $this->template = $template;
     $this->user = $user;
     $this->cache = $cache;
     $this->request = $request;
     $this->log = $phpbb_log;
     $user->add_lang(array('install', 'acp/extensions', 'migrator'));
     $user->add_lang_ext('lavigor/reenable', 'reenable');
     $this->page_title = 'ACP_REENABLE';
     $action = $request->variable('action', 'list');
     $ext_name = $request->variable('ext_name', '');
     // What is a safe limit of execution time? Half the max execution time should be safe.
     $safe_time_limit = ini_get('max_execution_time') / 2;
     $start_time = time();
     // If they've specified an extension, let's load the metadata manager and validate it.
     if ($ext_name) {
         $md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $user, $phpbb_root_path);
         try {
             $md_manager->get_metadata('all');
         } catch (\phpbb\extension\exception $e) {
             trigger_error($e, E_USER_WARNING);
         }
     }
     // What are we doing?
     switch ($action) {
         case 'list':
         default:
             $this->list_enabled_exts($phpbb_extension_manager, $ext_name);
             $this->template->assign_vars(array('U_VERSIONCHECK_FORCE' => $this->u_action . '&amp;action=list&amp;versioncheck_force=1', 'FORCE_UNSTABLE' => $config['extension_force_unstable'], 'U_ACTION' => $this->u_action));
             $this->tpl_name = 'acp_ext_reenable';
             break;
         case 'reenable':
         case 'reinstall':
             if (!$phpbb_extension_manager->is_enabled($ext_name)) {
                 redirect($this->u_action);
             }
             // We do not want too many logs for reinstallation
             $this->log->disable('admin');
             while ($phpbb_extension_manager->disable_step($ext_name)) {
                 // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
                 if (time() - $start_time >= $safe_time_limit) {
                     $template->assign_var('S_NEXT_STEP', true);
                     meta_refresh(0, $this->u_action . '&amp;action=' . $action . '&amp;ext_name=' . urlencode($ext_name));
                 }
             }
             if ($action == 'reinstall') {
                 try {
                     while ($phpbb_extension_manager->purge_step($ext_name)) {
                         // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
                         if (time() - $start_time >= $safe_time_limit) {
                             $template->assign_var('S_NEXT_STEP', true);
                             meta_refresh(0, $this->u_action . '&amp;action=' . $action . '&amp;ext_name=' . urlencode($ext_name));
                         }
                     }
                 } catch (\phpbb\db\migration\exception $e) {
                     $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user));
                 }
             }
             if (!$md_manager->validate_dir()) {
                 trigger_error($user->lang['EXTENSION_DIR_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
             }
             if (!$md_manager->validate_enable()) {
                 trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
             }
             try {
                 while ($phpbb_extension_manager->enable_step($ext_name)) {
                     // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
                     if (time() - $start_time >= $safe_time_limit) {
                         $template->assign_var('S_NEXT_STEP', true);
                         meta_refresh(0, $this->u_action . '&amp;action=' . $action . '&amp;ext_name=' . urlencode($ext_name));
                     }
                 }
             } catch (\phpbb\db\migration\exception $e) {
                 $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user));
             }
             $this->log->enable('admin');
             if ($action == 'reinstall') {
                 $this->log->add('admin', $user->data['user_id'], $user->ip, 'LOG_EXT_REINSTALL', time(), array($ext_name));
             } else {
                 $this->log->add('admin', $user->data['user_id'], $user->ip, 'LOG_EXT_REENABLE', time(), array($ext_name));
             }
             redirect($this->u_action . '&amp;action=list&amp;ext_name=' . urlencode($ext_name));
             break;
     }
 }
    public function display_points()
    {
        // Grab some vars
        $action = $this->request->variable('action', '');
        $id = $this->request->variable('id', 0);
        // Read out config data
        $sql_array = array('SELECT' => 'config_name, config_value', 'FROM' => array($this->points_config_table => 'c'));
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query($sql);
        while ($row = $this->db->sql_fetchrow($result)) {
            $points_config[$row['config_name']] = $row['config_value'];
        }
        $this->db->sql_freeresult($result);
        $this->template->assign_vars(array_change_key_case($points_config, CASE_UPPER));
        // Read out values data
        $sql_array = array('SELECT' => '*', 'FROM' => array($this->points_values_table => 'v'));
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query($sql);
        $points_values = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        // Form key
        add_form_key('acp_points');
        $this->template->assign_vars(array('BASE' => $this->u_action));
        $submit = $this->request->variable('submit', '');
        if ($submit) {
            if (!check_form_key('acp_points')) {
                trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
            }
            // Values for phpbb_config
            $points_name = $this->request->variable('points_name', '', true);
            $points_enable = $this->request->variable('points_enable', 0);
            // Values for phpbb_points_config
            $points_disablemsg = $this->request->variable('points_disablemsg', '', true);
            $transfer_enable = $this->request->variable('transfer_enable', 0);
            $transfer_pm_enable = $this->request->variable('transfer_pm_enable', 0);
            $comments_enable = $this->request->variable('comments_enable', 0);
            $uplist_enable = $this->request->variable('uplist_enable', 0);
            $stats_enable = $this->request->variable('stats_enable', 0);
            $logs_enable = $this->request->variable('logs_enable', 0);
            $images_topic_enable = $this->request->variable('images_topic_enable', 0);
            $images_memberlist_enable = $this->request->variable('images_memberlist_enable', 0);
            // Values for phpbb_points_values
            $sql_ary = array('transfer_fee' => $this->request->variable('transfer_fee', 0), 'number_show_per_page' => $this->request->variable('number_show_per_page', 0), 'number_show_top_points' => $this->request->variable('number_show_top_points', 0), 'points_per_attach' => round($this->request->variable('points_per_attach', 0.0), 2), 'points_per_attach_file' => round($this->request->variable('points_per_attach_file', 0.0), 2), 'points_per_poll' => round($this->request->variable('points_per_poll', 0.0), 2), 'points_per_poll_option' => round($this->request->variable('points_per_poll_option', 0.0), 2), 'points_per_topic_word' => round($this->request->variable('points_per_topic_word', 0.0), 2), 'points_per_topic_character' => round($this->request->variable('points_per_topic_character', 0.0), 2), 'points_per_post_word' => round($this->request->variable('points_per_post_word', 0.0), 2), 'points_per_post_character' => round($this->request->variable('points_per_post_character', 0.0), 2), 'reg_points_bonus' => round($this->request->variable('reg_points_bonus', 0.0), 2), 'points_bonus_chance' => round($this->request->variable('points_bonus_chance', 0.0), 2), 'points_bonus_min' => round($this->request->variable('points_bonus_min', 0.0), 2), 'points_bonus_max' => round($this->request->variable('points_bonus_max', 0.0), 2), 'points_per_warn' => round($this->request->variable('points_per_warn', 0.0), 2));
            // Check if number_show_per_page is at least 5
            $per_page_check = $this->request->variable('number_show_per_page', 0);
            if ($per_page_check < 5) {
                trigger_error($this->user->lang['POINTS_SHOW_PER_PAGE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING);
            }
            // Check if Transfer Fee percent is not more than 100%
            if ($sql_ary['transfer_fee'] > 100) {
                trigger_error($this->user->lang['POINTS_TRANSFER_FEE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING);
            }
            // Update values in phpbb_config
            if ($points_name != $this->config['points_name']) {
                $this->config->set('points_name', $points_name);
            }
            if ($points_enable != $this->config['points_enable']) {
                $this->config->set('points_enable', $points_enable);
            }
            // Update values in phpbb_points_config
            if ($points_disablemsg != $points_config['points_disablemsg']) {
                $this->functions_points->set_points_config('points_disablemsg', $points_disablemsg);
            }
            if ($transfer_enable != $points_config['transfer_enable']) {
                $this->functions_points->set_points_config('transfer_enable', $transfer_enable);
            }
            if ($transfer_pm_enable != $points_config['transfer_pm_enable']) {
                $this->functions_points->set_points_config('transfer_pm_enable', $transfer_pm_enable);
            }
            if ($comments_enable != $points_config['comments_enable']) {
                $this->functions_points->set_points_config('comments_enable', $comments_enable);
            }
            if ($uplist_enable != $points_config['uplist_enable']) {
                $this->functions_points->set_points_config('uplist_enable', $uplist_enable);
            }
            if ($stats_enable != $points_config['stats_enable']) {
                $this->functions_points->set_points_config('stats_enable', $stats_enable);
            }
            if ($logs_enable != $points_config['logs_enable']) {
                $this->functions_points->set_points_config('logs_enable', $logs_enable);
            }
            if ($images_topic_enable != $points_config['images_topic_enable']) {
                $this->functions_points->set_points_config('images_topic_enable', $images_topic_enable);
            }
            if ($images_memberlist_enable != $points_config['images_memberlist_enable']) {
                $this->functions_points->set_points_config('images_memberlist_enable', $images_memberlist_enable);
            }
            // Update values in phpbb_points_values
            $sql = 'UPDATE ' . $this->points_values_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary);
            $this->db->sql_query($sql);
            // Add logs
            $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_MOD_POINTS_SETTINGS');
            trigger_error($this->user->lang['POINTS_CONFIG_SUCCESS'] . adm_back_link($this->u_action));
        } else {
            $this->template->assign_vars(array('POINTS_NAME' => $this->config['points_name'], 'POINTS_PER_ATTACH' => $points_values['points_per_attach'], 'POINTS_PER_ATTACH_FILE' => $points_values['points_per_attach_file'], 'POINTS_PER_POLL' => $points_values['points_per_poll'], 'POINTS_PER_POLL_OPTION' => $points_values['points_per_poll_option'], 'POINTS_PER_TOPIC_WORD' => $points_values['points_per_topic_word'], 'POINTS_PER_TOPIC_CHARACTER' => $points_values['points_per_topic_character'], 'POINTS_PER_POST_WORD' => $points_values['points_per_post_word'], 'POINTS_PER_POST_CHARACTER' => $points_values['points_per_post_character'], 'POINTS_PER_WARN' => $points_values['points_per_warn'], 'REG_POINTS_BONUS' => $points_values['reg_points_bonus'], 'POINTS_BONUS_CHANCE' => $points_values['points_bonus_chance'], 'POINTS_BONUS_MIN' => $points_values['points_bonus_min'], 'POINTS_BONUS_MAX' => $points_values['points_bonus_max'], 'NUMBER_SHOW_TOP_POINTS' => $points_values['number_show_top_points'], 'NUMBER_SHOW_PER_PAGE' => $points_values['number_show_per_page'], 'TRANSFER_FEE' => $points_values['transfer_fee'], 'POINTS_ENABLE' => $this->config['points_enable'] ? true : false));
        }
        // Delete all userlogs
        $reset_pointslogs = isset($_POST['action_points_logs']) ? true : false;
        if ($reset_pointslogs) {
            if (confirm_box(true)) {
                if (!$this->auth->acl_get('a_points')) {
                    trigger_error($this->user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $sql_layer = $this->db->get_sql_layer();
                switch ($sql_layer) {
                    case 'sqlite':
                    case 'firebird':
                        $this->db->sql_query('DELETE FROM ' . $this->table_points_log);
                        break;
                    default:
                        $this->db->sql_query('TRUNCATE TABLE ' . $this->table_points_log);
                        break;
                }
                $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_RESYNC_POINTSLOGSCOUNTS');
                trigger_error($this->user->lang['LOG_RESYNC_POINTSLOGSCOUNTS'] . adm_back_link($this->u_action));
            } else {
                $s_hidden_fields = build_hidden_fields(array('action_points_logs' => true));
                // Display mode
                confirm_box(false, $this->user->lang['RESYNC_POINTSLOGS_CONFIRM'], $s_hidden_fields);
            }
        }
        // Delete all userpoints
        $reset_points_user = isset($_POST['action_points']) ? true : false;
        if ($reset_points_user) {
            if (confirm_box(true)) {
                if (!$this->auth->acl_get('a_points')) {
                    trigger_error($this->user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $this->db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_points = 0');
                $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_RESYNC_POINTSCOUNTS');
                trigger_error($this->user->lang['LOG_RESYNC_POINTSCOUNTS'] . adm_back_link($this->u_action));
            } else {
                $s_hidden_fields = build_hidden_fields(array('action_points' => true));
                // Display mode
                confirm_box(false, $this->user->lang['RESYNC_POINTS_CONFIRM'], $s_hidden_fields);
            }
        }
        // Transfer or set points for groups
        $group_transfer = isset($_POST['group_transfer']) ? true : false;
        $group_transfer_points = $this->request->variable('group_transfer_points', 0.0);
        $func = $this->request->variable('func', '');
        $group_id = $this->request->variable('group_id', 0);
        $pm_subject = $this->request->variable('pm_subject', '', true);
        $pm_text = $this->request->variable('pm_text', '', true);
        $sql_array = array('SELECT' => 'group_id, group_name, group_type', 'FROM' => array(GROUPS_TABLE => 'g'), 'ORDER_BY' => 'group_name');
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query($sql);
        $total_groups = $this->db->sql_affectedrows($result);
        $this->db->sql_freeresult($result);
        $this->template->assign_vars(array('U_SMILIES' => append_sid("{$this->phpbb_root_path}posting.{$this->phpEx}", 'mode=smilies'), 'S_GROUP_OPTIONS' => group_select_options($total_groups), 'U_ACTION' => $this->u_action));
        // Update the points
        if ($group_transfer) {
            if (!check_form_key('acp_points')) {
                trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
            }
            $sql_array = array('SELECT' => 'group_type, group_name', 'FROM' => array(GROUPS_TABLE => 'g'), 'WHERE' => 'group_id = ' . (int) $group_id);
            $sql = $this->db->sql_build_query('SELECT', $sql_array);
            $result = $this->db->sql_query($sql);
            $row = $this->db->sql_fetchrow($result);
            $this->db->sql_freeresult($result);
            $group_name = $row['group_type'] == GROUP_SPECIAL ? $this->user->lang['G_' . $row['group_name']] : $row['group_name'];
            // Check if we try transfering to BOTS or GUESTS
            if ($row['group_name'] == 'BOTS' || $row['group_name'] == 'GUESTS') {
                trigger_error($this->user->lang['POINTS_GROUP_TRANSFER_SEL_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING);
            }
            $sql_array = array('SELECT' => 'user_id', 'FROM' => array(USER_GROUP_TABLE => 'g'), 'WHERE' => 'user_pending <> ' . true . '
					AND group_id = ' . (int) $group_id);
            $sql = $this->db->sql_build_query('SELECT', $sql_array);
            $result = $this->db->sql_query($sql);
            $user_ids = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $user_ids[] = $row['user_id'];
            }
            $this->db->sql_freeresult($result);
            if (sizeof($user_ids)) {
                $userdata_group = implode(', ', $user_ids);
                if ($func == 'add') {
                    $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\t\tSET user_points = user_points + {$group_transfer_points}\n\t\t\t\t\t\tWHERE user_id IN ({$userdata_group})";
                    $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_GROUP_TRANSFER_ADD');
                }
                if ($func == 'substract') {
                    $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\t\tSET user_points = user_points - {$group_transfer_points}\n\t\t\t\t\t\tWHERE user_id IN ({$userdata_group})";
                    $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_GROUP_TRANSFER_ADD');
                }
                if ($func == 'set') {
                    $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\t\tSET user_points = {$group_transfer_points}\n\t\t\t\t\t\tWHERE user_id IN ({$userdata_group})";
                    $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_GROUP_TRANSFER_SET');
                }
                $result = $this->db->sql_query($sql);
                // Send PM, if pm subject and pm comment is entered
                if ($pm_subject != '' || $pm_text != '') {
                    if ($pm_subject == '' || $pm_text == '') {
                        trigger_error($this->user->lang['POINTS_GROUP_TRANSFER_PM_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING);
                    } else {
                        $sql_array = array('SELECT' => 'user_id, group_id', 'FROM' => array(USER_GROUP_TABLE => 'g'), 'WHERE' => 'user_pending <> ' . true . '
								AND group_id = ' . (int) $group_id);
                        $sql = $this->db->sql_build_query('SELECT', $sql_array);
                        $result = $this->db->sql_query($sql);
                        $group_to = array();
                        while ($row = $this->db->sql_fetchrow($result)) {
                            $group_to[$row['group_id']] = 'to';
                        }
                        // and notify PM to recipient of rating:
                        require_once $this->phpbb_root_path . 'includes/functions_privmsgs.' . $this->phpEx;
                        $poll = $uid = $bitfield = $options = '';
                        generate_text_for_storage($pm_subject, $uid, $bitfield, $options, false, false, false);
                        generate_text_for_storage($pm_text, $uid, $bitfield, $options, true, true, true);
                        $pm_data = array('address_list' => array('g' => $group_to), 'from_user_id' => $this->user->data['user_id'], 'from_username' => 'Points Transfer', 'icon_id' => 0, 'from_user_ip' => $this->user->data['user_ip'], 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $pm_text, 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid);
                        submit_pm('post', $pm_subject, $pm_data, false);
                        $this->db->sql_freeresult($result);
                    }
                    $message = $this->user->lang['POINTS_GROUP_TRANSFER_PM_SUCCESS'] . adm_back_link($this->u_action);
                    trigger_error($message);
                } else {
                    $message = $this->user->lang['POINTS_GROUP_TRANSFER_SUCCESS'] . adm_back_link($this->u_action);
                    trigger_error($message);
                }
            }
        }
        $this->template->assign_vars(array('S_POINTS_MAIN' => true, 'S_POINTS_ACTIVATED' => $this->config['points_enable'] ? true : false, 'U_ACTION' => $this->u_action));
        // Version check
        $this->user->add_lang(array('install', 'acp/extensions', 'migrator'));
        $ext_name = 'dmzx/ultimatepoints';
        $md_manager = new \phpbb\extension\metadata_manager($ext_name, $this->config, $this->phpbb_extension_manager, $this->template, $this->user, $this->phpbb_root_path);
        try {
            $this->metadata = $md_manager->get_metadata('all');
        } catch (\phpbb\extension\exception $e) {
            trigger_error($e, E_USER_WARNING);
        }
        $md_manager->output_template_data();
        try {
            $updates_available = $this->version_check($md_manager, $this->request->variable('versioncheck_force', false));
            $this->template->assign_vars(array('S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name'))));
            foreach ($updates_available as $branch => $version_data) {
                $this->template->assign_block_vars('updates_available', $version_data);
            }
        } catch (\RuntimeException $e) {
            $this->template->assign_vars(array('S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $this->user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : ''));
        }
    }
Example #12
0
 /**
  * Ultimate Blog | ACP | Settings
  */
 public function settings()
 {
     // Requests
     $action = $this->request->variable('action', '');
     $id = $this->request->variable('id', 0);
     // Create a form key for preventing CSRF attacks
     add_form_key('acp_ub_settings');
     // Is the form being submitted to us?
     if ($this->request->is_set('submit')) {
         // Check if the submitted form is valid
         if (!check_form_key('acp_ub_settings')) {
             trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
         } else {
             if ($this->request->variable('ub_rss_enabled', 0) && ($this->request->variable('ub_rss_title', '') == '' || $this->request->variable('ub_rss_desc', '') == '')) {
                 trigger_error($this->user->lang['ACP_UB_SETTINGS_RSS_REQUIRED'] . adm_back_link($this->u_action), E_USER_WARNING);
             } else {
                 // Requests
                 $ub_enabled = $this->request->variable('ub_enabled', 1);
                 $ub_blogs_per_page = $this->request->variable('ub_blogs_per_page', 5);
                 $ub_cutoff = $this->request->variable('ub_cutoff', 1500);
                 $ub_show_desc = $this->request->variable('ub_show_desc', 1);
                 $ub_rss_enabled = $this->request->variable('ub_rss_enabled', 0);
                 $ub_rss_title = $this->request->variable('ub_rss_title', '');
                 $ub_rss_desc = $this->request->variable('ub_rss_desc', '');
                 $ub_rss_cat = $this->request->variable('ub_rss_cat', '');
                 $ub_rss_copy = $this->request->variable('ub_rss_copy', '');
                 $ub_rss_lang = $this->request->variable('ub_rss_title', '');
                 $ub_rss_img = $this->request->variable('ub_rss_img', '');
                 $ub_rss_email = $this->request->variable('ub_rss_email', 1);
                 // Check if submitted value is different that stored value,
                 // if so change it to the submitted value
                 if ($ub_enabled != $this->config['ub_enabled']) {
                     $this->config->set('ub_enabled', $ub_enabled);
                 }
                 if ($ub_blogs_per_page != $this->config['ub_blogs_per_page']) {
                     $this->config->set('ub_blogs_per_page', $ub_blogs_per_page);
                 }
                 if ($ub_cutoff != $this->config['ub_cutoff']) {
                     $this->config->set('ub_cutoff', $ub_cutoff);
                 }
                 if ($ub_show_desc != $this->config['ub_show_desc']) {
                     $this->config->set('ub_show_desc', $ub_show_desc);
                 }
                 if ($ub_rss_enabled != $this->config['ub_rss_enabled']) {
                     $this->config->set('ub_rss_enabled', $ub_rss_enabled);
                 }
                 if ($ub_rss_title != $this->config['ub_rss_title']) {
                     $this->config->set('ub_rss_title', $ub_rss_title);
                 }
                 if ($ub_rss_desc != $this->config['ub_rss_desc']) {
                     $this->config->set('ub_rss_desc', $ub_rss_desc);
                 }
                 if ($ub_rss_cat != $this->config['ub_rss_cat']) {
                     $this->config->set('ub_rss_cat', $ub_rss_cat);
                 }
                 if ($ub_rss_copy != $this->config['ub_rss_copy']) {
                     $this->config->set('ub_rss_copy', $ub_rss_copy);
                 }
                 if ($ub_rss_lang != $this->config['ub_rss_lang']) {
                     $this->config->set('ub_rss_lang', $ub_rss_lang);
                 }
                 if ($ub_rss_img != $this->config['ub_rss_img']) {
                     $this->config->set('ub_rss_img', $ub_rss_img);
                 }
                 if ($ub_rss_email != $this->config['ub_rss_email']) {
                     $this->config->set('ub_rss_email', $ub_rss_email);
                 }
                 // Add the change of Ultimate Blog settings to the log
                 $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_UB_SETTINGS_CHANGED');
                 // Ultimate Blog settings have been updated and logged
                 // Confirm this to the user and provide link back to previous page
                 trigger_error($this->user->lang('ACP_UB_SETTINGS_SAVED') . adm_back_link($this->u_action));
             }
         }
     } else {
         // Set output vars for display in the template
         $this->template->assign_vars(['UB_ENABLED' => $this->config['ub_enabled'] ? true : false, 'UB_BLOGS_PER_PAGE' => $this->config['ub_blogs_per_page'], 'UB_CUTOFF' => $this->config['ub_cutoff'], 'UB_SHOW_DESC' => $this->config['ub_show_desc'], 'UB_RSS_ENABLED' => $this->config['ub_rss_enabled'], 'UB_RSS_TITLE' => $this->config['ub_rss_title'], 'UB_RSS_DESC' => $this->config['ub_rss_desc'], 'UB_RSS_CAT' => $this->config['ub_rss_cat'], 'UB_RSS_COPY' => $this->config['ub_rss_copy'], 'UB_RSS_LANG' => $this->config['ub_rss_lang'], 'UB_RSS_IMG' => $this->config['ub_rss_img'], 'UB_RSS_EMAIL' => $this->config['ub_rss_email'], 'UB_SETTINGS_RSS_EMAIL_EXPLAIN' => $this->user->lang('ACP_UB_SETTINGS_RSS_EMAIL_EXPLAIN', $this->config['board_contact']), 'S_UB_MAIN' => true]);
         // Version check
         $this->user->add_lang(['install', 'acp/extensions', 'migrator']);
         $ext_name = 'posey/ultimateblog';
         $md_manager = new \phpbb\extension\metadata_manager($ext_name, $this->config, $this->phpbb_ext_manager, $this->template, $this->user, $this->phpbb_root_path);
         try {
             $this->metadata = $md_manager->get_metadata('all');
         } catch (\phpbb\extension\exception $e) {
             trigger_error($e, E_USER_WARNING);
         }
         $md_manager->output_template_data();
         try {
             $updates_available = $this->version_check($md_manager, $this->request->variable('versioncheck_force', false));
             $this->template->assign_vars(['S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name'))]);
             foreach ($updates_available as $branch => $version_data) {
                 $this->template->assign_block_vars('updates_available', $version_data);
             }
         } catch (\RuntimeException $e) {
             $this->template->assign_vars(['S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $this->user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : '']);
         }
     }
 }
    function main($id, $mode)
    {
        global $db, $user, $auth, $phpbb_container, $phpbb_extension_manager, $template, $cache, $request;
        global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
        $table_did_you_know = $phpbb_container->getParameter('dmzx.didyouknow.table.did.you.know');
        include_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
        include_once $phpbb_root_path . 'includes/functions_display.' . $phpEx;
        include_once $phpbb_root_path . 'includes/functions_content.' . $phpEx;
        include_once $phpbb_root_path . 'includes/message_parser.' . $phpEx;
        $user->add_lang(array('posting'));
        // Set up general vars
        $action = $request->variable('action', '');
        $action = isset($_POST['add']) ? 'add' : (isset($_POST['save']) ? 'save' : $action);
        $s_hidden_fields = '';
        $word_edit = array();
        $this->tpl_name = 'acp_did_you_know';
        $this->page_title = 'ACP_DYK_TITLE';
        $form_name = 'acp_did_you_know';
        add_form_key($form_name);
        display_custom_bbcodes();
        generate_smilies('inline', '', 1);
        switch ($action) {
            case 'edit':
                $word_id = $request->variable('id', 0);
                if (!$word_id) {
                    trigger_error($user->lang['ACP_DYK_NO_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $sql = 'SELECT *
					FROM ' . $table_did_you_know . "\n\t\t\t\t\tWHERE word_id = {$word_id}";
                $result = $db->sql_query_limit($sql, 1);
                $word_edit = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $s_hidden_fields .= '<input type="hidden" name="id" value="' . $word_id . '" />';
                decode_message($word_edit['word'], $word_edit['bbcode_uid']);
                $template->assign_vars(array('S_EDIT_WORD' => true));
            case 'add':
                $sql = 'SELECT *
					FROM ' . LANG_TABLE;
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('lang', array('LANG_NAME' => $row['lang_local_name'], 'LANG_ISO' => $row['lang_iso']));
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_ADD_WORD' => isset($word_edit['word']) ? false : true, 'S_BBCODE_CHECKED' => true, 'S_SMILIES_CHECKED' => true, 'S_URLS_CHECKED' => true, 'U_ACTION' => $this->u_action, 'U_BACK' => $this->u_action, 'LANGUAGE' => isset($word_edit['lang_iso']) ? $word_edit['lang_iso'] : 'default', 'WORD' => isset($word_edit['word']) ? $word_edit['word'] : '', 'S_HIDDEN_FIELDS' => $s_hidden_fields));
                return;
                break;
            case 'save':
                if (!check_form_key($form_name)) {
                    trigger_error($user->lang['ACP_DYK_FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $word_id = $request->variable('id', 0);
                $word = $request->variable('message', '', true);
                $uid = $bitfield = $options = '';
                $allow_bbcode = $allow_urls = $allow_smilies = true;
                generate_text_for_storage($word, $uid, $bitfield, $options, $request->variable('parse_bbcode', false), $request->variable('parse_urls', false), $request->variable('parse_smilies', false));
                if (!$word) {
                    trigger_error($user->lang['ACP_DYK_ENTER_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $sql_ary = array('word' => $word, 'bbcode_uid' => $uid, 'bbcode_bitfield' => $bitfield, 'bbcode_options' => $options, 'lang_iso' => $request->variable('lang_iso', 'default'));
                if ($word_id) {
                    $db->sql_query('UPDATE ' . $table_did_you_know . '
						SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\tWHERE word_id = {$word_id}");
                    add_log('admin', 'LOG_DYK_SAVE', str_replace('%', '*', $word_id));
                } else {
                    $db->sql_query('INSERT INTO ' . $table_did_you_know . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                    add_log('admin', 'LOG_DYK_SAVE_NEW');
                }
                $message = $word_id ? $user->lang['ACP_DYK_WORD_UPDATED'] : $user->lang['ACP_DYK_WORD_ADDED'];
                trigger_error($message . adm_back_link($this->u_action));
                break;
            case 'delete':
                $word_id = $request->variable('id', 0);
                if (!$word_id) {
                    trigger_error($user->lang['ACP_DYK_NO_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                if (confirm_box(true)) {
                    $sql = 'SELECT word
						FROM ' . $table_did_you_know . "\n\t\t\t\t\t\tWHERE word_id = {$word_id}";
                    $result = $db->sql_query($sql);
                    $deleted_word = $db->sql_fetchfield('word');
                    $db->sql_freeresult($result);
                    $sql = 'DELETE FROM ' . $table_did_you_know . "\n\t\t\t\t\t\tWHERE word_id = {$word_id}";
                    $db->sql_query($sql);
                    add_log('admin', 'LOG_DYK_DELETE', str_replace('%', '*', $word_id));
                    trigger_error($user->lang['ACP_DYK_WORD_REMOVED'] . adm_back_link($this->u_action));
                } else {
                    confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'id' => $word_id, 'action' => 'delete')));
                }
                break;
        }
        $template->assign_vars(array('U_ACTION' => $this->u_action, 'S_HIDDEN_FIELDS' => $s_hidden_fields));
        $sql = 'SELECT dyk.*, l.lang_local_name
			FROM ' . $table_did_you_know . ' dyk
			LEFT JOIN ' . LANG_TABLE . ' l
				ON dyk.lang_iso = l.lang_iso
			ORDER BY dyk.word_id ASC';
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $template->assign_block_vars('words', array('LANGUAGE' => isset($row['lang_local_name']) ? $row['lang_local_name'] : $user->lang['LANGUAGE_SET_DEFAULT'], 'WORD' => $word = generate_text_for_display($row['word'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']), 'WORD_ID' => $row['word_id'], 'U_EDIT' => $this->u_action . '&amp;action=edit&amp;id=' . $row['word_id'], 'U_DELETE' => $this->u_action . '&amp;action=delete&amp;id=' . $row['word_id']));
        }
        $db->sql_freeresult($result);
        // Version check
        $user->add_lang(array('install', 'acp/extensions', 'migrator'));
        $ext_name = 'dmzx/didyouknow';
        $md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $user, $phpbb_root_path);
        try {
            $this->metadata = $md_manager->get_metadata('all');
        } catch (\phpbb\extension\exception $e) {
            trigger_error($e, E_USER_WARNING);
        }
        $md_manager->output_template_data();
        try {
            $updates_available = $this->version_check($md_manager, $request->variable('versioncheck_force', false));
            $template->assign_vars(array('S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name'))));
            foreach ($updates_available as $branch => $version_data) {
                $template->assign_block_vars('updates_available', $version_data);
            }
        } catch (\RuntimeException $e) {
            $template->assign_vars(array('S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : ''));
        }
    }
 function main($id, $mode)
 {
     global $db, $config, $user, $cache, $template, $request, $phpbb_root_path, $phpEx, $phpbb_extension_manager, $phpbb_container, $phpbb_dispatcher;
     $this->page_title = $user->lang['ACP_CRON_STATUS_TITLE'];
     $this->tpl_name = 'acp_cronstatus';
     $user->add_lang_ext('boardtools/cronstatus', 'cronstatus');
     list($sk_config, $sd_config) = explode("|", $config['cronstatus_default_sort']);
     $sk = $request->variable('sk', $sk_config);
     $sd = $request->variable('sd', $sd_config);
     if ($sk != $sk_config || $sd != $sd_config) {
         $config->set("cronstatus_default_sort", $sk . "|" . $sd);
     }
     $action = $request->variable('action', '');
     switch ($action) {
         case 'details':
             $user->add_lang(array('install', 'acp/extensions', 'migrator'));
             $ext_name = 'boardtools/cronstatus';
             $md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $user, $phpbb_root_path);
             try {
                 $this->metadata = $md_manager->get_metadata('all');
             } catch (\phpbb\extension\exception $e) {
                 trigger_error($e, E_USER_WARNING);
             }
             $md_manager->output_template_data();
             try {
                 $updates_available = $this->version_check($md_manager, $request->variable('versioncheck_force', false));
                 $template->assign_vars(array('S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name'))));
                 foreach ($updates_available as $branch => $version_data) {
                     $template->assign_block_vars('updates_available', $version_data);
                 }
             } catch (\RuntimeException $e) {
                 $template->assign_vars(array('S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : ''));
             }
             if ($request->is_ajax()) {
                 $template->assign_vars(array('IS_AJAX' => true));
             } else {
                 $template->assign_vars(array('U_BACK' => $this->u_action));
             }
             $this->tpl_name = 'acp_ext_details';
             break;
         default:
             $view_table = $request->variable('table', false);
             $cron_type = $request->variable('cron_type', '');
             if (!$request->is_ajax() && $cron_type) {
                 $url = append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=' . $cron_type);
                 $template->assign_var('RUN_CRON_TASK', '<img src="' . $url . '" width="1" height="1" alt="" />');
                 meta_refresh(60, $this->u_action . '&amp;sk=' . $sk . '&amp;sd=' . $sd);
             }
             $tasks = $task_array = array();
             $tasks = $phpbb_container->get('cron.manager')->get_tasks();
             $cronlock = '';
             $rows = $phpbb_container->get('boardtools.cronstatus.listener')->get_cron_tasks($cronlock);
             if (sizeof($tasks) && is_array($rows)) {
                 foreach ($tasks as $task) {
                     $task_name = $task->get_name();
                     if (empty($task_name)) {
                         continue;
                     }
                     $task_date = -1;
                     $find = strpos($task_name, 'tidy');
                     if ($find !== false) {
                         $name = substr($task_name, $find + 5);
                         $name = $name == 'sessions' ? 'session' : $name;
                         $task_date = (int) $this->array_find($name . '_last_gc', $rows);
                     } else {
                         if (strpos($task_name, 'prune_notifications')) {
                             $task_date = (int) $this->array_find('read_notification_last_gc', $rows);
                             $name = 'read_notification';
                         } else {
                             if (strpos($task_name, 'queue')) {
                                 $task_date = (int) $this->array_find('last_queue_run', $rows);
                                 $name = 'queue_interval';
                             } else {
                                 $name = strrpos($task_name, ".") !== false ? substr($task_name, strrpos($task_name, ".") + 1) : $task_name;
                                 $task_last_gc = $this->array_find($name . '_last_gc', $rows);
                                 $task_date = $task_last_gc !== false ? (int) $task_last_gc : -1;
                             }
                         }
                     }
                     $new_task_interval = $task_date > 0 ? $this->array_find($name . ($name != 'queue_interval' ? '_gc' : ''), $rows) : 0;
                     $new_task_date = $new_task_interval > 0 ? $task_date + $new_task_interval : 0;
                     /**
                      * Event to modify task variables before displaying cron information
                      *
                      * @event boardtools.cronstatus.modify_cron_task
                      * @var	object	task			Task object
                      * @var	object	task_name		Task name ($task->get_name())
                      * @var	object	name			Task name for new task date
                      * @var	object	task_date		Last task date
                      * @var	object	new_task_date	Next task date
                      * @since 3.1.0-RC3
                      * @changed 3.1.1 Added new_task_date variable
                      */
                     $vars = array('task', 'task_name', 'name', 'task_date', 'new_task_date');
                     extract($phpbb_dispatcher->trigger_event('boardtools.cronstatus.modify_cron_task', compact($vars)));
                     $task_array[] = array('task_sort' => $task->is_ready() ? 'ready' : 'not_ready', 'display_name' => $task_name, 'task_date' => $task_date, 'task_date_print' => $task_date == -1 ? $user->lang['CRON_TASK_AUTO'] : ($task_date ? $user->format_date($task_date, $config['cronstatus_dateformat']) : $user->lang['CRON_TASK_NEVER_STARTED']), 'new_date' => $new_task_date, 'new_date_print' => $new_task_date > 0 ? $user->format_date($new_task_date, $config['cronstatus_dateformat']) : '-', 'task_ok' => $task_date > 0 && $new_task_date > time() ? false : true, 'locked' => $config['cron_lock'] && $cronlock == $name ? true : false);
                 }
                 unset($tasks, $rows);
                 $task_array = $this->array_sort($task_array, $sk, $sd == 'a' ? SORT_ASC : SORT_DESC);
                 foreach ($task_array as $row) {
                     $template->assign_block_vars($row['task_sort'], array('DISPLAY_NAME' => $row['display_name'], 'TASK_DATE' => $row['task_date_print'], 'NEW_DATE' => $row['new_date_print'], 'TASK_OK' => $row['task_ok'], 'LOCKED' => $row['locked'], 'CRON_TASK_RUN' => $request->is_ajax() ? '' : ($row['display_name'] != $cron_type ? '<a href="' . $this->u_action . '&amp;cron_type=' . $row['display_name'] . '&amp;sk=' . $sk . '&amp;sd=' . $sd . '" class="cron_run_link">' . $user->lang['CRON_TASK_RUN'] . '</a>' : '<span class="cron_running_update">' . $user->lang['CRON_TASK_RUNNING'] . '</span>')));
                 }
             }
             $cron_url = append_sid($phpbb_root_path . 'cron.' . $phpEx, false, false);
             // This is used in JavaScript (no &amp;).
             $type_cast_helper = new \phpbb\request\type_cast_helper();
             // We need to use a special class because addslashes() is thought to be not valid by EPV.
             $type_cast_helper->addslashes_recursively($cron_url);
             $template->assign_vars(array('U_ACTION' => $this->u_action, 'U_NAME' => $sk, 'U_SORT' => $sd, 'CRON_URL' => $cron_url, 'VIEW_TABLE' => $view_table));
     }
 }