/** * Short captions and descriptions attached to images with a "labels.txt" file. * @return An array of SIGPlusImageLabel instances, or an empty array of no "labels.txt" file is found. */ public function getLabels($imagedirectory, $labelsfilename, &$defaultcaption, &$defaultdescription) { if ($remote = is_remote_path($imagedirectory)) { $urlparts = parse_url($imagedirectory); // read labels file $contents = $this->getLabelsFileContentsRemote($urlparts, $labelsfilename); } else { // read labels file $contents = $this->getLabelsFileContents($imagedirectory, $labelsfilename); } if ($contents === false) { return array(); } // remove UTF-8 BOM and normalize line endings if (!strcmp("", substr($contents, 0, 3))) { // file starts with UTF-8 BOM $contents = substr($contents, 3); // remove UTF-8 BOM } $contents = str_replace("\r", "\n", $contents); // normalize line endings // split into lines $matches = array(); preg_match_all('/^([^|\\n]+)(?:[|]([^|\\n]*)(?:[|]([^\\n]*))?)?$/mu', $contents, $matches, PREG_SET_ORDER); if (version_compare(PHP_VERSION, '5.2.0') >= 0) { switch (preg_last_error()) { case PREG_BAD_UTF8_ERROR: throw new SIGPlusEncodingException($labelsfile); } } // parse individual entries $labels = array(); foreach ($matches as $match) { $imagefile = $match[1]; $caption = count($match) > 2 ? $match[2] : false; $description = count($match) > 3 ? $match[3] : false; if ($imagefile == '*') { // set default label $defaultcaption = $caption; $defaultdescription = $description; } else { if (is_remote_path($imagefile)) { // a URL to a remote image $imagefile = safeurlencode($imagefile); } elseif ($remote) { // an image imported from a remote labels file $imagefile = http_build_url($urlparts, array('path' => $imagefile), HTTP_URL_JOIN_PATH | HTTP_URL_STRIP_QUERY | HTTP_URL_STRIP_FRAGMENT); } else { // a local image $imagefile = file_exists_case_insensitive($imagedirectory . DIRECTORY_SEPARATOR . $imagefile); if ($imagefile === false) { // check that image file truly exists continue; } } $labels[] = new SIGPlusImageLabel($imagefile, $caption, $description); } } return $labels; }
/** * Generates image thumbnails with alternate text, title and lightbox pop-up activation on mouse click. * This method is to be called as a regular expression replace callback. * Any error messages are printed to screen. * @param $match A regular expression match. */ public function getGalleryRegexReplacementExpanded($match) { $imagereference = $match[2]; if (is_remote_path($imagereference)) { $imagereference = safeurlencode($imagereference); } return $this->core->getGalleryHtml($imagereference, $match[1]); }