Zikula_Template_Plugins
[ class tree: Zikula_Template_Plugins ] [ index: Zikula_Template_Plugins ] [ all elements ]

Source for file outputfilter.shorturls.php

Documentation is available at outputfilter.shorturls.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright (c) 2004, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: outputfilter.shorturls.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @package Zikula_Template_Plugins
  10.  * @subpackage Filters
  11.  */
  12.  
  13. /**
  14.  * Smarty short urls outputfilter plugin
  15.  *
  16.  * File:      outputfilter.shorturls.php
  17.  * Type:      outputfilter
  18.  * Name:      shorturls
  19.  * Date:      Nov 7, 2003
  20.  * Purpose:   Generate short urls for the PN CMS
  21.  * @author    Craig R. Saunders (coldrolledsteel)
  22.  * @author    Martin Anderson (msanderson)
  23.  * @author    Luca Longinotti (CHTEKK)
  24.  * @author    Mark West
  25.  * @version   1.3
  26.  * @param     string 
  27.  * @param     Smarty 
  28.  */
  29. function smarty_outputfilter_shorturls($source&$smarty)
  30. {
  31.     // If you control the server, it is preferable for better performance to put rewrite rules
  32.     // from the htaccess file into main configuration file, httpd.conf.
  33.  
  34.     // get the site's base uri, eg /nuke/ for root-relative links
  35.     $baseurl pnGetBaseURL();
  36.     $type    FormUtil::getPassedValue('type''user''GETPOST');
  37.  
  38.     if (pnConfigGetVar('shorturlstype'== 0{
  39.         $prefix '[(<[^>]*?)[\'"](?:'.$baseurl.'|'.$baseurl.')?(?:[./]{0,2})'// Match local URLs in HTML tags, removes / and ./
  40.         // '|"(?:'.$baseurl.')?'; <[^>]*?[\'"]
  41.  
  42.         // (?i) means case insensitive; \w='word' character; \d=digit; (amp;)? means content of brackets optional; (?:catid=)? means optional and won't capture string for backreferences
  43.         // [#-~]+ matches ASCII# 35(#)-126(~), ie all (English) upper & lower case letters, numbers and special characters like #$!@+%^&*()~ etc, ie all but space (32), DEl, and other specxial non-printing codes like backspace, newline, and tab
  44.         // [0-9A-Za-zÀ-ÖØ-öø-ÿ_]+ matches all international letters
  45.         $in array(
  46.             $prefix '(?:index\.php\?|modules.php\?op=modload&(?:amp;)?)name=([\w\d\.\:\_\/]+)(?:&(?:amp;)?file=index)?&amp;req=([\w\d+]+)?&amp;([\w\d+]+)=([\w\d+]+)?&amp;([\w\d+]+)=([\w\d+]+)?&amp;([\w\d+]+)=([\w\d+]+)[\'"]]',
  47.             $prefix '(?:index\.php\?|modules.php\?op=modload&(?:amp;)?)name=([\w\d\.\:\_\/]+)(?:&(?:amp;)?file=index)?&amp;req=([\w\d+]+)?&amp;([\w\d+]+)=([\w\d+]+)?&amp;([\w\d+]+)=([\w\d+]+)[\'"]]',
  48.             $prefix '(?:index\.php\?|modules.php\?op=modload&(?:amp;)?)name=([\w\d\.\:\_\/]+)(?:&(?:amp;)?file=index)?&amp;req=([\w\d+]+)?&amp;([\w\d+]+)=([\w\d+]+)[\'"]]',
  49.             $prefix '(?:index\.php\?|modules.php\?op=modload&(?:amp;)?)name=([\w\d\.\:\_\/]+)(?:&(?:amp;)?file=index)?&amp;req=([\w\d+]+)[\'"]]',
  50.             $prefix '(?:index\.php\?|modules.php\?op=modload&(?:amp;)?)name=([\w\d\.\:\_\/]+)(?:&(?:amp;)?file=index)?[\'"]]',
  51.             '[<([^>]+)\s(src|href|background|action)\s*=\s*((["\'])?)(?!http)(?!mailto)(?!javascript:)(?![/"\'\s#]+)]Ui'
  52.         );
  53.  
  54.         $out array(
  55.             //    Generic links for old modules
  56.             '$1"'.$baseurl.'$2/$3/$4/$5/$6/$7/$8/$9"',
  57.             '$1"'.$baseurl.'$2/$3/$4/$5/$6/$7"',
  58.             '$1"'.$baseurl.'$2/$3/$4/$5"',
  59.             '$1"'.$baseurl.'$2/$3/"',
  60.             '$1"'.$baseurl.'$2/"',
  61.             '<$1 $2=$3'.$baseurl
  62.         );
  63.     else if ($type !== 'admin' && !stristr(pnServerGetVar('QUERY_STRING')'admin')) {
  64.         // Credits to
  65.         // ColdRolledSteel: for creating this file and the rewrite rules / per aver creato questo file e le regole di riscrittura
  66.         // msandersen: for tweaking this file and the rewrite rules / per aver aggiornato questo file e le regole di riscrittura
  67.         // CHTEKK: adaptation for eNvolution, writing/rewriting of many rules, italian translation and on/off variable / adattazione ad eNvolution, scrittura/riscrittura di diverse regole, traduzione italiana e variabile on/off
  68.         //
  69.         // If you control the server, it is preferable for better performance to put rewrite rules
  70.         // from the .htaccess file into main configuration file, httpd.conf.
  71.  
  72.         $extension pnConfigGetVar('shorturlsext');
  73.         $prefix '|"(?:'.$baseurl.')?';
  74.         $entrypoint pnConfigGetVar('entrypoint''index.php');
  75.  
  76.         // (?i) means case insensitive; \w='word' character; \d=digit; (amp;)? means optional; (?:catid=)? means optional and won't capture string for backreferences
  77.         $in array(
  78.             $prefix $entrypoint '\?newlang=([\w\d\.\:\_\/]+)"|',
  79.             $prefix '\?theme=([\w\d\.\:\_\/]+)"|',
  80.             $prefix '\?newtheme=([\w\d\.\:\_\/]+)"|',
  81.             $prefix $entrypoint '"|',
  82.             $prefix 'user.php"|',
  83.             $prefix 'print.php\?sid=(\d+)"|',
  84.             $prefix $entrypoint '\?name=([\w\d\.\:\_\/]+)"|',
  85.             $prefix $entrypoint '\?name=([\w\d\.\:\_\/]+)[#]([\w\d]*)"|',
  86.             $prefix $entrypoint '\?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=index"|',
  87.             $prefix $entrypoint '\?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=index[#]([\w\d]*)"|',
  88.             $prefix $entrypoint '\?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)"|',
  89.             $prefix $entrypoint '\?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)[#]([\w\d]*)"|',
  90.             $prefix $entrypoint '\?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)"|',
  91.             $prefix $entrypoint '\?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)[#]([\w\d]*)"|',
  92.             $prefix $entrypoint '\?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)"|',
  93.             $prefix $entrypoint '\?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)[#]([\w\d]*)"|',
  94.             $prefix $entrypoint '\?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)"|',
  95.             $prefix $entrypoint '\?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)[#]([\w\d]*)"|',
  96.             $prefix $entrypoint '\?module=([\w\d\.\:\_\/]+)"|',
  97.             $prefix $entrypoint '\?module=([\w\d\.\:\_\/]+)[#]([\w\d]*)"|',
  98.             $prefix $entrypoint '\?module=([\w\d\.\:\_\/]+)&(?:amp;)?func=main"|',
  99.             $prefix $entrypoint '\?module=([\w\d\.\:\_\/]+)&(?:amp;)?func=main[#]([\w\d]*)"|',
  100.             $prefix $entrypoint '\?module=([\w\d\.\:\_\/]+)&(?:amp;)?func=([\w\d\.\:\_\/]+)"|',
  101.             $prefix $entrypoint '\?module=([\w\d\.\:\_\/]+)&(?:amp;)?func=([\w\d\.\:\_\/]+)[#]([\w\d]*)"|',
  102.             $prefix $entrypoint '\?module=([\w\d\.\:\_\/]+)&(?:amp;)?func=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)"|',
  103.             $prefix $entrypoint '\?module=([\w\d\.\:\_\/]+)&(?:amp;)?func=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)[#]([\w\d]*)"|',
  104.             $prefix $entrypoint '\?module=([\w\d\.\:\_\/]+)&(?:amp;)?func=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)"|',
  105.             $prefix $entrypoint '\?module=([\w\d\.\:\_\/]+)&(?:amp;)?func=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)[#]([\w\d]*)"|',
  106.             $prefix $entrypoint '\?module=([\w\d\.\:\_\/]+)&(?:amp;)?func=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)"|',
  107.             $prefix $entrypoint '\?module=([\w\d\.\:\_\/]+)&(?:amp;)?func=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)"[#]([\w\d]*)|',
  108.             $prefix 'modules.php\?op=modload&(?:amp;)?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=index&(?:amp;)?req=([\w\d\.\:\_\/]+)"|',
  109.             $prefix 'modules.php\?op=modload&(?:amp;)?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=index"|',
  110.             $prefix 'modules.php\?op=modload&(?:amp;)?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)"|',
  111.             $prefix 'modules.php\?op=modload&(?:amp;)?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)[#]([\w\d]*)"|',
  112.             $prefix 'modules.php\?op=modload&(?:amp;)?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)"|',
  113.             $prefix 'modules.php\?op=modload&(?:amp;)?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)[#]([\w\d]*)"|',
  114.             $prefix 'modules.php\?op=modload&(?:amp;)?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)"|',
  115.             $prefix 'modules.php\?op=modload&(?:amp;)?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)[#]([\w\d]*)"|',
  116.             $prefix 'modules.php\?op=modload&(?:amp;)?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)"|',
  117.             $prefix 'modules.php\?op=modload&(?:amp;)?name=([\w\d\.\:\_\/]+)&(?:amp;)?file=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)&(?:amp;)?([\w\d\.\:\_\/]+)=([\w\d\.\:\_\/]+)[#]([\w\d]*)"|'
  118.         );
  119.  
  120.         $out array(
  121.             '"changelang-$1.'.$extension.'"',
  122.             '"previewtheme-$1.'.$extension.'"',
  123.             '"changetheme-$1.'.$extension.'"',
  124.             '"index.'.$extension.'"',
  125.             '"user.'.$extension.'"',
  126.             '"PrintArticle$1.'.$extension.'"',
  127.             '"$1.'.$extension.'"',
  128.             '"$1.'.$extension.'#$2"',
  129.             '"$1.'.$extension.'"',
  130.             '"$1.'.$extension.'#$2"',
  131.             '"$1-$2.'.$extension.'"',
  132.             '"$1-$2.'.$extension.'#$3"',
  133.             '"$1-$2-$3-$4.'.$extension.'"',
  134.             '"$1-$2-$3-$4.'.$extension.'#$5"',
  135.             '"$1-$2-$3-$4-$5-$6.'.$extension.'"',
  136.             '"$1-$2-$3-$4-$5-$6.'.$extension.'#$7"',
  137.             '"$1-$2-$3-$4-$5-$6-$7-$8.'.$extension.'"',
  138.             '"$1-$2-$3-$4-$5-$6-$7-$8.'.$extension.'#$9"',
  139.             '"module-$1.'.$extension.'"',
  140.             '"module-$1.'.$extension.'#$2"',
  141.             '"module-$1.'.$extension.'"',
  142.             '"module-$1.'.$extension.'#$2"',
  143.             '"module-$1-$2.'.$extension.'"',
  144.             '"module-$1-$2.'.$extension.'#$3"',
  145.             '"module-$1-$2-$3-$4.'.$extension.'"',
  146.             '"module-$1-$2-$3-$4.'.$extension.'#$5"',
  147.             '"module-$1-$2-$3-$4-$5-$6.'.$extension.'"',
  148.             '"module-$1-$2-$3-$4-$5-$6.'.$extension.'#$7"',
  149.             '"module-$1-$2-$3-$4-$5-$6-$7-$8.'.$extension.'"',
  150.             '"module-$1-$2-$3-$4-$5-$6-$7-$8.'.$extension.'#$9"',
  151.             '"$1+$2.'.$extension.'"',
  152.             '"$1.'.$extension.'"',
  153.             '"$1-$2.'.$extension.'"',
  154.             '"$1-$2.'.$extension.'#$3"',
  155.             '"$1-$2-$3-$4.'.$extension.'"',
  156.             '"$1-$2-$3-$4.'.$extension.'#$5"',
  157.             '"$1-$2-$3-$4-$5-$6.'.$extension.'"',
  158.             '"$1-$2-$3-$4-$5-$6.'.$extension.'#$7"',
  159.             '"$1-$2-$3-$4-$5-$6-$7-$8.'.$extension.'"',
  160.             '"$1-$2-$3-$4-$5-$6-$7-$8.'.$extension.'#$9"'
  161.         );
  162.     else {
  163.         $in array();
  164.         $out array();
  165.     }
  166.     // perform the replacement
  167.     $source preg_replace($in$out$source);
  168.  
  169.     // return the modified source
  170.     return $source;
  171. }

Documentation generated on Fri, 18 Jul 2008 21:48:03 +0200 by phpDocumentor 1.4.1