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

PHP tag_get_related_tags函数代码示例

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

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



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

示例1: get_content

 function get_content()
 {
     global $CFG, $USER;
     //note: do NOT include files at the top of this file
     require_once $CFG->dirroot . '/tag/lib.php';
     require_once $CFG->libdir . '/filelib.php';
     if ($this->content !== NULL) {
         return $this->content;
     }
     $tagid = optional_param('id', 0, PARAM_INT);
     // tag id - for backware compatibility
     $tag = optional_param('tag', '', PARAM_TAG);
     // tag
     if ($tag) {
         $tagobject = tag_get('name', $tag);
     } else {
         if ($tagid) {
             $tagobject = tag_get('id', $tagid);
         }
     }
     if (empty($tagobject)) {
         $this->content = new stdClass();
         $this->content->text = '';
         $this->content->footer = '';
         return $this->content;
     }
     //include related tags in the photo query ?
     $tagscsv = $tagobject->name;
     if (!empty($this->config->includerelatedtags)) {
         $tagscsv .= ',' . tag_get_related_tags_csv(tag_get_related_tags($tagobject->id), TAG_RETURN_TEXT);
     }
     $tagscsv = urlencode($tagscsv);
     //number of photos to display
     $numberofphotos = DEFAULT_NUMBER_OF_PHOTOS;
     if (!empty($this->config->numberofphotos)) {
         $numberofphotos = $this->config->numberofphotos;
     }
     //sort search results by
     $sortby = 'relevance';
     if (!empty($this->config->sortby)) {
         $sortby = $this->config->sortby;
     }
     //pull photos from a specific photoset
     if (!empty($this->config->photoset)) {
         $request = 'http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos';
         $request .= '&api_key=' . FLICKR_DEV_KEY;
         $request .= '&photoset_id=' . $this->config->photoset;
         $request .= '&per_page=' . $numberofphotos;
         $request .= '&format=php_serial';
         $response = $this->fetch_request($request);
         $search = unserialize($response);
         foreach ($search['photoset']['photo'] as $p) {
             $p['owner'] = $search['photoset']['owner'];
         }
         $photos = array_values($search['photoset']['photo']);
     } else {
         $request = 'http://api.flickr.com/services/rest/?method=flickr.photos.search';
         $request .= '&api_key=' . FLICKR_DEV_KEY;
         $request .= '&tags=' . $tagscsv;
         $request .= '&per_page=' . $numberofphotos;
         $request .= '&sort=' . $sortby;
         $request .= '&format=php_serial';
         $response = $this->fetch_request($request);
         $search = unserialize($response);
         $photos = array_values($search['photos']['photo']);
     }
     if (strcmp($search['stat'], 'ok') != 0) {
         return;
     }
     //if no results were returned, exit...
     //Accessibility: render the list of photos
     $text = '<ul class="inline-list">';
     foreach ($photos as $photo) {
         $text .= '<li><a href="http://www.flickr.com/photos/' . $photo['owner'] . '/' . $photo['id'] . '/" title="' . s($photo['title']) . '">';
         $text .= '<img alt="' . s($photo['title']) . '" class="flickr-photos" src="' . $this->build_photo_url($photo, 'square') . "\" /></a></li>\n";
     }
     $text .= "</ul>\n";
     $this->content = new stdClass();
     $this->content->text = $text;
     $this->content->footer = '';
     return $this->content;
 }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:82,代码来源:block_tag_flickr.php


示例2: tag_print_description_box

/**
 * Prints a box with the description of a tag and its related tags
 *
 * @param unknown_type $tag_object
 * @param $return if true return html string
 */
function tag_print_description_box($tag_object, $return = false)
{
    global $USER, $CFG;
    $max_tags_displayed = 10;
    // todo: turn this into a system setting
    $tagname = tag_display_name($tag_object);
    $related_tags = tag_get_related_tags($tag_object->id, TAG_RELATED_ALL, $max_tags_displayed + 1);
    // this gets one more than we want
    $content = !empty($tag_object->description) || $related_tags;
    $output = '';
    if ($content) {
        $output .= print_box_start('generalbox', 'tag-description', true);
    }
    if (!empty($tag_object->description)) {
        $options = new object();
        $options->para = false;
        $output .= format_text($tag_object->description, $tag_object->descriptionformat, $options);
    }
    if ($related_tags) {
        $more_links = false;
        if (count($related_tags) > $max_tags_displayed) {
            array_pop($related_tags);
            $more_links = true;
        }
        $output .= '<br /><br /><strong>' . get_string('relatedtags', 'tag') . ': </strong>' . tag_get_related_tags_csv($related_tags);
        if ($more_links) {
            $output .= ' ...';
        }
    }
    if ($content) {
        $output .= print_box_end(true);
    }
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:44,代码来源:locallib.php


示例3: tag_print_description_box

/**
 * Prints a box with the description of a tag and its related tags
 *
 * @package core_tag
 * @access  public
 * @todo    MDL-31149 create a system setting for $max_tags_displayed, instead of using an in code literal
 * @param   stdClass    $tag_object
 * @param   bool        $return     if true the function will return the generated tag cloud instead of displaying it.
 * @return  string/null a HTML box showing a description of the tag object and it's relationsips or null if output is done directly
 *                      in the function.
 */
function tag_print_description_box($tag_object, $return = false)
{
    global $USER, $CFG, $OUTPUT;
    $max_tags_displayed = 10;
    $tagname = tag_display_name($tag_object);
    $related_tags = tag_get_related_tags($tag_object->id, TAG_RELATED_ALL, $max_tags_displayed + 1);
    // this gets one more than we want
    $content = !empty($tag_object->description) || $related_tags;
    $output = '';
    if ($content) {
        $output .= $OUTPUT->box_start('generalbox', 'tag-description');
    }
    if (!empty($tag_object->description)) {
        $options = new stdClass();
        $options->para = false;
        $options->overflowdiv = true;
        $tag_object->description = file_rewrite_pluginfile_urls($tag_object->description, 'pluginfile.php', get_context_instance(CONTEXT_SYSTEM)->id, 'tag', 'description', $tag_object->id);
        $output .= format_text($tag_object->description, $tag_object->descriptionformat, $options);
    }
    if ($related_tags) {
        $more_links = false;
        if (count($related_tags) > $max_tags_displayed) {
            array_pop($related_tags);
            $more_links = true;
        }
        $output .= '<br /><br /><strong>' . get_string('relatedtags', 'tag') . ': </strong>' . tag_get_related_tags_csv($related_tags);
        if ($more_links) {
            $output .= ' ...';
        }
    }
    if ($content) {
        $output .= $OUTPUT->box_end();
    }
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:50,代码来源:locallib.php


示例4: tag_get

} else {
    if ($tag_id) {
        $tag = tag_get('id', $tag_id, '*');
    }
}
if (empty($tag)) {
    redirect($CFG->wwwroot . '/tag/search.php');
}
$PAGE->set_url('/tag/index.php', array('id' => $tag->id));
$PAGE->set_subpage($tag->id);
$PAGE->set_context($systemcontext);
$PAGE->set_blocks_editing_capability('moodle/tag:editblocks');
$PAGE->set_pagelayout('base');
$tagname = tag_display_name($tag);
// set the relatedtags field of the $tag object that will be passed to the form
$tag->relatedtags = tag_get_related_tags_csv(tag_get_related_tags($tag->id, TAG_RELATED_MANUAL), TAG_RETURN_TEXT);
$options = new stdClass();
$options->smiley = false;
$options->filter = false;
// convert and remove any XSS
$tag->description = format_text($tag->description, $tag->descriptionformat, $options);
$tag->descriptionformat = FORMAT_HTML;
$errorstring = '';
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'trusttext' => false, 'context' => $systemcontext, 'subdirs' => file_area_contains_subdirs($systemcontext, 'tag', 'description', $tag->id));
$tag = file_prepare_standard_editor($tag, 'description', $editoroptions, $systemcontext, 'tag', 'description', $tag->id);
$tagform = new tag_edit_form(null, compact('editoroptions'));
if ($tag->tagtype == 'official') {
    $tag->tagtype = '1';
} else {
    $tag->tagtype = '0';
}
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:31,代码来源:edit.php


示例5: test_move_tags_with_related

 public function test_move_tags_with_related()
 {
     global $DB;
     list($collid1, $collid2, $user1, $user2, $blogpost) = $this->prepare_move_tags();
     // Set Tag1 to be related to Tag2 and Tag4 (in collection 1).
     core_tag_tag::get_by_name($collid1, 'Tag1')->set_related_tags(array('Tag2', 'Tag4'));
     // Set collection for 'post' tag area to be collection 2 and add some tags there.
     $tagareablog = $DB->get_record('tag_area', array('itemtype' => 'post', 'component' => 'core'));
     core_tag_area::update($tagareablog, array('tagcollid' => $collid2));
     core_tag_tag::set_item_tags('core', 'post', $blogpost->id, context_system::instance(), array('TAG1', 'Tag3'));
     // Move 'user' area from collection 1 to collection 2, make sure tags were moved completely.
     $tagarea = $DB->get_record('tag_area', array('itemtype' => 'user', 'component' => 'core'));
     core_tag_area::update($tagarea, array('tagcollid' => $collid2));
     $this->assertEquals(array('Tag1', 'Tag2', 'Tag4'), $DB->get_fieldset_select('tag', 'rawname', 'tagcollid = ? ORDER BY name', array($collid1)));
     $this->assertEquals(array('TAG1', 'Tag2', 'Tag3', 'Tag4', 'Tag5'), $DB->get_fieldset_select('tag', 'rawname', 'tagcollid = ? ORDER BY name', array($collid2)));
     $this->assertEquals(array('TAG1', 'Tag2'), array_values(core_tag_tag::get_item_tags_array('core', 'user', $user1->id)));
     $this->assertEquals(array('Tag2', 'Tag3'), array_values(core_tag_tag::get_item_tags_array('core', 'user', $user2->id)));
     $tag11 = core_tag_tag::get_by_name($collid1, 'Tag1');
     $related11 = tag_get_related_tags($tag11->id, TAG_RELATED_MANUAL);
     $this->assertDebuggingCalled();
     $related11 = array_map('core_tag_tag::make_display_name', $related11);
     sort($related11);
     // Order of related tags may be random.
     $this->assertEquals('Tag2, Tag4', join(', ', $related11));
     $tag21 = core_tag_tag::get_by_name($collid2, 'TAG1');
     $related21 = tag_get_related_tags($tag21->id, TAG_RELATED_MANUAL);
     $this->assertDebuggingCalled();
     $related21 = array_map('core_tag_tag::make_display_name', $related21);
     sort($related21);
     // Order of related tags may be random.
     $this->assertEquals('Tag2, Tag4', join(', ', $related21));
 }
开发者ID:bewanyk,项目名称:moodle,代码行数:32,代码来源:taglib_test.php


示例6: test_correlations

 /**
  * Test for function tag_compute_correlations() that is part of tag cron
  */
 public function test_correlations()
 {
     global $DB;
     $user = $this->getDataGenerator()->create_user();
     $this->setUser($user);
     $user1 = $this->getDataGenerator()->create_user();
     $user2 = $this->getDataGenerator()->create_user();
     $user3 = $this->getDataGenerator()->create_user();
     $user4 = $this->getDataGenerator()->create_user();
     $user5 = $this->getDataGenerator()->create_user();
     $user6 = $this->getDataGenerator()->create_user();
     // Several records have both 'cat' and 'cats' tags attached to them.
     // This will make those tags automatically correlated.
     // Same with 'dog', 'dogs' and 'puppy.
     tag_set('user', $user1->id, array('cat', 'cats'), 'core', context_user::instance($user1->id)->id);
     tag_set('user', $user2->id, array('cat', 'cats', 'kitten'), 'core', context_user::instance($user2->id)->id);
     tag_set('user', $user3->id, array('cat', 'cats'), 'core', context_user::instance($user3->id)->id);
     tag_set('user', $user4->id, array('dog', 'dogs', 'puppy'), 'core', context_user::instance($user4->id)->id);
     tag_set('user', $user5->id, array('dog', 'dogs', 'puppy'), 'core', context_user::instance($user5->id)->id);
     tag_set('user', $user6->id, array('dog', 'dogs', 'puppy'), 'core', context_user::instance($user6->id)->id);
     $tags = tag_get_id(array('cat', 'cats', 'dog', 'dogs', 'kitten', 'puppy'));
     // Add manual relation between tags 'cat' and 'kitten'.
     tag_set('tag', $tags['cat'], array('kitten'), 'core', context_system::instance()->id);
     tag_compute_correlations();
     $this->assertEquals($tags['cats'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['cat'])));
     $this->assertEquals($tags['cat'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['cats'])));
     $this->assertEquals($tags['dogs'] . ',' . $tags['puppy'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['dog'])));
     $this->assertEquals($tags['dog'] . ',' . $tags['puppy'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['dogs'])));
     $this->assertEquals($tags['dog'] . ',' . $tags['dogs'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['puppy'])));
     // Make sure tag_get_correlated() returns 'cats' as the only correlated tag to the 'cat'.
     $correlatedtags = array_values(tag_get_correlated($tags['cat']));
     $this->assertCount(3, $correlatedtags);
     // This will return all existing instances but they all point to the same tag.
     $this->assertEquals('cats', $correlatedtags[0]->rawname);
     $this->assertEquals('cats', $correlatedtags[1]->rawname);
     $this->assertEquals('cats', $correlatedtags[2]->rawname);
     $correlatedtags = array_values(tag_get_related_tags($tags['cat'], TAG_RELATED_CORRELATED));
     $this->assertCount(1, $correlatedtags);
     // Duplicates are filtered out here.
     $this->assertEquals('cats', $correlatedtags[0]->rawname);
     // Make sure tag_get_correlated() returns 'dogs' and 'puppy' as the correlated tags to the 'dog'.
     $correlatedtags = array_values(tag_get_correlated($tags['dog']));
     $this->assertCount(6, $correlatedtags);
     // 2 tags times 3 instances.
     $correlatedtags = array_values(tag_get_related_tags($tags['dog'], TAG_RELATED_CORRELATED));
     $this->assertCount(2, $correlatedtags);
     $this->assertEquals('dogs', $correlatedtags[0]->rawname);
     $this->assertEquals('puppy', $correlatedtags[1]->rawname);
     // Function tag_get_related_tags() with default argument will return both related and correlated tags.
     $relatedtags = array_values(tag_get_related_tags($tags['cat']));
     $this->assertCount(2, $relatedtags);
     $this->assertEquals('kitten', $relatedtags[0]->rawname);
     $this->assertEquals('cats', $relatedtags[1]->rawname);
     // If we then manually set 'cat' and 'cats' as related, tag_get_related_tags() will filter out duplicates.
     tag_set('tag', $tags['cat'], array('kitten', 'cats'), 'core', context_system::instance()->id);
     $relatedtags = array_values(tag_get_related_tags($tags['cat']));
     $this->assertCount(2, $relatedtags);
     $this->assertEquals('kitten', $relatedtags[0]->rawname);
     $this->assertEquals('cats', $relatedtags[1]->rawname);
     // Make sure tag_get_correlated() and tag_get_tags() return the same set of fields.
     $relatedtags = tag_get_tags('tag', $tags['cat']);
     $relatedtag = reset($relatedtags);
     $correlatedtags = tag_get_correlated($tags['cat']);
     $correlatedtag = reset($correlatedtags);
     $this->assertEquals(array_keys((array) $relatedtag), array_keys((array) $correlatedtag));
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:69,代码来源:taglib_test.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP tag_get_related_tags_csv函数代码示例发布时间:2022-05-23
下一篇:
PHP tag_get_name函数代码示例发布时间: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