| [ 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 # Blogroll template functions 24 25 require dirname(__FILE__).'/_widgets.php'; 26 27 $core->tpl->addValue('Blogroll',array('tplBlogroll','blogroll')); 28 $core->tpl->addValue('BlogrollXbelLink',array('tplBlogroll','blogrollXbelLink')); 29 30 $core->url->register('xbel','xbel','^xbel(?:/?)$',array('urlBlogroll','xbel')); 31 32 class tplBlogroll 33 { 34 public static function blogroll($attr) 35 { 36 $category='<h3>%s</h3>'; 37 $block='<ul>%s</ul>'; 38 $item='<li>%s</li>'; 39 40 if (isset($attr['category'])) { 41 $category = addslashes($attr['category']); 42 } 43 44 if (isset($attr['block'])) { 45 $block = addslashes($attr['block']); 46 } 47 48 if (isset($attr['item'])) { 49 $item = addslashes($attr['item']); 50 } 51 52 return 53 '<?php '. 54 "echo tplBlogroll::getList('".$category."','".$block."','".$item."'); ". 55 '?>'; 56 } 57 58 public static function blogrollXbelLink($attr) 59 { 60 $f = $GLOBALS['core']->tpl->getFilters($attr); 61 return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getBase("xbel")').'; ?>'; 62 } 63 64 public static function getList($category='<h3>%s</h3>',$block='<ul>%s</ul>',$item='<li>%s</li>') 65 { 66 require_once dirname(__FILE__).'/class.dc.blogroll.php'; 67 $blogroll = new dcBlogroll($GLOBALS['core']->blog); 68 69 try { 70 $links = $blogroll->getLinks(); 71 } catch (Exception $e) { 72 return false; 73 } 74 75 $res = ''; 76 77 foreach ($blogroll->getLinksHierarchy($links) as $k => $v) 78 { 79 if ($k != '') { 80 $res .= sprintf($category,html::escapeHTML($k))."\n"; 81 } 82 83 $res .= self::getLinksList($v,$block,$item); 84 } 85 86 return $res; 87 } 88 89 private static function getLinksList($links,$block='<ul>%s</ul>',$item='<li>%s</li>') 90 { 91 $list = ''; 92 93 foreach ($links as $v) 94 { 95 $title = $v['link_title']; 96 $href = $v['link_href']; 97 $desc = $v['link_desc']; 98 $lang = $v['link_lang']; 99 $xfn = $v['link_xfn']; 100 101 $link = 102 '<a href="'.html::escapeHTML($href).'"'. 103 ((!$lang) ? '' : ' hreflang="'.html::escapeHTML($lang).'"'). 104 ((!$desc) ? '' : ' title="'.html::escapeHTML($desc).'"'). 105 ((!$xfn) ? '' : ' rel="'.html::escapeHTML($xfn).'"'). 106 '>'. 107 html::escapeHTML($title). 108 '</a>'; 109 110 $list .= sprintf($item,$link)."\n"; 111 } 112 113 return sprintf($block,$list)."\n"; 114 } 115 116 # Widget function 117 public static function linksWidget(&$w) 118 { 119 global $core; 120 121 if ($w->homeonly && $core->url->type != 'default') { 122 return; 123 } 124 125 return 126 '<div class="links">'. 127 ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). 128 self::getList('<h3>%s</h3>','<ul>%s</ul>','<li>%s</li>'). 129 '</div>'; 130 } 131 } 132 133 class urlBlogroll extends dcUrlHandlers 134 { 135 public static function xbel($args) 136 { 137 require dirname(__FILE__).'/class.dc.blogroll.php'; 138 $blogroll = new dcBlogroll($GLOBALS['core']->blog); 139 140 try { 141 $links = $blogroll->getLinks(); 142 } catch (Exception $e) { 143 self::p404(); 144 } 145 146 if ($args) { 147 self::p404(); 148 } 149 150 http::cache($GLOBALS['mod_files'],$GLOBALS['mod_ts']); 151 152 header('Content-Type: text/xml; charset=UTF-8'); 153 154 echo 155 '<?xml version="1.0" encoding="UTF-8"?>'."\n". 156 '<!DOCTYPE xbel PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange '. 157 'Language 1.0//EN//XML"'."\n". 158 '"http://www.python.org/topics/xml/dtds/xbel-1.0.dtd">'."\n". 159 '<xbel version="1.0">'."\n". 160 '<title>'.html::escapeHTML($GLOBALS['core']->blog->name)." blogroll</title>\n"; 161 162 $i = 1; 163 foreach ($blogroll->getLinksHierarchy($links) as $cat_title => $links) 164 { 165 if ($cat_title != '') { 166 echo 167 '<folder>'."\n". 168 "<title>".html::escapeHTML($cat_title)."</title>\n"; 169 } 170 171 foreach ($links as $k => $v) 172 { 173 $lang = $v['link_lang'] ? ' xml:lang="'.$v['link_lang'].'"' : ''; 174 175 echo 176 '<bookmark href="'.$v['link_href'].'"'.$lang.'>'."\n". 177 '<title>'.html::escapeHTML($v['link_title'])."</title>\n"; 178 179 if ($v['link_desc']) { 180 echo '<desc>'.html::escapeHTML($v['link_desc'])."</desc>\n"; 181 } 182 183 if ($v['link_xfn']) { 184 echo 185 "<info>\n". 186 '<metadata owner="http://gmpg.org/xfn/">'.$v['link_xfn']."</metadata>\n". 187 "</info>\n"; 188 } 189 190 echo 191 "</bookmark>\n"; 192 } 193 194 if ($cat_title != '') { 195 echo "</folder>\n"; 196 } 197 198 $i++; 199 } 200 201 echo 202 '</xbel>'; 203 204 exit; 205 } 206 } 207 ?>
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 |