Revision 2026
Added by darkviper almost 11 years ago
WbLinkAbstract.php | ||
---|---|---|
35 | 35 |
*/ |
36 | 36 |
abstract class WbLinkAbstract { |
37 | 37 |
|
38 |
protected $oDb = null; |
|
39 |
protected $oReg = null; |
|
40 |
|
|
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 |
*/ |
|
41 | 53 |
final public function __construct() |
42 | 54 |
{ |
43 |
$this->oDb = WbDatabase::getInstance(); |
|
44 |
$this->oReg = WbAdaptor::getInstance(); |
|
55 |
$this->oDb = WbDatabase::getInstance(); |
|
56 |
$this->oReg = WbAdaptor::getInstance(); |
|
57 |
$this->sAddon = preg_replace('/^.*?_([^_]+)_[^_]*?$/', '\1', get_class($this)); |
|
45 | 58 |
} |
46 | 59 |
|
60 |
|
|
47 | 61 |
abstract public function makeLinkFromTag(array $aReplacement); |
48 | 62 |
abstract public function &generateOptionsList(); |
49 | 63 |
|
50 | 64 |
/** |
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 |
|
65 |
* executeListGeneration |
|
60 | 66 |
* @return array by reference |
61 | 67 |
*/ |
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 |
) |
|
68 |
final protected function &_executeListGeneration() |
|
72 | 69 |
{ |
73 | 70 |
$aAddonItems = array(); |
74 | 71 |
//generate news lists |
75 |
$sql = 'SELECT `p`.`'.$sItemIdName.'` `ItemId`, `p`.`'.$sPageIdName.'` `PageId`, '
|
|
76 |
. '`s`.`section_id` `SectionId`, `p`.`'.$sTitleName.'` `Title` '
|
|
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` '
|
|
77 | 74 |
. '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'; |
|
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' : ''); |
|
81 | 79 |
if (( $oRes = $this->oDb->doQuery($sql))) { |
80 |
// preset group changer flags |
|
82 | 81 |
$iCurrentPage = 0; |
83 | 82 |
$iCurrentSection = 0; |
84 | 83 |
$iSectionCounter = 0; |
85 | 84 |
while ($aItem = $oRes->fetchRow(MYSQL_ASSOC)) { |
85 |
// iterate all matches |
|
86 | 86 |
if ($iCurrentPage != $aItem['PageId']) { |
87 |
// change group by PageId |
|
87 | 88 |
$iCurrentPage = $aItem['PageId']; |
88 | 89 |
$aAddonItems[$iCurrentPage.'P'] = array(); |
89 | 90 |
} |
90 | 91 |
if ($iCurrentSection != $aItem['SectionId']) { |
92 |
// change group by SectionId |
|
91 | 93 |
$iCurrentSection = $aItem['SectionId']; |
92 | 94 |
$aAddonItems[$iCurrentPage.'P'][] = array(); |
93 | 95 |
$iSectionCounter = sizeof($aAddonItems[$iCurrentPage.'P'])-1; |
94 | 96 |
} |
97 |
// save current record |
|
95 | 98 |
$aAddonItems[$iCurrentPage.'P'][$iSectionCounter][] = array( |
96 |
'wblink' => '[wblink'.$aItem['PageId'].'?addon='.$sAddonName.'&item='.$aItem['ItemId'].']',
|
|
99 |
'wblink' => '[wblink'.$aItem['PageId'].'?addon='.$sAddon.'&item='.$aItem['ItemId'].']', |
|
97 | 100 |
'title' => preg_replace("/\r?\n/", "\\n", $this->oDb->escapeString($aItem['Title'])) |
98 | 101 |
); |
99 | 102 |
} |
100 | 103 |
} |
101 | 104 |
return $aAddonItems; |
102 | 105 |
} |
103 |
|
|
104 |
|
|
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 = 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 |
} |
|
105 | 132 |
} // end of class WbLinkAbstract |
Also available in: Unified diff
! [wblink] outputfilter now can handle ancors too
! WbLink Interface is much more easier to use now.