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
	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 &generateOptionsList();
49

    
50
/**
51
 *
52
 * @param string $sAddonName
53
 * @param string $sAddonTableName
54
 * @param string $sPageIdName
55
 * @param string $sSectionIdName
56
 * @param string $sItemIdName
57
 * @param string $sDateTimeName
58
 * @param string $sTitleName
59
 * @param string $sActivatedName
60
 * @return array by reference
61
 */
62
	final protected function &_executeListGeneration(
63
	                                                  $sAddonName      = 'news',
64
	                                                  $sAddonTableName = 'mod_news_posts',
65
	                                                  $sPageIdName     = 'page_id',
66
	                                                  $sSectionIdName  = 'section_id',
67
	                                                  $sItemIdName     = 'post_id',
68
	                                                  $sDateTimeName   = 'created_when',
69
	                                                  $sTitleName      = 'title',
70
	                                                  $sActivatedName  = 'active'
71
	                                                )
72
	{
73
		$aAddonItems = array();
74
		//generate news lists
75
		$sql = 'SELECT `p`.`'.$sItemIdName.'` `ItemId`, `p`.`'.$sPageIdName.'` `PageId`, '
76
		     .        '`s`.`section_id` `SectionId`, `p`.`'.$sTitleName.'` `Title` '
77
		     . 'FROM `'.$this->oDb->TablePrefix.'sections` `s` '
78
			 . 'LEFT JOIN `'.$this->oDb->TablePrefix.$sAddonTableName.'` `p` ON `s`.`section_id`= `p`.`'.$sSectionIdName.'` '
79
			 . 'WHERE `p`.`'.$sActivatedName.'`>0 AND `s`.`module`=\''.$sAddonName.'\' '
80
			 . 'ORDER BY `s`.`page_id`, `s`.`section_id`, `p`.`'.$sDateTimeName.'` DESC';
81
		if (( $oRes = $this->oDb->doQuery($sql))) {
82
			$iCurrentPage    = 0;
83
			$iCurrentSection = 0;
84
			$iSectionCounter = 0;
85
			while ($aItem = $oRes->fetchRow(MYSQL_ASSOC)) {
86
				if ($iCurrentPage != $aItem['PageId']) {
87
					$iCurrentPage = $aItem['PageId'];
88
					$aAddonItems[$iCurrentPage.'P'] = array();
89
				}
90
				if ($iCurrentSection != $aItem['SectionId']) {
91
					$iCurrentSection = $aItem['SectionId'];
92
					$aAddonItems[$iCurrentPage.'P'][] = array();
93
					$iSectionCounter = sizeof($aAddonItems[$iCurrentPage.'P'])-1;
94
				}
95
				$aAddonItems[$iCurrentPage.'P'][$iSectionCounter][] = array(
96
				    'wblink' => '[wblink'.$aItem['PageId'].'?addon='.$sAddonName.'&item='.$aItem['ItemId'].']',
97
				    'title'  => preg_replace("/\r?\n/", "\\n", $this->oDb->escapeString($aItem['Title']))
98
				);
99
			}
100
		}
101
		return $aAddonItems;
102
	}
103

    
104

    
105
} // end of class WbLinkAbstract
(19-19/36)