Dotclear

Changeset 3965:b4e408d85ae5 for inc


Ignore:
Timestamp:
05/03/19 13:45:04 (6 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Allow ?sub for category/categories attributes of tpl:EntryIf, and for url/urls attributes of fpl:CategoryIf, closes #2295

Location:
inc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.blog.php

    r3874 r3965  
    457457    { 
    458458        return $this->getCategories(['start' => $id, 'level' => $id == 0 ? 1 : 2]); 
     459    } 
     460 
     461    /** 
     462     * Returns true if a given category if in a given category's subtree 
     463     * 
     464     * @param      string   $cat_url    The cat url 
     465     * @param      string   $start_url  The top cat url 
     466     * 
     467     * @return     boolean  true if cat_url is in given start_url cat subtree 
     468     */ 
     469    public function IsInCatSubtree($cat_url, $start_url) 
     470    { 
     471        // Get cat_id from start_url 
     472        $cat = $this->getCategories(['cat_url' => $start_url]); 
     473        if ($cat->fetch()) { 
     474            // cat_id found, get cat tree list 
     475            $cats = $this->getCategories(['start' => $cat->cat_id]); 
     476            while ($cats->fetch()) { 
     477                // check if post category is one of the cat or sub-cats 
     478                if ($cats->cat_url === $cat_url) { 
     479                    return true; 
     480                } 
     481            } 
     482        } 
     483        return false; 
    459484    } 
    460485 
  • inc/core/class.dc.rs.extensions.php

    r3874 r3965  
    457457        } 
    458458    } 
     459 
     460    /** 
     461     * Returns true if current category if in given cat_url subtree 
     462     * 
     463     * @param      record   $rs       Invisible parameter 
     464     * @param      string   $cat_url  The cat url 
     465     * 
     466     * @return     boolean  true if current cat is in given cat subtree 
     467     */ 
     468    public static function underCat($rs, $cat_url) 
     469    { 
     470        return $rs->core->blog->IsInCatSubtree($rs->cat_url, $cat_url); 
     471    } 
    459472} 
    460473 
  • inc/public/class.dc.template.php

    r3874 r3965  
    243243 
    244244        # --BEHAVIOR-- templateInsideBlock 
    245         $this->core->callBehavior('templateInsideBlock', $this->core, $this->current_tag, $attr, [&$content]); 
     245        $this->core->callBehavior('templateInsideBlock', $this->core, $this->current_tag, $attr, [ & $content]); 
    246246 
    247247        $res .= parent::compileBlockNode($this->current_tag, $attr, $content); 
     
    967967 
    968968        if (isset($attr['url'])) { 
    969             $url = addslashes(trim($attr['url'])); 
     969            $url  = addslashes(trim($attr['url'])); 
     970            $args = preg_split('/\s*[?]\s*/', $url, -1, PREG_SPLIT_NO_EMPTY); 
     971            $url  = array_shift($args); 
     972            $args = array_flip($args); 
    970973            if (substr($url, 0, 1) == '!') { 
    971                 $url  = substr($url, 1); 
    972                 $if[] = '($_ctx->categories->cat_url != "' . $url . '")'; 
     974                $url = substr($url, 1); 
     975                if (isset($args['sub'])) { 
     976                    $if[] = '(!$core->blog->IsInCatSubtree($_ctx->categories->cat_url, "' . $url . '"))'; 
     977                } else { 
     978                    $if[] = '($_ctx->categories->cat_url != "' . $url . '")'; 
     979                } 
    973980            } else { 
    974                 $if[] = '($_ctx->categories->cat_url == "' . $url . '")'; 
     981                if (isset($args['sub'])) { 
     982                    $if[] = '($core->blog->IsInCatSubtree($_ctx->categories->cat_url, "' . $url . '"))'; 
     983                } else { 
     984                    $if[] = '($_ctx->categories->cat_url == "' . $url . '")'; 
     985                } 
    975986            } 
    976987        } 
     
    980991            if (is_array($urls) && count($urls)) { 
    981992                foreach ($urls as $url) { 
     993                    $args = preg_split('/\s*[?]\s*/', trim($url), -1, PREG_SPLIT_NO_EMPTY); 
     994                    $url  = array_shift($args); 
     995                    $args = array_flip($args); 
    982996                    if (substr($url, 0, 1) == '!') { 
    983                         $url  = substr($url, 1); 
    984                         $if[] = '($_ctx->categories->cat_url != "' . $url . '")'; 
     997                        $url = substr($url, 1); 
     998                        if (isset($args['sub'])) { 
     999                            $if[] = '(!$core->blog->IsInCatSubtree($_ctx->categories->cat_url, "' . $url . '"))'; 
     1000                        } else { 
     1001                            $if[] = '($_ctx->categories->cat_url != "' . $url . '")'; 
     1002                        } 
    9851003                    } else { 
    986                         $if[] = '($_ctx->categories->cat_url == "' . $url . '")'; 
     1004                        if (isset($args['sub'])) { 
     1005                            $if[] = '($core->blog->IsInCatSubtree($_ctx->categories->cat_url, "' . $url . '"))'; 
     1006                        } else { 
     1007                            $if[] = '($_ctx->categories->cat_url == "' . $url . '")'; 
     1008                        } 
    9871009                    } 
    9881010                } 
     
    13251347        if (isset($attr['category'])) { 
    13261348            $category = addslashes(trim($attr['category'])); 
     1349            $args     = preg_split('/\s*[?]\s*/', $category, -1, PREG_SPLIT_NO_EMPTY); 
     1350            $category = array_shift($args); 
     1351            $args     = array_flip($args); 
    13271352            if (substr($category, 0, 1) == '!') { 
    13281353                $category = substr($category, 1); 
    1329                 $if[]     = '($_ctx->posts->cat_url != "' . $category . '")'; 
     1354                if (isset($args['sub'])) { 
     1355                    $if[] = '(!$_ctx->posts->underCat("' . $category . '"))'; 
     1356                } else { 
     1357                    $if[] = '($_ctx->posts->cat_url != "' . $category . '")'; 
     1358                } 
    13301359            } else { 
    1331                 $if[] = '($_ctx->posts->cat_url == "' . $category . '")'; 
     1360                if (isset($args['sub'])) { 
     1361                    $if[] = '($_ctx->posts->underCat("' . $category . '"))'; 
     1362                } else { 
     1363                    $if[] = '($_ctx->posts->cat_url == "' . $category . '")'; 
     1364                } 
    13321365            } 
    13331366        } 
     
    13371370            if (is_array($categories) && count($categories)) { 
    13381371                foreach ($categories as $category) { 
     1372                    $args     = preg_split('/\s*[?]\s*/', trim($category), -1, PREG_SPLIT_NO_EMPTY); 
     1373                    $category = array_shift($args); 
     1374                    $args     = array_flip($args); 
    13391375                    if (substr($category, 0, 1) == '!') { 
    13401376                        $category = substr($category, 1); 
    1341                         $if[]     = '($_ctx->posts->cat_url != "' . $category . '")'; 
     1377                        if (isset($args['sub'])) { 
     1378                            $if[] = '(!$_ctx->posts->underCat("' . $category . '"))'; 
     1379                        } else { 
     1380                            $if[] = '($_ctx->posts->cat_url != "' . $category . '")'; 
     1381                        } 
    13421382                    } else { 
    1343                         $if[] = '($_ctx->posts->cat_url == "' . $category . '")'; 
     1383                        if (isset($args['sub'])) { 
     1384                            $if[] = '($_ctx->posts->underCat("' . $category . '"))'; 
     1385                        } else { 
     1386                            $if[] = '($_ctx->posts->cat_url == "' . $category . '")'; 
     1387                        } 
    13441388                    } 
    13451389                } 
Note: See TracChangeset for help on using the changeset viewer.

Sites map