Plugin Directory

Changeset 3308108


Ignore:
Timestamp:
06/08/2025 04:38:27 PM (8 months ago)
Author:
wibergsweb
Message:

3.57 - Internal fixes regarding to object handling (singleton). Bugfix excel more columns than Z.

Location:
csv-to-html
Files:
891 added
3 edited

Legend:

Unmodified
Added
Removed
  • csv-to-html/trunk/csvtohtml.php

    r3258805 r3308108  
    44Plugin URI: http://www.wibergsweb.se/plugins/csvtohtml
    55Description:Display/edit/synchronize csv-file(s) dynamically into a html-table
    6 Version: 3.54
     6Version: 3.57
    77Author: Wibergs Web
    88Author URI: http://www.wibergsweb.se/
     
    1616use PhpOffice\PhpSpreadsheet\Writer\Csv;
    1717use PhpOffice\PhpSpreadsheet\Spreadsheet;
     18use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
    1819
    1920if( !class_exists('csvtohtmlwp') )
     
    2223    class csvtohtmlwp
    2324    {
     25    private static $instance = null;                //Use this class as singleton object. Store it in this variable
     26    private $source_type = 'guess';                 //Sourcetype stored in object. Usage from external sources , like addons
     27    private $nr_cols = 0;                           //Number of columns stored in object. Usage: external sources
     28    private $all_rowdata;                           //Stores an array of all row data (excluding filters etc)
     29
    2430    private $csv_delimit;                           //Used when using anonymous function in array_map when loading file(s) into array(s)   
    2531    private $title;                                 //Used together with sourcetype guessonecol
     
    3844
    3945    /**
     46     *  get_instance()
     47     *
     48     *  @param  void           
     49     *  @return object              instance of this class (singleton)
     50     *
     51     */   
     52    public static function get_instance()
     53    {
     54        if ( self::$instance === null )
     55        {
     56            self::$instance = new self();
     57        }
     58        return self::$instance;
     59    }
     60
     61
     62    /**
     63     *  get_sourcetype()
     64     *
     65     *  This function will return sourcetype
     66     *
     67     *  @param  void           
     68     *  @return string          source type
     69     *
     70     */   
     71    public function get_sourcetype()
     72    {
     73        return $this->source_type;
     74    }
     75
     76
     77    /**
     78     *
     79     *  get_nrcols()
     80     *
     81     *  This function will return number of columns in current fetched file(s)
     82     *
     83     *  @param  void           
     84     *  @return integer                 Number of columns found
     85     *
     86     */   
     87    public function get_nrcols()
     88    {
     89        return $this->nr_cols;
     90    }
     91
     92
     93    /**
     94     *
     95     *  get_rowdata()
     96     *
     97     *  This function will return rows of current fetched file(s)
     98     *
     99     *  @param  void           
     100     *  @return array                   Array of rows
     101     *
     102     */   
     103    public function get_rowdata() {
     104        return $this->all_rowdata;
     105    }
     106   
     107   
     108    /**
    40109    *  Constructor
    41110    *
     
    44113    *  @param   N/A
    45114    *  @return  N/A
     115    *
    46116    */ 
    47     public function __construct()
     117    private function __construct()
    48118    {           
    49119        if ( ! function_exists( 'WP_Filesystem' ) )
     
    95165            'name' => true,
    96166            'type' => true,
     167            'value' => true,
    97168            '?' => true
    98169            )
     
    103174    }
    104175
     176
     177    /**
     178    *  on_activation()
     179    *
     180    *  on activation of this plugin
     181    *
     182    *  @param   N/A
     183    *  @return  N/A
     184    *
     185    */     
    105186    public static function on_activation()
    106187    {
     
    113194    }
    114195
     196
     197    /**
     198    *  on_deactivation()
     199    *
     200    *  on deactivation of this plugin
     201    *
     202    *  @param   N/A
     203    *  @return  N/A
     204    *
     205    */     
    115206    public static function on_deactivation()
    116207    {
     
    123214    }
    124215
     216   
    125217    /**
    126218     *
     
    448540        $data = [];     
    449541        $html = '';
    450         $html = apply_filters( 'csvtohtml_before_table_html', $html, $new_arr );       
     542        $html = apply_filters( 'csvtohtml_before_table_html', $html );       
    451543
    452544        if (isset( $_POST) )
     
    9291021    {   
    9301022        $this->check_permission('manage_options');
    931         echo '<h1>CSV to HTML Shortcode Generator</h1>';
     1023        echo '<h1 class="shortcode-generator">CSV to HTML Shortcode Generator</h1>';
    9321024        echo '<form id="previewbuttonform" spellcheck="false"><input type="button" id="update_shortcode" value="Update/Preview"></form>';
    9331025 
     
    10531145        $rows_arr =  $this->source_to_table( $temp_attribs );
    10541146
     1147        if ( !empty ( $rows_arr ) )
     1148        {
     1149            $this->all_rowdata = array_slice($rows_arr,0);
     1150        }
     1151
    10551152        //Calculate cols and rows
    10561153        $nr_cols = 0;
     1154        $this->nr_cols = 0;
    10571155        if ( isset( $rows_arr[0] ) )
    10581156        {
    10591157            $nr_cols = count( $rows_arr[0] );
    1060         }
     1158            $this->nr_cols = $nr_cols;
     1159        }
     1160
    10611161        if ( $temp_attribs['source_type'] === 'guessonecol' )
    10621162        {
     
    10781178        {
    10791179            $nr_cols = 1;
     1180            $this->nr_cols = 1;
    10801181        }
    10811182
     
    30183119            'filter_criterias' => '',                           //and,or -logic when filtering: in format col,col,col or col,col (e.g. 1,6 or 2,9)
    30193120            'groupby_col' => null,                              //Group values by this column
    3020             'groupby_col_header' => 'yes',                      //Set new header within the table for each grouping
     3121            'groupby_col_header' => 'no',                      //Set new header within the table for each grouping
    30213122            'eol_detection' => 'auto',                          //Use linefeed when using external files, Default auto = autodetect, CR/LF = Carriage return when using external files, CR = Carriage return, LF = Line feed
    30223123            'convert_encoding_from' => null,                    //If you want to convert character encoding from source. (use both from and to for best result)
     
    30623163            'htmltags_autoconvert_imagealt' => '',              //Set alt text based on a specific columns value (Or same text for all images if you just set some text here instead of a number)
    30633164            'htmltags_autoconvert_imagewidth' => null,          //Width of converted images, can be set in px (default), %, vw, em, rem etc
    3064             'totals_cols_bottom_countlines' => null,            //Total number of lines
     3165            'totals_cols_bottom_countlines' => 'no',            //Total number of lines
    30653166            'totals_cols_bottom' => null,                       //Add totals with given columns at bottom of table (example 1,2,4 or 1-2,4)
    30663167            'totals_cols_bottom_empty' => '',                   //What string/character (maybe a zero?) to show when there's no calculation
     
    33723473                {
    33733474                    $highestRow = $sheet->getHighestRow();
    3374                     $highestColumn = $sheet->getHighestColumn();
    3375    
     3475                    $highestColumn = $sheet->getHighestColumn(); //This is in letter-format.
    33763476                    for ( $row = 1; $row <= $highestRow; $row++ )
    33773477                    {
    3378                         $rowData = [];
    3379                         for ( $col = 'A'; $col <= $highestColumn; $col++ )
     3478                        $rowData = [];                       
     3479                        //Compare with indexes instead of just letters for stable comparions
     3480                        $highestColumnIndex = Coordinate::columnIndexFromString($highestColumn);
     3481                        for ( $col = 1; $col <= $highestColumnIndex; $col++ )
    33803482                        {
    3381                             $cell = $sheet->getCell( $col . $row );
     3483                            $colLetter = Coordinate::stringFromColumnIndex($col);
     3484                            $cell = $sheet->getCell( $colLetter . $row );
    33823485                            $value = $cell->getValue();
    33833486   
     
    35303633        }
    35313634                               
     3635        $this->source_type = $source_type;
    35323636        $this->csv_delimit = $csv_delimiter; //Use this char as delimiter       
    35333637        if ( $excel_convertdates === "yes" )
     
    53795483}
    53805484       
    5381 $csvtohtmlwp = new csvtohtmlwp();
     5485csvtohtmlwp::get_instance();
     5486
    53825487// Register activation and deactivation hooks
    53835488register_activation_hook(__FILE__, array('csvtohtmlwp', 'on_activation'));
  • csv-to-html/trunk/js/wibergsweb198.js

    r3240486 r3308108  
    6262   
    6363    //Shortcode creation help function
    64     function  check_length( input_type , element_name ) {
     64    window.check_length = function( input_type , element_name ) {
     65        var use_val = true;
     66
    6567        var tp = 'input';
    6668        if (input_type=='select') {
    6769          tp = 'select';
    6870        }
     71        if (input_type=='button') {
     72            tp = 'button';
     73            use_val = false; //Use attr instead
     74        }
    6975        var element_nofrm = element_name.substr(4); //Remove four first chars (frm_)
    7076   
    7177        //Value exists, return value
    7278        //If no html-object found, just return ''
    73         let el_val = $('#dynamic_form').find(tp + '[name="' + element_name  + '"]').val();
     79        let el_val;
     80        if ( use_val === true ) {
     81            el_val = $('#dynamic_form').find(tp + '[name="' + element_name  + '"]').val();
     82        }
     83        else {
     84            el_val =  $('#shortcode_preview').find(tp + '[name="' + element_name + '"]').attr('value');
     85        }
     86       
    7487        if (!el_val) {return '';}
    7588
     
    94107
    95108    //Shortcode creation help function
    96     function generate_shortcode() {
     109    window.generate_shortcode = function() {
     110
    97111        var sc_arr = [];
    98112   
     
    236250        sc_arr.push ( check_length('select', 'frm_grabcontent_col_fromlink'));
    237251        sc_arr.push ( check_length('select', 'frm_grabcontent_col_tolink'));
    238         sc_arr.push ( check_length('select', 'frm_grabcontent_col_tolink_addhttp'));
     252        sc_arr.push ( check_length('select', 'frm_grabcontent_col_tolink_addhttps'));
    239253
    240254        sc_arr.push(']');       
     
    246260    //If path / files etc has changed, values in form must be updated
    247261    //regarding to columns, rows etc
    248     function updatevalues_fromshortcode() {
     262    window.updatevalues_fromshortcode = function() {
    249263        let selected_value = $('#new_shortcode').val();
    250264       
    251265        var current_url = my_ajax_object.ajax_url; 
     266
     267        //Store focus and position of textarea
     268        let isFocused = $('#new_shortcode').is(':focus');
     269        let cursorPos = $('#new_shortcode')[0].selectionStart;
     270
    252271        $.ajax({
    253272            url: current_url,
     
    263282        .done(function( response ) {       
    264283            $('#dynamic_form').html( response );
     284
     285            //Restore focus and position of textarea after update dynamic form
     286            if (isFocused) {
     287                $('#new_shortcode').focus();
     288                $('#new_shortcode')[0].setSelectionRange(cursorPos, cursorPos);
     289            }
     290
    265291            $("div.csvtohtml-p.admin h2").on( "click", function() {
    266292                $(this).parent().toggleClass('selectedsection');
  • csv-to-html/trunk/readme.txt

    r3259859 r3308108  
    55Requires PHP: 8.0
    66Requires at least: 3.0.1
    7 Tested up to: 6.7.2
    8 Stable Tag: 3.54
     7Tested up to: 6.8.1
     8Stable Tag: 3.57
    99License: GPLv2
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    141141* CSV to HTML addon
    142142
     143= 3.57 = (2025-06-08)
     144Internally now using the class as singleton (good for using this plugin from other plugins etc)
     145get_sourcetype(), get_nrcols(), get_rowdata() can now be used from external sources. Making update_valuesfromshortcode() globally available in the js windows object
     146Group by column default is now set to no
     147Selection of sheet bugfix when using more columns than the letter Z.
     148
    143149= 3.54 = (2025-03-19)
    144150programmatically use new attribute rows_array_all_cols_rows to fetch all columns and rows as an array
Note: See TracChangeset for help on using the changeset viewer.