Plugin Directory

Changeset 3274766


Ignore:
Timestamp:
04/16/2025 01:27:18 PM (10 months ago)
Author:
codeisartnet
Message:

update

Location:
codeart-units-converter/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • codeart-units-converter/trunk/codeart-units-converter.php

    r3273696 r3274766  
    1111 * Domain Path: /i18n/languages/
    1212 * Version: 2.3.0
    13  * Tested up to: 6.7.2
     13 * Tested up to: 6.8.0
    1414 */
    1515
  • codeart-units-converter/trunk/include/common.php

    r3272469 r3274766  
    6262////////////////////////////////////////////////////////////////////////////////////
    6363
     64////////////////////////////////////////////////////////////////////////////////////
     65function codeart_render_template_content($template_content, $content_array)
     66{
     67    $content = $template_content;
     68
     69    foreach ($content_array as $key => $value) {
     70        //print_r($array);
     71        $content = str_replace($key, $value, $content);
     72    }
     73
     74    return $content;
     75}
     76////////////////////////////////////////////////////////////////////////////////////
     77
     78////////////////////////////////////////////////////////////////////////////////////
     79function codeart_load_template($file_path)
     80{
     81    $content = file_get_contents(codeart_units_converter_plugin_path() . "/templates/" . $file_path);
     82
     83    return $content;
     84}
     85////////////////////////////////////////////////////////////////////////////////////
  • codeart-units-converter/trunk/include/converter/convert.php

    r3273696 r3274766  
    66    // print_r($units);
    77
     8    $item_template      = "";
     9    $container_template = "";
     10    if ($style == 'table') {
     11        $item_template      = codeart_load_template("user/units/table/item.htm");
     12        $container_template = codeart_load_template("user/units/table/container.htm");
     13    } elseif ($style == 'list') {
     14        $item_template      = codeart_load_template("user/units/list/item.htm");
     15        $container_template = codeart_load_template("user/units/list/container.htm");
     16    } else {
     17
     18    }
     19
    820    $items = "";
    921
    1022    foreach ($units as $unit) {
    1123
    12         if ($style == 'table') {
    13             $content_array = [
    14                 "{{name}}"         => $unit->name,
    15                 "{{code_name}}"    => $unit->code_name,
    16                 "{{type}}"         => $unit->type,
    17                 "__type__"         => $unit->type,
    18                 "{{abbreviation}}" => $unit->abbreviation,
    19             ];
    20             $items .= codeart_render_template("user/units/table/item.htm", $content_array);
    21         } elseif ($style == 'list') {
    22             $content_array = [];
    23             $items .= codeart_render_template("user/units/list/item.htm", $content_array);
    24         } else {
    25 
    26         }
    27     }
    28 
    29     if ($style == 'table') {
    30         $container_array = [
    31             "{{items}}" => $items,
    32             "__type__"  => $converter_type,
     24        $content_array = [
     25            "{{name}}"         => $unit->name,
     26            "{{code_name}}"    => $unit->code_name,
     27            "{{type}}"         => $unit->type,
     28            "__type__"         => $unit->type,
     29            "{{abbreviation}}" => $unit->abbreviation,
    3330        ];
    34         $container = codeart_render_template("user/units/table/container.htm", $container_array);
    35     } elseif ($style == 'list') {
    36         $container_array = [];
    37         $container     = codeart_render_template("user/units/list/container.htm", $container_array);
    38     } else {
     31        $items .= codeart_render_template_content($item_template, $content_array);
    3932
    4033    }
    4134
     35    $container_array = [
     36        "{{items}}" => $items,
     37        "__type__"  => $converter_type,
     38    ];
     39    $container = codeart_render_template_content($container_template, $container_array);
     40
    4241    return $container;
    4342}
  • codeart-units-converter/trunk/readme.txt

    r3273137 r3274766  
    55Requires at least: 4.7
    66Requires PHP: 7.0
    7 Tested up to: 6.7.2
     7Tested up to: 6.8.0
    88Stable tag: 2.3.0
    99License: GPLv3
  • codeart-units-converter/trunk/templates/user/units/list/container.htm

    r3273696 r3274766  
    6666        <div class="unit-row">
    6767            <div class="unit-group">
    68                 <input type="number" id="input1" placeholder="0" step="any" oninput="onInputChange('__type__', 'input1', 'input2', 'unit1', 'unit2')">
    69                 <select id="unit1" onchange="onInputChange('__type__', 'input1', 'input2', 'unit1', 'unit2')">
    70                     {{options}}
     68                <input type="number" id="left-text" placeholder="0" step="any" oninput="codeart_units_converter___type___get_data('__type__', document.getElementById('left-select').value, document.getElementById('left-text').value)">
     69                <select id="left-select" onchange="codeart_units_converter___type___get_data('__type__', document.getElementById('left-select').value, document.getElementById('left-text').value)">
     70                    {{items}}
    7171                </select>
    7272            </div>
    7373
    7474            <div class="unit-group">
    75                 <input type="number" id="input2" placeholder="0" step="any" oninput="onInputChange('__type__', 'input2', 'input1', 'unit2', 'unit1')">
    76                 <select id="unit2" onchange="onInputChange('__type__', 'input2', 'input1', 'unit2', 'unit1')">
    77                     {{options}}
     75                <input type="number" id="right-text" placeholder="0" step="any" oninput="codeart_units_converter___type___get_data('__type__', document.getElementById('right-select').value, document.getElementById('right-text').value)">
     76                <select id="right-select" onchange="codeart_units_converter___type___get_data('__type__', document.getElementById('right-select').value, document.getElementById('right-text').value)">
     77                    {{items}}
    7878                </select>
    7979            </div>
     
    8888
    8989<script>
    90     function codeart_units_converter___type___get_data(type, fromUnit, toUnit, value, targetInputId) {
    91         var url = CodeArtUnitsConverter.homeUrl + "/wp-json/CodeArtUnitsConverter/v1/" + type + "/?from=" + fromUnit + "&to=" + toUnit + "&v=" + value;
     90    function codeart_units_converter___type___get_data(type, unit, value) {
     91        var url = CodeArtUnitsConverter.homeUrl + "/wp-json/CodeArtUnitsConverter/v1/" + type + "/?u=" + unit + "&v=" + value;
    9292
    93         var request = new XMLHttpRequest();
     93        var request;
     94        if (window.XMLHttpRequest) {
     95            request = new XMLHttpRequest();
     96        } else if (window.ActiveXObject) {
     97            request = new ActiveXObject("Microsoft.XMLHTTP");
     98        }
     99
    94100        request.onreadystatechange = function() {
    95             if (this.readyState === 4 && this.status === 200) {
     101            if (this.readyState == 4 && this.status == 200) {
    96102                var jsonObj = JSON.parse(this.responseText);
    97                 if (jsonObj.result !== undefined) {
    98                     document.getElementById(targetInputId).value = jsonObj.result;
     103
     104                if (jsonObj.results) {
     105                    for (var key in jsonObj.results) {
     106                        if (jsonObj.results.hasOwnProperty(key)) {
     107                            // var element = document.getElementById(key);
     108                            // if (element) {
     109                            //     element.value = jsonObj.results[key];
     110                            // }
     111                            if (document.getElementById('left-select').value == key) {
     112                                document.getElementById('left-text').value = jsonObj.results[key];
     113                            }
     114                            if (document.getElementById('right-select').value == key) {
     115                                document.getElementById('right-text').value = jsonObj.results[key];
     116                            }
     117                        }
     118                    }
    99119                }
    100120            }
    101         };
     121        }
    102122
    103123        request.open("GET", url, true);
    104124        request.send();
    105125    }
    106 
    107     function onInputChange(type, sourceId, targetId, sourceUnitId, targetUnitId) {
    108         var value = document.getElementById(sourceId).value;
    109         var fromUnit = document.getElementById(sourceUnitId).value;
    110         var toUnit = document.getElementById(targetUnitId).value;
    111 
    112         if (value !== '') {
    113             codeart_units_converter___type___get_data(type, fromUnit, toUnit, value, targetId);
    114         }
    115     }
    116126</script>
  • codeart-units-converter/trunk/templates/user/units/list/item.htm

    r3273696 r3274766  
    1 <option value="{{value}}">{{name}}</option>
     1<option value="{{code_name}}">{{name}}</option>
Note: See TracChangeset for help on using the changeset viewer.