Skip to content

Commit fb7d198

Browse files
committed
Merge branch 'master' of https://github.com/vigneshmanix/pragyan into pdo
2 parents 562dba0 + b39f514 commit fb7d198

5 files changed

Lines changed: 108 additions & 84 deletions

File tree

cms/searchbar.lib.php

Lines changed: 88 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
22
/**
33
* @package pragyan
4+
* @author Sriram Sundarraj (srirams6)
45
* @copyright (c) 2010 Pragyan Team
56
* @license http://www.gnu.org/licenses/ GNU Public License
67
* For more details, see README
78
*/
8-
if(!defined('__PRAGYAN_CMS'))
9-
{
10-
header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
11-
echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
12-
echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
13-
exit(1);
9+
if (!defined('__PRAGYAN_CMS')) {
10+
header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
11+
echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
12+
echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
13+
exit(1);
1414
}
1515

1616
/**
@@ -19,67 +19,87 @@
1919
*
2020
* @return $searchbar The search bar for tags.
2121
*/
22-
function getSearchbar($userId, $pageId){
23-
if(isset($_GET['searchbar']) && isset($_GET['searchContents'])){
24-
$searchQuery="SELECT DISTINCT `page_id` FROM `". MYSQL_DATABASE_PREFIX ."pagetags` WHERE `tag_text` LIKE '%{$_GET['searchContents']}%';";
25-
$searchResult=mysql_query($searchQuery);
26-
$suggestions="";
27-
while($row=mysql_fetch_assoc($searchResult)){
28-
$suggestions.="<a href=".hostURL().getPagePath($row['page_id']).">";
29-
$pageInfo=getPageInfo($row['page_id']);
30-
$suggestions.=$pageInfo['page_title']."</a><br/>";
31-
}
32-
echo $suggestions;
33-
exit(0);
34-
}
35-
$allPageQuery="SELECT `page_id`, `page_module` FROM `". MYSQL_DATABASE_PREFIX ."pages`";
36-
$allPageResult=mysql_query($allPageQuery);
37-
$pagesIdList=array();
38-
while ($row=mysql_fetch_assoc($allPageResult)){
39-
if(getPermissions($userId, $row['page_id'], $action="view", $module=$row['page_module']))
40-
array_push($pagesIdList, intval($row['page_id']));
41-
}
42-
$tagsWithPermsQuery="SELECT * FROM `". MYSQL_DATABASE_PREFIX ."pagetags` WHERE `page_id` IN (";
43-
foreach ($pagesIdList as $key => $value) {
44-
$tagsWithPermsQuery.=$value.",";
45-
}
46-
$tagsWithPermsQuery=substr($tagsWithPermsQuery,0,-1).");";
47-
$tagsWithPermsResult= mysql_query($tagsWithPermsQuery);
48-
$searchbar=<<<SEARCHSCRIPT
49-
<script>
50-
function showResult(searchstr) {
51-
if (searchstr.length==0) {
52-
document.getElementById("tagSuggestions").innerHTML="";
53-
document.getElementById("tagSuggestions").style.border="0px";
54-
return;
55-
}
56-
if (window.XMLHttpRequest) {
57-
// code for IE7+, Firefox, Chrome, Opera, Safari
58-
xmlhttp=new XMLHttpRequest();
59-
}else { // code for IE6, IE5
60-
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
61-
}
62-
xmlhttp.onreadystatechange=function() {
63-
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
64-
if(xmlhttp.responseText != ""){
65-
console.log(xmlhttp.responseText);
66-
document.getElementById("tagSuggestions").innerHTML=xmlhttp.responseText;
67-
document.getElementById("tagSuggestions").style.border="1px solid #A5ACB2";
68-
}
69-
else{
70-
document.getElementById("tagSuggestions").innerHTML="";
71-
document.getElementById("tagSuggestions").style.border="0px";
72-
}
73-
}
74-
}
75-
xmlhttp.open("GET","./&searchbar=1&searchContents="+searchstr,true);
76-
xmlhttp.send();
77-
}
78-
</script>
22+
function getSearchbar($userId, $pageId) {
23+
if(isset($_GET['searchbar']) && isset($_GET['searchContents'])) {
24+
$_GET['searchbar'] = escape($_GET['searchbar']);
25+
$_GET['searchContents'] = escape($_GET['searchContents']);
26+
27+
$allPageQuery="SELECT `page_id`, `page_module` FROM `". MYSQL_DATABASE_PREFIX ."pages`";
28+
$allPageResult=mysql_query($allPageQuery);
29+
$pagesIdList=array(); //Contains all pages for which the user has view permission
30+
while ($row=mysql_fetch_assoc($allPageResult)) {
31+
if(getPermissions($userId, $row['page_id'], $action="view", $module=$row['page_module']))
32+
array_push($pagesIdList, intval($row['page_id']));
33+
}
34+
$searchQueryParams="";
35+
foreach ($pagesIdList as $key => $value) {
36+
$searchQueryParams.=$value.",";
37+
}
38+
$searchQueryParams=substr($searchQueryParams,0,-1);
39+
$searchQuery="SELECT * FROM `". MYSQL_DATABASE_PREFIX ."pagetags` WHERE `tag_text` LIKE '%{$_GET['searchContents']}%' AND `page_id` IN (".$searchQueryParams.");";
40+
$tagsWithPermsResult= mysql_query($searchQuery);
41+
42+
$searchResult=mysql_query($searchQuery);
43+
$suggestions="";
44+
while ($row=mysql_fetch_assoc($searchResult)) {
45+
$suggestions.="<a href=".hostURL().getPagePath($row['page_id']).">";
46+
$pageInfo=getPageInfo($row['page_id']);
47+
$suggestions.=$pageInfo['page_title']."</a><br/>";
48+
}
49+
echo $suggestions;
50+
exit(0);
51+
}
52+
$searchbar=<<<SEARCHSCRIPT
53+
<script>
54+
function showResult(searchstr) {
55+
if (searchstr.length==0) {
56+
document.getElementById("tagSuggestions").innerHTML="";
57+
document.getElementById("tagSuggestions").style.border="0px";
58+
return;
59+
}
60+
if (window.XMLHttpRequest) {
61+
// code for IE7+, Firefox, Chrome, Opera, Safari
62+
xmlhttp=new XMLHttpRequest();
63+
}else { // code for IE6, IE5
64+
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
65+
}
66+
xmlhttp.onreadystatechange=function() {
67+
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
68+
if(xmlhttp.responseText != "") {
69+
console.log(xmlhttp.responseText);
70+
document.getElementById("tagSuggestions").innerHTML=xmlhttp.responseText;
71+
document.getElementById("tagSuggestions").style.border="1px solid #A5ACB2";
72+
}
73+
else {
74+
document.getElementById("tagSuggestions").innerHTML="";
75+
document.getElementById("tagSuggestions").style.border="0px";
76+
}
77+
}
78+
}
79+
xmlhttp.open("GET","./&searchbar=1&searchContents="+searchstr,true);
80+
xmlhttp.send();
81+
}
82+
</script>
7983
SEARCHSCRIPT;
80-
$searchbar.="<div id=\"cms-searchbar\">";
81-
$searchbar.="<input type=\"text\" size=\"30\" onkeyup=\"showResult(this.value)\">";
82-
$searchbar.="<div id=\"tagSuggestions\"></div>";
83-
$searchbar.="</div>";
84-
return $searchbar;
84+
$searchbar.="<div id='cms-searchbar'>";
85+
$searchbar.="<input type='text' size='30' onkeyup='showResult(this.value)'>";
86+
$searchbar.="<div id='tagSuggestions'></div>";
87+
$searchbar.="</div>";
88+
return $searchbar;
89+
}
90+
91+
/**
92+
* @param $pageId The page on which the permissible action for the user is computed
93+
*
94+
* @return $pagetags The tags for the page.
95+
*/
96+
function getPagetags($pageId) {
97+
$pageTagQuery="SELECT `tag_text` FROM `". MYSQL_DATABASE_PREFIX ."pagetags` WHERE `page_id` = {$pageId}";
98+
$pageTagResult=mysql_query($pageTagQuery);
99+
$pagetags=[];
100+
while ($row=mysql_fetch_assoc($pageTagResult)) {
101+
array_push($pagetags, $row['tag_text']);
102+
}
103+
$pagetags = implode(" , ", $pagetags);
104+
return $pagetags;
85105
}

cms/template.lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function getPageTemplate($pageId)
5353
* template
5454
*
5555
*/
56-
function templateReplace(&$TITLE,&$MENUBAR,&$ACTIONBARMODULE,&$ACTIONBARPAGE,&$BREADCRUMB,&$SEARCHBAR,&$INHERITEDINFO,&$CONTENT,&$FOOTER,&$DEBUGINFO,&$ERRORSTRING,&$WARNINGSTRING,&$INFOSTRING,&$STARTSCRIPTS,&$LOGINFORM) {
56+
function templateReplace(&$TITLE,&$MENUBAR,&$ACTIONBARMODULE,&$ACTIONBARPAGE,&$BREADCRUMB,&$SEARCHBAR,&$PAGEKEYWORDS,&$INHERITEDINFO,&$CONTENT,&$FOOTER,&$DEBUGINFO,&$ERRORSTRING,&$WARNINGSTRING,&$INFOSTRING,&$STARTSCRIPTS,&$LOGINFORM) {
5757
global $cmsFolder;
5858
global $sourceFolder;
5959
global $templateFolder;

cms/templates/crystalx/index.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
<?php
2-
if(!defined('__PRAGYAN_CMS'))
3-
{
4-
header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
5-
echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
6-
echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
7-
exit(1);
8-
}
9-
?>
1+
<?php
2+
if(!defined('__PRAGYAN_CMS'))
3+
{
4+
header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
5+
echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
6+
echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
7+
exit(1);
8+
}
9+
?>
1010
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1111
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
1212
<head>
1313
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
1414
<title><?php echo $TITLE; ?></title>
1515
<meta name="description" content="<?php echo $SITEDESCRIPTION ?>" />
16-
<meta name="keywords" content="<?php echo $SITEKEYWORDS ?>" />
16+
<meta name="keywords" content="<?php echo $SITEKEYWORDS.', '.$PAGEKEYWORDS ?>" />
1717
<?php global $urlRequestRoot; global $PAGELASTUPDATED;
1818
if($PAGELASTUPDATED!="")
1919
echo '<meta http-equiv="Last-Update" content="'.substr($PAGELASTUPDATED,0,10).'" />'."\n";

cms/templates/integriti/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<link rel="shortcut icon" href="<?php echo $TEMPLATEBROWSERPATH; ?>/images/logo_16.png" >
1616
<link rel="stylesheet" type="text/css" href="<?php echo $TEMPLATEBROWSERPATH; ?>/styles/main.css" />
1717
<meta name="description" content="<?php echo $SITEDESCRIPTION ?>" />
18-
<meta name="keywords" content="<?php echo $SITEKEYWORDS ?>" />
18+
<meta name="keywords" content="<?php echo $SITEKEYWORDS.', '.$PAGEKEYWORDS ?>" />
1919
<?php global $urlRequestRoot; global $PAGELASTUPDATED;
2020
if($PAGELASTUPDATED!="")
2121
echo '<meta http-equiv="Last-Update" content="'.substr($PAGELASTUPDATED,0,10).'" />'."\n";

index.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@
225225
$BREADCRUMB = breadcrumbs(array(0=>0),"&nbsp;»&nbsp;");
226226
$MENUBAR = getMenu($userId, $pageIdArray);
227227
$SEARCHBAR = getSearchbar($userId, $pageId);
228-
templateReplace($TITLE,$MENUBAR,$ACTIONBARMODULE,$ACTIONBARPAGE,$BREADCRUMB,$SEARCHBAR,$INHERITEDINFO,$CONTENT,$FOOTER,$DEBUGINFO,$ERRORSTRING,$WARNINGSTRING,$INFOSTRING,$STARTSCRIPTS,$LOGINFORM);
228+
$PAGEKEYWORDS = getPagetags($pageId);
229+
templateReplace($TITLE,$MENUBAR,$ACTIONBARMODULE,$ACTIONBARPAGE,$BREADCRUMB,$SEARCHBAR,$PAGEKEYWORDS,$INHERITEDINFO,$CONTENT,$FOOTER,$DEBUGINFO,$ERRORSTRING,$WARNINGSTRING,$INFOSTRING,$STARTSCRIPTS,$LOGINFORM);
229230
exit(1);
230231
}
231232

@@ -238,7 +239,7 @@
238239
$MENUBAR = '';
239240
$CONTENT = "The requested URL was found to have invalid syntax and cannot be processed for security reasons.<br/> If you believe its a". "correct URL, please contact the administrator immediately..<br />$_SERVER[SERVER_SIGNATURE]".
240241
"<br /><br />Click <a href='".$urlRequestRoot."'>here </a> to return to the home page";
241-
templateReplace($TITLE,$MENUBAR,$ACTIONBARMODULE,$ACTIONBARPAGE,$BREADCRUMB,$SEARCHBAR,$INHERITEDINFO,$CONTENT,$FOOTER,$DEBUGINFO,$ERRORSTRING,$WARNINGSTRING,$INFOSTRING,$STARTSCRIPTS,$LOGINFORM);
242+
templateReplace($TITLE,$MENUBAR,$ACTIONBARMODULE,$ACTIONBARPAGE,$BREADCRUMB,$SEARCHBAR,$PAGEKEYWORDS,$INHERITEDINFO,$CONTENT,$FOOTER,$DEBUGINFO,$ERRORSTRING,$WARNINGSTRING,$INFOSTRING,$STARTSCRIPTS,$LOGINFORM);
242243
exit();
243244
}
244245

@@ -253,7 +254,7 @@
253254
$MENUBAR = '';
254255
$CONTENT = "The requested URL was not found on this server.<br />$_SERVER[SERVER_SIGNATURE]".
255256
"<br /><br />Click <a href='".$urlRequestRoot."'>here </a> to return to the home page";
256-
templateReplace($TITLE,$MENUBAR,$ACTIONBARMODULE,$ACTIONBARPAGE,$BREADCRUMB,$SEARCHBAR,$INHERITEDINFO,$CONTENT,$FOOTER,$DEBUGINFO,$ERRORSTRING,$WARNINGSTRING,$INFOSTRING,$STARTSCRIPTS,$LOGINFORM);
257+
templateReplace($TITLE,$MENUBAR,$ACTIONBARMODULE,$ACTIONBARPAGE,$BREADCRUMB,$SEARCHBAR,$PAGEKEYWORDS,$INHERITEDINFO,$CONTENT,$FOOTER,$DEBUGINFO,$ERRORSTRING,$WARNINGSTRING,$INFOSTRING,$STARTSCRIPTS,$LOGINFORM);
257258
exit();
258259
}
259260

@@ -294,6 +295,9 @@
294295
//Gets the searchbar
295296
$SEARCHBAR = getSearchbar($userId, $pageId);
296297

298+
//Gets the page-speciit keywords
299+
$PAGEKEYWORDS = getPagetags($pageId);
300+
297301
///Gets the menubar consisting of the child pages from the current location upto a certain depth
298302
$MENUBAR = getMenu($userId, $pageIdArray);
299303

@@ -352,7 +356,7 @@
352356
setcookie("cookie_support", "enabled", 0, "/");
353357

354358
///Apply the template on the generated content and display the page
355-
templateReplace($TITLE,$MENUBAR,$ACTIONBARMODULE,$ACTIONBARPAGE,$BREADCRUMB,$SEARCHBAR,$INHERITEDINFO,$CONTENT,$FOOTER,$DEBUGINFO,$ERRORSTRING,$WARNINGSTRING,$INFOSTRING,$STARTSCRIPTS,$LOGINFORM);
359+
templateReplace($TITLE,$MENUBAR,$ACTIONBARMODULE,$ACTIONBARPAGE,$BREADCRUMB,$SEARCHBAR,$PAGEKEYWORDS,$INHERITEDINFO,$CONTENT,$FOOTER,$DEBUGINFO,$ERRORSTRING,$WARNINGSTRING,$INFOSTRING,$STARTSCRIPTS,$LOGINFORM);
356360

357361
disconnect();
358362
exit();

0 commit comments

Comments
 (0)