Dotclear


Ignore:
Timestamp:
07/31/12 13:52:11 (13 years ago)
Author:
Dsls <dsls@…>
Branch:
sexy
Message:

sexy step 2 : no more cats.

Location:
inc/public
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • inc/public/class.dc.template.php

    r848 r851  
    6868          $this->addValue('BlogMetaRobots',array($this,'BlogMetaRobots')); 
    6969           
    70           # Categories 
    71           $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            
    8370          # Entries 
    8471          $this->addBlock('DateFooter',array($this,'DateFooter')); 
     
    9582          $this->addValue('EntryAuthorURL',array($this,'EntryAuthorURL')); 
    9683          $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')); 
    10284          $this->addValue('EntryContent',array($this,'EntryContent')); 
    10385          $this->addValue('EntryDate',array($this,'EntryDate')); 
     
    458440     <!ATTLIST tpl:Archives 
    459441     type      (day|month|year)    #IMPLIED  -- Get days, months or years, default to month -- 
    460      category  CDATA               #IMPLIED  -- Get dates of given category -- 
    461442     no_context (1|0)              #IMPLIED  -- Override context information 
    462443     order     (asc|desc)          #IMPLIED  -- Sort asc or desc -- 
     
    473454          } 
    474455           
    475           if (isset($attr['category'])) { 
    476                $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n"; 
    477           } 
    478          
    479456          if (isset($attr['post_type'])) { 
    480457               $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n"; 
     
    483460          if (isset($attr['post_lang'])) { 
    484461               $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"; 
    493462          } 
    494463           
     
    851820     } 
    852821      
    853      /* Categories ----------------------------------------- */ 
    854       
    855      /*dtd 
    856      <!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      /*dtd 
    887      <!ELEMENT tpl:CategoriesHeader - - -- First Categories result container --> 
    888      */ 
    889      public function CategoriesHeader($attr,$content) 
    890      { 
    891           return 
    892           "<?php if (\$_ctx->categories->isStart()) : ?>". 
    893           $content. 
    894           "<?php endif; ?>"; 
    895      } 
    896       
    897      /*dtd 
    898      <!ELEMENT tpl:CategoriesFooter - - -- Last Categories result container --> 
    899      */ 
    900      public function CategoriesFooter($attr,$content) 
    901      { 
    902           return 
    903           "<?php if (\$_ctx->categories->isEnd()) : ?>". 
    904           $content. 
    905           "<?php endif; ?>"; 
    906      } 
    907       
    908      /*dtd 
    909      <!ELEMENT tpl:CategoryIf - - -- tests on current entry --> 
    910      <!ATTLIST tpl:CategoryIf 
    911      url       CDATA     #IMPLIED  -- category has given url 
    912      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      /*dtd 
    951      <!ELEMENT tpl:CategoryFirstChildren - - -- Current category first children loop --> 
    952      */ 
    953      public function CategoryFirstChildren($attr,$content) 
    954      { 
    955           return 
    956           "<?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      /*dtd 
    962      <!ELEMENT tpl:CategoryParents - - -- Current category parents loop --> 
    963      */ 
    964      public function CategoryParents($attr,$content) 
    965      { 
    966           return 
    967           "<?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      /*dtd 
    973      <!ELEMENT tpl:CategoryFeedURL - O -- Category feed URL --> 
    974      <!ATTLIST tpl:CategoryFeedURL 
    975      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      /*dtd 
    992      <!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      /*dtd 
    1002      <!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      /*dtd 
    1011      <!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      /*dtd 
    1020      <!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       
    1028822     /* Entries -------------------------------------------- */ 
    1029823     /*dtd 
     
    1032826     lastn     CDATA     #IMPLIED  -- limit number of results to specified value 
    1033827     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 category 
    1036828     no_context (1|0)    #IMPLIED  -- Override context information 
    1037829     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) 
     
    1072864          } 
    1073865           
    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            
    1084866          if (!empty($attr['type'])) { 
    1085867               $p .= "\$params['post_type'] = preg_split('/\s*,\s*/','".addslashes($attr['type'])."',-1,PREG_SPLIT_NO_EMPTY);\n"; 
     
    1097879                    'if ($_ctx->exists("users")) { '. 
    1098880                         "\$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; ". 
    1107881                    "}\n"; 
    1108882               } 
     
    1185959     <!ATTLIST tpl:EntryIf 
    1186960     type CDATA     #IMPLIED  -- post has a given type (default: "post") 
    1187      category  CDATA     #IMPLIED  -- post has a given category 
    1188961     first     (0|1)     #IMPLIED  -- post is the first post from list (value : 1) or not (value : 0) 
    1189962     odd  (0|1)     #IMPLIED  -- post is in an odd position (value : 1) or not (value : 0) 
     
    1191964     extended  (0|1)     #IMPLIED  -- post has an excerpt (value : 1) or not (value : 0) 
    1192965     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) 
    1194966     has_attachment (0|1)     #IMPLIED  -- post has attachments (value : 1) or not (value : 0) (see Attachment plugin for code) 
    1195967     operator  (and|or)  #IMPLIED  -- combination of conditions, if more than 1 specifiec (default: and) 
     
    1201973          $if = new ArrayObject(); 
    1202974          $extended = null; 
    1203           $hascategory = null; 
    1204975           
    1205976          $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; 
     
    1221992          } 
    1222993           
    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            
    1233994          if (isset($attr['first'])) { 
    1234995               $sign = (boolean) $attr['first'] ? '=' : '!'; 
     
    12491010               $sign = (boolean) $attr['selected'] ? '' : '!'; 
    12501011               $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'; 
    12561012          } 
    12571013           
     
    14301186      
    14311187     /*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      /*dtd 
    1441      <!ELEMENT tpl:EntryCategoriesBreadcrumb - - -- Current entry parents loop (without last one) --> 
    1442      */ 
    1443      public function EntryCategoriesBreadcrumb($attr,$content) 
    1444      { 
    1445           return 
    1446           "<?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      /*dtd 
    1452      <!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      /*dtd 
    1461      <!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      /*dtd 
    1470      <!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      /*dtd 
    14801188     <!ELEMENT tpl:EntryFeedID - O -- Entry feed ID --> 
    14811189     */ 
     
    14911199     size           (sq|t|s|m|o)   #IMPLIED  -- Image size to extract 
    14921200     class          CDATA          #IMPLIED  -- Class to add on image tag 
    1493      with_category  (1|0)          #IMPLIED  -- Search in entry category description if present (default 0) 
    14941201     > 
    14951202     */ 
     
    15001207          $with_category = !empty($attr['with_category']) ? 'true' : 'false'; 
    15011208           
    1502           return "<?php echo context::EntryFirstImageHelper('".addslashes($size)."',".$with_category.",'".addslashes($class)."'); ?>"; 
     1209          return "<?php echo context::EntryFirstImageHelper('".addslashes($size)."','".addslashes($class)."'); ?>"; 
    15031210     } 
    15041211      
     
    15291236     <!ELEMENT tpl:EntryNext - - -- Next entry block --> 
    15301237     <!ATTLIST tpl:EntryNext 
    1531      restrict_to_category     (0|1)     #IMPLIED  -- find next post in the same category (default: 0) 
    15321238     restrict_to_lang         (0|1)     #IMPLIED  -- find next post in the same language (default: 0) 
    15331239     > 
     
    18771583     <!ELEMENT tpl:SysIf - - -- System settings tester container --> 
    18781584     <!ATTLIST tpl:SysIf 
    1879      categories          (0|1)     #IMPLIED  -- test if categories are set in current context (value : 1) or not (value : 0) 
    18801585     posts               (0|1)     #IMPLIED  -- test if posts are set in current context (value : 1) or not (value : 0) 
    18811586     blog_lang           CDATA     #IMPLIED  -- tests if blog language is the one given in parameter 
     
    18941599           
    18951600          $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           } 
    19011601           
    19021602          if (isset($attr['posts'])) { 
  • inc/public/lib.tpl.context.php

    r839 r851  
    162162     } 
    163163      
    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       
    186164     # Static methods for pagination 
    187165     public static function PaginationNbPages() 
     
    341319      
    342320     # First post image helpers 
    343      public static function EntryFirstImageHelper($size,$with_category,$class="") 
     321     public static function EntryFirstImageHelper($size,$class="") 
    344322     { 
    345323          global $core, $_ctx; 
     
    378356          } 
    379357           
    380           # No src, look in category description if available 
    381           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            
    397358          if ($src) { 
    398359               return '<img alt="'.$alt.'" src="'.$src.'" class="'.$class.'" />'; 
  • inc/public/lib.urlhandlers.php

    r848 r851  
    245245               $_ctx->cur_lang = $args; 
    246246               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           else 
    262           { 
    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                else 
    276                { 
    277                     if ($n) { 
    278                          $GLOBALS['_page_number'] = $n; 
    279                     } 
    280                     self::serveDocument('category.html'); 
    281                } 
    282247          } 
    283248     } 
Note: See TracChangeset for help on using the changeset viewer.

Sites map