PageRenderTime 69ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/rmcommon/tags/rmcommon-2.0.95/include/tiny-images.php

http://bitcero-modules.googlecode.com/
PHP | 205 lines | 155 code | 37 blank | 13 comment | 18 complexity | 84201bb87b48d78c81a248a7e2a7dee7 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. // $Id: tiny-images.php 511 2010-07-26 06:08:44Z 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. include '../../../mainfile.php';
  11. XoopsLogger::getInstance()->activated = false;
  12. XoopsLogger::getInstance()->renderingEnabled = false;
  13. function send_message($message){
  14. global $xoopsSecurity;
  15. echo $message;
  16. echo '<input type="hidden" id="ret-token" value="'.$xoopsSecurity->createToken().'" />';
  17. die();
  18. }
  19. $category = rmc_server_var($_POST,'category', 0);
  20. $action = rmc_server_var($_POST,'action', '');
  21. $cat = new RMImageCategory($category);
  22. $type = rmc_server_var($_REQUEST, 'type', 'tiny');
  23. $en = rmc_server_var($_REQUEST, 'name', '');
  24. if ($action==''){
  25. RMTemplate::get()->add_script(RMCURL.'/include/js/jquery.min.js');
  26. RMTemplate::get()->add_script(RMCURL.'/include/js/jquery-ui.min.js');
  27. RMTemplate::get()->add_script(RMCURL.'/include/js/images_editor.js');
  28. if (!$cat->isNew()){
  29. $uploader = new RMFlashUploader('files-container', 'upload.php');
  30. $uploader->add_setting('scriptData', array(
  31. 'action'=>'upload',
  32. 'category'=>$cat->id(),
  33. 'rmsecurity'=>TextCleaner::getInstance()->encrypt($xoopsUser->uid().'|'.RMCURL.'/images.php'.'|'.$xoopsSecurity->createToken(), true))
  34. );
  35. $uploader->add_setting('multi', true);
  36. $uploader->add_setting('fileExt', '*.jpg;*.png;*.gif');
  37. $uploader->add_setting('fileDesc', __('All Images (*.jpg, *.png, *.gif)','rmcommon'));
  38. $uploader->add_setting('sizeLimit', $cat->getVar('filesize') * $cat->getVar('sizeunit'));
  39. $uploader->add_setting('buttonText', __('Browse Images...','rmcommon'));
  40. $uploader->add_setting('queueSizeLimit', 100);
  41. $uploader->add_setting('auto', true);
  42. $uploader->add_setting('onSelect', "function(event, qid, file){
  43. if (queuefiles[qid]) return false;
  44. queuefiles[qid] = true;
  45. return true;
  46. }");
  47. $uploader->add_setting('onComplete',"function(event, id, file, resp, data){
  48. eval('ret = '+resp);
  49. if (ret.error){
  50. \$('#upload-errors').append('<span class=\"failed\"><strong>'+file.name+'</strong>: '+ret.message+'</span>');
  51. } else {
  52. total++;
  53. ids[total-1] = ret.id;
  54. \$('#upload-errors').append('<span class=\"done\"><strong>'+file.name+'</strong>: ".__('Uploaded successfully!','rmcommon')."</span>');
  55. }
  56. return true;
  57. }");
  58. $uploader->add_setting('onAllComplete', "function(event, data){
  59. if(total<=0) return;
  60. \$('.categories_selector').hide('slow');
  61. \$('#upload-errors').hide('slow');
  62. \$('#upload-errors').html('');
  63. \$('#upload-controls').hide('slow');
  64. \$('#resizer-bar').show('slow');
  65. \$('#resizer-bar').effect('highlight',{},1000);
  66. \$('#gen-thumbnails').show();
  67. var increments = 1/total*100;
  68. url = '".RMCURL."/images.php';
  69. params = '".TextCleaner::getInstance()->encrypt($xoopsUser->uid().'|'.RMCURL.'/images.php'.'|'.$xoopsSecurity->createToken(), true)."';
  70. resize_image(params);
  71. }");
  72. $uploader->add_setting('onSelectOnce', "function(event, data){
  73. \$('#upload-errors').html('');
  74. }");
  75. RMTemplate::get()->add_head($uploader->render());
  76. }
  77. $categories = RMFunctions::load_images_categories("WHERE status='open' ORDER BY id_cat DESC", true);
  78. RMTemplate::get()->add_style('imgmgr.css', 'rmcommon');
  79. RMTemplate::get()->add_style('pagenav.css', 'rmcommon');
  80. RMTemplate::get()->add_style('editor_img.css', 'rmcommon');
  81. if($type=='tiny'){
  82. RMTemplate::get()->add_script(RMCURL.'/api/editors/tinymce/tiny_mce_popup.js');
  83. } else {
  84. RMTemplate::get()->add_head('<script type="text/javascript">var exmPopup = window.parent.'.$en.';</script>');
  85. }
  86. RMEvents::get()->run_event('rmcommon.loading_editorimages', '');
  87. include RMTemplate::get()->get_template('editor_image.php', 'module', 'rmcommon');
  88. } elseif($action=='load-images'){
  89. $db = Database::getInstance();
  90. if (!$xoopsSecurity->check()){
  91. _e('Sorry, unauthorized operation!','rmcommon');
  92. die();
  93. }
  94. // Check if some category exists
  95. $catnum = RMFunctions::get_num_records("rmc_img_cats");
  96. if ($catnum<=0){
  97. send_message(__('There are not categories yet! Please create one in order to add images.','rmcommon'));
  98. die();
  99. }
  100. if ($cat->isNew()){
  101. send_message(__('You must select a category before','rmcommon'));
  102. die();
  103. }
  104. $sql = "SELECT COUNT(*) FROM ".$db->prefix("rmc_images");
  105. if (!$cat->isNew()) $sql .= " WHERE cat='".$cat->id()."'";
  106. /**
  107. * Paginacion de Resultados
  108. */
  109. $page = intval(rmc_server_var($_REQUEST, 'page', 1));
  110. $page = $page<=0 ? $page = 1 : $page;
  111. $limit = 10;
  112. list($num) = $db->fetchRow($db->query($sql));
  113. $tpages = ceil($num / $limit);
  114. $page = $page > $tpages ? $tpages : $page;
  115. $start = $num<=0 ? 0 : ($page - 1) * $limit;
  116. $nav = new RMPageNav($num, $limit, $page, 5);
  117. $nav->target_url('javascript:;" onclick="show_library({PAGE_NUM});');
  118. // Get categories
  119. $sql = "SELECT * FROM ".$db->prefix("rmc_images")." ".(!$cat->isNew() ? "WHERE cat='".$cat->id()."'" : '')." ORDER BY id_img DESC LIMIT $start,$limit";
  120. $result = $db->query($sql);
  121. $images = array();
  122. $categories = array();
  123. $authors = array();
  124. $category = $cat;
  125. $sizes = $category->getVar('sizes');
  126. $current_size = array();
  127. foreach ($sizes as $size){
  128. if (empty($current_size)){
  129. $current_size = $size;
  130. } else {
  131. if ($current_size['width']>=$size['width'] && $size['width']>0){
  132. $current_size = $size;
  133. }
  134. }
  135. }
  136. $mimes = include(XOOPS_ROOT_PATH.'/include/mimetypes.inc.php');
  137. while($row = $db->fetchArray($result)){
  138. $img = new RMImage();
  139. $img->assignVars($row);
  140. if (!isset($categories[$img->getVar('cat')])){
  141. $categories[$img->getVar('cat')] = new RMImageCategory($img->getVar('cat'));
  142. }
  143. if (!isset($authors[$img->getVar('uid')])){
  144. $authors[$img->getVar('uid')] = new XoopsUser($img->getVar('uid'));
  145. }
  146. $fd = pathinfo($img->getVar('file'));
  147. $filesurl = XOOPS_UPLOAD_URL.'/'.date('Y',$img->getVar('date')).'/'.date('m',$img->getVar('date'));
  148. $ret = array(
  149. 'id' => $img->id(),
  150. 'title' => $img->getVar('title'),
  151. 'date' => formatTimestamp($img->getVar('date'), 'l'),
  152. 'desc' => $img->getVar('desc', 'n'),
  153. 'cat' => $categories[$img->getVar('cat')]->getVar('name'),
  154. 'author' => $authors[$img->getVar('uid')],
  155. 'thumb' => XOOPS_UPLOAD_URL.'/'.date('Y',$img->getVar('date')).'/'.date('m',$img->getVar('date')).'/sizes/'.$fd['filename'].'_'.$current_size['width'].'x'.$current_size['height'].'.'.$fd['extension'],
  156. 'url' => $filesurl,
  157. 'file' => $fd['filename'],
  158. 'extension' => $fd['extension'],
  159. 'mime' => isset($mimes[$fd['extension']]) ? $mimes[$fd['extension']] : 'application/octet-stream',
  160. 'links' => array(
  161. 'file'=>array('caption'=>__('File URL','rmcommon'),'value'=>XOOPS_UPLOAD_URL.'/'.date('Y',$img->getVar('date')).'/'.date('m',$img->getVar('date')).'/'.$img->getVar('file')),
  162. 'none'=>array('caption'=>__('None','rmcommon'),'value'=>'')
  163. )
  164. );
  165. $images[] = RMEvents::get()->run_event('rmcommon.loading.single.editorimgs', $ret, rmc_server_var($_REQUEST, 'url', ''));
  166. }
  167. include RMTemplate::get()->get_template('images_list_editor.php','module','rmcommon');
  168. }