• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

cms/iconmanagement.lib.php

Go to the documentation of this file.
00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 { 
00004         header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005         echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006         echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007         exit(1);
00008 }
00024 function handleIconManagement() {
00025 
00026         /*
00027         *       Upload a new icon
00028         */
00029         if(isset($_POST['FileUploadForm'])){
00030                 global $userId,$sourceFolder;
00031                 require_once("$sourceFolder/upload.lib.php");
00032                 $allowableTypes = array (
00033                                 'jpeg',
00034                                 'jpg',
00035                                 'png',
00036                                 'gif'
00037                         );
00038                 $result = submitFileUploadForm($userId, 'iconman', $userId, false, $allowableTypes, 'iconUpload');
00039                 
00040         }
00041 
00045         if(isset($_GET['iconURL']))
00046         {
00047                 $rootUri = hostURL();   
00048                 global $cmsFolder,$templateFolder;
00049                 
00050                 if(isset($_GET["iconURL"]) && isset($_GET['targetId'])) {
00051                 
00053                         $iconURL = $_GET["iconURL"];
00054                         $iconURL = str_replace($rootUri, "", $iconURL);
00055                         $parse = strstr($iconURL, "$cmsFolder/$templateFolder/common/icons/");
00056                         if($parse == "")
00057                                 $parse = strstr($iconURL, "$cmsFolder/uploads/iconman/");
00058                         $iconURL = $parse;
00059                         $iconURL = escape($iconURL);
00060                         $target = escape($_GET["targetId"]);
00061                         
00066                         mysql_query("UPDATE `".MYSQL_DATABASE_PREFIX."pages` SET `page_image`='$iconURL' WHERE `page_id`='$target'");
00067                         $pageDetails = getPageInfo($target);
00068                         if($pageDetails['page_image'] != NULL)
00069                                 echo "<img src=\"$rootUri/$cmsFolder/$templateFolder/common/icons/16x16/status/weather-clear.png\" /> ";
00070                         else
00071                                 echo "<img src=\"$rootUri/$cmsFolder/$templateFolder/common/icons/16x16/status/dialog-error.png\" width=12 height=12/> ";
00072                         echo $pageDetails["page_name"];
00073         
00074                 }
00075                 
00080                 else if(isset($_GET['iconAction'])) {
00081                         $action = $_GET['iconAction'];
00082                         
00083                 }
00085                 else
00086                 {
00087                         die("Restricted access");
00088                 }
00089                 exit(0);
00090         }
00091 
00092 
00096         $iconForm = "";
00097         $iconForm .= <<<ICONFORM
00098                 <style type="text/css">
00099                 .myIconForm div {
00100                         padding: 5px;
00101                 }
00102                 .myIconForm div a{
00103                         text-decoration: none!important;
00104                 }       
00105                 </style>
00106                 
00107 ICONFORM;
00108 
00109         global $cmsFolder;
00110         global $sourceFolder;
00111         global $templateFolder;
00112         global $userId;
00113         $myhostURL = hostURL();
00114         
00116         $iconForm .= "<script type=\"text/javascript\" src=\"$myhostURL/$cmsFolder/$templateFolder/common/scripts/icon.event.handler.js\"></script>";
00117         
00118         $iconForm .= <<<STYLES
00119                 <style type="text/css">
00120                 .myIconForm {
00121                         margin:0;
00122                         padding:0;
00123                 }
00124                 #iconTreeMenu {
00125                         position:relative;
00126                 }
00127                 .myIconForm ul {
00128                         margin: 5px;
00129                         width: 100%;
00130                         margin-left: 10px;
00131                         padding: 0;
00132                         border-left: solid 1px #333;
00133                 }
00134                 .myFormIcon ul li a {
00135                         padding: 5px;
00136                 }
00137                 .myIconList {
00138                         height:500px;
00139                         overflow:scroll;
00140                         max-width:100%;
00141                 }
00142                 </style>
00143 STYLES;
00144         
00146         require_once("$sourceFolder/upload.lib.php");
00147         
00149         $fakeid = $userId;
00150         
00152         $imageUploadField = getMultipleFileUploadField('iconUpload','iconman',512*1024);
00153         
00154         //$iconForm .= $imageUploadField;
00155         $uploadForm = <<<FORM
00156         <form method="POST" action="./+admin&subaction=icon" enctype="multipart/form-data">
00157         $imageUploadField
00158         <input type="submit" />
00159         </form>
00160         
00161 FORM;
00162         
00164         $iconForm .= "<table class=\"myIconForm\"><tr><td id=\"iconTreeMenu\">";
00165         
00168         $iconForm .= getTreeView(0,-1,$myhostURL,$userId,1);
00169         $iconForm .= "</td>";
00170         $iconForm .="<td>";
00171         
00173         $selectionList = getIconList();
00174 
00176         $iconForm .= <<<SELECTION
00177                 <div class="selection" id="targetIcon">
00178                         <h3>Upload new icons</h3>
00179                                 <p align="left">
00180                                         {$uploadForm}<br/>
00181                                         - Select Multiple files
00182                                 </p>
00183                         <h3>List of available icons</h3>
00184                         <p align="left">
00185                                 Usage : <br />
00186                                 - Drag and drop<br />
00187                                 - Select an icon and then choose the target.
00188                                 </p>
00189                         <div class="selectlist">
00190                                 {$selectionList}
00191                         </div>
00192                 </div>
00193 SELECTION;
00194 
00195         $iconForm .="</td>";
00196 
00197         $iconForm .= "</tr></table>";
00198 
00199 
00200 
00201         return $iconForm;
00202 }
00203 
00217 function getTreeView($pageId,$depth,$rootUri,$userId,$curdepth) {
00218         global $cmsFolder;
00219         global $templateFolder;
00220         require_once("menu.lib.php");
00221   if($depth>0 || $depth==-1) {
00222   if($curdepth==1 || $pageId==0) $classname="treeRoot";
00223   else $classname="treeItem";
00224   $pageRow = getChildren($pageId,$userId);
00225   $var = "<ul class='{$classname}'>";
00226   for($i=0;$i<count($pageRow);$i+=1) {
00227           $newdepth=$curdepth+1;
00228           $var .= "<li><a href=\"./\" class=\"dropme\" onclick=\"return selectItem(event,this)\"";
00229           $var .= <<<DROPZONE
00230           ondragenter="dragEnterHandler(event)" ondragover="dragOverHandler(event)" ondragleave="dragOutHandler(event)" ondrop="dropHandler(event)" id="p{$pageRow[$i][0]}">  
00231 DROPZONE;
00232           if($pageRow[$i][3] != NULL)
00233                 $var .= "<img src=\"$rootUri/$cmsFolder/$templateFolder/common/icons/16x16/status/weather-clear.png\" />\n ";
00234           else
00235                 $var .= "<img src=\"$rootUri/$cmsFolder/$templateFolder/common/icons/16x16/status/dialog-error.png\" width=12 height=12/>\n ";
00236           $var .= "{$pageRow[$i][1]}</a>";
00237           $var .= getTreeView($pageRow[$i][0],($depth==-1)?$depth:($depth-1),$rootUri,$userId,$newdepth);
00238           $var .= "</li>";
00239         }
00240   $var .= "</ul>";
00241   if(count($pageRow)==0) return "";
00242   return $var;
00243   }
00244 }
00245 
00251 function getIconList() {
00252         $iconList = "";
00253         $rootUri = hostURL();
00254         global $cmsFolder,$sourceFolder;
00255         global $templateFolder;
00256         $dir = "$cmsFolder/$templateFolder/common/icons/32x32/";
00257         $uploaded = "";
00258         if(is_dir("$sourceFolder/uploads/iconman/")) {
00259                 $uploaded = "$cmsFolder/uploads/iconman/";
00260         }
00261         
00262         //$dir = "$cmsFolder/$templateFolder/trinity/images/events/";
00263         
00264         $handle = scandir($dir);
00265         $iconList .= <<<SCRIPTS
00266         <script type="text/javascript">
00267         var rootUri = "{$rootUri}";
00268         var cmsFolder = "{$cmsFolder}";
00269         var templateFolder = "{$templateFolder}";
00270         </script>
00271 SCRIPTS;
00272         $iconList .= <<<STYLES
00273         <style type="text/css">
00274         .dragme{
00275                 float:left;
00276         }
00277         .myIconList #noImage {
00278                 width: 30px;
00279                 height: 30px;
00280                 border: solid 1px #000;
00281         }
00282         </style>
00283 STYLES;
00284         $iconList .= "<div class='myIconList'>";
00285         
00286         $id=0;
00287         $iconList .= <<<NONE
00288                 <div class="dragme" draggable="true" ondragstart="dragStartHandler(event,this)" id="noImage" onclick="selectIcon(event,this)">
00289                 <img src="{$rootUri}/{$cmsFolder}/{$templateFolder}/common/images/erase_icon.jpg" width=30 height=30/>
00290                 </div>
00291 NONE;
00292 
00293 
00294         if($uploaded != "") {
00295                 $iconList .= <<<HTMl
00296                         <style type="text/css">
00297                                 .myUploadedIcons {
00298                                         clear: both;
00299                                 }
00300                                 .cms-common-icons {
00301                                         clear: both;
00302                                 }
00303                         </style>
00304                         <div class="myUploadedIcons">
00305                         <h3>My Uploads: </h3>
00306 HTMl;
00307                 $iconList .= getListOfFiles($uploaded, true);
00308                 $iconList .= "</div><div class=\"clearer\"></div>";
00309         }
00310         
00311         $iconList .= "<div class=\"cms-common-icons\"><h3>CMS icons</h3>";
00312         $iconList .= getListOfFiles($dir,true);
00313         $iconList .= "</div>";
00314         
00315         $iconList .= "</div>";
00316         return $iconList;
00317 }
00318 
00326 function getListOfFiles($dir, $isTopLevel=false) {
00327         global $iconList;
00328         if(substr($dir,-1) != '/')
00329                 $dir .= "/";
00330         $rootUri = hostURL();
00331         if($isTopLevel)
00332                 $iconList = "";
00333         if(is_readable($dir)) {
00334                 $handle = scandir($dir);
00335                 foreach($handle as $item) {
00336                         if($item != '.' && $item != '..' && $item[0]!=".") {
00337                                 if(is_dir($dir.$item))
00338                                         getListOfFiles($dir.$item);
00339                                 else {
00340                                         if(is_readable($dir.$item)) {
00341                                                 $type = explode("/",mime_content_type($dir.$item));
00342                                                 if($type[0] == "image") {
00343                                                         $iconList .= "<div class=\"dragme\" draggable=\"true\" ondragstart=\"dragStartHandler(event,this)\" onclick=\"selectIcon(event,this)\">";
00344                                                         $iconList .= "<img title='$item' alt='$item' src='{$rootUri}/{$dir}{$item}' width=32 height=32 /></div>\n";
00345                                                 }
00346                                         }
00347                                 }
00348                         }
00349                 }
00350         }
00351         return $iconList;
00352 }
00353 
00358 if(!function_exists('mime_content_type')) {
00359 
00360     function mime_content_type($filename) {
00361 
00362         $mime_types = array(
00363 
00364             'txt' => 'text/plain',
00365             'htm' => 'text/html',
00366             'html' => 'text/html',
00367             'php' => 'text/html',
00368             'css' => 'text/css',
00369             'js' => 'application/javascript',
00370             'json' => 'application/json',
00371             'xml' => 'application/xml',
00372             'swf' => 'application/x-shockwave-flash',
00373             'flv' => 'video/x-flv',
00374 
00375             // images
00376             'png' => 'image/png',
00377             'jpe' => 'image/jpeg',
00378             'jpeg' => 'image/jpeg',
00379             'jpg' => 'image/jpeg',
00380             'gif' => 'image/gif',
00381             'bmp' => 'image/bmp',
00382             'ico' => 'image/vnd.microsoft.icon',
00383             'tiff' => 'image/tiff',
00384             'tif' => 'image/tiff',
00385             'svg' => 'image/svg+xml',
00386             'svgz' => 'image/svg+xml',
00387 
00388             // archives
00389             'zip' => 'application/zip',
00390             'rar' => 'application/x-rar-compressed',
00391             'exe' => 'application/x-msdownload',
00392             'msi' => 'application/x-msdownload',
00393             'cab' => 'application/vnd.ms-cab-compressed',
00394 
00395             // audio/video
00396             'mp3' => 'audio/mpeg',
00397             'qt' => 'video/quicktime',
00398             'mov' => 'video/quicktime',
00399 
00400             // adobe
00401             'pdf' => 'application/pdf',
00402             'psd' => 'image/vnd.adobe.photoshop',
00403             'ai' => 'application/postscript',
00404             'eps' => 'application/postscript',
00405             'ps' => 'application/postscript',
00406 
00407             // ms office
00408             'doc' => 'application/msword',
00409             'rtf' => 'application/rtf',
00410             'xls' => 'application/vnd.ms-excel',
00411             'ppt' => 'application/vnd.ms-powerpoint',
00412 
00413             // open office
00414             'odt' => 'application/vnd.oasis.opendocument.text',
00415             'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
00416         );
00417 
00418         $ext = strtolower(array_pop(explode('.',$filename)));
00419         if (array_key_exists($ext, $mime_types)) {
00420             return $mime_types[$ext];
00421         }
00422         elseif (function_exists('finfo_open')) {
00423             $finfo = finfo_open(FILEINFO_MIME);
00424             $mimetype = finfo_file($finfo, $filename);
00425             finfo_close($finfo);
00426             return $mimetype;
00427         }
00428         else {
00429             return 'application/octet-stream';
00430         }
00431     }
00432 }
00433 
00434 ?>

Generated on Mon Mar 14 2011 05:35:29 for Pragyan CMS by  doxygen 1.7.1