File: Zend_Feed-Importing.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (359 lines) | stat: -rw-r--r-- 13,003 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.feed.importing">
    <title>Importing Feeds</title>

    <para>
        <classname>Zend_Feed</classname> enables developers to retrieve feeds very easily. If you
        know the <acronym>URI</acronym> of a feed, simply use the
        <methodname>Zend_Feed::import()</methodname> method:
    </para>

    <programlisting language="php"><![CDATA[
$feed = Zend_Feed::import('http://feeds.example.com/feedName');
]]></programlisting>

    <para>
        You can also use <classname>Zend_Feed</classname> to fetch the contents of a feed from a
        file or the contents of a <acronym>PHP</acronym> string variable:
    </para>

    <programlisting language="php"><![CDATA[
// importing a feed from a text file
$feedFromFile = Zend_Feed::importFile('feed.xml');

// importing a feed from a PHP string variable
$feedFromPHP = Zend_Feed::importString($feedString);
]]></programlisting>

    <para>
        In each of the examples above, an object of a class that extends
        <classname>Zend_Feed_Abstract</classname> is returned upon success, depending on the type of
        the feed. If an <acronym>RSS</acronym> feed were retrieved via one of the import methods
        above, then a <classname>Zend_Feed_Rss</classname> object would be returned. On the other
        hand, if an Atom feed were imported, then a <classname>Zend_Feed_Atom</classname> object is
        returned. The import methods will also throw a <classname>Zend_Feed_Exception</classname>
        object upon failure, such as an unreadable or malformed feed.
    </para>

    <sect2 id="zend.feed.importing.custom">
        <title>Custom feeds</title>

        <para>
            <classname>Zend_Feed</classname> enables developers to create custom feeds very easily.
            You just have to create an array and to import it with <classname>Zend_Feed</classname>.
            This array can be imported with <methodname>Zend_Feed::importArray()</methodname> or
            with <methodname>Zend_Feed::importBuilder()</methodname>. In this last case the array
            will be computed on the fly by a custom data source implementing
            <classname>Zend_Feed_Builder_Interface</classname>.
        </para>

        <sect3 id="zend.feed.importing.custom.importarray">
            <title>Importing a custom array</title>

            <programlisting language="php"><![CDATA[
// importing a feed from an array
$atomFeedFromArray = Zend_Feed::importArray($array);

// the following line is equivalent to the above;
// by default a Zend_Feed_Atom instance is returned
$atomFeedFromArray = Zend_Feed::importArray($array, 'atom');

// importing a rss feed from an array
$rssFeedFromArray = Zend_Feed::importArray($array, 'rss');
]]></programlisting>

            <para>
                The format of the array must conform to this structure:
            </para>

            <programlisting language="php"><![CDATA[
array(
    //required
    'title' => 'title of the feed',
    'link'  => 'canonical url to the feed',

    // optional
    'lastUpdate' => 'timestamp of the update date',
    'published'  => 'timestamp of the publication date',

    // required
    'charset' => 'charset of the textual data',

    // optional
    'description' => 'short description of the feed',
    'author'      => 'author/publisher of the feed',
    'email'       => 'email of the author',

    // optional, ignored if atom is used
    'webmaster' => 'email address for person responsible '
                .  'for technical issues',

    // optional
    'copyright' => 'copyright notice',
    'image'     => 'url to image',
    'generator' => 'generator',
    'language'  => 'language the feed is written in',

    // optional, ignored if atom is used
    'ttl'    => 'how long in minutes a feed can be cached '
             .  'before refreshing',
    'rating' => 'The PICS rating for the channel.',

    // optional, ignored if atom is used
    // a cloud to be notified of updates
    'cloud'       => array(
        // required
        'domain' => 'domain of the cloud, e.g. rpc.sys.com',

        // optional, defaults to 80
        'port' => 'port to connect to',

        // required
        'path'              => 'path of the cloud, e.g. /RPC2',
        'registerProcedure' => 'procedure to call, e.g. myCloud.rssPlsNotify',
        'protocol'          => 'protocol to use, e.g. soap or xml-rpc'
    ),

    // optional, ignored if atom is used
    // a text input box that can be displayed with the feed
    'textInput'   => array(
        // required
        'title'       => 'label of the Submit button in the text input area',
        'description' => 'explains the text input area',
        'name'        => 'the name of the text object in the text input area',
        'link'        => 'URL of the CGI script processing text input requests'
    ),

    // optional, ignored if atom is used
    // Hint telling aggregators which hours they can skip
    'skipHours' => array(
        // up to 24 rows whose value is a number between 0 and 23
        // e.g 13 (1pm)
        'hour in 24 format'
    ),

    // optional, ignored if atom is used
    // Hint telling aggregators which days they can skip
    'skipDays ' => array(
        // up to 7 rows whose value is
        // Monday, Tuesday, Wednesday, Thursday, Friday, Saturday or Sunday
        // e.g Monday
        'a day to skip'
    ),

    // optional, ignored if atom is used
    // Itunes extension data
    'itunes' => array(
        // optional, default to the main author value
        'author' => 'Artist column',

        // optional, default to the main author value
        // Owner of the podcast
        'owner' => array(
            'name'  => 'name of the owner',
            'email' => 'email of the owner'
        ),

        // optional, default to the main image value
        'image' => 'album/podcast art',

        // optional, default to the main description value
        'subtitle' => 'short description',
        'summary'  => 'longer description',

        // optional
        'block' => 'Prevent an episode from appearing (yes|no)',

        // required, Category column and in iTunes Music Store Browse
        'category' => array(
            // up to 3 rows
            array(
                // required
                'main' => 'main category',

                // optional
                'sub'  => 'sub category'
            )
        ),

        // optional
        'explicit'     => 'parental advisory graphic (yes|no|clean)',
        'keywords'     => 'a comma separated list of 12 keywords maximum',
        'new-feed-url' => 'used to inform iTunes of new feed URL location'
    ),

    'entries' => array(
        array(
            //required
            'title' => 'title of the feed entry',
            'link'  => 'url to a feed entry',

            // required, only text, no html
            'description' => 'short version of a feed entry',

            // optional
            'guid' => 'id of the article, '
                   .  'if not given link value will used',

            // optional, can contain html
            'content' => 'long version',

            // optional
            'lastUpdate' => 'timestamp of the publication date',
            'comments'   => 'comments page of the feed entry',
            'commentRss' => 'the feed url of the associated comments',

            // optional, original source of the feed entry
            'source' => array(
                // required
                'title' => 'title of the original source',
                'url'   => 'url of the original source'
            ),

            // optional, list of the attached categories
            'category' => array(
                array(
                    // required
                    'term' => 'first category label',

                    // optional
                    'scheme' => 'url that identifies a categorization scheme'
                ),

                array(
                    // data for the second category and so on
                )
            ),

            // optional, list of the enclosures of the feed entry
            'enclosure'    => array(
                array(
                    // required
                    'url' => 'url of the linked enclosure',

                    // optional
                    'type' => 'mime type of the enclosure',
                    'length' => 'length of the linked content in octets'
                ),

                array(
                    //data for the second enclosure and so on
                )
            )
        ),

        array(
            //data for the second entry and so on
        )
    )
);
]]></programlisting>

            <para>
                References:
            </para>

            <itemizedlist>
                <listitem>
                    <para>
                        <acronym>RSS</acronym> 2.0 specification: <ulink
                            url="http://blogs.law.harvard.edu/tech/rss">RSS 2.0</ulink>
                    </para>
                </listitem>

                <listitem>
                    <para>
                        Atom specification: <ulink
                            url="http://tools.ietf.org/html/rfc4287">RFC 4287</ulink>
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <acronym>WFW</acronym> specification: <ulink
                            url="http://wellformedweb.org/news/wfw_namespace_elements">Well
                            Formed Web</ulink>
                    </para>
                </listitem>

                <listitem>
                    <para>
                        iTunes specification: <ulink
                            url="http://www.apple.com/itunes/store/podcaststechspecs.html">iTunes
                            Technical Specifications</ulink>
                    </para>
                </listitem>
            </itemizedlist>
        </sect3>

        <sect3 id="zend.feed.importing.custom.importbuilder">
            <title>Importing a custom data source</title>

            <para>
                You can create a <classname>Zeed_Feed</classname> instance from any data source
                implementing <classname>Zend_Feed_Builder_Interface</classname>. You just have to
                implement the <methodname>getHeader()</methodname> and
                <methodname>getEntries()</methodname> methods to be able to use your object with
                <methodname>Zend_Feed::importBuilder()</methodname>. As a simple reference
                implementation, you can use <classname>Zend_Feed_Builder</classname>, which takes
                an array in its constructor, performs some minor validation, and then can be used
                in the <methodname>importBuilder()</methodname> method. The
                <methodname>getHeader()</methodname> method must return an instance of
                <classname>Zend_Feed_Builder_Header</classname>, and
                <methodname>getEntries()</methodname> must return an array of
                <classname>Zend_Feed_Builder_Entry</classname> instances.
            </para>

            <note>
                <para>
                    <classname>Zend_Feed_Builder</classname> serves as a concrete implementation to
                    demonstrate the usage. Users are encouraged to make their own classes to
                    implement <classname>Zend_Feed_Builder_Interface</classname>.
                </para>
            </note>

            <para>
                Here is an example of <methodname>Zend_Feed::importBuilder()</methodname> usage:
            </para>

            <programlisting language="php"><![CDATA[
// importing a feed from a custom builder source
$atomFeedFromArray =
    Zend_Feed::importBuilder(new Zend_Feed_Builder($array));

// the following line is equivalent to the above;
// by default a Zend_Feed_Atom instance is returned
$atomFeedFromArray =
    Zend_Feed::importBuilder(new Zend_Feed_Builder($array), 'atom');

// importing a rss feed from a custom builder array
$rssFeedFromArray =
    Zend_Feed::importBuilder(new Zend_Feed_Builder($array), 'rss');
]]></programlisting>
        </sect3>

        <sect3 id="zend.feed.importing.custom.dump">
            <title>Dumping the contents of a feed</title>

            <para>
                To dump the contents of a <classname>Zend_Feed_Abstract</classname> instance, you
                may use <methodname>send()</methodname> or <methodname>saveXml()</methodname>
                methods.
            </para>

            <programlisting language="php"><![CDATA[
assert($feed instanceof Zend_Feed_Abstract);

// dump the feed to standard output
print $feed->saveXML();

// send http headers and dump the feed
$feed->send();
]]></programlisting>
        </sect3>
    </sect2>
</sect1>
<!--
vim:se ts=4 sw=4 et:
-->