/cms/modules/gallery.lib.php
PHP | 374 lines | 356 code | 6 blank | 12 comment | 24 complexity | 705c3aeec1178c27672c395ecb97d583 MD5 | raw file
- <?php
- if(!defined('__PRAGYAN_CMS'))
- {
- header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
- echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
- echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
- exit(1);
- }
- /**
- * @package pragyan
- * @author Harini A
- * @copyright (c) 2008 Pragyan Team
- * @license http://www.gnu.org/licenses/ GNU Public License
- * For more details, see README
- */
- class gallery implements module, fileuploadable {
- private $userId;
- private $moduleComponentId;
- private $action;
- public function getHtml($gotuid, $gotmoduleComponentId, $gotaction) {
- $this->userId = $gotuid;
- $this->moduleComponentId = $gotmoduleComponentId;
- $this->action = $gotaction;
- if ($this->action == "view")
- return $this->actionView();
- if ($this->action == "create")
- return $this->createModule($this->moduleComponentId);
- if ($this->action == "edit")
- return $this->actionEdit($this->moduleComponentId);
- }
- /**
- * Funtion which tells the cms uploaded file access is defined by which action
- */
- public static function getFileAccessPermission($pageId, $moduleComponentId, $userId, $fileName) {
- return getPermissions($userId, $pageId, "view");
- }
- public static function getUploadableFileProperties(& $fileTypesArray, & $maxFileSizeInBytes) {
- $fileTypesArray = array (
- 'jpg',
- 'jpeg',
- 'png',
- 'gif'
- );
- $maxFileSizeInBytes = 2 * 1024 * 1024;
- }
- public static function getFileAccessAction() {
- return "view";
- }
- public function actionView() {
- global $sourceFolder,$cmsFolder;
- global $templateFolder;
- global $urlRequestRoot;
- global $moduleFolder;
- global $uploadFolder;
- // Ajax request for returning the views of the image
- if(isset($_GET['subaction'])&&$_GET['subaction']=='ajax') {
- if($_GET['ref']){
- $arr=explode("/",$_GET['ref']);
- $arr = $arr[sizeof($arr)-1];
- $query="SELECT* FROM `gallery_pics` WHERE upload_filename='".$arr."' AND page_modulecomponentid='$this->moduleComponentId' LIMIT 1";
- $result=mysql_query($query);
- if($result){
- $newrate = mysql_result($result,0,'pic_rate')+1;
- $query="UPDATE `gallery_pics` SET `pic_rate`='".$newrate."' WHERE upload_filename='".$arr."' AND page_modulecomponentid='$this->moduleComponentId'";
- mysql_query($query);
- }}
- else if($_GET['getView']){
- $arr1=explode("/",$_GET['getView']);
- $arr1 = $arr1[sizeof($arr1)-1];
- $query="SELECT* FROM `gallery_pics` WHERE upload_filename='".$arr1."' AND page_modulecomponentid='$this->moduleComponentId' LIMIT 1";
- $result1=mysql_query($query);
- if($result1){
- $view = mysql_result($result1,0,'pic_rate');
- echo $view;
- }
- }
- else if($_GET['rateIt']){
- $arr3 = $_GET['rateRef'];
- $query="SELECT `vote_avg`,`voters` FROM `gallery_pics` WHERE upload_filename='".$arr3."' AND page_modulecomponentid='$this->moduleComponentId' LIMIT 1";
- $result3=mysql_query($query);
- if($result3){
- $voteAvg = mysql_result($result3,0,'vote_avg');
- $voters = mysql_result($result3,0,'voters');
- $newAvg = (($voters*$voteAvg)+$_GET['rateIt'])/($voters+1);
- $voters=$voters+1;
- $query="UPDATE `gallery_pics` SET `vote_avg`='".$newAvg."',`voters`='".$voters."' WHERE upload_filename='".$arr3."' AND page_modulecomponentid='$this->moduleComponentId'";
- $result = mysql_query($query);
- if (!$result){echo "a";}
- else{
- $query="SELECT* FROM `gallery_pics` WHERE upload_filename='".$arr3."' AND page_modulecomponentid='$this->moduleComponentId' LIMIT 1";
- $result3 = mysql_query($query);
- if($result3){
- $rating = mysql_result($result3,0,'vote_avg');
- $voters = mysql_result($result3,0,'voters');
- echo $rating."-".$voters;
- }
- else{
- echo "b";
- }
- }
- }
- }
- disconnect();
- exit(0);
- }
- // Ajax request for views ends here
- $content =<<<JS
- <script type="text/javascript" src="$urlRequestRoot/$cmsFolder/$moduleFolder/gallery/highslide-with-gallery.js"></script>
- <link rel="stylesheet" type="text/css" href="$urlRequestRoot/$cmsFolder/$moduleFolder/gallery/highslide.css" />
- <script type="text/javascript">
- hs.graphicsDir = '$urlRequestRoot/$cmsFolder/$moduleFolder/gallery/graphics/';
- hs.align = 'center';
- hs.transitions = ['expand', 'crossfade'];
- hs.fadeInOut = true;
- hs.dimmingOpacity = 0.8;
- hs.outlineType = 'rounded-white';
- hs.captionEval = 'this.thumb.alt';
- hs.marginBottom = 105;
- hs.numberPosition = 'caption';
- hs.addSlideshow({
- interval: 5000,
- repeat: false,
- useControls: true,
- overlayOptions: {
- className: 'text-controls',
- position: 'bottom center',
- relativeTo: 'viewport',
- offsetY: -60
- },
- thumbstrip: {
- position: 'bottom center',
- mode: 'horizontal',
- relativeTo: 'viewport'
- }
- });
- </script>
- JS;
- $gallQuery = "SELECT * from `gallery_name` where `page_modulecomponentid`='$this->moduleComponentId'";
- $gallResult = mysql_query($gallQuery);
- $row = mysql_fetch_assoc($gallResult);
- $content .= "<h2><center>{$row['gallery_name']}</center></h2><br/><center><h3>{$row['gallery_desc']}</center></h3>";
- $perPage = $row['imagesPerPage'];
- $viewCheck = $row['allowViews'];
- $ratingCheck = $row['allowRatings'];
- include_once ("$sourceFolder/" . 'upload.lib.php');
- $query = "SELECT `upload_filename` FROM `gallery_pics` WHERE `page_modulecomponentid` ='". $this->moduleComponentId."'";
- $pic_result = mysql_query($query) or die(mysql_error());
- $arr = array ();
- while ($row = mysql_fetch_assoc($pic_result))
- $arr[] = $row;
- $numPic = count($arr);
- if(isset($_GET['gallerypage']))
- $page = (int)escape($_GET['gallerypage']) - 1;
- else
- $page = 0;
- $start = $page * $perPage;
- if($start > $numPic) {
- $start = 0;
- $page = 0;
- }
- $end = $start + $perPage;
- if($end > $numPic)
- $end = $numPic;
- $content .= '<div class="highslide-gallery" style="width: 100%; margin: auto">';
- for ($i = $start; $i < $end; $i++) {
- $gallQuery2 = "SELECT * FROM `gallery_pics` where `upload_filename`='{$arr[$i]['upload_filename']}' AND `page_modulecomponentid`= '$this->moduleComponentId'";
- $gallResult2 = mysql_query($gallQuery2);
- $row2 = mysql_fetch_assoc($gallResult2);
- if ($row2) {
- $content .= "<input type=\"hidden\" id=\""."thumb_"."{$row2['upload_filename']}\" value=\"{$row2['pic_rate']}\" />";
- $content .= "<input type=\"hidden\" id=\""."thumb1_"."{$row2['upload_filename']}\" value=\"{$row2['vote_avg']}\" />";
- $content .= "<input type=\"hidden\" id=\""."thumb2_"."{$row2['upload_filename']}\" value=\"{$row2['voters']}\" />";
- $content .= "<input type=\"hidden\" id=\""."thumb3_"."{$row2['upload_filename']}\" value=\"0\" />";
- $content .= "<a href=\"./" . $arr[$i]['upload_filename'] . '" class=\'highslide\' onclick="return hs.expand(this,0,0,0,document.getElementById(\'thumb_' .$row2['upload_filename'].'\'),'.$viewCheck.',document.getElementById(\'thumb1_' .$row2['upload_filename'].'\'),document.getElementById(\'thumb2_' .$row2['upload_filename'].'\'),'.$ratingCheck.',document.getElementById(\'thumb3_' .$row2['upload_filename'].'\'))">';
- $content .= "<img src=\"./thumb_" . $arr[$i]['upload_filename'] . "\" alt='{$row2['gallery_filecomment']}' title='Click to enlarge' /></a> ";
- }
- }
- $content .= '</div>';
- $nextVal = $page + 2;
- if($start == 0)
- $prevButton = "<<Prev ";
- else
- $prevButton = "<a href='./+view&gallerypage=" . $page . "'> <<Prev</a> ";
- if($end == $numPic)
- $nextButton = " Next>>";
- else
- $nextButton = " <a href='./+view&gallerypage=" . $nextVal . "'> Next>> </a>";
- $pages = "";
- $pageStart = 1;
- $pageEnd = ceil($numPic/$perPage);
- if($page > 4) {
- $pageStart = $page - 3;
- $pages .= "... ";
- }
- if($pageEnd - $page > 5)
- $pageEnd = $page + 5;
- $pageVal = $page + 1;
- for($i = $pageStart; $i <= $pageEnd; $i++)
- if($i == $pageVal)
- $pages .= " $pageVal ";
- else
- $pages .= " <a href='./+view&gallerypage={$i}'>{$i}</a> ";
- if(ceil($numPic/$perPage) - $page > 5)
- $pages .= " ...";
- $content .= "<p>" . $prevButton . $pages . $nextButton . "</p>";
- return $content;
- }
- public function createModule($nextId) {
- $gallQuery = "INSERT INTO `gallery_name` (`page_modulecomponentid`, `gallery_name`, `gallery_desc`) VALUES('$nextId', 'New Gallery', 'Edit your new gallery')";
- $gallResult = mysql_query($gallQuery);
- }
- public function actionEdit($moduleComponentId) {
- global $sourceFolder;
- global $templateFolder;
- global $urlRequestRoot;
- global $uploadFolder;
- require_once ("$sourceFolder/upload.lib.php");
- $arr = getUploadedFiles($moduleComponentId, 'gallery');
- if (isset ($_POST['btnDeleteImage']) && isset ($_POST['imagename']) && $_POST['imagename'] != '') {
- deleteFile($moduleComponentId, 'gallery', $_POST['imagename']);
- $gallQuery = "DELETE FROM `gallery_pics` WHERE `upload_filename`='".escape($_POST['imagename'])."'";
- $gallResult = mysql_query($gallQuery);
- }
- else if (isset ($_POST['btnEditComment']) && isset ($_POST['imagename']) && $_POST['imagename'] != '') {
- $imageName = escape($_POST['imagename']);
- $comment = escape($_POST['desc']);
- $gallQuery = "UPDATE `gallery_pics` SET `gallery_filecomment`=\"$comment\" WHERE `upload_filename`=\"$imageName\"";
- $gallResult = mysql_query($gallQuery);
- }
- if (isset ($_POST['btnEditGallname']) && isset ($_POST['gallName']) && isset ($_POST['gallDesc']) && $_POST['gallName'] != '' && $_POST['gallDesc'] != '') {
- if(is_numeric($_POST['imagesPerPage']))
- $perPage = (int)escape($_POST['imagesPerPage']);
- $viewCount = ( $_POST['allowViews'] ? 1 : 0 );
- $ratingCount = ( $_POST['allowRatings'] ? 1 : 0 );
- $gallQuery = "UPDATE `gallery_name` SET `gallery_name`='".escape($_POST['gallName'])."',`gallery_desc`='".escape($_POST['gallDesc'])."', `imagesPerPage`='".$perPage."',`allowViews`='".$viewCount."',`allowRatings`='".$ratingCount."' WHERE `page_modulecomponentid`='$moduleComponentId'";
- $gallResult = mysql_query($gallQuery);
- }
- $content2 = getFileUploadForm($this->moduleComponentId, "gallery", './+edit', 10000000, 5);
- $allowableTypes = array (
- 'jpeg',
-