1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace mod_seo\classes; |
4
|
|
|
|
5
|
|
|
use MY_Controller; |
6
|
|
|
use Seoexpert_model; |
7
|
|
|
use Seoexpert_model_products; |
8
|
|
|
|
9
|
|
|
if (!defined('BASEPATH')) { |
10
|
|
|
exit('No direct script access allowed'); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Helper for mod_seo module |
15
|
|
|
* @property Seoexpert_model_products seoexpert_model_products |
16
|
|
|
* @property Seoexpert_model seoexpert_model |
17
|
|
|
* @uses \MY_Controller |
18
|
|
|
* @author DevImageCms |
19
|
|
|
* @copyright (c) 2014, ImageCMS |
20
|
|
|
* @package ImageCMSModule |
21
|
|
|
*/ |
22
|
|
|
class SeoHelper extends MY_Controller |
23
|
|
|
{ |
|
|
|
|
24
|
|
|
|
25
|
|
|
protected static $_instance; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* __construct base object loaded |
29
|
|
|
* @access public |
30
|
|
|
* @author DevImageCms |
31
|
|
|
* @copyright (c) 2013, ImageCMS |
32
|
|
|
*/ |
33
|
|
|
public function __construct() { |
34
|
|
|
parent::__construct(); |
35
|
|
|
/** Load model * */ |
36
|
|
|
$this->load->model('seoexpert_model'); |
37
|
|
|
$lang = new \MY_Lang(); |
38
|
|
|
$lang->load('mod_seo'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return SeoHelper |
43
|
|
|
*/ |
44
|
|
|
public static function create() { |
45
|
|
|
(null !== self::$_instance) OR self::$_instance = new self(); |
46
|
|
|
return self::$_instance; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Prepare parent category name (in future all categories in full path) |
51
|
|
|
* @param bool|int $categoryId |
52
|
|
|
* @param bool|string $locale |
53
|
|
|
* @return array|bool - parentCategory |
54
|
|
|
*/ |
55
|
|
|
public function prepareCategoriesForProductCategory($categoryId = false, $locale = false) { |
56
|
|
|
$res = $this->seoexpert_model_products->getCategoryByIdAndLocale($categoryId, $locale); |
57
|
|
|
|
58
|
|
|
if ($res) { |
59
|
|
|
$res['parentCategory'] = $res['name']; |
60
|
|
|
unset($res['name']); |
61
|
|
|
return $res; |
62
|
|
|
} |
63
|
|
|
return FALSE; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Autocomplete categories |
68
|
|
|
* @return jsone |
|
|
|
|
69
|
|
|
*/ |
70
|
|
|
public function autoCompleteCategories() { |
71
|
|
|
$sCoef = $this->input->get('term'); |
72
|
|
|
$sLimit = $this->input->get('limit'); |
73
|
|
|
|
74
|
|
|
$categories = $this->seoexpert_model->getCategoriesByIdName($sCoef, $sLimit); |
75
|
|
|
|
76
|
|
|
if ($categories != false) { |
77
|
|
|
foreach ($categories as $category) { |
|
|
|
|
78
|
|
|
$response[] = [ |
|
|
|
|
79
|
|
|
'value' => html_entity_decode($category['name']), |
80
|
|
|
'id' => $category['id'], |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
echo json_encode($response); |
84
|
|
|
return; |
|
|
|
|
85
|
|
|
} |
86
|
|
|
echo ''; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get base settings |
91
|
|
|
* @param bool|string $locale |
92
|
|
|
* @return array|bool |
|
|
|
|
93
|
|
|
*/ |
94
|
|
View Code Duplication |
public function getBaseSettings($locale = FALSE) { |
95
|
|
|
if (!$locale) { |
96
|
|
|
$locale = MY_Controller::getCurrentLocale(); |
97
|
|
|
} |
98
|
|
|
$langId = $this->seoexpert_model->getLangIdByLocale($locale); |
99
|
|
|
$res = $this->seoexpert_model->getBaseSettings($langId); |
100
|
|
|
|
101
|
|
|
if ($res) { |
102
|
|
|
return $res; |
103
|
|
|
} |
104
|
|
|
return FALSE; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* |
109
|
|
|
* @param bool|string $locale |
110
|
|
|
* @param bool|array $settings |
111
|
|
|
* @return bool |
112
|
|
|
*/ |
113
|
|
View Code Duplication |
public function setBaseSettings($locale = FALSE, $settings = FALSE) { |
114
|
|
|
if (!$locale) { |
115
|
|
|
$locale = MY_Controller::getCurrentLocale(); |
116
|
|
|
} |
117
|
|
|
$langId = $this->seoexpert_model->getLangIdByLocale($locale); |
118
|
|
|
|
119
|
|
|
$res = $this->seoexpert_model->setBaseSettings($langId, $settings); |
120
|
|
|
|
121
|
|
|
if ($res) { |
122
|
|
|
return $res; |
123
|
|
|
} |
124
|
|
|
return FALSE; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
} |