1<?php 2/** 3 * Ansel Hooks configuration file. 4 * 5 * THE HOOKS PROVIDED IN THIS FILE ARE EXAMPLES ONLY. DO NOT ENABLE THEM 6 * BLINDLY IF YOU DO NOT KNOW WHAT YOU ARE DOING. YOU HAVE TO CUSTOMIZE THEM 7 * TO MATCH YOUR SPECIFIC NEEDS AND SYSTEM ENVIRONMENT. 8 */ 9 10class Ansel_Hooks 11{ 12 /** 13 * Here is an example _ansel_hook_user_age(). is called to get the user age 14 * when he/she tries to view an age limited content. This function must 15 * return an integer value of user age 16 */ 17// public function user_age() 18// { 19// $query = 'SELECT age FROM user WHERE user_uid = ' . $GLOBALS['ansel_db']->quote($GLOBALS['registry']->getAuth()); 20// try { 21// return (int)$GLOBALS['ansel_db']->queryOne($query); 22// } catch (Ansel_Exception $e) { 23// return 0; 24// } 25// } 26 27 28 /** 29 * Example hook for sending a stream notification to facebook after a user 30 * uploads images to Ansel. This will likely go away, being replaced by 31 * by an remote image import/export functionality. 32 */ 33// public function postupload($image_ids) 34// { 35// $context = array('http_client' => new Horde_Http_Client(), 36// 'http_request' => new Horde_Controller_Request_Http(),); 37// $facebook = new Horde_Service_Facebook($GLOBALS['conf']['facebook']['key'], 38// $GLOBALS['conf']['facebook']['secret'], 39// $context); 40// $fbp = unserialize($GLOBALS['prefs']->getValue('facebook')); 41// 42// // If no prefs exist just exit since there's nowhere to publish to. 43// if (empty($fbp['sid'])) { 44// return; 45// } else { 46// $facebook->auth->setUser($fbp['uid'], $fbp['sid'], 0); 47// } 48// // Limit of the number of images to include. This should really come 49// // from a configuration parameter or at the very least, a user pref. 50// // (5 is the facebook api's max) 51// $limit = min(5, (count($image_ids))); 52// $images = $GLOBALS['ansel_storage']->getImages(array_slice($image_ids, 0, $limit)); 53// $perms = array(); 54// $media = array(); 55// foreach ($images as $image) { 56// // Only the gallery owner should be able to publish news about the 57// // gallery, and only public galleries with no passwd or age checks 58// // should be considered as well since the links on facebook would 59// // be useless. 60// if (!isset($perms[$image->gallery])) { 61// $g = $GLOBALS['ansel_storage']->getGallery($image->gallery); 62// $pwd = $g->get('passwd'); 63// $no_agelimit = empty($GLOBALS['conf']['ages']['limits']) || $g->get('age') == 0; 64// if ($GLOBALS['registry']->getAuth() && $g->get('owner') == $GLOBALS['registry']->getAuth() && empty($pwd) && $no_agelimit) { 65// $perms[$image->gallery] = true; 66// } else { 67// $perms[$image->gallery] = false; 68// } 69// } 70// if ($perms[$image->gallery]) { 71// $media[] = array('type' => 'image', 72// 'href' => Ansel::getUrlFor('view',array('view' => 'Image', 'image' => $image->id, 'gallery' => $image->gallery), true, -1), 73// 'src' => Ansel::getImageUrl($image->id, 'thumb', true)); 74// 75// } 76// } 77// // For this example, just use the last image's gallery title and description 78// $attachment = array('name' => $g->get('name'), 'caption' => $g->get('description'), 'media' => $media); 79// 80// //Do it. 81// try { 82// $facebook->streams->publish(sprintf("just uploaded these pictures to %s", $GLOBALS['registry']->get('name')), $attachment); 83// } catch (Horde_Service_Facebook_Exception $e) { 84// // For now, just pass back as a pear error...needs to be cleaned up 85// $GLOBALS['notification']->push('Horde_Service_Facebook: ' . $e->getMessage(), 'horde.err'); 86// throw new Horde_Exception_Wrapped($e); 87// } 88// if (!empty($GLOBALS['notification'])) { 89// $GLOBALS['notification']->push('Notification published to Facebook.', 'horde.success'); 90// } 91// } 92 93} 94