Change CP anchor text

RT: Give CP anchors meaningful names.

This RT offers the possibility for CP anchors to give them “meaningful names”.

An anchor that can be specified autom. for each CP e.g. <a name="cpid123"> (123 is the CP-Id)
will become: <a name="mein-toller-ankername">

These names are set in the respective CP

  • With a TAG in the Notes field e.g. [Xanchor:nice-cp-text-anchor]
  • or titles or subtitles may be used for the text.

The settings have to be made in the script in CUSTOM VAR.

Additionally, you can set whether hidden CPs (when working with CP alias or SHOW_CONTENT) are involved in the process. (Default: $visible_cp = false;)

In front of each anchor a text can be defined, for example, $prev_anchor = 'prev-'; === > <a name="prev-nice-cp-text-anchor">.
This is also adjusted in the script in CUSTOM VAR.

Usable characters:

(a-z A-Z) (0-9) (_) (-) (.)
All other characters are converted, for example “Mein größter Ankertext” will be converted to “mein_groesster_ankertext”.
All characters are converted to lowercase. If this isn't a wanted behaviour, please comment out the statement $str = strtolower( $str ); in ”function rt_val_special_chars($str)”.

If you want another replacement this can be changed in the above Function.


—-

rt_change_cp_anchor_text V1.0 12.06.2010

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

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

Tag: –

Filename: rt_change_cp_anchor_text.php

Folder: template/inc_script/frontend_render/

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

  • $phpwcms['allow_ext_render'] = 1;



Code:

File: template/inc_script/frontend_render/rt_change_cp_anchor_text.php

rt_change_cp_anchor_text

<?php
/*
* **************************************************************************
* 12.06.09 CP (V 1.0): Change anchor for CPs into given text
* - In Notes fiels with the tag: [Xanchor:nice-cp-text]
* - Using the title text
* - Using the subtitle text
*
* E.g.: IF set [Xanchor:nice-cp-anchor] changes
* <a name="cpid10" id="cpid10" class="cpidClass"></a>
* to
* <a name="nice-cp-anchor" id="nice-cp-anchor" class="cpidClass"></a>
*
* hhttp://forum.phpwcms.org/viewtopic.php?p=124823
*
* TAG:      [Xanchor:nice-cp-anchor-text] in the comment field of the displayed CP
*           Places this tag first in comment field!!!
*
* Location: Put it into the file e.g.:
*           /template/inc_script/frontend_render/rt_change_cp_anchor_text.php
* Switch in conf.inc.php: $phpwcms['allow_ext_render']  = 1;
*
* Knut Heermann (flip-flop) http://planmatrix.de
*
* **************************************************************************
*/
// -------------------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
   die("You Cannot Access This Script Directly, Have a Nice Day.");
}
// -------------------------------------------------------------------------
 
// Ist ein CP Anker vorhanden
// Only run if a cp achor is available
if ( strpos($content["all"], '<a name="cpid') !== false ) {
 
// ------- CUSTOM VAR ------------------------------------------------------
 
// Welcher Text soll als Anker eingesetzt werden
// What text is to be used as anchor
 $anchor_text = 0;    // [0=Notiz | 1=Inhaltstitel | 2=Untertitel]
                      // [0=notes | 1=title        | 2=subtitle  ]
 
// Text vor dem Anker   // Text before the anchor
 $prev_anchor = '';     // Z.B.: name="prev-nice-cp-anchor"
                        // E.g: name="prev-nice-cp-anchor"
 
// Zeige sichtbare CPs   // Show visible CPs
// Spezieller Schalter wenn CP-alias oder SHOW_CONTENT verwendet wird.
// Special switsch if you work with CP-alias or SHOW_CONTENT
 $visible_cp = false;    // [true|false] [Nur sichtbare CPs | alle CPs]
                         // [true|false] [Only visible CPs  | all CPs ]
 
// ------- END CUSTOM VAR --------------------------------------------------
 
 
// Validiere spezielle Zeichen   // Validate special chars
// Verwendbare Zeichen   // Usable characters: (a-z A-Z) (0-9) (_) (-) (.)
function rt_val_special_chars($str) {
 
    $replace = array(
    ' ' => '_', '\\' => '-', '/' => '-',
    'ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue',
    'Ä' => 'Ae', 'Ö' => 'Oe', 'Ü' => 'Ue', 'ß' => 'ss',
    'à' => 'a', 'á' => 'a', 'â' => 'a' , 'ã' => 'a', 'å' => 'a',
    'ç' => 'c',
    'è' => 'e', 'é' => 'e', 'ê' => 'e' , 'ë' => 'e',
    'ì' => 'i', 'í' => 'i', 'î' => 'i' , 'ï' => 'i',
    'ò' => 'o', 'ó' => 'o', 'ô' => 'o' , 'õ' => 'o', 'õ' => 'o', 'ø' => 'o',
    'ù' => 'u', 'ú' => 'u', 'û' => 'u' ,
    'ý' => 'y', 'ÿ' => 'y',
    'ñ' => 'n'
    );
 
    $str = strtr( $str, $replace );
 
    // Convert into lower case: Comment it out if you do not need it.
    $str = strtolower( $str );
 
    return trim( $str );
}
 
// *************************************************************************
    // CP ID holen   // Catch cp id
    if (preg_match_all('/\<a name="cpid(.*?)"/i', $content["all"], $match)) {
 
 
        // DB Data
        $sql  = "SELECT acontent_id, acontent_title, acontent_subtitle, acontent_comment ";
        $sql .= "FROM ".DB_PREPEND."phpwcms_articlecontent ";
        $sql .= 'WHERE acontent_id IN ('.implode(',', $match[1]).') ';
        $sql .= "AND acontent_trash=0 ";
        if ($visible_cp)             $sql .= "AND acontent_visible=1 ";        // Only visible CPs
        if         ($anchor_text == 1)    $sql .= "AND acontent_title <> '' ";    // Title is anchor text
        elseif     ($anchor_text == 2)    $sql .= "AND acontent_subtitle <> '' ";    // SubTitle is anchor text
        else                          $sql .= "AND acontent_comment LIKE '%[Xanchor:%' "; // notic text is anchor text
 
        $result = _dbQuery($sql);
 
 
        // Aller verfuegbaren Anker ersetzen   // replace all avaialbe anchors
        foreach ($result as $value) {
 
            // Title is anchor text
            if     ($anchor_text == 1)     $anchor_replace = $prev_anchor.$value['acontent_title'];
            // SubTitle is anchor text
            elseif     ($anchor_text == 2)    $anchor_replace = $prev_anchor.$value['acontent_subtitle'];
            // notic text is anchor text
            else                         $anchor_replace = $prev_anchor.preg_replace('/\[Xanchor:(.*?)]/i','$1',$value['acontent_comment']);
 
            $content["all"] = str_replace('name="cpid'.$value['acontent_id'].'"', 'name="'.rt_val_special_chars($anchor_replace).'"', $content["all"]);
//            $content["all"] = str_replace('id="cpid'.$value['acontent_id'].'"', 'id="'.rt_val_special_chars($anchor_replace).'"', $content["all"]);
        }
 
    }
 
}
 
?>
english/phpwcms_replacer_rts/frontend_render/change-cp-anchor-text.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