PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/modules/tools/control.php

http://textmotion.googlecode.com/
PHP | 251 lines | 163 code | 68 blank | 20 comment | 23 complexity | f09c2775ccb7de434cf643e20970e374 MD5 | raw file
Possible License(s): MIT, CC0-1.0
  1. <?php
  2. /**
  3. * textMotion
  4. * ---
  5. * Written by Jose Carlos Nieto <xiam@menteslibres.org>
  6. * Copyright (c) 2007-2008, Jose Carlos Nieto <xiam@menteslibres.org>
  7. *
  8. * Licensed under The MIT License
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @author Jose Carlos Nieto <xiam@menteslibres.org>
  12. * @package textMotion
  13. * @copyright Copyright (c) 2007-2008, J. Carlos Nieto <xiam@menteslibres.org>
  14. * @link http://www.textmotion.org
  15. * @version $Revision: 1416 $
  16. * @modifiedby $LastChangedBy: xiam.core $
  17. * @lastmodified $Date: 2008-10-29 10:41:55 +1100 (Wed, 29 Oct 2008) $
  18. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  19. *
  20. */
  21. class tools_control extends tm_control {
  22. private function sort(&$data) {
  23. usort($data, array($this, '_sort'));
  24. }
  25. private function _sort($a, $b) {
  26. return ($b['mtime'] - $a['mtime']);
  27. }
  28. public function blank() {
  29. $this->layout = 'misc/blank';
  30. }
  31. public function ajax_emoticons() {
  32. extract(
  33. $this->using(
  34. 'param',
  35. 'conf'
  36. )
  37. );
  38. $theme = $conf->get('core/emoticon_theme', 'default', 's');
  39. $inifile = TM_MEDIA_DIR.'emoticons'.DS.$theme.DS.'theme.ini';
  40. $icons = array();
  41. if (file_exists($inifile)) {
  42. $data = parse_ini_file($inifile, array('theme', 'icons'));
  43. if (!empty($data['icons'])) {
  44. foreach($data['icons'] as $icon => $pattern) {
  45. $pattern = explode(' ', $pattern);
  46. $pattern = $pattern[0];
  47. $icons[] = array(
  48. 'text' => $pattern,
  49. 'url' => TM_BASE_URL.'media/emoticons/'.$theme.'/'.$icon.'.'.$data['theme']['extension'],
  50. 'width' => $data['theme']['width'],
  51. 'height' => $data['theme']['height']
  52. );
  53. }
  54. }
  55. }
  56. $param->set('icons', $icons);
  57. }
  58. public function operator_ajax_file() {
  59. extract(
  60. $this->using(
  61. 'param',
  62. 'cache',
  63. 'conf',
  64. 'json'
  65. )
  66. );
  67. $file = $param->get('file');
  68. if ($file) {
  69. $file = preg_replace('/\.\./', '', $file);
  70. $file = preg_replace('/\/+/', '/', $file);
  71. if (preg_match('/^\/data\/.+/', $file)) {
  72. $path = TM_USER_DIR.ltrim($file, DS);
  73. if (file_exists($path) && is_file($path)) {
  74. $files_model =& $this->load_model('files');
  75. $info = $files_model->file_info($path);
  76. $param->set('link', $file);
  77. if ($info['mime'] == 'image/x-generic') {
  78. $param->set('is_image', true);
  79. $size = getimagesize($path);
  80. //$longest_side = $conf->get('core/editor.image_longest_side', 300, 'i');
  81. $longest_side = 280;
  82. $width = $size[0];
  83. $height = $size[1];
  84. $min = $width;
  85. if ($height < $min) {
  86. $min = $height;
  87. }
  88. if ($longest_side > $min) {
  89. $longest_side = $min;
  90. }
  91. $param->set('orig_width', $width);
  92. $param->set('orig_height', $height);
  93. $max = ($width > $height) ? $width : $height;
  94. $factor = 1;
  95. if ($max > $longest_side) {
  96. $factor = $longest_side/$max;
  97. }
  98. $width = ceil($factor*$width);
  99. $height = ceil($factor*$height);
  100. $param->set('width', $width);
  101. $param->set('height', $height);
  102. $param->set('max', $max);
  103. $param->set('longest_side', $longest_side);
  104. }
  105. $param->set('path', $path);
  106. $param->set('info', $info);
  107. }
  108. }
  109. }
  110. }
  111. public function auto_save() {
  112. $this->layout = 'misc/ajax';
  113. extract(
  114. $this->using(
  115. 'param',
  116. 'cache',
  117. 'json'
  118. )
  119. );
  120. $cache = new cache($this->model->auto_save_key(), 3600*24, 'auto_save', true);
  121. if ($cache->is_valid()) {
  122. $data = $cache->get('data');
  123. $cache->clear();
  124. $json->response(
  125. array(
  126. 'data' => $data
  127. )
  128. );
  129. } else {
  130. $json->response(null);
  131. }
  132. }
  133. private function set_editor() {
  134. $param =& $this->using('param');
  135. $param->map('/editor=int');
  136. $param->set('editor', intval($param->get('editor')));
  137. }
  138. public function operator_ajax_insert() {
  139. $this->set_editor();
  140. }
  141. public function operator_ajax_upload() {
  142. $this->set_editor();
  143. }
  144. public function operator_ajax_reset() {
  145. $this->set_editor();
  146. }
  147. public function operator_ajax_recent() {
  148. extract(
  149. $this->using(
  150. 'db',
  151. 'param',
  152. 'archive'
  153. )
  154. );
  155. $files_model =& $this->load_model('files');
  156. $items = $galleries = array();
  157. $param->map('/editor=int?path=string');
  158. $param->set('editor', (int)$param->get('editor'));
  159. $path = $param->get('path');
  160. $path = rtrim($path, '/').'/';
  161. if (!preg_match('/^\/files\/.*/', $path)) {
  162. $path = '/uploads/';
  163. }
  164. $param->set('path', $path);
  165. $files = array();
  166. if ($archive->secure_path(TM_DATA_DIR, $path) && file_exists(TM_DATA_DIR.$path) && is_dir(TM_DATA_DIR.$path)) {
  167. $full_path = TM_DATA_DIR.$path;
  168. $dh = opendir($full_path);
  169. while (($file = readdir($dh)) !== false) {
  170. if ($file != '.' && $file != '..') {
  171. $file = $files_model->file_info($full_path.'/'.$file);
  172. if (!$file['type']['dir']) {
  173. $files[] = $file;
  174. }
  175. }
  176. }
  177. closedir($dh);
  178. }
  179. $this->sort($files);
  180. $param->set('files', $files);
  181. }
  182. }
  183. ?>