public function __construct()
 {
     $options = array('reference' => APPPATH . 'views/articles');
     parent::__construct($options);
 }
Example #2
0
 public function __construct()
 {
     $options = array('reference' => './modules/images');
     parent::__construct($options);
 }
 public function __construct()
 {
     $options = array('reference' => APPPATH . 'language');
     parent::__construct($options);
 }
Example #4
0
 /**
  * Register Edited image
  *
  * @access	private
  * @param   integer $id File ID (if 0 then is a new item)
  * @param   array 	$_post _POST array
  * @return  void
  */
 private function saving($id_file, $_post)
 {
     $msg = null;
     // check permissions
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'files', $id_file, 2);
     if (is_null($msg)) {
         $ko = _MSG_ERROR;
         // check if set asnew
         $asnew = intval(isset($_post['asnew']));
         $mod = new File_model();
         $file = $mod->get_by_id($id_file);
         if ($file) {
             switch ($file->xtype) {
                 case 0:
                     // images
                     $path = APATH . 'files/filemanager/img/';
                     $rotation = intval($_post['rotate']);
                     $rotation = $rotation ? 360 - $rotation : 0;
                     if ($asnew) {
                         // save a new file
                         // set the new name
                         $final_name = X4Files_helper::get_final_name($path, $file->name);
                         $chk = X4Files_helper::create_cropped($path . $file->name, $path . $final_name, array($_post['width'], $_post['height']), array($_post['xcoord'], $_post['ycoord']), true);
                         if ($chk) {
                             $post = array();
                             $post[] = array('id_area' => $file->id_area, 'xtype' => $file->xtype, 'category' => $file->category, 'subcategory' => $file->subcategory, 'name' => $final_name, 'alt' => $file->alt, 'xon' => 1);
                             // insert
                             $result = $mod->insert_file($post);
                             // create permissions
                             if ($result[1]) {
                                 $id = $result[0];
                                 $perm = new Permission_model();
                                 // privs permissions
                                 $array[] = array('action' => 'insert', 'id_what' => $id, 'id_user' => $_SESSION['xuid'], 'level' => 4);
                                 $res = $perm->pexec('files', $array, $file->id_area);
                                 if ($rotation) {
                                     sleep(1);
                                     $res = X4Files_helper::rotate($path . $final_name, $path . $final_name, $rotation);
                                 }
                             }
                         } else {
                             $result = array($_post['id'], intval($chk));
                         }
                     } else {
                         // replace old
                         $chk = X4Files_helper::create_cropped($path . $file->name, $path . $file->name, array($_post['width'], $_post['height']), array($_post['xcoord'], $_post['ycoord']), true);
                         if ($chk && $rotation) {
                             sleep(1);
                             $res = X4Files_helper::rotate($path . $file->name, $path . $file->name, $rotation);
                         }
                         $result = array($_post['id'], intval($chk));
                         $id = $file->id;
                     }
                     break;
                 case 1:
                     // generic text file
                     $path = APATH . 'files/filemanager/files/';
                     $txt = $_post['content'];
                     $res = file_put_contents($path . $file->name, $txt);
                     $id = $id_file;
                     $result = array($id, intval($res));
                     break;
                 case 2:
                     // video file
                     // get the command, if exists
                     $ffmpeg = str_replace(NL, '', $this->command_exist('ffmpeg'));
                     if (!empty($ffmpeg)) {
                         $file_name = $file->name;
                         $mimes = array('video/quicktime' => 'mov', 'video/mp4' => 'mp4', 'video/webm' => 'webm', 'video/ogg' => 'ogv', 'application/ogg' => 'ogv', 'video/x-flv' => 'flv', 'video/avi' => 'avi', 'application/vnd.adobe.flash.movie' => 'swf', 'application/x-shockwave-flash' => 'swf');
                         if (isset($_post['capture'])) {
                             // we have to extract a frame
                             $vpath = APATH . 'files/filemanager/media/';
                             $ipath = APATH . 'files/filemanager/img/';
                             $file_name = str_replace($mimes[$_post['old_format']], 'jpg', $file_name);
                             // set the new name
                             $final_name = X4Files_helper::get_final_name($ipath, $file_name);
                             //ffmpeg -i video_file -an -ss 27.888237 -vframes 1 -s 320x240 -f image2 image_file
                             $chk = shell_exec($ffmpeg . ' -i ' . $vpath . $file->name . ' -an -ss ' . $_post['sec'] . ' -vframes 1 -s ' . $_post['iwidth'] . 'x' . $_post['iheight'] . ' -f image2 ' . $ipath . $final_name . ' 2>&1');
                             if ($chk && file_exists($ipath . $final_name)) {
                                 chmod($ipath . $final_name, 0777);
                                 $post = array();
                                 $post[] = array('id_area' => $file->id_area, 'xtype' => 0, 'category' => $file->category, 'subcategory' => $file->subcategory, 'name' => $final_name, 'alt' => $file->alt, 'xon' => 1);
                                 // insert
                                 $result = $mod->insert_file($post);
                                 // create permissions
                                 if ($result[1]) {
                                     $id = $result[0];
                                     $perm = new Permission_model();
                                     // privs permissions
                                     $array[] = array('action' => 'insert', 'id_what' => $id, 'id_user' => $_SESSION['xuid'], 'level' => 4);
                                     $res = $perm->pexec('files', $array, $file->id_area);
                                 }
                             }
                         } else {
                             // is a video conversion
                             $path = APATH . 'files/filemanager/media/';
                             $new_format = $new_size = 0;
                             if ($_post['old_width'] != $_post['width'] || $_post['old_height'] != $_post['height']) {
                                 $new_size = 1;
                             }
                             // if new format is a new file
                             if ($_post['old_format'] != $_post['format']) {
                                 $new_format = 1;
                                 $file_name = str_replace($mimes[$_post['old_format']], $mimes[$_post['format']], $file_name);
                             }
                             if ($asnew || $new_format) {
                                 // save a new file
                                 // set the new name
                                 $final_name = X4Files_helper::get_final_name($path, $file_name);
                                 if ($new_size) {
                                     $chk = shell_exec($ffmpeg . ' -i ' . $path . $file->name . ' -vf scale=' . $_post['width'] . ':' . $_post['height'] . ' ' . $path . $final_name . ' 2>&1');
                                 } else {
                                     // -c:a copy
                                     $chk = shell_exec($ffmpeg . ' -i ' . $path . $file->name . ' ' . $path . $final_name . ' 2>&1');
                                 }
                                 if ($chk) {
                                     chmod($path . $final_name, 0777);
                                     $post = array();
                                     $post[] = array('id_area' => $file->id_area, 'xtype' => $file->xtype, 'category' => $file->category, 'subcategory' => $file->subcategory, 'name' => $final_name, 'alt' => $file->alt, 'xon' => 1);
                                     // insert
                                     $result = $mod->insert_file($post);
                                     // create permissions
                                     if ($result[1]) {
                                         $id = $result[0];
                                         $perm = new Permission_model();
                                         // privs permissions
                                         $array[] = array('action' => 'insert', 'id_what' => $id, 'id_user' => $_SESSION['xuid'], 'level' => 4);
                                         $res = $perm->pexec('files', $array, $file->id_area);
                                     }
                                 }
                             } else {
                                 // replace old
                                 if ($new_size) {
                                     $chk = shell_exec($ffmpeg . ' -i ' . $path . $file->name . ' -vf scale=' . $_post['width'] . ':' . $_post['height'] . ' ' . $path . $file->name . ' 2>&1');
                                 } else {
                                     $chk = 1;
                                 }
                                 $result = array($_post['id'], intval($chk));
                                 $id = $result[0];
                             }
                         }
                     } else {
                         // ffmpeg not available
                         $result = array(0, 0);
                         $ko = _FFMPEG_NOT_FOUND;
                     }
                     break;
                 case 3:
                     // template
                     $path = APATH . 'files/filemanager/template/';
                     if (extension_loaded('php5-tidy')) {
                         // clean the code
                         $tidy = tidy_parse_string($_post['content']);
                         $tidy->cleanRepair();
                         $html = $tidy->html();
                     } else {
                         $html = $_post['content'];
                     }
                     $res = file_put_contents($path . $file->name, $html);
                     $id = $id_file;
                     $result = array($id, intval($res));
                     break;
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result, _MSG_OK, $ko);
             // set what update
             if ($result[1]) {
                 $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'files/editor/' . $id, 'title' => null);
             }
         } else {
             // file not found
             // set message
             $msg = AdmUtils_helper::set_msg(array(0, 0));
         }
     }
     $this->response($msg);
 }