Project

General

Profile

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
/**
39
 * @var object $oDb the active instance of WbDatabase 
40
 */
41
	protected $oDb    = null;
42
/**
43
 * @var object $oReg the active instance of WbAdaptor
44
 */
45
	protected $oReg   = null;
46
/**
47
 * @var string $sAddon the name of the addon, which extends this class
48
 */
49
	protected $sAddon = '';
50
/**
51
 * protected constructor
52
 */
53
	final public function __construct()
54
	{
55
		$this->oDb    = WbDatabase::getInstance();
56
		$this->oReg   = WbAdaptor::getInstance();
57
		$this->sAddon = preg_replace('/^.*?_([^_]+)_[^_]*?$/', '\1', get_class($this));
58
	}
59

    
60

    
61
	abstract public function makeLinkFromTag(array $aReplacement);
62
	abstract public function &generateOptionsList();
63

    
64
/**
65
 * executeListGeneration
66
 * @return array by reference
67
 */
68
	final protected function &_executeListGeneration()
69
	{
70
		$aAddonItems = array();
71
		//generate news lists
72
		$sql = 'SELECT `p`.`'.$this::FIELDNAME_ITEM_ID.'` `ItemId`, `p`.`'.$this::FIELDNAME_PAGE_ID.'` `PageId`, '
73
		     .        '`s`.`section_id` `SectionId`, `p`.`'.$this::FIELDNAME_TITLE.'` `Title` '
74
		     . 'FROM `'.$this->oDb->TablePrefix.'sections` `s` '
75
			 . 'LEFT JOIN `'.$this->oDb->TablePrefix.$this::TABLE_NAME.'` `p` ON `s`.`section_id`= `p`.`'.$this::FIELDNAME_SECTION_ID.'` '
76
			 . 'WHERE `s`.`module`=\''.$this->sAddon.'\' '
77
		     . ($this::FIELDNAME_ACTIVE != '' ? 'AND `p`.`'.$this::FIELDNAME_ACTIVE.'`>0 ' : '')
78
			 . 'ORDER BY `s`.`page_id`, `s`.`section_id`'.($this::FIELDNAME_TIMESTAMP != '' ? ', `p`.`'.$this::FIELDNAME_TIMESTAMP.'` DESC' : '');
79
		if (( $oRes = $this->oDb->doQuery($sql))) {
80
		// preset group changer flags
81
			$iCurrentPage    = 0;
82
			$iCurrentSection = 0;
83
			$iSectionCounter = 0;
84
			while ($aItem = $oRes->fetchRow(MYSQL_ASSOC)) {
85
			// iterate all matches
86
				if ($iCurrentPage != $aItem['PageId']) {
87
				// change group by PageId
88
					$iCurrentPage = $aItem['PageId'];
89
					$aAddonItems[$iCurrentPage.'P'] = array();
90
				}
91
				if ($iCurrentSection != $aItem['SectionId']) {
92
				// change group by SectionId
93
					$iCurrentSection = $aItem['SectionId'];
94
					$aAddonItems[$iCurrentPage.'P'][] = array();
95
					$iSectionCounter = sizeof($aAddonItems[$iCurrentPage.'P'])-1;
96
				}
97
				// save current record
98
				$aAddonItems[$iCurrentPage.'P'][$iSectionCounter][] = array(
99
				    'wblink' => '[wblink'.$aItem['PageId'].'?addon='.$this->sAddon.'&item='.$aItem['ItemId'].']',
100
				    'title'  => preg_replace("/\r?\n/", "\\n", $this->oDb->escapeString($aItem['Title']))
101
				);
102
			}
103
		}
104
		return $aAddonItems;
105
	}
106
/**
107
 * makeLinkFromTag
108
 * @param string $sBasePath
109
 * @param array $aReplacement
110
 * @return string a valid URL or '#' on error
111
 */
112
	protected function _makeLinkFromTag($sBasePath, array $aReplacement)
113
	{
114
	// set link on failure ('#' means, still stay on current page)
115
		$sRetval = '#';
116
	// search `link` from posts table and create absolute URL
117
		$sql = 'SELECT `'.$this::FIELDNAME_LINK.'` '
118
			 . 'FROM `'.$this->oDb->TablePrefix.$this::TABLE_NAME.'` '
119
			 . 'WHERE `'.$this::FIELDNAME_ITEM_ID.'`='.$aReplacement['item'];
120
		if (($sLink = $this->oDb->get_one($sql))) {
121
			$sLink     = trim(str_replace('\\', '/', $sLink), '/');
122
			$sBasePath = rtrim(str_replace('\\', '/', $sBasePath), '/').'/';
123
		// test if valid accessfile is available
124
			$sFilePath = $sBasePath.$sLink.$this->oReg->PageExtension;
125
			if (is_readable($sFilePath)) {
126
				$sRelPath = preg_replace('/^'.preg_quote($this->oReg->AppPath, '/').'/', '', $sFilePath);
127
				$sRetval = $this->oReg->AppUrl.$sRelPath.$aReplacement['ancor'];
128
			}
129
		}
130
		return $sRetval;
131
	}
132
} // end of class WbLinkAbstract
(19-19/36)