Plugin Directory

Changeset 2130839


Ignore:
Timestamp:
07/30/2019 01:51:59 PM (7 years ago)
Author:
calj
Message:

Support for lang property in shortcode

Location:
calj/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • calj/trunk/CalJPlugin.php

    r1559123 r2130839  
    2828    {
    2929        $decodedAttr = shortcode_atts( array(
    30             'val' => ''
     30            'val' => '',
     31            'lang' => '',
     32            'city' => ''
    3133        ), $atts );
    3234
     
    7274        if (isset($json['success']) && $json['success']) {
    7375
     76            $city = $decodedAttr['city'];
     77            $lang = $decodedAttr['lang'];
     78
    7479            // dot notation to access the json properties
    7580            $jsonPath = preg_split('#\.#', $decodedAttr['val']);
     
    7782            for($i = 0; $i < count($jsonPath); ++ $i) {
    7883                $component = $jsonPath[$i];
    79                 if (array_key_exists($component, $jsonCursor)) {
     84
     85                // If the component name exists with a 'Loc' suffix,
     86                // treat it as an array of language codes
     87                if ($lang &&
     88                    array_key_exists($component.'Loc', $jsonCursor) &&
     89                    is_array($jsonCursor[$component.'Loc']) &&
     90                    array_key_exists($lang, $jsonCursor[$component.'Loc'])
     91                ) {
     92                    $jsonCursor = $jsonCursor[$component.'Loc'][$lang];
     93                }
     94
     95                else if (array_key_exists($component, $jsonCursor)) {
    8096                    $jsonCursor = $jsonCursor[$component];
    8197                }
     
    109125            $key = $options['api_key'];
    110126            $city = $options['city'];
    111             $response = file_get_contents('http://api.calj.net/wp/1/shabbat.json?city='.$city.'&key='.$key);
     127            $response = file_get_contents('https://api.calj.net/wp/1/shabbat.json?city='.$city.'&key='.$key);
    112128
    113129            $response = json_decode($response, true);
  • calj/trunk/readme.txt

    r2127860 r2130839  
    55Requires at least: 4
    66Tested up to: 5.2.2
    7 Stable tag: 1.1.1
     7Stable tag: 1.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    21211. Activate the plugin through the 'Plugins' screen in WordPress
    22221. Use the Settings->CalJ screen to configure the plugin
    23 1. Register for an API key on http://www.calj.net/api
     231. Register for a free API key for your current WordPress instance inside the Settings Form
    2424
    2525
     
    3737
    3838  Prints the name of the current week's Parasha.
     39
     40* `[caljshabbat val="shabbat.parasha" lang="he"]`
     41
     42  Prints the name of the current week's Parasha in Hebrew.
    3943
    4044* `[caljshabbat val="shabbat.begins"]`
     
    6670  Prints the name of the Jewish month of Shabbat.
    6771
     72* `[caljshabbat val="shabbat.jmonthName" lang="ru"]`
     73
     74  Prints the name of the Jewish month of Shabbat in Russian.
     75
    6876* `[caljshabbat val="shabbat.jyear"]`
    6977
     
    8290== Changelog ==
    8391
     92= 1.2 =
     93Support for additional languages.
     94
    8495= 1.1 =
    8596Added Daf Yomi.
Note: See TracChangeset for help on using the changeset viewer.