/** * Upload premade layout to file * * @return type */ function upload_layout() { if (!isset($_POST[WR_NONCE]) || !wp_verify_nonce($_POST[WR_NONCE], WR_NONCE)) { return; } $status = 0; if (!empty($_FILES)) { $fileinfo = $_FILES['file']; $file = $fileinfo['tmp_name']; $tmp_file = 'tmp-layout-' . time(); $dest = WR_Pb_Helper_Functions::get_wp_upload_folder('/wr-pb-layout/' . $tmp_file); if ($fileinfo['type'] == 'application/octet-stream') { WP_Filesystem(); $unzipfile = unzip_file($file, $dest); if ($unzipfile) { // explore extracted folder to get provider info $status = WR_Pb_Helper_Layout::import($dest); } // remove zip file unlink($file); } WR_Pb_Utils_Common::recursive_delete($dest); } echo intval($status); exit; }
/** * Store relation: array(file1, file2) => compressed file * * @param type $handle_info * @param type $file_name * * @return type */ static function compression_data_store($handle_info, $file_name) { $cache_dir = WR_Pb_Helper_Functions::get_wp_upload_folder('/igcache/pagebuilder'); $file_to_write_ = "{$cache_dir}/wr-pb.cache"; $fp = fopen($file_to_write_, 'a+'); if ($fp) { // Get stored data $str = ''; while (!feof($fp)) { $str .= fread($fp, 1024); } $stored_data = unserialize($str); $stored_data = $stored_data ? $stored_data : array(); // Check if $handle_info is existed in stored data $exist = ''; foreach ($stored_data as $handle_info_serialized => $compressed_file) { $handle_info_old = unserialize($handle_info_serialized); // Check if handle names are same if (!count(array_diff(array_keys($handle_info), array_keys($handle_info_old)))) { // Check if date modified are same if (!count(array_diff($handle_info, $handle_info_old))) { $exist = $compressed_file; fclose($fp); return array('exist', $compressed_file); } } } // close current handle fclose($fp); // open new handle to write from beginning of file $fp = fopen($file_to_write_, 'w'); $string = serialize($handle_info); $stored_data[$string] = $file_name; fwrite($fp, serialize($stored_data)); fclose($fp); return array('not exist', $file_name); } }
/** * Remove group in layout * * @param type $group * @param type $layout */ static function remove_layout($group, $layout) { $layout_name = str_replace('.tpl', '', $layout); $dir = WR_Pb_Helper_Functions::get_wp_upload_folder('/wr-pb-layout/' . $group, false); $deleted = array(); if (is_dir($dir)) { // remove .tpl file $layout_file = $dir . "/{$layout_name}.tpl"; if (file_exists($layout_file)) { $deleted[] = unlink($layout_file) ? 1 : 0; } $thumbnail = "{$dir}/{$layout_name}.png"; $got_ext = self::check_ext_exist($dir, $layout_name); if (!empty($got_ext)) { $thumbnail = "{$dir}/{$layout_name}.{$got_ext}"; if (file_exists($thumbnail)) { $deleted[] = unlink($thumbnail) ? 1 : 0; } } if (in_array(0, $deleted)) { return false; } return true; } return false; }