/** * Add a secret token to the form (requires the S_FORM_TOKEN template variable) * @param string $form_name The name of the form; has to match the name used in check_form_key, otherwise no restrictions apply */ public function get_form_key($form_name) { add_form_key($form_name); $rootref = $this->template_context->get_root_ref(); $s_form_token = $rootref['S_FORM_TOKEN']; return $s_form_token; }
/** * Enable confirmation */ public function page_footer($event) { $rootref =& $this->template_context->get_root_ref(); foreach (array('FORUMS', 'TOPICS') as $target) { if (!empty($rootref['U_MARK_' . $target])) { $this->user->add_lang_ext('kasimi/markreadconfirm', 'common'); $this->template->assign_vars(array('MARKREADCONFIRM' => true, 'MARKREADCONFIRM_TARGET' => strtolower($target), 'MARKREADCONFIRM_LANG' => $this->user->lang('MARKREADCONFIRM_' . $target))); break; } } }
/** * Updates the template data by inserting the (possibly selected) 'Created time' <option> into the $select tag right after the 'Post time' <option> * * @param string $template_select_key_var * @param string $sort_key * @param bool $template_select_dir_var * @param bool $sort_dir */ protected function inject_created_time_select_option($template_select_key_var, $sort_key, $template_select_dir_var = false, $sort_dir = false) { $rootref =& $this->template_context->get_root_ref(); $select = $rootref[$template_select_key_var]; // Insert 'Created time' $this->user->add_lang_ext('kasimi/sorttopics', 'common'); $new_option = '<option value="c">' . $this->user->lang('SORTTOPICS_CREATED_TIME') . '</option>'; $select = preg_replace("/(value=\"t\".*?<\\/option>)/su", "\$1" . $new_option, $select); // Fix selection $select = $this->set_selected($select, $sort_key); $rootref[$template_select_key_var] = $select; if ($template_select_dir_var !== false && $sort_dir !== false) { $rootref[$template_select_dir_var] = $this->set_selected($rootref[$template_select_dir_var], $sort_dir); } }
/** * Apply custom sorting to SQL query * * @param $event */ public function viewforum_get_topic_ids_data($event) { $this->sort_options_source = 'default'; $this->custom_sort_key = $this->user->data['user_topic_sortby_type']; $this->custom_sort_dir = $this->user->data['user_topic_sortby_dir']; if ($event['forum_data']['sort_topics_by'] != $this->default_sort_by) { // Forum-specific sorting $this->sort_options_source = 'forum'; $this->custom_sort_key = $event['forum_data']['sort_topics_by']; $this->custom_sort_dir = $event['forum_data']['sort_topics_order']; } else { if ($this->user->data['is_registered'] && $this->config['kasimi.sorttopics.ucp_enabled'] && $this->user->data['sort_topics_by_created_time']) { // UCP-specific sorting by created time $this->sort_options_source = 'ucp'; $this->custom_sort_key = 'c'; } } // Temporary sorting if the user used the options at the bottom of viewforum if ($this->request->is_set('sk')) { $this->sort_options_source = 'request'; $this->custom_sort_key = $this->request->variable('sk', $this->custom_sort_key); $this->custom_sort_dir = $this->request->variable('sd', $this->custom_sort_dir); } $this->inject_created_time_select_option('S_SELECT_SORT_KEY', $this->custom_sort_key, 'S_SELECT_SORT_DIR', $this->custom_sort_dir); // Bail out if we don't need to adjust sorting if ($this->custom_sort_key == $this->sort_key && $this->custom_sort_dir == $this->sort_dir) { return; } // This forum requires custom topic sorting, let's get our hands dirty $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => array('t.topic_last_post_time', 't.topic_last_post_id'), 'c' => array('t.topic_time', 't.topic_id'), 'r' => $this->auth->acl_get('m_approve', $event['forum_data']['forum_id']) ? 't.topic_posts_approved + t.topic_posts_unapproved + t.topic_posts_softdeleted' : 't.topic_posts_approved', 's' => 't.topic_title', 'v' => 't.topic_views'); $store_reverse = $event['store_reverse']; if ($store_reverse) { $direction = $this->custom_sort_dir == 'd' ? 'ASC' : 'DESC'; } else { $direction = $this->custom_sort_dir == 'd' ? 'DESC' : 'ASC'; } if (is_array($sort_by_sql[$this->custom_sort_key])) { $sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$this->custom_sort_key]) . ' ' . $direction; } else { $sql_sort_order = $sort_by_sql[$this->custom_sort_key] . ' ' . $direction; } $sql_ary = $event['sql_ary']; $sql_ary['ORDER_BY'] = 't.topic_type ' . (!$store_reverse ? 'DESC' : 'ASC') . ', ' . $sql_sort_order; $event['sql_sort_order'] = $sql_sort_order; $event['sql_ary'] = $sql_ary; $rootref =& $this->template_context->get_root_ref(); if ($this->sort_options_source == 'request' && $this->custom_sort_key == 'c') { $rootref['U_VIEW_FORUM'] .= '&sk=c'; } }