XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
tiny-images.php
Go to the documentation of this file.
1 <?php
2 // $Id: tiny-images.php 999 2012-07-02 03:53:17Z i.bitcero $
3 // --------------------------------------------------------------
4 // Red México Common Utilities
5 // A framework for Red México Modules
6 // Author: Eduardo Cortés <i.bitcero@gmail.com>
7 // Email: i.bitcero@gmail.com
8 // License: GPL 2.0
9 // --------------------------------------------------------------
10 
11 include '../../../mainfile.php';
12 XoopsLogger::getInstance()->activated = false;
13 XoopsLogger::getInstance()->renderingEnabled = false;
14 
15 function send_message($message){
16  global $xoopsSecurity;
17 
18  echo $message;
19  echo '<input type="hidden" id="ret-token" value="'.$xoopsSecurity->createToken().'" />';
20  die();
21 
22 }
23 
24 $category = rmc_server_var($_POST,'category', 0);
25 $action = rmc_server_var($_POST,'action', '');
27 $type = rmc_server_var($_REQUEST, 'type', 'tiny');
28 $en = rmc_server_var($_REQUEST, 'name', '');
29 
30 // Check if target is different from editor
31 $target = rmc_server_var($_REQUEST, 'target', '');
32 $container = rmc_server_var($_REQUEST, 'idcontainer', '');
33 
34 if ($action==''){
35 
36  RMTemplate::get()->add_local_script('jquery.min.js', 'rmcommon', 'include');
37  RMTemplate::get()->add_local_script('jquery-ui.min.js', 'rmcommon', 'include');
38  RMTemplate::get()->add_local_script('images_editor.js', 'rmcommon', 'include');
39 
40  if (!$cat->isNew()){
41  $uploader = new RMFlashUploader('files-container', 'upload.php');
42  $uploader->add_setting('scriptData', array(
43  'action'=>'upload',
44  'category'=>$cat->id(),
45  'rmsecurity'=>TextCleaner::getInstance()->encrypt($xoopsUser->uid().'|'.RMCURL.'/images.php'.'|'.$xoopsSecurity->createToken(), true)
46  ));
47  $uploader->add_setting('multi', true);
48  $uploader->add_setting('fileExt', '*.jpg;*.png;*.gif');
49  $uploader->add_setting('fileDesc', __('All Images (*.jpg, *.png, *.gif)','rmcommon'));
50  $uploader->add_setting('sizeLimit', $cat->getVar('filesize') * $cat->getVar('sizeunit'));
51  $uploader->add_setting('buttonText', __('Browse Images...','rmcommon'));
52  $uploader->add_setting('queueSizeLimit', 100);
53  $uploader->add_setting('auto', true);
54  $uploader->add_setting('onSelect', "function(file){
55  if (queuefiles[file]) return false;
56  queuefiles[file] = true;
57  \$('#upload-errors').html('');
58  return true;
59  }");
60  $uploader->add_setting('onUploadSuccess',"function(file, resp, data){
61  eval('ret = '+resp);
62  if (ret.error){
63  \$('#upload-errors').append('<span class=\"failed\"><strong>'+file.name+'</strong>: '+ret.message+'</span>');
64  } else {
65  total++;
66  ids[total-1] = ret.id;
67  \$('#upload-errors').append('<span class=\"done\"><strong>'+file.name+'</strong>: ".__('Uploaded successfully!','rmcommon')."</span>');
68  }
69  return true;
70  }");
71  $uploader->add_setting('onQueueComplete', "function(event, data){
72  if(total<=0) return;
73  \$('.categories_selector').hide('slow');
74  \$('#upload-errors').hide('slow');
75  \$('#upload-errors').html('');
76  \$('#upload-controls').hide('slow');
77  \$('#resizer-bar').show('slow');
78  \$('#resizer-bar').effect('highlight',{},1000);
79  \$('#gen-thumbnails').show();
80 
81  var increments = 1/total*100;
82  url = '".RMCURL."/images.php".($target!=''?"?taget=$target&amp;id=$container":'')."';
83 
84  params = '".TextCleaner::getInstance()->encrypt($xoopsUser->uid().'|'.RMCURL.'/images.php'.'|'.$xoopsSecurity->createToken(), true)."';
85  resize_image(params);
86 
87  }");
88 
89  RMTemplate::get()->add_head($uploader->render());
90  }
91 
92  $categories = RMFunctions::load_images_categories("WHERE status='open' ORDER BY id_cat DESC", true);
93 
94  RMTemplate::get()->add_style('imgmgr.css', 'rmcommon');
95  RMTemplate::get()->add_style('pagenav.css', 'rmcommon');
96  RMTemplate::get()->add_style('editor_img.css', 'rmcommon');
97  if($type=='tiny' && $target!='container'){
98  RMTemplate::get()->add_script(RMCURL.'/api/editors/tinymce/tiny_mce_popup.js');
99  } elseif($target!='container'&&$type!='external') {
100  RMTemplate::get()->add_head('<script type="text/javascript">var exmPopup = window.parent.'.$en.';</script>');
101  }
102 
103  RMEvents::get()->run_event('rmcommon.loading.editorimages', '');
104 
105  include RMTemplate::get()->get_template('editor_image.php', 'module', 'rmcommon');
106 
107 } elseif($action=='load-images'){
108 
109  $db = XoopsDatabaseFactory::getDatabaseConnection();
110 
111  if (!$xoopsSecurity->check()){
112  _e('Sorry, unauthorized operation!','rmcommon');
113  die();
114  }
115 
116  // Check if some category exists
117  $catnum = RMFunctions::get_num_records("rmc_img_cats");
118  if ($catnum<=0){
119  send_message(__('There are not categories yet! Please create one in order to add images.','rmcommon'));
120  die();
121  }
122 
123  if ($cat->isNew()){
124  send_message(__('You must select a category before','rmcommon'));
125  die();
126  }
127 
128  $sql = "SELECT COUNT(*) FROM ".$db->prefix("rmc_images");
129  if (!$cat->isNew()) $sql .= " WHERE cat='".$cat->id()."'";
133  $page = intval(rmc_server_var($_REQUEST, 'page', 1));
134  $page = $page<=0 ? $page = 1 : $page;
135  $limit = 10;
136  list($num) = $db->fetchRow($db->query($sql));
137 
138  $tpages = ceil($num / $limit);
139  $page = $page > $tpages ? $tpages : $page;
140 
141  $start = $num<=0 ? 0 : ($page - 1) * $limit;
142 
143  $nav = new RMPageNav($num, $limit, $page, 5);
144  $nav->target_url('javascript:;" onclick="show_library({PAGE_NUM});');
145 
146  // Get categories
147  $sql = "SELECT * FROM ".$db->prefix("rmc_images")." ".(!$cat->isNew() ? "WHERE cat='".$cat->id()."'" : '')." ORDER BY id_img DESC LIMIT $start,$limit";
148 
149  $result = $db->query($sql);
150  $images = array();
151  $categories = array();
152  $authors = array();
153 
154  $category = $cat;
155  $sizes = $category->getVar('sizes');
156  $current_size = array();
157 
158  foreach ($sizes as $size){
159  if (empty($current_size)){
160  $current_size = $size;
161  } else {
162  if ($current_size['width']>=$size['width'] && $size['width']>0){
163  $current_size = $size;
164  }
165  }
166  }
167 
168  $mimes = include(XOOPS_ROOT_PATH.'/include/mimetypes.inc.php');
169 
170  while($row = $db->fetchArray($result)){
171  $img = new RMImage();
172  $img->assignVars($row);
173  if (!isset($categories[$img->getVar('cat')])){
174  $categories[$img->getVar('cat')] = new RMImageCategory($img->getVar('cat'));
175  }
176 
177  if (!isset($authors[$img->getVar('uid')])){
178  $authors[$img->getVar('uid')] = new XoopsUser($img->getVar('uid'));
179  }
180 
181  $fd = pathinfo($img->getVar('file'));
182  $filesurl = XOOPS_UPLOAD_URL.'/'.date('Y',$img->getVar('date')).'/'.date('m',$img->getVar('date'));
183 
184  $thumb = date('Y',$img->getVar('date')).'/'.date('m',$img->getVar('date')).'/sizes/'.$fd['filename'].'_'.$current_size['width'].'x'.$current_size['height'].'.'.$fd['extension'];
185  if(!file_exists(XOOPS_UPLOAD_PATH.'/'.$thumb)){
186  $thumb = date('Y',$img->getVar('date')).'/'.date('m',$img->getVar('date')).'/'.$fd['filename'].'.'.$fd['extension'];
187  }
188 
189  $ret = array(
190  'id' => $img->id(),
191  'title' => $img->getVar('title'),
192  'date' => formatTimestamp($img->getVar('date'), 'l'),
193  'desc' => $img->getVar('desc', 'n'),
194  'cat' => $categories[$img->getVar('cat')]->getVar('name'),
195  'author' => $authors[$img->getVar('uid')],
196  'thumb' => XOOPS_UPLOAD_URL.'/'.$thumb,
197  'url' => $filesurl,
198  'file' => $fd['filename'],
199  'extension' => $fd['extension'],
200  'mime' => isset($mimes[$fd['extension']]) ? $mimes[$fd['extension']] : 'application/octet-stream',
201  'links' => array(
202  'file'=>array('caption'=>__('File URL','rmcommon'),'value'=>XOOPS_UPLOAD_URL.'/'.date('Y',$img->getVar('date')).'/'.date('m',$img->getVar('date')).'/'.$img->getVar('file')),
203  'none'=>array('caption'=>__('None','rmcommon'),'value'=>'')
204  )
205  );
206 
207  $images[] = RMEvents::get()->run_event('rmcommon.loading.single.editorimgs', $ret, rmc_server_var($_REQUEST, 'url', ''));
208  }
209 
210  include RMTemplate::get()->get_template('images_list_editor.php','module','rmcommon');
211 
212 }