public static function log($logs, $extraTags = array())
 {
     if (!defined('LOGGLY_API_KEY') || !defined('LOGGLY_ENV') || !is_array($logs) || !is_array($extraTags)) {
         return self::error_log($logs);
     }
     // Create a "cached" URL and array of tags
     if (!is_string(self::$_url) || !is_array(self::$_default_tags)) {
         self::$_url = self::LOGGLY_ENDPOINT . LOGGLY_API_KEY . '/tag/';
         self::$_default_tags = array(self::LOGLLY_HTTP_TAG, self::KIGO_WP_PLUGIN_TAG . '-' . LOGGLY_ENV);
     }
     $logs = array('CONTENT' => $logs, 'SERVER_NAME' => $_SERVER['SERVER_NAME']);
     $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => json_encode($logs))));
     if (!is_string($reply = @file_get_contents(self::$_url . implode(',', array_merge(self::$_default_tags, $extraTags)), null, $context)) || !is_array($http_response_header) || !isset($http_response_header[0]) || false === strpos($http_response_header[0], '200') || !is_array($response = json_decode($reply, true)) || !isset($response['response']) || 'ok' !== $response['response']) {
         return self::error_log($logs, true);
     }
     return self::error_log($logs);
 }
Пример #2
0
function kigo_get_site_language()
{
    if (!is_array($solution_data = BAPISync::getSolutionData()) || !is_array($solution_data['Site']) || !is_string($solution_data['Site']['Language'])) {
        Loggly_logs::log(array('msg' => 'Unable to retrieve site language from solution data.', 'blog_id' => get_current_blog_id()));
        return 'en-US';
    }
    return $solution_data['Site']['Language'];
}
Пример #3
0
 /**
  * Handle the errors log if any
  * 
  * @param $debug_mode
  */
 private static function handle_logs($echo_logs = false)
 {
     if (count($logs = array_merge(self::$sync_error_logs, self::$wp_die_logs))) {
         if ($echo_logs) {
             echo '<pre>';
             print_r($logs);
             echo '</pre>';
         } else {
             Loggly_logs::log($logs, array(self::LOGGLY_TAG));
         }
     }
 }
Пример #4
0
 /**
  * Echo the json response and exist
  * 
  * @param boolean $success
  * @param string $msg
  * @param array $data
  */
 private static function echo_json_response($success, $msg = '', $data = array())
 {
     header('Content-Type: application/json');
     if (!is_bool($success) || !is_string($msg) || !is_array($data)) {
         $data = array('success' => $success, 'msg' => $msg, 'data' => $data);
         Loggly_logs::log($data, array(self::LOGGLY_LOG_TAG_FATAL));
         echo json_encode(array('success' => false, 'msg' => 'Incorect parameters passed to method: ' . __METHOD__, 'data' => $data));
         exit;
     }
     echo json_encode(array('success' => $success, 'msg' => $msg, 'data' => $data));
     exit;
 }
 /**
  * Retrieve all the default and overwritten translations, and apply search and sort on it.
  * 
  * @param $nb_items
  *
  * @return array|null
  */
 private function _prepare_items(&$nb_items)
 {
     if (!is_string($lang_code = kigo_get_site_language()) || !is_array($translations = kigo_I18n::get_translations_for_edit($lang_code))) {
         Loggly_logs::log(array('msg' => 'Unable to retrieve translation for edit', 'lang_code' => $lang_code), array(kigo_I18n::LOGGLY_LOG_TAG_FATAL));
         return null;
     }
     // Handle the input search
     if (isset($_GET['s']) && strlen($search = wp_unslash(trim($_GET['s'])))) {
         $translations = array_filter($translations, function ($item) use($search) {
             return false !== stripos($item['key'], $search) || false !== stripos($item['default_value'], $search) || false !== stripos($item['value'], $search);
         });
     }
     $nb_items = count($translations);
     if (!isset($_REQUEST['orderby']) || !strlen($orderby = $_REQUEST['orderby']) || !in_array($orderby, array_keys(self::$sortable_colums))) {
         $orderby = 'key';
     }
     if (!isset($_REQUEST['order']) || !strlen($order = $_REQUEST['order']) || !in_array($orderby, array('asc', 'desc'))) {
         $order = 'asc';
     }
     uasort($translations, function ($item_a, $item_b) use($orderby, $order) {
         return ('desc' === $order ? -1 : 1) * strnatcasecmp($item_a[$orderby], $item_b[$orderby]);
     });
     return array_slice($translations, ($this->get_pagenum() - 1) * Kigo_Translations_List_Table::TRANSLATIONS_PER_PAGE, Kigo_Translations_List_Table::TRANSLATIONS_PER_PAGE, true);
 }
Пример #6
0
 public function get($entity, $ids, $options = null)
 {
     if (!$this->isvalid()) {
         return null;
     }
     // In case init_get_cache() has been called before, try to retrieve the values from the local cache
     if (isset($this->use_cache_in_get_calls[$entity]) && $this->use_cache_in_get_calls[$entity]) {
         $fake_response = array('status' => 1, 'result' => array());
         $error = false;
         foreach ($ids as $id) {
             if (!isset($this->cache_get_call[$entity][$id])) {
                 $error = true;
                 break;
             }
             $fake_response['result'][] = $this->cache_get_call[$entity][$id];
         }
         if (!$error) {
             // In case of error, retrieving one or more id from the cache, default to the get call.
             return $fake_response;
         }
     }
     $url = $this->baseURL . "/ws/?method=get&apikey=" . $this->apikey . "&entity=" . $entity . '&ids=' . implode(",", $ids);
     if (!empty($options)) {
         $url = $url . "&" . http_build_query($options);
     }
     // adding <meta> on the page, for debugging purposes
     global $entityUpdateURL;
     $entityUpdateURL = $url;
     add_action('wp_head', 'bapi_add_entity_meta', 1);
     $response = wp_remote_get($url, array('sslverify' => !(defined('KIGO_DEBUG') && KIGO_DEBUG), 'timeout' => 50, 'headers' => array('User-Agent' => 'InstaSites Agent')));
     if (is_wp_error($response)) {
         Loggly_logs::log(array('BAPI get faillure', $response->get_error_message()), array('wp_bapi'));
         return false;
     }
     if (is_array($response) && isset($response['response']) && is_array($response['response']) && isset($response['response']['code']) && $response['response']['code'] == 200 && isset($response['body']) && is_string($response['body'])) {
         // BAPI also returns 200 when there are problems. So if the entity doesn't seem to be correctly retrieved, consider it a resource not found (404)
         if (!self::json_decode($decoded, $response['body']) || isset($decoded['error']) || !isset($decoded['status']) || $decoded['status'] != '1' || !isset($decoded['result']) || !is_array($decoded['result'])) {
             return true;
             // "not found"
         }
         return $decoded;
     }
     return false;
 }