Ejemplo n.º 1
0
 /**
  * Event: core.postingsubmit_post_end
  *
  * After a posting we assign the tags to the topic
  */
 public function submit_post_end($event)
 {
     if ($this->auth->acl_get(permissions::USE_TAGS, permissions::ADMIN_EDIT_TAGS, permissions::MOD_EDIT_TAGS)) {
         $event_data = $event->get_data();
         $data = $event_data['data'];
         $mode = $event_data['mode'];
         if ($this->is_new_topic($mode) || $this->is_edit_first_post($mode, $data)) {
             $tags = $this->get_tags_from_post_request();
             $all_tags = $this->tags_manager->split_valid_tags($tags);
             $valid_tags = $all_tags['valid'];
             $this->tags_manager->assign_tags_to_topic($data['topic_id'], $valid_tags);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Shows a list of topics that have the given $tags assigned
  *
  * @param $tags tags seperated by comma (",")
  * @param $mode the mode indicates whether all tags (AND, default) or any tag (OR) should be assigned to the resulting topics
  * @param casesensitive wether to search case-sensitive (true) or -insensitive (false, default)
  */
 public function show_tag($tags, $mode, $casesensitive)
 {
     // validate mode
     // default == AND
     $mode = $mode == 'OR' ? 'OR' : 'AND';
     $tags = explode(',', urldecode($tags));
     // remove possible duplicates
     $tags = array_unique($tags);
     $all_tags = $this->tags_manager->split_valid_tags($tags);
     if (sizeof($all_tags['invalid']) > 0) {
         $this->template->assign_var('RH_TOPICTAGS_SEARCH_IGNORED_TAGS', $this->user->lang('RH_TOPICTAGS_SEARCH_IGNORED_TAGS', join(', ', $all_tags['invalid'])));
     }
     $tags = $all_tags['valid'];
     $tags_string = join(', ', $tags);
     $this->template->assign_var('RH_TOPICTAGS_SEARCH_HEADER', $this->user->lang('RH_TOPICTAGS_SEARCH_HEADER_' . $mode, $tags_string));
     if (empty($tags)) {
         // no valid tags
         $this->template->assign_var('NO_TOPICS_FOR_TAG', $this->user->lang('RH_TOPICTAGS_NO_TOPICS_FOR_NO_TAG'));
         return $this->helper->render('show_tag.html', $this->user->lang('RH_TOPICTAGS_TAG_SEARCH'));
     }
     $topics_count = $this->tags_manager->count_topics_by_tags($tags, $mode, $casesensitive);
     if ($topics_count <= 0) {
         $this->template->assign_var('NO_TOPICS_FOR_TAG', $this->user->lang('RH_TOPICTAGS_NO_TOPICS_FOR_TAG_' . $mode, $tags_string));
     } else {
         $pagination = $this->pagination;
         $start = $this->request->variable('start', 0);
         $limit = $this->config['topics_per_page'];
         $start = $pagination->validate_start($start, $limit, $topics_count);
         $topics = $this->tags_manager->get_topics_by_tags($tags, $start, $limit, $mode, $casesensitive);
         $base_url = $this->helper->route('robertheim_topictags_show_tag_controller', array('tags' => urlencode($tags_string)));
         $base_url = append_sid($base_url);
         $pagination->generate_template_pagination($base_url, 'pagination', 'start', $topics_count, $limit, $start);
         $this->user->add_lang('viewforum');
         $this->template->assign_vars(array('TOTAL_TOPICS' => $this->user->lang('VIEW_FORUM_TOPICS', $topics_count), 'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'REPORTED_IMG' => $this->user->img('icon_topic_reported', 'TOPIC_REPORTED'), 'UNAPPROVED_IMG' => $this->user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'), 'DELETED_IMG' => $this->user->img('icon_topic_deleted', 'TOPIC_DELETED'), 'POLL_IMG' => $this->user->img('icon_topic_poll', 'TOPIC_POLL'), 'S_TOPIC_ICONS' => true));
         $this->display_topics($topics);
     }
     // else
     return $this->helper->render('show_tag.html', $this->user->lang('RH_TOPICTAGS_TAG_SEARCH'));
 }
Ejemplo n.º 3
0
 public function test_split_valid_tags()
 {
     $tags = array('tag', 'ta', 'tag1', 'validtag');
     $tags = $this->tags_manager->split_valid_tags($tags);
     $this->assertEquals(array('valid' => array('tag', 'validtag'), 'invalid' => array('ta', 'tag1')), $tags);
 }