Changeset 3965:b4e408d85ae5 for inc
- Timestamp:
- 05/03/19 13:45:04 (6 years ago)
- Branch:
- default
- Location:
- inc
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.blog.php
r3874 r3965 457 457 { 458 458 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; 459 484 } 460 485 -
inc/core/class.dc.rs.extensions.php
r3874 r3965 457 457 } 458 458 } 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 } 459 472 } 460 473 -
inc/public/class.dc.template.php
r3874 r3965 243 243 244 244 # --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]); 246 246 247 247 $res .= parent::compileBlockNode($this->current_tag, $attr, $content); … … 967 967 968 968 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); 970 973 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 } 973 980 } 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 } 975 986 } 976 987 } … … 980 991 if (is_array($urls) && count($urls)) { 981 992 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); 982 996 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 } 985 1003 } 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 } 987 1009 } 988 1010 } … … 1325 1347 if (isset($attr['category'])) { 1326 1348 $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); 1327 1352 if (substr($category, 0, 1) == '!') { 1328 1353 $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 } 1330 1359 } 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 } 1332 1365 } 1333 1366 } … … 1337 1370 if (is_array($categories) && count($categories)) { 1338 1371 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); 1339 1375 if (substr($category, 0, 1) == '!') { 1340 1376 $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 } 1342 1382 } 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 } 1344 1388 } 1345 1389 }
Note: See TracChangeset
for help on using the changeset viewer.