NAVIGATION
This shows you the differences between two versions of the page.
|
deutsch:ersetzer_rts:frontend_render:anchor-jump [2011/08/17 17:15] Knut Heermann (flip-flop) created |
deutsch:ersetzer_rts:frontend_render:anchor-jump [2018/06/03 18:09] (current) |
||
|---|---|---|---|
| Line 9: | Line 9: | ||
| * Anker der mit dem TAG **{A:MeinAnker}** an irgendeiner Stelle in einem CP gesetzt werden kann (**%%<a name="MeinAnker">%%**). \\ | * Anker der mit dem TAG **{A:MeinAnker}** an irgendeiner Stelle in einem CP gesetzt werden kann (**%%<a name="MeinAnker">%%**). \\ | ||
| - | Diese Namen werden eingestellt im jeweiligen CP | + | \\ |
| - | * Mit einem TAG im Notizfeld z.B. **[Xanchor:**nice-cp-text-anchor**]** | + | **TAG:** |
| - | * oder Titel oder Untertitel werden für den Text verwendet. | + | * ##{GO-A:CP-ID,Linktext}## |
| + | * ##{GO-A:Ankertext,Linktext}## | ||
| - | Die Einstellungen dazu werden im Script im Bereich CUSTOM VAR vorgenommen. | + | \\ |
| + | **Bedingungen im TAG:** | ||
| - | Zusätzlich kann eingestellt werden ob auch unsichtbare CPs //(wenn mit CP-Alias oder SHOW_CONTENT gearbeitet wird)// in den Prozess mit einbezogen werden. //(Default: $visible_cp = false;)// | + | * CP-ID: |
| + | * Numerischer Wert //(Es wird autom. angenommen, dass eine ContentPart-ID gemeint ist).// | ||
| - | Vor jedem Anker kann ein Text gesetzt werden z.B. **%%$prev_anchor = 'prev-';%%** === > **%%<a name="prev-nice-cp-text-anchor">%%**. \\ | + | * Ankername: |
| - | Einstellbar ebenfalls im Script in CUSTOM VAR. | + | * Ein Wort, keine Leerzeichen, keine Sonderzeichen oder Umlaute //(Es wird angenommen, dass eine gültiger Anker auf der Seite gesetzt ist).// |
| - | **Verwendbare Zeichen:** | + | * Linktext: |
| + | * Minimale Wortlänge sind drei Zeichen | ||
| - | (a-z A-Z) (0-9) (_) (-) (.) \\ | ||
| - | Alle anderen Zeichen werden konvertiert, z.B. wird aus "Mein größter Ankertext" === > "mein_groesster_ankertext". \\ | ||
| - | Alle Zeichen werden in Kleinbuchstaben konvertiert. Ist das nicht gewünscht kann in "%%function rt_val_special_chars($str)%%" die Anweisung **%%$str = strtolower( $str );%%** auskommentiert werden. | ||
| - | Wird eine andere Ersetzung gewünscht kann das in in der o.g. Funktion geändert werden. | + | Ist eine Bedingung nicht erfüllt wird ein Fehlertext im FE ausgegeben. |
| + | |||
| + | |||
| + | <note> | ||
| + | **Der RT überprüft nicht das Vorhandensein von gültigen Sprungzielen!** | ||
| + | </note> | ||
| + | |||
| + | |||
| + | |||
| + | **Beispiel:** | ||
| + | |||
| + | **{GO-A:149,Linktext}** | ||
| + | |||
| + | <code html> | ||
| + | <a href="#cpid149" class="phpwcmsAnchorLink-GO" title="Linktext">Linktext</a> | ||
| + | </code> | ||
| + | |||
| + | \\ | ||
| + | **{GO-A:MyAnchorName,Linktext}** | ||
| + | <code html> | ||
| + | <a href="#MyAnchorName" class="phpwcmsAnchorLink-GO" title="Linktext">Linktext</a> | ||
| + | </code> | ||
| \\ | \\ | ||
| - | |||
| ---- | ---- | ||
| - | **rt_change_cp_anchor_text** V1.0 12.06.2010 | + | **rt_goto_anchor** V1.0 16.08.2011 |
| Docu: -- \\ | Docu: -- \\ | ||
| - | Forum: [[http://forum.phpwcms.org/viewtopic.php?p=124823]] | + | Forum: [[http://forum.phpwcms.org/viewtopic.php?p=131995]] |
| Line 46: | Line 67: | ||
| - | Tag: -- \\ | + | Tag: -- ##{GO-A:CP-ID, Linktext}## oder ##{GO-A:Ankertext, Linktext}## |
| - | Dateiname: **rt_change_cp_anchor_text.php** | + | Dateiname: **rt_goto_anchor.php** |
| Verzeichnis: ** template/inc_script/frontend_render/ ** | Verzeichnis: ** template/inc_script/frontend_render/ ** | ||
| Line 63: | Line 84: | ||
| ===== Code: ===== | ===== Code: ===== | ||
| - | **Datei:** template/inc_script/frontend_render/rt_change_cp_anchor_text.php | + | **Datei:** template/inc_script/frontend_render/rt_goto_anchor.php |
| - | <code php |h rt_change_cp_anchor_text |h > | + | <code php |h rt_goto_anchor |h > |
| <?php | <?php | ||
| - | /* | + | /** |
| - | * ************************************************************************** | + | * ***************************************************************************** |
| - | * 12.06.09 CP (V 1.0): Change anchor for CPs into given text | + | * 16.08.2011 V1.0 K.Heermann http://planmatrix.de |
| - | * - In Notes fiels with the tag: [Xanchor:nice-cp-text] | + | * |
| - | * - Using the title text | + | * GoTo anchor link |
| - | * - Using the subtitle text | + | * |
| - | * | + | * Tags v1.0: |
| - | * E.g.: IF set [Xanchor:nice-cp-anchor] changes | + | * - {GO-A:CP-ID,Link text} |
| - | * <a name="cpid10" id="cpid10" class="cpidClass"></a> | + | * - {GO-A:Anchor_name,Link text} |
| - | * to | + | * |
| - | * <a name="nice-cp-anchor" id="nice-cp-anchor" class="cpidClass"></a> | + | *CP-ID: |
| - | * | + | * - Only numeric values |
| - | * hhttp://forum.phpwcms.org/viewtopic.php?p=124823 | + | * |
| - | * | + | * Anchor_name: |
| - | * TAG: [Xanchor:nice-cp-anchor-text] in the comment field of the displayed CP | + | * - One word, no spaces |
| - | * Places this tag first in comment field!!! | + | * - No special characters and umlauts. |
| - | * | + | * |
| - | * Location: Put it into the file e.g.: | + | * Link text: |
| - | * /template/inc_script/frontend_render/rt_change_cp_anchor_text.php | + | * - If there is no link text an error occures |
| - | * Switch in conf.inc.php: $phpwcms['allow_ext_render'] = 1; | + | * - Minimum word length is three characters |
| - | * | + | * ***************************************************************************** |
| - | * Knut Heermann (flip-flop) http://planmatrix.de | + | |
| - | * | + | |
| - | * ************************************************************************** | + | |
| */ | */ | ||
| - | // ------------------------------------------------------------------------- | + | // ----------------------------------------------------------------------------- |
| // obligate check for phpwcms constants | // obligate check for phpwcms constants | ||
| - | if (!defined('PHPWCMS_ROOT')) { | + | if (!defined('PHPWCMS_ROOT')) { |
| - | die("You Cannot Access This Script Directly, Have a Nice Day."); | + | 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 -------------------------------------------------- | ||
| - | + | if (strpos($content["all"],'{GO-A:') !== false) { // Is there any anchor jump? | |
| - | // Validiere spezielle Zeichen // Validate special chars | + | |
| - | // Verwendbare Zeichen // Usable characters: (a-z A-Z) (0-9) (_) (-) (.) | + | |
| - | function rt_val_special_chars($str) { | + | |
| - | $replace = array( | + | // cp anchor is available |
| - | ' ' => '_', '\\' => '-', '/' => '-', | + | IF (strpos($content["all"],'<a name="cpid') !== false) { |
| - | 'ä' => '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 ); | + | $mySearch = '/\{GO-A:(\d+),([\x20-\x7F]{3,})\}/is'; |
| - | + | $myReplace = '<a href="#cpid$1" class="phpwcmsAnchorLink-GO" title="$2">$2</a>'; | |
| - | // 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); | + | $content['all'] = preg_replace($mySearch, $myReplace, $content['all']); |
| + | } | ||
| + | // TAG anchor is available | ||
| + | IF (strpos($content["all"],'class="phpwcmsAnchorLink"') !== false) { | ||
| - | // Aller verfuegbaren Anker ersetzen // replace all avaialbe anchors | + | $mySearch = '/\{GO-A:([^\x7B-\xFF\s\W]+?),([\x20-\x7F]{3,})\}/is'; |
| - | foreach ($result as $value) { | + | $myReplace = '<a href="#$1" class="phpwcmsAnchorLink-GO" title="$2">$2</a>'; |
| - | + | $content['all'] = preg_replace($mySearch, $myReplace, $content['all']); | |
| - | // 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"]); | + | |
| - | } | + | |
| - | } | + | // Error output |
| + | $mySearch = '/\{GO-A:(.*?)\}/is'; | ||
| + | $myReplace = '<b style="color:red">Anchor error:</b> "$1"'; | ||
| + | $content['all'] = preg_replace($mySearch, $myReplace, $content['all']); | ||
| + | $content['all'] = str_replace('\'', ''', $content['all']); | ||
| + | $content['all'] = str_replace('&quot;', '"', $content['all']); | ||
| } | } | ||
| ?> | ?> | ||
| </code> | </code> | ||