/src/modules/tools/control.php
PHP | 251 lines | 163 code | 68 blank | 20 comment | 23 complexity | f09c2775ccb7de434cf643e20970e374 MD5 | raw file
Possible License(s): MIT, CC0-1.0
- <?php
- /**
- * textMotion
- * ---
- * Written by Jose Carlos Nieto <xiam@menteslibres.org>
- * Copyright (c) 2007-2008, Jose Carlos Nieto <xiam@menteslibres.org>
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice.
- *
- * @author Jose Carlos Nieto <xiam@menteslibres.org>
- * @package textMotion
- * @copyright Copyright (c) 2007-2008, J. Carlos Nieto <xiam@menteslibres.org>
- * @link http://www.textmotion.org
- * @version $Revision: 1416 $
- * @modifiedby $LastChangedBy: xiam.core $
- * @lastmodified $Date: 2008-10-29 10:41:55 +1100 (Wed, 29 Oct 2008) $
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
- *
- */
- class tools_control extends tm_control {
-
- private function sort(&$data) {
- usort($data, array($this, '_sort'));
- }
- private function _sort($a, $b) {
- return ($b['mtime'] - $a['mtime']);
- }
- public function blank() {
- $this->layout = 'misc/blank';
- }
- public function ajax_emoticons() {
- extract(
- $this->using(
- 'param',
- 'conf'
- )
- );
-
- $theme = $conf->get('core/emoticon_theme', 'default', 's');
- $inifile = TM_MEDIA_DIR.'emoticons'.DS.$theme.DS.'theme.ini';
- $icons = array();
- if (file_exists($inifile)) {
- $data = parse_ini_file($inifile, array('theme', 'icons'));
- if (!empty($data['icons'])) {
- foreach($data['icons'] as $icon => $pattern) {
- $pattern = explode(' ', $pattern);
- $pattern = $pattern[0];
- $icons[] = array(
- 'text' => $pattern,
- 'url' => TM_BASE_URL.'media/emoticons/'.$theme.'/'.$icon.'.'.$data['theme']['extension'],
- 'width' => $data['theme']['width'],
- 'height' => $data['theme']['height']
- );
- }
- }
- }
- $param->set('icons', $icons);
- }
- public function operator_ajax_file() {
- extract(
- $this->using(
- 'param',
- 'cache',
- 'conf',
- 'json'
- )
- );
- $file = $param->get('file');
- if ($file) {
- $file = preg_replace('/\.\./', '', $file);
- $file = preg_replace('/\/+/', '/', $file);
- if (preg_match('/^\/data\/.+/', $file)) {
- $path = TM_USER_DIR.ltrim($file, DS);
- if (file_exists($path) && is_file($path)) {
- $files_model =& $this->load_model('files');
-
- $info = $files_model->file_info($path);
-
- $param->set('link', $file);
- if ($info['mime'] == 'image/x-generic') {
- $param->set('is_image', true);
- $size = getimagesize($path);
- //$longest_side = $conf->get('core/editor.image_longest_side', 300, 'i');
- $longest_side = 280;
- $width = $size[0];
- $height = $size[1];
-
- $min = $width;
- if ($height < $min) {
- $min = $height;
- }
-
- if ($longest_side > $min) {
- $longest_side = $min;
- }
- $param->set('orig_width', $width);
- $param->set('orig_height', $height);
- $max = ($width > $height) ? $width : $height;
- $factor = 1;
- if ($max > $longest_side) {
- $factor = $longest_side/$max;
- }
- $width = ceil($factor*$width);
- $height = ceil($factor*$height);
- $param->set('width', $width);
- $param->set('height', $height);
- $param->set('max', $max);
- $param->set('longest_side', $longest_side);
- }
-
- $param->set('path', $path);
- $param->set('info', $info);
- }
- }
- }
- }
- public function auto_save() {
- $this->layout = 'misc/ajax';
- extract(
- $this->using(
- 'param',
- 'cache',
- 'json'
- )
- );
- $cache = new cache($this->model->auto_save_key(), 3600*24, 'auto_save', true);
- if ($cache->is_valid()) {
- $data = $cache->get('data');
- $cache->clear();
- $json->response(
- array(
- 'data' => $data
- )
- );
- } else {
- $json->response(null);
- }
- }
- private function set_editor() {
- $param =& $this->using('param');
- $param->map('/editor=int');
- $param->set('editor', intval($param->get('editor')));
- }
-
- public function operator_ajax_insert() {
- $this->set_editor();
- }
-
- public function operator_ajax_upload() {
- $this->set_editor();
- }
-
- public function operator_ajax_reset() {
- $this->set_editor();
- }
- public function operator_ajax_recent() {
- extract(
- $this->using(
- 'db',
- 'param',
- 'archive'
- )
- );
- $files_model =& $this->load_model('files');
- $items = $galleries = array();
- $param->map('/editor=int?path=string');
- $param->set('editor', (int)$param->get('editor'));
- $path = $param->get('path');
- $path = rtrim($path, '/').'/';
- if (!preg_match('/^\/files\/.*/', $path)) {
- $path = '/uploads/';
- }
-
- $param->set('path', $path);
- $files = array();
- if ($archive->secure_path(TM_DATA_DIR, $path) && file_exists(TM_DATA_DIR.$path) && is_dir(TM_DATA_DIR.$path)) {
-
- $full_path = TM_DATA_DIR.$path;
- $dh = opendir($full_path);
- while (($file = readdir($dh)) !== false) {
- if ($file != '.' && $file != '..') {
- $file = $files_model->file_info($full_path.'/'.$file);
- if (!$file['type']['dir']) {
- $files[] = $file;
- }
- }
- }
- closedir($dh);
- }
- $this->sort($files);
-
- $param->set('files', $files);
- }
- }
- ?>