// DEPRECATED function smd_slimbox_inc($atts) { global $production_status; if (in_array($production_status, array('debug', 'testing'))) { trigger_error("smd_slimbox_inc is no longer supported. Please remove it and include the relevant javascript libraries manually on your page."); } return; } function smd_slimbox($atts, $thing='') { require_plugin('smd_lib'); global $production_status, $pretext, $thisarticle, $img_dir, $smd_sboxLang; // MLP support $smd_sboxStr = array( 'next_lbl' => 'Next', 'prev_lbl' => 'Prev', ); $smd_sboxLang = new smd_MLP('smd_slimbox', 'smd_sbox', $smd_sboxStr); // ** LOOKUP TABLES // Holds database field as key index and plugin option names as value. // Use array_search to find if value exists and return correct key for use in db calls. $fieldMap = array( "name" => "name", "id" => "id", "alt" => "alt", "caption" => "caption", "category" => "category", "author" => "author", "date" => "date", "ext" => "ext", "w" => "width", "h" => "height", ); $showLocs = array("below","above","after","before","onchange"); // $classTypes = array_merge(array("group","cell","link","img","thumbtext","nav","prev","next"),$showLocs); // $operands = array("changes", "contains", "eq", "lt", "gt", "lte", "gte", "not"); $thumbholder = "::SBOX_REPL::"; $attemptMatch = (isset($atts['category']) || isset($atts['imageid'])) ? true : false; // Plugin options extract(lAtts(array( 'delim' => ',', 'paramdelim' => ':', 'imageid' => '', 'category' => '', 'subcats' => '0', 'trigger' => 'lightbox-', 'groupname' => 'smd', 'thumb' => '0:1', 'limit' => '0', 'maxlimit' => '99999', 'sort' => 'category asc', // was orderby 'orderby' => '', // DEPRECATED 'showpagelinks' => '1', 'galleryid' => '?4:6', 'imagecaption' => '?caption', 'thumbsize' => '', 'thumbtext' => '', 'thumbtextwrap' => 'span', 'thumbtextclass' => '', 'wraptag' => '', 'navwraptag' => '', 'prevlabel' => $smd_sboxLang->gTxt('prev_lbl'), 'nextlabel' => $smd_sboxLang->gTxt('next_lbl'), 'prevclass' => 'smd_slimbox_prev', 'nextclass' => 'smd_slimbox_next', 'navclass' => '', 'cellclass' => '', 'linkclass' => '', 'imgclass' => '', 'debug' => '0', ), $atts)); // DEPRECATED: Convert orderby to the new sort. Remove in later versions if ($orderby) { $sort = str_replace (":", " ", $orderby); if (in_array($production_status, array('debug', 'testing'))) { trigger_error("'orderby' is now renamed 'sort'. Use a space instead of a colon to specify sort order (e.g. orderby='category:asc' is now sort='category asc')."); } } // Category relies on whether imageid has been specified or not. // lAtts() won't let us handle this logic so it has to be done manually $category = isset($category) ? doSlash($category) : (($imageid=="") ? $pretext['c']: ''); // The gallery identifier is used for keeping track of next/prev thumbpage links. // Don't use paramdelim here or the default option breaks $gallID = ""; if ($galleryid == "" || substr($galleryid,0,1) == "?") { // Generate a unique ID for this gallery instance $gallTmp = md5($category.$imageid.$orderby.$limit.$maxlimit.$wraptag); list($gallLen, $gallSkip) = explode(":", substr($galleryid,1)); $gallLen = (empty($gallLen)) ? "4" : $gallLen; $gallSkip = (empty($gallSkip)) ? "1" : $gallSkip; for ($idx = 0, $cnt = 0; $cnt < $gallLen; $cnt++, $idx = (($idx+$gallSkip) % strlen($gallTmp))) { $gallID .= $gallTmp[$idx]; } } else { $gallID = $galleryid; } // Set up the variables from the thumb option. // Don't use paramdelim here or the default option breaks $thumbOpts = do_list($thumb, ":"); if (count($thumbOpts) == 1) { $fullmod = ($thumbOpts[0] == 1) ? "t" : ""; $thumbmod = "t"; } else { $fullmod = ($thumbOpts[0] == 1) ? "t" : ""; $thumbmod = ($thumbOpts[1] == 1) ? "t" : ""; } // Extract the given category/imageid lists and make up the beginnings of a WHERE clause $clause[] = '1=1'; $clauseOR = array(); $subinfo = ($subcats) ? "image:".$subcats : ''; list($fullIDList, $notIDList) = smd_doList($imageid, true, '', true, $delim); list($fullCatList, $notCatList) = smd_doList($category, false, $subinfo, true, $delim); if ($fullIDList) { $clauseOR[] = 'txp_image.id IN ('.implode(",", $fullIDList).')'; } if ($fullCatList) { $clauseOR[] = 'txp_image.category IN ('.implode(",", $fullCatList).')'; } if (!empty($clauseOR)) { $clause[] = implode(" OR ", $clauseOR); } $clause = implode(" AND ", $clause); $clause .= ($notCatList) ? ' AND txp_image.category NOT IN ('.implode(",", $notCatList).')' : ''; $clause .= ($notIDList) ? ' AND txp_image.id NOT IN ('.implode(",", $notIDList).')' : ''; // If a category/imageid option was chosen and they matched nothing, use a bogus category that should not exist. // This ensures that the plugin does the expected thing of matching nothing in the event it finds nothing. if ($clause == "1=1" && $attemptMatch) { $clause = 'txp_image.category = "smd_' .mt_rand(). '"'; } // Convert the sort into a valid sorting hierarchy. // Note that random is a special case and the following rules apply: // 1) Anything appearing before random is passed to the database query for ordering // 2) As soon as random is encountered, the rest of the sort string is ignored. // The resultset will be sorted randomly instead // 3) If random appears first in the list, the data is retrieved randomly then the // remaining options sort the resultset $clauseSort = array(); $postOrder = array(); $rule = "sql"; $postPrefix = "SORT_"; $fixedOrder = $randsort = false; $sort = do_list($sort, $delim); for ($idx = 0; $idx < count($sort); $idx++) { $sort_dir = explode(' ', $sort[$idx]); $direction = $colRef = ''; if (count($sort_dir) <= 1) { $sort_dir[1] = "asc"; } if ($rule == "sql") { $direction = ($sort_dir[1] == "desc") ? ' desc' : ' asc'; } else { $direction = ($sort_dir[1] == "desc") ? $postPrefix.'DESC' : $postPrefix.'ASC'; } switch ($sort_dir[0]) { case 'random': $rule = "post"; if ($idx == 0) { $clauseSort[] = 'rand()'; } else { $randsort = true; } break; case 'fixed': // 'fixed' only works on ids $fixedOrder = ($imageid == '') ? false : true; break; default: $colRef = array_search($sort_dir[0], $fieldMap); break; } if ($rule == "sql") { if ($colRef != '') { $clauseSort[] = $colRef.$direction; } } else { if (!$randsort) { if ($colRef != '') { $postOrder[] = array("col" => $colRef, "sort" => $direction); } } } } if (count($clauseSort) > 0) { $clause .= ' ORDER BY ' . implode(",",$clauseSort); } // The database fields required $fields = 'id,name,caption,alt,category,date,author,ext,w,h'; // Handle paging if (($limit > 0) && $showpagelinks) { $rs = safe_rows($fields, 'txp_image', $clause .' LIMIT 0,'.$maxlimit, $debug); $numthum = count($rs); $numPages = ($numthum > 0) ? ceil($numthum/$limit) : 1; $thumbpage = (!gps($gallID)) ? 1 : gps($gallID); $offset = ($thumbpage - 1) * $limit; } else { // No paging required $numPages = 1; $thumbpage = 1; $rs = safe_rows($fields, 'txp_image', $clause .' LIMIT 0,'. (($limit==0) ? $maxlimit : $limit), $debug); } // Is post-ordering required? Do it if ($randsort) { shuffle($rs); } else if (count($postOrder) > 0) { // Translate the rows into columns that can be sorted foreach($rs as $key => $row) { $col_id[$key] = $row['id']; $col_name[$key] = $row['name']; $col_caption[$key] = $row['caption']; $col_alt[$key] = $row['alt']; $col_category[$key] = $row['category']; $col_date[$key] = $row['date']; $col_ext[$key] = $row['ext']; $col_author[$key] = $row['author']; $col_w[$key] = $row['w']; $col_h[$key] = $row['h']; } // Make up an array_multisort arg list and execute it for ($idx = 0; $idx < count($postOrder); $idx++) { $sortargs[] = '$col_'.$postOrder[$idx]['col']; $sortargs[] = $postOrder[$idx]['sort']; } $sortit = 'array_multisort('.implode(", ",$sortargs).', $rs);'; eval($sortit); } // Is fixed-order output desired? If so, re-order the $rs if ($fixedOrder) { $orderedRS = Array(); $ignoreList = Array(); $remainingRS = Array(); // Suck out the fixed items first for ($idx = 0; $idx < count($fullIDList); $idx++) { foreach($rs as $row) { if ("'".$row['id']."'" == $fullIDList[$idx]) { $orderedRS[] = $row; $ignoreList[] = $row['id']; } } } // Tack on the remaining rows foreach($rs as $row) { if (!in_array($row['id'], $ignoreList)) { $remainingRS[] = $row; } } $rs = array_merge($orderedRS, $remainingRS); } if (($limit > 0) && $showpagelinks) { $rs = array_slice($rs, $offset, $limit); } // Handle thumbsize $thumbWidth = $thumbHeight = ''; $thumbWUnits = $thumbHUnits = ''; if ($thumbsize) { $thumbSizes = do_list($thumbsize, $delim); if (count($thumbSizes) == 1) { $thumbWidth = $thumbHeight = ereg_replace("[^0-9]", '', $thumbSizes[0]); $units = ereg_replace("[0-9]", '', $thumbSizes[0]); $thumbWUnits = $thumbHUnits = ($units == '') ? $thumbWUnits : $units; } else { $thumbWidth = ereg_replace("[^0-9]", '', $thumbSizes[0]); $thumbHeight = ereg_replace("[^0-9]", '', $thumbSizes[1]); $units = ereg_replace("[0-9]", '', $thumbSizes[0]); $thumbWUnits = ($units == '' && $thumbWidth != '') ? $thumbWUnits : $units; $units = ereg_replace("[0-9]", '', $thumbSizes[1]); $thumbHUnits = ($units == '' && $thumbHeight != '') ? $thumbHUnits : $units; } } // Set up the thumbtext positions $posArray = array(); $showopts = do_list($thumbtext, $delim); foreach ($showopts as $item) { $showpos = do_list($item, $paramdelim); if (count($showpos) > 1 && in_array($showpos[0],$showLocs)) { $posArray[$showpos[0]] = $showpos[1]; } else { $posArray[$showLocs[0]] = ((count($showpos)>1) ? $showpos[1] : $showpos[0]); } } // Construct the output $fieldRE = '/\?('.implode('|', $fieldMap).'|url)/'; $thumbtextPlate = (($thumbtextwrap) ? '<' . $thumbtextwrap . (($thumbtextclass != "") ? ' class="' .$thumbtextclass. '"' : '') . '>' : '') .$thumbholder. (($thumbtextwrap) ? '' : ''); $outStr = ''; if ($debug) { dmp($rs); } if($rs) { $thumbtextCurr=""; foreach($rs as $row) { $theThumb = hu.$img_dir.'/' . $row['id'] . $thumbmod . $row['ext']; $full = hu.$img_dir.'/' . $row['id'] . $fullmod .$row['ext']; if ($groupname === "?c") { $grp = $row['category']; } else if ($groupname === "?id") { $grp = $row['id']; } else if ($groupname === "?author") { $grp = $row['author']; } else if ($groupname === "?date") { $grp = $row['date']; } else if ($groupname === "?alt") { $grp = $row['alt']; } else if ($groupname === "?caption") { $grp = $row['caption']; } else if ($groupname === "?ext") { $grp = $row['ext']; } else if ($groupname === "?name") { $grp = $row['name']; } else if ($groupname === "?width") { $grp = $row['w']; } else if ($groupname === "?height") { $grp = $row['h']; } else if (substr($groupname,0,1) === "?") { // Split off the field name from the question mark $fieldname = substr($groupname,1); if (isset($thisarticle[$fieldname])) { $grp = $thisarticle[$fieldname]; } else { $grp = ''; } } else { $grp = $groupname; } // Handle imagecaption $captionMsg = $imagecaption; $matches = array(); $ctr = preg_match_all($fieldRE, $captionMsg, $matches, PREG_SET_ORDER); for ($idx = 0; $idx < $ctr; $idx++) { $fieldname = $matches[$idx][1]; $key = array_search($fieldname, $fieldMap); if ($key) { $rep = $row[$key]; } else if ($fieldname == "url") { $rep = $full; } else { $rep = $fieldname; } $captionMsg = str_replace($matches[$idx][0], $rep, $captionMsg); } // Handle thumbtext $thumbtextArray = array_combine($showLocs, array("","","","","")); // Initialise every element foreach ($posArray as $pos => $text) { $matches = array(); $ctr = preg_match_all($fieldRE, $text, $matches, PREG_SET_ORDER); for ($idx = 0; $idx < $ctr; $idx++) { $fieldname = $matches[$idx][1]; $key = array_search($fieldname, $fieldMap); if ($key) { $rep = $row[$key]; } else if ($fieldname == "url") { $rep = $full; } else { $rep = $fieldname; } $text = str_replace($matches[$idx][0], $rep, $text); } $thumbtextArray[$pos] = $text; } // Construct the link and put thumbtext in the appropriate positions $outStr .= ($thumbtextArray["onchange"] && $thumbtextArray["onchange"] != $thumbtextCurr) ? str_replace($thumbholder, htmlspecialchars_decode($thumbtextArray["onchange"]), $thumbtextPlate) : ''; $outStr .= ($wraptag != "") ? '<' .$wraptag. (($cellclass != "") ? ' class="' .$cellclass. '"' : '') . '>' : ''; $outStr .= ($thumbtextArray["above"]) ? str_replace($thumbholder, htmlspecialchars_decode($thumbtextArray["above"]), $thumbtextPlate) : ''; $outStr .= '' .(($thumbtextArray["before"]) ? str_replace($thumbholder, htmlspecialchars_decode($thumbtextArray["before"]), $thumbtextPlate) : ''). '' .$row['alt']. '' .(($thumbtextArray["after"]) ? str_replace($thumbholder, htmlspecialchars_decode($thumbtextArray["after"]), $thumbtextPlate) : ''). ''.n; $outStr .= ($thumbtextArray["below"]) ? str_replace($thumbholder, htmlspecialchars_decode($thumbtextArray["below"]), $thumbtextPlate) : ''; $outStr .= ($wraptag != "") ? '' : ''; $outStr .= n; $thumbtextCurr = $thumbtextArray["onchange"]; } // Add the paging features if required if (($limit > 0) && $showpagelinks) { $next = ($numPages > 1 && $thumbpage != $numPages); $prev = ($numPages > 1 && $thumbpage > 1); // Replace any paging info in the query string $prevPage = smd_addQSVar($pretext['request_uri'], $gallID, $thumbpage-1); $nextPage = smd_addQSVar($pretext['request_uri'], $gallID, $thumbpage+1); $outStr .= ($navwraptag != "") ? '<' .$navwraptag. (($navclass != "") ? ' class="' .$navclass. '"' : '') . '>' : ''; $outStr .= ($prev) ? '' .$prevlabel. ''.n : ''; $outStr .= ($next) ? '' .$nextlabel. ''.n : ''; $outStr .= ($navwraptag != "") ? '' : ''; $outStr .= n; } } return $outStr; }