4 * Arthrology for Elxis CMS 2008.x and 2009.x+
6 * Frontend Event Handler
10 * @author Apostolos Koutsoulelos <akoutsoulelos@yahoo.gr>
11 * @authorurl http://www.bitcraft-labs.gr
12 * @copyright Copyright (C) 2009-2011 Apostolos Koutsoulelos. All rights reserved.
13 * @license GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
15 * @link http://www.elxis-downloads.com/downloads/miscellaneous/204.html
18 // Prevent direct inclusion of this file
19 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
21 // Check the permissions
22 if ( $my->usertype
== '' ) {
23 $usertype = eUTF
::utf8_strtolower($acl->get_group_name('29'));
25 $usertype = eUTF
::utf8_strtolower($my->usertype
);
27 // Check if the user is allowed to access this component. If not then re-direct him to the main page.
28 if (($mosConfig_access == '1') |
($mosConfig_access == '3')) {
29 if (!($acl->acl_check( 'action', 'view', 'users', $usertype, 'components', 'all' ) ||
30 $acl->acl_check( 'action', 'view', 'users', $usertype, 'components', 'com_arthrology' ))) {
31 mosRedirect( 'index.php', _NOT_AUTH
);
36 require_once($mainframe->getCfg('absolute_path' ).'/components/com_arthrology/arthrology.class.php'); // Component's general class
37 require_once($mainframe->getCfg('absolute_path' ).'/components/com_arthrology/arthrology.html.php'); // Component's html file for the public area
39 /*************************************************************************/
40 /* THE CLASS THAT WILL CONTAIN THE COMPONENT'S FRONT-END FUNCTIONALITY */
41 /*************************************************************************/
44 // Initialize variables
45 public $live_path = ''; // component's live path
46 public $abs_path = ''; // component's absolute path
47 public $lng = null; // component's language
48 public $params = array(); // component's parameters
54 /****************************/
55 /* The class' constructor */
56 /****************************/
57 public function __construct() {
58 global $mainframe, $lang, $Itemid, $database;
60 // Set absolute and live path
61 $this->live_path
= $mainframe->getCfg('live_site').'/components/com_arthrology';
62 $this->abs_path
= $mainframe->getCfg('absolute_path').'/components/com_arthrology';
65 if (file_exists($this->abs_path
.'/language/'.$lang.'.php')) {
66 require_once($this->abs_path
.'/language/'.$lang.'.php');
68 require_once($this->abs_path
.'/language/english.php');
70 $this->lng
= new clsArthrologyLng();
72 // Load params from Arthrology (component)
73 $database->setQuery("SELECT params FROM #__components WHERE link = 'option=com_arthrology'", '#__', 1, 0);
74 $result = $database->loadResult();
75 $com_params = new mosParameters($result);
76 // Load params from MENUITEM
77 $menu = new mosMenu($database);
79 $menu_params = new mosParameters($menu->params
);
80 // Create an array with parameters
81 $this->params
['com'] = $com_params;
82 $this->params
['menu'] = $menu_params;
83 $this->params
['menuobj'] = $menu;
85 //Set current task and keyword
86 $this->task
= $this->makesafe((string)mosGetParam($_REQUEST, 'task' , 'search'));
89 $this->keyword
= $this->makesafe((string)mosGetParam($_POST, 'keyword' , NULL));
90 if ($this->keyword
== '') {
91 $this->keyword
= $this->makesafe((string)mosGetParam($_REQUEST, 'keyword' , NULL));
93 $this->catid
= $this->makesafe((string)mosGetParam($_POST, 'catid', NULL));
94 if ($this->catid
== '') {
95 $this->catid
= $this->makesafe((string)mosGetParam($_REQUEST, 'catid' , NULL));
99 /******************************/
100 /* The class' main function */
101 /******************************/
102 public function main() {
105 clsArthrologyHTML
::prepareHTML();
107 switch($this->task
) {
110 $this->showResults();
113 clsArthrologyHTML
::searchScreenHTML();
115 default: // Redirect to search mode
116 mosRedirect( sefRelToAbs("index.php?option=com_arthrology&task=search&Itemid=".$Itemid, ARTHBASE
."/search.html") );
121 /*****************************/
122 /* Prepare to show results */
123 /*****************************/
124 private function showResults() {
125 global $database, $mainframe;
127 if (eUTF
::utf8_strlen($this->keyword
) >= 3) {
128 $like_clause = "\n AND ((e.title LIKE '%".$this->keyword
."%') OR (e.tags LIKE '%".$this->keyword
."%') OR (e.description LIKE '%".$this->keyword
."%') OR (e.author LIKE '%".$this->keyword
."%'))";
134 $where_clause = "\n WHERE e.published = '1' AND c.id = '" . $this->catid
. "'";
136 $where_clause = "\n WHERE e.published = '1'";
139 // Load page navigation
140 $query = "SELECT COUNT(e.id) FROM #__arthrology e"
141 ."\n INNER JOIN #__categories c ON c.id = e.catid"
144 $database->setQuery($query);
145 $total = intval($database->loadResult());
147 if ($this->task
!= 'printlist') {
148 $limit = $this->params
['com']->get('limit', 25);
150 if ($mainframe->getCfg('sef') == 2) {
151 $page = intval(mosGetParam($_REQUEST, 'page', 0));
152 if ($page < 1) { $page = 0; }
153 $limitstart = ($page * $limit);
155 if ( $total <= $limit ) { $limitstart = 0; }
161 require_once($mainframe->getCfg('absolute_path').'/includes/pageNavigation.php');
162 $pageNav = new mosPageNav($total, $limitstart, $limit);
165 $query = "SELECT e.*, c.title AS cat_name, c.description AS cat_description, c.params AS cat_params, c.seotitle AS cat_seotitle"
166 ."\n FROM #__arthrology e"
167 ."\n INNER JOIN #__categories c ON c.id = e.catid"
170 ."\n ORDER BY e.year DESC, c.title ASC, e.title ASC";
171 $database->setQuery($query, '#__', $pageNav->limit
, $pageNav->limitstart
);
172 $rows = $database->loadObjectList();
174 clsArthrologyHTML
::showResultsHTML($this->keyword
, $this->catid
, $rows, $total, $pageNav);
178 /***********************/
179 /* Make strings safe */
180 /***********************/
181 public function makesafe($string='', $strict=1) {
182 // Special thanks to Ioannis <datahell> Sannos for this
184 if ($string == '') { return $string; }
186 $pat = "([\']|[\!]|[\(]|[\)]|[\;]|[\"]|[\$]|[\#]|[\<]|[\>]|[\*]|[\%]|[\~]|[\`]|[\^]|[\|]|[\{]|[\}]|[\\\])";
188 $pat = "([\']|[\"]|[\$]|[\#]|[\<]|[\>]|[\*]|[\%]|[\~]|[\`]|[\^]|[\|]|[\{]|[\}]|[\\\])";
190 $s = eUTF
::utf8_trim(preg_replace($pat, '', $string));
195 // Initiate the class and execute it, then unset the
196 // object in order to free the allocated PHP memory.
197 $objArthrology = new clsArthrology();
198 $objArthrology->main();
199 unset($objArthrology);