function save_options($validate = true) { $profile_url = $this->get_user_profile_url(); $data = $this->lifestream->file_get_contents($profile_url); if (preg_match('<input type="hidden" id="user_id" name="user_id" value="(\\d+)" />', $data, $matches)) { $this->add_option('user_id', $matches[1]); } else { throw new Lifestream_Error("Error getting User ID from profile page source: " . $this->get_user_profile_url() . "\n(if you don't see your profile page under this link then you entered wrong username)"); } $url = $this->get_url(); if ($validate) { $data = $this->lifestream->file_get_contents($url); $json = json_decode($data); # json_last_error function is available in PHP 5.3.0 or newer if (version_compare(PHP_VERSION, '5.3', '>=')) { if (json_last_error() != JSON_ERROR_NONE) { $sample = substr($data, 0, 150); throw new Lifestream_FeedFetchError("Error fetching JSON format from " . $url . "\n(Received: " . $sample . ")"); } } else { if (!$data || $data && $json === NULL) { $sample = substr($data, 0, 150); throw new Lifestream_FeedFetchError("Error fetching JSON format from " . $url . "\n(Received: " . $sample . ")"); } } } parent::save_options(); }
function save_options($validate = true) { $urls = $this->get_url(); if (!is_array($urls)) { $urls = array($urls); } $url = $urls[0]; if (is_array($url)) { $url = $url[0]; } $feed = new SimplePie(); $feed->enable_cache(false); if ($validate) { $data = $this->lifestream->file_get_contents($url); $feed->set_raw_data($data); $feed->enable_order_by_date(false); $feed->force_feed(true); $success = $feed->init(); } if ($this->get_option('auto_icon') == 2 && ($url = $feed->get_favicon())) { if ($this->lifestream->validate_image($url)) { $this->update_option('icon_url', $url); } else { $this->update_option('icon_url', ''); } } // elseif ($this->get_option('icon_url')) // { // if (!$this->lifestream->validate_image($this->get_option('icon_url'))) // { // throw new Lifestream_Error($this->lifestream->__('The icon url is not a valid image.')); // } // } parent::save_options(); }