Dotclear

source: plugins/lastImages/_public.php @ 1704

Revision 1704, 3.9 KB checked in by kozlika, 13 years ago (diff)

Spéciale cassededi pour Philippe le Rebelle histoire que je puisse corriger ses plougs.

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

Sites map