Quick Category link with ALIAS/ID

A single TAG that makes a link, automatically grabs the title of the destination category and insert the name as link text.

[QIDC|qIDC category-alias or category-ID]


rt_qidc_link_to_category_alias V1.0 29.11.2011

Docu: –
Forum: http://forum.phpwcms.org/viewtopic.php?p=133283

Author: K.Heermann (flip-flop) http://planmatrix.de
CMS Version: >= 1.3
Version: V1.0

TAGs: [QIDC|qIDC category-alias or category-ID]

Fileiname: rt_qidc_link_to_category_alias.php

Folder: template/inc_script/frontend_render/

Condition:/config/phpwcms/conf.inc.php

  • $phpwcms['allow_ext_render'] = 1;



Script:

rt_qidc_link_to_category_alias

<?php
 
/**
*********************************************************************************************
* 29.11.11 KH: http://planmatrix.de V1.0
* frontend_render-Script: Link to article alias/id
* A single tag that makes a link, automatically grabs the name of the destination category
* and inserts the name as link text
* TAGs: [QIDC|[qIDC category alias|category id]
*********************************************************************************************
*/
// -------------------------------------------------------------------------------------------
// obligate check for phpwcms constants
    if (!defined('PHPWCMS_ROOT')) {
        die("You Cannot Access This Script Directly, Have a Nice Day."); }
// -------------------------------------------------------------------------------------------
 
// ============= [QIDC] Category
if (strpos($content["all"], '[QIDC ') != false OR strpos($content["all"], '[qIDC ') != false ) {
 
    $hidden_category = array(); // CUSTOM: All not available categories like 23,45,78,...'
 
     preg_match_all('/\[QIDC (.*?)\]/im', $content["all"], $match);
 
 
    if ( isset($match['1']) AND !empty($match['1']) ) {                // if match found, replace
 
        // Separate IDs and articles TAGs
        $id_i = array();        // ID
        $id_a = array();        // article
 
        foreach ($match['1'] as $key=>$value) {
 
            // ID or alias input??  // ID oder alias Eingabe????
            if ((int)$value == $value AND (int)$value != 0)
                $id_i[] = trim($value);
            else
                $id_a[] = strtolower(trim($value));
 
        }
        // Count all possible matches for a better performance in loop
        $count = count($id_i);
        $count = $count + count($id_a);
 
 
        // ID based search
        if (isset($id_i[0])) {             // Is there any TAG using IDs?
 
            foreach ( $id_i as $key=>$value) {        // Looking for all tagged IDs
 
                if (array_key_exists($value, $content["struct"])         AND     // Looking for the tagged IDs in structure tree
                    $content["struct"][$value]["acat_regonly"] == 0     AND     // for registered user only
                    $content["struct"][$value]["acat_hidden"]  == 0     AND     // category hidden?
                    !in_array($value, $hidden_category)    ) {                        // custom category hidden?
 
                    // Replace in content
                    $link = '<a href="index.php?'.$content["struct"][$value]['acat_alias'].'" title="'.$content["struct"][$value]['acat_name'].'">'.$content["struct"][$value]['acat_name'].'</a>';
                    $content["all"] = str_replace('[QIDC '.$value.']',$link, $content["all"] );
                    $content["all"] = str_replace('[qIDC '.$value.']',$link, $content["all"] );
                    $count--;
                }
            }
        }
 
        // article based search
        if (isset($id_a[0])) {            // Is there any TAG using IDs?
 
            foreach ( $content["struct"] as $key=>$value) {        // Looking for all tagged IDs
 
                if (in_array($value['acat_alias'],$id_a)              AND         // Looking for all tagged IDs
                    $content["struct"][$key]["acat_regonly"] == 0     AND         // for registered user only
                    $content["struct"][$key]["acat_hidden"]  == 0     AND         // category hidden?
                    !in_array($value['acat_alias'], $hidden_category)    ) {        // custom category hidden?
 
                    // Replace in content
                    $link = '<a href="index.php?'.$content["struct"][$key]['acat_alias'].'" title="'.$content["struct"][$key]['acat_name'].'">'.$content["struct"][$key]['acat_name'].'</a>';
                    $content["all"] = preg_replace('/\[QIDC '.$content["struct"][$key]['acat_alias'].'\]/im',$link, $content["all"] );
 
                    // Faster solution: If no match is possible -> break the loop
                    $count--;
                    if ($count == 0) break;
                }
            }
        }
 
        if ($count > 0)        // If no match kill the rest
            $content["all"] = preg_replace('/\[QIDC (.*?)\]/im','[[No Link set!]]', $content["all"] );
 
    } // END ( isset($match['1'])
 
}
 
?>


  • In “$hidden_category” category IDs can be registered, which then will be excluded from selection. ('23,56,74,12,...') .


english/phpwcms_replacer_rts/frontend_render/link-category-alias-id.txt · Last modified: 2018/06/03 18:09 (external edit)
www.planmatrix.de www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0