Plugin Directory

Changeset 1333533


Ignore:
Timestamp:
01/22/2016 08:56:03 AM (10 years ago)
Author:
calj
Message:

more shortcode values

Location:
calj/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • calj/trunk/CalJPlugin.php

    r1331961 r1333533  
    8080
    8181        if (isset($json['success']) && $json['success']) {
    82             switch($decodedAttr['val']) {
    83                 case 'shabbatBegins': $result = $json['shabbat']['begins']; break;
    84                 case 'shabbatEnds': $result = $json['shabbat']['ends']; break;
    85                 case 'parasha': $result = $json['shabbat']['parasha']; break;
    86                 case 'cityName': $result = $json['city']['name']; break;
    87                 default:  break;
     82
     83            // dot notation to access the json properties
     84            $jsonPath = preg_split('#\.#', $decodedAttr['val']);
     85            $jsonCursor = $json;
     86            for($i = 0; $i < count($jsonPath); ++ $i) {
     87                $component = $jsonPath[$i];
     88                if (array_key_exists($component, $jsonCursor)) {
     89                    $jsonCursor = $jsonCursor[$component];
     90                }
     91                else {
     92                    $jsonCursor = '';
     93                    break;
     94                }
     95            }
     96
     97            if (is_array($jsonCursor)) {
     98                $result = '';
     99            }
     100            else {
     101                $result = $jsonCursor;
    88102            }
    89103        }
     
    98112            $city = $options['city'];
    99113            $response = file_get_contents('http://api.calj.net/wp/1/shabbat.json?city='.$city.'&key='.$key);
    100             $response = self::xorString(base64_decode($response));
    101114
    102115            $response = json_decode($response, true);
    103             if (! $response) {
     116            if ( (! $response) || (! isset($response['data'])) || (! $response['data']) ) {
     117                return null;
     118            }
     119
     120            $response = json_decode( self::xorString($response['data']), true );
     121            if ( ! $response ) {
    104122                return null;
    105123            }
     
    145163        // Iterate through each character
    146164        for($i = 0; $i < strlen($text); )
    147      for($j = 0; ($j < strlen($key) && $i < strlen($text)); $j++, $i++)
    148          $outText .= $text{$i} ^ $key{$j};
     165            for($j = 0; ($j < strlen($key) && $i < strlen($text)); $j++, $i++)
     166                $outText .= $text{$i} ^ $key{$j};
    149167
    150168        return $outText;
  • calj/trunk/readme.txt

    r1331973 r1333533  
    3030The `caljshabbat` shortcode accepts several directives, which you can arrange the way you want in your pages.
    3131
    32 * `[caljshabbat val="cityName"]`
     32* `[caljshabbat val="city.name"]`
    3333
    3434  Prints the name of the location for which you are showing the times. You may configure the city on the CalJ API configuration page.
    3535
    36 * `[caljshabbat val="parasha"]`
     36* `[caljshabbat val="shabbat.parasha"]`
    3737
    3838  Prints the name of the current week's Parasha.
    3939
    40 * `[caljshabbat val="shabbatBegins"]`
     40* `[caljshabbat val="shabbat.begins"]`
    4141
    42   Prints the candle-lighting time for the forecoming Shabbat, in 24-hour format.
     42  Prints the candle-lighting time for the forthcoming Shabbat, in 24-hour format.
    4343
    44 * `[caljshabbat val="shabbatEnds"]`
     44* `[caljshabbat val="shabbat.ends"]`
    4545
    4646  Prints the end of shabbat, in 24-hour format.
     47
     48* `[caljshabbat val="shabbat.day"]`
     49
     50  Prints the day of month (secular) of Shabbat.
     51
     52* `[caljshabbat val="shabbat.month"]`
     53
     54  Prints the month number (secular) of Shabbat.
     55
     56* `[caljshabbat val="shabbat.year"]`
     57
     58  Prints the year (secular) of Shabbat.
     59
     60* `[caljshabbat val="shabbat.jday"]`
     61
     62  Prints the day of month (Jewish) of Shabbat.
     63
     64* `[caljshabbat val="shabbat.jmonthName"]`
     65
     66  Prints the name of the Jewish month of Shabbat.
     67
     68* `[caljshabbat val="shabbat.jyear"]`
     69
     70  Prints the Jewish year of Shabbat.
    4771
    4872
Note: See TracChangeset for help on using the changeset viewer.