コード例 #1
0
ファイル: amber.php プロジェクト: genevec/amber_wordpress
 public static function ajax_get_url_status()
 {
     if (isset($_REQUEST['url']) && isset($_REQUEST['country'])) {
         header("Content-Type: application/json");
         header("Cache-Control: no-cache, must-revalidate");
         header("Pragma: no-cache");
         header("Expires: 0");
         $lookup = Amber::get_availability();
         $lookup_result = $lookup->get_status($_REQUEST['url'], $_REQUEST['country']);
         if ($lookup_result === FALSE || !isset($lookup_result['data'])) {
             status_header(500);
             die;
         }
         foreach ($lookup_result['data'] as $key => $value) {
             $lookup_result['data'][$key]['behavior'] = Amber::get_behavior($lookup_result['data'][$key]['available']);
         }
         print json_encode($lookup_result, JSON_UNESCAPED_SLASHES);
         status_header(200);
     } else {
         status_header(400);
     }
     die;
 }
コード例 #2
0
ファイル: amber.php プロジェクト: su/amber_wordpress
 /**
  * Build the data- attributes to be added to the anchor tag, given saved metadata
  * @param array $summaries array dictionary from the Amber Status module
  * @return array attributes to be added to the link
  */
 private static function build_link_attributes($summaries)
 {
     $result = array();
     // Assume that we only have one cache of the data. This would need to change if we start tracking multiple caches
     if (isset($summaries['default']['location'], $summaries['default']['date'], $summaries['default']['size']) && $summaries['default']['size'] > 0) {
         $result['data-versionurl'] = join("/", array(get_site_url(), $summaries['default']['location']));
         $result['data-versiondate'] = date('c', $summaries['default']['date']);
     } else {
         return $result;
     }
     $default_status = isset($summaries['default']['status']) ? $summaries['default']['status'] : null;
     // Add default behavior
     if (!is_null($default_status)) {
         $behavior = Amber::get_behavior($default_status);
         if ($behavior) {
             $result['data-amber-behavior'] = $behavior;
         } else {
             $result['data-amber-behavior'] = "";
         }
     }
     // See if we have country-specific behavior
     if ($country = Amber::get_option('amber_country_id', '')) {
         $country_status = isset($summaries[$country]['status']) ? $summaries[$country]['status'] : $default_status;
         if (!is_null($country_status)) {
             $country_behavior = Amber::get_behavior($country_status, true);
             // Add country-specific behavior only if it is different than the default behavior
             if ($country_behavior && $country_behavior != $result['data-amber-behavior']) {
                 $result['data-amber-behavior'] .= ",{$country} {$country_behavior}";
             }
         }
     }
     return $result;
 }
コード例 #3
0
 function test_get_behavior_country_down_hover()
 {
     update_option('amber_options', array('amber_unavailable_action' => AMBER_ACTION_NONE, 'amber_unavailable_action_hover' => 1, 'amber_country_unavailable_action' => AMBER_ACTION_HOVER, 'amber_country_unavailable_action_hover' => 5));
     $this->assertEquals("down hover:5", Amber::get_behavior(false, true));
 }