[ Index ] |
|
Code source de Dotclear 2.0-beta6 |
1 <?php 2 # ***** BEGIN LICENSE BLOCK ***** 3 # This file is part of DotClear. 4 # Copyright (c) 2005 Olivier Meunier and contributors. All rights 5 # reserved. 6 # 7 # DotClear is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # DotClear is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with DotClear; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 # 21 # ***** END LICENSE BLOCK ***** 22 23 require dirname(__FILE__).'/_widgets.php'; 24 25 $core->tpl->addBlock('MetaData',array('tplMetadata','MetaData')); 26 $core->tpl->addBlock('MetaDataHeader',array('tplMetadata','MetaDataHeader')); 27 $core->tpl->addBlock('MetaDataFooter',array('tplMetadata','MetaDataFooter')); 28 $core->tpl->addValue('MetaID',array('tplMetadata','MetaID')); 29 $core->tpl->addValue('MetaPercent',array('tplMetadata','MetaPercent')); 30 $core->tpl->addValue('MetaRoundPercent',array('tplMetadata','MetaRoundPercent')); 31 $core->tpl->addValue('MetaURL',array('tplMetadata','MetaURL')); 32 $core->tpl->addValue('MetaAllURL',array('tplMetadata','MetaAllURL')); 33 $core->tpl->addValue('TagFeedURL',array('tplMetadata','TagFeedURL')); 34 $core->tpl->addBlock('EntryMetaData',array('tplMetadata','EntryMetaData')); 35 36 $core->addBehavior('templateBeforeBlock',array('behaviorsMetadata','templateBeforeBlock')); 37 38 class behaviorsMetadata 39 { 40 public static function templateBeforeBlock(&$core,$b,$attr) 41 { 42 if (($b == 'Entries' || $b == 'Comments') && isset($attr['tag'])) 43 { 44 return 45 "<?php\n". 46 "@\$params['from'] .= ', '.\$core->prefix.'meta META ';\n". 47 "@\$params['sql'] .= 'AND META.post_id = P.post_id ';\n". 48 "\$params['sql'] .= \"AND META.meta_type = 'tag' \";\n". 49 "\$params['sql'] .= \"AND META.meta_id = '".$core->con->escape($attr['tag'])."' \";\n". 50 "?>\n"; 51 } 52 elseif ($b == 'Entries' || $b == 'Comments') 53 { 54 return 55 '<?php if ($_ctx->exists("meta")) { '. 56 "@\$params['from'] .= ', '.\$core->prefix.'meta META ';\n". 57 "@\$params['sql'] .= 'AND META.post_id = P.post_id ';\n". 58 "\$params['sql'] .= \"AND META.meta_type = 'tag' \";\n". 59 "\$params['sql'] .= \"AND META.meta_id = '\".\$core->con->escape(\$_ctx->meta->meta_id).\"' \";\n". 60 "} ?>\n"; 61 } 62 } 63 } 64 65 class tplMetadata 66 { 67 public static function MetaData($attr,$content) 68 { 69 $type = isset($attr['type']) ? addslashes($attr['type']) : 'tag'; 70 71 $limit = isset($attr['limit']) ? (integer) $attr['limit'] : 'null'; 72 73 $sortby = 'meta_id_lower'; 74 if (isset($attr['sortby']) && $attr['sortby'] == 'count') { 75 $sortby = 'count'; 76 } 77 78 $order = 'asc'; 79 if (isset($attr['order']) && $attr['order'] == 'desc') { 80 $order = 'desc'; 81 } 82 83 $res = 84 "<?php\n". 85 '$objMeta = new dcMeta($core); '. 86 "\$_ctx->meta = \$objMeta->getMeta('".$type."',".$limit."); ". 87 "\$_ctx->meta->sort('".$sortby."','".$order."'); ". 88 '?>'; 89 90 $res .= 91 '<?php while ($_ctx->meta->fetch()) : ?>'.$content.'<?php endwhile; '. 92 '$_ctx->meta = null; unset($objMeta); ?>'; 93 94 return $res; 95 } 96 97 public static function MetaDataHeader($attr,$content) 98 { 99 return 100 "<?php if (\$_ctx->meta->isStart()) : ?>". 101 $content. 102 "<?php endif; ?>"; 103 } 104 105 public static function MetaDataFooter($attr,$content) 106 { 107 return 108 "<?php if (\$_ctx->meta->isEnd()) : ?>". 109 $content. 110 "<?php endif; ?>"; 111 } 112 113 public static function EntryMetaData($attr,$content) 114 { 115 $type = isset($attr['type']) ? addslashes($attr['type']) : 'tag'; 116 117 $sortby = 'meta_id_lower'; 118 if (isset($attr['sortby']) && $attr['sortby'] == 'count') { 119 $sortby = 'count'; 120 } 121 122 $order = 'asc'; 123 if (isset($attr['order']) && $attr['order'] == 'desc') { 124 $order = 'desc'; 125 } 126 127 $res = 128 "<?php\n". 129 '$objMeta = new dcMeta($core); '. 130 "\$_ctx->meta = \$objMeta->getMetaRecordset(\$_ctx->posts->post_meta,'".$type."'); ". 131 "\$_ctx->meta->sort('".$sortby."','".$order."'); ". 132 '?>'; 133 134 $res .= 135 '<?php while ($_ctx->meta->fetch()) : ?>'.$content.'<?php endwhile; '. 136 '$_ctx->meta = null; unset($objMeta); ?>'; 137 138 return $res; 139 } 140 141 public static function MetaID($attr) 142 { 143 $f = $GLOBALS['core']->tpl->getFilters($attr); 144 return '<?php echo '.sprintf($f,'$_ctx->meta->meta_id').'; ?>'; 145 } 146 147 public static function MetaPercent($attr) 148 { 149 return '<?php echo $_ctx->meta->percent; ?>'; 150 } 151 152 public static function MetaRoundPercent($attr) 153 { 154 return '<?php echo $_ctx->meta->roundpercent; ?>'; 155 } 156 157 public static function MetaURL($attr) 158 { 159 $f = $GLOBALS['core']->tpl->getFilters($attr); 160 return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getBase("tag").'. 161 '"/".rawurlencode($_ctx->meta->meta_id)').'; ?>'; 162 } 163 164 public static function MetaAllURL($attr) 165 { 166 $f = $GLOBALS['core']->tpl->getFilters($attr); 167 return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getBase("tags")').'; ?>'; 168 } 169 170 public static function TagFeedURL($attr) 171 { 172 $type = !empty($attr['type']) ? $attr['type'] : 'rss2'; 173 174 if (!preg_match('#^(rss2|atom)$#',$type)) { 175 $type = 'rss2'; 176 } 177 178 $f = $GLOBALS['core']->tpl->getFilters($attr); 179 return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getBase("tag_feed")."/".'. 180 'rawurlencode($_ctx->meta->meta_id)."/'.$type.'"').'; ?>'; 181 } 182 183 # Widget function 184 public static function tagsWidget(&$w) 185 { 186 global $core; 187 188 $limit = abs((integer) $w->limit); 189 190 $objMeta = new dcMeta($core); 191 $rs = $objMeta->getMeta('tag',$limit); 192 193 if ($rs->isEmpty()) { 194 return; 195 } 196 197 $sort = $w->sortby; 198 if (!in_array($sort,array('meta_id_lower','count'))) { 199 $sort = 'meta_id_lower'; 200 } 201 202 $order = $w->orderby; 203 if ($order != 'asc') { 204 $order = 'desc'; 205 } 206 207 $rs->sort($sort,$order); 208 209 $res = 210 '<div class="tags">'. 211 ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). 212 '<ul>'; 213 214 while ($rs->fetch()) 215 { 216 $res .= 217 '<li><a href="'.$core->blog->url.$core->url->getBase('tag').'/'.rawurlencode($rs->meta_id).'" '. 218 'class="tag'.$rs->roundpercent.'">'. 219 $rs->meta_id.'</a> </li>'; 220 } 221 222 $res .= '</ul>'. 223 '<p><strong><a href="'.$core->blog->url.$core->url->getBase("tags").'">'. 224 __('All tags').'</a></strong></p>'. 225 '</div>'; 226 227 return $res; 228 } 229 } 230 231 class urlMetadata extends dcUrlHandlers 232 { 233 public static function tag($args) 234 { 235 $n = self::getPageNumber($args); 236 237 if ($args == '' && !$n) 238 { 239 self::p404(); 240 } 241 elseif (preg_match('%(.*?)/feed/(rss2|atom)?$%u',$args,$m)) 242 { 243 $type = $m[2] == 'atom' ? 'atom' : 'rss2'; 244 $mime = 'application/xml'; 245 $comments = !empty($m[3]); 246 247 $objMeta = new dcMeta($GLOBALS['core']); 248 $GLOBALS['_ctx']->meta = $objMeta->getMeta('tag',null,$m[1]); 249 250 if ($GLOBALS['_ctx']->meta->isEmpty()) { 251 self::p404(); 252 } 253 254 $tpl = $type; 255 256 if ($type == 'atom') { 257 $mime = 'application/atom+xml'; 258 } 259 260 self::serveDocument($tpl.'.xml',$mime); 261 } 262 else 263 { 264 if ($n) { 265 $GLOBALS['_page_number'] = $n; 266 } 267 268 $objMeta = new dcMeta($GLOBALS['core']); 269 $GLOBALS['_ctx']->meta = $objMeta->getMeta('tag',null,$args); 270 271 if ($GLOBALS['_ctx']->meta->isEmpty()) { 272 self::p404(); 273 } else { 274 self::serveDocument('tag.html'); 275 } 276 } 277 exit; 278 } 279 280 public static function tags($args) 281 { 282 self::serveDocument('tags.html'); 283 exit; 284 } 285 286 public static function tagFeed($args) 287 { 288 $mime = 'application/xml'; 289 290 if (preg_match('#^(.+)/(atom|rss2)(/comments)?$#',$args,$m)) 291 { 292 $tag = $m[1]; 293 $type = $m[2]; 294 $comments = !empty($m[3]); 295 } 296 else 297 { 298 self::p404(); 299 } 300 301 $objMeta = new dcMeta($GLOBALS['core']); 302 $GLOBALS['_ctx']->meta = $objMeta->getMeta('tag',null,$tag); 303 $GLOBALS['_ctx']->feed_subtitle = ' - '.$GLOBALS['_ctx']->meta->meta_id; 304 305 if ($GLOBALS['_ctx']->meta->isEmpty()) { 306 self::p404(); 307 } 308 309 if ($type == 'atom') { 310 $mime = 'application/atom+xml'; 311 } 312 313 $tpl = $type; 314 if ($comments) { 315 $tpl .= '-comments'; 316 } 317 $tpl .= '.xml'; 318 319 self::serveDocument($tpl,$mime); 320 exit; 321 } 322 } 323 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Feb 23 22:16:06 2007 | par Balluche grâce à PHPXref 0.7 |