$name)) return $this->$name; else return null; } public function forMobile() { return $this->displayMobile; } public function forDesktop() { return $this->displayDesktop; } public function isCountable() { return $this->countable; } public function get_nice_name() { if (isset($this->nice_name)) return $this->nice_name; else return ucfirst($this->network); } public function getRemoteShareCount($share_url) { if (! $this->countable) return false; $count_api = $this->count_api; if ($count_api == '') return false; // no api $network = $this->network; $timeout = 60; // prevent the same requests from running multiple times ( i.e. one page, many collections on same url ) . $locked = maxUtils::get_transient('shares-' . $network . '-' . $share_url. '-lock'); if ($locked == true) return 'locked'; // try again on next refresh. //lock out next request while this one is still running. maxUtils::set_transient('shares-' . $network . '-' . $share_url . '-lock', true, $timeout ); $count_api = str_replace("{url}", $share_url, $count_api); $count = $this->remoteRequest($count_api); if (defined('MAXBUTTONS_DEBUG') && MAXBUTTONS_DEBUG) { $admin = MB()->getClass("admin"); $admin->log("Get Remote Share", "Call: $count_api - Network : " . $this->network . " - Count: $count \n "); } if ($count !== false) { $network = $this->network; $check_time = $this->count_check_time; // set count maxUtils::set_transient('shares-' . $network . '-' . $share_url, $count, $check_time ); } // remove lock maxUtils::delete_transient('shares-' . $network . '-' . $share_url . '-lock'); return $count; } protected function remoteRequest($url) { $response = wp_remote_get($url); $result_path = $this->return_var; $result_array = explode("|",$result_path); if (count($result_array) == 0) $result_array = array($result_path); if (is_wp_error($response) || $response['response']['code'] != 200) { return false; } else { $result = wp_remote_retrieve_body($response); } $result = json_decode($result, true); foreach($result_array as $result_val) { if (isset($result[$result_val])) $result = $result[$result_val]; } if (is_int($result)) return $result; return 0; // some networks don't return the json return var. Only return false on network errors } public function getShareCount($args = array()) { if ( $this->count_api == '') return 0; // no api - count always zero. $defaults = array( "url" => "", "preview" => false, "force_share_update" => false, ); $args = wp_parse_args($args,$defaults); $share_url = esc_url($args["url"]); $network = $this->network; //$count = get_transient('mb-col-' . $network . '-' . $share_url . '-shares'); $count = maxUtils::get_transient('shares-' . $network . '-' . $share_url); if ($args["force_share_update"]) $count = -1; // force an update if ( ($count === false || $count == -1) && ! $args["preview"]) { // request from external - this is done via ajax on runtime. return false; } return $count; } /** Function to display additional network-specific options. * @return String Option Output. **/ public function admin() { return ''; } }