. /** * Flickr tag block. * * @package block_tag_flickr * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define('FLICKR_DEV_KEY', '4fddbdd7ff2376beec54d7f6afad425e'); define('DEFAULT_NUMBER_OF_PHOTOS', 6); class block_tag_flickr extends block_base { function init() { $this->title = get_string('pluginname','block_tag_flickr'); } function applicable_formats() { return array('tag' => true); } function specialization() { $this->title = !empty($this->config->title) ? $this->config->title : get_string('pluginname', 'block_tag_flickr'); } function instance_allow_multiple() { return true; } function get_content() { global $CFG, $USER; //note: do NOT include files at the top of this file 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 $tc = optional_param('tc', 0, PARAM_INT); // Tag collection id. if ($tagid) { $tagobject = core_tag_tag::get($tagid); } else if ($tag) { $tagobject = core_tag_tag::get_by_name($tc, $tag); } 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)) { foreach ($tagobject->get_related_tags() as $t) { $tagscsv .= ',' . $t->get_display_name(false); } } $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 = 'https://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']); } //search for photos tagged with $tagscsv else{ $request = 'https://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 = '