Skip to content

Commit 562dba0

Browse files
committed
created pdo.class.php and used in some lib files
1 parent 9d2c793 commit 562dba0

File tree

8 files changed

+202
-67
lines changed

8 files changed

+202
-67
lines changed

cms/actionbar.lib.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@
2424
* @return $actionbar The list of permitted actions for the 'user' of 'page'.
2525
*/
2626
function getActionbarPage($userId, $pageId) {
27-
27+
global $pdb;
2828
$action_query = "SELECT perm_id, perm_action, perm_text FROM `".MYSQL_DATABASE_PREFIX."permissionlist` WHERE page_module = 'page'";
29-
$action_result = mysql_query($action_query);
29+
$action_result = $pdb->query($action_query);
3030
$allow_login_query = "SELECT `value` FROM `".MYSQL_DATABASE_PREFIX."global` WHERE `attribute` = 'allow_login'";
31-
$allow_login_result = mysql_query($allow_login_query);
32-
$allow_login_result = mysql_fetch_array($allow_login_result);
31+
$allow_login_result = $pdb->query($allow_login_query);
32+
$allow_login_result = $allow_login_result[0];
3333
$actionbarPage=array();
34-
while($action_row = mysql_fetch_assoc($action_result)) {
34+
foreach($action_result as $action_row) {
3535
if(getPermissions($userId, $pageId, $action_row['perm_action']))
3636
$actionbarPage[$action_row['perm_action']]=$action_row['perm_text'];
3737
}
3838
if($userId==0) {
39-
if($allow_login_result[0]) {
39+
if($allow_login_result['value']) {
4040
$actionbarPage["login"]="Login";
4141
$actionbarPage["login&subaction=register"]="Register";
4242
}
@@ -75,19 +75,20 @@ function getActionbarPage($userId, $pageId) {
7575
* @return $actionbar The list of permitted module specific actions for the 'user' of 'page'.
7676
*/
7777
function getActionbarModule($userId, $pageId) {
78+
global $pdb;
7879
$action_query = "SELECT perm_id, perm_action, perm_text FROM `".MYSQL_DATABASE_PREFIX."permissionlist` WHERE perm_action != 'create' AND page_module = '".getEffectivePageModule($pageId)."'";
79-
$action_result = mysql_query($action_query);
80+
$action_result = $pdb->query($action_query);
8081
$allow_login_query = "SELECT `value` FROM `".MYSQL_DATABASE_PREFIX."global` WHERE `attribute` = 'allow_login'";
81-
$allow_login_result = mysql_query($allow_login_query);
82-
$allow_login_result = mysql_fetch_array($allow_login_result);
82+
$allow_login_result = $pdb->query($allow_login_query);
83+
$allow_login_result = $allow_login_result[0];
8384
$actionbarPage = array();
84-
while($action_row = mysql_fetch_assoc($action_result))
85+
foreach($action_result as $action_row)
8586
if(getPermissions($userId, $pageId, $action_row['perm_action']))
8687
$actionbarPage[$action_row['perm_action']]=$action_row['perm_text'];
8788
$actionbar="<div id=\"cms-actionbarModule\">";
8889
if(is_array($actionbarPage)>0)
8990
foreach($actionbarPage as $action=>$actionname) {
90-
if((!$allow_login_result[0])&&($actionname=="View")&&!($userId))
91+
if((!$allow_login_result['value'])&&($actionname=="View")&&!($userId))
9192
continue;
9293
$actionbar.="<span class=\"cms-actionbarModuleItem\"><a class=\"robots-nofollow\" rel=\"nofollow\" href=\"./+$action\">$actionname</a></span>\n";
9394
}

cms/authenticate.lib.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
*
2525
*/
2626
function getSessionData($user_id) {
27+
global $pdb;
2728
$user_id=escape($user_id);
2829
$query = "SELECT `user_name`,`user_email`,`user_lastlogin` FROM `" . MYSQL_DATABASE_PREFIX . "users` WHERE `user_id`='$user_id'";
29-
$data = mysql_query($query) or die(mysql_error());
30-
$temp = mysql_fetch_assoc($data);
30+
$data = $pdb->query($query);
31+
$temp = $data[0];
3132
$user_name = $temp['user_name'];
3233
$user_email = $temp['user_email'];
3334
$lastlogin = $temp['user_lastlogin'];
@@ -129,6 +130,7 @@ function firstTimeGetUserId() {
129130
*
130131
*/
131132
function getGroupIds($userId) {
133+
global $pdb;
132134
$groups = array (
133135
0
134136
);
@@ -137,9 +139,9 @@ function getGroupIds($userId) {
137139
else
138140
$groups[] = 1;
139141
$groupQuery = 'SELECT `group_id` FROM `' . MYSQL_DATABASE_PREFIX . 'usergroup` WHERE `user_id` = \'' . escape($userId)."'";
140-
$groupQueryResult = mysql_query($groupQuery) or die(mysql_error());
141-
while ($groupQueryResultRow = mysql_fetch_row($groupQueryResult))
142-
$groups[] = $groupQueryResultRow[0];
142+
$groupQueryResult = $pdb->query($groupQuery);
143+
foreach($groupQueryResult as $groupQueryResultRow)
144+
$groups[] = $groupQueryResultRow['group_id'];
143145
return $groups;
144146
}
145147

cms/breadcrumbs.lib.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
* @return HTML string representing the breadcrumbs to be displayed for the given page
2626
*/
2727
function breadcrumbs($pageIdArray) {
28+
global $pdb;
2829
$sqlOutputArray = array();
2930
$pageIdList = join($pageIdArray, ",");
3031
$query = 'SELECT `page_id`, `page_name`, `page_title` FROM `' . MYSQL_DATABASE_PREFIX . 'pages` WHERE `page_id` IN (' . $pageIdList . ')';
31-
$resultId = mysql_query($query);
3232

33-
while ($row = mysql_fetch_assoc($resultId))
33+
$rows=$pdb->query($query);
34+
foreach ($rows as $row)
3435
$sqlOutputArray[$row['page_id']] = array($row['page_name'], $row['page_title']);
3536

3637
global $urlRequestRoot;

cms/download.lib.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
function download($pageId, $userId, $fileName,$action="") {
28-
28+
global $pdb;
2929
/// If page not found display error
3030
if($pageId===false) {
3131
header("http/1.0 404 Not Found" );
@@ -75,8 +75,8 @@ function download($pageId, $userId, $fileName,$action="") {
7575
//return the file the particular page id.
7676

7777
$query = "SELECT * FROM `" . MYSQL_DATABASE_PREFIX . "uploads` WHERE `upload_filename`= '". escape($fileName). "' AND `page_module` = '".escape($moduleType)."' AND `page_modulecomponentid` = '".escape($moduleComponentId)."'";
78-
$result = mysql_query($query) or die(mysql_error() . "upload L:85");
79-
$row = mysql_fetch_assoc($result);
78+
$rows = $pdb->query($query);
79+
$row = $rows[0];
8080

8181
$fileType = $row['upload_filetype'];
8282
/**

cms/iconmanagement.lib.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @return HTML of the FORM
2323
*/
2424
function handleIconManagement() {
25-
25+
global $pdb;
2626
/*
2727
* Upload a new icon
2828
*/
@@ -63,7 +63,7 @@ function handleIconManagement() {
6363
* Save the Icon in Database - The following entries are saved
6464
* icon URL - path relative to the website installation folder on the server
6565
*/
66-
mysql_query("UPDATE `".MYSQL_DATABASE_PREFIX."pages` SET `page_image`='$iconURL' WHERE `page_id`='$target'");
66+
$pdb->query("UPDATE `".MYSQL_DATABASE_PREFIX."pages` SET `page_image`='$iconURL' WHERE `page_id`='$target'");
6767
$pageDetails = getPageInfo($target);
6868
if($pageDetails['page_image'] != NULL)
6969
echo "<img src=\"$rootUri/$cmsFolder/$templateFolder/common/icons/16x16/status/weather-clear.png\" /> ";

cms/modules/article.lib.php

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ public static function getUploadableFileProperties(&$fileTypesArray,&$maxFileSiz
4242
}
4343

4444
function isCommentsEnabled() {
45-
$result = mysql_fetch_array(mysql_query("SELECT `allowComments` FROM `article_content` WHERE `page_modulecomponentid` = '{$this->moduleComponentId}'"));
46-
return $result['allowComments'];
45+
global $pdb;
46+
$result = $pdb->query("SELECT `allowComments` FROM `article_content` WHERE `page_modulecomponentid` = '{$this->moduleComponentId}'");
47+
return $result[0]['allowComments'];
4748
}
4849

4950
function setCommentEnable($val) {
50-
mysql_query("UPDATE `article_content` SET `allowComments` ='$val' WHERE `page_modulecomponentid` = '{$this->moduleComponentId}'");
51+
global $pdb;
52+
$result = $pdb->query("UPDATE `article_content` SET `allowComments` ='$val' WHERE `page_modulecomponentid` = '{$this->moduleComponentId}'");
5153
}
5254

5355
function renderComment($id,$user,$timestamp,$comment,$delete=0) {
@@ -93,40 +95,41 @@ function commentBox() {
9395

9496
public function actionView($text="") {
9597

98+
global $pdb;
9699
if (isset($_GET['draft']) && isset ($_POST['CKEditor1'])){
97100

98101
//$query = "UPDATE `article_draft` SET `draft_content` = '" . $_POST["CKEditor1"] . "' WHERE `page_modulecomponentid` =".$this->moduleComponentId;
99102
$query="SELECT MAX(draft_number) AS MAX FROM `article_draft` WHERE page_modulecomponentid ='$this->moduleComponentId'";
100-
$result = mysql_query($query);
101-
if(!$result) { displayerror(mysql_error() . "article.lib L:44"); return; }
102-
if(mysql_num_rows($result))
103+
$result = $pdb->query($query);
104+
//if(!$result) { displayerror(mysql_error() . "article.lib L:44"); return; }
105+
if(count($result))
103106
{
104-
$drow = mysql_fetch_assoc($result);
107+
$drow = $result[0];
105108
$draftId = $drow['MAX'] + 1;
106109
}
107110
else $draftId=1;
108111

109112
$query = "INSERT INTO `article_draft` (`page_modulecomponentid`,`draft_number`,`draft_content`,`draft_lastsaved`,`user_id`) VALUES ('".$this->moduleComponentId."','".$draftId."','".$_POST['CKEditor1']."',now(),'".$this->userId."')";
110-
$result = mysql_query($query) or die(mysql_error());
111-
if(mysql_affected_rows() < 1)
113+
$result = $pdb->query($query);
114+
if($result < 1)
112115
displayerror("Unable to draft the article");
113116

114117
}
115118
if($this->isCommentsEnabled() && isset($_POST['btnSubmit'])) {
116-
$id = mysql_fetch_array(mysql_query("SELECT MAX(`comment_id`) AS MAX FROM `article_comments`"));
117-
$id = $id['MAX'] + 1;
119+
$id = $pdb->query("SELECT MAX(`comment_id`) AS MAX FROM `article_comments`");
120+
$id = $id[0]['MAX'] + 1;
118121
$user = getUserName($this->userId);
119122
$comment = escape(safe_html($_POST['comment']));
120-
mysql_query("INSERT INTO `article_comments`(`comment_id`,`page_modulecomponentid`,`user`,`comment`) VALUES('$id','{$this->moduleComponentId}','$user','$comment')");
121-
if(mysql_affected_rows())
123+
$result = $pdb->query("INSERT INTO `article_comments`(`comment_id`,`page_modulecomponentid`,`user`,`comment`) VALUES('$id','{$this->moduleComponentId}','$user','$comment')");
124+
if($result)
122125
displayinfo("Post successful");
123126
else
124127
displayerror("Error in posting comment");
125128
}
126129
if($text==""){
127130
$query = "SELECT article_content,article_lastupdated FROM article_content WHERE page_modulecomponentid='" . $this->moduleComponentId."'";
128-
$result = mysql_query($query);
129-
if($row = mysql_fetch_assoc($result)) {
131+
$result = $pdb->query($query);
132+
if($row = $result[0]) {
130133
$text = $row['article_content'];
131134
$text = censor_words($text);
132135
global $PAGELASTUPDATED;
@@ -148,12 +151,12 @@ public function actionView($text="") {
148151

149152

150153
if($this->isCommentsEnabled()) {
151-
$comments = mysql_query("SELECT `comment_id`,`user`,`timestamp`,`comment` FROM `article_comments` WHERE `page_modulecomponentid` = '{$this->moduleComponentId}' ORDER BY `timestamp`");
152-
if(mysql_num_rows($comments)>0)
154+
$comments = $pdb->query("SELECT `comment_id`,`user`,`timestamp`,`comment` FROM `article_comments` WHERE `page_modulecomponentid` = '{$this->moduleComponentId}' ORDER BY `timestamp`");
155+
if(count($comments)>0)
153156
$ret .= "<fieldset><legend>Comments</legend>";
154-
while($row = mysql_fetch_array($comments))
157+
foreach($comments as $row)
155158
$ret .= $this->renderComment($row['comment_id'],$row['user'],$row['timestamp'],censor_words($row['comment']));
156-
if(mysql_num_rows($comments)>0)
159+
if(count($comments)>0)
157160
$ret .= "</fieldset>";
158161
$ret .= $this->commentBox();
159162
}
@@ -162,15 +165,15 @@ public function actionView($text="") {
162165

163166

164167
public function actionEdit() {
165-
global $sourceFolder,$ICONS;
168+
global $sourceFolder,$ICONS,$pdb;
166169
//require_once("$sourceFolder/diff.lib.php");
167170
require_once($sourceFolder."/upload.lib.php");
168171

169172
if (isset($_GET['deldraft']))
170173
{
171174
$dno = escape($_GET['dno']);
172175
$query = "DELETE FROM `article_draft` WHERE `page_modulecomponentid`='". $this->moduleComponentId."' AND `draft_number`=".$dno;
173-
$result = mysql_query($query) or die(mysql_error());
176+
$result = $pdb->query($query);
174177
}
175178

176179
global $ICONS;
@@ -192,8 +195,8 @@ public function actionEdit() {
192195

193196
submitFileUploadForm($this->moduleComponentId,"article",$this->userId,UPLOAD_SIZE_LIMIT);
194197
if(isset($_GET['delComment']) && $this->userId == 1) {
195-
mysql_query("DELETE FROM `article_comments` WHERE `comment_id` = '".escape($_GET['delComment'])."'");
196-
if(mysql_affected_rows())
198+
$result = $pdb->query("DELETE FROM `article_comments` WHERE `comment_id` = '".escape($_GET['delComment'])."'");
199+
if($result)
197200
displayinfo("Comment deleted!");
198201
else
199202
displayerror("Error in deleting comment");
@@ -217,30 +220,30 @@ public function actionEdit() {
217220

218221
/*Save the diff :-*/
219222
$query = "SELECT article_content FROM article_content WHERE page_modulecomponentid='" . $this->moduleComponentId."'";
220-
$result = mysql_query($query);
221-
$row = mysql_fetch_assoc($result);
222-
$diff = mysql_escape_string($this->diff($_POST['CKEditor1'],$row['article_content']));
223+
$result = $pdb->query($query);
224+
$row = $result[0];
225+
$diff = $this->diff($_POST['CKEditor1'],$row['article_content']);
223226
$query="SELECT MAX(article_revision) AS MAX FROM `article_contentbak` WHERE page_modulecomponentid ='" . $this->moduleComponentId."'";
224-
$result = mysql_query($query);
225-
if(!$result) { displayerror(mysql_error() . "article.lib L:44"); return; }
226-
if(mysql_num_rows($result))
227+
$result = $pdb->query($query);
228+
//if(!$result) { displayerror(mysql_error() . "article.lib L:44"); return; }
229+
if(count($result))
227230
{
228-
$row = mysql_fetch_assoc($result);
231+
$row = $result[0];
229232
$revId = $row['MAX'] + 1;
230233
}
231234
else $revId=1;
232235

233236

234237
$query = "INSERT INTO `article_contentbak` (`page_modulecomponentid` ,`article_revision` ,`article_diff`,`user_id`)
235238
VALUES ('$this->moduleComponentId', '$revId','$diff','$this->userId')";
236-
$result = mysql_query($query);
237-
if(!$result) { displayerror(mysql_error() . "article.lib L:44"); return; }
239+
$result = $pdb->query($query);
240+
//if(!$result) { displayerror(mysql_error() . "article.lib L:44"); return; }
238241

239242
/*Save the diff end.*/
240243

241244
$query = "UPDATE `article_content` SET `article_content` = '" . escape($_POST["CKEditor1"]) . "' WHERE `page_modulecomponentid` ='$this->moduleComponentId' ";
242-
$result = mysql_query($query);
243-
if(mysql_affected_rows() < 0)
245+
$result = $pdb->query($query);
246+
if(count($result) <= 0)
244247
displayerror("Unable to update the article content");
245248
else {
246249

@@ -254,8 +257,8 @@ public function actionEdit() {
254257
if(isset($_POST['editor'])){
255258
$editor=escape($_POST['editor']);
256259
$query = "UPDATE `article_content` SET `default_editor` = '" . $editor . "' WHERE `page_modulecomponentid` ='$this->moduleComponentId' ";
257-
$result = mysql_query($query);
258-
if(mysql_affected_rows() < 0)
260+
$result = $pdb->query($query);
261+
if(count($result) < 0)
259262
displayerror("Unable to update the article Editor");
260263
}
261264
return $this->actionView();
@@ -265,12 +268,12 @@ public function actionEdit() {
265268
$commentsedit = "<fieldset><legend><a name='comments'>{$ICONS['Page Comments']['small']}Comments</a></legend>";
266269

267270
if($this->isCommentsEnabled()) {
268-
$comments = mysql_query("SELECT `comment_id`,`user`,`timestamp`,`comment` FROM `article_comments` WHERE `page_modulecomponentid` = '{$this->moduleComponentId}' ORDER BY `timestamp`");
269-
if(mysql_num_rows($comments)==0)
271+
$comments = $pdb->query("SELECT `comment_id`,`user`,`timestamp`,`comment` FROM `article_comments` WHERE `page_modulecomponentid` = '{$this->moduleComponentId}' ORDER BY `timestamp`");
272+
if(count($comments)==0)
270273
$commentsedit.= "No comments have been posted !";
271274

272275

273-
while($row = mysql_fetch_array($comments))
276+
foreach($comments as $row)
274277
{
275278
$commentsedit .= $this->renderComment($row['comment_id'],$row['user'],$row['timestamp'],$row['comment'],1);
276279

@@ -366,13 +369,14 @@ public function patch($article,$patch) {
366369
return $patch;
367370
}
368371
public function getRevision($revisionNo) {
372+
global $pdb;
369373
$currentquery = "SELECT article_content FROM article_content WHERE page_modulecomponentid='" . $this->moduleComponentId."'";
370-
$currentresult = mysql_query($currentquery);
371-
$currentrow = mysql_fetch_assoc($currentresult);
374+
$currentresult = $pdb->query($currentquery);
375+
$currentrow = $currentresult[0];
372376
$revision = $currentrow['article_content'];
373377
$diffquery = "SELECT * FROM `article_contentbak` WHERE `page_modulecomponentid`='$this->moduleComponentId' AND article_revision >= '$revisionNo' ORDER BY article_revision DESC";
374-
$diffresult = mysql_query($diffquery);
375-
while($diffrow = mysql_fetch_assoc($diffresult)) {
378+
$diffresult = $pdb->query($diffquery);
379+
foreach($diffresult as $diffrow) {
376380
$revision = $this->patch($revision,$diffrow['article_diff']);
377381
}
378382
return $revision;

0 commit comments

Comments
 (0)