예제 #1
0
 /**
  * Display board announcements
  *
  * @return null
  * @access public
  */
 public function display_board_announcements()
 {
     // Do not continue if announcement has been disabled
     if (!$this->config['board_announcements_enable']) {
         return;
     }
     // Get board announcement data from the cache
     $board_announcement_data = $this->cache->get('_board_announcement_data');
     if ($board_announcement_data === false) {
         // Get board announcement data from the config_text object
         $board_announcement_data = $this->config_text->get_array(array('announcement_text', 'announcement_uid', 'announcement_bitfield', 'announcement_options', 'announcement_bgcolor', 'announcement_timestamp'));
         // Cache board announcement data
         $this->cache->put('_board_announcement_data', $board_announcement_data);
     }
     // Get announcement cookie if one exists
     $cookie = $this->request->variable($this->config['cookie_name'] . '_baid', '', true, \phpbb\request\request_interface::COOKIE);
     // Do not continue if announcement has been dismissed
     if (!$this->user->data['board_announcements_status'] || $cookie == $board_announcement_data['announcement_timestamp']) {
         return;
     }
     // Prepare board announcement message for display
     $announcement_message = generate_text_for_display($board_announcement_data['announcement_text'], $board_announcement_data['announcement_uid'], $board_announcement_data['announcement_bitfield'], $board_announcement_data['announcement_options']);
     // Add board announcements language file
     $this->user->add_lang_ext('phpbb/boardannouncements', 'boardannouncements');
     // Output board announcement to the template
     $this->template->assign_vars(array('S_BOARD_ANNOUNCEMENT' => true, 'S_BOARD_ANNOUNCEMENT_DISMISS' => (bool) $this->config['board_announcements_dismiss'], 'BOARD_ANNOUNCEMENT' => $announcement_message, 'BOARD_ANNOUNCEMENT_BGCOLOR' => $board_announcement_data['announcement_bgcolor'], 'U_BOARD_ANNOUNCEMENT_CLOSE' => $this->controller_helper->route('phpbb_boardannouncements_controller', array('hash' => generate_link_hash('close_boardannouncement')))));
 }
예제 #2
0
 public function test_set_array_get_array_subset()
 {
     $set_array_param = array('baby' => 'phpBB', 'bar' => '64', 'foo' => '23');
     $this->config_text->set_array($set_array_param);
     $expected = array_merge($set_array_param, array('foo' => '23'));
     $actual = $this->config_text->get_array(array_keys($expected));
     ksort($actual);
     $this->assertSame($expected, $actual);
 }
예제 #3
0
 /**
  * {inheritDoc}
  */
 public function render(\phpbb\template\template $template)
 {
     $l_admin_info = $this->config_text->get('contact_admin_info');
     if ($l_admin_info) {
         $contact_admin_data = $this->config_text->get_array(array('contact_admin_info', 'contact_admin_info_uid', 'contact_admin_info_bitfield', 'contact_admin_info_flags'));
         $l_admin_info = generate_text_for_display($contact_admin_data['contact_admin_info'], $contact_admin_data['contact_admin_info_uid'], $contact_admin_data['contact_admin_info_bitfield'], $contact_admin_data['contact_admin_info_flags']);
     }
     $template->assign_vars(array('S_CONTACT_ADMIN' => true, 'S_CONTACT_FORM' => $this->config['contact_admin_form_enable'], 'S_IS_REGISTERED' => $this->user->data['is_registered'], 'S_POST_ACTION' => append_sid($this->phpbb_root_path . 'memberlist.' . $this->phpEx, 'mode=contactadmin'), 'CONTACT_INFO' => $l_admin_info, 'MESSAGE' => $this->body, 'SUBJECT' => $this->subject, 'NAME' => $this->sender_name, 'EMAIL' => $this->sender_address));
     parent::render($template);
 }
예제 #4
0
 /**
  * Add some stats from piwik on the index
  *
  * @param object $event The event object
  * @return null
  * @access public
  */
 public function add_on_index($event)
 {
     //Is it activated?
     if (!empty($this->config['piwik_stats_index_active']) == false) {
         return;
     }
     // Get piwikstats data from the config_text object
     $config_text = $this->config_text->get_array(array('piwik_token', 'piwik_time_index', 'piwik_cache_index'));
     //Get the data from Cache
     $data = false;
     // $this->cache->get('piwik_stats_index');
     //No Data in the Cache
     if ($data === false) {
         //url to piwik
         $url = $this->config['piwik_url'] . '/index.php?module=API&method=VisitsSummary.get' . '&idSite=' . $this->config['piwik_site_id'] . '&apiModule=VisitsSummary&apiAction=get' . '&period=range&date=last' . $config_text['piwik_time_index'] . '&token_auth=' . $config_text['piwik_token'] . '&format=php';
         //get the data from piwik
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $data = curl_exec($ch);
         curl_close($ch);
         //Is it a correct url?
         if ($data === false) {
             return;
         }
         //$this->cache->put('piwik_stats_index', $data, $config_text['piwik_cache_index']);
     }
     //unserialize the data
     $data = @unserialize($data);
     //Is there serialized data or get we an error from piwik?
     if ($data === false || isset($data['result']) && $data['result'] === 'error') {
         return;
     }
     // Add piwikstats language file
     $this->user->add_lang_ext('tacitus89/piwikstats', 'piwikstats');
     // Output piwikstats to the template
     $this->template->assign_vars(array('S_PIWIK_STATS_INDEX_ACTIVATE' => !empty($this->config['piwik_stats_index_active']) ? true : false, 'S_PIWIK_STATS_PAGE_ACTIVATE' => !empty($this->config['piwik_stats_page_active']) ? true : false, 'PIWIK_STATS_URL' => $this->helper->route('tacitus89_piwikstats_main_controller'), 'PIWIK_VISITORS' => number_format($data['nb_visits'], 0, ',', '.'), 'PIWIK_ACTIONS' => number_format($data['nb_actions'], 0, ',', '.'), 'PIWIK_AVG_TIME_ON_SITE' => gmdate("H:i:s", $data['avg_time_on_site']), 'PIWIK_ACTIONS_PER_VISIT' => round($data['nb_actions_per_visit'], 2), 'PIWIK_TIME' => $config_text['piwik_time_index']));
 }
    public function main($id, $mode)
    {
        global $cache, $config, $db, $phpbb_log, $request, $template, $user, $phpbb_root_path, $phpEx, $phpbb_container;
        $this->cache = $cache;
        $this->config = $config;
        $this->config_text = $phpbb_container->get('config_text');
        $this->db = $db;
        $this->log = $phpbb_log;
        $this->request = $request;
        $this->template = $template;
        $this->user = $user;
        $this->phpbb_root_path = $phpbb_root_path;
        $this->php_ext = $phpEx;
        // Add the posting lang file needed by BBCodes
        $this->user->add_lang(array('posting'));
        // Add the board announcements ACP lang file
        $this->user->add_lang_ext('phpbb/boardannouncements', 'boardannouncements_acp');
        // Load a template from adm/style for our ACP page
        $this->tpl_name = 'board_announcements';
        // Set the page title for our ACP page
        $this->page_title = 'ACP_BOARD_ANNOUNCEMENTS_SETTINGS';
        // Define the name of the form for use as a form key
        $form_name = 'acp_board_announcements';
        add_form_key($form_name);
        // Set an empty error string
        $error = '';
        // Include files needed for displaying BBCodes
        if (!function_exists('display_custom_bbcodes')) {
            include $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext;
        }
        // Get all board announcement data from the config_text table in the database
        $data = $this->config_text->get_array(array('announcement_text', 'announcement_uid', 'announcement_bitfield', 'announcement_options', 'announcement_bgcolor'));
        // If form is submitted or previewed
        if ($this->request->is_set_post('submit') || $this->request->is_set_post('preview')) {
            // Test if form key is valid
            if (!check_form_key($form_name)) {
                $error = $this->user->lang('FORM_INVALID');
            }
            // Get new announcement text and bgcolor values from the form
            $data['announcement_text'] = $this->request->variable('board_announcements_text', '', true);
            $data['announcement_bgcolor'] = $this->request->variable('board_announcements_bgcolor', '', true);
            // Get config options from the form
            $enable_announcements = $this->request->variable('board_announcements_enable', false);
            $allow_guests = $this->request->variable('board_announcements_guests', false);
            $dismiss_announcements = $this->request->variable('board_announcements_dismiss', false);
            // Prepare announcement text for storage
            generate_text_for_storage($data['announcement_text'], $data['announcement_uid'], $data['announcement_bitfield'], $data['announcement_options'], !$this->request->variable('disable_bbcode', false), !$this->request->variable('disable_magic_url', false), !$this->request->variable('disable_smilies', false));
            // Store the announcement text and settings if submitted with no errors
            if (empty($error) && $this->request->is_set_post('submit')) {
                // Store the config enable/disable state
                $this->config->set('board_announcements_enable', $enable_announcements);
                $this->config->set('board_announcements_guests', $allow_guests);
                $this->config->set('board_announcements_dismiss', $dismiss_announcements);
                // Store the announcement settings to the config_table in the database
                $this->config_text->set_array(array('announcement_text' => $data['announcement_text'], 'announcement_uid' => $data['announcement_uid'], 'announcement_bitfield' => $data['announcement_bitfield'], 'announcement_options' => $data['announcement_options'], 'announcement_bgcolor' => $data['announcement_bgcolor'], 'announcement_timestamp' => time()));
                // Set the board_announcements_status for all normal users
                // to 1 when an announcement is created, or 0 when announcement is empty
                $announcement_status = !empty($data['announcement_text']) ? 1 : 0;
                $sql = 'UPDATE ' . USERS_TABLE . '
					SET board_announcements_status = ' . $announcement_status . '
					WHERE user_type <> ' . USER_IGNORE;
                $this->db->sql_query($sql);
                // Set the board_announcement status for guests if they are allowed
                // We do this separately for guests to make sure it is always set to
                // the correct value every time.
                $sql = 'UPDATE ' . USERS_TABLE . '
					SET board_announcements_status = ' . ($allow_guests && $announcement_status ? 1 : 0) . '
					WHERE user_id = ' . ANONYMOUS;
                $this->db->sql_query($sql);
                // Log the announcement update
                $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'BOARD_ANNOUNCEMENTS_UPDATED_LOG');
                // Destroy any cached board announcement data
                $this->cache->destroy('_board_announcement_data');
                // Output message to user for the announcement update
                trigger_error($this->user->lang('BOARD_ANNOUNCEMENTS_UPDATED') . adm_back_link($this->u_action));
            }
        }
        // Prepare a fresh announcement preview
        $announcement_text_preview = '';
        if ($this->request->is_set_post('preview')) {
            $announcement_text_preview = generate_text_for_display($data['announcement_text'], $data['announcement_uid'], $data['announcement_bitfield'], $data['announcement_options']);
        }
        // prepare the announcement text for editing inside the textbox
        $announcement_text_edit = generate_text_for_edit($data['announcement_text'], $data['announcement_uid'], $data['announcement_options']);
        // Output data to the template
        $this->template->assign_vars(array('ERRORS' => $error, 'BOARD_ANNOUNCEMENTS_ENABLED' => isset($enable_announcements) ? $enable_announcements : $this->config['board_announcements_enable'], 'BOARD_ANNOUNCEMENTS_GUESTS' => isset($allow_guests) ? $allow_guests : $this->config['board_announcements_guests'], 'BOARD_ANNOUNCEMENTS_DISMISS' => isset($dismiss_announcements) ? $dismiss_announcements : $this->config['board_announcements_dismiss'], 'BOARD_ANNOUNCEMENTS_TEXT' => $announcement_text_edit['text'], 'BOARD_ANNOUNCEMENTS_PREVIEW' => $announcement_text_preview, 'BOARD_ANNOUNCEMENTS_BGCOLOR' => $data['announcement_bgcolor'], 'S_BBCODE_DISABLE_CHECKED' => !$announcement_text_edit['allow_bbcode'], 'S_SMILIES_DISABLE_CHECKED' => !$announcement_text_edit['allow_smilies'], 'S_MAGIC_URL_DISABLE_CHECKED' => !$announcement_text_edit['allow_urls'], 'BBCODE_STATUS' => $this->user->lang('BBCODE_IS_ON', '<a href="' . append_sid("{$this->phpbb_root_path}faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>'), 'SMILIES_STATUS' => $this->user->lang('SMILIES_ARE_ON'), 'IMG_STATUS' => $this->user->lang('IMAGES_ARE_ON'), 'FLASH_STATUS' => $this->user->lang('FLASH_IS_ON'), 'URL_STATUS' => $this->user->lang('URL_IS_ON'), 'S_BBCODE_ALLOWED' => true, 'S_SMILIES_ALLOWED' => true, 'S_BBCODE_IMG' => true, 'S_BBCODE_FLASH' => true, 'S_LINKS_ALLOWED' => true, 'S_BOARD_ANNOUNCEMENTS' => true, 'U_ACTION' => $this->u_action));
        // Build custom bbcodes array
        display_custom_bbcodes();
    }
예제 #6
0
 function main($id, $mode)
 {
     global $config, $request, $template, $user, $phpbb_container;
     $this->config = $config;
     $this->request = $request;
     $this->template = $template;
     $this->user = $user;
     $this->log = $phpbb_container->get('log');
     $this->config_text = $phpbb_container->get('config_text');
     // Add the piwikstats ACP lang file
     $user->add_lang_ext('tacitus89/piwikstats', 'piwikstats_acp');
     // Create a form key for preventing CSRF attacks
     add_form_key('piwikstats_config');
     // Create an array to collect errors that will be output to the user
     $errors = array();
     // Is the form being submitted to us?
     if ($this->request->is_set_post('submit')) {
         // Test if the submitted form is valid
         if (!check_form_key('piwikstats_config')) {
             $errors[] = $this->user->lang('FORM_INVALID');
         }
         $cacheTime = $this->request->variable('piwik_cache_page', 0);
         $cacheTimeIndex = $this->request->variable('piwik_cache_index', 0);
         if ($cacheTime > 2592000 || $cacheTimeIndex > 2592000) {
             $errors[] = $this->user->lang('ACP_PIWIK_CACHE_TOO_HIGH');
         }
         // If no errors, process the form data
         if (empty($errors)) {
             // Set the options
             $this->config->set('piwik_ext_active', $this->request->variable('piwik_ext_active', 0));
             $this->config->set('piwik_url', rtrim($this->request->variable('piwik_url', '', true), '/'));
             $this->config->set('piwik_site_id', $this->request->variable('piwik_site_id', 0));
             $this->config->set('piwik_accept_donottrack', $this->request->variable('piwik_accept_donottrack', 0));
             $this->config->set('piwik_use_user_id', $this->request->variable('piwik_use_user_id', 0));
             $this->config->set('piwik_set_title', $this->request->variable('piwik_set_title', 0));
             $this->config->set('piwik_track_visitortype', $this->request->variable('piwik_track_visitortype', 0));
             $this->config->set('piwik_search', $this->request->variable('piwik_search', 0));
             $this->config_text->set('piwik_token', $this->request->variable('piwik_token', '', true));
             //Set stats_page
             $this->config->set('piwik_stats_page_active', $this->request->variable('piwik_stats_page_active', 0));
             $this->config_text->set('piwik_time_page', $this->request->variable('piwik_time_page', 0));
             $this->config_text->set('piwik_cache_page', $cacheTime);
             //Set stats_index
             $this->config->set('piwik_stats_index_active', $this->request->variable('piwik_stats_index_active', 0));
             $this->config_text->set('piwik_time_index', $this->request->variable('piwik_time_index', 0));
             $this->config_text->set('piwik_cache_index', $cacheTimeIndex);
             // Add option settings change action to the admin log
             $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_PIWIKSTATS_SETTINGS_LOG');
             // Option settings have been updated
             // Confirm this to the user and provide link back to previous page
             trigger_error($this->user->lang('ACP_PIWIKSTATS_SETTINGS_SAVED') . adm_back_link($this->u_action));
         }
     }
     // Get piwikstats data from the config_text object
     $config_text = $this->config_text->get_array(array('piwik_token', 'piwik_cache_page', 'piwik_time_page', 'piwik_cache_index', 'piwik_time_index'));
     // Set output vars for display in the template
     $this->template->assign_vars(array('S_ERROR' => sizeof($errors) ? true : false, 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'U_ACTION' => $this->u_action, 'S_PIWIK_EXT_ACTIVE' => $this->config['piwik_ext_active'] ? true : false, 'PIWIK_URL' => $this->config['piwik_url'], 'PIWIK_SITE_ID' => $this->config['piwik_site_id'], 'S_PIWIK_ACCEPT_DONOTTRACK' => $this->config['piwik_accept_donottrack'] ? true : false, 'S_PIWIK_USER_ID' => $this->config['piwik_use_user_id'] ? true : false, 'S_PIWIK_SET_TITLE' => $this->config['piwik_set_title'] ? true : false, 'S_PIWIK_TRACK_VISITORTYPE' => $this->config['piwik_track_visitortype'] ? true : false, 'S_PIWIK_SEARCH' => $this->config['piwik_search'] ? true : false, 'PIWIK_TOKEN' => $config_text['piwik_token'], 'S_PIWIK_STATS_PAGE_ACTIVE' => $this->config['piwik_stats_page_active'] ? true : false, 'PIWIK_TIME_PAGE' => $config_text['piwik_time_page'], 'PIWIK_CACHE_PAGE' => $config_text['piwik_cache_page'], 'S_PIWIK_STATS_INDEX_ACTIVE' => $this->config['piwik_stats_index_active'] ? true : false, 'PIWIK_TIME_INDEX' => $config_text['piwik_time_index'], 'PIWIK_CACHE_INDEX' => $config_text['piwik_cache_index']));
     // Load a template from adm/style for our ACP page
     $this->tpl_name = 'acp_piwikstats';
     // Set the page title for our ACP page
     $this->page_title = $user->lang('ACP_PIWIK_INDEX');
 }
예제 #7
0
 /**
  * Get piwikstats data from the config_text object
  *
  * @return array
  * @access private
  */
 private function getConfigText()
 {
     // Get piwikstats data from the config_text object
     return $this->config_text->get_array(array('piwik_token', 'piwik_cache_page', 'piwik_time_page'));
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 protected function get_records_by_range($min_id, $max_id)
 {
     $values = $this->config_text->get_array(array('contact_admin_info', 'contact_admin_info_uid', 'contact_admin_info_flags'));
     return array(array('id' => 1, 'text' => $values['contact_admin_info'], 'bbcode_uid' => $values['contact_admin_info_uid'], 'enable_bbcode' => $values['contact_admin_info_flags'] & OPTION_FLAG_BBCODE, 'enable_magic_url' => $values['contact_admin_info_flags'] & OPTION_FLAG_LINKS, 'enable_smilies' => $values['contact_admin_info_flags'] & OPTION_FLAG_SMILIES));
 }