Project

General

Profile

« Previous | Next » 

Revision 1993

Added by darkviper about 11 years ago

! /module/output_filter/filters/filterWbLink added extended format to [wblinkXX] - tag
+ /framework/WbLinkAbstract.php added abstract class/interface for filterWbLink

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12
===============================================================================
13 13

  
14
06 Nov-2013 Build 1993 Manuela v.d.Decken(DarkViper)
15
! /module/output_filter/filters/filterWbLink added extended format to [wblinkXX] - tag
16
+ /framework/WbLinkAbstract.php added abstract class/interface for filterWbLink
14 17
25 Oct-2013 Build 1992 Dietmar Woellbrink (Luisehahne)
15 18
! /admin/modules/index.php : captions of module lists changed from `directory` to real `name` and sorted by name
16 19
21 Oct-2013 Build 1991 Manuela v.d.Decken(DarkViper)
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.3');
54
if(!defined('REVISION')) define('REVISION', '1992');
54
if(!defined('REVISION')) define('REVISION', '1993');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/framework/WbLinkAbstract.php
1
<?php
2

  
3
/**
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19

  
20
/**
21
 * WbLinkAbstract.php
22
 *
23
 * @category     Core
24
 * @package      Core_Interfaces
25
 * @subpackage   WbLink outputfilter
26
 * @copyright    Manuela v.d.Decken <manuela@isteam.de>
27
 * @author       Manuela v.d.Decken <manuela@isteam.de>
28
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
29
 * @version      0.0.1
30
 * @revision     $Revision: $
31
 * @link         $HeadURL: $
32
 * @lastmodified $Date: $
33
 * @since        File available since 03.11.2013
34
 * @description  Interface definition for all addon/ * /WbLink.php
35
 */
36
abstract class WbLinkAbstract {
37

  
38
	protected $oDb  = null;
39
	protected $oReg = null;
40

  
41
	final public function __construct()
42
	{
43
		$this->oDb  = WbDatabase::getInstance();
44
		$this->oReg = WbAdaptor::getInstance();
45
	}
46

  
47
	abstract public function makeLinkFromTag(array $aReplacement);
48
//	abstract public function generateLinkList(Template $oTpl);
49

  
50

  
51
} // end of class WbLinkAbstract
branches/2.8.x/wb/modules/output_filter/filters/filterWbLink.php
1 1
<?php
2 2
/*
3
 * replace all "[wblink{page_id}]" with real links
4
 * @param string &$content : reference to global $content
5
 * @return void
6
 * @history 100216 17:00:00 optimise errorhandling, speed, SQL-strict
3
 * @param  string $content : contains the full content of the current page
4
 * @return string
5
 * @description replace all "[wblink{page_id}{?addon=n&item=n...}]" with real links to accessfiles<br />
6
 *     All modules must offer the class 'WbLink'(implementing 'WbLinkAbstract'), to be taken into consideration.
7 7
 */
8
	function doFilterWbLink($content)
8
	function doFilterWbLink($sContent)
9 9
	{
10
		global $database, $wb;
11
		$replace_list = array();
12
		$pattern = '/\[wblink([0-9]+)\]/isU';
13
		if(preg_match_all($pattern,$content,$ids))
10
		$oDb  = WbDatabase::getInstance();
11
		$oReg = WbAdaptor::getInstance();
12
		$aReplaceList = array();
13
		$sPattern = '/\[wblink([0-9]+)\??([^\]]*)\]/is';
14
		if(preg_match_all($sPattern,$sContent,$aMatches))
14 15
		{
15
			foreach($ids[1] as $key => $page_id) {
16
				$replace_list[$page_id] = $ids[0][$key];
17
			}
18
			foreach($replace_list as $page_id => $tag)
16
		// iterate through all found matches
17
			foreach($aMatches[0] as $iKey => $sKeyString )
19 18
			{
20
				$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.(int)$page_id;
21
				$link = $database->get_one($sql);
22
				if(!is_null($link)) {
23
					$link = $wb->page_link($link);
24
					$content = str_replace($tag, $link, $content);
19
				$aReplaceList[$sKeyString] = array();
20
			// use original Tag to save PageId
21
				$aReplaceList[$sKeyString]['PageId'] = $aMatches[1][$iKey];
22
			// if there are additional arguments given
23
				if($aMatches[2][$iKey])
24
				{
25
					$aReplaceList[$sKeyString]['Args'] = array();
26
					$aArgs = explode('&', $aMatches[2][$iKey]);
27
					foreach($aArgs as $sArgument)
28
					{
29
						$aTmp = explode('=', $sArgument);
30
						$aReplaceList[$sKeyString]['Args'][$aTmp[0]] = $aTmp[1];
31
					}
25 32
				}
26 33
			}
34
			if(sizeof($aReplaceList) > 0)
35
			{ // iterate list if replacements are available
36
				foreach($aReplaceList as $sKey => $aReplacement)
37
				{
38
				// set link on failure ('#' means, still stay on current page)
39
					$aReplaceList[$sKey] = '#';
40
				// handle normal pages links
41
					if(!isset($aReplacement['Args'])) 
42
					{
43
					// read corresponding link from table 'pages'
44
						$sql = 'SELECT `link` FROM `'.$oDb->TablePrefix.'pages` WHERE `page_id` = '.(int)$aReplacement['PageId'];
45
						if(($sLink = $oDb->get_one($sql)))
46
						{
47
							$sLink = trim(str_replace('\\', '/', $sLink), '/');
48
						// test if valid accessfile is available
49
							if(is_readable($oReg->AppPath.$oReg->PagesDir.$sLink.$oReg->PageExtension))
50
							{
51
							// create absolute URL
52
								$aReplaceList[$sKey] = $oReg->AppUrl.$oReg->PagesDir.$sLink.$oReg->PageExtension;
53
							}
54
						}
55
					// handle links of modules
56
					}else 
57
					{
58
					// build name of the needed class
59
						$sClass = 'm_'.$aReplacement['Args']['addon'].'_WbLink';
60
					// remove addon name from replacement array
61
						unset($aReplacement['Args']['addon']);
62
						if(class_exists($sClass))
63
						{
64
						// instantiate class
65
							$oWbLink = new $sClass();
66
						// the class must implement the interface
67
							if($oWbLink instanceof WbLinkAbstract)
68
							{
69
							// create real link from replacement data
70
								$aReplaceList[$sKey] = $oWbLink->makeLinkFromTag($aReplacement);
71
							}
72
						}
73
					}
74
				}
75
			// extract indexes into a new array
76
				$aSearchList = array_keys($aReplaceList);
77
			// replace all identified wblink-tags in content
78
				$sContent = str_replace($aSearchList, $aReplaceList, $sContent);
79
			}
27 80
		}
28
		return $content;
81
		return $sContent;
29 82
	}

Also available in: Unified diff