Committer: Apostolos Koutsoulelos <apostolos@desktop.(none)>
[arthrology.git] / arthrology.seovs.class.php
blob96cac34eb0893fd7d8c7d82c2f7d0fe49d8979bf
1 <?php
3 /*
4 * Arthrology for Elxis CMS 2008.x and 2009.x
6 * SEO handler
8 * @version 1.3
9 * @package Arthrology
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 // Declare globals
22 global $mainframe;
24 // Include seovs class
25 require_once($mainframe->getCfg('absolute_path').'/administrator/includes/seovs.class.php');
27 /*********************************************************/
28 /* THE CLASS THAT WILL CONTAIN THE SEOVS FUNCTIONALITY */
29 /*********************************************************/
30 class seovsArthrology extends seovs {
32 public $option = '';
33 public $title = '';
34 public $seotitle = '';
35 public $ascii = '';
36 public $id = 0;
37 public $catid = 0;
38 public $Itemid = 0;
39 public $message = '';
40 public $code = 0;
41 public $section = '';
43 /********************************/
44 /* Implement suggest function */
45 /********************************/
46 public function suggest() {
47 global $mosConfig_absolute_path;
49 if ($this->title == '') {
50 $this->writeMsg('1');
51 return false;
53 $ascii = strtolower(eUTF::utf8_to_ascii($this->title, ''));
54 $this->ascii = preg_replace("/[^a-zA-Z0-9-_\s]/", '', $ascii);
55 if ($this->ascii == '') {
56 $this->writeMsg('1');
57 return false;
60 $parts = split(' ', $this->ascii);
61 $nparts = array();
62 foreach ($parts as $part) {
63 if (strlen($part) > 1) { array_push($nparts, $part); }
65 if (count($nparts) == 0) {
66 $this->writeMsg('1');
67 return false;
69 $newtitle = implode('-', $nparts);
71 $invalidNames = array('save', 'cancel');
72 if (in_array($newtitle, $invalidNames) || preg_match('/^(com_)/', $newtitle)) {
73 $newtitle = 'arthrology-'.$newtitle;
74 } else if (file_exists($mosConfig_absolute_path.'/'.$newtitle.'/')) {
75 $newtitle = 'arthrology-'.$newtitle;
78 return $this->suggest_articles($newtitle);
81 /***************************************************/
82 /* New suggest_events function for EventCalendar */
83 /***************************************************/
84 protected function suggest_articles($ntitle) { //feed manually id and catid before suggest
85 global $database;
87 if (intval($this->catid) < 1) {
88 $this->writeMsg('6');
89 return false;
92 $extra = ($this->id) ? " AND id <> '".$this->id."'" : '';
93 $database->setQuery("SELECT COUNT(*) FROM #__arthrology WHERE catid='".$this->catid."' AND seotitle='".$ntitle."'".$extra);
94 $c = intval($database->loadResult());
95 if ($c) {
96 for ($i=2; $i<21; $i++) {
97 $database->setQuery("SELECT COUNT(*) FROM #__arthrology WHERE catid='".$this->catid."' AND seotitle='".$ntitle."-".$i."'".$extra);
98 $c2 = intval($database->loadResult());
99 if (!$c2) {
100 $ntitle .= '-'.$i;
101 break;
104 if ($c2) { $ntitle .= '-'.rand(1000,9999); }
107 $this->sugtitle = $ntitle;
108 return $ntitle;
111 /*********************************/
112 /* Implement validate function */
113 /*********************************/
114 public function validate() {
115 global $mosConfig_absolute_path;
117 $invalidNames = array('save', 'cancel');
118 if ( in_array($this->seotitle, $invalidNames) || preg_match('/^(com_)/', $this->seotitle) || file_exists($mosConfig_absolute_path.'/'.$this->seotitle.'/') ) {
119 $this->writeMsg('2');
120 return false;
123 if ($this->seotitle == '') {
124 $this->writeMsg('5');
125 return false;
127 if (!eUTF::utf8_isASCII($this->seotitle)) {
128 $this->writeMsg('2');
129 return false;
131 $seotitle2 = preg_replace("/[^a-z0-9-_]/", '', $this->seotitle);
132 if ($seotitle2 != $this->seotitle) {
133 $this->writeMsg('2');
134 return false;
137 return $this->validate_articles();
140 /*********************************************/
141 /* New validate function for EventCalendar */
142 /*********************************************/
143 protected function validate_articles() { //feed manually id, catid before validation
144 global $database;
146 if (intval($this->catid) < 1) {
147 $this->writeMsg('6');
148 return false;
151 $extra = ($this->id) ? " AND id <> '".$this->id."'" : '';
152 $database->setQuery("SELECT COUNT(*) FROM #__arthrology WHERE catid='".$this->catid."' AND seotitle='".$this->seotitle."'".$extra);
153 $c = intval($database->loadResult());
154 if ($c) {
155 $this->writeMsg('3');
156 return false;
158 $this->writeMsg('4');
159 return true;