4 * Arthrology for Elxis CMS 2008.x and 2009.x
10 * @author Apostolos Koutsoulelos <akoutsoulelos@yahoo.gr>
11 * @copyright Copyright (C) 2009 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 seovsArthrology
extends seovs
{
32 public $seotitle = '';
41 /********************************/
42 /* Implement suggest function */
43 /********************************/
44 public function suggest() {
45 global $mosConfig_absolute_path;
47 if ($this->title
== '') {
51 $ascii = strtolower(eUTF
::utf8_to_ascii($this->title
, ''));
52 $this->ascii
= preg_replace("/[^a-zA-Z0-9-_\s]/", '', $ascii);
53 if ($this->ascii
== '') {
58 $parts = split(' ', $this->ascii
);
60 foreach ($parts as $part) {
61 if (strlen($part) > 1) { array_push($nparts, $part); }
63 if (count($nparts) == 0) {
67 $newtitle = implode('-', $nparts);
69 $invalidNames = array('save', 'cancel');
70 if (in_array($newtitle, $invalidNames) ||
preg_match('/^(com_)/', $newtitle)) {
71 $newtitle = 'arthrology-'.$newtitle;
72 } else if (file_exists($mosConfig_absolute_path.'/'.$newtitle.'/')) {
73 $newtitle = 'arthrology-'.$newtitle;
76 return $this->suggest_articles($newtitle);
79 /***************************************************/
80 /* New suggest_events function for EventCalendar */
81 /***************************************************/
82 protected function suggest_articles($ntitle) { //feed manually id and catid before suggest
85 if (intval($this->catid
) < 1) {
90 $extra = ($this->id
) ?
" AND id <> '".$this->id
."'" : '';
91 $database->setQuery("SELECT COUNT(*) FROM #__arthrology WHERE catid='".$this->catid
."' AND seotitle='".$ntitle."'".$extra);
92 $c = intval($database->loadResult());
94 for ($i=2; $i<21; $i++
) {
95 $database->setQuery("SELECT COUNT(*) FROM #__arthrology WHERE catid='".$this->catid
."' AND seotitle='".$ntitle."-".$i."'".$extra);
96 $c2 = intval($database->loadResult());
102 if ($c2) { $ntitle .= '-'.rand(1000,9999); }
105 $this->sugtitle
= $ntitle;
109 /*********************************/
110 /* Implement validate function */
111 /*********************************/
112 public function validate() {
113 global $mosConfig_absolute_path;
115 $invalidNames = array('save', 'cancel');
116 if ( in_array($this->seotitle
, $invalidNames) ||
preg_match('/^(com_)/', $this->seotitle
) ||
file_exists($mosConfig_absolute_path.'/'.$this->seotitle
.'/') ) {
117 $this->writeMsg('2');
121 if ($this->seotitle
== '') {
122 $this->writeMsg('5');
125 if (!eUTF
::utf8_isASCII($this->seotitle
)) {
126 $this->writeMsg('2');
129 $seotitle2 = preg_replace("/[^a-z0-9-_]/", '', $this->seotitle
);
130 if ($seotitle2 != $this->seotitle
) {
131 $this->writeMsg('2');
135 return $this->validate_articles();
138 /*********************************************/
139 /* New validate function for EventCalendar */
140 /*********************************************/
141 protected function validate_articles() { //feed manually id, catid before validation
144 if (intval($this->catid
) < 1) {
145 $this->writeMsg('6');
149 $extra = ($this->id
) ?
" AND id <> '".$this->id
."'" : '';
150 $database->setQuery("SELECT COUNT(*) FROM #__arthrology WHERE catid='".$this->catid
."' AND seotitle='".$this->seotitle
."'".$extra);
151 $c = intval($database->loadResult());
153 $this->writeMsg('3');
156 $this->writeMsg('4');