private function gicon_upload_file()
 {
     $fileElementName = 'wpl_gicon_file';
     $file = wpl_request::getVar($fileElementName, '', 'FILES');
     $ext_array = array('jpg', 'png', 'gif', 'jpeg');
     $error = "";
     $msg = "";
     if (!empty($file['error']) or (empty($file['tmp_name']) or $file['tmp_name'] == 'none')) {
         $error = __("An error occurred uploading your file!", WPL_TEXTDOMAIN);
     } else {
         $extention = strtolower(wpl_file::getExt($file['name']));
         $name = strtolower(wpl_file::stripExt(wpl_file::getName($file['name'])));
         if (!in_array($extention, $ext_array)) {
             $error = __("File extension should be jpg, png or gif", WPL_TEXTDOMAIN);
         }
         /** check the file size **/
         $filesize = @filesize($file['tmp_name']);
         if ($filesize > 500 * 1024) {
             $error .= __("Icons should not be bigger than 500KB!", WPL_TEXTDOMAIN);
             @unlink($file);
         }
         if ($error == "") {
             $dest = WPL_ABSPATH . 'assets' . DS . 'img' . DS . 'listing_types' . DS . 'gicon' . DS . $name . '.' . $extention;
             while (wpl_file::exists($dest)) {
                 $name .= '_copy';
                 $dest = WPL_ABSPATH . 'assets' . DS . 'img' . DS . 'listing_types' . DS . 'gicon' . DS . $name . '.' . $extention;
             }
             wpl_file::upload($file['tmp_name'], $dest);
         }
     }
     $message = '';
     $response = array('error' => $error, 'message' => $message);
     echo json_encode($response);
     exit;
 }
예제 #2
0
 /**
  * added by Francis
  * @param array $file: the array which come from $_FILE
  * description       : save watermark image to the specific path and
  *                     save filename as a setting value to database
  */
 private function save_watermark_image($file)
 {
     $filename = wpl_global::normalize_string($file['name']);
     $ext_array = array('jpg', 'png', 'gif', 'jpeg');
     $error = '';
     $message = '';
     if (!empty($file['error']) or (empty($file['tmp_name']) or $file['tmp_name'] == 'none')) {
         $error = __('An error ocurred uploading your file.', WPL_TEXTDOMAIN);
     } else {
         // check the extention
         $extention = strtolower(wpl_file::getExt($file['name']));
         if (!in_array($extention, $ext_array)) {
             $error = __('File extension should be jpg, png or gif.', WPL_TEXTDOMAIN);
         }
         if ($error == '') {
             $dest = WPL_ABSPATH . 'assets' . DS . 'img' . DS . 'system' . DS . $filename;
             wpl_file::upload($file['tmp_name'], $dest);
             wpl_settings::save_setting('watermark_url', $filename, 2);
         }
     }
     $response = array('error' => $error, 'message' => $message);
     echo json_encode($response);
     exit;
 }
예제 #3
0
 /**
  * Uploads a file and return the results
  * @author Howard <*****@*****.**>
  * @static
  * @param array $file
  * @param string $dest
  * @param array $ext_array
  * @param int $max_file_size
  * @param string $extension
  * @return array
  */
 public static function upload($file, $dest = '', $ext_array = array('jpg', 'png', 'gif', 'jpeg'), $max_file_size = 512000, $extension = NULL)
 {
     $error = '';
     $msg = '';
     if (!empty($file['error']) or (empty($file['tmp_name']) or $file['tmp_name'] == 'none')) {
         $error .= __('An error occurred uploading your file!', WPL_TEXTDOMAIN);
     } else {
         if (is_null($extension)) {
             $extension = strtolower(wpl_file::getExt($file['name']));
         }
         if (!in_array($extension, $ext_array)) {
             $error .= __('File extension is not valid.', WPL_TEXTDOMAIN);
         }
         /** check the file size **/
         $filesize = @filesize($file['tmp_name']);
         if ($filesize > $max_file_size) {
             $error .= __('File size is not valid!', WPL_TEXTDOMAIN);
             @unlink($file);
         }
         /** upload file **/
         if ($error == '') {
             wpl_file::upload($file['tmp_name'], $dest);
         }
     }
     $message = '';
     return array('error' => $error, 'message' => $message);
 }
예제 #4
0
 private function upload_file($file_name, $user_id)
 {
     $file = wpl_request::getVar($file_name, '', 'FILES');
     $filename = $file['name'];
     $ext_array = array('jpg', 'png', 'gif', 'jpeg');
     $error = "";
     $message = "";
     if (!empty($file['error']) or (empty($file['tmp_name']) or $file['tmp_name'] == 'none')) {
         $error = __('An error ocurred uploading your file.', WPL_TEXTDOMAIN);
     } else {
         // check the extention
         $extention = strtolower(wpl_file::getExt($file['name']));
         if (!in_array($extention, $ext_array)) {
             $error = __('File extension should be jpg, png or gif.', WPL_TEXTDOMAIN);
         }
         if ($error == '') {
             if ($file_name == 'wpl_c_912') {
                 /** delete previous file **/
                 self::delete_file(912, $user_id, false);
                 $new_file_name = 'profile.' . $extention;
                 /** save into db and add to items **/
                 wpl_db::set('wpl_users', $user_id, 'profile_picture', $new_file_name);
             } elseif ($file_name == 'wpl_c_913') {
                 /** delete previous file **/
                 self::delete_file(913, $user_id, false);
                 $new_file_name = 'logo.' . $extention;
                 /** save into db and add to items **/
                 wpl_db::set('wpl_users', $user_id, 'company_logo', $new_file_name);
             } else {
                 $new_file_name = $filename;
             }
             $dest = wpl_items::get_path($user_id, 2) . $new_file_name;
             wpl_file::upload($file['tmp_name'], $dest);
         }
     }
     $res = 1;
     $message = $res ? __('Saved.', WPL_TEXTDOMAIN) : __('Error Occured.', WPL_TEXTDOMAIN);
     $data = NULL;
     $response = array('error' => $error, 'message' => $message);
     echo json_encode($response);
     exit;
 }
예제 #5
0
 /**
  * Import Settings from a file
  * @author Steve A. <*****@*****.**>
  * @static
  * @param  string  $file Settings File
  * @return boolean		 Result
  */
 public static function import_settings($file)
 {
     $content = wpl_file::read($file);
     $ext = wpl_file::getExt($file);
     if ($ext == 'json') {
         $settings = json_decode($content);
         if (!$settings) {
             return false;
         }
     } elseif ($ext == 'xml') {
         $settings = simplexml_load_string($content);
         if (!$settings) {
             return false;
         }
         $settings = (array) $settings;
     } else {
         return false;
     }
     foreach ($settings as $name => $value) {
         self::update_setting($name, $value);
     }
     return true;
 }
예제 #6
0
 /**
  * Creates profile image
  * @author Howard <*****@*****.**>
  * @param string $source
  * @param int $width
  * @param int $height
  * @param array $params
  * @param int $watermark
  * @param int $rewrite
  * @param int $crop
  * description: resize and watermark images specially
  */
 public static function create_profile_images($source, $width, $height, $params, $watermark = 0, $rewrite = 0, $crop = '')
 {
     /** first validation **/
     if (!trim($source)) {
         return NULL;
     }
     $image_name = wpl_file::stripExt($params['image_name']);
     $image_ext = wpl_file::getExt($params['image_name']);
     $resized_image_name = 'th' . $image_name . '_' . $width . 'x' . $height . '.' . $image_ext;
     $image_dest = wpl_items::get_path($params['image_parentid'], 2) . $resized_image_name;
     $image_url = wpl_items::get_folder($params['image_parentid'], 2) . $resized_image_name;
     /** check resized files existance and rewrite option **/
     if ($rewrite or !wpl_file::exists($image_dest)) {
         if ($watermark) {
             self::resize_watermark_image($source, $image_dest, $width, $height);
         } else {
             self::resize_image($source, $image_dest, $width, $height, $crop);
         }
     }
     return $image_url;
 }