4 * Event Calendar for Elxis CMS 2008.x and 2009.x
9 * @package eventCalendar
10 * @author Apostolos Koutsoulelos <akoutsoulelos@yahoo.gr>
11 * @copyright Copyright (C) 2009-2010 Apostolos Koutsoulelos. All rights reserved.
12 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
16 // Prevent direct inclusion of this file
17 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
22 // Include seovs class
23 require_once($mainframe->getCfg('absolute_path').'/administrator/includes/seovs.class.php');
25 /*********************************************************/
26 /* THE CLASS THAT WILL CONTAIN THE SEOVS FUNCTIONALITY */
27 /*********************************************************/
28 class seovsEventCalendar
extends seovs
{
32 public $seotitle = '';
41 /********************/
42 /* Generate message */
43 /********************/
44 private function writeMsg($code='0') {
45 global $adminLanguage;
47 $this->code
= intval($code);
48 switch ($this->code
) {
49 case 1: $this->message
= $adminLanguage->A_SEOTLARGER
; break;
50 case 2: $this->message
= $adminLanguage->A_INVALID
; break;
51 case 3: $this->message
= $adminLanguage->A_INVALID
.', '.$adminLanguage->A_SEOTEXIST
; break;
52 case 4: $this->message
= $adminLanguage->A_VALID
; break;
53 case 5: $this->message
= $adminLanguage->A_INVALID
.', '.$adminLanguage->A_SEOTEMPTY
; break;
54 case 6: $this->message
= $adminLanguage->A_INVALID
.', '.$adminLanguage->A_PLSSELECTCAT
; break;
55 case 7: $this->message
= $adminLanguage->A_INVALID
.' '.$adminLanguage->A_SECTION
; break;
57 $this->message
= _GEM_UNKN_ERR
;
62 /********************************/
63 /* Implement suggest function */
64 /********************************/
65 public function suggest() {
66 global $mosConfig_absolute_path;
68 if ($this->title
== '') {
72 $ascii = strtolower(eUTF
::utf8_to_ascii($this->title
, ''));
73 $this->ascii
= preg_replace("/[^a-zA-Z0-9-_\s]/", '', $ascii);
74 if ($this->ascii
== '') {
79 $parts = split(' ', $this->ascii
);
81 foreach ($parts as $part) {
82 if (strlen($part) > 1) { array_push($nparts, $part); }
84 if (count($nparts) == 0) {
88 $newtitle = implode('-', $nparts);
90 $invalidNames = array('save', 'cancel');
91 if (in_array($newtitle, $invalidNames) ||
preg_match('/^(com_)/', $newtitle)) {
92 $newtitle = 'evcal-'.$newtitle;
93 } else if (file_exists($mosConfig_absolute_path.'/'.$newtitle.'/')) {
94 $newtitle = 'evcal-'.$newtitle;
97 return $this->suggest_events($newtitle);
100 /***************************************************/
101 /* New suggest_events function for EventCalendar */
102 /***************************************************/
103 protected function suggest_events($ntitle) { //feed manually id and catid before suggest
106 if (intval($this->catid
) < 1) {
107 $this->writeMsg('6');
111 $extra = ($this->id
) ?
" AND id <> '".$this->id
."'" : '';
112 $database->setQuery("SELECT COUNT(*) FROM #__eventcalendar WHERE catid='".$this->catid
."' AND seotitle='".$ntitle."'".$extra);
113 $c = intval($database->loadResult());
115 for ($i=2; $i<21; $i++
) {
116 $database->setQuery("SELECT COUNT(*) FROM #__eventcalendar WHERE catid='".$this->catid
."' AND seotitle='".$ntitle."-".$i."'".$extra);
117 $c2 = intval($database->loadResult());
123 if ($c2) { $ntitle .= '-'.rand(1000,9999); }
126 $this->sugtitle
= $ntitle;
130 /*********************************/
131 /* Implement validate function */
132 /*********************************/
133 public function validate() {
134 global $mosConfig_absolute_path;
136 $invalidNames = array('save', 'cancel');
137 if ( in_array($this->seotitle
, $invalidNames) ||
preg_match('/^(com_)/', $this->seotitle
) ||
file_exists($mosConfig_absolute_path.'/'.$this->seotitle
.'/') ) {
138 $this->writeMsg('2');
141 if ($this->seotitle
== '') {
142 $this->writeMsg('5');
145 if (!eUTF
::utf8_isASCII($this->seotitle
)) {
146 $this->writeMsg('2');
149 $seotitle2 = preg_replace("/[^a-z0-9-_]/", '', $this->seotitle
);
150 if ($seotitle2 != $this->seotitle
) {
151 $this->writeMsg('2');
155 return $this->validate_events();
158 /*********************************************/
159 /* New validate function for EventCalendar */
160 /*********************************************/
161 protected function validate_events() { //feed manually id, catid before validation
164 if (intval($this->catid
) < 1) {
165 $this->writeMsg('6');
169 $extra = ($this->id
) ?
" AND id <> '".$this->id
."'" : '';
170 $database->setQuery("SELECT COUNT(*) FROM #__eventcalendar WHERE catid='".$this->catid
."' AND seotitle='".$this->seotitle
."'".$extra);
171 $c = intval($database->loadResult());
173 $this->writeMsg('3');
176 $this->writeMsg('4');