public static function instance() { if (self::$instance == null) { // get the flickr key $key = file_get_contents(WIKIDOT_ROOT . '/files/flickr-api-key.txt'); self::$instance = new FlickrHandler($key, null, false); } return self::$instance; }
public function build($runData) { $flickrId = $runData->getParameterList()->getParameterValue("flickr_id"); $secret = $runData->getParameterList()->getParameterValue("secret"); $flickr = FlickrHandler::instance(); $photo = $flickr->photos_getInfo($flickrId, $secret); if ($photo == null) { $runData->contextAdd("nophoto", true); return; } $src = $flickr->buildPhotoURL($photo, "thumbnail"); $runData->contextAdd("flickrId", $flickrId . $secret); $runData->contextAdd("photoSrc", $src); $runData->contextAdd("photo", $photo); }
public function build($runData) { $pl = $runData->getParameterList(); $photoId = $pl->getParameterValue("photoId"); $flickr = FlickrHandler::instance(); $secret = $runData->getParameterList()->getParameterValue("secret"); $photo = $flickr->photos_getInfo($photoId, $secret); if ($photo == null) { $runData->contextAdd("nophoto", true); throw new ProcessException(_("The photo can not be loaded.")); } $sizes = $flickr->photos_getSizes($photoId); $size = "Medium"; // perhaps sometimes original??? MUST BE UPPERCASED $src = $flickr->buildPhotoURL($photo, $size); $dimensions = $sizes[$size]['_attributes']; $runData->contextAdd("photoSrc", $src); $runData->contextAdd("photoUrl", $photo['urls']['url'][0]['_value']); $runData->contextAdd("photo", $photo); $runData->contextAdd("sizes", $sizes); $runData->contextAdd("size", $size); $runData->contextAdd("dimensions", $dimensions); }
/** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { $pageName = $this->wiki->vars['pageName']; $size = $options['size']; if (!in_array($size, array("small", "medium", "thumbnail", "square", "original"))) { $size = "thumbnail"; } $sources = $options['sources']; if ($sources) { $noLocal = $this->getConf("no_local"); // each line is a source + parameters. // parse in a similar way as the image rule. // parse sources $sources = explode("\n", $sources); if (count($sources) === 0) { return '<div class="error-block">' . _('Sorry, no images found.') . '</div>'; } $out = '<div class="gallery-box">'; foreach ($sources as $row) { if (!preg_match("/^: /", $row)) { continue; } $row = trim(preg_replace("/^: /", '', $row)); $pos = strpos($row, ' '); if ($pos === false) { $src = $row; $attr = array(); } else { // everything after the space is attribute arguments $src = substr($row, 0, $pos); $attr = $this->getAttrs(substr($row, $pos + 1)); } // SINGLE IMAGE PROCESSING BEGINS if ($src && $src[0] == '*') { $src = substr($src, 1); $target = 'target="_blank"'; } // see if is a flickr image if (strpos($src, 'flickr:') !== false) { preg_match("/^flickr:([0-9]+)(?:_([a-z0-9]+))?/i", $src, $mat2); $photoId = $mat2[1]; $secret = $mat2[2]; $flickr = FlickrHandler::instance(); $photo = $flickr->photos_getInfo($photoId, $secret); if ($photo == null) { return '<div class="error-block">Error fetching flickr image (id: ' . $photoId . ') info. ' . 'The file does not exist, is private or other problem.</div>'; } $src = $flickr->buildPhotoURL($photo, $size); //"http://static.flickr.com/".$photo['_attributes']['server']."/".$photo['_attributes']['id']."_".$photo['_attributes']['secret'].".jpg"; // set/override link attribute $attr['link'] = $photo['urls']['url'][0]['_value']; } elseif (strpos($src, '://') === false) { // is the source a local file or URL? // the source refers to a local file. // add the URL base to it. // see if it refers to a different page if (strpos($src, '/') !== false) { $src = preg_replace("/^\\//", '', $src); $osrc = "/local--files/" . $src; $src = "/local--resized-images/" . $src . '/' . $size . '.jpg'; } else { if ($noLocal) { return '<div class="error-block">' . 'Error fetching local image (: ' . $row . ').' . 'Sorry, can not load files attached to this page in this mode. ' . 'You should specify source page for each local image.</div>'; } $osrc = "/local--files/" . $this->wiki->vars['pageName'] . '/' . $src; $src = "/local--resized-images/" . $this->wiki->vars['pageName'] . '/' . $src . '/' . $size . '.jpg'; } if ($size == "original") { $src = $osrc; } } elseif (strpos($src, '://') !== false) { $attr['link'] = $src; $size = "original"; } else { return '<div class="error-block">Sorry, format for gallery item:<pre>' . $row . '</pre> is not supported.</div>'; } if (isset($attr['link'])) { $link = $attr['link']; if ($link[0] == '*') { $link = substr($link, 1); $target = 'target="_blank"'; $attr['link'] = $link; } // yes, the image is clickable. // are we linked to a URL or a wiki page? if (strpos($attr['link'], '://')) { // it's a URL $href = $attr['link']; } else { // it's a WikiPage; assume it exists. /** @todo This needs to honor sprintf wikilinks (pmjones) */ /** @todo This needs to honor interwiki (pmjones) */ /** @todo This needs to honor freelinks (pmjones) */ $href = $this->wiki->getRenderConf('xhtml', 'wikilink', 'view_url') . $attr['link']; } } else { // image is not clickable. $href = $osrc; } $out .= '<div class="gallery-item ' . $size . '">'; $out .= '<table><tr><td>'; $out .= '<a href="' . $href . '" ' . $target . '>'; $out .= '<img src="' . $src . '" alt=""/>'; $out .= '</a>'; $out .= '</td></tr></table>'; $out .= '</div>'; // SINGLE IMAGE PROCESSING ENDS } $out .= '</div>'; return $out; } // local mode $noLocal = $this->getConf("no_local"); if ($noLocal) { return '<div class="error-block">' . 'Sorry, can not load files attached to the page in this mode. ' . 'You should specify sources for each image.</div>'; } // get page first $site = $GLOBALS['site']; $page = DB_PagePeer::instance()->selectByName($site->getSiteId(), $pageName); if ($page == null) { return '<div class="error-block">Error selecting page.</div>'; } // get attachments that might be images. $c = new Criteria(); $c->add("page_id", $page->getPageId()); $c->add("mimetype", "^image", "~*"); $c->add("has_resized", true); $files = DB_FilePeer::instance()->select($c); if (count($files) == 0) { return '<div class="error-block">Sorry, no images found attached ' . 'to this page.</div>'; } // ok, we have images. now GOGOGO!!! $out = '<div class="gallery-box">'; foreach ($files as $file) { $src = '/local--resized-images/' . $pageName . '/' . $file->getFilename() . '/' . $size . '.jpg'; $href = 'local--files/' . $pageName . '/' . $file->getFilename(); if ($size == "original") { $src = $href; } $out .= '<div class="gallery-item ' . $size . '">'; $out .= '<table><tr><td>'; $out .= '<a href="' . $href . '">'; $out .= '<img src="' . $src . '" alt=""/>'; $out .= '</a>'; $out .= '</td></tr></table>'; $out .= '</div>'; } $out .= '</div>'; return $out; }
public function build($runData) { $fh = FlickrHandler::instance(); // determine mode. if either photosetId or groupName given - enter specific mode. // if not - just search photos. $pl = $runData->getParameterList(); $contentOnly = $pl->getParameterValue("contentOnly"); $photosetId = $pl->getParameterValue("photosetId"); $groupId = $pl->getParameterValue("groupId"); $groupUrl = $pl->getParameterValue("groupUrl"); $pageNumber = $pl->getParameterValue("pageNumber"); if ($pageNumber === null) { $pageNumber = 1; } $perPage = $pl->getParameterValue("perPage"); if ($perPage == null || !is_numeric($perPage) || $perPage < 1 || $perPage > 100) { $perPage = 30; } $size = $pl->getParameterValue("size"); if ($size == null || $size != "square" && $size != "small" && $size != "thumbnail" && $size != "medium") { $size = "thumbnail"; } $limit = $pl->getParameterValue("limitPages"); if (!is_numeric($limit) || $limit < 1) { $limit = null; } if ($photosetId != null) { // get photoset info $photoset = $fh->photosets_getInfo($photosetId); if ($photoset == null) { throw new ProcessException(_("Can not fetch photoset data - photoset might not exist or not be public (or other problem)."), "no_photoset"); } // take photos from the photoset!! $result = $fh->photosets_getPhotos($photosetId); $photos = $result['photo']; $totalPhotos = $photoset['photos']; // slice to get only page results $photos = array_slice($photos, ($pageNumber - 1) * $perPage, $perPage); $userId = $photoset['owner']; for ($i = 0; $i < count($photos); $i++) { $photos[$i]['src'] = $fh->buildPhotoURL($photos[$i], $size); $photos[$i]['href'] = 'http://www.flickr.com/photos/' . $userId . '/' . $photos[$i]['id']; } } elseif ($groupId !== null || $groupUrl != null) { // take photos from a group if ($groupId !== null) { // get group by ID $group = $fh->groups_getInfo($groupId); } else { $group = $fh->urls_lookupGroup($groupUrl); $groupId = $group['id']; } if ($group == null) { throw new ProcessException(_("Can not fetch group data."), "no_group"); } $result = $fh->groups_pools_getPhotos($groupId, null, null, null, $perPage, $pageNumber); $totalPhotos = $result['total']; $photos = $result['photo']; for ($i = 0; $i < count($photos); $i++) { $photos[$i]['src'] = $fh->buildPhotoURL($photos[$i], $size); $photos[$i]['href'] = 'http://www.flickr.com/photos/' . $photos[$i]['owner'] . '/' . $photos[$i]['id']; } } else { // just search. woooo. this is COOOOOL!!! $args = array(); //search parameters $userName = $pl->getParameterValue("userName"); if ($userName) { // get user $user = $fh->people_findByUsername($userName); if ($user == null) { throw new ProcessException(sprintf(_('Sorry, user <em>%s</em> could not be found.'), $userName), "no_user"); } $args['user_id'] = $user; } $tags = $pl->getParameterValue("tags"); if ($tags) { $args['tags'] = $tags; } $tagMode = $pl->getParameterValue("tagMode"); if ($tagMode == "any" || $tagMode == "all") { $args['tag_mode'] = $tagMode; } $sort = $pl->getParameterValue("sort"); if (count($args) == 0) { $result = $fh->photos_getRecent(null, $perPage, $pageNumber); $photos = $result['photo']; $totalPhotos = $result['total']; } else { // sort does not count. if ($sort && in_array($sort, array("date-posted-asc", "date-posted-desc", "date-taken-asc", "date-taken-desc", "interestingness-desc", "interestingness-asc", "relevance"))) { $args['sort'] = $sort; } $args['per_page'] = $perPage; $args['page'] = $pageNumber; $result = $fh->photos_search($args); $photos = $result['photo']; $totalPhotos = $result['total']; } for ($i = 0; $i < count($photos); $i++) { $photos[$i]['src'] = $fh->buildPhotoURL($photos[$i], $size); $photos[$i]['href'] = 'http://www.flickr.com/photos/' . $photos[$i]['owner'] . '/' . $photos[$i]['id']; } } // build urls $pagerData = array(); $totalPages = ceil($totalPhotos / $perPage); if ($limit) { $totalPages = min($limit, $totalPages); } $pagerData['total_pages'] = $totalPages; $pagerData['current_page'] = $pageNumber; $runData->contextAdd("pagerData", $pagerData); $runData->contextAdd("photos", $photos); $runData->contextAdd("size", $size); if ($contentOnly) { $runData->contextAdd("contentOnly", true); } $runData->contextAdd("makeHoverTitles", true); //(bool)$pl->getParameterValue("makeHoverTitles")); $runData->contextAdd("disableBrowsing", (bool) $pl->getParameterValue("disableBrowsing")); //put parameters into context if (!$runData->getAjaxMode()) { $parameters = $pl->getParametersByType("MODULE"); $runData->contextAdd("parameters", $parameters); } }
/** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { // note the image source $src = $options['src']; $size = $options['attr']['size']; $postVars = $this->getConf("post_vars"); if (preg_match('/^:first/', $src)) { $page = DB_PagePeer::instance()->selectByName($GLOBALS['site']->getSiteId(), $this->wiki->vars['pageName']); if (!$page) { return ""; } $c = new Criteria(); $c->add("page_id", $page->getPageId()); $c->add("mimetype", "^image", "~*"); $c->add("has_resized", true); $c->addOrderAscending("filename"); if ($file = DB_FilePeer::instance()->selectOne($c)) { $src = $file->getFileName(); $options['src'] = $src; } else { return ""; } } // see if is a flickr image if (strpos($src, 'flickr:') !== false) { //check if valid arguments, handle sizes etc. preg_match("/^flickr:([0-9]+)(?:_([a-z0-9]+))?/i", $src, $mat2); $photoId = $mat2[1]; $secret = $mat2[2]; if (!in_array($size, array("small", "medium", "thumbnail", "square", "large", "original"))) { $size = null; } $flickr = FlickrHandler::instance(); $photo = $flickr->photos_getInfo($photoId, $secret); if ($photo == null) { return '<div class="error-block">' . sprintf(_('Error fetching flickr image (id: %s) info. The file does not exist, is private or other problem.'), $photoId) . '</div>'; } $src = $flickr->buildPhotoURL($photo, $size); //"http://static.flickr.com/".$photo['_attributes']['server']."/".$photo['_attributes']['id']."_".$photo['_attributes']['secret'].".jpg"; // set/override link attribute $options['attr']['link'] = $photo['urls']['url'][0]['_value']; } elseif (strpos($src, '://') === false) { // is the source a local file or URL? // the source refers to a local file. // add the URL base to it. if (!in_array($size, array("small", "medium", "thumbnail", "square"))) { $size = null; } // should we force size? yes if the file has resized version but is // not a viewable image, e.g. .pdf if (!$size && !preg_match('/\\.(png|jpg|gif)$/i', $src)) { $size = "medium"; } // see if it refers to a different page if ($postVars || preg_match("/^%%%[^%]+%%\$/", $src)) { // this is ok. used for feed parsing. } elseif (strpos($src, '/') !== false) { if ($size) { $src = preg_replace("/^\\//", '', $src); $src = "/local--resized-images/" . $src . '/' . $size . '.jpg'; if ($options['attr']['link'] == null) { // link to the original image $srch = preg_replace("/^\\//", '', $options['src']); $options['attr']['link'] = "/local--files/" . $srch; } } else { // ok, hardcode the path... sorry. $src = preg_replace("/^\\//", '', $src); $src = "/local--files/" . $src; } } else { $noLocal = $this->getConf("no_local"); if ($noLocal) { return '<span class="error-inline">' . _('Sorry, local images without page name specified not allowed. Use <em>pagename</em>/<em>filename</em> as the image source') . '</span>'; } if ($size) { $src = "/local--resized-images/" . $this->wiki->vars['pageName'] . '/' . $src . '/' . $size . '.jpg'; if ($options['attr']['link'] == null) { // link to the original image $srch = preg_replace("/^\\//", '', $options['src']); $options['attr']['link'] = "/local--files/" . $this->wiki->vars['pageName'] . '/' . $srch; } } else { $src = "/local--files/" . $this->wiki->vars['pageName'] . '/' . $src; } } } if (isset($options['attr']['link'])) { // yes, the image is clickable. // are we linked to a URL or a wiki page? if (strpos($options['attr']['link'], '://')) { // it's a URL, prefix the URL base $href = $this->getConf('url_base') . $options['attr']['link']; } else { // it's a WikiPage; assume it exists. /** @todo This needs to honor sprintf wikilinks (pmjones) */ /** @todo This needs to honor interwiki (pmjones) */ /** @todo This needs to honor freelinks (pmjones) */ $href = '/' . $options['attr']['link']; $href = preg_replace(';^/+;', '/', $href); // a dirty fix } } else { // image is not clickable. $href = null; } // unset so it won't show up as an attribute unset($options['attr']['link']); $output .= '<img src="' . htmlspecialchars($src) . '"'; // get the CSS class but don't add it yet $css = "image"; // add the attributes to the output, and be sure to // track whether or not we find an "alt" attribute $alt = false; foreach ($options['attr'] as $key => $val) { // track the 'alt' attribute if (strtolower($key) == 'alt') { $alt = true; } // the 'class' attribute overrides the CSS class conf if (strtolower($key) == 'class') { $css = null; } if ($key == "class" || $key == "alt" || $key == "style" || $key == "width" || $key == "height") { $key = htmlspecialchars($key); $val = htmlspecialchars($val); $output .= " {$key}=\"{$val}\""; } } // always add an "alt" attribute per Stephane Solliec if (!$alt) { $alt = htmlspecialchars(basename($options['src'])); $output .= " alt=\"{$alt}\""; } // end the image tag with the automatic CSS class (if any) if ($css) { $output .= ' class="' . $css . '"'; } $output .= " />"; // was the image clickable? if ($href) { // yes, add the href and return $href = htmlspecialchars($href); $css = $this->formatConf(' class="%s"', 'css_link'); $target = ''; if ($options['target']) { $target = ' target="' . $options['target'] . '" '; } $output = "<a{$css} href=\"{$href}\" {$target}>{$output}</a>"; } $align = $options['align']; if ($align) { $output2 = $output; $output = ''; // start the HTML output $output .= '<div class="image-container'; if ($align === "f<") { $output .= ' floatleft'; } elseif ($align === "f>") { $output .= ' floatright'; } elseif ($align === "<") { $output .= ' alignleft'; } elseif ($align === ">") { $output .= ' alignright'; } elseif ($align === '=') { $output .= ' aligncenter'; } $output .= '">'; $output .= $output2; $output .= '</div>'; } return $output; }