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

Services/RTE/tiny_mce/plugins/ibrowser/imagemanager.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 include_once "HTML/Template/ITX.php";
00025 include_once "config.php"; 
00026 
00027 $dir = getcwd();
00028 chdir("../../../../../");
00029 include_once "webservice/soap/include/inc.soap_functions.php";
00030 $mobs = getMobsOfObject($_GET["session_id"]."::".$_GET["client_id"], $_GET["obj_type"].":html", $_GET["obj_id"]);
00031 chdir($dir);
00032 
00033 $preview = "";
00034 $arr_tinyMCE_image_files = array();
00035 $request_uri = urldecode(empty($_POST['request_uri'])?(empty($_GET['request_uri'])?'':$_GET['request_uri']):$_POST['request_uri']);
00036 $img = isset($_POST['imglist'])?$_POST['imglist']:'';
00037 $_root = $installpath;
00038 $errors = array();
00039 
00040 // upload images
00041 if (isset($_FILES['img_file']['size']) && $_FILES['img_file']['size']>0)
00042 {
00043         $dir = getcwd();
00044         chdir("../../../../../");
00045         include_once "webservice/soap/include/inc.soap_functions.php";
00046         $safefilename = preg_replace("/[^a-zA-z0-9_\.]/", "", $_FILES["img_file"]["name"]);
00047         $media_object = saveTempFileAsMediaObject($_GET["session_id"]."::".$_GET["client_id"], $safefilename, $_FILES["img_file"]["tmp_name"]);
00048         if (file_exists($iliasAbsolutePath.$iliasMobPath."mm_".$media_object->getId() . "/" . $media_object->getTitle()))
00049         {
00050                 // only save usage if the file was uploaded
00051                 $media_object->_saveUsage($media_object->getId(), $_GET["obj_type"].":html", $_GET["obj_id"]);
00052         }
00053         chdir($dir);
00054         $preview = $iliasHttpPath.$iliasMobPath."mm_".$media_object->getId() . "/" . $media_object->getTitle();
00055         $mobs[$media_object->getId()] = $media_object->getId();
00056 }
00057 
00058 $tpl = new HTML_Template_ITX();
00059 $tpl->loadTemplatefile("tpl.imagemanager.html", TRUE, TRUE);
00060 
00061 // delete image
00062 if ($tinyMCE_img_delete_allowed && isset($_POST['lib_action']) 
00063         && ($_POST['lib_action']=='delete') && !empty($img)) 
00064 {
00065   deleteImg();
00066 }
00067 
00068 if ($tinyMCE_img_delete_allowed)
00069 {
00070         $tpl->touchBlock("delete_allowed");
00071 }
00072 outMobImages();
00073 outMobImageParams();
00074 $tpl->setVariable("REQUEST_URI", $_GET["request_uri"]);
00075 $tpl->setVariable("VALUE_REQUEST_URI", $request_uri);
00076 $tpl->setVariable("OBJ_ID", $_GET["obj_id"]);
00077 $tpl->setVariable("OBJ_TYPE", $_GET["obj_type"]);
00078 $tpl->setVariable("SESSION_ID", $_GET["session_id"]);
00079 $tpl->setVariable("CLIENT_ID", $_GET["client_id"]);
00080 $tpl->setVariable("VALUE_UPDATE", $_GET["update"]);
00081 if ($_GET["update"] == 1)
00082 {
00083         $tpl->setVariable("INSERT_COMMAND", "{\$lang_update}");
00084 }
00085 else
00086 {
00087         $tpl->setVariable("INSERT_COMMAND", "{\$lang_insert}");
00088 }
00089 $tpl->setVariable("URL_PREVIEW", $preview);
00090 $error_messages = "";
00091 if (!empty($errors))
00092 {
00093         $error_messages .= '<span class="error">';
00094   foreach ($errors as $err)
00095   {
00096                 $error_messages .= $err . "<br />";
00097         }
00098   $error_messages .= "</span>";
00099 }
00100 $tpl->setVariable("ERROR_MESSAGES", $error_messages);
00101 $tpl->show();
00102 
00103         function outMobImages()
00104         {
00105                 global $mobs;
00106                 global $iliasMobPath;
00107                 global $iliasAbsolutePath;
00108                 global $iliasHttpPath;
00109                 global $tinyMCE_valid_imgs;
00110                 global $tpl;
00111                 global $errors;
00112                 global $img;
00113                 global $arr_tinyMCE_image_files;
00114                 
00115                 $i = 0;
00116                 // read image directory
00117                 foreach ($mobs as $mob)
00118                 {
00119                         $mobdir = $iliasAbsolutePath.$iliasMobPath."mm_".$mob . "/";
00120                         $d = @dir($mobdir);
00121                         if ($d) 
00122                         {
00123                                 while (FALSE !== ($entry = $d->read())) 
00124                                 {
00125                                         $ext = strtolower(substr(strrchr($entry,'.'), 1));
00126                                         if (is_file($mobdir.$entry) && in_array($ext, $tinyMCE_valid_imgs))
00127                                         {
00128                                                 $arr_tinyMCE_image_files[$i]["file_name"] = $entry;                     
00129                                                 $arr_tinyMCE_image_files[$i]["file_dir"] = $mobdir;                     
00130                                                 $arr_tinyMCE_image_files[$i]["http_dir"] = $iliasHttpPath.$iliasMobPath."mm_".$mob . "/";                       
00131                                                 $i++;
00132                                         }
00133                                 }
00134                                 $d->close();
00135                         }  
00136                         else
00137                         {
00138                                 $errors[] = '{$lang_ibrowser_errornodir}';
00139                         }
00140                 }
00141                 // sort the list of image filenames alphabetically.
00142                 sort($arr_tinyMCE_image_files);
00143                 
00144                 for ($k=0; $k<count($arr_tinyMCE_image_files); $k++)
00145                 { 
00146                         $entry = $arr_tinyMCE_image_files[$k]["file_name"];
00147                         $size = getimagesize($arr_tinyMCE_image_files[$k]["file_dir"].$entry);
00148                         $fsize = filesize($arr_tinyMCE_image_files[$k]["file_dir"].$entry);
00149                         $tpl->setCurrentBlock("imagefile");
00150                         $tpl->setVariable("IMAGEFILE_VALUE", $arr_tinyMCE_image_files[$k]["http_dir"]);
00151                         $tpl->setVariable("IMAGEFILE_TEXT", $entry);
00152                         if ($entry == $img)
00153                         {
00154                                 $tpl->setVariable("IMAGEFILE_SELECTED", " selected=\"selected\"");
00155                         }
00156                         $tpl->parseCurrentBlock();
00157                 }
00158         }
00159         
00160         function outMobImageParams()
00161         {
00162                 global $arr_tinyMCE_image_files;
00163                 global $tpl;
00164                 for ($k=0; $k<count($arr_tinyMCE_image_files); $k++)
00165                 {
00166                         $tpl->setCurrentBlock("imageparams");
00167                         $entry = $arr_tinyMCE_image_files[$k]["file_name"];
00168                   $size = getimagesize($arr_tinyMCE_image_files[$k]["file_dir"].$entry);
00169                   $fsize = filesize($arr_tinyMCE_image_files[$k]["file_dir"].$entry);
00170                         $tpl->setVariable("IMG_WIDTH", $size[0]);
00171                         $tpl->setVariable("IMG_HEIGHT", $size[1]);
00172                         $tpl->setVariable("IMG_PATH", $arr_tinyMCE_image_files[$k]["http_dir"]);
00173                         $tpl->setVariable("F_SIZE", filesize_h($fsize,2));
00174                         $tpl->parseCurrentBlock();
00175                 }
00176         }
00177 
00178         function deleteImg()
00179         {
00180         }
00181 
00182 // Return the human readable size of a file
00183 // @param int $size a file size
00184 // @param int $dec a number of decimal places
00185 
00186 function filesize_h($size, $dec = 1)
00187 {
00188         $sizes = array('byte(s)', 'kb', 'mb', 'gb');
00189         $count = count($sizes);
00190         $i = 0;
00191 
00192         while ($size >= 1024 && ($i < $count - 1)) {
00193                 $size /= 1024;
00194                 $i++;
00195         }
00196 
00197         return round($size, $dec) . ' ' . $sizes[$i];
00198 }
00199         
00200 function liboptions($arr, $prefix = '', $sel = '')
00201 {
00202   $buf = '';
00203   foreach($arr as $lib) {
00204     $buf .= '<option value="'.$lib['value'].'"'.(($lib['value'] == $sel)?' selected':'').'>'.$prefix.$lib['text'].'</option>'."\n";
00205   }
00206   return $buf;
00207 }
00208 
00209 ?>

Generated on Fri Dec 13 2013 13:52:12 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1