| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | /********************************************************************\ |
|---|
| 5 | * This program is free software; you can redistribute it and/or * |
|---|
| 6 | * modify it under the terms of the GNU General Public License as * |
|---|
| 7 | * published by the Free Software Foundation; either version 2 of * |
|---|
| 8 | * the License, or (at your option) any later version. * |
|---|
| 9 | * * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, * |
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|---|
| 13 | * GNU General Public License for more details. * |
|---|
| 14 | * * |
|---|
| 15 | * You should have received a copy of the GNU General Public License* |
|---|
| 16 | * along with this program; if not, contact: * |
|---|
| 17 | * * |
|---|
| 18 | * Free Software Foundation Voice: +1-617-542-5942 * |
|---|
| 19 | * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * |
|---|
| 20 | * Boston, MA 02111-1307, USA gnu@gnu.org * |
|---|
| 21 | * * |
|---|
| 22 | \********************************************************************/ |
|---|
| 23 | /**@file FlickrPhotostream.php |
|---|
| 24 | * @author Copyright (C) 2005 François Proulx <francois.proulx@gmail.com>, |
|---|
| 25 | * Technologies Coeus inc. |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | // Make sure the Phlickr support is activated |
|---|
| 29 | if (defined('PHLICKR_SUPPORT') && PHLICKR_SUPPORT === true) |
|---|
| 30 | { |
|---|
| 31 | require_once BASEPATH.'classes/Content.php'; |
|---|
| 32 | require_once BASEPATH.'classes/FormSelectGenerator.php'; |
|---|
| 33 | |
|---|
| 34 | // Set the include_path in order to include Phlickr classes. |
|---|
| 35 | ini_set("include_path", ini_get("include_path").":".BASEPATH.PHLICKR_REL_PATH); |
|---|
| 36 | |
|---|
| 37 | require_once "Phlickr/Api.php"; |
|---|
| 38 | require_once "Phlickr/User.php"; |
|---|
| 39 | require_once "Phlickr/Group.php"; |
|---|
| 40 | |
|---|
| 41 | /** |
|---|
| 42 | * A Flickr Photostreams wrapper |
|---|
| 43 | * - Flexible administrative options |
|---|
| 44 | */ |
|---|
| 45 | class FlickrPhotostream extends ContentGroup |
|---|
| 46 | { |
|---|
| 47 | /* Photo selection modes */ |
|---|
| 48 | const SELECT_BY_GROUP = 'PSM_GROUP'; |
|---|
| 49 | const SELECT_BY_USER = 'PSM_USER'; |
|---|
| 50 | const SELECT_BY_TAGS = 'PSM_TAGS'; |
|---|
| 51 | |
|---|
| 52 | /* Tags matching mode */ |
|---|
| 53 | const TAG_MODE_ANY = 'ANY_TAG'; |
|---|
| 54 | const TAG_MODE_ALL = 'ALL_TAGS'; |
|---|
| 55 | |
|---|
| 56 | private $flickr_api; |
|---|
| 57 | |
|---|
| 58 | protected function __construct($content_id) |
|---|
| 59 | { |
|---|
| 60 | parent :: __construct($content_id); |
|---|
| 61 | global $db; |
|---|
| 62 | $content_id = $db->EscapeString($content_id); |
|---|
| 63 | |
|---|
| 64 | $sql = "SELECT * FROM flickr_photostream WHERE flickr_photostream_id='$content_id'"; |
|---|
| 65 | $db->ExecSqlUniqueRes($sql, $row, false); |
|---|
| 66 | if ($row == null) |
|---|
| 67 | { |
|---|
| 68 | /*Since the parent Content exists, the necessary data in content_group had not yet been created */ |
|---|
| 69 | $sql = "INSERT INTO flickr_photostream (flickr_photostream_id) VALUES ('$content_id')"; |
|---|
| 70 | $db->ExecSqlUpdate($sql, false); |
|---|
| 71 | |
|---|
| 72 | $sql = "SELECT * FROM flickr_photostream WHERE flickr_photostream_id='$content_id'"; |
|---|
| 73 | $db->ExecSqlUniqueRes($sql, $row, false); |
|---|
| 74 | if ($row == null) |
|---|
| 75 | { |
|---|
| 76 | throw new Exception(_("The content with the following id could not be found in the database: ").$content_id); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | //TODO: Force no locative content until we find a better solution |
|---|
| 82 | $this->setIsLocativeContent(false); |
|---|
| 83 | $this->flickr_photostream_row = $row; |
|---|
| 84 | $this->mBd = & $db; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | public function getFlickrApi() |
|---|
| 88 | { |
|---|
| 89 | if ($this->getApiKey() && $this->flickr_api == null) |
|---|
| 90 | $this->flickr_api = new Phlickr_Api($this->getApiKey()); |
|---|
| 91 | return $this->flickr_api; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | public function setFlickrApi($api) |
|---|
| 95 | { |
|---|
| 96 | $this->flickr_api = $api; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | public function getSelectionMode() |
|---|
| 100 | { |
|---|
| 101 | return $this->flickr_photostream_row['photo_selection_mode']; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | public function setSelectionMode($selection_mode) |
|---|
| 105 | { |
|---|
| 106 | switch ($selection_mode) |
|---|
| 107 | { |
|---|
| 108 | case self :: SELECT_BY_GROUP : |
|---|
| 109 | case self :: SELECT_BY_USER : |
|---|
| 110 | case self :: SELECT_BY_TAGS : |
|---|
| 111 | $selection_mode = $this->mBd->EscapeString($selection_mode); |
|---|
| 112 | $this->mBd->ExecSqlUpdate("UPDATE flickr_photostream SET photo_selection_mode = '".$selection_mode."' WHERE flickr_photostream_id = '".$this->getId()."'"); |
|---|
| 113 | $this->refresh(); |
|---|
| 114 | break; |
|---|
| 115 | default : |
|---|
| 116 | throw new Exception(_("Illegal Flickr Photostream selection mode.")); |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | public function getPhotoBatchSize() |
|---|
| 121 | { |
|---|
| 122 | return $this->flickr_photostream_row['photo_batch_size']; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | public function setPhotoBatchSize($size) |
|---|
| 126 | { |
|---|
| 127 | //TODO: Add photo batch size support in getAdminUI() |
|---|
| 128 | if (is_numeric($size)) |
|---|
| 129 | { |
|---|
| 130 | $size = $this->mBd->EscapeString($size); |
|---|
| 131 | $this->mBd->ExecSqlUpdate("UPDATE flickr_photostream SET photo_batch_size ='$size' WHERE flickr_photostream_id = '".$this->getId()."'"); |
|---|
| 132 | $this->refresh(); |
|---|
| 133 | return true; |
|---|
| 134 | } |
|---|
| 135 | else |
|---|
| 136 | return false; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | public function getApiKey() |
|---|
| 140 | { |
|---|
| 141 | return $this->flickr_photostream_row['api_key']; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | public function setApiKey($api_key) |
|---|
| 145 | { |
|---|
| 146 | $api_key = $this->mBd->EscapeString($api_key); |
|---|
| 147 | $this->mBd->ExecSqlUpdate("UPDATE flickr_photostream SET api_key ='$api_key' WHERE flickr_photostream_id = '".$this->getId()."'"); |
|---|
| 148 | $this->refresh(); |
|---|
| 149 | $this->setFlickrApi(null); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | public function pingFlickr() |
|---|
| 153 | { |
|---|
| 154 | if ($this->getFlickrApi()) |
|---|
| 155 | { |
|---|
| 156 | try |
|---|
| 157 | { |
|---|
| 158 | $request = $$this->getFlickrApi()->createRequest("flickr.test.echo", null); |
|---|
| 159 | $request->setExceptionThrownOnFailure(true); |
|---|
| 160 | $resp = $request->execute(); |
|---|
| 161 | return true; |
|---|
| 162 | } |
|---|
| 163 | catch (Phlickr_Exception $ex) |
|---|
| 164 | { |
|---|
| 165 | return false; |
|---|
| 166 | } |
|---|
| 167 | } |
|---|
| 168 | else |
|---|
| 169 | return false; |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | private function getUserByEmail($email) |
|---|
| 173 | { |
|---|
| 174 | if ($this->getFlickrApi()) |
|---|
| 175 | { |
|---|
| 176 | try |
|---|
| 177 | { |
|---|
| 178 | $request = $this->getFlickrApi()->createRequest("flickr.people.findByEmail", array ("find_email" => $email)); |
|---|
| 179 | $request->setExceptionThrownOnFailure(true); |
|---|
| 180 | $resp = $request->execute(); |
|---|
| 181 | return new Phlickr_User($this->getFlickrApi(), (string) $resp->xml->user['id']); |
|---|
| 182 | } |
|---|
| 183 | catch (Phlickr_Exception $ex) |
|---|
| 184 | { |
|---|
| 185 | return null; |
|---|
| 186 | } |
|---|
| 187 | } |
|---|
| 188 | else |
|---|
| 189 | return null; |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | public function getFlickrUserId() |
|---|
| 193 | { |
|---|
| 194 | return $this->flickr_photostream_row['user_id']; |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | public function setUserId($user_id) |
|---|
| 198 | { |
|---|
| 199 | $user_id = $this->mBd->EscapeString($user_id); |
|---|
| 200 | $this->mBd->ExecSqlUpdate("UPDATE flickr_photostream SET user_id ='$user_id' WHERE flickr_photostream_id = '".$this->getId()."'"); |
|---|
| 201 | $this->refresh(); |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | public function getUserName() |
|---|
| 205 | { |
|---|
| 206 | return $this->flickr_photostream_row['user_name']; |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | public function setUserName($user_name) |
|---|
| 210 | { |
|---|
| 211 | $user_name = $this->mBd->EscapeString($user_name); |
|---|
| 212 | $this->mBd->ExecSqlUpdate("UPDATE flickr_photostream SET user_name = '$user_name' WHERE flickr_photostream_id = '".$this->getId()."'"); |
|---|
| 213 | $this->refresh(); |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | public function getGroupId() |
|---|
| 217 | { |
|---|
| 218 | return $this->flickr_photostream_row['group_id']; |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | public function setGroupId($group_id) |
|---|
| 222 | { |
|---|
| 223 | $group_id = $this->mBd->EscapeString($group_id); |
|---|
| 224 | $this->mBd->ExecSqlUpdate("UPDATE flickr_photostream SET group_id = '$group_id' WHERE flickr_photostream_id = '".$this->getId()."'"); |
|---|
| 225 | $this->refresh(); |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | public function getTags() |
|---|
| 229 | { |
|---|
| 230 | return $this->flickr_photostream_row['tags']; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | public function setTags($tags) |
|---|
| 234 | { |
|---|
| 235 | $tags = $this->mBd->EscapeString($tags); |
|---|
| 236 | $this->mBd->ExecSqlUpdate("UPDATE flickr_photostream SET tags = '$tags' WHERE flickr_photostream_id = '".$this->getId()."'"); |
|---|
| 237 | $this->refresh(); |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | public function getTagMode() |
|---|
| 241 | { |
|---|
| 242 | return $this->flickr_photostream_row['tag_mode']; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | public function setTagMode($mode) |
|---|
| 246 | { |
|---|
| 247 | switch ($mode) |
|---|
| 248 | { |
|---|
| 249 | case self :: TAG_MODE_ANY : |
|---|
| 250 | case self :: TAG_MODE_ALL : |
|---|
| 251 | $mode = $this->mBd->EscapeString($mode); |
|---|
| 252 | $this->mBd->ExecSqlUpdate("UPDATE flickr_photostream SET tag_mode = '$mode' WHERE flickr_photostream_id = '".$this->getId()."'"); |
|---|
| 253 | $this->refresh(); |
|---|
| 254 | break; |
|---|
| 255 | default : |
|---|
| 256 | throw new Exception("Illegal tag matching mode."); |
|---|
| 257 | } |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | public function shouldDisplayTitle() |
|---|
| 261 | { |
|---|
| 262 | return $this->flickr_photostream_row['display_title'] == "t"; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | public function setDisplayTitle($display_title) |
|---|
| 266 | { |
|---|
| 267 | $display_title = $display_title == true ? "true" : "false"; |
|---|
| 268 | $this->mBd->ExecSqlUpdate("UPDATE flickr_photostream SET display_title = $display_title WHERE flickr_photostream_id = '".$this->getId()."'"); |
|---|
| 269 | $this->refresh(); |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | public function shouldDisplayTags() |
|---|
| 273 | { |
|---|
| 274 | return $this->flickr_photostream_row['display_tags'] == "t"; |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | public function setDisplayTags($display_tags) |
|---|
| 278 | { |
|---|
| 279 | $display_tags = $display_tags == true ? "true" : "false"; |
|---|
| 280 | $this->mBd->ExecSqlUpdate("UPDATE flickr_photostream SET display_tags = $display_tags WHERE flickr_photostream_id = '".$this->getId()."'"); |
|---|
| 281 | $this->refresh(); |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | public function shouldDisplayDescription() |
|---|
| 285 | { |
|---|
| 286 | return $this->flickr_photostream_row['display_description'] == "t"; |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | public function setDisplayDescription($display_description) |
|---|
| 290 | { |
|---|
| 291 | $display_description = $display_description == true ? "true" : "false"; |
|---|
| 292 | $this->mBd->ExecSqlUpdate("UPDATE flickr_photostream SET display_description = $display_description WHERE flickr_photostream_id = '".$this->getId()."'"); |
|---|
| 293 | $this->refresh(); |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | public function getAdminUI($subclass_admin_interface = null) |
|---|
| 297 | { |
|---|
| 298 | $generator = new FormSelectGenerator(); |
|---|
| 299 | |
|---|
| 300 | $html = ''; |
|---|
| 301 | $html .= "<div class='admin_class'>Flickr Photostream (".get_class($this)." instance)</div>\n"; |
|---|
| 302 | |
|---|
| 303 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 304 | $html .= "<div class='admin_section_title'>"._("Flickr API key")." <a href='http://www.flickr.com/services/api/misc.api_keys.html'>(?)</a> : </div>\n"; |
|---|
| 305 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 306 | $name = "flickr_photostream_".$this->id."_api_key"; |
|---|
| 307 | $html .= "<input type='text' name='$name' value='".$this->getApiKey()."'\n"; |
|---|
| 308 | $html .= "</div>\n"; |
|---|
| 309 | $html .= "</div>\n"; |
|---|
| 310 | |
|---|
| 311 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 312 | $html .= "<div class='admin_section_title'>"._("Flick photo selection mode :")."</div>\n"; |
|---|
| 313 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 314 | |
|---|
| 315 | $selection_modes = array (array (0 => self :: SELECT_BY_GROUP, 1 => _("Select by group")), array (0 => self :: SELECT_BY_TAGS, 1 => _("Select by tags")), array (0 => self :: SELECT_BY_USER, 1 => _("Select by user"))); |
|---|
| 316 | $html .= $generator->generateFromArray($selection_modes, $this->getSelectionMode(), "SelectionMode".$this->getID(), "FlickrPhotostream", false, null, "onChange='submit()'"); |
|---|
| 317 | |
|---|
| 318 | // Check for existing API key |
|---|
| 319 | if ($this->getAPIKey()) |
|---|
| 320 | { |
|---|
| 321 | try |
|---|
| 322 | { |
|---|
| 323 | switch ($this->getSelectionMode()) |
|---|
| 324 | { |
|---|
| 325 | // Process common data ( User ID + User name ) |
|---|
| 326 | case self :: SELECT_BY_GROUP : |
|---|
| 327 | case self :: SELECT_BY_USER : |
|---|
| 328 | if ($this->getFlickrUserId()) |
|---|
| 329 | { |
|---|
| 330 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 331 | $html .= "<div class='admin_section_title'>"._("Flickr User ID + Username")." : </div>\n"; |
|---|
| 332 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 333 | $html .= $this->getUserName()." [".$this->getFlickrUserId()."]"; |
|---|
| 334 | $name = "flickr_photostream_".$this->id."_reset_user_id"; |
|---|
| 335 | $html .= " <b>( <input type='checkbox' name='$name' value='true'>"._("Reset Flickr User ID")." )</b>"; |
|---|
| 336 | $html .= "</div>\n"; |
|---|
| 337 | $html .= "</div>\n"; |
|---|
| 338 | } |
|---|
| 339 | else |
|---|
| 340 | { |
|---|
| 341 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 342 | $html .= "<div class='admin_section_title'>"._("Flickr User E-mail")." : </div>\n"; |
|---|
| 343 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 344 | $name = "flickr_photostream_".$this->id."_email"; |
|---|
| 345 | $html .= "<input type='text' name='$name' value=''>"; |
|---|
| 346 | $html .= "</div>\n"; |
|---|
| 347 | $html .= "</div>\n"; |
|---|
| 348 | } |
|---|
| 349 | break; |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | switch ($this->getSelectionMode()) |
|---|
| 353 | { |
|---|
| 354 | case self :: SELECT_BY_GROUP : |
|---|
| 355 | if ($this->getFlickrUserId()) |
|---|
| 356 | { |
|---|
| 357 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 358 | $html .= "<div class='admin_section_title'>"._("Group Photo Pool")." : </div>\n"; |
|---|
| 359 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 360 | $group_photo_pools = array (); |
|---|
| 361 | |
|---|
| 362 | $flickr_user = new Phlickr_User($this->getFlickrApi(), $this->getFlickrUserId()); |
|---|
| 363 | $groups = array (); |
|---|
| 364 | $group_photo_pools = $flickr_user->getGroupList()->getGroups(); |
|---|
| 365 | foreach ($group_photo_pools as $group_photo_pool) |
|---|
| 366 | $groups[] = array (0 => $group_photo_pool->getId(), 1 => $group_photo_pool->getName()); |
|---|
| 367 | |
|---|
| 368 | if (count($groups) > 0) |
|---|
| 369 | $html .= $generator->generateFromArray($groups, $this->getGroupId(), "GroupPhotoPool".$this->getID(), "FlickrPhotostream", false, null, "onChange='submit()'"); |
|---|
| 370 | else |
|---|
| 371 | $html .= _("Could not find any group photo pool."); |
|---|
| 372 | |
|---|
| 373 | $html .= "</div>\n"; |
|---|
| 374 | $html .= "</div>\n"; |
|---|
| 375 | } |
|---|
| 376 | break; |
|---|
| 377 | case self :: SELECT_BY_TAGS : |
|---|
| 378 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 379 | $html .= "<div class='admin_section_title'>"._("Tags (comma-separated)")." : </div>\n"; |
|---|
| 380 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 381 | $name = "flickr_photostream_".$this->id."_tags"; |
|---|
| 382 | $html .= "<input type='text' name='$name' value='".$this->getTags()."'>"; |
|---|
| 383 | $tag_modes = array (array (0 => self :: TAG_MODE_ANY, 1 => _("Match any tag")), array (0 => self :: TAG_MODE_ALL, 1 => _("Match all tags"))); |
|---|
| 384 | $html .= $generator->generateFromArray($tag_modes, $this->getTagMode(), "TagMode".$this->getID(), "FlickrPhotostream", false, null, "onChange='submit()'"); |
|---|
| 385 | $html .= "</div>\n"; |
|---|
| 386 | $html .= "</div>\n"; |
|---|
| 387 | break; |
|---|
| 388 | } |
|---|
| 389 | |
|---|
| 390 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 391 | $html .= "<div class='admin_section_title'>"._("Flickr photo display options")." : </div>\n"; |
|---|
| 392 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 393 | |
|---|
| 394 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 395 | $html .= "<div class='admin_section_title'>"._("Show Flickr photo title ?")." : </div>\n"; |
|---|
| 396 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 397 | $name = "flickr_photostream_".$this->id."_display_title"; |
|---|
| 398 | $this->shouldDisplayTitle() ? $checked = 'CHECKED' : $checked = ''; |
|---|
| 399 | $html .= "<input type='checkbox' name='$name' $checked>\n"; |
|---|
| 400 | $html .= "</div>\n"; |
|---|
| 401 | $html .= "</div>\n"; |
|---|
| 402 | |
|---|
| 403 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 404 | $html .= "<div class='admin_section_title'>"._("Show Flickr tags ?")." : </div>\n"; |
|---|
| 405 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 406 | $name = "flickr_photostream_".$this->id."_display_tags"; |
|---|
| 407 | $this->shouldDisplayTags() ? $checked = 'CHECKED' : $checked = ''; |
|---|
| 408 | $html .= "<input type='checkbox' name='$name' $checked>\n"; |
|---|
| 409 | $html .= "</div>\n"; |
|---|
| 410 | $html .= "</div>\n"; |
|---|
| 411 | |
|---|
| 412 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 413 | $html .= "<div class='admin_section_title'>"._("Show Flickr photo description ?")." : </div>\n"; |
|---|
| 414 | $html .= "<div class='admin_section_data'>\n"; |
|---|
| 415 | $name = "flickr_photostream_".$this->id."_display_description"; |
|---|
| 416 | $this->shouldDisplayDescription() ? $checked = 'CHECKED' : $checked = ''; |
|---|
| 417 | $html .= "<input type='checkbox' name='$name' $checked>\n"; |
|---|
| 418 | $html .= "</div>\n"; |
|---|
| 419 | $html .= "</div>\n"; |
|---|
| 420 | |
|---|
| 421 | //TODO: Add photo batch size support |
|---|
| 422 | //TODO: Add photo count support ( number of photos to display at once ) |
|---|
| 423 | //TODO: Add random support (checkbox) |
|---|
| 424 | //TODO: Add date range support |
|---|
| 425 | |
|---|
| 426 | $html .= "</div>\n"; |
|---|
| 427 | $html .= "</div>\n"; |
|---|
| 428 | } |
|---|
| 429 | catch (Phlickr_ConnectionException $e) |
|---|
| 430 | { |
|---|
| 431 | $html .= _("Unable to connect to Flickr API."); |
|---|
| 432 | } |
|---|
| 433 | catch (Phlickr_MethodFailureException $e) |
|---|
| 434 | { |
|---|
| 435 | $html .= _("Some of the request parameters provided to Flickr API are invalid."); |
|---|
| 436 | } |
|---|
| 437 | catch (Phlickr_XmlParseException $e) |
|---|
| 438 | { |
|---|
| 439 | $html .= _("Unable to parse Flickr's response."); |
|---|
| 440 | } |
|---|
| 441 | catch (Phlickr_Exception $e) |
|---|
| 442 | { |
|---|
| 443 | $html .= _("Could not get content from Flickr : ").$e; |
|---|
| 444 | } |
|---|
| 445 | } |
|---|
| 446 | else |
|---|
| 447 | { |
|---|
| 448 | $html .= "<div class='admin_section_container'>\n"; |
|---|
| 449 | $html .= "<div class='admin_section_title'>"._("YOU MUST SPECIFY AN API KEY BEFORE YOU CAN GO ON.")."</div>\n"; |
|---|
| 450 | $html .= "</div>\n"; |
|---|
| 451 | } |
|---|
| 452 | |
|---|
| 453 | $html .= $subclass_admin_interface; |
|---|
| 454 | return parent :: getAdminUI($html); |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | function processAdminUI() |
|---|
| 458 | { |
|---|
| 459 | parent :: processAdminUI(); |
|---|
| 460 | $generator = new FormSelectGenerator(); |
|---|
| 461 | |
|---|
| 462 | $name = "flickr_photostream_".$this->id."_api_key"; |
|---|
| 463 | !empty ($_REQUEST[$name]) ? $this->setApiKey($_REQUEST[$name]) : $this->setApiKey(null); |
|---|
| 464 | |
|---|
| 465 | if ($generator->isPresent("SelectionMode".$this->getID(), "FlickrPhotostream")) |
|---|
| 466 | $this->setSelectionMode($generator->getResult("SelectionMode".$this->getID(), "FlickrPhotostream")); |
|---|
| 467 | |
|---|
| 468 | // Check for existing API key |
|---|
| 469 | if ($this->getAPIKey() && $this->getSelectionMode()) |
|---|
| 470 | { |
|---|
| 471 | try |
|---|
| 472 | { |
|---|
| 473 | switch ($this->getSelectionMode()) |
|---|
| 474 | { |
|---|
| 475 | // Process common data for groups and users |
|---|
| 476 | case self :: SELECT_BY_GROUP : |
|---|
| 477 | if ($generator->isPresent("GroupPhotoPool".$this->getID(), "FlickrPhotostream")) |
|---|
| 478 | $this->setGroupId($generator->getResult("GroupPhotoPool".$this->getID(), "FlickrPhotostream")); |
|---|
| 479 | case self :: SELECT_BY_USER : |
|---|
| 480 | $name = "flickr_photostream_".$this->id."_reset_user_id"; |
|---|
| 481 | if (!empty ($_REQUEST[$name]) || !$this->getFlickrUserId()) |
|---|
| 482 | { |
|---|
| 483 | $this->setUserId(null); |
|---|
| 484 | $name = "flickr_photostream_".$this->id."_email"; |
|---|
| 485 | if (!empty ($_REQUEST[$name]) && ($flickr_user = $this->getUserByEmail($_REQUEST[$name])) != null) |
|---|
| 486 | { |
|---|
| 487 | $this->setUserId($flickr_user->getId()); |
|---|
| 488 | $this->setUserName($flickr_user->getName()); |
|---|
| 489 | } |
|---|
| 490 | else |
|---|
| 491 | echo _("Could not find a Flickr user with this e-mail."); |
|---|
| 492 | } |
|---|
| 493 | break; |
|---|
| 494 | case self :: SELECT_BY_TAGS : |
|---|
| 495 | $name = "flickr_photostream_".$this->id."_tags"; |
|---|
| 496 | if (!empty ($_REQUEST[$name])) |
|---|
| 497 | $this->setTags($_REQUEST[$name]); |
|---|
| 498 | else |
|---|
| 499 | $this->setTags(null); |
|---|
| 500 | if ($generator->isPresent("TagMode".$this->getID(), "FlickrPhotostream")) |
|---|
| 501 | $this->setTagMode($generator->getResult("TagMode".$this->getID(), "FlickrPhotostream")); |
|---|
| 502 | break; |
|---|
| 503 | } |
|---|
| 504 | } |
|---|
| 505 | catch (Exception $e) |
|---|
| 506 | { |
|---|
| 507 | echo _("Could not complete successfully the saving procedure."); |
|---|
| 508 | } |
|---|
| 509 | |
|---|
| 510 | $name = "flickr_photostream_".$this->id."_display_title"; |
|---|
| 511 | !empty ($_REQUEST[$name]) ? $this->setDisplayTitle(true) : $this->setDisplayTitle(false); |
|---|
| 512 | $name = "flickr_photostream_".$this->id."_display_tags"; |
|---|
| 513 | !empty ($_REQUEST[$name]) ? $this->setDisplayTags(true) : $this->setDisplayTags(false); |
|---|
| 514 | $name = "flickr_photostream_".$this->id."_display_description"; |
|---|
| 515 | !empty ($_REQUEST[$name]) ? $this->setDisplayDescription(true) : $this->setDisplayDescription(false); |
|---|
| 516 | } |
|---|
| 517 | |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | /** Retreives the user interface of this object. Anything that overrides this method should call the parent method with it's output at the END of processing. |
|---|
| 521 | * @param $subclass_admin_interface Html content of the interface element of a children |
|---|
| 522 | * @return The HTML fragment for this interface */ |
|---|
| 523 | public function getUserUI($subclass_user_interface = null) |
|---|
| 524 | { |
|---|
| 525 | $html = ''; |
|---|
| 526 | $html .= "<div class='user_ui_container'>\n"; |
|---|
| 527 | $html .= "<div class='user_ui_object_class'>FlickrPhotostream (".get_class($this)." instance)</div>\n"; |
|---|
| 528 | |
|---|
| 529 | // Initialize a Flickr API wrapper |
|---|
| 530 | try |
|---|
| 531 | { |
|---|
| 532 | $photos = null; |
|---|
| 533 | switch ($this->getSelectionMode()) |
|---|
| 534 | { |
|---|
| 535 | case self :: SELECT_BY_GROUP : |
|---|
| 536 | if ($this->getGroupId()) |
|---|
| 537 | { |
|---|
| 538 | $photo_pool = new Phlickr_Group($this->getFlickrApi(), $this->getGroupId()); |
|---|
| 539 | $photos = $photo_pool->getPhotoList($this->getPhotoBatchSize())->getPhotos(); |
|---|
| 540 | } |
|---|
| 541 | break; |
|---|
| 542 | case self :: SELECT_BY_TAGS : |
|---|
| 543 | if ($this->getTags()) |
|---|
| 544 | { |
|---|
| 545 | $request = $this->getFlickrApi()->createRequest('flickr.photos.search', array ('tags' => $this->getTags(), 'tag_mode' => $this->getTagMode())); |
|---|
| 546 | $photo_list = new Phlickr_PhotoList($request, $this->getPhotoBatchSize()); |
|---|
| 547 | $photos = $photo_list->getPhotos(); |
|---|
| 548 | } |
|---|
| 549 | break; |
|---|
| 550 | case self :: SELECT_BY_USER : |
|---|
| 551 | if ($this->getFlickrUserId()) |
|---|
| 552 | { |
|---|
| 553 | $user = new Phlickr_User($this->getFlickrApi(), $this->getFlickrUserId()); |
|---|
| 554 | $photos = $user->getPhotoList($this->getPhotoBatchSize())->getPhotos(); |
|---|
| 555 | } |
|---|
| 556 | break; |
|---|
| 557 | } |
|---|
| 558 | |
|---|
| 559 | if (is_array($photos) && !empty ($photos)) |
|---|
| 560 | { |
|---|
| 561 | // Choose one photo at random |
|---|
| 562 | //TODO: manage multiple photos at once ( photo_count field in database ) |
|---|
| 563 | $photo = $photos[mt_rand(0, count($photos) - 1)]; |
|---|
| 564 | if (is_object($photo)) |
|---|
| 565 | { |
|---|
| 566 | $html .= '<div class="flickr_photo_block">'."\n"; |
|---|
| 567 | if ($this->shouldDisplayTitle()) |
|---|
| 568 | $html .= '<div class="flickr_title"><h3>'.$photo->getTitle().'</h3></div>'."\n"; |
|---|
| 569 | $html .= '<div class="flickr_photo"><a href="'.$photo->buildUrl().'"><img src="'.$photo->buildImgUrl().'"></a></div>'."\n"; |
|---|
| 570 | if ($this->shouldDisplayTags()) |
|---|
| 571 | { |
|---|
| 572 | $tags = $photo->getTags(); |
|---|
| 573 | if (!empty ($tags)) |
|---|
| 574 | { |
|---|
| 575 | $html .= '<div class="flickr_tags">'."\n"; |
|---|
| 576 | $html .= '<h3>'._("Tags")."</h3>\n"; |
|---|
| 577 | $html .= '<ul>'."\n"; |
|---|
| 578 | foreach ($tags as $tag) |
|---|
| 579 | { |
|---|
| 580 | $url_encoded_tag = urlencode($tag); |
|---|
| 581 | $html .= '<li><a href="http://www.flickr.com/photos/tags/'.$url_encoded_tag.'/">'.$tag.'</a></li>'."\n"; |
|---|
| 582 | } |
|---|
| 583 | $html .= '</ul>'."\n"; |
|---|
| 584 | $html .= '</div>'."\n"; |
|---|
| 585 | } |
|---|
| 586 | } |
|---|
| 587 | if ($this->shouldDisplayDescription()) |
|---|
| 588 | { |
|---|
| 589 | $description = $photo->getDescription(); |
|---|
| 590 | if (!empty ($description)) |
|---|
| 591 | $html .= '<div class="flickr_description">'.$description.'</div>'."\n"; |
|---|
| 592 | } |
|---|
| 593 | $html .= '</div>'."\n"; |
|---|
| 594 | } |
|---|
| 595 | } |
|---|
| 596 | else |
|---|
| 597 | { |
|---|
| 598 | $html .= _("No Flickr content matches the request !"); |
|---|
| 599 | } |
|---|
| 600 | } |
|---|
| 601 | catch (Phlickr_ConnectionException $e) |
|---|
| 602 | { |
|---|
| 603 | $html .= _("Unable to connect to Flickr API."); |
|---|
| 604 | } |
|---|
| 605 | catch (Phlickr_MethodFailureException $e) |
|---|
| 606 | { |
|---|
| 607 | $html .= _("Some of the request parameters provided to Flickr API are invalid."); |
|---|
| 608 | } |
|---|
| 609 | catch (Phlickr_XmlParseException $e) |
|---|
| 610 | { |
|---|
| 611 | $html .= _("Unable to parse Flickr's response."); |
|---|
| 612 | } |
|---|
| 613 | catch (Phlickr_Exception $e) |
|---|
| 614 | { |
|---|
| 615 | $html .= _("Could not get content from Flickr : ").$e; |
|---|
| 616 | } |
|---|
| 617 | |
|---|
| 618 | $html .= $subclass_user_interface; |
|---|
| 619 | $html .= "</div>\n"; |
|---|
| 620 | return parent :: getUserUI($html); |
|---|
| 621 | } |
|---|
| 622 | |
|---|
| 623 | /** Delete this Content from the database */ |
|---|
| 624 | public function delete(& $errmsg) |
|---|
| 625 | { |
|---|
| 626 | $user = User :: getCurrentUser(); |
|---|
| 627 | if (!$this->isOwner($user) || !$user->isSuperAdmin()) |
|---|
| 628 | { |
|---|
| 629 | $errmsg = _('Access denied!'); |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | if ($this->isPersistent() == false) |
|---|
| 633 | { |
|---|
| 634 | $this->mBd->ExecSqlUpdate("DELETE FROM flickr_photostream WHERE flickr_photostream_id = '".$this->getId()."'", false); |
|---|
| 635 | } |
|---|
| 636 | parent :: delete($errmsg); |
|---|
| 637 | } |
|---|
| 638 | |
|---|
| 639 | } // End class |
|---|
| 640 | } |
|---|
| 641 | ?> |
|---|