Plugin Directory

Changeset 1531594


Ignore:
Timestamp:
11/10/2016 12:23:04 PM (9 years ago)
Author:
wordgenie
Message:

Added feature to set different file extensions for each file type question

Location:
files-addon-for-event-espresso-4/trunk
Files:
5 added
9 edited

Legend:

Unmodified
Added
Removed
  • files-addon-for-event-espresso-4/trunk/EE_FILE_Validation_Strategy.php

    r1481341 r1531594  
    88    public function __construct($validation_error_message = null)
    99    {
     10
    1011        if (! $validation_error_message) {
    1112            $validation_error_message = __("Please enter a valid URL", "event_espresso");
     
    2526    public function validate($normalized_value)
    2627    {
    27        
    2828            $filetype = wp_check_filetype($normalized_value);
    2929            $data = parse_url($normalized_value);
     
    3535                throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
    3636            }
    37        
    38         parent::validate($normalized_value);
     37            parent::validate($normalized_value);
    3938    }
    4039}
  • files-addon-for-event-espresso-4/trunk/EE_File.class.php

    r1449260 r1531594  
    1010define('EE_FILE_ADMIN', EE_FILE_PATH . 'admin/file/');
    1111
    12 /**
    13  *
    14  * Class  EE_File
    15  *
    16  * @package         Event Espresso
    17  * @subpackage      eea-file
    18  *
    19  */
     12
    2013class EE_File extends EE_Addon
    2114{
     
    4538            )
    4639        );
     40        add_action('admin_enqueue_scripts', array('EE_File','ssa_load_scripts'));
    4741        require_once "EE_FILE_Validation_Strategy.php";
    4842        require_once "EE_File_Display_Strategy.php";
     
    5145        include_once "ssa_run_filters.php";
    5246    }
     47    public static function ssa_load_scripts($hook)
     48    {
     49     
     50        global $wpdb;
     51        $table = $wpdb->prefix.'esp_question_allowed_ext';
     52        $ext ='';
     53        if ($hook == 'event-espresso_page_espresso_registration_form') {
     54            if (isset($_GET['QST_ID']) && $_GET['QST_ID'] != '') {
     55                $que_id = $_GET['QST_ID'];
     56                $ext = $wpdb->get_var("SELECT ext FROM $table WHERE qst_id='$que_id'");
     57
     58            }
     59           
     60            wp_enqueue_style('admin-file-css', plugins_url('css/admin-screen.css', __FILE__));
     61            wp_enqueue_script('file-js', plugins_url('js/admin-js.js', __FILE__), array('jquery'));
     62            wp_localize_script('file-js', 'ssa_var_ds', array('ext'=>$ext));
     63        }
     64    }
    5365}
     66add_action('AHEE__Extend_Registration_Form_Admin_Page___redirect_after_action__before_redirect_modification_insert_question', 'update_ext_function', 10, 1);
     67
     68add_action('AHEE__Extend_Registration_Form_Admin_Page___redirect_after_action__before_redirect_modification_update_question', 'update_ext_function', 10, 1);
     69
     70function update_ext_function($args)
     71{
     72    global $wpdb;
     73    $table = $wpdb->prefix.'esp_question_allowed_ext';
     74    $question_id = $args['QST_ID'];
     75   
     76    $count = $wpdb->get_var("SELECT COUNT(id) FROM $table WHERE qst_id='{$question_id}'");
     77    $ext = $_POST['question_ext'];
     78   
     79   
     80    if ($count > 0) {
     81       
     82          $wpdb->update(
     83              $table,
     84              array('ext'=>$ext),
     85              array('qst_id'=>$question_id),
     86              array('%s'),
     87              array('%d')
     88          );
     89    } else {
     90       
     91         $wpdb->insert(
     92             $table,
     93             array('ext'=>$ext,
     94                    'qst_id'=>$question_id),
     95             array( '%s',
     96                    '%d')
     97         );
     98    }
     99 
     100   
     101}
  • files-addon-for-event-espresso-4/trunk/EE_File_Display_Strategy.php

    r1481341 r1531594  
    3131    public function display()
    3232    {
     33     
    3334        $value = $this->_input->raw_value_in_form();
    34         $input ='<input type="text">';
    3535        $input = '<input type="'. $this->get_type() .'"';
     36        $input .= ' name="ssa_' . $this->_input->html_name() . '"';
     37        $input .= ' id="ssa_' . $this->_input->html_id() . '"';
    3638        $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
    37         $input .= ' class="ssa-file ' . $class . '"';
     39        $input .= ' class="' . $class . ' ssa-file"';
    3840        $input .= $this->_input->required() ? ' required' : '';
    3941        $input .= ' value="' . $this->_input->raw_value_in_form() . '"';
    4042        $input .= ' style="' . $this->_input->html_style() . '"';
    41         $input .= $this->_input->html_other_attributes();
     43        $input .= $this->_input->other_html_attributes();
    4244        $input .= '/>';
    4345        $input .= "<span class='ssa-remove'></span>";
    4446        $input .= "<span class='ssa-loading'></span>";
    45         $input .= '<input  type="hidden"';
     47        $input .= '<input type="hidden"';
    4648        $input .= ' name="' . $this->_input->html_name() . '"';
    4749        $input .= ' id="' . $this->_input->html_id() . '"';
    4850        $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
    49 
    5051        $input .= ' class="file_value ' . $class . '"';
     52        // add html5 required
     53        $input .= $this->_input->required() ? ' required' : '';
     54        $input .= ' value="' . $this->_input->raw_value_in_form() . '"';
    5155        $input .= ' style="' . $this->_input->html_style() . '"';
    52         $input .= $this->_input->html_other_attributes();
     56        $input .= $this->_input->other_html_attributes();
    5357        $input .= '/>';
    5458        if ($value != '') {
  • files-addon-for-event-espresso-4/trunk/EE_SSA_FILE.php

    r1449260 r1531594  
    2020    static function ssa_enqueue_scripts()
    2121    {
     22        global $wpdb;
     23        $table = $wpdb->prefix.'esp_question_allowed_ext';
     24        $ext = $wpdb->get_results("SELECT * FROM $table");
     25        $arr = array();
     26        foreach ($ext as $extension) {
     27            $id = $extension->qst_id;
     28            $et = $extension->ext;
     29            $arr[$id] = $et;
     30        }
     31        $d = json_encode($arr);
    2232        wp_enqueue_style('ssa_file_css', plugins_url('css/ssa_style.css', __FILE__));
    2333        $year = date('Y');
     
    3040        wp_localize_script(
    3141            'ssa_file_upload',
    32             'ssa_var',
     42            'ssa_var_ds',
    3343            array(
    3444                'ajax_path' =>$ajax_path,
    3545                'ssa_upload'=>$uploads,
    36                 'ssa_url'=>$uploads_url)
     46                'ssa_url'=>$uploads_url,
     47                'extensions'=> $d)
    3748        );
    3849    }
  • files-addon-for-event-espresso-4/trunk/css/ssa_style.css

    r1481341 r1531594  
    2121    display:none !important;
    2222}
     23.ssa-loading+label
     24{
     25    display:none !important;
     26}
  • files-addon-for-event-espresso-4/trunk/eea-file.php

    r1497941 r1531594  
    33 * Plugin Name: Files Addon for Event Espresso 4
    44 * Description: Files add on plugin allows to create file type question in event registration form. Attendees will be able to upload files while registering for an event.
    5  * Author: WordGenie
     5 * Author: WordGeniee
    66 * License:GPL2
    7  * Version: 1.0.3
     7 * Version: 1.0.4
    88 * TextDomain:  wordfile
    99 */
    1010// define versions and this file
    1111define('EE_FILE_CORE_VERSION_REQUIRED', '4.8.0.rc.0000');
    12 define('EE_FILE_VERSION', '1.0.0');
     12define('EE_FILE_VERSION', '1.0.4');
    1313define('EE_FILE_PLUGIN_FILE', __FILE__);
    1414
     
    7878function ssa_upload_file()
    7979{
     80    global $wpdb;
     81
     82    $table = $wpdb->prefix.'esp_question_allowed_ext';
    8083    $data = array();
    8184    if (isset($_FILES)) {
     
    8588       
    8689        $uploadedfile = $_FILES['file'];
     90        $qid = $_POST['qst_id'];
     91        $ext = $wpdb->get_var("SELECT ext FROM $table WHERE qst_id='$qid'");
     92        $allowed =  array('gif','png' ,'jpg','jpeg','bmp');
     93        if ($ext !='') {
     94            $allowed = explode(',', $ext);
     95        }
    8796
    88         $allowed =  array('gif','png' ,'jpg','jpeg','bmp');
     97        $allowed=array_map('trim', $allowed);
     98       
    8999        $filename = $_FILES['file']['name'];
    90100        $extn = pathinfo($filename, PATHINFO_EXTENSION);
    91101        if (!in_array($extn, $allowed)) {
    92             $data = array('error' => "Only formats are allowed : ".implode(', ', $allowed));
     102            $data = array('error' => __("Only formats are allowed : ".implode(', ', $allowed),'wordfile'));
    93103        }
    94 
     104       
    95105        $upload_overrides = array( 'test_form' => false );
    96106
     
    108118        }
    109119    } else {
    110         $data = array('error' => 'No file submitted');
     120        $data = array('error' => __('No file submitted','wordfile'));
    111121    }
    112122
    113      echo json_encode($data);
     123    echo json_encode($data);
    114124    die();
    115125}
     
    122132}
    123133
     134
     135function ssa_create_ext_tbl()
     136{
     137    $val = get_option('file_db_created');
     138    if($val != 1)
     139    {
     140    global $wpdb;
     141    $tbl = $wpdb->prefix.'esp_question_allowed_ext';
     142 
     143   
     144    if ($wpdb->get_var("show tables like '$tbl'") != $tbl) {
     145        $sql = "CREATE TABLE " . $tbl . " (
     146        id int NOT NULL AUTO_INCREMENT,
     147        qst_id int,
     148        ext varchar(100),
     149        UNIQUE KEY id (id)
     150        );";
     151 
     152        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
     153        dbDelta($sql);
     154    }
     155    update_option('file_db_created',1);
     156    }
     157}
     158add_action('admin_head', 'ssa_create_ext_tbl');
  • files-addon-for-event-espresso-4/trunk/js/ssa_file_upload.js

    r1481341 r1531594  
    11jQuery(document).ready(function(){
    2    
     2    exts = JSON.parse(ssa_var_ds.extensions);
     3   // console.log(exts);
    34    jQuery('.ssa-file').on('change',function(event){
    4 
    5         var fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];
     5        id = jQuery(this).prev('label').attr('id');
     6        piece = id.split('-');
     7        qid = piece[2];
     8     
     9        var fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];
     10        if(exts[qid] != '' && typeof exts[qid] != 'undefined')
     11        {
     12            var fileExtension = exts[qid].split(',');
     13            for(i=0;i<fileExtension.length;i++)
     14                fileExtension[i] =  fileExtension[i].trim();
     15        }
     16       
    617        if (jQuery.inArray(jQuery(this).val().split('.').pop().toLowerCase(), fileExtension) == -1) {
    718            alert("Only formats are allowed : "+fileExtension.join(', '));
    8             jQuery('.ssa-file').val('');
     19            jQuery(this).val('');
    920            return;
    1021        }
     
    1728        data.append("file", file_data);
    1829        data.append("action", 'ssa_upload_file');
    19         path = ssa_var.ajax_path;
     30        data.append("qst_id", qid);
     31        path = ssa_var_ds.ajax_path;
    2032        jQuery(this).siblings('.ssa-loading').css('display','inline-block');
    2133        jQuery.ajax({
     
    2941            success: function(data, textStatus, jqXHR)
    3042            {
    31                 // console.log(data.files.url);
     43                console.log(data.files.url);
    3244               
    3345                if(typeof data.error === 'undefined')
  • files-addon-for-event-espresso-4/trunk/readme.txt

    r1497941 r1531594  
    55Tested up to: 4.5
    66Requires Event espresso version: 4.8.0
    7 Stable tag: 1.0.3
     7Stable tag: 1.0.4
    88License: GPL2
    99
     
    1212== Description ==
    1313
    14 Files add on plugin allows to create file type question which can be used in event registration form. Attendees will be able to upload image files while registerting for an event using this addon.
     14Files add on plugin allows to create file type question which can be used in event registration form. Attendees will be able to upload files while registerting for an event using this addon. Admin will be able to restrict the file type by setting file extensions for each question.
    1515
    1616== Installation ==
     
    2121* PHP version 5.2.4 or greater
    2222* MySQL version 5.0 or greater
     23* Event espresso version: 4.8.0 or greater
    2324* This add on will not work in Internet explorer version 9 or below, because formData (javascript object used to upload file on server) is not supported in IE 9 or its below version.
    2425
     
    2728Following steps should be followed to install plugin manually
    2829
    29 1. Upload 'files-addon-for-event-espresso-4' folder to the '/wp-content/plugins/' directory or upload 'files-addon-for-event-espresso-4.1.0.1.zip' through WordPress admin panel
     301. Upload 'files-addon-for-event-espresso-4' folder to the '/wp-content/plugins/' directory or upload 'files-addon-for-event-espresso-4.1.0.4.zip' through WordPress admin panel
    30312. Activate the plugin through the 'Plugins' menu in WordPress
    31323. You are ready to create file type question.
     
    5859
    5960== Changelog ==
     61= 1.0.4 =
    6062
    61 = 1.0.0 =
    62 Plugin release
     631. Added feature to set different file extensions for each file type question
     642. If extensions are not set then uploaded file is validated against following extensions ['gif','png' ,'jpg','jpeg','bmp']
    6365
    64 = 1.0.1 =
     66= 1.0.3 =
    6567
    66 Fixed file upload security issue. Added EE_FILE_Validation_Strategy class for validating uploaded file.
     681. Added filter 'ssa_change_file_upload_path' to change directory path of uploaded file
     692. Added standard code to return file type question.
    6770
    6871= 1.0.2 =
     
    71742. Added link to image.
    7275
    73 = 1.0.3 =
     76= 1.0.1 =
    7477
    75 1. Added filter 'ssa_change_file_upload_path' to change directory path of uploaded file
    76 2. Added standard code to return file type question.
     78Fixed file upload security issue. Added EE_FILE_Validation_Strategy class for validating uploaded file.
    7779
     80= 1.0.0 =
     81Plugin release
     82
     83
  • files-addon-for-event-espresso-4/trunk/ssa_run_filters.php

    r1497941 r1531594  
    33function ssa_add_file_type($question_types)
    44{
    5     $question_types['file']= __('File', 'event_espresso');
     5    $question_types['file']= __('File', 'wordfile');
    66    return $question_types;
    77}
Note: See TracChangeset for help on using the changeset viewer.