• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP tag_normalize函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中tag_normalize函数的典型用法代码示例。如果您正苦于以下问题:PHP tag_normalize函数的具体用法?PHP tag_normalize怎么用?PHP tag_normalize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: smarty_function_mttagname

function smarty_function_mttagname($args, &$ctx)
{
    $tag = $ctx->stash('Tag');
    if (!$tag) {
        return '';
    }
    if (is_array($tag)) {
        $tag_name = $tag['tag_name'];
    } else {
        $tag_name = $tag;
    }
    if ($args['quote'] && preg_match('/ /', $tag_name)) {
        $tag_name = '"' . $tag_name . '"';
    } elseif ($args['normalize']) {
        require_once "MTUtil.php";
        $tag_name = tag_normalize($tag_name);
    }
    return $tag_name;
}
开发者ID:benvanstaveren,项目名称:melody,代码行数:19,代码来源:function.mttagname.php


示例2: tag_print_search_results

/**
 * Prints the tag search results
 *
 * @param string $query text that tag names will be matched against
 * @param int $page current page
 * @param int $perpage nr of users displayed per page
 * @param $return if true return html string
 */
function tag_print_search_results($query, $page, $perpage, $return = false)
{
    global $CFG, $USER;
    $query = array_shift(tag_normalize($query, TAG_CASE_ORIGINAL));
    $count = sizeof(tag_find_tags($query, false));
    $tags = array();
    if ($found_tags = tag_find_tags($query, true, $page * $perpage, $perpage)) {
        $tags = array_values($found_tags);
    }
    $baseurl = $CFG->wwwroot . '/tag/search.php?query=' . rawurlencode($query);
    $output = '';
    // link "Add $query to my interests"
    $addtaglink = '';
    if (!tag_record_tagged_with('user', $USER->id, $query)) {
        $addtaglink = '<a href="' . $CFG->wwwroot . '/tag/user.php?action=addinterest&amp;sesskey=' . sesskey() . '&amp;tag=' . rawurlencode($query) . '">';
        $addtaglink .= get_string('addtagtomyinterests', 'tag', htmlspecialchars($query)) . '</a>';
    }
    if (!empty($tags)) {
        // there are results to display!!
        $output .= print_heading(get_string('searchresultsfor', 'tag', htmlspecialchars($query)) . " : {$count}", '', 3, 'main', true);
        //print a link "Add $query to my interests"
        if (!empty($addtaglink)) {
            $output .= print_box($addtaglink, 'box', 'tag-management-box', true);
        }
        $nr_of_lis_per_ul = 6;
        $nr_of_uls = ceil(sizeof($tags) / $nr_of_lis_per_ul);
        $output .= '<ul id="tag-search-results">';
        for ($i = 0; $i < $nr_of_uls; $i++) {
            $output .= '<li>';
            foreach (array_slice($tags, $i * $nr_of_lis_per_ul, $nr_of_lis_per_ul) as $tag) {
                $tag_link = ' <a href="' . $CFG->wwwroot . '/tag/index.php?id=' . $tag->id . '">' . tag_display_name($tag) . '</a>';
                $output .= '&#8226;' . $tag_link . '<br/>';
            }
            $output .= '</li>';
        }
        $output .= '</ul>';
        $output .= '<div>&nbsp;</div>';
        // <-- small layout hack in order to look good in Firefox
        $output .= print_paging_bar($count, $page, $perpage, $baseurl . '&amp;', 'page', false, true);
    } else {
        //no results were found!!
        $output .= print_heading(get_string('noresultsfor', 'tag', htmlspecialchars($query)), '', 3, 'main', true);
        //print a link "Add $query to my interests"
        if (!empty($addtaglink)) {
            $output .= print_box($addtaglink, 'box', 'tag-management-box', true);
        }
    }
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:61,代码来源:locallib.php


示例3: tag_find_tags

/**
 * Search for tags with names that match some text
 *
 * @param string $text escaped string that the tag names will be matched against
 * @param boolean $ordered If true, tags are ordered by their popularity. If false, no ordering.
 * @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
 * @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
 * @return mixed an array of objects, or false if no records were found or an error occured.
 */
function tag_find_tags($text, $ordered = true, $limitfrom = '', $limitnum = '')
{
    global $CFG;
    $text = array_shift(tag_normalize($text, TAG_CASE_LOWER));
    if ($ordered) {
        $query = "SELECT tg.id, tg.name, tg.rawname, COUNT(ti.id) AS count " . "FROM {$CFG->prefix}tag tg LEFT JOIN {$CFG->prefix}tag_instance ti ON tg.id = ti.tagid " . "WHERE tg.name LIKE '%{$text}%' " . "GROUP BY tg.id, tg.name, tg.rawname " . "ORDER BY count DESC";
    } else {
        $query = "SELECT tg.id, tg.name, tg.rawname " . "FROM {$CFG->prefix}tag tg " . "WHERE tg.name LIKE '%{$text}%'";
    }
    return get_records_sql($query, $limitfrom, $limitnum);
}
开发者ID:r007,项目名称:PMoodle,代码行数:20,代码来源:lib.php


示例4: tag_type_set

$tagform->set_data($tag);
// If new data has been sent, update the tag record
if ($tagnew = $tagform->get_data()) {
    if (has_capability('moodle/tag:manage', $systemcontext)) {
        if ($tag->tagtype != 'default' && (!isset($tagnew->tagtype) || $tagnew->tagtype != '1')) {
            tag_type_set($tag->id, 'default');
        } elseif ($tag->tagtype != 'official' && $tagnew->tagtype == '1') {
            tag_type_set($tag->id, 'official');
        }
    }
    if (!has_capability('moodle/tag:manage', $systemcontext)) {
        unset($tagnew->name);
        unset($tagnew->rawname);
    } else {
        // They might be trying to change the rawname, make sure it's a change that doesn't affect name
        $norm = tag_normalize($tagnew->rawname, TAG_CASE_LOWER);
        $tagnew->name = array_shift($norm);
        if ($tag->name != $tagnew->name) {
            // The name has changed, let's make sure it's not another existing tag
            if (tag_get_id($tagnew->name)) {
                // Something exists already, so flag an error
                $errorstring = s($tagnew->rawname) . ': ' . get_string('namesalreadybeeingused', 'tag');
            }
        }
    }
    if (empty($errorstring)) {
        // All is OK, let's save it
        $tagnew = file_postupdate_standard_editor($tagnew, 'description', $editoroptions, $systemcontext, 'tag', 'description', $tag->id);
        tag_description_set($tag_id, $tagnew->description, $tagnew->descriptionformat);
        $tagnew->timemodified = time();
        if (has_capability('moodle/tag:manage', $systemcontext)) {
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:31,代码来源:edit.php


示例5: test_normalize

 public function test_normalize()
 {
     $tagset = array('Cat', ' Dog  ', '<Mouse', '<>', 'mouse', 'Dog');
     // Test function tag_normalize() that was deprecated in 3.1.
     $this->assertEquals(array('Cat' => 'Cat', 'Dog' => 'Dog', '<Mouse' => 'Mouse', '<>' => '', 'mouse' => 'mouse'), tag_normalize($tagset, TAG_CASE_ORIGINAL));
     $this->assertDebuggingCalled();
     $this->assertEquals(array('Cat' => 'cat', 'Dog' => 'dog', '<Mouse' => 'mouse', '<>' => '', 'mouse' => 'mouse'), tag_normalize($tagset, TAG_CASE_LOWER));
     $this->assertDebuggingCalled();
     // Test replacement function core_tag_tag::normalize().
     $this->assertEquals(array('Cat' => 'Cat', 'Dog' => 'Dog', '<Mouse' => 'Mouse', '<>' => '', 'mouse' => 'mouse'), core_tag_tag::normalize($tagset, false));
     $this->assertEquals(array('Cat' => 'cat', 'Dog' => 'dog', '<Mouse' => 'mouse', '<>' => '', 'mouse' => 'mouse'), core_tag_tag::normalize($tagset, true));
 }
开发者ID:bewanyk,项目名称:moodle,代码行数:12,代码来源:taglib_test.php


示例6: tag_type_set

$tagform->set_data($tag);
// If new data has been sent, update the tag record
if ($tagnew = $tagform->get_data()) {
    if (has_capability('moodle/tag:manage', $systemcontext)) {
        if ($tag->tagtype != 'default' && (!isset($tagnew->tagtype) || $tagnew->tagtype != '1')) {
            tag_type_set($tag->id, 'default');
        } elseif ($tag->tagtype != 'official' && $tagnew->tagtype == '1') {
            tag_type_set($tag->id, 'official');
        }
    }
    if (!has_capability('moodle/tag:manage', $systemcontext) && !has_capability('moodle/tag:edit', $systemcontext)) {
        unset($tagnew->name);
        unset($tagnew->rawname);
    } else {
        // They might be trying to change the rawname, make sure it's a change that doesn't affect name
        $tagnew->name = array_shift(tag_normalize($tagnew->rawname, TAG_CASE_LOWER));
        if ($tag->name != $tagnew->name) {
            // The name has changed, let's make sure it's not another existing tag
            if (tag_get_id($tagnew->name)) {
                // Something exists already, so flag an error
                $errorstring = s($tagnew->rawname) . ': ' . get_string('namesalreadybeeingused', 'tag');
            }
        }
    }
    if (empty($errorstring)) {
        // All is OK, let's save it
        $tagnew = file_postupdate_standard_editor($tagnew, 'description', $editoroptions, $systemcontext, 'tag', 'description', $tag->id);
        tag_description_set($tag_id, $tagnew->description, $tagnew->descriptionformat);
        $tagnew->timemodified = time();
        if (has_capability('moodle/tag:manage', $systemcontext)) {
            // rename tag
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:31,代码来源:edit.php


示例7: tag_find_tags

/**
 * Search for tags with names that match some text
 *
 * @param string $text escaped string that the tag names will be matched against
 * @param boolean $ordered If true, tags are ordered by their popularity. If false, no ordering.
 * @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
 * @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
 * @return mixed an array of objects, or false if no records were found or an error occured.
 */
function tag_find_tags($text, $ordered = true, $limitfrom = '', $limitnum = '')
{
    global $DB;
    $text = array_shift(tag_normalize($text, TAG_CASE_LOWER));
    if ($ordered) {
        $query = "SELECT tg.id, tg.name, tg.rawname, COUNT(ti.id) AS count\n                    FROM {tag} tg LEFT JOIN {tag_instance} ti ON tg.id = ti.tagid\n                   WHERE tg.name LIKE ?\n                GROUP BY tg.id, tg.name, tg.rawname\n                ORDER BY count DESC";
    } else {
        $query = "SELECT tg.id, tg.name, tg.rawname\n                    FROM {tag} tg\n                   WHERE tg.name LIKE ?";
    }
    $params = array("%{$text}%");
    return $DB->get_records_sql($query, $params, $limitfrom, $limitnum);
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:21,代码来源:lib.php


示例8: optional_param

require_once '../tag/lib.php';
$action = optional_param('action', '', PARAM_ALPHA);
require_login();
if (empty($CFG->usetags)) {
    error('Tags are disabled!');
}
if (isguestuser()) {
    print_error('noguest');
}
if (!confirm_sesskey()) {
    print_error('sesskey');
}
switch ($action) {
    case 'addinterest':
        $id = optional_param('id', 0, PARAM_INT);
        $name = optional_param('name', '', PARAM_TEXT);
        if (empty($name) && $id) {
            $name = tag_name($id);
        }
        tag_an_item('user', $USER->id, $name);
        if (!empty($name) && !$id) {
            $id = tag_id(tag_normalize($name));
        }
        redirect($CFG->wwwroot . '/tag/index.php?id=' . $id);
        break;
    case 'flaginappropriate':
        $id = required_param('id', PARAM_INT);
        tag_flag_inappropriate($id);
        redirect($CFG->wwwroot . '/tag/index.php?id=' . $id, get_string('responsiblewillbenotified', 'tag'));
        break;
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:31,代码来源:tag.php


示例9: tag_split_delim

function tag_split_delim($delim, $str)
{
    $delim = quotemeta($delim);
    $tags = array();
    $str = trim($str);
    while (strlen($str) && preg_match("/^(((['\"])(.*?)[^{$delim}]*?|.*?)({$delim}\\s*|\$))/s", $str, $match)) {
        $str = substr($str, strlen($match[1]));
        $tag = isset($match[4]) && $match[4] != '' ? $match[4] : $match[2];
        $tag = trim($tag);
        $tag = preg_replace('/\\s+/', ' ', $tag);
        $n8d_tag = tag_normalize($tag);
        if ($n8d_tag != '') {
            if ($tag != '') {
                $tags[] = $tag;
            }
        }
    }
    return $tags;
}
开发者ID:kjacobs,项目名称:oneocean_blog,代码行数:19,代码来源:MTUtil.php


示例10: set_group_tags

 /**
  * Sets 'Set' tags for groups for the forum.
  * Necessary to use this rather than core tag lib as that does not deal with context
  * and as group item ids can be the same that is an issue
  * Also can only have 1 unique group/tag/user record
  * @param int $forumid forum table id
  * @param int $groupid groups table id
  * @param array $tags array of tag rawnames e.g. Fish, frog
  */
 public static function set_group_tags($forumid, $groupid, $tags)
 {
     global $DB, $CFG, $USER;
     require_once $CFG->dirroot . '/tag/lib.php';
     $forum = self::get_from_id($forumid, self::CLONE_DIRECT);
     $context = $forum->get_context(true);
     $transaction = $DB->start_delegated_transaction();
     // Get existing tags used.
     $settags = array();
     $taginstances = $DB->get_records_sql("\n                SELECT DISTINCT t.*, ti.id as instanceid\n                  FROM {tag} t\n            INNER JOIN {tag_instance} ti\n               ON t.id = ti.tagid\n                 WHERE ti.component = ? AND ti.itemtype = ? AND ti.contextid = ? AND ti.itemid = ?", array('mod_forumng', 'groups', $context->id, $groupid));
     // Delete instances any not in new tags (note tag records not deleted as cleaned in cron).
     $tistodelete = array();
     foreach ($taginstances as $tinstance) {
         if (!in_array($tinstance->rawname, $tags)) {
             $tistodelete[] = $tinstance->instanceid;
         } else {
             // Store existing tag instance used.
             $settags[$tinstance->instanceid] = $tinstance->rawname;
         }
     }
     if ($tistodelete) {
         list($delsql, $delparams) = $DB->get_in_or_equal($tistodelete);
         $DB->delete_records_select('tag_instance', "id {$delsql}", $delparams);
     }
     // Add/get new tag records.
     $existingtags = tag_get_id($tags, TAG_RETURN_ARRAY);
     // Normalize tags passed so can match to existing tags array.
     $normaltags = tag_normalize($tags);
     // Add tag instances (where needed).
     $ordering = 0;
     foreach ($normaltags as $rawname => $name) {
         if (in_array($rawname, $settags)) {
             // Pre-existing instance, skip.
             $ordering++;
             continue;
         }
         $tagid = 0;
         if (!array_key_exists($name, $existingtags) || empty($existingtags[$name])) {
             // Need to add tag.
             $newtag = tag_add($rawname);
             $tagid = array_pop($newtag);
         } else {
             $tagid = $existingtags[$name];
         }
         // Create instance (like tag_assign()).
         $tag_instance_object = new stdClass();
         $tag_instance_object->tagid = $tagid;
         $tag_instance_object->component = 'mod_forumng';
         $tag_instance_object->itemid = $groupid;
         $tag_instance_object->itemtype = 'groups';
         $tag_instance_object->contextid = $context->id;
         $tag_instance_object->ordering = $ordering;
         $tag_instance_object->timecreated = time();
         $tag_instance_object->timemodified = $tag_instance_object->timecreated;
         $tag_instance_object->tiuserid = self::get_group_taginstance_userid($groupid, $tagid);
         $DB->insert_record('tag_instance', $tag_instance_object);
         $ordering++;
     }
     $DB->commit_delegated_transaction($transaction);
 }
开发者ID:ULCC-QMUL,项目名称:moodle-mod_forumng,代码行数:69,代码来源:mod_forumng.php


示例11: redirect

        redirect(new moodle_url($PAGE->url, array('notice' => 'resetflag')));
        break;
    case 'changetype':
        require_sesskey();
        if ($tagtype === 'official' || $tagtype === 'default') {
            if (tag_type_set($tagid, $tagtype)) {
                redirect(new moodle_url($PAGE->url, array('notice' => 'typechanged')));
            }
        }
        redirect($PAGE->url);
        break;
    case 'addofficialtag':
        require_sesskey();
        $otagsadd = optional_param('otagsadd', '', PARAM_RAW);
        $newtags = preg_split('/\\s*,\\s*/', trim($otagsadd), -1, PREG_SPLIT_NO_EMPTY);
        $newtags = array_filter(tag_normalize($newtags, TAG_CASE_ORIGINAL));
        if (!$newtags) {
            redirect($PAGE->url);
        }
        foreach ($newtags as $newotag) {
            if ($newotagid = tag_get_id($newotag)) {
                // Tag exists, change the type.
                tag_type_set($newotagid, 'official');
            } else {
                tag_add($newotag, 'official');
            }
        }
        redirect(new moodle_url($PAGE->url, array('notice' => 'added')));
        break;
}
echo $OUTPUT->header();
开发者ID:alanaipe2015,项目名称:moodle,代码行数:31,代码来源:manage.php


示例12: tag_find_tags

/**
 * Search for tags with names that match some text
 *
 * @param string $text escaped string that the tag names will be matched against
 * @param boolean $ordered If true, tags are ordered by their popularity. If false, no ordering.
 * @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
 * @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
 * @return mixed an array of objects, or false if no records were found or an error occured.
 */
function tag_find_tags($text, $ordered = true, $limitfrom = '', $limitnum = '')
{
    global $CFG;
    $text = addslashes(array_shift(tag_normalize($text, TAG_CASE_LOWER)));
    if ($ordered) {
        $query = "SELECT tg.id, tg.name, tg.rawname, ti.itemtype, ti.itemid, COUNT(ti.id) AS count " . "FROM {$CFG->prefix}tag tg LEFT JOIN {$CFG->prefix}tag_instance ti ON tg.id = ti.tagid " . "WHERE tg.name LIKE '%{$text}%' " . "GROUP BY tg.id, tg.name, tg.rawname " . "ORDER BY count DESC";
    } else {
        $query = "SELECT tg.id, tg.name, tg.rawname " . "FROM {$CFG->prefix}tag tg " . "WHERE tg.name LIKE '%{$text}%'";
    }
    //funky TAO hack to prevent no published LPS from disp(laying.
    $tags = get_records_sql($query, $limitfrom, $limitnum);
    $tags = tao_filter_tags($tags);
    return $tags;
}
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:23,代码来源:lib.php


示例13: tag_update_name

/**
 * Function that updates tags names.
 * Updates only if the new name suggested for a tag doesn´t exist already.
 *
 * @param Array $tags_names_changed array of new tag names indexed by tag ids.
 * @return Array array of tags names that were effectively updated, indexed by tag ids.
 */
function tag_update_name($tags_names_changed)
{
    $tags_names_updated = array();
    foreach ($tags_names_changed as $id => $newname) {
        $norm_newname = tag_normalize($newname);
        if (!tag_exists($norm_newname) && is_tag_name_valid($norm_newname)) {
            $tag = tag_by_id($id);
            $tags_names_updated[$id] = $tag->name;
            // rawname keeps the original casing of the string
            $tag->rawname = tag_normalize($newname, false);
            // name lowercases the string
            $tag->name = $norm_newname;
            $tag->timemodified = time();
            update_record('tag', $tag);
        }
    }
    return $tags_names_updated;
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:25,代码来源:lib.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP tag_rename函数代码示例发布时间:2022-05-23
下一篇:
PHP tag_get_tags_ids函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap