root/branches/MidCOM_2_8/org.routamc.photostream/handler/feed.php

Revision 11036, 3.3 kB (checked in by rambo, 3 years ago)

Started work on feed creation, the viewer now autogenerates some
request switches it considers likely to be usefull and passes them on
to a dispatcher that will then call corresponding handler to see if we
can get an array of photos.

Making an actual feed from those with feedcreator is next up.

Line 
1 <?php
2 /**
3  * Created on 2006-Oct-Thu
4  * @package org.routamc.photostream
5  * @copyright The Midgard Project, http://www.midgard-project.org
6  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7  *
8  */
9 require('list.php');
10 class org_routamc_photostream_handler_feed extends org_routamc_photostream_handler_list
11 {
12     /**
13      * Simple default constructor.
14      */
15     function org_routamc_photostream_handler_feed()
16     {
17         parent::org_routamc_photostream_handler_list();
18     }
19
20     /**
21      * Overloaded since we really dont' need those
22      */
23     function _prepare_ajax_controllers()
24     {
25         // No need for these in the feed...
26         return;
27     }
28
29     /**
30      * This rather sneaky dispatcher is able to create a feed from any
31      * request_switch supported by org_routamc_photostream_handler_list
32      * that populates $data['photos'] (with a little help from org_routamc_photostream_viewer)
33      */
34     function _handler_dispatcher($handler_id, $args, &$data)
35     {
36         debug_push_class(__CLASS__, __FUNCTION__);
37         $parent_handler_id = preg_replace('/^feed:/', '', $handler_id);
38         if (!isset($data['request_switch'][$parent_handler_id]))
39         {
40             // Fatal, cannot solve haandler to use to get the actual data
41             debug_add("Cannot find handler_id '{$parent_handler_id}'", MIDCOM_LOG_ERROR);
42             debug_pop();
43             return false;
44         }
45         $parent_method = "_handler_{$data['request_switch'][$parent_handler_id]['handler'][1]}";
46         debug_add("Resolved parent method to '{$parent_method}'");
47         // Now that we have all that we need, we can remove this reference from cluttering our world
48         unset($data['request_switch']);
49
50         if (!is_callable(array($this, $parent_method)))
51         {
52             // Fatal, parent method is not callable
53             debug_add("Handler method \$this->{$parent_method} is not callable", MIDCOM_LOG_ERROR);
54             debug_pop();
55             return false;
56         }
57         // Use array_pop so we can pass the args on to the parent handler and it will not get confused by too long argument list
58         $data['feed_type_arg'] = array_pop($args);
59         
60         // TODO: Validate feed type before continuing
61         
62         debug_add("Calling \$this->{$parent_method}('{$parent_handler_id}', \$args, \$data)");
63         if (!$this->$parent_method($parent_handler_id, $args, $data))
64         {
65             debug_add("\$this->{$parent_method}('{$parent_handler_id}', \$args, \$data) returned false", MIDCOM_LOG_ERROR);
66             debug_pop();
67             return false;
68         }
69         if (!isset($data['photos']))
70         {
71             debug_add("\$data['photos'] is not set, most probably we hit a method ('{$parent_method}') in the list handler that does not populate it", MIDCOM_LOG_WARN);
72             debug_pop();
73             /* TODO: Check if this is correct way
74             $_MIDCOM->generate_error(MIDCOM_ERR_NOTFOUND);
75             // This will exit
76             */
77             return false;
78         }
79
80         debug_pop();
81         return true;
82     }
83
84     function _show_dispatcher($handler_id, &$data)
85     {
86         echo "<p>Handler '{$handler_id}' says: Hello world!</p>";
87         /*
88         echo "request_data: <pre>\n";
89         print_r($data);
90         echo "</pre>\n";
91         */
92     }
93 }
94 ?>
Note: See TracBrowser for help on using the browser.