changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / page / imagegallery.php
1 <?php
2
3 /*
4    This plugins brings together all uploaded/cached images onto one
5    page (this usually includes [refrenced] graphics), see internal://
6
7    CSS:
8       td.lighter { ... }
9
10    ----
11
12    jeremy mikola <jmikola@arsjerm.net>
13        - contributor, added image mime-type filtering
14    jeffrey engleman 
15        - removed database call in loop significantly increasing performance
16 */
17
18  $ewiki_config["action_links"]["gallery"]["info"] = 'More Info';
19  
20 define("EWIKI_GALLERY_WIDTH", 3);
21 define("EWIKI_PAGE_IMAGEGALLERY", "ImageGallery");
22 $ewiki_plugins["page"][EWIKI_PAGE_IMAGEGALLERY] = "ewiki_page_image_gallery";
23
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']='';
29
30 function ewiki_page_image_gallery($id, $data=0, $action) {
31     global $ewiki_config;
32
33    $o = ewiki_make_title($id, $id, 2);
34
35    $mwidth = 120;
36    $mscale = 0.7;
37    
38    #-- fetch and asort images
39    $sorted = array();
40    $pages = array();
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){
48                         continue (2);
49             
50                     }
51                 }
52             }            
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;
56             }           
57         } elseif (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT){
58             $page_refs[$row["id"]]=$row["refs"];
59         } 
60     }
61     
62    arsort($sorted);
63    
64    #-- start table
65    $o .= '<table border="0" cellpadding="10" cellspacing="4">' . "\n";
66    $n = 0;
67    $num_per_row = EWIKI_GALLERY_WIDTH;
68    foreach ($sorted as $image => $uu) {
69
70       $row = $pages[$image];
71       $meta = $row["meta"];
72
73       #-- height, width
74       $x = $x0 = $meta["width"];
75       $y = $y0 = $meta["height"];
76       if (! ($x && $y)) {
77          $x = $mwidth;
78          $y = (int) ($mwidth * $mscale);
79       }
80       $r = 1;
81       if ($y > $mwidth * $mscale) {
82          $r = $mwidth * $mscale / $y;
83       }
84       if ($r > $mwidth / $x) {
85          $r = $mwidth / $x;
86       }
87       $x = (int) ($x * $r);
88       $y = (int) ($y * $r);
89
90       #-- get image references
91       $ref=array();
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")) {
95             continue;
96           }   
97           $ref[] = '<a href=?page='.$pageid . '>' . $pageid . '</a>';
98         }
99         if (count($ref) >= 5) {
100           break;
101         }
102       }
103
104       $ref = implode(", ", $ref);
105       
106       #-- table lines
107       (($n % $num_per_row) == 0) && ($o .= "<tr>\n");
108
109       #-- print a/img tag
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.'"' : '')
115           . ' />'
116           . str_replace('/','/ ', urldecode($meta["Content-Location"]))
117           . '</a><br />'
118           . ($x0 && $y0 ? "{$x0}x{$y0}<br />" : "")
119           . $ref
120           #-- gallery-actions
121           . '<div class="action-links">'
122           . ewiki_control_links_list($image, $uuu, $ewiki_config["action_links"]["gallery"])
123           . "</div>\n"
124           . "</td>\n";
125
126       #-- table lines
127       $n++;
128       (($n % $num_per_row) == 0) && ($o .= "</tr>\n");
129
130    }
131
132    #-- empty table cells
133    if ($n % $num_per_row) {
134       while (($n % $num_per_row) && ($n++)) {
135          $o .= "<td class=\"lighter\">&nbsp;</td>\n";
136       }
137       $o .= "</tr>\n";
138    }
139    $o .= "</table>\n";
140     
141    return($o);
142 }
143
144  
145 ?>