Project

General

Profile

1 1993 darkviper
<?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 2026 darkviper
/**
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 1993 darkviper
	final public function __construct()
54
	{
55 2026 darkviper
		$this->oDb    = WbDatabase::getInstance();
56
		$this->oReg   = WbAdaptor::getInstance();
57
		$this->sAddon = preg_replace('/^.*?_([^_]+)_[^_]*?$/', '\1', get_class($this));
58 1993 darkviper
	}
59
60 2026 darkviper
61 1993 darkviper
	abstract public function makeLinkFromTag(array $aReplacement);
62 2014 darkviper
	abstract public function &generateOptionsList();
63 1993 darkviper
64 2014 darkviper
/**
65 2026 darkviper
 * executeListGeneration
66 2014 darkviper
 * @return array by reference
67
 */
68 2026 darkviper
	final protected function &_executeListGeneration()
69 2014 darkviper
	{
70
		$aAddonItems = array();
71
		//generate news lists
72 2026 darkviper
		$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 2014 darkviper
		     . 'FROM `'.$this->oDb->TablePrefix.'sections` `s` '
75 2026 darkviper
			 . '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 2027 darkviper
		     . ($this::FIELDNAME_ACTIVE != '' ? 'AND `p`.`'.$this::FIELDNAME_ACTIVE.'`>0 ' : '')
78 2026 darkviper
			 . 'ORDER BY `s`.`page_id`, `s`.`section_id`'.($this::FIELDNAME_TIMESTAMP != '' ? ', `p`.`'.$this::FIELDNAME_TIMESTAMP.'` DESC' : '');
79 2014 darkviper
		if (( $oRes = $this->oDb->doQuery($sql))) {
80 2026 darkviper
		// preset group changer flags
81 2014 darkviper
			$iCurrentPage    = 0;
82
			$iCurrentSection = 0;
83
			$iSectionCounter = 0;
84
			while ($aItem = $oRes->fetchRow(MYSQL_ASSOC)) {
85 2026 darkviper
			// iterate all matches
86 2014 darkviper
				if ($iCurrentPage != $aItem['PageId']) {
87 2026 darkviper
				// change group by PageId
88 2014 darkviper
					$iCurrentPage = $aItem['PageId'];
89
					$aAddonItems[$iCurrentPage.'P'] = array();
90
				}
91
				if ($iCurrentSection != $aItem['SectionId']) {
92 2026 darkviper
				// change group by SectionId
93 2014 darkviper
					$iCurrentSection = $aItem['SectionId'];
94
					$aAddonItems[$iCurrentPage.'P'][] = array();
95
					$iSectionCounter = sizeof($aAddonItems[$iCurrentPage.'P'])-1;
96
				}
97 2026 darkviper
				// save current record
98 2014 darkviper
				$aAddonItems[$iCurrentPage.'P'][$iSectionCounter][] = array(
99 2027 darkviper
				    'wblink' => '[wblink'.$aItem['PageId'].'?addon='.$this->sAddon.'&item='.$aItem['ItemId'].']',
100 2014 darkviper
				    'title'  => preg_replace("/\r?\n/", "\\n", $this->oDb->escapeString($aItem['Title']))
101
				);
102
			}
103
		}
104
		return $aAddonItems;
105
	}
106 2026 darkviper
/**
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 = trim(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 1993 darkviper
} // end of class WbLinkAbstract