site =& $site; $this->path =& $path; $this->fields = $fields; # Request server => get raw XML feed $feed = wp_remote_get( "http://{$this->site}/{$this->path}" ); # Getting XML content $xmlContent = ( is_array( $feed ) && ( $feed[ 'response' ][ 'code' ] == 200 ) ) ? wp_remote_retrieve_body( $feed ) : ' ERROR !!! ERROR Fetching data from CJT Server https://css-javascript-toolbox.com/ '; # Creating feed $this->feed = new SimpleXMLElement($xmlContent); } /** * put your comment there... * */ public function getAllItems() { // Initialize. $items = array(); $xmlItems = $this->feed->channel->xpath('item'); // Read only items count specifed by $count param. foreach ($xmlItems as $xmlItem) { # Read fields. $item = array(); foreach ($this->fields as $field) { $item[$field] = (string) $xmlItem->$field; } # Add to list $items[] = $item; } # Return items. return $items; } /** * put your comment there... * * @param mixed $count */ public function getLatestItems($count) { # Initialize. $items = array(); $xmlItems = $this->feed->channel->xpath('item'); # Get all available items if the total items count is less that what is originally requested if (count($xmlItems) < $count) { $count = count($xmlItems); } # Read only items count specifed by $count param. for ($currentIndex = 0; $currentIndex < $count; $currentIndex++) { # Copy only title and link. $xmlItem = $xmlItems[$currentIndex]; # Read fields. $item = array(); foreach ($this->fields as $field) { $item[$field] = (string) $xmlItem->$field; } # Add to list $items[] = $item; } # Return items. return $items; } /** * put your comment there... * */ protected function getPath() { return $this->path; } /** * put your comment there... * */ public function getSite() { return $this->site; } /** * put your comment there... * */ public function isError() { return !$this->feed || $this->feed->channel->attributes()->cjt_error; } } // End class.