/php/photobucket_external_repository_manager.class.php
PHP | 199 lines | 113 code | 27 blank | 59 comment | 4 complexity | 7f33f24fec2ef8f748cbd2e795d379d1 MD5 | raw file
1<?php 2namespace common\extensions\external_repository_manager\implementation\photobucket; 3 4use common\libraries\Translation; 5use common\libraries\Request; 6use common\libraries\Path; 7use common\libraries\ActionBarSearchForm; 8use common\libraries\PatternMatchCondition; 9use common\libraries\OrCondition; 10use common\libraries\Utilities; 11 12use common\extensions\external_repository_manager\ExternalRepositoryManager; 13use common\extensions\external_repository_manager\ExternalRepositoryObject; 14use common\extensions\external_repository_manager\ExternalRepositoryObjectRenderer; 15use common\extensions\external_repository_manager\ExternalRepositoryObjectDisplay; 16 17use repository\ExternalSetting; 18use repository\content_object\document\Document; 19/** 20 * 21 * @author magali.gillard 22 * 23 */ 24class PhotobucketExternalRepositoryManager extends ExternalRepositoryManager 25{ 26 const REPOSITORY_TYPE = 'photobucket'; 27 28 const PARAM_FEED_TYPE = 'feed'; 29 const PARAM_FEED_IDENTIFIER = 'identifier'; 30 31 const FEED_TYPE_GENERAL = 1; 32 const FEED_TYPE_MY_PHOTOS = 2; 33 34 /** 35 * @param Application $application 36 */ 37 function __construct($external_repository, $application) 38 { 39 parent :: __construct($external_repository, $application); 40 $this->set_parameter(self :: PARAM_FEED_TYPE, Request :: get(self :: PARAM_FEED_TYPE)); 41 } 42 43 /* (non-PHPdoc) 44 * @see application/common/external_repository_manager/ExternalRepositoryManager#get_application_component_path() 45 */ 46 function get_application_component_path() 47 { 48 return Path :: get_common_extensions_path() . 'external_repository_manager/implementation/photobucket/php/component/'; 49 } 50 51 /* (non-PHPdoc) 52 * @see application/common/external_repository_manager/ExternalRepositoryManager#validate_settings() 53 */ 54 function validate_settings($external_repository) 55 { 56 $key = ExternalSetting :: get('consumer_key', $external_repository->get_id()); 57 $secret = ExternalSetting :: get('consumer_secret', $external_repository->get_id()); 58 59 if (! $key || ! $secret) 60 { 61 return false; 62 } 63 return true; 64 } 65 66 /* (non-PHPdoc) 67 * @see application/common/external_repository_manager/ExternalRepositoryManager#support_sorting_direction() 68 */ 69 function support_sorting_direction() 70 { 71 return true; 72 } 73 74 /** 75 * @param ExternalRepositoryObject $object 76 * @return string 77 */ 78 function get_external_repository_object_viewing_url(ExternalRepositoryObject $object) 79 { 80 $parameters = array(); 81 $parameters[self :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION] = self :: ACTION_VIEW_EXTERNAL_REPOSITORY; 82 $parameters[self :: PARAM_EXTERNAL_REPOSITORY_ID] = $object->get_id(); 83 84 return $this->get_url($parameters); 85 } 86 87 /* (non-PHPdoc) 88 * @see application/common/external_repository_manager/ExternalRepositoryManager#get_menu_items() 89 */ 90 function get_menu_items() 91 { 92 $menu_items = array(); 93 94 $my_photos = array(); 95 $my_photos['title'] = Translation :: get('MyPhotos'); 96 $my_photos['url'] = $this->get_url(array(self :: PARAM_FEED_TYPE => self :: FEED_TYPE_MY_PHOTOS), array( 97 ActionBarSearchForm :: PARAM_SIMPLE_SEARCH_QUERY)); 98 $my_photos['class'] = 'user'; 99 $menu_items[] = $my_photos; 100 101 $general = array(); 102 $general['title'] = Translation :: get('Public'); 103 $general['url'] = $this->get_url(array(self :: PARAM_FEED_TYPE => self :: FEED_TYPE_GENERAL), array( 104 ActionBarSearchForm :: PARAM_SIMPLE_SEARCH_QUERY)); 105 $general['class'] = 'home'; 106 $menu_items[] = $general; 107 108 return $menu_items; 109 } 110 111 /* (non-PHPdoc) 112 * @see application/common/external_repository_manager/ExternalRepositoryManager#is_ready_to_be_used() 113 */ 114 function is_ready_to_be_used() 115 { 116 return false; 117 } 118 119 /* (non-PHPdoc) 120 * @see application/common/external_repository_manager/ExternalRepositoryManager#get_external_repository_actions() 121 */ 122 function get_external_repository_actions() 123 { 124 $actions = array(self :: ACTION_BROWSE_EXTERNAL_REPOSITORY, self :: ACTION_UPLOAD_EXTERNAL_REPOSITORY, 125 self :: ACTION_EXPORT_EXTERNAL_REPOSITORY); 126 127 $is_platform = $this->get_user()->is_platform_admin() && (count(ExternalSetting :: get_all($this->get_external_repository()->get_id())) > 0); 128 129 if ($is_platform) 130 { 131 $actions[] = self :: ACTION_CONFIGURE_EXTERNAL_REPOSITORY; 132 } 133 134 return $actions; 135 } 136 137 /* (non-PHPdoc) 138 * @see application/common/external_repository_manager/ExternalRepositoryManager#get_available_renderers() 139 */ 140 function get_available_renderers() 141 { 142 return array(ExternalRepositoryObjectRenderer :: TYPE_GALLERY, 143 ExternalRepositoryObjectRenderer :: TYPE_SLIDESHOW, ExternalRepositoryObjectRenderer :: TYPE_TABLE); 144 } 145 146 /* (non-PHPdoc) 147 * @see application/common/external_repository_manager/ExternalRepositoryManager#get_content_object_type_conditions() 148 */ 149 function get_content_object_type_conditions() 150 { 151 $image_types = Document :: get_image_types(); 152 $image_conditions = array(); 153 foreach ($image_types as $image_type) 154 { 155 $image_conditions[] = new PatternMatchCondition(Document :: PROPERTY_FILENAME, '*.' . $image_type, Document :: get_type_name()); 156 } 157 158 return new OrCondition($image_conditions); 159 } 160 161 /** 162 * @return string 163 */ 164 function get_repository_type() 165 { 166 return self :: REPOSITORY_TYPE; 167 } 168 169 /** 170 * Helper function for the SubManager class, 171 * pending access to class constants via variables in PHP 5.3 172 * e.g. $name = $class :: DEFAULT_ACTION 173 * 174 * DO NOT USE IN THIS SUBMANAGER'S CONTEXT 175 * Instead use: 176 * - self :: DEFAULT_ACTION in the context of this class 177 * - YourSubManager :: DEFAULT_ACTION in all other application classes 178 */ 179 static function get_default_action() 180 { 181 return self :: DEFAULT_ACTION; 182 } 183 184 /** 185 * Helper function for the SubManager class, 186 * pending access to class constants via variables in PHP 5.3 187 * e.g. $name = $class :: PARAM_ACTION 188 * 189 * DO NOT USE IN THIS SUBMANAGER'S CONTEXT 190 * Instead use: 191 * - self :: PARAM_ACTION in the context of this class 192 * - YourSubManager :: PARAM_ACTION in all other application classes 193 */ 194 static function get_action_parameter() 195 { 196 return self :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION; 197 } 198} 199?>