当前位置: 首页>>代码示例>>PHP>>正文


PHP Tags::get_one方法代码示例

本文整理汇总了PHP中Tags::get_one方法的典型用法代码示例。如果您正苦于以下问题:PHP Tags::get_one方法的具体用法?PHP Tags::get_one怎么用?PHP Tags::get_one使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tags的用法示例。


在下文中一共展示了Tags::get_one方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: rename

 /**
  * TODO: be more careful
  * INSERT INTO {tag2post} / SELECT $master_tag->ID,post_ID FROM {tag2post} WHERE tag_id = $tag->id" and then "DELETE FROM {tag2post} WHERE tag_id = $tag->id"
  * Renames tags.
  * If the master tag exists, the tags will be merged with it.
  * If not, it will be created first.
  *
  * @param Array tags The tag text, slugs or ids to be renamed
  * @param mixed master The Tag to which they should be renamed, or the slug, text or id of it
  **/
 public static function rename($master, $tags)
 {
     if (!is_array($tags)) {
         $tags = array($tags);
     }
     $tag_names = array();
     // get array of existing tags first to make sure we don't conflict with a new master tag
     foreach ($tags as $tag) {
         $posts = array();
         $post_ids = array();
         $tag = Tags::get_one($tag);
         // get all the post ID's tagged with this tag
         $posts = DB::get_results('SELECT post_id FROM {tag2post} WHERE tag_id = ?', array($tag->id));
         if (count($posts) > 0) {
             // build a list of all the post_id's we need for the new tag
             foreach ($posts as $post) {
                 $post_ids[] = $post->post_id;
             }
             $tag_names[] = $tag->tag;
         }
         Tags::delete($tag);
     }
     // get the master tag
     $master_tag = Tags::get_one($master);
     if (!isset($master_tag->slug)) {
         // it didn't exist, so we assume it's tag text and create it
         $master_tag = Tag::create(array('tag_slug' => Utils::slugify($master), 'tag_text' => $master));
         $master_ids = array();
     } else {
         // get the posts the tag is already on so we don't duplicate them
         $master_posts = DB::get_results('SELECT post_id FROM {tag2post} WHERE tag_id = ?', array($master_tag->id));
         $master_ids = array();
         foreach ($master_posts as $master_post) {
             $master_ids[] = $master_post->post_id;
         }
     }
     if (count($post_ids) > 0) {
         // only try and add the master tag to posts it's not already on
         $post_ids = array_diff($post_ids, $master_ids);
         // link the master tag to each distinct post we removed tags from
         foreach ($post_ids as $post_id) {
             DB::query('INSERT INTO {tag2post} ( tag_id, post_id ) VALUES ( ?, ? )', array($master_tag->id, $post_id));
         }
     }
     EventLog::log(sprintf(_n('Tag %s has been renamed to %s.', 'Tags %s have been renamed to %s.', count($tags)), implode($tag_names, ', '), $master), 'info', 'tag', 'habari');
 }
开发者ID:anupom,项目名称:my-blog,代码行数:56,代码来源:tags.php

示例2: get_by_id

 /**
  * Returns a Tag object based on a supplied ID
  *
  * @param Integer tag_id The ID of the tag to retrieve
  * @return	A Tag object
  */
 public static function get_by_id($tag)
 {
     return Tags::get_one($tag);
 }
开发者ID:psaintlaurent,项目名称:Habari,代码行数:10,代码来源:tags.php

示例3: parse_url_tags

 /**
  * Parse tag parameters from a URL string
  *
  * @param String $tags The URL parameter string
  *
  * @return Array. Associative array of included and excluded tags
  */
 public static function parse_url_tags($tags, $objectify = false)
 {
     $tags = explode(' ', $tags);
     $exclude_tag = array();
     $include_tag = array();
     foreach ($tags as $tag) {
         if (MultiByte::substr($tag, 0, 1) == '-') {
             $tag = MultiByte::substr($tag, 1);
             $exclude_tag[] = $objectify ? Tags::get_one(Utils::slugify($tag)) : Utils::slugify($tag);
         } else {
             $include_tag[] = $objectify ? Tags::get_one(Utils::slugify($tag)) : Utils::slugify($tag);
         }
     }
     return compact('include_tag', 'exclude_tag');
 }
开发者ID:habari,项目名称:system,代码行数:22,代码来源:tags.php

示例4: stage3

    /**
     * Create the UI for stage two of the WP import process
     *
     * This stage kicks off the actual import process.
     *
     * @return string The UI for the second stage of the import process
     */
    private function stage3()
    {
        $valid_fields = array('db_name', 'db_host', 'db_port', 'db_user', 'db_pass', 'db_prefix', 's9y_version', 's9y_root_web', 's9y_input_version', 'category_import', 'comments_ignore_unapproved', 'rewrites_import', 'merge_user', 'merge_user_matched', 'import_user');
        $inputs = $this->get_valid_inputs($valid_fields);
        extract($inputs);
        /* 
         * Cache some local private variables for use in 
         * the import_xxx() private functions 
         */
        $this->comments_ignore_unapproved = $comments_ignore_unapproved;
        $this->category_import = $category_import;
        $this->s9y_db_prefix = $db_prefix;
        $this->port_rewrites = $rewrites_import;
        if ($rewrites_import) {
            // atom feed link:
            $rew_url = URL::get('atom_feed', array('index' => 1), true, false, false);
            $rewrite = new RewriteRule(array('name' => 'from_s9yimporter_atom_feed', 'parse_regex' => '%^feeds/atom(?P<r>.*)$%i', 'build_str' => $rew_url . '(/{$p})', 'handler' => 'actionHandler', 'action' => 'redirect', 'priority' => 1, 'is_active' => 1, 'rule_class' => RewriteRule::RULE_CUSTOM, 'description' => 'redirects s9y atom feed to habari feed'));
            $rewrite->insert();
            // rss feed link:
            $rew_url = Plugins::is_loaded('RSS 2.0') ? URL::get('rss_feed', array('index' => 1), true, false, false) : URL::get('atom_feed', array('index' => 1), true, false, false);
            $rewrite = new RewriteRule(array('name' => 'from_s9yimporter_rss_feed', 'parse_regex' => '%^feeds/index.rss(?P<r>.*)$%i', 'build_str' => $rew_url . '(/{$p})', 'handler' => 'actionHandler', 'action' => 'redirect', 'priority' => 1, 'is_active' => 1, 'rule_class' => RewriteRule::RULE_CUSTOM, 'description' => 'redirects s9y rss feed to habari feed'));
            $rewrite->insert();
            // comments feed link:
            $rew_url = Plugins::is_loaded('RSS 2.0') ? URL::get('rss_feed_comments', array(), true, false, false) : URL::get('atom_feed_comments', array(), true, false, false);
            $rewrite = new RewriteRule(array('name' => 'from_s9yimporter_comments_feed', 'parse_regex' => '%^feeds/comments.rss(?P<r>.*)$%i', 'build_str' => $rew_url . '(/{$p})', 'handler' => 'actionHandler', 'action' => 'redirect', 'priority' => 1, 'is_active' => 1, 'rule_class' => RewriteRule::RULE_CUSTOM, 'description' => 'redirects s9y rss feed to habari feed'));
            $rewrite->insert();
        }
        if (FALSE !== ($this->s9ydb = $this->s9y_connect($db_host, $db_name, $db_user, $db_pass, $db_prefix, $db_port))) {
            /*
             * First step is to go through our import_user and
             * merge_user arrays and see if we need to merge the
             * incoming authoring user with an existing user in 
             * Habari, ignore the user, or create a new Habari user.
             *
             * $import_user= array( [imported_user_id] => [1 | null], [next_imported_user_id] => [1 | null], ...)
             * $merge_user= array( [imported_user_id] => [habari_user_id | "__new_user"], ...)
             */
            $users = array();
            foreach ($import_user as $import_user_id => $import_this) {
                /* Is this s9y user selected for import? */
                if ($import_this != 1) {
                    continue;
                }
                $users[$import_user_id] = array('imported_user_id' => $import_user_id);
                /* Was there a direct match for this imported user? */
                if (in_array($import_user_id, array_keys($merge_user_matched))) {
                    $users[$import_user_id]['habari_user_id'] = $merge_user_matched[$import_user_id];
                }
                /* Is this s9y user manually selected to merge with a habari user? */
                if (isset($merge_user) && in_array($import_user_id, array_keys($merge_user))) {
                    if ($merge_user[$import_user_id] != '__new_user') {
                        $users[$import_user_id]['habari_user_id'] = $merge_user[$import_user_id];
                    }
                }
            }
            echo "Starting import transaction.<br />";
            $this->s9ydb->begin_transaction();
            if ($category_import) {
                /*
                 * If we are importing the categories as taxonomy, 
                 * let's go ahead and import the base category tags
                 * now, and during the post import, we'll attach
                 * the category tag to the relevant posts.
                 *
                 * mysql> desc s9y_category;
                 * +----------------------+--------------+------+-----+---------+----------------+
                 * | Field                | Type         | Null | Key | Default | Extra          |
                 * +----------------------+--------------+------+-----+---------+----------------+
                 * | categoryid           | int(11)      |      | PRI | NULL    | auto_increment |
                 * | category_name        | varchar(255) | YES  |     | NULL    |                |
                 * | category_icon        | varchar(255) | YES  |     | NULL    |                |
                 * | category_description | text         | YES  |     | NULL    |                |
                 * | authorid             | int(11)      | YES  | MUL | NULL    |                |
                 * | category_left        | int(11)      | YES  | MUL | 0       |                |
                 * | category_right       | int(11)      | YES  |     | 0       |                |
                 * | parentid             | int(11)      |      | MUL | 0       |                |
                 * +----------------------+--------------+------+-----+---------+----------------+
                 */
                $sql = <<<ENDOFSQL
SELECT categoryid, category_name
FROM `{$db_prefix}category
ENDOFSQL;
                if (FALSE !== ($imported_categories = $this->s9ydb->get_results($sql, array(), 'QueryRecord'))) {
                    $num_categories_imported = 0;
                    foreach ($imported_categories as $imported_category) {
                        if ($tag_check = Tags::get_one($imported_category->category_name)) {
                            // tag already exists
                            $this->imported_categories[$imported_category->categoryid] = $tag_check->id;
                            $this->imported_category_names[$imported_category->categoryid] = $imported_category->category_name;
                            ++$num_categories_imported;
                            continue;
                        }
                        if ($new_tag = Tag::create(array('tag_text' => $imported_category->category_name))) {
//.........这里部分代码省略.........
开发者ID:habari-extras,项目名称:s9yimport,代码行数:101,代码来源:s9yimport.plugin.php


注:本文中的Tags::get_one方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。