/**
	 * Respond to Javascript callbacks
	 * The name of this method is action_ajax_ followed by what you passed to the context parameter above.
	 */
	public function action_ajax_auto_tags( $handler )
	{
		$selected = array();
		if( isset( $handler->handler_vars['selected'] ) ) {
			$selected = Utils::single_array( $handler->handler_vars['selected'] );
		}
		if( isset( $handler->handler_vars['term'] ) && MultiByte::strlen( $handler->handler_vars['term'] ) ) {
			$search = $handler->handler_vars['term'] . '%';
			$tags = new Terms( DB::get_results( "SELECT * FROM {terms} WHERE vocabulary_id = :vid and LOWER(term_display) LIKE LOWER(:crit) ORDER BY term_display ASC", array( 'vid' => Tags::vocabulary()->id, 'crit' => $search ), 'Term' ) );
		}
		else {
			$tags = Tags::vocabulary()->get_tree( 'term_display ASC' );
		}

		$resp = array();
		foreach ( $tags as $tag ) {
			$resp[] = MultiByte::strpos( $tag->term_display, ',' ) === false ? $tag->term_display : $tag->tag_text_searchable;
		}

		if( count( $selected ) ) {
			$resp = array_diff($resp, $selected );
		}
		// Send the response
//		$ar = new AjaxResponse();
//		$ar->data = $resp;
//		$ar->out();
		echo json_encode( $resp );
	}
Пример #2
0
 /**
  * Handles get requests for the dashboard
  * @todo update check should probably be cron'd and cached, not re-checked every load
  */
 public function get_dashboard()
 {
     // Not sure how best to determine this yet, maybe set an option on install, maybe do this:
     $firstpostdate = DB::get_value('SELECT min(pubdate) FROM {posts} WHERE status = ?', array(Post::status('published')));
     if ($firstpostdate) {
         $this->theme->active_time = DateTime::create($firstpostdate);
     }
     // check to see if we have updates to display
     $this->theme->updates = Options::get('updates_available', array());
     // collect all the stats we display on the dashboard
     $user = User::identify();
     $this->theme->stats = array('author_count' => Users::get(array('count' => 1)), 'post_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('published'))), 'comment_count' => Comments::count_total('approved', false), 'tag_count' => Tags::vocabulary()->count_total(), 'user_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('draft'), 'user_id' => $user->id)), 'unapproved_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total('unapproved', false) : Comments::count_by_author(User::identify()->id, Comment::status('unapproved')), 'spam_comment_count' => $user->can('manage_all_comments') ? Comments::count_total('spam', false) : Comments::count_by_author($user->id, Comment::status('spam')), 'user_scheduled_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('scheduled'), 'user_id' => $user->id)));
     // check for first run
     $u = User::identify();
     $uinfo = $u->info;
     if (!isset($uinfo->experience_level)) {
         $this->theme->first_run = true;
         $u->info->experience_level = 'user';
         $u->info->commit();
     } else {
         $this->theme->first_run = false;
     }
     $this->get_additem_form();
     Stack::add('admin_header_javascript', 'dashboard-js');
     $this->display('dashboard');
 }
Пример #3
0
 /**
  * Add additional template variables to the template output.
  * 
  * This function gets executed *after* regular data is assigned to the
  * template.  So the values here, unless checked, will overwrite any existing 
  * values.
  */
 public function add_template_vars()
 {
     parent::add_template_vars();
     if (!$this->template_engine->assigned('pages')) {
         $this->assign('pages', Posts::get('page_list'));
     }
     if (!$this->template_engine->assigned('asides')) {
         //For Asides loop in sidebar.php
         $this->assign('asides', Posts::get('asides'));
     }
     if (!$this->template_engine->assigned('recent_comments')) {
         //for recent comments loop in sidebar.php
         $this->assign('recent_comments', Comments::get(array('limit' => 5, 'status' => Comment::STATUS_APPROVED, 'orderby' => 'date DESC')));
     }
     if (!$this->template_engine->assigned('more_posts')) {
         //Recent posts in sidebar.php
         //visiting page/2 will offset to the next page of posts in the footer /3 etc
         $pagination = Options::get('pagination');
         $this->assign('more_posts', Posts::get(array('content_type' => 'entry', 'status' => 'published', 'vocabulary' => array('tags:not:tag' => 'asides'), 'offset' => $pagination * $this->page, 'limit' => 5)));
     }
     if (!$this->template_engine->assigned('all_tags')) {
         // List of all the tags
         $this->assign('all_tags', Tags::vocabulary()->get_tree());
     }
     if (!$this->template_engine->assigned('all_entries')) {
         // List of all the entries
         $this->assign('all_entries', Posts::get(array('content_type' => 'entry', 'status' => 'published', 'nolimit' => 1)));
     }
 }
Пример #4
0
	public function test_create_post()
	{
		$tags = array('one', 'two', 'THREE');
		$params = array(
			'title' => 'A post title',
			'content' => 'Some great content. Really.',
			'user_id' => $this->user->id,
			'status' => Post::status('published'),
			'content_type' => Post::type('entry'),
			'tags' => 'one, two, THREE',
			'pubdate' => HabariDateTime::date_create( time() ),
		);
		$post = Post::create($params);

		$this->assert_true( $post instanceof Post, 'Post should be created.' );

		// Check the post's id is set.
		$this->assert_true( (int)$post->id > 0, 'The Post id should be greater than zero' );

		// Check the post's tags are usable.
		$this->assert_equal(count($post->tags), count($tags), 'All tags should have been created.');
		foreach ( $post->tags as $tag ) {
			$this->assert_equal($tag->tag_slug, Utils::slugify($tag->tag_text), 'Tags key should be slugified tag.');
		}
		foreach( $post->tags as $tag ) {
			Tags::vocabulary()->delete_term( $tag );
		}

	}
Пример #5
0
 public static function get_stat($type, $month = NULL)
 {
     $str = 'chicklet_stat_' . $type;
     if ($month != NULL) {
         $str .= '_' . $month;
     }
     if (Cache::has($str)) {
         return Cache::get($str);
     }
     switch ($type) {
         case 'entries':
         case 'posts':
             $params = array('content_type' => array(Post::type('entry'), Post::type('link')), 'nolimit' => TRUE);
             $stat = count(Posts::get($params));
             break;
         case 'subscribers':
             $stat = self::fetch();
             break;
         case 'comments':
             $stat = Comments::count_total(Comment::STATUS_APPROVED);
             break;
         case 'tags':
             $stat = count(Tags::vocabulary()->get_tree());
             break;
         default:
             $stat = 0;
             break;
     }
     Cache::set($str, $stat);
     return $stat;
 }
Пример #6
0
 /**
  * Handles get requests for the dashboard
  * @todo update check should probably be cron'd and cached, not re-checked every load
  */
 public function get_dashboard()
 {
     // Not sure how best to determine this yet, maybe set an option on install, maybe do this:
     $firstpostdate = DB::get_value('SELECT min(pubdate) FROM {posts} WHERE status = ?', array(Post::status('published')));
     $this->theme->active_time = HabariDateTime::date_create($firstpostdate);
     // get the active theme, so we can check it
     // @todo this should be worked into the main Update::check() code for registering beacons
     $active_theme = Themes::get_active();
     $active_theme = $active_theme->name . ':' . $active_theme->version;
     // check to see if we have updates to display
     $this->theme->updates = Options::get('updates_available', array());
     // collect all the stats we display on the dashboard
     $this->theme->stats = array('author_count' => Users::get(array('count' => 1)), 'page_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('published'))), 'entry_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('published'))), 'comment_count' => Comments::count_total(Comment::STATUS_APPROVED, false), 'tag_count' => Tags::vocabulary()->count_total(), 'page_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'entry_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'unapproved_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_UNAPPROVED, false) : Comments::count_by_author(User::identify()->id, Comment::STATUS_UNAPPROVED), 'spam_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_SPAM, false) : Comments::count_by_author(User::identify()->id, Comment::STATUS_SPAM), 'user_entry_scheduled_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('scheduled'), 'user_id' => User::identify()->id)));
     $this->fetch_dashboard_modules();
     // check for first run
     $u = User::identify();
     if (!isset($u->info->experience_level)) {
         $this->theme->first_run = true;
         $u->info->experience_level = 'user';
         $u->info->commit();
     } else {
         $this->theme->first_run = false;
     }
     $this->display('dashboard');
 }
Пример #7
0
 /**
  * Produce HTML output for all this fieldset and all contained controls
  *
  * @param boolean $forvalidation True if this control should render error information based on validation.
  * @return string HTML that will render this control in the form
  */
 function get($forvalidation = true)
 {
     $theme = $this->get_theme($forvalidation);
     $max = Tags::vocabulary()->max_count();
     $tag = $this->tag;
     $theme->class = 'tag_' . $tag->term;
     $theme->id = $tag->id;
     $theme->weight = $max > 0 ? round($tag->count * 10 / $max) : 0;
     $theme->caption = $tag->term_display;
     $theme->count = $tag->count;
     return $theme->fetch($this->get_template(), true);
 }
Пример #8
0
 /**
  * Handles AJAX from /admin/tags
  * Used to delete and rename tags
  */
 public function ajax_tags($handler_vars)
 {
     Utils::check_request_method(array('POST'));
     $wsse = Utils::WSSE($handler_vars['nonce'], $handler_vars['timestamp']);
     if ($handler_vars['digest'] != $wsse['digest']) {
         Session::error(_t('WSSE authentication failed.'));
         echo Session::messages_get(true, array('Format', 'json_messages'));
         return;
     }
     $tag_names = array();
     $theme_dir = Plugins::filter('admin_theme_dir', Site::get_dir('admin_theme', true));
     $this->theme = Themes::create('admin', 'RawPHPEngine', $theme_dir);
     $action = $this->handler_vars['action'];
     switch ($action) {
         case 'delete':
             foreach ($_POST as $id => $delete) {
                 // skip POST elements which are not tag ids
                 if (preg_match('/^tag_\\d+/', $id) && $delete) {
                     $id = substr($id, 4);
                     $tag = Tags::get_by_id($id);
                     $tag_names[] = $tag->term_display;
                     Tags::vocabulary()->delete_term($tag);
                 }
             }
             $msg_status = _n(_t('Tag %s has been deleted.', array(implode('', $tag_names))), _t('%d tags have been deleted.', array(count($tag_names))), count($tag_names));
             Session::notice($msg_status);
             break;
         case 'rename':
             if (!isset($this->handler_vars['master'])) {
                 Session::error(_t('Error: New name not specified.'));
                 echo Session::messages_get(true, array('Format', 'json_messages'));
                 return;
             }
             $master = $this->handler_vars['master'];
             $tag_names = array();
             foreach ($_POST as $id => $rename) {
                 // skip POST elements which are not tag ids
                 if (preg_match('/^tag_\\d+/', $id) && $rename) {
                     $id = substr($id, 4);
                     $tag = Tags::get_by_id($id);
                     $tag_names[] = $tag->term_display;
                 }
             }
             Tags::vocabulary()->merge($master, $tag_names);
             $msg_status = sprintf(_n('Tag %1$s has been renamed to %2$s.', 'Tags %1$s have been renamed to %2$s.', count($tag_names)), implode($tag_names, ', '), $master);
             Session::notice($msg_status);
             break;
     }
     $this->theme->tags = Tags::vocabulary()->get_tree();
     $this->theme->max = Tags::vocabulary()->max_count();
     echo json_encode(array('msg' => Session::messages_get(true, 'array'), 'tags' => $this->theme->fetch('tag_collection')));
 }
 public function action_block_content_tag_cloud($block, $theme)
 {
     $minimum = isset($block->minimum) ? $block->minimum : 0;
     $items = '';
     $tags = Tags::vocabulary()->get_tree();
     // does this need to specify published?
     $max = intval(Tags::vocabulary()->max_count());
     foreach ($tags as $tag) {
         if ($tag->count > $minimum) {
             $size = $tag->count * 15 / $max + 10;
             $items .= '<a href="' . URL::get('display_entries_by_tag', array('tag' => $tag->term)) . '" title="' . $tag->count . "\" style=\"font-size:{$size}pt;\" >" . $tag->term_display . "</a>\n";
         }
     }
     $block->cloud = $items;
 }
Пример #10
0
 /**
  * Add additional template variables to the template output.
  *
  *  You can assign additional output values in the template here, instead of
  *  having the PHP execute directly in the template.  The advantage is that
  *  you would easily be able to switch between template types (RawPHP/Smarty)
  *  without having to port code from one to the other.
  *
  *  You could use this area to provide "recent comments" data to the template,
  *  for instance.
  *
  *  Also, this function gets executed *after* regular data is assigned to the
  *  template.  So the values here, unless checked, will overwrite any existing
  *  values.
  */
 public function add_template_vars()
 {
     // Add FormUI template placing the input before the label
     $this->add_template('formcontrol_text', dirname(__FILE__) . '/forms/formcontrol_text.php', true);
     $this->habari = Site::get_url('habari');
     if (!$this->posts) {
         $this->posts = Posts::get(array('content_type' => 'entry', 'status' => Post::status('published')));
     }
     $this->top_posts = array_slice((array) $this->posts, 0, 2);
     $params = array('content_type' => 'entry', 'status' => Post::status('published'), 'limit' => 7);
     $this->previous_posts = array_slice((array) Posts::get($params), 2, 5);
     if (!$this->user) {
         $this->user = User::identify();
     }
     if (!$this->page) {
         $this->page = isset($page) ? $page : 1;
     }
     if (!$this->tags) {
         $this->tags = Tags::vocabulary()->get_tree();
     }
     if (!$this->pages) {
         $this->pages = Posts::get(array('content_type' => 'page', 'status' => Post::status('published')));
     }
     // Use the configured data format
     $date_format = Options::get('blossom_date_format');
     if ($date_format == 'american') {
         // Apply Format::nice_date() to post date - US style
         Format::apply('nice_date', 'post_pubdate_out', 'g:ia m/d/Y');
     } else {
         // Apply Format::nice_date() to post date - European style
         Format::apply('nice_date', 'post_pubdate_out', 'g:ia d/m/Y');
     }
     // del.icio.us username.
     $delicious_username = Options::get('blossom_delicious_username');
     if ($delicious_username == '') {
         $delicious_username = '******';
     }
     $this->delicious = $delicious_username;
     // Default to hidden
     $this->show_interests = (bool) Options::get('show_interests');
     $this->show_other_news = (bool) Options::get('show_other_news');
     parent::add_template_vars();
 }
Пример #11
0
 /**
  * Add the tray to the publish form
  * @params FormUI $form The publish form object instance
  * @params Post $post The post that is being edited
  **/
 public function action_form_publish($form, $post)
 {
     // Create the tags selector
     $tagselector = $form->publish_controls->append('fieldset', 'tagselector', _t('Tags'));
     $tags_buttons = $tagselector->append('wrapper', 'tags_buttons');
     $tags_buttons->class = 'container';
     $tags_buttons->append('static', 'clearbutton', '<p class="span-5"><input type="button" value="' . _t('Clear') . '" id="clear"></p>');
     $tags_list = $tagselector->append('wrapper', 'tags_list');
     $tags_list->class = 'container';
     $tags_list->append('static', 'tagsliststart', '<ul id="tag-list" class="span-19">');
     $tags = Tags::vocabulary()->get_tree('term_display ASC');
     $tag_html = "";
     foreach ($tags as $tag) {
         $tag_html .= "\n<li class=\" tag_" . $tag->term;
         if (preg_match("/{$tag->term_display}/i", $post->content) || preg_match("/{$tag->term}/i", $post->content)) {
             $tag_html .= ' appearance';
         }
         $tag_html .= '">' . $tag->term_display . "</li>\n";
     }
     $tags_list_content = $tags_list->append('static', 'tagslistcontent', $tag_html);
     $tags_list->append('static', 'tagslistend', '</ul>');
 }
Пример #12
0
 /**
  * Returns an unordered list of all used Tags
  */
 public function theme_show_tags($theme)
 {
     $limit = Options::get(__CLASS__ . '__tags_count');
     $sql = "\n\t\t\tSELECT t.term AS slug, t.term_display AS text, count(tp.object_id) as ttl\n\t\t\tFROM {terms} t\n\t\t\tINNER JOIN {object_terms} tp\n\t\t\tON t.id=tp.term_id\n\t\t\tINNER JOIN {posts} p\n\t\t\tON p.id=tp.object_id AND p.status = ?\n\t\t\tWHERE t.vocabulary_id = ? AND tp.object_type_id = ?\n\t\t\tGROUP BY t.term, t.term_display\n\t\t\tORDER BY t.term_display\n\t\t\tLIMIT {$limit}\n\t\t";
     $tags = DB::get_results($sql, array(Post::status('published'), Tags::vocabulary()->id, Vocabulary::object_type_id('post')));
     foreach ($tags as $index => $tag) {
         $tags[$index]->url = URL::get('display_entries_by_tag', array('tag' => $tag->slug));
     }
     $theme->taglist = $tags;
     return $theme->fetch('taglist');
 }
Пример #13
0
 /**
  * Parses a search string for status, type, author, and tag keywords. Returns
  * an associative array which can be passed to Posts::get(). If multiple
  * authors, statuses, tags, or types are specified, we assume an implicit OR
  * such that (e.g.) any author that matches would be returned.
  *
  * @param string $search_string The search string
  * @return array An associative array which can be passed to Posts::get()
  */
 public static function search_to_get($search_string)
 {
     // if adding to this array, make sure you update the consequences of a search on this below in the switch.
     $keywords = array('author' => 1, 'status' => 1, 'type' => 1, 'tag' => 1, 'info' => 1);
     $statuses = Post::list_post_statuses();
     $types = Post::list_active_post_types();
     $arguments = array('user_id' => array(), 'status' => array(), 'content_type' => array(), 'vocabulary' => array(), 'info' => array());
     $criteria = '';
     // this says, find stuff that has the keyword at the start, and then some term straight after.
     // the terms should have no whitespace, or if it does, be ' delimited.
     // ie tag:foo or tag:'foo bar'
     $flag_regex = '/(?P<flag>\\w+):(?P<value>[^\'"][^\\s]*|(?P<quote>[\'"])[^\\3]+(?<!\\\\)\\3)/i';
     // now do some matching.
     preg_match_all($flag_regex, $search_string, $matches, PREG_SET_ORDER);
     // now we remove those terms from the search string, otherwise the keyword search below has issues. It will pick up things like
     // from tag:'pair of' -> matches of'
     $criteria = trim(preg_replace($flag_regex, '', $search_string));
     // Add special criteria based on the flag parameters.
     foreach ($matches as $match) {
         // trim out any quote marks that have been matched.
         $quote = isset($match['quote']) ? $match['quote'] : ' ';
         $value = trim(stripslashes($match['value']), $quote);
         $flag = $match['flag'];
         $arguments = Plugins::filter('posts_search_to_get', $arguments, $flag, $value, $match, $search_string);
         switch ($flag) {
             case 'author':
                 if ($u = User::get($value)) {
                     $arguments['user_id'][] = (int) $u->id;
                 }
                 break;
             case 'tag':
                 $arguments['vocabulary'][Tags::vocabulary()->name . ':term_display'][] = $value;
                 break;
             case 'status':
                 if (isset($statuses[$value])) {
                     $arguments['status'][] = (int) $statuses[$value];
                 }
                 break;
             case 'type':
                 if (isset($types[$value])) {
                     $arguments['content_type'][] = (int) $types[$value];
                 }
                 break;
             case 'info':
                 if (strpos($value, ':') !== false) {
                     list($infokey, $infovalue) = explode(':', $value, 2);
                     $arguments['info'][] = array($infokey => $infovalue);
                 }
                 break;
         }
     }
     // flatten keys that have single-element or no-element arrays
     foreach ($arguments as $key => $arg) {
         switch (count($arg)) {
             case 0:
                 unset($arguments[$key]);
                 break;
             case 1:
                 if (is_array($arg)) {
                     $arguments[$key] = $arg;
                 } else {
                     $arguments[$key] = $arg[0];
                 }
                 break;
         }
     }
     if ($criteria != '') {
         $arguments['criteria'] = $criteria;
     }
     return $arguments;
 }
Пример #14
0
 /**
  * Save the tags associated to this object into the terms and object_terms tables
  *
  * @param Array $tags strings. The tag names to associate to the object
  * @param Integer $object_id. The id of the object being tagged
  * @param String $object_type. The name of the type of the object being tagged. Defaults to post
  *
  * @return boolean. Whether the associating succeeded or not. true
  */
 public static function save_associations($terms, $object_id, $object_type = 'post')
 {
     if (!$terms instanceof Terms) {
         $terms = Terms::parse($terms, 'Tag', Tags::vocabulary());
     }
     return self::vocabulary()->set_object_terms($object_type, $object_id, $terms);
 }
Пример #15
0
 /**
  * Grabs post data and inserts that data into the internal
  * handler_vars array, which eventually gets extracted into
  * the theme's ( and thereby the template_engine's ) local
  * symbol table for use in the theme's templates
  *
  * This is the default, generic function to grab posts.  To
  * "filter" the posts retrieved, simply pass any filters to
  * the handler_vars variables associated with the post retrieval.
  * For instance, to filter by tag, ensure that handler_vars['tag']
  * contains the tag to filter by.  Simple as that.
  */
 public function act_display($paramarray = array('user_filters' => array()))
 {
     Utils::check_request_method(array('GET', 'HEAD', 'POST'));
     // Get any full-query parameters
     $possible = array('user_filters', 'fallback', 'posts', 'post', 'content_type');
     foreach ($possible as $varname) {
         if (isset($paramarray[$varname])) {
             ${$varname} = $paramarray[$varname];
         }
     }
     /**
      * Since handler_vars no longer contains $_GET and $_POST, we have broken out our valid filters into
      * an array based upon where we should expect them to be. We then only merge those specific pieces together.
      *
      * These are ordered so that handler vars gets overwritten by POST, which gets overwritten by GET, should the
      * same key exist multiple places. This seemed logical to me at the time, but needs further thought.
      */
     $where_filters = array();
     $where_filters_hv = Controller::get_handler_vars()->filter_keys($this->valid_filters['handler_vars']);
     $where_filters_post = $_POST->filter_keys($this->valid_filters['POST']);
     $where_filters_get = $_GET->filter_keys($this->valid_filters['GET']);
     $where_filters = $where_filters_hv->merge($where_filters_post, $where_filters_get);
     $where_filters['vocabulary'] = array();
     if (array_key_exists('tag', $where_filters)) {
         $tags = Tags::parse_url_tags($where_filters['tag']);
         $not_tag = $tags['exclude_tag'];
         $all_tag = $tags['include_tag'];
         if (count($not_tag) > 0) {
             $where_filters['vocabulary'] = array_merge($where_filters['vocabulary'], array(Tags::vocabulary()->name . ':not:term' => $not_tag));
         }
         if (count($all_tag) > 0) {
             $where_filters['vocabulary'] = array_merge($where_filters['vocabulary'], array(Tags::vocabulary()->name . ':all:term' => $all_tag));
         }
         $where_filters['tag_slug'] = Utils::slugify($where_filters['tag']);
         unset($where_filters['tag']);
     }
     if (!isset($_GET['preview'])) {
         $where_filters['status'] = Post::status('published');
     }
     if (!isset($posts)) {
         $user_filters = Plugins::filter('template_user_filters', $user_filters);
         // Work around the tags parameters to Posts::get() being subsumed by the vocabulary parameter
         if (isset($user_filters['not:tag'])) {
             $user_filters['vocabulary'] = array(Tags::vocabulary()->name . ':not:term' => $user_filters['not:tag']);
             unset($user_filters['not:tag']);
         }
         if (isset($user_filters['tag'])) {
             $user_filters['vocabulary'] = array(Tags::vocabulary()->name . ':term_display' => $user_filters['tag']);
             unset($user_filters['tag']);
         }
         $where_filters = $where_filters->merge($user_filters);
         $where_filters = Plugins::filter('template_where_filters', $where_filters);
         $posts = Posts::get($where_filters);
     }
     $this->assign('posts', $posts);
     if ($posts !== false && count($posts) > 0) {
         if (count($posts) == 1) {
             $post = $posts instanceof Post ? $posts : reset($posts);
             Stack::add('body_class', Post::type_name($post->content_type) . '-' . $post->id);
             Stack::add('body_class', 'single');
         } else {
             $post = reset($posts);
             Stack::add('body_class', 'multiple');
         }
         $this->assign('post', $post);
         $type = Post::type_name($post->content_type);
     } elseif ($posts === false || isset($where_filters['page']) && $where_filters['page'] > 1 && count($posts) == 0) {
         if ($this->template_exists('404')) {
             $fallback = array('404');
             // Replace template variables with the 404 rewrite rule
             $this->request->{URL::get_matched_rule()->name} = false;
             $this->request->{URL::set_404()->name} = true;
             $this->matched_rule = URL::get_matched_rule();
             // 404 status header sent in act_display_404, but we're past
             // that, so send it now.
             header('HTTP/1.1 404 Not Found', true, 404);
         } else {
             $this->display('header');
             echo '<h2>';
             _e("Whoops! 404. The page you were trying to access is not really there. Please try again.");
             echo '</h2>';
             header('HTTP/1.1 404 Not Found', true, 404);
             $this->display('footer');
             die;
         }
     }
     $extract = $where_filters->filter_keys('page', 'type', 'id', 'slug', 'posttag', 'year', 'month', 'day', 'tag', 'tag_slug');
     foreach ($extract as $key => $value) {
         ${$key} = $value;
     }
     $this->assign('page', isset($page) ? $page : 1);
     if (!isset($fallback)) {
         // Default fallbacks based on the number of posts
         $fallback = array('{$type}.{$id}', '{$type}.{$slug}', '{$type}.tag.{$posttag}');
         if (count($posts) > 1) {
             $fallback[] = '{$type}.multiple';
             $fallback[] = 'multiple';
         } else {
             $fallback[] = '{$type}.single';
             $fallback[] = 'single';
         }
     }
     $searches = array('{$id}', '{$slug}', '{$year}', '{$month}', '{$day}', '{$type}', '{$tag}');
     $replacements = array(isset($post) && $post instanceof Post ? $post->id : '-', isset($post) && $post instanceof Post ? $post->slug : '-', isset($year) ? $year : '-', isset($month) ? $month : '-', isset($day) ? $day : '-', isset($type) ? $type : '-', isset($tag_slug) ? $tag_slug : '-');
     $fallback[] = 'home';
     $fallback = Plugins::filter('template_fallback', $fallback, $posts, isset($post) ? $post : null);
     $fallback = array_values(array_unique(MultiByte::str_replace($searches, $replacements, $fallback)));
     for ($z = 0; $z < count($fallback); $z++) {
         if (MultiByte::strpos($fallback[$z], '{$posttag}') !== false && isset($post) && $post instanceof Post) {
             $replacements = array();
             if ($alltags = $post->tags) {
                 foreach ($alltags as $current_tag) {
                     $replacements[] = MultiByte::str_replace('{$posttag}', $current_tag->term, $fallback[$z]);
                 }
                 array_splice($fallback, $z, 1, $replacements);
             } else {
                 break;
             }
         }
     }
     return $this->display_fallback($fallback);
 }
 /**
  * Add simplified tag array to the available template vars
  * @param Theme $theme The theme that will display the template
  **/
 public function theme_tag_links($theme, $sortorder = 'term_display asc')
 {
     $theme->tag_links = Tags::vocabulary()->get_tree($sortorder);
     return $theme->fetch('simpletaglist');
 }
Пример #17
0
 /**
  * Handles AJAX from /admin/tags
  * Used to delete and rename tags
  */
 public function ajax_tags($handler_vars)
 {
     Utils::check_request_method(array('POST'));
     $response = new AjaxResponse();
     $wsse = Utils::WSSE($handler_vars['nonce'], $handler_vars['timestamp']);
     if ($handler_vars['digest'] != $wsse['digest']) {
         $response->message = _t('WSSE authentication failed.');
         $response->out();
         return;
     }
     $tag_names = array();
     $this->create_theme();
     $action = $this->handler_vars['action'];
     switch ($action) {
         case 'delete':
             foreach ($_POST as $id => $delete) {
                 // skip POST elements which are not tag ids
                 if (preg_match('/^tag_\\d+/', $id) && $delete) {
                     $id = substr($id, 4);
                     $tag = Tags::get_by_id($id);
                     $tag_names[] = $tag->term_display;
                     Tags::vocabulary()->delete_term($tag);
                 }
             }
             $response->message = _n(_t('Tag %s has been deleted.', array(implode('', $tag_names))), _t('%d tags have been deleted.', array(count($tag_names))), count($tag_names));
             break;
         case 'rename':
             if (!isset($this->handler_vars['master'])) {
                 $response->message = _t('Error: New name not specified.');
                 $response->out();
                 return;
             }
             $master = $this->handler_vars['master'];
             $tag_names = array();
             foreach ($_POST as $id => $rename) {
                 // skip POST elements which are not tag ids
                 if (preg_match('/^tag_\\d+/', $id) && $rename) {
                     $id = substr($id, 4);
                     $tag = Tags::get_by_id($id);
                     $tag_names[] = $tag->term_display;
                 }
             }
             Tags::vocabulary()->merge($master, $tag_names);
             $response->message = sprintf(_n('Tag %1$s has been renamed to %2$s.', 'Tags %1$s have been renamed to %2$s.', count($tag_names)), implode($tag_names, ', '), $master);
             break;
     }
     $this->theme->tags = Tags::vocabulary()->get_tree('term_display ASC');
     $this->theme->max = Tags::vocabulary()->max_count();
     $response->data = $this->theme->fetch('tag_collection');
     $response->out();
 }
Пример #18
0
	/**
	 * Output a post collection based on the provided parameters.
	 *
	 * @param array $params An array of parameters as passed to Posts::get() to retrieve posts.
	 */
	public function get_collection( $params = array() )
	{
		// Store handler vars since we'll be using them a lot.
		$handler_vars = Controller::get_handler_vars();

		// Retrieve the current matched rule and store its name and argument values.
		$rr = URL::get_matched_rule();
		$rr_name = $rr->name;
		$rr_args = $rr->named_arg_values;

		// Assign alternate links based on the matched rule.
		$alternate_rules = array(
			'atom_feed_tag' => 'display_entries_by_tag',
			'atom_feed' => 'display_home',
			'atom_entry' => 'display_entry',
			'atom_feed_entry_comments' => 'display_entry',
			'atom_feed_page_comments' => 'display_entry',
			'atom_feed_comments' => 'display_home',
			);
		$alternate_rules = Plugins::filter( 'atom_get_collection_alternate_rules', $alternate_rules );
		$alternate = URL::get( $alternate_rules[$rr_name], $handler_vars, false );

		// Assign self link based on the matched rule.
		$self = URL::get( $rr_name, $rr_args, false );

		// Get posts to put in the feed
		$page = ( isset( $rr_args['page'] ) ) ? $rr_args['page'] : 1;
		if ( $page > 1 ) {
			$params['page'] = $page;
		}

		if ( !isset( $params['content_type'] ) ) {
			$params['content_type'] = Post::type( 'entry' );
		}
		$params['content_type'] = Plugins::filter( 'atom_get_collection_content_type', $params['content_type'] );

		$params['status'] = $this->is_auth() ? 'any' : Post::status( 'published' );
		$params['orderby'] = 'updated DESC';
		$params['limit'] = Options::get( 'atom_entries' );

		$params = array_merge( $params, $rr_args );

		if ( array_key_exists( 'tag', $params ) ) {
			$id = urlencode( $params['tag'] );
			$tags = explode( ' ', $params['tag'] );
			foreach ( $tags as $tag ) {
				if ( $tag[0] == '-' ) {
					$tag = substr( $tag, 1 );
					$params['vocabulary'][Tags::vocabulary()->name . ':not:term'][] = Utils::slugify( $tag );
				}
				else {
					$params['vocabulary'][Tags::vocabulary()->name . ':all:term'][] = Utils::slugify( $tag );
				}
			}
			unset( $params['tag'] );
		}
		else {
			$id = 'atom';
		}
		$posts = Posts::get( $params );

		if ( count( $posts ) ) {
			$updated = $posts[0]->updated;
		}
		else {
			$updated = null;
			header( 'HTTP/1.1 404 Not Found', true, 404 );
			die( 'Posts could not be found' );
		}

		$xml = $this->create_atom_wrapper( $alternate, $self, $id, $updated );

		$xml = $this->add_pagination_links( $xml, $posts->count_all() );

		$xml = $this->add_posts( $xml, $posts );

		Plugins::act( 'atom_get_collection', $xml, $params, $handler_vars );
		$xml = $xml->asXML();

		ob_clean();
		header( 'Content-Type: application/atom+xml' );

		print $this->tidy_xml( $xml );
	}
Пример #19
0
	public function test_get_tag()
	{
		$this->tag->insert();
		// Get tag by text
		$t = Tags::vocabulary()->get_term( $this->text, 'Tag' );
		$this->assertEquals( $t->term_display, $this->tag->term_display );
		// Get tag by id
		$t = Tags::vocabulary()->get_term( (int)$t->id, 'Tag' );
		$this->assertEquals( $t->term_display, $this->tag->term_display );
		Tags::vocabulary()->delete_term( $t );
	}
Пример #20
0
 /**
  * Handles AJAX from /admin/tags
  * Used to search for, delete and rename tags
  */
 public function ajax_tags()
 {
     Utils::check_request_method(array('POST', 'HEAD'));
     $this->create_theme();
     $params = $_POST['query'];
     // Get a usable array with filter parameters from the odd syntax we received from the faceted search
     $fetch_params = array();
     if (isset($params)) {
         foreach ($params as $param) {
             $key = key($param);
             // Revert translation
             if ($key != 'text') {
                 $key = self::$facets[$key];
             }
             $value = current($param);
             if (array_key_exists($key, $fetch_params)) {
                 $fetch_params[$key] = Utils::single_array($fetch_params[$key]);
                 $fetch_params[$key][] = $value;
             } else {
                 $fetch_params[$key] = $value;
             }
         }
     }
     // Grab facets / params
     $search = array_key_exists('text', $fetch_params) ? $fetch_params['text'] : null;
     $min = array_key_exists('morethan', $fetch_params) ? $fetch_params['morethan'] + 1 : 0;
     $max = array_key_exists('lessthan', $fetch_params) ? $fetch_params['lessthan'] - 1 : null;
     $orderby_code = array_key_exists('orderby', $fetch_params) ? $fetch_params['orderby'] : null;
     $orderby = isset($orderby_code) ? explode('_', self::$facet_values['orderby'][$orderby_code]) : ['alphabetical', 'asc'];
     $this->theme->tags = Tags::get_by_frequency(null, null, $min, $max, $search, self::$orderby_translate[$orderby[0]], $orderby[1] == 'asc');
     // Create FormUI elements (list items) from the filtered tag list
     $this->theme->max = Tags::vocabulary()->max_count();
     $this->theme->min = Tags::vocabulary()->min_count();
     $output = '';
     if (count($this->theme->tags) > 0) {
         $listitems = $this->get_tag_listitems();
         // Get HTML from FormUI
         foreach ($listitems as $listitem) {
             $output .= $listitem->get($this->theme);
         }
     }
     $ar = new AjaxResponse();
     $ar->html('#tag_collection', $output);
     $ar->out();
 }
Пример #21
0
 public static function get_associations($object_id, $object_type = 'post')
 {
     return Tags::vocabulary()->get_object_terms($object_type, $object_id);
 }
Пример #22
0
 /**
  * Tag Archives
  *
  * Handle tag archive block output
  *
  * @param Block $block The block instance to be configured
  * @param Theme $theme The active theme
  */
 public function action_block_content_tag_archives($block, $theme)
 {
     $tags = array();
     $results = Tags::vocabulary()->get_tree();
     foreach ($results as $result) {
         $count = '';
         if ($block->show_counts) {
             $count = " (" . Posts::count_by_tag($result->term_display, "published") . ")";
         }
         $url = URL::get('display_entries_by_tag', array('tag' => $result->term));
         $tags[] = array('tag' => $result->term_display, 'count' => $count, 'url' => $url);
     }
     $block->tags = $tags;
 }
Пример #23
0
 /**
  * Get posts by tag
  */
 public function test_get_posts_by_tag()
 {
     // setup
     $tags = array();
     if (Tags::vocabulary()->get_term("laser")) {
         Tags::vocabulary()->delete_term("laser");
     }
     if (Tags::vocabulary()->get_term("dog")) {
         Tags::vocabulary()->delete_term("dog");
     }
     if (Tags::vocabulary()->get_term("name")) {
         Tags::vocabulary()->delete_term("name");
     }
     $tags[] = Tags::vocabulary()->add_term("laser");
     $five_tags = array("mattress", "freeze", "DOG", "Name", "hash");
     foreach ($five_tags as $tag) {
         $tags[] = Tags::vocabulary()->add_term($tag);
         $count_before[$tag] = Posts::get(array('vocabulary' => array('tags:term' => $tag), 'count' => 'DISTINCT {posts}.id', 'ignore_permissions' => true, 'nolimit' => 1));
     }
     for ($i = 1; $i <= 15; $i++) {
         $post_tags = array();
         for ($j = 0; $j < 5; $j++) {
             if ($i % ($j + 2) == 0) {
                 $post_tags[] = $five_tags[$j];
             }
         }
         $post = Post::create(array('title' => "Test post {$i}", 'content' => count($post_tags) . " tags: " . implode(', ', $post_tags), 'user_id' => $this->user->id, 'status' => Post::status('published'), 'tags' => $post_tags, 'content_type' => Post::type('entry'), 'pubdate' => DateTime::date_create(time())));
         $post->info->testing_tag = 1;
         $post->info->commit();
     }
     /**
      * At this point, these are the posts and their tags:
      *  1 (no tags)
      *  2: mattress
      *  3: freeze
      *  4: mattress, DOG
      *  5: Name
      *  6: mattress, freeze, hash
      *  7 (no tags)
      *  8: mattress, DOG
      *  9: freeze
      * 10: mattress, Name
      * 11 (no tags)
      * 12: mattress, freeze, DOG, hash
      * 13 (no tags)
      * 14: mattress
      * 15: freeze, Name
      */
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n                LEFT JOIN {object_terms} o ON p.id = o.object_id\n\t\t\t\tWHERE o.term_id IN (\n\t\t\t\t\tSELECT id FROM {terms} WHERE term_display = 'DOG'\n\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM vocabularies WHERE name = 'tags' )\n\t\t\t\t)\n\t\t\t");
     // tags:term_display
     $post_count = Posts::get(array('vocabulary' => array('tags:term_display' => 'DOG'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     $post_count = Posts::count_by_tag('DOG', Post::status('published'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Posts::count_by_tag(): {$post_count}");
     // tags:term
     $post_count = Posts::get(array('vocabulary' => array('tags:term' => 'dog'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n                LEFT JOIN {object_terms} o ON p.id = o.object_id\n\t\t\t\tWHERE o.term_id IN (\n\t\t\t\t\tSELECT id FROM {terms} WHERE term = 'name'\n\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM vocabularies WHERE name = 'tags' )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:term' => 'name'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n                LEFT JOIN {object_terms} o ON\n                    p.id = o.object_id\n\t\t\t\tWHERE o.term_id IN (\n\t\t\t\t\tSELECT id FROM {terms} WHERE term in ( 'mattress', 'freeze' )\n\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:term' => array('mattress', 'freeze')), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     // tags:all:term
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id IN (\n\t\t\t\t\tSELECT o1.object_id FROM {object_terms} o1\n\t\t\t\t\t\tLEFT JOIN {object_terms} o2 ON\n\t\t\t\t\t\t\to1.object_id = o2.object_id AND\n\t\t\t\t\t\t\to1.term_id != o2.term_id\n\t\t\t\t\tWHERE\n\t\t\t\t\t\to1.term_id = ( SELECT id FROM {terms} WHERE term = 'mattress'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) ) AND\n\t\t\t\t\t\to2.term_id = ( SELECT id FROM {terms} WHERE term = 'freeze'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $any_count = $post_count;
     $post_count = count(Posts::get(array('vocabulary' => array('tags:all:term' => array('mattress', 'freeze')), 'ignore_permissions' => true, 'nolimit' => 1)));
     $this->assert_not_equal($any_count, $post_count, "Any: {$any_count} All: {$post_count}");
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     // tags:all:term_display
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id IN (\n\t\t\t\t\tSELECT o1.object_id FROM {object_terms} o1\n\t\t\t\t\t\tLEFT JOIN {object_terms} o2 ON\n\t\t\t\t\t\t\to1.object_id = o2.object_id AND\n\t\t\t\t\t\t\to1.term_id != o2.term_id\n\t\t\t\t\tWHERE\n\t\t\t\t\t\to1.term_id = ( SELECT id FROM {terms} WHERE term_display = 'Name'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) ) AND\n\t\t\t\t\t\to2.term_id = ( SELECT id FROM {terms} WHERE term_display = 'DOG'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $any_count = $post_count;
     $post_count = Posts::get(array('vocabulary' => array('tags:all:term' => array('Name', 'DOG')), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_not_equal($any_count, $post_count, "Any: {$any_count} All: {$post_count}");
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     // tags:not:term
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'laser'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:not:term' => 'laser'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'mattress'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t\tAND id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'freeze'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:not:term' => array('mattress', 'freeze')), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'laser'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t\tAND id IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'mattress'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:not:term' => 'laser', 'tags:term' => 'mattress'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     // tags:not:term_display
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term_display = 'DOG'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t\tAND id IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'mattress'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:not:term_display' => 'DOG', 'tags:term' => 'mattress'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term_display = 'DOG'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t\tAND id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'freeze'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t\tAND id IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'mattress'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:not:term_display' => array('DOG', 'freeze'), 'tags:term' => 'mattress'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     // teardown
     Posts::get(array('ignore_permissions' => true, 'has:info' => 'testing_tag', 'nolimit' => 1))->delete();
     foreach ($tags as $tag) {
         Tags::vocabulary()->delete_term($tag);
     }
 }
Пример #24
0
 /**
  * Create a tag and save it.
  *
  * @param array $paramarray An associative array of tag fields
  * @return Tag The new Tag object
  */
 public static function create($paramarray)
 {
     $tag = new Tag($paramarray);
     $tag = Tags::vocabulary()->add_term($tag);
     return $tag;
 }
Пример #25
0
	public function test_get_tag()
	{
		Tags::vocabulary()->add_term( $this->tag );
		// Get tag by text
		$t = Tags::vocabulary()->get_term( $this->text );
		$this->assert_equal( $t->term_display, $this->tag->term_display );
		// Get tag by id
		$t = Tags::vocabulary()->get_term( $t->id );
		$this->assert_equal( $t->term_display, $this->tag->term_display );
		Tags::vocabulary()->delete_term( $t );
	}
    /**
     * Ouputs the default menu in the template footer, and runs the 'hadminstrip' plugin filter.
     * You can add menu items via the filter. See the 'filter_hadminstrip' method for
     * an example.
     */
    public function action_template_footer()
    {
        if (User::identify()->loggedin) {
            ?>
			
			<div id="adminstrip">
				
				<?php 
            $unapprovedcomments = Comments::count_total(Comment::STATUS_UNAPPROVED, FALSE);
            $postnumber = Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('published')));
            $commentnumber = Comments::count_total(Comment::STATUS_APPROVED, FALSE);
            $spamnumber = Comments::count_total(Comment::STATUS_SPAM);
            $tagscount = Tags::vocabulary()->count_total();
            $pagecount = Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('published')));
            ?>
				
				
				<a id="striplink" href="<?php 
            echo URL::get('admin', 'page=dashboard');
            ?>
" title="Visit the Dashboard.."><span id="admin">DASHBOARD</span></a>
				&middot; <a id="striplink" href="<?php 
            echo URL::get('user', 'page=logout');
            ?>
" title="Log out..">Logout</a> 
				&middot; <a id="striplink" href="<?php 
            echo URL::get('admin', 'page=publish');
            ?>
" title="Write an entry..">Write</a> 
				&middot; <a id="striplink" href="<?php 
            echo URL::get('admin', 'page=plugins');
            ?>
" title="Plugins">Plugins</a> 
				&middot; <a id="striplink" href="<?php 
            echo URL::get('admin', 'page=options');
            ?>
" title="Update settings..">Options</a> 
					
				<?php 
            if ($unapprovedcomments != 0) {
                ?>
 &middot; <a id="modcomments" href="<?php 
                echo URL::get('admin', 'page=comments');
                ?>
" title="Unapproved Comments"><?php 
                echo $unapprovedcomments;
                ?>
 moderate</a><?php 
            }
            ?>
				
				<?php 
            if ($spamnumber != 0) {
                ?>
 &middot; <a id="admincomments" href="<?php 
                echo URL::get('admin', 'page=comments');
                ?>
?status=2" title="Spam Comments"><?php 
                echo $spamnumber;
                ?>
 spam</a><?php 
            }
            ?>
				 
				&middot; There are <a id="striplink" href="<?php 
            echo URL::get('admin', 'page=posts&type=' . Post::type('entry'));
            ?>
" title="<?php 
            echo $postnumber;
            ?>
 posts"><?php 
            echo $postnumber;
            ?>
 posts</a>, <a id="striplink" href="<?php 
            echo URL::get('admin', 'page=posts&type=' . Post::type('page'));
            ?>
" title="<?php 
            echo $pagecount;
            ?>
 pages"><?php 
            echo $pagecount;
            ?>
 pages</a> and <a id="striplink" href="<?php 
            echo URL::get('admin', 'page=comments');
            ?>
" title="Comments"><?php 
            echo $commentnumber;
            ?>
 comments</a> within <a id="striplink" href="<?php 
            echo URL::get('admin', 'page=tags');
            ?>
" Tags="Tags"><?php 
            echo $tagscount;
            ?>
 tags</a>
								
				 </div>
				
				
		
		<?php 
        }
    }
Пример #27
0
 /**
  * Get a count of how many times the tag has been used in a post
  * @return integer The number of times the tag has been used
  **/
 public function count($object_type = 'post')
 {
     $term = Tags::vocabulary()->get_term($this->id);
     return count($term->objects($object_type));
 }
Пример #28
0
 public function xmlrpc_metaWeblog__getCategories($params)
 {
     // Authentication
     $user = $this->is_auth($params[1], $params[2]);
     // Fetch all tags from the database
     $tags = Tags::vocabulary()->get_tree('term_display ASC');
     // Create a new array struct for tags
     $structCollection = array();
     foreach ($tags as $tag) {
         $struct = new XMLRPCStruct();
         $struct->description = $tag->term_display;
         $struct->htmlUrl = URL::get('atom_feed_tag', array('tag' => $tag->term));
         $struct->rssUrl = URL::get('display_entries_by_tag', array('tag' => $tag->term));
         $struct->title = $tag->term_display;
         $struct->categoryid = $tag->id;
         $structCollection[] = $struct;
     }
     return $structCollection;
 }
Пример #29
0
	/**
	 * function get_tags
	 * Gets the tags for the post
	 * @return Terms The tags object for this post
	 */
	private function get_tags()
	{
		if ( $this->tags_object == null ) {
			$result = Tags::vocabulary()->get_associations( $this->id );
			if ( $result ) {
				$tags = new Terms($result);
			}
			else {
				$tags = new Terms();
			}
			$this->tags_object = $tags;
		}
		else {
			$tags = $this->tags_object;
		}
		return $tags;

	}
Пример #30
0
    /**
     * Returns an unordered list of all used Tags
     */
    public function theme_show_tags($theme)
    {
        // List of all the tags
        $tags = DB::get_results('
			SELECT t.id AS id, t.term_display AS tag, t.term AS slug
			FROM {terms} t
			LEFT JOIN {object_terms} tp ON t.id=tp.term_id
			INNER JOIN {posts} p ON p.id=tp.object_id AND p.status = ?
			WHERE t.vocabulary_id = ?
			GROUP BY slug
			ORDER BY tag ASC', array(Post::status('published'), Tags::vocabulary()->id));
        $this->taglist = $tags;
        return $theme->fetch('taglist');
    }