On branch master
[arthrology.git] / arthrology.seovs.class.php
blob67c350cf874f33d79fa9fa83034d06560822fd50
1 <?php
3 /*
4 * Arthrology for Elxis CMS 2008.x and 2009.x
6 * SEO handler
8 * @version 1.1
9 * @package Arthrology
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
13 * @link
16 // Prevent direct inclusion of this file
17 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
19 // Declare globals
20 global $mainframe;
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 {
30 public $option = '';
31 public $title = '';
32 public $seotitle = '';
33 public $ascii = '';
34 public $id = 0;
35 public $catid = 0;
36 public $Itemid = 0;
37 public $message = '';
38 public $code = 0;
39 public $section = '';
41 /********************************/
42 /* Implement suggest function */
43 /********************************/
44 public function suggest() {
45 global $mosConfig_absolute_path;
47 if ($this->title == '') {
48 $this->writeMsg('1');
49 return false;
51 $ascii = strtolower(eUTF::utf8_to_ascii($this->title, ''));
52 $this->ascii = preg_replace("/[^a-zA-Z0-9-_\s]/", '', $ascii);
53 if ($this->ascii == '') {
54 $this->writeMsg('1');
55 return false;
58 $parts = split(' ', $this->ascii);
59 $nparts = array();
60 foreach ($parts as $part) {
61 if (strlen($part) > 1) { array_push($nparts, $part); }
63 if (count($nparts) == 0) {
64 $this->writeMsg('1');
65 return false;
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
83 global $database;
85 if (intval($this->catid) < 1) {
86 $this->writeMsg('6');
87 return false;
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());
93 if ($c) {
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());
97 if (!$c2) {
98 $ntitle .= '-'.$i;
99 break;
102 if ($c2) { $ntitle .= '-'.rand(1000,9999); }
105 $this->sugtitle = $ntitle;
106 return $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');
118 return false;
121 if ($this->seotitle == '') {
122 $this->writeMsg('5');
123 return false;
125 if (!eUTF::utf8_isASCII($this->seotitle)) {
126 $this->writeMsg('2');
127 return false;
129 $seotitle2 = preg_replace("/[^a-z0-9-_]/", '', $this->seotitle);
130 if ($seotitle2 != $this->seotitle) {
131 $this->writeMsg('2');
132 return false;
135 return $this->validate_articles();
138 /*********************************************/
139 /* New validate function for EventCalendar */
140 /*********************************************/
141 protected function validate_articles() { //feed manually id, catid before validation
142 global $database;
144 if (intval($this->catid) < 1) {
145 $this->writeMsg('6');
146 return false;
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());
152 if ($c) {
153 $this->writeMsg('3');
154 return false;
156 $this->writeMsg('4');
157 return true;