PluginProbe
CSS & JavaScript Toolbox / 8.0.2
CSS & JavaScript Toolbox v8.0.2
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
css-javascript-toolbox / framework / wordpress / feed.php

feed.php in CSS & JavaScript Toolbox 8.0.2, at framework/wordpress/feed.php

145 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 */
5
6 /**
7 *
8 */
9 class CJT_Framework_Wordpress_Feed {
10
11 /**
12 * put your comment there...
13 *
14 * @var mixed
15 */
16 protected $feed;
17
18 /**
19 * put your comment there...
20 *
21 * @var mixed
22 */
23 protected $fields;
24
25 /**
26 * put your comment there...
27 *
28 * @var mixed
29 */
30 protected $path;
31
32 /**
33 * put your comment there...
34 *
35 * @var mixed
36 */
37 protected $site;
38
39 /**
40 * put your comment there...
41 *
42 * @param mixed $site
43 * @param mixed $path
44 * @return CJT_Framework_Wordpress_Feed
45 */
46 public function __construct($site, $path, $fields) {
47 # Initialize.
48 $this->site =& $site;
49 $this->path =& $path;
50 $this->fields = $fields;
51 # Request server => get raw XML feed
52 $feed = wp_remote_get("http://{$this->site}/{$this->path}");
53 # Getting XML content
54 $xmlContent = ((gettype($feed) !== 'WP_Error') && ($feed['response']['code'] == 200)) ?
55 wp_remote_retrieve_body($feed) :
56 '<cjterrorrequest>
57 <channel cjt_error="true">
58 <item>
59 <title>ERROR</title>
60 <description>ERROR</description>
61 <link>http://css-javascript-toolbox.com/</link>
62 </item>
63 </channel>
64 </cjterrorrequest>';
65 # Creating feed
66 $this->feed = new SimpleXMLElement($xmlContent);
67 }
68
69 /**
70 * put your comment there...
71 *
72 */
73 public function getAllItems() {
74 // Initialize.
75 $items = array();
76 $xmlItems = $this->feed->channel->xpath('item');
77 // Read only items count specifed by $count param.
78 foreach ($xmlItems as $xmlItem) {
79 # Read fields.
80 $item = array();
81 foreach ($this->fields as $field) {
82 $item[$field] = (string) $xmlItem->$field;
83 }
84 # Add to list
85 $items[] = $item;
86 }
87 # Return items.
88 return $items;
89 }
90
91 /**
92 * put your comment there...
93 *
94 * @param mixed $count
95 */
96 public function getLatestItems($count) {
97 # Initialize.
98 $items = array();
99 $xmlItems = $this->feed->channel->xpath('item');
100 # Get all available items if the total items count is less that what is originally requested
101 if (count($xmlItems) < $count) {
102 $count = count($xmlItems);
103 }
104 # Read only items count specifed by $count param.
105 for ($currentIndex = 0; $currentIndex < $count; $currentIndex++) {
106 # Copy only title and link.
107 $xmlItem = $xmlItems[$currentIndex];
108 # Read fields.
109 $item = array();
110 foreach ($this->fields as $field) {
111 $item[$field] = (string) $xmlItem->$field;
112 }
113 # Add to list
114 $items[] = $item;
115 }
116 # Return items.
117 return $items;
118 }
119
120 /**
121 * put your comment there...
122 *
123 */
124 protected function getPath() {
125 return $this->path;
126 }
127
128 /**
129 * put your comment there...
130 *
131 */
132 public function getSite() {
133 return $this->site;
134 }
135
136 /**
137 * put your comment there...
138 *
139 */
140 public function isError() {
141 return !$this->feed || $this->feed->channel->attributes()->cjt_error;
142 }
143
144 } // End class.
145