Cheetah
tags.php
Go to the documentation of this file.
1 <?php
2 
8 define('CH_TAGS_ACTION_HOME', 'home');
9 define('CH_TAGS_ACTION_ALL', 'all');
10 define('CH_TAGS_ACTION_POPULAR', 'popular');
11 define('CH_TAGS_ACTION_CALENDAR', 'calendar');
12 define('CH_TAGS_ACTION_SEARCH', 'search');
13 
14 define('CH_TAGS_BOX_DISIGN', 1);
15 define('CH_TAGS_BOX_INT_MENU', 2);
16 
17 require_once( 'inc/header.inc.php' );
18 require_once( CH_DIRECTORY_PATH_INC . 'design.inc.php' );
19 
20 ch_import('ChTemplTags');
21 ch_import('ChWsbPageView');
22 ch_import('ChTemplCalendar');
23 
24 $bAjaxMode = isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ? true : false;
25 
26 function showTags($aParam = array(), $iBoxId = 1, $sAction = '', $iBox = 0, $sTitle = '')
27 {
28  $oTags = new ChTemplTags();
29 
30  $oTags->getTagObjectConfig($aParam);
31 
32  if (empty($oTags->aTagObjects)) {
33  if ($iBox & CH_TAGS_BOX_DISIGN)
34  return DesignBoxContent($sTitle, MsgBox(_t('_Empty')), 1);
35  else
36  return MsgBox(_t('_Empty'));
37  }
38 
39  $aParam['type'] = isset($_GET['tags_mode']) && isset($oTags->aTagObjects[$_GET['tags_mode']]) ? $_GET['tags_mode'] : $oTags->getFirstObject();
40 
41  $sCode = '';
42  if ($iBox & CH_TAGS_BOX_INT_MENU)
43  $sCode .= $oTags->getTagsInternalMenuHtml($aParam, $iBoxId, $sAction);
44  $sCode .= $oTags->display($aParam, $iBoxId, $sAction);
45 
46  if ($iBox & CH_TAGS_BOX_DISIGN) {
47  $aCaptionMenu = $iBox & CH_TAGS_BOX_INT_MENU ? '' : $oTags->getTagsTopMenuHtml($aParam, $iBoxId, $sAction);
48  $sCode = DesignBoxContent($sTitle, $sCode, 1, $aCaptionMenu);
49  $sCode = '<div id="page_block_' . $iBoxId . '">' . $sCode . '<div class="clear_both"></div></div>';
50  return $sCode;
51  } else
52  return array(
53  $sCode,
54  ($iBox & CH_TAGS_BOX_INT_MENU ? '' : $oTags->getTagsTopMenu($aParam, $sAction)),
55  array(),
56  ($sDate ? _t('_tags_by_day') . $sDate : '')
57  );
58 }
59 
61 {
63  {
64  parent::__construct($iYear, $iMonth);
65  }
66 
67  function display($isMiniMode = false)
68  {
69  $sTopControls = $GLOBALS['oSysTemplate']->parseHtmlByName('calendar_top_controls.html', array(
70  'month_prev_url' => $this->getBaseUri () . "&year={$this->iPrevYear}&month={$this->iPrevMonth}",
71  'month_next_url' => $this->getBaseUri () . "&year={$this->iNextYear}&month={$this->iNextMonth}",
72  'month_current' => $this->getTitle(),
73  ));
74 
75  $sHtml = $GLOBALS['oSysTemplate']->parseHtmlByName('calendar.html', array (
76  'top_controls' => $sTopControls,
77  'ch_repeat:week_names' => $this->_getWeekNames (),
78  'ch_repeat:calendar_row' => $this->_getCalendar (),
79  'bottom_controls' => $sTopControls,
80  ));
81  $sHtml = preg_replace ('#<ch_repeat:events>.*?</ch_repeat:events>#s', '', $sHtml);
82  $GLOBALS['oSysTemplate']->addCss('calendar.css');
83  return $sHtml;
84  }
85 
86  function getData()
87  {
89 
90  return $oDb->getAll("SELECT *, DAYOFMONTH(`Date`) AS `Day`
91  FROM `sys_tags`
92  WHERE `Date` >= TIMESTAMP(?) AND `Date` < TIMESTAMP(?)",
93  [
94  "{$this->iYear}-{$this->iMonth}-1",
95  "{$this->iNextYear}-{$this->iNextMonth}-1"
96  ]
97  );
98  }
99 
100  function getBaseUri()
101  {
102  return CH_WSB_URL_ROOT . 'tags.php?action=calendar';
103  }
104 
105  function getBrowseUri()
106  {
107  return CH_WSB_URL_ROOT . 'tags.php?action=calendar';
108  }
109 
110  function getEntriesNames ()
111  {
112  return array(_t('_tags_single'), _t('_tags_plural'));
113  }
114 
115  function _getCalendar ()
116  {
117  $sBrowseUri = $this->getBrowseUri();
118  list ($sEntriesSingle, $sEntriesMul) = $this->getEntriesNames ();
119 
120  $this->_getCalendarGrid($aCalendarGrid);
121  $aRet = array ();
122  for ($i = 0; $i < 6; $i++) {
123 
124  $aRow = array ('ch_repeat:cell');
125  $isRowEmpty = true;
126 
127  for ($j = $this->iWeekStart; $j < $this->iWeekEnd; $j++) {
128 
129  $aCell = array ();
130 
131  if ($aCalendarGrid[$i][$j]['today']) {
132  $aCell['class'] = 'sys_cal_cell sys_cal_today';
133  $aCell['day'] = $aCalendarGrid[$i][$j]['day'];
134  $aCell['ch_if:num'] = array ('condition' => $aCalendarGrid[$i][$j]['num'], 'content' => array(
135  'num' => $aCalendarGrid[$i][$j]['num'],
136  'href' => $sBrowseUri . '&year=' . $this->iYear . '&month=' . $this->iMonth . '&day=' . $aCell['day'],
137  'entries' => 1 == $aCalendarGrid[$i][$j]['num'] ? $sEntriesSingle : $sEntriesMul,
138  ));
139  $isRowEmpty = false;
140  } elseif (isset($aCalendarGrid[$i][$j]['day'])) {
141  $aCell['class'] = 'sys_cal_cell';
142  $aCell['day'] = $aCalendarGrid[$i][$j]['day'];
143  $aCell['ch_if:num'] = array ('condition' => $aCalendarGrid[$i][$j]['num'], 'content' => array(
144  'num' => $aCalendarGrid[$i][$j]['num'],
145  'href' => $sBrowseUri . '&year=' . $this->iYear . '&month=' . $this->iMonth . '&day=' . $aCell['day'],
146  'entries' => 1 == $aCalendarGrid[$i][$j]['num'] ? $sEntriesSingle : $sEntriesMul,
147  ));
148  $isRowEmpty = false;
149  } else {
150  $aCell['class'] = 'sys_cal_cell_blank';
151  $aCell['day'] = '';
152  $aCell['ch_if:num'] = array ('condition' => false, 'content' => array(
153  'num' => '',
154  'href' => '',
155  'entries' => '',
156  ));
157  }
158 
159  if ($aCell)
160  $aRow['ch_repeat:cell'][] = $aCell;
161  }
162 
163  if ($aRow['ch_repeat:cell'] && !$isRowEmpty) {
164  $aRet[] = $aRow;
165  }
166  }
167  return $aRet;
168  }
169 
170 }
171 
173 {
174  var $sPage;
175 
176  function __construct()
177  {
178  $this->sPage = 'tags_home';
179  parent::__construct($this->sPage);
180  }
181 
182  function getBlockCode_Recent($iBlockId)
183  {
184  $aParam = array(
185  'orderby' => 'recent',
186  'limit' => getParam('tags_show_limit'),
187  );
188 
189  return showTags($aParam, $iBlockId, CH_TAGS_ACTION_HOME, CH_TAGS_BOX_INT_MENU, _t('_tags_recent'));
190  }
191 
192  function getBlockCode_Popular($iBlockId)
193  {
194  $aParam = array(
195  'orderby' => 'popular',
196  'limit' => getParam('tags_show_limit')
197  );
198 
199  return showTags($aParam, $iBlockId, CH_TAGS_ACTION_HOME, 0, _t('_tags_popular'));
200  }
201 }
202 
204 {
205  var $sPage;
206 
207  function __construct()
208  {
209  $this->sPage = 'tags_calendar';
210  parent::__construct($this->sPage);
211  }
212 
213  function getBlockCode_Calendar($iBlockId)
214  {
215  $sYear = isset($_GET['year']) ? (int)$_GET['year'] : '';
216  $sMonth = isset($_GET['month']) ? (int)$_GET['month'] : '';
217  $oCalendar = new TagsCalendar($sYear, $sMonth);
218 
219  return $oCalendar->display();
220  }
221 
222  function getBlockCode_TagsDate($iBlockId)
223  {
224  if (isset($_GET['year']) && isset($_GET['month']) && isset($_GET['day'])) {
225  $aParam = array(
226  'pagination' => getParam('tags_perpage_browse'),
227  'date' => array(
228  'year' => (int)$_GET['year'],
229  'month' => (int)$_GET['month'],
230  'day' => (int)$_GET['day']
231  )
232  );
233 
234  return showTags($aParam, $iBlockId, CH_TAGS_ACTION_CALENDAR, 0, _t('_tags_by_day'));
235  } else
236  return MsgBox(_t('_Empty'));
237  }
238 }
239 
241 {
243  var $oForm;
244  var $sPage;
245 
246  function __construct()
247  {
248  $this->sPage = 'tags_search';
249  parent::__construct($this->sPage);
250 
251  ch_import('ChTemplFormView');
252  $this->aSearchForm = array(
253  'form_attrs' => array(
254  'name' => 'form_search_tags',
255  'action' => '',
256  'method' => 'post',
257  ),
258 
259  'params' => array (
260  'db' => array(
261  'submit_name' => 'submit_form',
262  ),
263  ),
264 
265  'inputs' => array(
266  'Keyword' => array(
267  'type' => 'text',
268  'name' => 'Keyword',
269  'caption' => _t('_tags_caption_keyword'),
270  'required' => true,
271  'checker' => array (
272  'func' => 'length',
273  'params' => array(1, 100),
274  'error' => _t ('_tags_err_keyword'),
275  ),
276  'db' => array (
277  'pass' => 'Xss',
278  ),
279  ),
280  'Submit' => array (
281  'type' => 'submit',
282  'name' => 'submit_form',
283  'value' => _t('_Submit'),
284  'colspan' => true,
285  ),
286  ),
287  );
288 
289  $this->oForm = new ChTemplFormView($this->aSearchForm);
290  $this->oForm->initChecker();
291  }
292 
293  function getBlockCode_Form()
294  {
295  return $GLOBALS['oSysTemplate']->parseHtmlByName('search_tags_box.html', array('form' => $this->oForm->getCode()));
296  }
297 
298  function getBlockCode_Founded($iBlockId)
299  {
300  $aParam = array(
301  'pagination' => getParam('tags_perpage_browse')
302  );
303 
304  $sFilter = ch_get('filter');
305  if ($sFilter !== false)
306  $aParam['filter'] = process_db_input($sFilter);
307  else if ($this->oForm->isSubmittedAndValid())
308  $aParam['filter'] = $this->oForm->getCleanValue('Keyword');
309 
310  if (isset($aParam['filter']))
311  return showTags($aParam, $iBlockId, CH_TAGS_ACTION_SEARCH, 0, _t('_tags_founded_tags'));
312  else
313  return MsgBox(_t('_Empty'));
314  }
315 }
316 
317 function getPage_Home()
318 {
319  $oHomePage = new TagsHomePage();
320 
321  return $oHomePage->getCode();
322 }
323 
324 function getPage_All()
325 {
326  $aParam = array(
327  'pagination' => getParam('tags_perpage_browse')
328  );
329 
330  return showTags($aParam, 1, CH_TAGS_ACTION_ALL, CH_TAGS_BOX_DISIGN, _t('_all_tags'));
331 }
332 
333 function getPage_Popular()
334 {
335  $aParam = array(
336  'orderby' => 'popular',
337  'limit' => getParam('tags_show_limit')
338  );
339 
340  return showTags($aParam, 2, CH_TAGS_ACTION_POPULAR, CH_TAGS_BOX_DISIGN, _t('_popular_tags'));
341 }
342 
344 {
345  $oCalendarPage = new TagsCalendarPage();
346 
347  return $oCalendarPage->getCode();
348 }
349 
350 function getPage_Search()
351 {
352  $oSearchPage = new TagsSearchPage();
353 
354  return $oSearchPage->getCode();
355 }
356 
357 $sAction = empty($_GET['action']) ? '' : $_GET['action'];
358 switch ($sAction) {
361  break;
362 
363  case CH_TAGS_ACTION_ALL:
365  break;
366 
369  break;
370 
373  break;
374 
375  default:
377 }
378 
379 if (!$bAjaxMode) {
380  global $_page;
382  $iIndex = 25;
383 
384  $_page['name_index'] = $iIndex;
385  $_page['css_name'] = 'tags.css';
386 
387  $_page['header'] = _t('_Tags');
388  $_page['header_text'] = _t('_Tags');
389  $_page_cont[$iIndex]['page_main_code'] = $sContent;
390 
391  check_logged();
392  PageCode();
393 } else
394  echo $sContent;
TagsCalendarPage\getBlockCode_Calendar
getBlockCode_Calendar($iBlockId)
Definition: tags.php:213
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
TagsSearchPage\$sPage
$sPage
Definition: tags.php:244
$sAction
$sAction
Definition: tags.php:357
ChWsbCalendar\$iMonth
$iMonth
Definition: ChWsbCalendar.php:50
TagsSearchPage
Definition: tags.php:241
ChTemplFormView
Definition: ChTemplFormView.php:11
true
if(!defined("TRUE_VAL")) define("TRUE_VAL" true
Definition: constants.inc.php:8
$bAjaxMode
$bAjaxMode
Definition: tags.php:24
TagsCalendarPage
Definition: tags.php:204
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
check_logged
check_logged()
Definition: admin.inc.php:238
TagsSearchPage\$oForm
$oForm
Definition: tags.php:243
ChWsbPageView
Definition: ChWsbPageView.php:99
$sCode
$sCode
Definition: explanation.php:19
TagsCalendarPage\$sPage
$sPage
Definition: tags.php:205
$_page
$_page['name_index']
Definition: about_us.php:13
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$_page_cont
$_page_cont[$_ni]['page_main_code']
Definition: about_us.php:24
ch_get
ch_get($sName)
Definition: utils.inc.php:1664
getPage_Search
getPage_Search()
Definition: tags.php:350
ChWsbCalendar\_getWeekNames
_getWeekNames($isMiniMode=false)
Definition: ChWsbCalendar.php:101
getPage_Calendar
getPage_Calendar()
Definition: tags.php:343
ChWsbCalendar\_getCalendarGrid
_getCalendarGrid(&$aCalendarGrid)
Definition: ChWsbCalendar.php:119
php
getPage_Popular
getPage_Popular()
Definition: tags.php:333
TagsCalendarPage\getBlockCode_TagsDate
getBlockCode_TagsDate($iBlockId)
Definition: tags.php:222
TagsCalendar\display
display($isMiniMode=false)
Definition: tags.php:67
TagsHomePage\getBlockCode_Popular
getBlockCode_Popular($iBlockId)
Definition: tags.php:192
CH_TAGS_BOX_DISIGN
const CH_TAGS_BOX_DISIGN
Definition: tags.php:14
showTags
showTags($aParam=array(), $iBoxId=1, $sAction='', $iBox=0, $sTitle='')
Definition: tags.php:26
CH_TAGS_BOX_INT_MENU
const CH_TAGS_BOX_INT_MENU
Definition: tags.php:15
TagsCalendar
Definition: tags.php:61
ChWsbCalendar\getTitle
getTitle()
Definition: ChWsbCalendar.php:200
$_GET
$_GET['debug']
Definition: index.php:67
$iIndex
$iIndex
Definition: bottom_menu_compose.php:142
and
and
Definition: license.txt:18
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
TagsSearchPage\$aSearchForm
$aSearchForm
Definition: tags.php:242
$sTitle
$sTitle
Definition: actions.inc.php:13
ChTemplTags
Definition: ChTemplTags.php:11
$oDb
global $oDb
Definition: db.inc.php:39
CH_TAGS_ACTION_ALL
const CH_TAGS_ACTION_ALL
Definition: tags.php:9
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
CH_TAGS_ACTION_HOME
const CH_TAGS_ACTION_HOME
Definition: tags.php:8
$sContent
$sContent
Definition: bottom_menu_compose.php:169
TagsHomePage\getBlockCode_Recent
getBlockCode_Recent($iBlockId)
Definition: tags.php:182
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
PageCode
PageCode($oTemplate=null)
Definition: design.inc.php:91
TagsCalendar\__construct
__construct($iYear, $iMonth)
Definition: tags.php:62
TagsSearchPage\getBlockCode_Founded
getBlockCode_Founded($iBlockId)
Definition: tags.php:298
TagsCalendar\_getCalendar
_getCalendar()
Definition: tags.php:115
TagsSearchPage\__construct
__construct()
Definition: tags.php:246
TagsHomePage\$sPage
$sPage
Definition: tags.php:174
ChTemplCalendar
Definition: ChTemplCalendar.php:14
TagsCalendar\getData
getData()
Definition: tags.php:86
TagsSearchPage\getBlockCode_Form
getBlockCode_Form()
Definition: tags.php:293
CH_TAGS_ACTION_SEARCH
const CH_TAGS_ACTION_SEARCH
Definition: tags.php:12
TagsHomePage\__construct
__construct()
Definition: tags.php:176
ChWsbCalendar\$iWeekEnd
$iWeekEnd
Definition: ChWsbCalendar.php:51
DesignBoxContent
DesignBoxContent($title, $content, $db_num=0, $caption_item='', $bottom_item='')
Definition: design.inc.php:78
TagsCalendar\getEntriesNames
getEntriesNames()
Definition: tags.php:110
getPage_Home
getPage_Home()
Definition: tags.php:317
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
TagsCalendar\getBrowseUri
getBrowseUri()
Definition: tags.php:105
TagsHomePage
Definition: tags.php:173
ChWsbCalendar\$iYear
$iYear
Definition: ChWsbCalendar.php:50
ChWsbDb\getInstance
static getInstance()
Definition: ChWsbDb.php:82
CH_TAGS_ACTION_POPULAR
const CH_TAGS_ACTION_POPULAR
Definition: tags.php:10
TagsCalendarPage\__construct
__construct()
Definition: tags.php:207
CH_TAGS_ACTION_CALENDAR
const CH_TAGS_ACTION_CALENDAR
Definition: tags.php:11
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
TagsCalendar\getBaseUri
getBaseUri()
Definition: tags.php:100
getPage_All
getPage_All()
Definition: tags.php:324