103 |
- |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/***************************************************************************
|
|
|
4 |
* Copyright (C) 2009-2011 by Geo Varghese(www.seopanel.in) *
|
|
|
5 |
* sendtogeo@gmail.com *
|
|
|
6 |
* *
|
|
|
7 |
* This program is free software; you can redistribute it and/or modify *
|
|
|
8 |
* it under the terms of the GNU General Public License as published by *
|
|
|
9 |
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
10 |
* (at your option) any later version. *
|
|
|
11 |
* *
|
|
|
12 |
* This program is distributed in the hope that it will be useful, *
|
|
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
15 |
* GNU General Public License for more details. *
|
|
|
16 |
* *
|
|
|
17 |
* You should have received a copy of the GNU General Public License *
|
|
|
18 |
* along with this program; if not, write to the *
|
|
|
19 |
* Free Software Foundation, Inc., *
|
|
|
20 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
21 |
***************************************************************************/
|
|
|
22 |
|
|
|
23 |
# class defines all controller functions
|
|
|
24 |
class Controller extends Seopanel{
|
|
|
25 |
var $view;
|
|
|
26 |
var $session;
|
|
|
27 |
var $validate;
|
|
|
28 |
var $dbHelper;
|
|
|
29 |
var $db;
|
|
|
30 |
var $spider;
|
|
|
31 |
var $paging;
|
|
|
32 |
var $layout = 'default';
|
|
|
33 |
var $sessionCats = array('common','login','button','label');
|
|
|
34 |
|
|
|
35 |
function __construct(){
|
|
|
36 |
|
|
|
37 |
# create database object
|
|
|
38 |
$dbObj = New Database(DB_ENGINE);
|
|
|
39 |
$this->dbHelper = $dbObj;
|
|
|
40 |
$this->db = $dbObj->dbConnect();
|
|
|
41 |
$this->view = New View();
|
|
|
42 |
$this->session = New Session();
|
|
|
43 |
$this->validate = New Validation();
|
|
|
44 |
$this->spider = New Spider();
|
|
|
45 |
$this->paging = New Paging();
|
|
|
46 |
|
|
|
47 |
# to define all system variables
|
|
|
48 |
$force = false;
|
|
|
49 |
if (!empty($_GET['lang_code'])) {
|
|
|
50 |
$_GET['lang_code'] = addslashes($_GET['lang_code']);
|
|
|
51 |
$this->assignLangCode(trim($_GET['lang_code']));
|
|
|
52 |
$_GET['lang_code'] = '';
|
|
|
53 |
$force = true;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
# func to assign texts to session
|
|
|
57 |
$_SESSION['lang_code'] = empty($_SESSION['lang_code']) ? SP_DEFAULTLANG : $_SESSION['lang_code'];
|
|
|
58 |
$this->assignTextsToSession($_SESSION['lang_code'], $force);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
# func to assign lang code
|
|
|
62 |
function assignLangCode($langCode) {
|
|
|
63 |
|
|
|
64 |
$sql = "select count(*) count from languages where lang_code='$langCode' and translated=1";
|
|
|
65 |
$info = $this->db->select($sql, true);
|
|
|
66 |
$langCode = empty($info['count']) ? 'en' : $langCode;
|
|
|
67 |
|
|
|
68 |
$_SESSION['lang_code'] = $langCode;
|
|
|
69 |
if ($userId = isLoggedIn()) {
|
|
|
70 |
$sql = "update users set lang_code='$langCode' where id=$userId";
|
|
|
71 |
$res = $this->db->query($sql);
|
|
|
72 |
@Session::setSession('text', '');
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
# func to get all system settings
|
|
|
77 |
function __getAllSettings($showCheck=false, $showVal=1, $category='system') {
|
|
|
78 |
$condition = $showCheck ? " where `display`=$showVal and set_category='$category'" : "";
|
|
|
79 |
$sql = "select * from settings $condition order by id";
|
|
|
80 |
$settingsList = $this->db->select($sql);
|
|
|
81 |
return $settingsList;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
# to define all system settings
|
|
|
86 |
function defineAllSystemSettings() {
|
|
|
87 |
|
|
|
88 |
$settingsList = $this->__getAllSettings();
|
|
|
89 |
foreach($settingsList as $settingsInfo){
|
|
|
90 |
if(!defined($settingsInfo['set_name'])){
|
|
|
91 |
define($settingsInfo['set_name'], $settingsInfo['set_val']);
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
# func to restore data
|
|
|
97 |
function restoreData() {
|
|
|
98 |
$dbFile = SP_DATAPATH."/seopanel.sql";
|
|
|
99 |
$this->db->importDatabaseFile($dbFile);
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
# func set variable to ctp
|
|
|
103 |
function set($varName, $varValue){
|
|
|
104 |
$this->data[$varName] = $varValue;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
# normal render function
|
|
|
108 |
function render($viewFile='home', $layout='default'){
|
|
|
109 |
if(empty($layout) || ($layout == 'default')){
|
|
|
110 |
if(!empty($this->layout)){
|
|
|
111 |
$layout = $this->layout;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
if ($layout == 'default') {
|
|
|
115 |
$this->set('translatorInfo', $this->getTranslatorInfo());
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
}
|
|
|
119 |
$this->view->data = $this->data;
|
|
|
120 |
$this->view->render($viewFile, $layout);
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
# function to get translator info
|
|
|
124 |
function getTranslatorInfo() {
|
|
|
125 |
$translatorInfo = '';
|
|
|
126 |
if ($_SESSION['lang_code'] != 'en') {
|
|
|
127 |
$sql = "select t.*,lang_show from translators t,languages l where l.lang_code=t.lang_code and t.lang_code='{$_SESSION['lang_code']}'";
|
|
|
128 |
$list = $this->db->select($sql);
|
|
|
129 |
if (count($list) > 0) {
|
|
|
130 |
$trname = $list[0]['lang_show']." ". $_SESSION['text']['label']['translation by']. " ";
|
|
|
131 |
$trlink = "";
|
|
|
132 |
foreach ($list as $i => $info) {
|
|
|
133 |
$trname .= $i ? " and ".$info['trans_name'] : $info['trans_name'];
|
|
|
134 |
$trlink .= " | <a href='{$info['trans_website']}' target='_blank' style='font-size:12px;'>{$info['trans_company']}</a>";
|
|
|
135 |
}
|
|
|
136 |
$translatorInfo .= " | $trname $trlink";
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
return $translatorInfo;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
# plugin render function
|
|
|
143 |
function pluginRender($viewFile='home', $layout='default'){
|
|
|
144 |
if(empty($layout) || ($layout == 'default')){
|
|
|
145 |
if(!empty($this->layout)){
|
|
|
146 |
$layout = $this->layout;
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
$this->view->data = $this->data;
|
|
|
150 |
$this->view->pluginRender($viewFile, $layout);
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
# normal plugingetViewContent function
|
|
|
154 |
function getPluginViewContent($viewFile){
|
|
|
155 |
$this->view->data = $this->data;
|
|
|
156 |
return $this->view->getPluginViewContent($viewFile);
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
# func to getting language texts
|
|
|
160 |
function getLanguageTexts($category, $langCode='en') {
|
|
|
161 |
$langTexts = array();
|
|
|
162 |
|
|
|
163 |
$sql = "select label,content from texts where category='$category' and lang_code='$langCode' and content!='' order by label";
|
|
|
164 |
$textList = $this->db->select($sql);
|
|
|
165 |
foreach ($textList as $listInfo) {
|
|
|
166 |
$langTexts[$listInfo['label']] = stripslashes($listInfo['content']);
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
# if langauge is not english
|
|
|
170 |
if ($langCode != 'en') {
|
|
|
171 |
$defaultTexts = $this->getLanguageTexts($category, 'en');
|
|
|
172 |
foreach ($defaultTexts as $label => $content) {
|
|
|
173 |
if (empty($langTexts[$label])) {
|
|
|
174 |
$langTexts[$label] = $content;
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
return $langTexts;
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
# func to assign language to session
|
|
|
183 |
function assignTextsToSession($langCode='en', $force=false) {
|
|
|
184 |
if (SP_LANGTESTING || empty($_SESSION['text']) || $force ) {
|
|
|
185 |
$_SESSION['text'] = array();
|
|
|
186 |
foreach ($this->sessionCats as $category) {
|
|
|
187 |
$_SESSION['text'][$category] = $this->getLanguageTexts($category, $langCode);
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
# function to check whether user is keyword owner or not
|
|
|
193 |
function checkUserIsObjectOwner($objId, $objName='website') {
|
|
|
194 |
|
|
|
195 |
if (!isAdmin()) {
|
|
|
196 |
$userId = isLoggedIn();
|
|
|
197 |
switch ($objName) {
|
|
|
198 |
|
|
|
199 |
case "keyword":
|
|
|
200 |
$sql = "select k.id from keywords k,websites w where k.website_id=w.id and w.user_id='".intval($userId)."' and k.id='".intval($objId)."'";
|
|
|
201 |
break;
|
|
|
202 |
|
|
|
203 |
case "website":
|
|
|
204 |
$sql = "select id from websites where id='".intval($objId)."' and user_id='".intval($userId)."'";
|
|
|
205 |
break;
|
|
|
206 |
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
$info = $this->db->select($sql, true);
|
|
|
210 |
if (empty($info['id'])) {
|
|
|
211 |
showErrorMsg("You are not allowed to access this page!");
|
|
|
212 |
}
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
# to create component object
|
|
|
218 |
function createComponent($compName) {
|
|
|
219 |
include_once(SP_CTRLPATH."/components/".strtolower($compName).".php");
|
|
|
220 |
$componentObj = new $compName();
|
|
|
221 |
return $componentObj;
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
# to create cotroller object
|
|
|
225 |
function createController($ctrlName) {
|
|
|
226 |
include_once(SP_CTRLPATH."/".strtolower($ctrlName).".ctrl.php");
|
|
|
227 |
$ctrlName .= "Controller";
|
|
|
228 |
$controllerObj = new $ctrlName();
|
|
|
229 |
return $controllerObj;
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
# function to create mysql connect again
|
|
|
233 |
function checkDBConn($force=false) {
|
|
|
234 |
if($force || !is_object($this->db)){
|
|
|
235 |
$dbObj = New Database(DB_ENGINE);
|
|
|
236 |
$this->db = $dbObj->dbConnect();
|
|
|
237 |
}
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
# normal getViewContent function
|
|
|
241 |
function getViewContent($viewFile){
|
|
|
242 |
$this->view->data = $this->data;
|
|
|
243 |
return $this->view->getViewContent($viewFile);
|
|
|
244 |
}
|
|
|
245 |
}
|
|
|
246 |
?>
|