Plugin Directory

Changeset 602441


Ignore:
Timestamp:
09/22/2012 05:53:34 PM (14 years ago)
Author:
ti2m
Message:

Filesystem usage changes

Location:
edge-suite/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • edge-suite/trunk/admin/manage.php

    r594166 r602441  
    5858
    5959    // Init file system
    60     WP_Filesystem();
     60    // Todo: this doesn't work with FTP
     61    //WP_Filesystem();
    6162
    6263    $tmp_file = EDGE_SUITE_PUBLIC_DIR . '/tmp/' . $_FILES['edge_suite_composition_upload']['name'];
     
    9394  <h2>Edge Suite - Manage compositions</h2>
    9495
     96  <?php
     97  $msg = check_filesystem();
     98    if(!empty($msg)){
     99      echo '<div class="error"><p>';
     100      echo implode('</br>',$msg);
     101      echo '</p></div>';
     102    }
     103  ?>
    95104
    96   <h3>Upload new composition</h3>
     105<h3>Upload new composition</h3>
    97106<form enctype="multipart/form-data" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="POST">
    98107  <input name="edge_suite_composition_upload" type="file" />
  • edge-suite/trunk/admin/options.php

    r587841 r602441  
    66    <?php settings_fields('edge_suite_options'); ?>
    77    <table class="form-table">
    8 
    9       <tr valign="top">
    10         <th scope="row">Max upload file size</th>
    11         <td>
    12           <input type="text" name="edge_suite_max_size"
    13                  value="<?php echo get_option('edge_suite_max_size'); ?>"/>
    14           <span class="setting-description">
    15             File size in MB<br/>This is the max size that your file uploads will be limited to. 2 MB is the default upload size.
    16           </span>
    17         </td>
    18       </tr>
    19 
    208
    219      <tr valign="top">
     
    4836      </tr>
    4937
     38      <tr valign="top">
     39          <th scope="row">Max upload file size</th>
     40          <td>
     41              <input type="text" name="edge_suite_max_size"
     42                     value="<?php echo intval(get_option('edge_suite_max_size')); ?>"/>
     43        <span class="setting-description">
     44          File size in MB<br/>This is the max size that your file uploads will be limited to. 2 MB is the default upload size.
     45        </span>
     46          </td>
     47      </tr>
     48
     49      <tr valign="top">
     50          <th scope="row">Deactivation deletion</th>
     51          <td>
     52            <?php
     53            $selected = intval(get_option('edge_suite_deactivation_delete')) == 1 ? 'checked="checked"' : '';
     54            ?>
     55            <p><input type="checkbox" name="edge_suite_deactivation_delete" value="1" <?php echo $selected; ?>"/>
     56                Delete Edge Suite assets and settings on plugin deactivation</p>
     57            <span class="setting-description">
     58              Activate this option to delete all uploaded compositions (files and database entries) including all Edge Suite
     59              settings from wordpress when deactivating the plugin. This should be activated if you are unable to delete files
     60              manually through FTP and want to clean out Edge Suite completely.
     61            </span>
     62          </td>
     63      </tr>
     64
    5065
    5166    </table>
     
    5368    <input type="hidden" name="action" value="update"/>
    5469    <input type="hidden" name="page_options"
    55            value="edge_suite_max_size,edge_suite_comp_default,edge_suite_comp_homepage"/>
     70           value="edge_suite_max_size,edge_suite_comp_default,edge_suite_comp_homepage,edge_suite_deactivation_delete"/>
    5671
    5772    <p class="submit">
  • edge-suite/trunk/edge-suite.php

    r594166 r602441  
    22/*
    33Plugin Name: Edge Suite
    4 Plugin URI: http://timm-jansen.net/edge_suite_wp
     4Plugin URI: http://edgedocks.com/edge_suite
    55Description: Upload Adobe Edge compositions to your website.
    66Author: Timm Jansen
    77Author URI: http://timm-jansen.net/
    8 Version: 0.1
     8Version: 0.2
    99*/
    1010
     
    2828/**
    2929 * This is a port of the Drupal Edge Suite module (done by me as well) for wordpress.
    30  */
     30*/
    3131
    3232require_once('includes/edge-suite-general.php');
    3333require_once('includes/edge-suite-comp.inc');
     34
     35/**
     36 * Set all needed constants
     37 */
     38function edge_suite_init_constants(){
     39  // Respect general upload path.
     40  $upload_dir = get_option('upload_path');
     41  if (empty($upload_dir)) {
     42    $upload_dir = 'wp-content/uploads';
     43  }
     44  $upload_dir = untrailingslashit($upload_dir);
     45
     46  define('EDGE_SUITE_PUBLIC_DIR_REL', get_bloginfo('wpurl') . '/' . $upload_dir . '/edge_suite');
     47  define('EDGE_SUITE_PUBLIC_DIR', untrailingslashit(ABSPATH) . '/' . $upload_dir . '/edge_suite');
     48
     49  define('EDGE_SUITE_COMP_PROJECT_DIR', EDGE_SUITE_PUBLIC_DIR . '/project');
     50  define('EDGE_SUITE_COMP_PROJECT_DIR_REL', EDGE_SUITE_PUBLIC_DIR_REL . '/project');
     51
     52
     53  define('EDGE_SUITE_ALLOWED_ASSET_EXTENSIONS', 'js|png|jpg|gif|svg|css');
     54
     55
     56  define('REQUEST_TIME', time());
     57
     58}
    3459
    3560/*** UN/INSTALL ***/
     
    6186  // Default options.
    6287  add_option('edge_suite_max_size', 2);
    63   add_option('edge_suite_comp_default', 0);
     88  add_option('edge_suite_comp_default', -1);
    6489  add_option('edge_suite_comp_homepage', 0);
     90  add_option('edge_suite_deactivation_delete', 0);
     91
     92  // Create main edge suite directory.
     93  mkdir_recursive(trailingslashit(EDGE_SUITE_PUBLIC_DIR));
    6594}
    6695
     
    6998
    7099function edge_suite_uninstall() {
    71   global $wpdb;
    72   $table_name = $wpdb->prefix . "edge_suite_composition_definition";
    73   if ($wpdb->get_var("show tables like '$table_name'") == $table_name) {
    74     $wpdb->query('DROP TABLE ' . $table_name);
    75   }
    76   // Todo: Delete all edge directories / options / meta data?
     100  if(get_option('edge_suite_deactivation_delete') == 1){
     101    edge_suite_init_constants();
     102
     103    global $wpdb;
     104    $table_name = $wpdb->prefix . "edge_suite_composition_definition";
     105    if ($wpdb->get_var("show tables like '$table_name'") == $table_name) {
     106      $wpdb->query('DROP TABLE ' . $table_name);
     107    }
     108
     109    // Delete all edge directories
     110    rmdir_recursive(trailingslashit(EDGE_SUITE_PUBLIC_DIR));
     111
     112    // Delete options
     113    delete_option('edge_suite_max_size');
     114    delete_option('edge_suite_comp_default');
     115    delete_option('edge_suite_comp_homepage');
     116    delete_option('edge_suite_deactivation_delete');
     117  }
    77118}
    78119
    79120register_deactivation_hook(__FILE__, 'edge_suite_uninstall');
    80 
    81 
    82 /**
    83  * Register general options.
    84  */
     121//register_uninstall_hook(__FILE__, 'edge_suite_uninstall');
     122
     123
     124/**
     125* Register general options.
     126*/
    85127function edge_suite_options_init() {
    86128  register_setting('edge_suite_options', 'edge_suite_max_size');
    87129  register_setting('edge_suite_options', 'edge_suite_comp_default');
    88130  register_setting('edge_suite_options', 'edge_suite_comp_homepage');
     131  register_setting('edge_suite_options', 'edge_suite_deactivation_delete');
    89132}
    90133
    91134add_action('admin_init', 'edge_suite_options_init');
     135
    92136
    93137
     
    101145  $edge_suite->msg = array();
    102146
    103   // Respect general upload path.
    104   $upload_dir = get_option('upload_path');
    105   if (empty($upload_dir)) {
    106     $upload_dir = 'wp-content/uploads';
    107   }
    108 
    109   define('EDGE_SUITE_PUBLIC_DIR_REL', get_bloginfo('wpurl') . '/' . $upload_dir . '/edge_suite');
    110   define('EDGE_SUITE_PUBLIC_DIR', ABSPATH . '/' . $upload_dir . '/edge_suite');
    111 
    112   define('EDGE_SUITE_COMP_PROJECT_DIR', EDGE_SUITE_PUBLIC_DIR . '/project');
    113   define('EDGE_SUITE_COMP_PROJECT_DIR_REL', EDGE_SUITE_PUBLIC_DIR_REL . '/project');
     147  edge_suite_init_constants();
    114148
    115149  //Check if dir is writable and create directory structure.
    116150  if (!mkdir_recursive(EDGE_SUITE_COMP_PROJECT_DIR)) {
    117     $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), EDGE_SUITE_COMP_PROJECT_DIR_REL);
    118     return array('error' => $message);
    119   }
    120 
    121   define('REQUEST_TIME', time());
     151    print sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), EDGE_SUITE_COMP_PROJECT_DIR_REL);
     152  }
     153
    122154}
    123155
  • edge-suite/trunk/includes/edge-suite-comp-builder.inc

    r594166 r602441  
    325325
    326326    // Get archiver.
    327     $success = unzip_file($file, $destination);
    328     if (!$success) {
    329       throw new Exception('Extraction of ' . $file . 'failed.');
     327    $success = unzip($file, $destination);
     328    if (is_wp_error($success)) {
     329      throw new Exception('Extraction of ' . $file . ' failed.');
    330330    }
    331331  }
     
    535535
    536536        if ($overwrite || !$exists) {
    537           $moved = $wp_filesystem->move($lib->uri, $this->edgeDir . '/edge_includes/' . $lib->filename, TRUE);
     537          $moved = move_file($lib->uri, $this->edgeDir . '/edge_includes/' . $lib->filename);
    538538          if (!$moved) {
    539539            set_message('Library ' . check_plain($lib->filename) . ' could not be added/moved.');
     
    604604      // TODO: Feedback if file couldn't be moved.
    605605      $file_info = pathinfo($f);
    606       $moved = $wp_filesystem->move($f, $dest . '/' . $rel_dir . '/' . $file_info['basename']);
     606      $moved = move_file($f, $dest . '/' . $rel_dir . '/' . $file_info['basename']);
    607607    }
    608608  }
  • edge-suite/trunk/includes/edge-suite-comp.inc

    r594166 r602441  
    8989
    9090      $project_path = EDGE_SUITE_COMP_PROJECT_DIR . '/' . $def_name;
    91       rename($project_tmp_path, $project_path);
     91      move_file($project_tmp_path, $project_path);
    9292
    9393      $success = TRUE;
     
    9595  } catch (Exception $e) {
    9696    // Clean out all files.
    97     print $e->getMessage();
    9897
    9998    // Make sure source extraction directory gets cleaned out.
     
    107106      rmdir_recursive($project_path);
    108107    }
     108
     109    // Hand exception to the next level.
     110    throw new Exception($e->getMessage());
    109111    // TODO: Libraries might have been copied. Critical?
    110112  }
  • edge-suite/trunk/includes/edge-suite-general.php

    r594166 r602441  
    11<?php
    22
     3
     4
     5// Not used yet
     6function fs_connect( $directories = array() ) {
     7  global $wp_filesystem;
     8
     9  $url = "edge_suite";
     10  if ( false === ($credentials = request_filesystem_credentials($url)) )
     11    return false;
     12
     13  if ( ! WP_Filesystem($credentials) ) {
     14    $error = true;
     15    if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() )
     16      $error = $wp_filesystem->errors;
     17    $this->skin->request_filesystem_credentials($error); //Failed to connect, Error and request again
     18    return false;
     19  }
     20
     21  if ( ! is_object($wp_filesystem) )
     22    return new WP_Error('fs_unavailable', $this->strings['fs_unavailable'] );
     23
     24  if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
     25    return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors);
     26
     27  foreach ( (array)$directories as $dir ) {
     28        if ( ! $wp_filesystem->find_folder($dir) )
     29          return new WP_Error('fs_no_folder', sprintf($this->strings['fs_no_folder'], $dir));
     30  }
     31  return true;
     32}
     33
     34function check_filesystem(){
     35  $msg = array();
     36  if(!class_exists('ZipArchive')){
     37    $msg['zip'] = 'Your server is not able to extract zip files (PHP Class "ZipArchive" not found).';
     38  }
     39
     40  // Check file system method
     41
     42  $method = null;
     43  $fs_msg = '';
     44  if ( function_exists('getmyuid') && function_exists('fileowner') ){
     45    $context = trailingslashit(EDGE_SUITE_PUBLIC_DIR);
     46    $temp_file_name = $context . 'temp-write-test-edge-' . time();
     47    $temp_handle = @fopen($temp_file_name, 'w');
     48    if ( $temp_handle ) {
     49      $myuid = getmyuid();
     50      $owner = @fileowner($temp_file_name);
     51      @fclose($temp_handle);
     52      @unlink($temp_file_name);
     53      if ( $myuid == $owner )
     54        $method = 'direct';
     55      else {
     56        $fs_msg = 'The owner of the scripts (most likely your FTP user) is different from the user that runs the PHP server process. </br>';
     57        $fs_msg .= 'Files handled through Edge Suite might not be manually deletable by you through FTP. <br>';
     58        $fs_msg .= 'Alternative uploading methods are on the roadmap for Edge Suite.';
     59      }
     60    }
     61    else{
     62      $fs_msg = 'Tmp test file could not be written to ' . EDGE_SUITE_PUBLIC_DIR;
     63    }
     64  }
     65  else{
     66    $fs_msg = 'PHP functions getmyuid() and fileowner() could not be found.';
     67  }
     68  if(!empty($fs_msg)){
     69    $msg['filesystem'] = $fs_msg;
     70  }
     71
     72  return $msg;
     73
     74}
     75
     76
     77function unzip($file, $to){
     78  if ( class_exists('ZipArchive') && apply_filters('unzip_file_use_ziparchive', true ) ) {
     79
     80
     81    require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
     82    require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php');
     83    $filesystem = new WP_Filesystem_Direct(null);
     84
     85    $z = new ZipArchive();
     86
     87    // PHP4-compat - php4 classes can't contain constants
     88    $zopen = $z->open($file, /* ZIPARCHIVE::CHECKCONS */ 4);
     89    if ( true !== $zopen )
     90      return new WP_Error('incompatible_archive', __('Incompatible Archive.'));
     91
     92
     93    for ( $i = 0; $i < $z->numFiles; $i++ ) {
     94      if ( ! $info = $z->statIndex($i) )
     95        return new WP_Error('stat_failed', __('Could not retrieve file from archive.'));
     96
     97      if ( '/' == substr($info['name'], -1) ) // directory
     98        continue;
     99
     100      if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Don't extract the OS X-created __MACOSX directory files
     101        continue;
     102
     103      if(!preg_match('/(.*)\.(' . EDGE_SUITE_ALLOWED_ASSET_EXTENSIONS . ')$/', $info['name'])){
     104        continue;
     105      }
     106
     107      $dir_creation = mkdir_recursive(trailingslashit($to) . dirname($info['name']));
     108      $contents = $z->getFromIndex($i);
     109      if ( false === $contents )
     110        return new WP_Error('extract_failed', __('Could not extract file from archive.'), $info['name']);
     111
     112      if ( ! $filesystem->put_contents( trailingslashit($to) . $info['name'], $contents, FS_CHMOD_FILE) )
     113        return new WP_Error('copy_failed', __('Could not copy file.'), $to . $info['name']);
     114    }
     115
     116    $z->close();
     117
     118    return true;
     119
     120  }
     121}
    3122
    4123function file_scan_directory($dir, $pattern) {
     
    13132}
    14133
    15 function rmdir_recursive($path) {
    16   global $wp_filesystem;
    17   $wp_filesystem->rmdir($path, TRUE);
     134function rmdir_recursive($dir) {
     135  //global $wp_filesystem;
     136  foreach(glob($dir . '/*') as $file) {
     137    if(@is_dir($file))
     138      rmdir_recursive($file);
     139    else
     140      @unlink($file);
     141  }
     142  @rmdir($dir);
    18143}
    19144
     
    28153
    29154function dir_is_writable($path){
    30   global $wp_filesystem;
    31   return $wp_filesystem->is_writable($path);
     155  //global $wp_filesystem;
     156  return is_writable($path);
     157}
     158
     159
     160function move_file($source, $destination){
     161  // Todo: add overwrite flag
     162  // Todo: copy new file, delete old file
     163  return rename($source, $destination);
     164
    32165}
    33166
  • edge-suite/trunk/readme.txt

    r593619 r602441  
    11=== Edge Suite ===
    22Contributors: ti2m
    3 Tags: media, animation, interactive, adobe edge, edge animate, edge, embed, integration
     3Tags: media, animation, interactive, adobe edge animate, edge animate, edge, embed, integration
    44Requires at least: 4.3
    55Tested up to: 4.3
     
    1717Since Edge Animate itself is still in pre-release this plugin is a moving target as well and should therefore not yet be used in production.
    1818
     19There have been problems with unzipping composition archives on shared hosting plans due to the wordpress filesystem. More detailed info is available in the FAQ section.
     20
     21Roadmap: FTP Filesystem support, data injection
     22
    1923Please help to review and test the plugin. Feedback is appreciated.
    2024
     
    2529* Easy placement of compositions on the website
    2630
     31== Frequently Asked Questions ==
     32
     33= PHP ZipArchive not found =
     34
     35zip.so needs to be installed as a PHP library
    2736
    2837== Installation ==
     
    5059
    5160Please report any bugs to the Edge Suite support queue on wordpress.
     61
     62
     63== Changelog ==
     64
     65= 0.2 =
     66Change of filesystem usage
Note: See TracChangeset for help on using the changeset viewer.