root / rpc.php

View | Annotate | Download (5.3 KB)

1
<?php
2
3
/* *************************************************************************
4
 *
5
 * phpfspot, presents your F-Spot photo collection in Web browsers.
6
 *
7
 * Copyright (c) by Andreas Unterkircher
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program; if not, write to the Free Software
21
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
 *
23
 * *************************************************************************/
24
25
require_once "phpfspot.class.php";
26
27
/**
28
 * PHPFSPOT_RPC class
29
 *
30
 * handles AJAX-RPC calls from client browsers
31
 * @package phpfspot
32
 */
33
class PHPFSPOT_RPC {
34
35
   /**
36
    * PHPFSPOT_RPC constructor
37
    */
38
   public function __construct()
39
   {
40
      /* start PHP session */
41
      session_start();
42
43
   } // __construct()
44
45
   public function process_ajax_request()
46
   {
47
      require_once 'HTML/AJAX/Server.php';
48
49
      $server = new HTML_AJAX_Server();
50
      $server->handleRequest();
51
52
      $phpfspot = new PHPFSPOT();
53
54
      /* if no action is specified, no need to further process this
55
       * function here.
56
       */
57
      if(!isset($_GET['action']) && !isset($_POST['action']))
58
         return;
59
60
      if(isset($_GET['action']))
61
         $action = $_GET['action'];
62
      if(isset($_POST['action']))
63
         $action = $_POST['action'];
64
65
      switch($action) {
66
         case 'showphoto':
67
            if(isset($_GET['id']) && is_numeric($_GET['id'])) {
68
               print $phpfspot->showPhoto($_GET['id']);
69
            }
70
            break;
71
   
72
         case 'getxmltaglist':
73
            print $phpfspot->get_xml_tag_list();
74
            break;
75
76
         case 'show_available_tags':
77
            print $phpfspot->getAvailableTags();
78
            break;
79
80
         case 'show_selected_tags':
81
            print $phpfspot->getSelectedTags();
82
            break;
83
84
         case 'addtag':
85
            if(isset($_POST['id']) && is_numeric($_POST['id'])) {
86
               print $phpfspot->addTag($_POST['id']);
87
            }
88
            break;
89
90
         case 'deltag':
91
            if(isset($_POST['id']) && is_numeric($_POST['id'])) {
92
               print $phpfspot->delTag($_POST['id']);
93
            }
94
            break;
95
96
         case 'reset':
97
            $phpfspot->resetTagSearch();
98
            $phpfspot->resetNameSearch();
99
            $phpfspot->resetTags();
100
            $phpfspot->resetDateSearch();
101
            $phpfspot->resetRateSearch();
102
            $phpfspot->resetPhotoView();
103
            break;
104
105
         case 'tagcondition':
106
            if(isset($_POST['mode']) && in_array($_POST['mode'], Array('or', 'and'))) {
107
               print $phpfspot->setTagCondition($_POST['mode']);
108
            }
109
            break;
110
111
         case 'show_photo_index':
112
            if(isset($_GET['begin_with']) && is_numeric($_GET['begin_with'])) {
113
               $_SESSION['begin_with'] = $_GET['begin_with'];
114
            }
115
            else {
116
               unset($_SESSION['begin_with']);
117
            }
118
            if(isset($_GET['last_photo']) && is_numeric($_GET['last_photo']))
119
               $_SESSION['last_photo'] = $_GET['last_photo'];
120
121
            print $phpfspot->showPhotoIndex();
122
            break;
123
   
124
         case 'showcredits':
125
            $phpfspot->showCredits();
126
            break;
127
128
         case 'search':
129
            print $phpfspot->startSearch();
130
            break;
131
132
         case 'update_sort_order':
133
            if(isset($_POST['value']) && is_string($_POST['value'])) {
134
               print $phpfspot->updateSortOrder($_POST['value']);
135
            }
136
            break;
137
138
         case 'update_photo_version':
139
            if(isset($_POST['photo_version']) && is_numeric($_POST['photo_version']) &&
140
               isset($_POST['photo_idx']) && is_numeric($_POST['photo_idx'])) {
141
               print $phpfspot->update_photo_version($_POST['photo_idx'], $_POST['photo_version']);
142
            }
143
            break;
144
145
         case 'get_export':
146
            /* $_GET['mode'] will be validated by getExport() */
147
            $phpfspot->getExport($_GET['mode']);
148
            break;
149
150
         case 'get_photo_to_show':
151
            print $phpfspot->get_current_photo();
152
            break;
153
154
         case 'get_calendar_matrix':
155
            if(isset($_GET['date']) && is_string($_GET['date'])) {
156
               $phpfspot->get_calendar_matrix($_GET['date']);
157
            }
158
            break;
159
160
         case 'what_to_do':
161
            print $phpfspot->whatToDo();
162
            break;
163
164
         case 'reset_slideshow':
165
            print $phpfspot->resetSlideShow();
166
            break;
167
168
         case 'get_next_slideshow_img':
169
            print $phpfspot->getNextSlideShowImage();
170
            break;
171
         
172
         case 'get_prev_slideshow_img':
173
            print $phpfspot->getPrevSlideShowImage();
174
            break;
175
176
      }
177
178
   } // process_ajax_request();
179
180
} // class PHPFSPOT_RPC
181
182
$rpc = new PHPFSPOT_RPC();
183
$rpc->process_ajax_request();
184
185
?>
186