Example #1
0
 /**
  * Uninstalling WPL
  * @author Howard <*****@*****.**>
  * @return boolean
  */
 public function uninstall_wpl()
 {
     $tables = wpl_db::select('SHOW TABLES');
     $database = wpl_db::get_DBO();
     foreach ($tables as $table_name => $table) {
         if (strpos($table_name, $database->prefix . 'wpl_') !== false) {
             /** drop table **/
             wpl_db::q("DROP TABLE `{$table_name}`");
         }
     }
     /** delete options **/
     wpl_db::q("DELETE FROM `#__options` WHERE `option_name` LIKE 'wpl_%' AND `option_name` NOT LIKE 'wpl_theme%'", 'delete');
     /** remove WPL upload directory **/
     if (function_exists('is_multisite') and is_multisite() and wpl_global::check_addon('multisite')) {
         $original_blog_id = wpl_global::get_current_blog_id();
         // Get all blogs
         $blogs = wpl_db::select("SELECT `blog_id` FROM `#__blogs`", 'loadColumn');
         foreach ($blogs as $blog) {
             if (!isset($blog->blog_id)) {
                 continue;
             }
             switch_to_blog($blog->blog_id);
             $upload_path = wpl_global::get_upload_base_path($blog->blog_id);
             if (wpl_folder::exists($upload_path)) {
                 wpl_folder::delete($upload_path);
             }
         }
         switch_to_blog($original_blog_id);
     } else {
         $upload_path = wpl_global::get_upload_base_path();
         if (wpl_file::exists($upload_path)) {
             wpl_file::delete($upload_path);
         }
     }
     return true;
 }
Example #2
0
 /**
  * Removes user thumbnails
  * @author Howard R <*****@*****.**>
  * @static
  * @param int $user_id
  * @return boolean
  */
 public static function remove_thumbnails($user_id)
 {
     /** first validation **/
     if (!trim($user_id)) {
         return false;
     }
     $ext_array = array('jpg', 'jpeg', 'gif', 'png');
     $path = wpl_items::get_path($user_id, 2);
     $thumbnails = wpl_folder::files($path, 'th.*\\.(' . implode('|', $ext_array) . ')$', 3, true);
     foreach ($thumbnails as $thumbnail) {
         wpl_file::delete($thumbnail);
     }
     return true;
 }
Example #3
0
 /**
  * Deletes a file
  * @author Howard R <*****@*****.**>
  * @static
  * @param string $file_name
  * @param int $parent_id
  * @param int $kind
  * @return boolean
  */
 public static function delete_file($file_name, $parent_id, $kind = 0)
 {
     if (!trim($file_name) or !trim($parent_id)) {
         return false;
     }
     $query = "DELETE FROM `#__wpl_items` WHERE `parent_kind`='{$kind}' AND `parent_id`='{$parent_id}' AND `item_name`='{$file_name}'";
     $affected_rows = wpl_db::q($query, 'delete');
     $folder = wpl_items::get_path($parent_id, $kind);
     if (wpl_file::exists($folder . $file_name)) {
         wpl_file::delete($folder . $file_name);
         if (wpl_file::exists($folder . 'thumbnail' . DS . $file_name)) {
             wpl_file::delete($folder . 'thumbnail' . DS . $file_name);
         }
     }
     /** trigger event **/
     wpl_global::event_handler('item_deleted', array('file_name' => $file_name, 'parent_id' => $parent_id));
     return true;
 }
Example #4
0
 /**
  * Run a SQL Query file
  * @author Howard <*****@*****.**>
  * @static
  * @param string $sql_file
  * @param boolean $delete
  * @param boolean $exception
  * @return boolean
  */
 public static function do_file_queries($sql_file, $delete = false, $exception = false)
 {
     if (!wpl_file::exists($sql_file)) {
         return false;
     }
     $read_file = wpl_file::read($sql_file);
     if ($read_file != '') {
         $read_file = str_replace(";\r\n", "-=++=-", $read_file);
         $read_file = str_replace(";\r", "-=++=-", $read_file);
         $read_file = str_replace(";\n", "-=++=-", $read_file);
         $list_query = explode("-=++=-", $read_file);
         for ($i = 0; $i < count($list_query); $i++) {
             if (trim($list_query[$i]) == '') {
                 continue;
             }
             $query = $list_query[$i];
             if ($exception) {
                 wpl_db::q($query);
             } else {
                 try {
                     wpl_db::q($query);
                 } catch (Exception $e) {
                 }
             }
         }
     }
     if ($delete) {
         wpl_file::delete($sql_file);
     }
     return true;
 }
Example #5
0
 /**
  * Delete a folder.
  * @author Howard <*****@*****.**>
  * @param string $path
  * @return boolean
  */
 public static function delete($path)
 {
     @set_time_limit(ini_get('max_execution_time'));
     // Sanity check
     if (!$path) {
         return false;
     }
     // Check to make sure the path valid and clean
     $path = wpl_path::clean($path);
     // Is this really a folder?
     if (!is_dir($path)) {
         return false;
     }
     // Remove all the files in folder if they exist; disable all filtering
     $files = self::files($path, '.', false, true, array(), array());
     if (!empty($files)) {
         if (wpl_file::delete($files) !== true) {
             return false;
         }
     }
     // Remove sub-folders of folder; disable all filtering
     $folders = self::folders($path, '.', false, true, array(), array());
     foreach ($folders as $folder) {
         if (is_link($folder)) {
             if (wpl_file::delete($folder) !== true) {
                 return false;
             }
         } elseif (self::delete($folder) !== true) {
             return false;
         }
     }
     // In case of restricted permissions we zap it one way or the other
     // as long as the owner is either the webserver or the ftp.
     if (@rmdir($path)) {
         $ret = true;
     } else {
         $ret = false;
     }
     return $ret;
 }
Example #6
0
 private function delete_file($field_id, $user_id, $output = true)
 {
     $field_data = (array) wpl_db::get('*', 'wpl_dbst', 'id', $field_id);
     $user_data = (array) wpl_users::get_wpl_user($user_id);
     $path = wpl_items::get_path($user_id, $field_data['kind']) . $user_data[$field_data['table_column']];
     /** delete file and reset db **/
     wpl_file::delete($path);
     wpl_db::set('wpl_users', $user_id, $field_data['table_column'], '');
     /** delete thumbnails **/
     wpl_users::remove_thumbnails($user_id);
     /** called from other functions (upload function) **/
     if (!$output) {
         return;
     }
     $res = 1;
     $message = $res ? __('Saved.', WPL_TEXTDOMAIN) : __('Error Occured.', WPL_TEXTDOMAIN);
     $data = NULL;
     $response = array('success' => $res, 'message' => $message, 'data' => $data);
     echo json_encode($response);
     exit;
 }
 private function gicon_delete($icon)
 {
     if (trim($icon) == '') {
         $icon = wpl_request::getVar('icon');
     }
     $dest = WPL_ABSPATH . 'assets' . DS . 'img' . DS . 'listing_types' . DS . 'gicon' . DS . $icon;
     if (wpl_file::exists($dest)) {
         wpl_file::delete($dest);
     }
     /** trigger event **/
     wpl_global::event_handler('gicon_removed', array('icon' => $icon));
     exit;
 }
Example #8
0
 private function remove_upload()
 {
     $setting_name = wpl_request::getVar('setting_name', '');
     $settings_value = wpl_settings::get($setting_name);
     $upload_src = wpl_global::get_wpl_asset_url('img/system/' . $settings_value);
     wpl_settings::save_setting($setting_name, NULL);
     wpl_file::delete($upload_src);
     /** Remove Thumbnails **/
     wpl_settings::clear_cache('listings_thumbnails');
     wpl_settings::clear_cache('users_thumbnails');
     $response = array('success' => 1, 'message' => __('Uploaded file removed successfully!', WPL_TEXTDOMAIN));
     echo json_encode($response);
     exit;
 }
Example #9
0
 /**
  * Removes WPL cached data
  * @author Howard <*****@*****.**>
  * @static
  * @param type $cache_type
  * @return boolean
  */
 public static function clear_cache($cache_type = 'all')
 {
     /** first validation **/
     $cache_type = strtolower($cache_type);
     if (trim($cache_type) == '') {
         return false;
     }
     /** import libraries **/
     _wpl_import('libraries.property');
     _wpl_import('libraries.items');
     if ($cache_type == 'unfinalized_properties' or $cache_type == 'all') {
         $properties = wpl_db::select("SELECT `id` FROM `#__wpl_properties` WHERE `finalized`='0'", 'loadAssocList');
         foreach ($properties as $property) {
             wpl_property::purge($property['id']);
         }
     }
     if ($cache_type == 'properties_cached_data' or $cache_type == 'all') {
         $q = " `location_text`='', `rendered`='', `alias`=''";
         if (wpl_global::check_multilingual_status()) {
             $q = self::get_multilingual_query(array('alias', 'location_text', 'rendered'));
         }
         $query = "UPDATE `#__wpl_properties` SET " . $q;
         wpl_db::q($query);
     }
     if ($cache_type == 'location_texts' or $cache_type == 'all') {
         $q = " `location_text`=''";
         if (wpl_global::check_multilingual_status()) {
             $q = self::get_multilingual_query(array('location_text'));
         }
         $query = "UPDATE `#__wpl_properties` SET " . $q;
         wpl_db::q($query);
     }
     if ($cache_type == 'listings_thumbnails' or $cache_type == 'all') {
         $properties = wpl_db::select("SELECT `id`, `kind` FROM `#__wpl_properties` WHERE `id`>0", 'loadAssocList');
         $ext_array = array('jpg', 'jpeg', 'gif', 'png');
         foreach ($properties as $property) {
             $path = wpl_items::get_path($property['id'], $property['kind']);
             $thumbnails = wpl_folder::files($path, 'th.*\\.(' . implode('|', $ext_array) . ')$', 3, true);
             foreach ($thumbnails as $thumbnail) {
                 wpl_file::delete($thumbnail);
             }
         }
     }
     if ($cache_type == 'users_cached_data' or $cache_type == 'all') {
         $q = " `location_text`='', `rendered`=''";
         if (wpl_global::check_multilingual_status()) {
             $q = self::get_multilingual_query(array('location_text', 'rendered'), 'wpl_users');
         }
         $query = "UPDATE `#__wpl_users` SET " . $q;
         wpl_db::q($query);
     }
     if ($cache_type == 'users_thumbnails' or $cache_type == 'all') {
         $users = wpl_db::select("SELECT `id` FROM `#__wpl_users` WHERE `id`>0", 'loadAssocList');
         $ext_array = array('jpg', 'jpeg', 'gif', 'png');
         foreach ($users as $user) {
             $path = wpl_items::get_path($user['id'], 2);
             $thumbnails = wpl_folder::files($path, 'th.*\\.(' . implode('|', $ext_array) . ')$', 3, true);
             foreach ($thumbnails as $thumbnail) {
                 wpl_file::delete($thumbnail);
             }
         }
     }
     /** trigger event **/
     wpl_global::event_handler('cache_cleared', array('cache_type' => $cache_type));
     return true;
 }