예제 #1
0
 public function listProducts($limit = 9999, $category = false)
 {
     try {
         $output = array();
         $stream = new Pos_RemoteConnector(self::request('/products.js'));
         if (!$stream->getErrorMessage()) {
             $products = json_decode($stream);
             if ($category) {
                 foreach ($products as $product) {
                     foreach ($product->categories as $product_category) {
                         if ($product_category->permalink == $category) {
                             $output[] = $product;
                         }
                     }
                 }
             } else {
                 $output = $products;
             }
             return $output;
         }
     } catch (Exception $e) {
         // log $e
     }
 }
예제 #2
0
 function getCDNsets()
 {
     if ($this->_options['cdn-key'] == '') {
     } else {
         if (strlen($this->_options['cdn-key']) != 40) {
             echo "<div class='errors'>It looks like you have put in an incorrect CDN API key.</div>";
         } else {
             $result = get_transient('cdnsets');
             if ($this->_options['cdn']['status_txt'] == 'FAIL' || $result === false) {
                 require_once 'RemoteConnector.php';
                 $url = "http://api.share-and-follow.com/v1/getSets2.php?url=" . trailingslashit(get_bloginfo('url')) . "&challange=" . md5(trailingslashit(get_bloginfo('url')) . $this->_options['cdn-key']);
                 $control = new Pos_RemoteConnector($url);
                 $result = $control->__toString();
                 if ($result != false) {
                     set_transient('cdnsets', $result, 60 * 60);
                 }
             }
             if ($result === false) {
                 echo $control->getErrorMessage();
             } else {
                 $replies = json_decode($result, true);
                 if ($replies['status_txt'] == 'FAIL') {
                     $this->_options['cdn']['status_txt'] = 'FAIL';
                     $this->update_plugin_options();
                     return "<div class='errors'>The following error has happened : " . $replies['data'] . "</div>";
                 } else {
                     $this->_options['cdn'] = json_decode($result, true);
                     // jason format
                     $this->update_plugin_options();
                 }
             }
         }
     }
 }