Dotclear

source: plugins/lastImages/_public.php @ 1109

Revision 1109, 3.6 KB checked in by philippe, 14 years ago (diff)

New plugin Last Post Images created

Line 
1<?php
2$core->addBehavior('publicHeadContent',array('lastImagesPublic','publicHeadContent'));
3require dirname(__FILE__).'/_widget.php';
4class lastImagesPublic
5{
6     public static function publicHeadContent(&$core)
7     {
8         
9          $url = $core->blog->getQmarkURL().'pf='.basename(dirname(__FILE__));
10          echo
11          '<style type="text/css">'."\n".
12          '@import url('.$url.'/css/image-box.css);'."\n".
13          "</style>\n";
14     }
15}
16class publicLastImages
17{
18     public static function lastImages(&$w)
19     {
20          global $core;
21         
22          if ($w->homeonly && $core->url->type != 'default') {
23               return;
24          }
25          $params['limit'] = '0';
26          $params['no_content'] = false;
27         
28          if ($w->category != '') {
29          $category  = $w->category;
30          $params['cat_url'] = explode(",", $category);
31          }
32          if ($w->selected == '1') {
33               $params['post_selected'] = '1';
34          }
35         
36          $rsp = $core->blog->getPosts($params);
37          if ($rsp->isEmpty()) {
38               return;
39          }
40
41          $size = $w->size;
42
43          $i = '1';
44          $ret = '<div class="images">';
45          $ret .= ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '');
46          $ret .= '<div class="wrapper">';
47          $nb_billets = $rsp->count();
48          $randIDs = array();
49          for ($j = 0; $j < $nb_billets; $j++) {
50
51               if ($w->random != '0') {
52                   
53                    $id = mt_rand(0, $nb_billets - 1);
54                   
55                    $key_attempts = 0;
56                    while (array_key_exists($id, $randIDs) && $key_attempts < 20) {
57                         $id = mt_rand(0, $nb_billets - 1);
58                         $key_attempts++;
59                    }
60                    $randIDs[$id] = TRUE;
61                    $rsp->index($id);
62               } else {
63                    $rsp->index($j);
64               }
65
66               // URL du billet
67               $full_url = $rsp->getURL();
68               
69               // Construction de la vignette
70               $img_src_regexp = '/<img .*?src="(.+?)"/i';
71               
72               if (($i <= abs((integer) $w->limit) || abs((integer) $w->limit) == '0') &&
73                    (preg_match($img_src_regexp,$rsp->post_excerpt_xhtml,$rs) || preg_match($img_src_regexp,$rsp->post_content_xhtml,$rs))) {
74                    $img_thumb = '<img ';
75                    $img_path = $rs[1];
76                    //découpage de l'url de l'image
77                   
78                    $img_path = parse_url($img_path, PHP_URL_PATH); //si url absolue ?
79                         
80                    $path_string = explode("/", $img_path);
81                    $img_name = array_pop ($path_string);
82                    $path_string = implode("/", $path_string);
83                    if (substr($img_name,0,1) == '.') {
84                         //c'est une miniature
85                         $replace = array ('_t.jpg','_sq.jpg','_s.jpg','_m.jpg');
86                         $img_short_name = str_replace($replace,'',$img_name);
87                         if ($size == 'o') {
88                              $img_thumb_name = $path_string.'/'.ltrim($img_short_name,'.').'.jpg';
89                         } else {
90                              $img_thumb_name = $path_string.'/'.$img_short_name.'_'.$size.'.jpg';
91                         }
92                    } else {
93                         //c'est l'originale
94                         $replace = array ('.jpg','.png','.gif');
95                         $img_short_name = str_replace($replace,'',$img_name);
96                         
97                         if ($size == 'o') {
98                              $img_thumb_name = $path_string.'/'.$img_name;
99                         } else {
100                              $img_thumb_name = $path_string.'/.'.$img_short_name.'_'.$size.'.jpg';
101                         }
102                    }
103                    // Test si la miniature demandée existe
104                   
105                    $public_string = $core->blog->settings->public_url;
106                    $file_name = $core->blog->settings->public_path.str_replace($public_string,'',$img_thumb_name);
107
108                    if (file_exists($file_name)) {
109                   
110                         $img_thumb .= 'src="'.$img_thumb_name.'" alt="'.$rsp->post_title.'"';
111                         $img_thumb .= ' />';
112                         
113                         // Mise en forme html
114                         $ret .= '<div class="img-box">'."\n";                 
115                         $ret .= '    <div class="img-thumbnail"><a title="'.$rsp->post_title.'" href="'.$full_url.'">'.$img_thumb.'</a></div>'."\n";
116                         $ret .= '</div>'."\n";
117                         
118                         $i++;
119                    }         
120               }
121          }
122          $ret .= '</div>'."\n";
123          $ret .= '</div>'."\n";
124          return $ret;
125     }
126}
127?>
Note: See TracBrowser for help on using the repository browser.

Sites map