function get_videos_by_tag_and_category() { $tagid = optional_param('id', 0, PARAM_INT); // tag id $query_tag = tag_display_name(tag_by_id($tagid)); $query_tag = urlencode($query_tag); $numberofvideos = DEFAULT_NUMBER_OF_VIDEOS; if (!empty($this->config->numberofvideos)) { $numberofvideos = $this->config->numberofvideos; } $request = 'http://www.youtube.com/api2_rest?method=youtube.videos.list_by_category_and_tag'; $request .= '&category_id=' . $this->config->category; $request .= '&dev_id=' . YOUTUBE_DEV_KEY; $request .= "&tag={$query_tag}"; $request .= "&page=1"; $request .= "&per_page={$numberofvideos}"; return $this->fetch_request($request); }
/** * function to attach tags into a post * @param int postid - id of the blog */ function add_tags_info($postid) { global $USER; $post = get_record('post', 'id', $postid); /// Attach official tags if ($otags = optional_param('otags', '', PARAM_INT)) { foreach ($otags as $otag) { $tag->tagid = $otag; //insert_record('blog_tag_instance', $tag); tag_an_item('blog', $postid, $otag, 'official'); } } /// Attach Personal Tags if ($ptags = optional_param('ptags', '', PARAM_NOTAGS)) { $ptags = explode(',', $ptags); foreach ($ptags as $ptag) { $ptag = trim($ptag); // check for existance // it does not matter whether it is an offical tag or personal tag // we do not want to have 1 copy of offical tag and 1 copy of personal tag (for the same tag) if ($ctag = tag_by_id($ptag)) { tag_an_item('blog', $postid, $ctag); } else { // create a personal tag if ($tagid = tag_create($ptag)) { if ($tagid = array_shift($tagid)) { tag_an_item('blog', $postid, $tagid); } } } } } }
function get_content() { global $CFG, $USER, $PAGE; if ($this->content !== NULL) { return $this->content; } $tagid = optional_param('id', 0, PARAM_INT); // tag id //include related tags in the photo query ? $tags_csv = tag_display_name(tag_by_id($tagid)); if (!empty($this->config->includerelatedtags)) { $tags_csv .= ',' . tag_names_csv(get_item_tags('tag', $tagid)); } $tags_csv = urlencode($tags_csv); //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=' . $tags_csv; $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... //render the list of photos $text = ''; foreach ($photos as $photo) { $text .= '<a href="http://www.flickr.com/photos/' . $photo['owner'] . '/' . $photo['id'] . '/">'; $text .= '<img title="' . s($photo['title']) . '" alt="' . s($photo['title']) . '" class="flickr-photos" src="' . $this->build_photo_url($photo, 'square') . '" /></a>'; } $this->content = new stdClass(); $this->content->text = $text; $this->content->footer = ''; return $this->content; }
$str_tagschecked = str_replace(',', ', ', $str_tagschecked); tag_flag_reset(implode($tagschecked, ',')); $notice = $str_tagschecked . ' -- ' . get_string('reset', 'tag'); break; case 'changetype': if (!data_submitted or !confirm_sesskey()) { break; } $changed = array(); foreach ($tagschecked as $tag_id) { if (!in_array($tagtypes[$tag_id], $existing_tagtypes)) { //can not add new types here!! continue; } // update tag type; $tag = tag_by_id($tag_id); $tag->tagtype = $tagtypes[$tag_id]; if (update_record('tag', $tag)) { $changed[] = $tag_id; } } if ($changed) { $str_changed = tag_name_from_string(implode($changed, ',')); $str_changed = str_replace(',', ', ', $str_changed); $notice = $str_changed . ' -- ' . get_string('typechanged', 'tag'); } break; case 'changename': if (!data_submitted or !confirm_sesskey()) { break; }
function delete_otags($tagids, $sitecontext) { foreach ($tagids as $tagid) { if (!($tag = tag_by_id($tagid))) { error('Can not delete tag, tag doesn\'t exist'); } if ($tag->tagtype != 'official') { continue; } if ($tag->tagtype == 'official' and !has_capability('moodle/blog:manageofficialtags', $sitecontext)) { //can not delete error('Can not delete tag, you don\'t have permission to delete an official tag'); } // Delete the tag itself if (!tag_delete($tagid)) { error('Can not delete tag'); } } }
/** * 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; }