Changeset 851:0993f64c4809 for inc/public
- Timestamp:
- 07/31/12 13:52:11 (13 years ago)
- Branch:
- sexy
- Location:
- inc/public
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/public/class.dc.template.php
r848 r851 68 68 $this->addValue('BlogMetaRobots',array($this,'BlogMetaRobots')); 69 69 70 # Categories71 $this->addBlock('Categories',array($this,'Categories'));72 $this->addBlock('CategoriesHeader',array($this,'CategoriesHeader'));73 $this->addBlock('CategoriesFooter',array($this,'CategoriesFooter'));74 $this->addBlock('CategoryIf',array($this,'CategoryIf'));75 $this->addBlock('CategoryFirstChildren',array($this,'CategoryFirstChildren'));76 $this->addBlock('CategoryParents',array($this,'CategoryParents'));77 $this->addValue('CategoryFeedURL',array($this,'CategoryFeedURL'));78 $this->addValue('CategoryURL',array($this,'CategoryURL'));79 $this->addValue('CategoryShortURL',array($this,'CategoryShortURL'));80 $this->addValue('CategoryDescription',array($this,'CategoryDescription'));81 $this->addValue('CategoryTitle',array($this,'CategoryTitle'));82 83 70 # Entries 84 71 $this->addBlock('DateFooter',array($this,'DateFooter')); … … 95 82 $this->addValue('EntryAuthorURL',array($this,'EntryAuthorURL')); 96 83 $this->addValue('EntryBasename',array($this,'EntryBasename')); 97 $this->addValue('EntryCategory',array($this,'EntryCategory'));98 $this->addBlock('EntryCategoriesBreadcrumb',array($this,'EntryCategoriesBreadcrumb'));99 $this->addValue('EntryCategoryID',array($this,'EntryCategoryID'));100 $this->addValue('EntryCategoryURL',array($this,'EntryCategoryURL'));101 $this->addValue('EntryCategoryShortURL',array($this,'EntryCategoryShortURL'));102 84 $this->addValue('EntryContent',array($this,'EntryContent')); 103 85 $this->addValue('EntryDate',array($this,'EntryDate')); … … 458 440 <!ATTLIST tpl:Archives 459 441 type (day|month|year) #IMPLIED -- Get days, months or years, default to month -- 460 category CDATA #IMPLIED -- Get dates of given category --461 442 no_context (1|0) #IMPLIED -- Override context information 462 443 order (asc|desc) #IMPLIED -- Sort asc or desc -- … … 473 454 } 474 455 475 if (isset($attr['category'])) {476 $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n";477 }478 479 456 if (isset($attr['post_type'])) { 480 457 $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n"; … … 483 460 if (isset($attr['post_lang'])) { 484 461 $p .= "\$params['post_lang'] = '".addslashes($attr['post_lang'])."';\n"; 485 }486 487 if (empty($attr['no_context']) && !isset($attr['category']))488 {489 $p .=490 'if ($_ctx->exists("categories")) { '.491 "\$params['cat_id'] = \$_ctx->categories->cat_id; ".492 "}\n";493 462 } 494 463 … … 851 820 } 852 821 853 /* Categories ----------------------------------------- */854 855 /*dtd856 <!ELEMENT tpl:Categories - - -- Categories loop -->857 */858 public function Categories($attr,$content)859 {860 $p = "if (!isset(\$params)) \$params = array();\n";861 862 if (isset($attr['url'])) {863 $p .= "\$params['cat_url'] = '".addslashes($attr['url'])."';\n";864 }865 866 if (!empty($attr['post_type'])) {867 $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n";868 }869 870 if (!empty($attr['level'])) {871 $p .= "\$params['level'] = ".(integer) $attr['level'].";\n";872 }873 874 $res = "<?php\n";875 $res .= $p;876 $res .= $this->core->callBehavior("templatePrepareParams",877 array("tag" => "Categories","method" => "blog::getCategories"),878 $attr,$content);879 $res .= '$_ctx->categories = $core->blog->getCategories($params);'."\n";880 $res .= "?>\n";881 $res .= '<?php while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; unset($params); ?>';882 883 return $res;884 }885 886 /*dtd887 <!ELEMENT tpl:CategoriesHeader - - -- First Categories result container -->888 */889 public function CategoriesHeader($attr,$content)890 {891 return892 "<?php if (\$_ctx->categories->isStart()) : ?>".893 $content.894 "<?php endif; ?>";895 }896 897 /*dtd898 <!ELEMENT tpl:CategoriesFooter - - -- Last Categories result container -->899 */900 public function CategoriesFooter($attr,$content)901 {902 return903 "<?php if (\$_ctx->categories->isEnd()) : ?>".904 $content.905 "<?php endif; ?>";906 }907 908 /*dtd909 <!ELEMENT tpl:CategoryIf - - -- tests on current entry -->910 <!ATTLIST tpl:CategoryIf911 url CDATA #IMPLIED -- category has given url912 has_entries (0|1) #IMPLIED -- post is the first post from list (value : 1) or not (value : 0)913 has_description (0|1) #IMPLIED -- category has description (value : 1) or not (value : 0)914 >915 */916 public function CategoryIf($attr,$content)917 {918 $if = new ArrayObject();919 $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&';920 921 if (isset($attr['url'])) {922 $url = addslashes(trim($attr['url']));923 if (substr($url,0,1) == '!') {924 $url = substr($url,1);925 $if[] = '($_ctx->categories->cat_url != "'.$url.'")';926 } else {927 $if[] = '($_ctx->categories->cat_url == "'.$url.'")';928 }929 }930 931 if (isset($attr['has_entries'])) {932 $sign = (boolean) $attr['has_entries'] ? '>' : '==';933 $if[] = '$_ctx->categories->nb_post '.$sign.' 0';934 }935 936 if (isset($attr['has_description'])) {937 $sign = (boolean) $attr['has_description'] ? '!=' : '==';938 $if[] = '$_ctx->categories->cat_desc '.$sign.' ""';939 }940 941 $this->core->callBehavior('tplIfConditions','CategoryIf',$attr,$content,$if);942 943 if (count($if) != 0) {944 return '<?php if('.implode(' '.$operator.' ', (array) $if).') : ?>'.$content.'<?php endif; ?>';945 } else {946 return $content;947 }948 }949 950 /*dtd951 <!ELEMENT tpl:CategoryFirstChildren - - -- Current category first children loop -->952 */953 public function CategoryFirstChildren($attr,$content)954 {955 return956 "<?php\n".957 '$_ctx->categories = $core->blog->getCategoryFirstChildren($_ctx->categories->cat_id);'."\n".958 'while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; ?>';959 }960 961 /*dtd962 <!ELEMENT tpl:CategoryParents - - -- Current category parents loop -->963 */964 public function CategoryParents($attr,$content)965 {966 return967 "<?php\n".968 '$_ctx->categories = $core->blog->getCategoryParents($_ctx->categories->cat_id);'."\n".969 'while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; ?>';970 }971 972 /*dtd973 <!ELEMENT tpl:CategoryFeedURL - O -- Category feed URL -->974 <!ATTLIST tpl:CategoryFeedURL975 type (rss2|atom) #IMPLIED -- feed type (default : rss2)976 >977 */978 public function CategoryFeedURL($attr)979 {980 $type = !empty($attr['type']) ? $attr['type'] : 'atom';981 982 if (!preg_match('#^(rss2|atom)$#',$type)) {983 $type = 'atom';984 }985 986 $f = $this->getFilters($attr);987 return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getURLFor("feed","category/".'.988 '$_ctx->categories->cat_url."/'.$type.'")').'; ?>';989 }990 991 /*dtd992 <!ELEMENT tpl:CategoryURL - O -- Category URL (complete iabsolute URL, including blog URL) -->993 */994 public function CategoryURL($attr)995 {996 $f = $this->getFilters($attr);997 return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getURLFor("category",'.998 '$_ctx->categories->cat_url)').'; ?>';999 }1000 1001 /*dtd1002 <!ELEMENT tpl:CategoryShortURL - O -- Category short URL (relative URL, from /category/) -->1003 */1004 public function CategoryShortURL($attr)1005 {1006 $f = $this->getFilters($attr);1007 return '<?php echo '.sprintf($f,'$_ctx->categories->cat_url').'; ?>';1008 }1009 1010 /*dtd1011 <!ELEMENT tpl:CategoryDescription - O -- Category description -->1012 */1013 public function CategoryDescription($attr)1014 {1015 $f = $this->getFilters($attr);1016 return '<?php echo '.sprintf($f,'$_ctx->categories->cat_desc').'; ?>';1017 }1018 1019 /*dtd1020 <!ELEMENT tpl:CategoryTitle - O -- Category title -->1021 */1022 public function CategoryTitle($attr)1023 {1024 $f = $this->getFilters($attr);1025 return '<?php echo '.sprintf($f,'$_ctx->categories->cat_title').'; ?>';1026 }1027 1028 822 /* Entries -------------------------------------------- */ 1029 823 /*dtd … … 1032 826 lastn CDATA #IMPLIED -- limit number of results to specified value 1033 827 author CDATA #IMPLIED -- get entries for a given user id 1034 category CDATA #IMPLIED -- get entries for specific categories only (multiple comma-separated categories can be specified. Use "!" as prefix to exclude a category)1035 no_category CDATA #IMPLIED -- get entries without category1036 828 no_context (1|0) #IMPLIED -- Override context information 1037 829 sortby (title|selected|author|date|id) #IMPLIED -- specify entries sort criteria (default : date) (multiple comma-separated sortby can be specified. Use "?asc" or "?desc" as suffix to provide an order for each sorby) … … 1072 864 } 1073 865 1074 if (isset($attr['category'])) {1075 $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n";1076 $p .= "context::categoryPostParam(\$params);\n";1077 }1078 1079 if (isset($attr['no_category']) && $attr['no_category']) {1080 $p .= "@\$params['sql'] .= ' AND P.cat_id IS NULL ';\n";1081 $p .= "unset(\$params['cat_url']);\n";1082 }1083 1084 866 if (!empty($attr['type'])) { 1085 867 $p .= "\$params['post_type'] = preg_split('/\s*,\s*/','".addslashes($attr['type'])."',-1,PREG_SPLIT_NO_EMPTY);\n"; … … 1097 879 'if ($_ctx->exists("users")) { '. 1098 880 "\$params['user_id'] = \$_ctx->users->user_id; ". 1099 "}\n";1100 }1101 1102 if (!isset($attr['category']) && (!isset($attr['no_category']) || !$attr['no_category']))1103 {1104 $p .=1105 'if ($_ctx->exists("categories")) { '.1106 "\$params['cat_id'] = \$_ctx->categories->cat_id; ".1107 881 "}\n"; 1108 882 } … … 1185 959 <!ATTLIST tpl:EntryIf 1186 960 type CDATA #IMPLIED -- post has a given type (default: "post") 1187 category CDATA #IMPLIED -- post has a given category1188 961 first (0|1) #IMPLIED -- post is the first post from list (value : 1) or not (value : 0) 1189 962 odd (0|1) #IMPLIED -- post is in an odd position (value : 1) or not (value : 0) … … 1191 964 extended (0|1) #IMPLIED -- post has an excerpt (value : 1) or not (value : 0) 1192 965 selected (0|1) #IMPLIED -- post is selected (value : 1) or not (value : 0) 1193 has_category (0|1) #IMPLIED -- post has a category (value : 1) or not (value : 0)1194 966 has_attachment (0|1) #IMPLIED -- post has attachments (value : 1) or not (value : 0) (see Attachment plugin for code) 1195 967 operator (and|or) #IMPLIED -- combination of conditions, if more than 1 specifiec (default: and) … … 1201 973 $if = new ArrayObject(); 1202 974 $extended = null; 1203 $hascategory = null;1204 975 1205 976 $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; … … 1221 992 } 1222 993 1223 if (isset($attr['category'])) {1224 $category = addslashes(trim($attr['category']));1225 if (substr($category,0,1) == '!') {1226 $category = substr($category,1);1227 $if[] = '($_ctx->posts->cat_url != "'.$category.'")';1228 } else {1229 $if[] = '($_ctx->posts->cat_url == "'.$category.'")';1230 }1231 }1232 1233 994 if (isset($attr['first'])) { 1234 995 $sign = (boolean) $attr['first'] ? '=' : '!'; … … 1249 1010 $sign = (boolean) $attr['selected'] ? '' : '!'; 1250 1011 $if[] = $sign.'(boolean)$_ctx->posts->post_selected'; 1251 }1252 1253 if (isset($attr['has_category'])) {1254 $sign = (boolean) $attr['has_category'] ? '' : '!';1255 $if[] = $sign.'$_ctx->posts->cat_id';1256 1012 } 1257 1013 … … 1430 1186 1431 1187 /*dtd 1432 <!ELEMENT tpl:EntryCategory - O -- Entry category (full name) -->1433 */1434 public function EntryCategory($attr)1435 {1436 $f = $this->getFilters($attr);1437 return '<?php echo '.sprintf($f,'$_ctx->posts->cat_title').'; ?>';1438 }1439 1440 /*dtd1441 <!ELEMENT tpl:EntryCategoriesBreadcrumb - - -- Current entry parents loop (without last one) -->1442 */1443 public function EntryCategoriesBreadcrumb($attr,$content)1444 {1445 return1446 "<?php\n".1447 '$_ctx->categories = $core->blog->getCategoryParents($_ctx->posts->cat_id);'."\n".1448 'while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; ?>';1449 }1450 1451 /*dtd1452 <!ELEMENT tpl:EntryCategoryID - O -- Entry category ID -->1453 */1454 public function EntryCategoryID($attr)1455 {1456 $f = $this->getFilters($attr);1457 return '<?php echo '.sprintf($f,'$_ctx->posts->cat_id').'; ?>';1458 }1459 1460 /*dtd1461 <!ELEMENT tpl:EntryCategoryURL - O -- Entry category URL -->1462 */1463 public function EntryCategoryURL($attr)1464 {1465 $f = $this->getFilters($attr);1466 return '<?php echo '.sprintf($f,'$_ctx->posts->getCategoryURL()').'; ?>';1467 }1468 1469 /*dtd1470 <!ELEMENT tpl:EntryCategoryShortURL - O -- Entry category short URL (relative URL, from /category/) -->1471 */1472 public function EntryCategoryShortURL($attr)1473 {1474 $f = $this->getFilters($attr);1475 return '<?php echo '.sprintf($f,'$_ctx->posts->cat_url').'; ?>';1476 }1477 1478 1479 /*dtd1480 1188 <!ELEMENT tpl:EntryFeedID - O -- Entry feed ID --> 1481 1189 */ … … 1491 1199 size (sq|t|s|m|o) #IMPLIED -- Image size to extract 1492 1200 class CDATA #IMPLIED -- Class to add on image tag 1493 with_category (1|0) #IMPLIED -- Search in entry category description if present (default 0)1494 1201 > 1495 1202 */ … … 1500 1207 $with_category = !empty($attr['with_category']) ? 'true' : 'false'; 1501 1208 1502 return "<?php echo context::EntryFirstImageHelper('".addslashes($size)."', ".$with_category.",'".addslashes($class)."'); ?>";1209 return "<?php echo context::EntryFirstImageHelper('".addslashes($size)."','".addslashes($class)."'); ?>"; 1503 1210 } 1504 1211 … … 1529 1236 <!ELEMENT tpl:EntryNext - - -- Next entry block --> 1530 1237 <!ATTLIST tpl:EntryNext 1531 restrict_to_category (0|1) #IMPLIED -- find next post in the same category (default: 0)1532 1238 restrict_to_lang (0|1) #IMPLIED -- find next post in the same language (default: 0) 1533 1239 > … … 1877 1583 <!ELEMENT tpl:SysIf - - -- System settings tester container --> 1878 1584 <!ATTLIST tpl:SysIf 1879 categories (0|1) #IMPLIED -- test if categories are set in current context (value : 1) or not (value : 0)1880 1585 posts (0|1) #IMPLIED -- test if posts are set in current context (value : 1) or not (value : 0) 1881 1586 blog_lang CDATA #IMPLIED -- tests if blog language is the one given in parameter … … 1894 1599 1895 1600 $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; 1896 1897 if (isset($attr['categories'])) {1898 $sign = (boolean) $attr['categories'] ? '!' : '=';1899 $if[] = '$_ctx->categories '.$sign.'== null';1900 }1901 1601 1902 1602 if (isset($attr['posts'])) { -
inc/public/lib.tpl.context.php
r839 r851 162 162 } 163 163 164 public static function categoryPostParam(&$p)165 {166 $not = substr($p['cat_url'],0,1) == '!';167 if ($not) {168 $p['cat_url'] = substr($p['cat_url'],1);169 }170 171 $p['cat_url'] = preg_split('/\s*,\s*/',$p['cat_url'],-1,PREG_SPLIT_NO_EMPTY);172 173 foreach ($p['cat_url'] as &$v)174 {175 if ($not) {176 $v .= ' ?not';177 }178 if ($GLOBALS['_ctx']->exists('categories') && preg_match('/#self/',$v)) {179 $v = preg_replace('/#self/',$GLOBALS['_ctx']->categories->cat_url,$v);180 } elseif ($GLOBALS['_ctx']->exists('posts') && preg_match('/#self/',$v)) {181 $v = preg_replace('/#self/',$GLOBALS['_ctx']->posts->cat_url,$v);182 }183 }184 }185 186 164 # Static methods for pagination 187 165 public static function PaginationNbPages() … … 341 319 342 320 # First post image helpers 343 public static function EntryFirstImageHelper($size,$ with_category,$class="")321 public static function EntryFirstImageHelper($size,$class="") 344 322 { 345 323 global $core, $_ctx; … … 378 356 } 379 357 380 # No src, look in category description if available381 if (!$src && $with_category && $_ctx->categories)382 {383 if (preg_match_all($pattern,$_ctx->categories->cat_desc,$m) > 0)384 {385 foreach ($m[1] as $i => $img) {386 if (($src = self::ContentFirstImageLookup($p_root,$img,$size)) !== false) {387 $src = $p_url.(dirname($img) != '/' ? dirname($img) : '').'/'.$src;388 if (preg_match('/alt="([^"]+)"/',$m[0][$i],$malt)) {389 $alt = $malt[1];390 }391 break;392 }393 }394 };395 }396 397 358 if ($src) { 398 359 return '<img alt="'.$alt.'" src="'.$src.'" class="'.$class.'" />'; -
inc/public/lib.urlhandlers.php
r848 r851 245 245 $_ctx->cur_lang = $args; 246 246 self::home(null); 247 }248 }249 250 public static function category($args)251 {252 $_ctx =& $GLOBALS['_ctx'];253 $core =& $GLOBALS['core'];254 255 $n = self::getPageNumber($args);256 257 if ($args == '' && !$n) {258 # No category was specified.259 self::p404();260 }261 else262 {263 $params = new ArrayObject(array(264 'cat_url' => $args,265 'post_type' => 'post'));266 267 $core->callBehavior('publicCategoryBeforeGetCategories',$params,$args);268 269 $_ctx->categories = $core->blog->getCategories($params);270 271 if ($_ctx->categories->isEmpty()) {272 # The specified category does no exist.273 self::p404();274 }275 else276 {277 if ($n) {278 $GLOBALS['_page_number'] = $n;279 }280 self::serveDocument('category.html');281 }282 247 } 283 248 }
Note: See TracChangeset
for help on using the changeset viewer.