eigene Replacement Tags

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
iriechaos
Posts: 19
Joined: Wed 29. Jun 2005, 13:02

eigene Replacement Tags

Post by iriechaos »

Hi all,

Kann mir jmd sagen wo ich eigene Replacement Tags anlegen kann?

Ich möchte das bestimmte Wörter im Artikeltext automatisch mit Links Hinterlegt werden. zb. Ich schreibe Google und phpwcms gibt den link zu google aus.

Hatt jmd schon ne gute lösung?

greetz
ff123
Posts: 172
Joined: Thu 9. Jun 2005, 20:03
Location: The Netherlands
Contact:

Post by ff123 »

If you want to make your own replacement tag, you have to program a .php script and put it in:
phpwcms_template/inc_script/frontend_render

Reptags are always called with {...}, for example {autolink}.

An example for a reptag is breadcrump:

Code: Select all

<?php
/** 
	BREADCRUMB_LEVELS
	Version: 1.0 
	Replacementtag for BREADCRUMB_LEVELS
	This Replacementtag allows you to show an breadcrumb with setting the start-level 
  and the end-level of the category-structure. So it is possible to show only on 
  level or the sub's beginning with the choosen level. Level is the real level of
  the structure not the category-ID.
  
  Home will not be shown!
  
  The Start-level has to be lower than or equal to the End-Level otherwise the 
  Startlevel will be the first level (main below home)
  
  If there is no such level in the end-level so, the next possible level will be
  shown. If there is no level found, so you can decide if the whole breadcrumb 
  will be shown otherwise it can be hided.

		- for use of this you must set in ../config/phpwcms/conf.inc.php:
		  $phpwcms["allow_ext_init"]    = 1;       
		  $phpwcms["allow_ext_render"]  = 1; 
		- copy the provided .php-file into 
		  phpwcms_template/inc_script/frontend_render/

	{BREADCRUMB_LEVELS:0:0:0:} = {BREADCRUMB_LEVELS} without home
	All levels till the active will be shown


	{BREADCRUMB_LEVELS:1:1:0:|}
	Only the first level (main below home) will be shown
	
		·	:1 start level for display 
		·	:1 end level for display 
		·	:0 hide breadcrumb if there is no level to show
		·	:| the delimiter between breadcrumb-levels

	{BREADCRUMB_LEVELS:2:4:0:|}
  All levels between level 2 and level 4 will be shown

	ad1) All levels beginning with this level to the 4th level will be shown
	ad2) This is the end level for show, if you use 0 then all levels beginning 
      with the start level will be shown
	ad3) if you choose 0, then all levels will be shown, if you use 1 then the 
      breadcrumb will not be on display
  ad4) the delimiter between the breadcrumb-levels can be set if there is nothing
      the delimiter will be '>'


*************************************************************************************
   Copyright notice
   
    Parts FROM
   (c) 2002-2005 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
   (c) 2005 Jochen Regenfelder // All rights reserved.

   This script is for PHPWCMS. 
   
   The PHPWCMS web content management system is free software; you can redistribute 
   it and/or modify it under the terms of the GNU General Public License as published 
   by the Free Software Foundation; either version 2 of the License, or (at your option) 
   any later version.
  
   The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
   A copy is found in the textfile GPL.txt and important notices to the license 
   from the author is found in LICENSE.txt distributed with these scripts.
  
   This script is distributed in the hope that it will be useful, but WITHOUT ANY 
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
   PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 
   This copyright notice MUST APPEAR in all copies of the script!
*************************************************************************************
**/


// -------------------------------------------------------------

// #####--- modified by jochen--- 

function breadcrumb_levels ($end_id, $struct_array, $start_id, $hide_menu, $spacer="", $link_to="index.php") {
	//builds the breadcrumb menu based on given values
	//$link_to = the page on which the breadcrum part links
	//$root_name = name of the breadcrumb part if empty/false/0 $start_id
	//$spacer = how should breadcrumb parts be divided
	
	if ($spacer==false) $spacer=">";
  $spacer=" ".$spacer." ";
	
	$nohide=true;
	$act_id = $GLOBALS ['content']["cat_id"]; //store actual ID for later comparing	
	
  //if Home-level is disabled, then set the level to level 1
  //This is necassery if the given level is not included at the act leveltree

	
	//Proof if end_level is greater then start_level, because this are levels
	if (($end_id>$start_id) && ($start_id >0)) {
    $end_id=1;
  }
	
	// setting the start_level (this is the level of the last menu, but gives the 
  // ACAT_ID of the first menu)
	if ($start_id==0) {
    $start_id = intval($act_id);  
  } else {
  
  	$array_order = array_flip($GLOBALS['LEVEL_ID']);
		$level_key = array_search($start_id ,$array_order);
    
		if ($level_key==false){
      //if start_id can not be found, so take the last found level for dispay 
      // if it is greater then act_id, else use act_id
      $jr_max = count($array_order)-1;
      if ($jr_max >= $end_id){
        $start_id=$GLOBALS['LEVEL_ID'][$jr_max];
      } else {
        // IF no level is found and hide is selected
        if ($hide_menu==1){
          $nohide=false;
        } 
        $start_id = $act_id;          
      }
    } else {
      $start_id = intval($level_key);
    }
  }
		
	// setting the end_level (this is the level of the first menu, but gives the 
  // ACAT_ID of the last menu)
	if ($end_id==0) {
    $array_order = array_flip($GLOBALS['LEVEL_ID']);
    $end_id = array_search("1" ,$array_order);  
  } else {
    $array_order = array_flip($GLOBALS['LEVEL_ID']);
		$level_key = array_search($end_id ,$array_order);
		
    if ($level_key==false){
      //if no level is found hide breadcrumb  
      if ($hide_menu==1){
        $nohide=false;
      }      
      $end_id = array_search("1" ,$array_order);  
    } else {
      $end_id = intval($level_key);
    }
  }
 
 // #####--- END --- modified by jochen---
  
  if ($nohide){  

  	while ($start_id) { //get the breadcrumb path starting with given start_id
  		$data[$start_id] = $struct_array[$start_id]["acat_name"];
      // #####--- modified by jochen--- 
      // this is moved so that home is not displayed
		  if($end_id && $start_id == $end_id) break;
  		// #####--- END --- modified by jochen---
      $start_id		 = $struct_array[$start_id]["acat_struct"];
  	}
	
    $data[$start_id] = $struct_array[$start_id]["acat_name"];
    $crumbs_part = array_reverse($data, 1);	
	
	
  	if(is_array($crumbs_part) && count($crumbs_part)) {
  		$breadcrumb = "";
  		foreach($crumbs_part as $key => $value) {	
  			$alias = '';
   			if ($act_id != $key) {
  				if($breadcrumb) $breadcrumb .= $spacer;
  				if(!$struct_array[$key]["acat_redirect"]) {
  					$breadcrumb .= '<a href="index.php?';
  					$alias = $struct_array[$key]["acat_alias"];
  					$breadcrumb .= ($alias) ? html_specialchars($alias) : 'id='.$key.',0,0,1,0,0';
  					$breadcrumb .= '">';
  				} else {
  					$redirect = get_redirect_link($struct_array[$key]["acat_redirect"], ' ', '');
  					$breadcrumb .= '<a href="'.$redirect['link'].'"'.$redirect['target'].'>';
  				}
  				$breadcrumb .= html_specialchars($crumbs_part[$key]).'</a>';
  			} else {
  				if($breadcrumb) $breadcrumb .= $spacer;
  				$breadcrumb .= html_specialchars($crumbs_part[$key]);
  			}
  		}
  	} else {
  		$breadcrumb = "";
  	}
  	return $breadcrumb;
  }
}

// -------------------------------------------------------------



// -------------------------------------------------------------

//breadcrumb replacementtag
if( ! ( strpos($content["all"],'{BREADCRUMB_LEVELS')===false ) ) {
	$content["all"] = str_replace('{BREADCRUMB_LEVELS}', '{BREADCRUMB_LEVELS:0:0:0:>}', $content["all"]);
	$replace = 'breadcrumb_levels("$1", $content["struct"], "$2", "$3", "$4", "index.php");';
	$content["all"] = preg_replace('/\{BREADCRUMB_LEVELS:(.*?):(.*?):(.*?):(.*?)\}/e', $replace, $content["all"]);
}

// -------------------------------------------------------------


?>
As you see in the end, the reptag {BREADCRUMP} is replaced with php code. Thats how it works! :wink: Good luck!

Vuurvos
-- Vuurvos --
iriechaos
Posts: 19
Joined: Wed 29. Jun 2005, 13:02

Post by iriechaos »

I want to call the reptag without {}. for example when I write phpwcms I want to get an autolink to http://www.phpwcms.de/.
ff123
Posts: 172
Joined: Thu 9. Jun 2005, 20:03
Location: The Netherlands
Contact:

Post by ff123 »

Sounds very strange to me... So for every word there should be a link and how should phpwcms where to link?

Maybe the autolink plugin from wordpress is like what you mean:
http://wp-plugins.net/plugin/wp-autolink/

Maybe a reptag would be looking like this:
{AUTOLINK:phpwcms|www.phpwcms.de}

Yes! It already exists:
[EXT http://www.phpwcms.de]phpWCMS[/EXT]
Source: http://www.phpwcms-docu.de/link_tags.phtml
-- Vuurvos --
iriechaos
Posts: 19
Joined: Wed 29. Jun 2005, 13:02

Post by iriechaos »

I tell one time that the link for phpwcms is http://www.phpwcms.de/ for example.
So I can type phpwcms in every artikel and the cms knows that the link is http://www.phpwcms.de/ without telling every time the link.

sorry 4 my english!!!
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

just a hint

setup an array with a wordlist and with related links
with a regExpr. function from php you replace all words from the array in $content['all'].

if you are familiar with php, it's no problem :-)

no codesnippets at the moment, sorry.
iriechaos
Posts: 19
Joined: Wed 29. Jun 2005, 13:02

Post by iriechaos »

meine php kenntnisse sind genau so schlecht wie mein english *g
iriechaos
Posts: 19
Joined: Wed 29. Jun 2005, 13:02

Post by iriechaos »

put the following in a file in the frontend_render folder:
<?
$datei = "config/links.txt";
$wordlist = file($datei);

for ($i = 0; $i < count($wordlist); $i++) {
$wordlist[$i] = explode(";" , $wordlist[$i]);

$wordlist[$i]['keyword']=$wordlist[$i][0];
$wordlist[$i]['link']=$wordlist[$i][1];
}

function mytag($keyword,$link) {
$output="<a href=\"http://" . $link . "\" target=\"_blank\">" . $keyword . "</a>";
return $output;
}


$i=0;
while ($i <= count($wordlist)) {
$content['all'] = str_replace($wordlist[$i]['keyword'],mytag($wordlist[$i]['keyword'],$wordlist[$i]['link']),$content['all']);
$i++;
}
?>
Create a file links.txt with the keywords and the links in the config folder:
keyword;url
google;www.google.de
phpwcms;www.phpwcms.de
Thats all. Now the srcipt will replace all keywords with the urls.
thx to marcus!!!
User avatar
Oliver Georgi
Site Admin
Posts: 9892
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

Sorry, es gefährlich einen solchen Tipp zu geben!!!!

Ein Dokument besteht eben nicht nur aus Text, sodass man einfach dahergehen kann und mal eben wahllos aus phpwcms einen <a href...> machen kann. Es ist gut möglich, dass es bereits woher auch immer einen solchen Link gibt - na überlegt was passiert, trifft der Replacer auf <a href="http://phpwcms.de">Na gucke</a> - genau: daraus wird <a href="http://<a href="...">phpwcms</a>.de">Na gucke</a>. Also ist das Schrott.

Es ist also IMMER empfohlen, bewußt etwas zu setzen und auch genau hierfür einen Tag einzuführen. Eine Wortliste an sich ist OK, aber es ist immer ratsam bewußt zu taggen! Oder man muss Code nutzen, der genau auch die Ausnahmen berücksichtigt. Für den Laien eher kompliziert!

Es ist also ratsam, sich umschließende Tags zu definieren. Dann arbeitet man die Tags von oben nach unten ab und am Ende werden alle Tags entfernt, die eventuell übrig geblieben sind, weil z.B. das Keyword nicht definiert ist.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
iriechaos
Posts: 19
Joined: Wed 29. Jun 2005, 13:02

Post by iriechaos »

Hi Oliver,
das hatte ich nicht bedacht der Marcus hat mich auch schon darauf hingewiesen vielen dank für deine hilfe.
phalancs
Posts: 793
Joined: Thu 19. Feb 2004, 05:09
Location: Germany

:O

Post by phalancs »

Danke für eure Hinweise, das Skript würde mich dennoch sehr interessieren aber es funktioniert nicht. :O

Im frontend erscheint immer.

Code: Select all

" target="_blank">keyword
wobei keyword das entsorechende Wort ist.
Woran kann es liegen?
2008
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

hi,
ich hab jetzt nicht das endgültige skript vorliegen, weil ja bloß mit half bei der umsetzung.
aber der beitrag zuvor von oliver könnte der entsprechende hinweis sein.
wenn "keyword" in einem html tag vorkommt, dann wird das natürlich auch ersetzt und ergibt murks.
prüfe das nochmal.
normalerweise dürfte die ersetzung nur durchgeführt werden, wenn keyword nicht innerhalb von < > vorkommt.
prüf das mal. ansonsten geb mal bitte die zeile aus der ersetzungsliste und etwas mehr von dem fehlerhaften output mit.

grüße
marcus
phalancs
Posts: 793
Joined: Thu 19. Feb 2004, 05:09
Location: Germany

Post by phalancs »

hmm, also ich hab ja jetzt nur keyword in die fehlerzeile eingefügt damit ihr wisst was da stehen würde.

In meinem Test ahtte ich da einen einzigartigen string verwendet um sowas auszuschließen.

Also die zu ersetzenden worte werden ja egtl. erkannt aber der umschließend link wird nciht korretk gesetzt.

vor das keyword wird immer nur

Code: Select all

" target="_blank">
eingefügt.

Eine Idee?
Danke für die schnelle antwort schonmal.
2008
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

also, es kann nur sein, das sich das skript hier irgendwo aufhängt:
$output="<a href=\"http://" . $link . "\" target=\"_blank\">" . $keyword . "</a>";
also den fettgedruckten teil unterschlägt das skript einfach... :-/, warum auch immer. sorry, weiss ich jetzt keinen rat. das script hast du 1:1 übernommen?
eigenartig...
phalancs
Posts: 793
Joined: Thu 19. Feb 2004, 05:09
Location: Germany

Post by phalancs »

ja hab das so übernommen. hmm, also immerhin erkennt er die stellen.
ich dneke auch dass es was mit der von dir angegebenen stelle zu tun hat.

schade. villeicht hat ja jemand noch ne idee dazu :O
prinzipiell kann die idee mit dem global replacing sehr hilfreich sein, wenn man das beachtet auf das oli hingewiesen hat.
2008
Post Reply