ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
imagemanager.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 chdir('../../../../../');
25 
26 require_once 'Services/Init/classes/class.ilInitialisation.php';
28 
33 
34 $htdocs = $ilIliasIniFile->readVariable('server', 'absolute_path') . '/';
35 $weburl = $ilIliasIniFile->readVariable('server', 'http_path') . '/';
37 
38 
39 // directory where tinymce files are located
40 $iliasMobPath = 'data/' . CLIENT_ID . '/mobs/';
43 // base url for images
46 
48 {
52  global $https;
53 
54  if(strpos($iliasHttpPath, 'https://') === false && $https->isDetected())
55  {
56  $iliasHttpPath = str_replace('http://', 'https://', $iliasHttpPath);
57  }
58 }
59 
60 // allowed extentions for uploaded image files
61 $tinyMCE_valid_imgs = array('gif', 'jpg', 'jpeg', 'png');
62 
63 // allow upload in image library
65 
66 include_once 'webservice/soap/include/inc.soap_functions.php';
67 $mobs = ilSoapFunctions::getMobsOfObject(session_id() . '::' . CLIENT_ID, $_GET['obj_type'] . ':html', (int)$_GET['obj_id']);
68 $preview = '';
69 
70 
71 $img = isset($_POST['imglist']) ? $_POST['imglist'] : '';
73 $errors = array();
74 
75 // upload images
76 if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0)
77 {
78  include_once 'webservice/soap/include/inc.soap_functions.php';
79  $safefilename = preg_replace('/[^a-zA-z0-9_\.]/', '', $_FILES['img_file']['name']);
80  $media_object = ilSoapFunctions::saveTempFileAsMediaObject(session_id() . '::' . CLIENT_ID, $safefilename, $_FILES['img_file']['tmp_name']);
81  if(file_exists($iliasAbsolutePath . $iliasMobPath . 'mm_' . $media_object->getId() . '/' . $media_object->getTitle()))
82  {
83  // only save usage if the file was uploaded
84  $media_object->_saveUsage($media_object->getId(), $_GET['obj_type'] . ':html', (int)$_GET['obj_id']);
85  }
86  $preview = $iliasHttpPath . $iliasMobPath . 'mm_' . $media_object->getId() . '/' . $media_object->getTitle();
87  $mobs[$media_object->getId()] = $media_object->getId();
88 }
89 
90 $tpl = new ilTemplate(dirname(__FILE__).'/tpl.imagemanager.html', true, true);
91 
92 // delete image
93 if ($tinyMCE_img_delete_allowed && isset($_POST['lib_action'])
94  && ($_POST['lib_action']=='delete') && !empty($img))
95 {
96  deleteImg();
97 }
98 
100 {
101  $tpl->touchBlock("delete_allowed");
102 }
103 outMobImages();
105 $tpl->setVariable('OBJ_ID', (int)$_GET['obj_id']);
106 $tpl->setVariable('OBJ_TYPE', $_GET['obj_type']);
107 $tpl->setVariable('VALUE_UPDATE', (int)$_GET['update']);
108 $tpl->setVariable('ILIAS_INST_PATH', $iliasHttpPath);
109 if($_GET['update'] == 1)
110 {
111  $tpl->setVariable('INSERT_COMMAND', '{#update}');
112 }
113 else
114 {
115  $tpl->setVariable('INSERT_COMMAND', '{#insert}');
116 }
117 $tpl->setVariable('URL_PREVIEW', $preview);
119 if(!empty($errors))
120 {
121  $error_messages .= '<span class="error">';
122  foreach($errors as $err)
123  {
124  $error_messages .= $err . '<br />';
125  }
126  $error_messages .= '</span>';
127 }
128 $tpl->setVariable('ERROR_MESSAGES', $error_messages);
129 $tpl->show();
130 
131 function outMobImages()
132 {
133  global $mobs;
134  global $iliasMobPath;
135  global $iliasAbsolutePath;
136  global $iliasHttpPath;
137  global $tinyMCE_valid_imgs;
138  global $tpl;
139  global $errors;
140  global $img;
141  global $arr_tinyMCE_image_files;
142 
143  $arr_tinyMCE_image_files = array();
144 
145  $i = 0;
146  // read image directory
147  foreach($mobs as $mob)
148  {
149  $mobdir = $iliasAbsolutePath . $iliasMobPath . 'mm_' . $mob . '/';
150  $d = @dir($mobdir);
151  if($d)
152  {
153  while(FALSE !== ($entry = $d->read()))
154  {
155  $ext = strtolower(substr(strrchr($entry, '.'), 1));
156  if(is_file($mobdir . $entry) && in_array($ext, $tinyMCE_valid_imgs))
157  {
158  $arr_tinyMCE_image_files[$i]['file_name'] = $entry;
159  $arr_tinyMCE_image_files[$i]['file_dir'] = $mobdir;
160  $arr_tinyMCE_image_files[$i]['http_dir'] = $iliasHttpPath . $iliasMobPath . 'mm_' . $mob . '/';
161  $i++;
162  }
163  }
164  $d->close();
165  }
166  else
167  {
168  $errors[] = '{#ibrowser.errornodir}';
169  }
170  }
171  // sort the list of image filenames alphabetically.
172  sort($arr_tinyMCE_image_files);
173 
174  for($k = 0; $k < count($arr_tinyMCE_image_files); $k++)
175  {
176  $entry = $arr_tinyMCE_image_files[$k]['file_name'];
177  $size = getimagesize($arr_tinyMCE_image_files[$k]['file_dir'] . $entry);
178  $fsize = filesize($arr_tinyMCE_image_files[$k]['file_dir'] . $entry);
179  $tpl->setCurrentBlock('imagefile');
180  $tpl->setVariable('IMAGEFILE_VALUE', $arr_tinyMCE_image_files[$k]['http_dir']);
181  $tpl->setVariable('IMAGEFILE_TEXT', $entry);
182  if($entry == $img)
183  {
184  $tpl->setVariable('IMAGEFILE_SELECTED', ' selected=\'selected\'');
185  }
186  $tpl->parseCurrentBlock();
187  }
188 }
189 
190 function deleteImg()
191 {
192 }
193 
195 {
196  global $arr_tinyMCE_image_files;
197  global $tpl;
198  for($k = 0; $k < count($arr_tinyMCE_image_files); $k++)
199  {
200  $tpl->setCurrentBlock('imageparams');
201  $entry = $arr_tinyMCE_image_files[$k]['file_name'];
202  $size = getimagesize($arr_tinyMCE_image_files[$k]['file_dir'] . $entry);
203  $fsize = filesize($arr_tinyMCE_image_files[$k]['file_dir'] . $entry);
204  $tpl->setVariable('IMG_WIDTH', $size[0]);
205  $tpl->setVariable('IMG_HEIGHT', $size[1]);
206  $tpl->setVariable('IMG_PATH', $arr_tinyMCE_image_files[$k]['http_dir']);
207  $tpl->setVariable('F_SIZE', ilFormat::formatSize($fsize));
208  $tpl->parseCurrentBlock();
209  }
210 }
211 
212 function liboptions($arr, $prefix = '', $sel = '')
213 {
214  $buf = '';
215  foreach($arr as $lib)
216  {
217  $buf .= '<option value="' . $lib['value'] . '"' . (($lib['value'] == $sel) ? ' selected' : '') . '>' . $prefix . $lib['text'] . '</option>' . "\n";
218  }
219  return $buf;
220 }