Plugin Directory

Changeset 3066207

Timestamp:
04/07/2024 09:13:56 AM (4 months ago)
Author:
nikelschubert
Message:

1.8.0

  • NEW: added setting for using original filename in download link.
  • REFACTOR: minor code clean ups
Location:
easy-pdf-restaurant-menu-upload
Files:
27 added
6 edited

Legend:

Unmodified
Added
Removed
  • easy-pdf-restaurant-menu-upload/tags/1.7.1/plugin-config.json

    r3002932 r3066207  
    3030            "pre_selected_value": false,
    3131            "additional_text": "Currently live:<span style='font-weight: bold'>{{current_lunch_menu_filename}}</span>",
    32             "helpertext": "Shortcode: [nsc_eprm_menu_link restaurant_menu_type='lunch' linktext='Lunch menu']",
     32            "helpertext": "Shortcode: [nsc_eprm_menu_link restaurant_menu_type='lunch' linktext='Lunch menu']",
    3333            "name": "Lunch Menu",
    3434            "save_in_db": false
     
    4141            "pre_selected_value": false,
    4242            "additional_text": "Currently live:<span font-weight: bold'>{{current_general_menu_filename}}</span>",
    43             "helpertext": "Shortcode: [nsc_eprm_menu_link restaurant_menu_type='general' linktext='General Menu']",
     43            "helpertext": "Shortcode: [nsc_eprm_menu_link restaurant_menu_type='general' linktext='General Menu']",
    4444            "name": "General Menu",
    4545            "save_in_db": false
  • easy-pdf-restaurant-menu-upload/trunk/class/class-admin-html-formfields-nsc_eprm.php

    r2533652 r3066207  
    1313            case "checkbox":
    1414                return $this->create_checkbox();
    15                 break;
    1615            case "textarea":
    1716                return $this->create_textarea();
    18                 break;
    1917            case "text":
    2018                return $this->create_text();
    21                 break;
    2219            case "longtext":
    2320                return $this->create_text("long");
    24                 break;
    2521            case "select":
    2622                return $this->create_select();
    27                 break;
    2823            case "radio":
    2924                return $this->create_radio();
    30                 break;
    3125            case "button":
    3226                return $this->create_button();
    33                 break;
    3427            case "display":
    3528                return $this->create_display();
    36                 break;
    3729            case "file":
    3830                return $this->create_file();
    39                 break;
    4031            case "hidden":
    4132                return $this->create_hidden_field();
    42                 break;
    4333            default:
    4434                return $this->field->pre_selected_value;
    45                 break;
    4635        }
    4736    }
     
    9786        foreach ($this->field->selectable_values as $selectable_value) {
    9887            $select = "";
    99             if ($selectable_value->value == $this->field->pre_selected_value) {$select = " selected";}
     88            if ($selectable_value->value == $this->field->pre_selected_value) {
     89                $select = " selected";
     90            }
    10091            $html .= '<option value="' . $selectable_value->value . '"' . $select . '>' . $selectable_value->name . '</option>';
    10192        }
     
    109100        foreach ($this->field->selectable_values as $selectable_value) {
    110101            $select = "";
    111             if ($selectable_value->value == $this->field->pre_selected_value) {$select = " checked";}
     102            if ($selectable_value->value == $this->field->pre_selected_value) {
     103                $select = " checked";
     104            }
    112105            $html .= '<input id="ff_' . $this->prefix . $this->field->field_slug . '" type="radio" name="' . $this->prefix . $this->field->field_slug . '" value="' . $selectable_value->value . '"' . $select . '>' . $selectable_value->name . ' ';
    113106        }
  • easy-pdf-restaurant-menu-upload/trunk/class/class_admin_easy_pdf_restaurant_menu.php

    r3002932 r3066207  
    33class nsc_easy_pdf_restaurant_menu
    44{
    5 
    65    private $adminMessage = array('error' => array(), 'update' => array());
    76    private $pluginPath;
     
    4443                . implode(", ", array_keys($this->allowedExt))
    4544                . ". You uploaded: " . $this->uploadedFileExt . "!");
    46 
    47         } else {
    48             $upload_status = move_uploaded_file($uploadedFile['tmp_name'], $this->return_menu_upload_path()
    49                 . $this->return_menu_file_name_without_extension($type)
    50                 . "." . $this->uploadedFileExt
    51             );
    52             if ($upload_status === true) {
    53                 update_option('nsc_eprm_' . $type . '_orifilename', $oriFileName);
    54                 $this->add_admin_message('update', "File " . $oriFileName . " successfully uploaded and already live!");
    55             } else {
    56                 $this->add_admin_message('error', "Not able to upload file!");
    57             }
    58         }
     45            return false;
     46
     47        }
     48
     49        $useOriFileName = $this->plugin_configs->get_option_nsc_eprm("orifilename_for_download") == true ? true : false;
     50        $upload_status = move_uploaded_file(
     51            $uploadedFile['tmp_name'],
     52            $this->return_menu_upload_path()
     53            . $this->return_menu_file_name_without_extension($type, $useOriFileName)
     54            . "." . $this->uploadedFileExt
     55        );
     56
     57        if ($upload_status !== true) {
     58            $this->add_admin_message('error', "Not able to upload file!");
     59            return false;
     60        }
     61
     62        update_option('nsc_eprm_' . $type . '_orifilename', $oriFileName);
     63        $this->add_admin_message('update', "File " . $oriFileName . " successfully uploaded and already live!");
     64
    5965    }
    6066
     
    6369        $attr = $this->clean_input->sanitize_user_input_nsc_eprm($attr);
    6470
    65         $atts = shortcode_atts(array(
    66             'restaurant_menu_type' => 'general',
    67             'linktext' => '',
    68             'css_class' => 'nsc_eprm_download_link',
    69         ), $attr);
     71        $atts = shortcode_atts(
     72            array(
     73                'restaurant_menu_type' => 'general',
     74                'linktext' => '',
     75                'css_class' => 'nsc_eprm_download_link',
     76            ),
     77            $attr
     78        );
    7079        return $this->create_href_link($atts['restaurant_menu_type'], $atts['linktext'], array("class" => $atts['css_class'], "id" => "nsceprm_" . $atts['restaurant_menu_type']));
    7180    }
     
    7584        $attr = $this->clean_input->sanitize_user_input_nsc_eprm($attr);
    7685
    77         $atts = shortcode_atts(array(
    78             'restaurant_menu_type' => 'general',
    79             'cachebuster' => true,
    80         ), $attr);
     86        $atts = shortcode_atts(
     87            array(
     88                'restaurant_menu_type' => 'general',
     89                'cachebuster' => true,
     90            ),
     91            $attr
     92        );
    8193        return $this->nsc_eprm_return_download_url($atts['restaurant_menu_type'], $atts['cachebuster']);
    8294    }
     
    125137    }
    126138
    127     private function return_menu_file_name_without_extension($type)
    128     {
     139    private function return_menu_file_name_without_extension($type, $returnOriFilename)
     140    {
     141        if ($returnOriFilename == true) {
     142            $orifilename = get_option('nsc_eprm_' . $type . '_orifilename');
     143            $orifilenameWithoutExtension = pathinfo($orifilename, PATHINFO_FILENAME);
     144            $file_name = preg_replace('/[^a-z0-9\._-]+/', '-', strtolower($orifilenameWithoutExtension));
     145            $file_name = apply_filters('file_name_without_extension_nsc_eprm', $file_name, $type);
     146            return $file_name;
     147        }
     148
    129149        $type = sanitize_file_name($type);
    130150        $file_name = preg_replace('/[^a-z0-9\._-]+/', '-', strtolower(get_bloginfo('name') . "-menu-" . $type));
     
    174194    {
    175195        $files = $this->scan_dir($this->return_menu_upload_path());
     196
    176197
    177198        if (!is_array($files)) {
     
    188209                $original_file_name = $this->plugin_configs->get_option_nsc_eprm($type['menutype'] . "_orifilename", "none");
    189210                $extension = pathinfo($original_file_name, PATHINFO_EXTENSION);
    190                 if ($file === $this->return_menu_file_name_without_extension($type['menutype']) . "." . $extension) {
     211                $fileNameOfType = $this->return_menu_file_name_without_extension($type['menutype'], $useOriFileName) . "." . $extension;
     212
     213                if ($file === $fileNameOfType) {
     214                    $file_needed = true;
     215                    break;
     216                }
     217
     218                // not found. maybe recently toggled "use orifilename". So try to migrate.
     219                $fileNameOfTypeNoToggle = $this->return_menu_file_name_without_extension($type['menutype'], !$useOriFileName) . "." . $extension;
     220                if ($file === $fileNameOfTypeNoToggle) {
     221                    $currentFilePath = $this->return_menu_upload_path() . $file;
     222                    $targetFilePath = $this->return_menu_upload_path() . $fileNameOfType;
     223                    rename(
     224                        $currentFilePath,
     225                        $targetFilePath
     226                    );
    191227                    $file_needed = true;
    192228                    break;
     
    237273        $uploadDirArray = wp_upload_dir();
    238274
    239         $defaultUploadDirPath = realpath($uploadDirArray['basedir']);
    240275        $defaultUploadDirURL = $uploadDirArray['baseurl'];
    241276
     
    248283    private function return_menu_file_name_for_download($type)
    249284    {
    250         $filename = "error_no_file_found_please_upload_in_MEDIA-EASY_PDF_MENU.";
    251285        $files = $this->scan_dir($this->return_menu_upload_path());
    252286
    253287        if (!is_array($files)) {
    254             return $fileName;
    255         }
     288            return "error_files_is_not_an_array_should_not_happen";
     289        }
     290
     291        $useOriFileName = $this->plugin_configs->get_option_nsc_eprm("orifilename_for_download") == true ? true : false;
     292
    256293        foreach ($files as $file) {
    257             if (pathinfo($file, PATHINFO_FILENAME) == $this->return_menu_file_name_without_extension($type)) {
    258                 $filename = $file;
    259                 break;
    260             }
    261         }
    262         return $filename;
     294            if (pathinfo($file, PATHINFO_FILENAME) == $this->return_menu_file_name_without_extension($type)) {
     295                $file;
     296           
     297        }
     298
     299        return ;
    263300    }
    264301
     
    268305
    269306        if (empty($anchorText)) {
    270             $fileName = $this->plugin_configs->get_option_nsc_eprm($menuType . "_orifilename", "none");
    271             $fileName = pathinfo($fileName, PATHINFO_FILENAME);
    272             $anchorText = $fileName;
     307            $fileame = $this->plugin_configs->get_option_nsc_eprm($menuType . "_orifilename", "none");
     308            $fileame, PATHINFO_FILENAME);
     309            $anchorText = $file;
    273310        }
    274311
  • easy-pdf-restaurant-menu-upload/trunk/nsc_easy-pdf-restaurant-menu.php

    r3002932 r3066207  
    55Author:            Beautiful WP | made in Germany
    66Author URI:        https://beautiful-wp.com/
    7 Version: 1.7.1
     7Version: 1.
    88Text Domain: easy-pdf-restaurant-menu
    99License: GPL3
  • easy-pdf-restaurant-menu-upload/trunk/plugin-config.json

    r2859208 r3066207  
    3030            "pre_selected_value": false,
    3131            "additional_text": "Currently live:<span style='font-weight: bold'>{{current_lunch_menu_filename}}</span>",
    32             "helpertext": "Shortcode: [nsc_eprm_menu_link restaurant_menu_type='lunch' linktext='Lunch menu']",
     32            "helpertext": "Shortcode: [nsc_eprm_menu_link restaurant_menu_type='lunch' linktext='Lunch menu']",
    3333            "name": "Lunch Menu",
    3434            "save_in_db": false
     
    4141            "pre_selected_value": false,
    4242            "additional_text": "Currently live:<span font-weight: bold'>{{current_general_menu_filename}}</span>",
    43             "helpertext": "Shortcode: [nsc_eprm_menu_link restaurant_menu_type='general' linktext='General Menu']",
     43            "helpertext": "Shortcode: [nsc_eprm_menu_link restaurant_menu_type='general' linktext='General Menu']",
    4444            "name": "General Menu",
    4545            "save_in_db": false
     
    6565            "helpertext": "If you check this all admin users are redirected after login to the menu upload page. If unchecked, only users with role 'Restaurant Menu Uploader' are redirected.",
    6666            "name": "Force redirect for all after login",
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
    6778            "save_in_db": true
    6879          },
  • easy-pdf-restaurant-menu-upload/trunk/readme.txt

    r3002932 r3066207  
    33Requires at least: 4.0
    44Donate link: https://www.paypal.me/nikelschubert/6.00EUR
    5 Tested up to: 6.4
     5Tested up to: 6.
    66Requires PHP: 5.3
    7 Stable tag: 1.7.1
     7Stable tag: 1.
    88License: GPLv3
    99
     
    6262
    6363== Changelog ==
     64
     65
     66
     67
    6468
    6569= 1.7.1 =
Note: See TracChangeset for help on using the changeset viewer.