4 This plugins brings together all uploaded/cached images onto one
5 page (this usually includes [refrenced] graphics), see internal://
12 jeremy mikola <jmikola@arsjerm.net>
13 - contributor, added image mime-type filtering
15 - removed database call in loop significantly increasing performance
18 $ewiki_config["action_links"]["gallery"]["info"] = 'More Info';
20 define("EWIKI_GALLERY_WIDTH", 3);
21 define("EWIKI_PAGE_IMAGEGALLERY", "ImageGallery");
22 $ewiki_plugins["page"][EWIKI_PAGE_IMAGEGALLERY] = "ewiki_page_image_gallery";
24 //The main gallery includes only uploaded images and cached images *not* images
25 // that have been uploaded as attachments to a page or into a section.
26 // Only pages with no section attribute are included.
27 $ewiki_plugins["page"]['MainGallery'] = "ewiki_page_image_gallery";
28 $ewiki_config['image-galleries']['MainGallery']['section']='';
30 function ewiki_page_image_gallery($id, $data=0, $action) {
33 $o = ewiki_make_title($id, $id, 2);
38 #-- fetch and asort images
41 $result = ewiki_db::GETALL(array("flags", "created", "meta", "refs"));
42 while ($row = $result->get()) {
43 if ((($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_BINARY)
44 && (strpos($row['meta']['Content-Type'], 'image/') === 0)) {
45 if(isset($ewiki_config['image-galleries'][$id])){
46 foreach($ewiki_config['image-galleries'][$id]as $field=>$value){
47 if($row['meta'][$field]!=$value){
53 if (!EWIKI_PROTECTED_MODE || (EWIKI_PROTECTED_MODE_HIDING <= .5)|| ewiki_auth($row["id"], $uu, "binary-get")) {
54 $sorted[$row["id"]] = $row["created"];
55 $pages[$row["id"]] = $row;
57 } elseif (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT){
58 $page_refs[$row["id"]]=$row["refs"];
65 $o .= '<table border="0" cellpadding="10" cellspacing="4">' . "\n";
67 $num_per_row = EWIKI_GALLERY_WIDTH;
68 foreach ($sorted as $image => $uu) {
70 $row = $pages[$image];
74 $x = $x0 = $meta["width"];
75 $y = $y0 = $meta["height"];
78 $y = (int) ($mwidth * $mscale);
81 if ($y > $mwidth * $mscale) {
82 $r = $mwidth * $mscale / $y;
84 if ($r > $mwidth / $x) {
90 #-- get image references
92 foreach($page_refs as $pageid => $pageref) {
93 if(strstr($pageref, $image)){
94 if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($pageid, $str_null, "view")) {
97 $ref[] = '<a href=?page='.$pageid . '>' . $pageid . '</a>';
99 if (count($ref) >= 5) {
104 $ref = implode(", ", $ref);
107 (($n % $num_per_row) == 0) && ($o .= "<tr>\n");
110 $o .= '<td class="lighter" align="center">'
111 . '<a href="' . ewiki_script_binary("", $image) . '">'
112 . '<img src="' . ewiki_script_binary("", $image)
113 . '" alt="' . $image . '" border="0"'
114 . ($x && $y ? ' width="'.$x.'" height="'.$y.'"' : '')
116 . str_replace('/','/ ', urldecode($meta["Content-Location"]))
118 . ($x0 && $y0 ? "{$x0}x{$y0}<br />" : "")
121 . '<div class="action-links">'
122 . ewiki_control_links_list($image, $uuu, $ewiki_config["action_links"]["gallery"])
128 (($n % $num_per_row) == 0) && ($o .= "</tr>\n");
132 #-- empty table cells
133 if ($n % $num_per_row) {
134 while (($n % $num_per_row) && ($n++)) {
135 $o .= "<td class=\"lighter\"> </td>\n";