File: controller.inc.php

package info (click to toggle)
zoph 1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,632 kB
  • sloc: php: 28,044; javascript: 10,435; sql: 527; sh: 153; makefile: 4
file content (266 lines) | stat: -rw-r--r-- 8,010 bytes parent folder | download
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
<?php
/**
 * Controller for web services
 *
 * This file is part of Zoph.
 *
 * Zoph is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Zoph is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Zoph; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @package Zoph
 * @author Jeroen Roos
 */

namespace web\service;

use album;
use category;
use conf\conf;
use feature\base as feature;
use generic\controller as genericController;
use geo\locationLookup;
use import\web as webImport;
use language;
use person;
use photo;
use photographer;
use photo\collection;
use photo\data as photoData;
use photo\people as photoPeople;
use place;
use user;
use web\request;

/**
 * Controller for web services
 */
class controller extends genericController {
    protected static $viewJson = view\json::class;
    protected static $viewXML = view\xml::class;

    /** @var array Actions that can be used in this controller */
    protected $actions = array(
        "album",
        "category",
        "details",
        "feature",
        "importThumbs",
        "location",
        "locationLookup",
        "person",
        "photographer",
        "photoData",
        "photoPeople",
        "place",
        "search",
        "translation"
    );

    /** @var array Objects that can be used to show details */
    protected $detailsObjects = array(
        "album",
        "category",
        "circle",
        "person",
        "place"
    );

    /**
     * Do action 'Details'
     */
    public function actionDetails() {
        $object = $this->request["search"];
        $id = (int) $this->request["id"];

        if (in_array($object, $this->detailsObjects)) {
            $obj = new $object($id);
            $this->view = new static::$viewXML($this->request, $obj->getDetailsXML());
        }
    }

    /**
     * Do action 'locationLookup'
     */
    public function actionLocationlookup() {
        $search = $this->request["search"];
        $server = $this->request->getServerVar("SERVER_NAME");
        $location = new locationLookup($search, $server);
        $data = [ "search" => $search, "lat" => $location->getLat(), "lon" => $location->getLong(), "zoom" => $location->getZoom() ];
        $this->view = new static::$viewJson($this->request, $data);
    }

    /**
     * Do action 'photoData'
     */
    public function actionPhotoData() {
        $this->view = "json";
        $photoId = $this->request["photoId"];
        $photo = new photo($photoId);
        if ($photo->lookup()) {
            $photodata = new photoData($photo);
            $data = $photodata->getData();
        }
        $this->view = new static::$viewJson($this->request, $data ?? null);
    }

    /**
     * Do action 'photoPeople'
     */
    public function actionPhotoPeople() {
        $photoId = (int) $this->request["photoId"];
        $personId = (int) $this->request["personId"];
        $photo = new photo($photoId);
        $person = new person($personId);
        $photoPeople = new photoPeople($photo);
        $user=user::getCurrent();

        if (!$photo->isWritableBy($user)) {
            $this->view = new static::$viewJson($this->request, array(
                "error" => "insufficient rights"
            ));
            return;
        }

        $action = $this->request["action"];
        if (in_array($action, [ "left", "right", "up", "down" ])) {
            list($row, $pos) = $photoPeople->getPosition($person);
        }

        switch ($action) {
            case "left":
                $photoPeople->setPosition($person, $pos - 1);
                break;
            case "right":
                $photoPeople->setPosition($person, $pos + 1);
                break;
            case "up":
                $photoPeople->setRow($person, $row - 1);
                break;
            case "down":
                $photoPeople->setRow($person, $row + 1);
                break;
            case "add":
                $row = (int) $this->request["row"];
                $person->addPhoto($photo);
                $photoPeople->setRow($person, $row);
                break;
            case "remove":
                $person->removePhoto($photo);
                break;
            default:
                // Not making any changes, just outputting status quo
                break;
        }
        if ($photo->lookup()) {
            $photoPeople = new photoPeople($photo);
            $data = $photoPeople->getData();
        }
        $this->view = new static::$viewJson($this->request, $data ?? null);
    }


    /**
     * Do action 'search'
     * This is used in the slideshow to gather the list of photos to show,
     * but could in the future also be used to give a dynamic preview of
     * search actions.
     */
    public function actionSearch() {
        $photoCollection = collection::createFromRequest($this->request);

        $data=$photoCollection->getIds();
        $this->view = new static::$viewJson($this->request, $data ?? null);
    }


    /**
     * Do action 'translate'
     * Retrieves translations so they can be used in javascript-generated elements
     */
    public function actionTranslation() {
        $this->view = new static::$viewJson($this->request, language::getCurrent()->getAllTranslations());
    }

    /**
     * Do action 'feature'
     * Retrieve 'featured' photos
     */
    public function actionFeature() {
        $type = $this->request["type"];
        $count = $this->request["count"] ?? 10;
        $features = feature::getAll();
        $feature = new $features[$type];
        $this->view = new static::$viewJson($this->request, $feature->getData($count));
    }

    /**
     * Do action 'importThumbs'
     * Get thumbnails of photos that are in the import queue
     */
    public function actionImportThumbs() {
        $this->view = new static::$viewXML($this->request, webImport::getThumbsXML());
    }

    /**
     * Do action 'album'
     * Get XML of albums, used for autocomplete
     */
    public function actionAlbum() {
        $search = $this->request["search"];
        $this->view = new static::$viewXML($this->request, album::getXML($search));
    }

    /**
     * Do action 'categories'
     * Get XML of categories, used for autocomplete, as well as assigning categories based on XMP-profiles during web import
     */
    public function actionCategory() {
        $search = $this->request["search"];
        $this->view = new static::$viewXML($this->request, category::getXML($search));
    }

    /**
     * Do action 'place'
     * Get XML of places, used for autocomplete
     */
    public function actionPlace() {
        $search = $this->request["search"];
        $this->view = new static::$viewXML($this->request, place::getXML($search));
    }

    /**
     * Do action 'location'
     * Get XML of locations, used for autocomplete
     */
    public function actionLocation() {
        $this->actionPlace();
    }

    /**
     * Do action 'person'
     * Get XML of people, used for autocomplete
     */
    public function actionPerson() {
        $search = $this->request["search"];
        $this->view = new static::$viewXML($this->request, person::getXML($search));
    }

    /**
     * Do action 'photographer'
     * Get XML of photographers, used for autocomplete
     */
    public function actionPhotographer() {
        $search = $this->request["search"];
        $this->view = new static::$viewXML($this->request, photographer::getXML($search));
    }
}