Changeset 11977
- Timestamp:
- 09/03/07 16:52:19 (1 year ago)
- Files:
-
- trunk/midcom/net.nemein.teams/config/config.inc (modified) (1 diff)
- trunk/midcom/net.nemein.teams/config/schemadb_default.inc (modified) (1 diff)
- trunk/midcom/net.nemein.teams/handler/admin.php (modified) (1 diff)
- trunk/midcom/net.nemein.teams/handler/team.php (modified) (7 diffs)
- trunk/midcom/net.nemein.teams/logger.php (modified) (1 diff)
- trunk/midcom/net.nemein.teams/midcom/interfaces.php (modified) (2 diffs)
- trunk/midcom/net.nemein.teams/style/application.php (modified) (1 diff)
- trunk/midcom/net.nemein.teams/style/registered_index.php (modified) (1 diff)
- trunk/midcom/net.nemein.teams/style/teams_list_end.php (modified) (1 diff)
- trunk/midcom/net.nemein.teams/style/teams_list_item.php (modified) (1 diff)
- trunk/midcom/net.nemein.teams/style/teams_list_start.php (modified) (1 diff)
- trunk/midcom/net.nemein.teams/team.php (modified) (1 diff)
- trunk/midcom/net.nemein.teams/viewer.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midcom/net.nemein.teams/config/config.inc
r11965 r11977 13 13 * This is used when having created the complete crud component - not just the basic one. 14 14 * */ 15 'schema ' => 'default',15 'schema_team_create' => 'team', 16 16 17 17 'teams_root_guid' => 'bd153978547111dcbbc6cf47b1b3dd3fdd3f', 18 18 'create_team_home' => true, 19 'create_team_home_plugin' => 'create_team_home', 20 'display_teams_per_page' => 1, 21 'display_pages' => 10, 22 23 /** 24 * Plugins and other miscellaneous configuration keys 25 */ 26 // see the docs of the viewer/admin classes for details about the plugin handlers 27 /* 28 'plugins' => array 29 ( 30 'create_team_home' => Array 31 ( 32 'class' => 'midgard_admin_sitewizard_plugin', 33 'src' => 'file:/net/nemein/teams/plugins/midgard_admin_sitewizard_plugin.php', 34 'name' => 'Team home creation', 35 'config' => Array 36 ( 37 'sitewizard_path' => '/usr/share/php/midcom/static/data/midgard_admin_sitewizard.php', 38 'host_guid' => '983e66725acd11db845a197adaa843af43af', 39 'creation_root_topic_guid' => '6d3af3384be911dcb7b0b3bf4b275d0d5d0d', 40 'creation_root_topic_parent_guid' => '6d3af3384be911dcb7b0b3bf4b275d0d5d0d', 41 'creation_root_topic_component' => 'net.nehmer.static', 42 'creation_root_topic_parameters' => array(), 43 'creation_root_group_guid' => '94f058364f0f11dc93f803ebc4b67c0c7c0c', 44 'creation_root_group_parent_guid' => '', 45 'creation_root_group_name' => '', 46 'verbose' => true, 47 'structure_config_path' => '/usr/share/midgard/svn/midcom-trunk/net.nemein.teams/plugins/leet_team_home_structure.inc', 48 ), 49 ), 50 ), 51 */ trunk/midcom/net.nemein.teams/config/schemadb_default.inc
r11965 r11977 19 19 'team_name' => Array 20 20 ( 21 'title' => 'team name',22 'storage' => 'name',23 'type' => 'text',24 'widget' => 'text',21 'title' => 'team name', 22 'storage' => 'name', 23 'type' => 'text', 24 'widget' => 'text', 25 25 ), 26 'team_logo' => Array 27 ( 28 'title' => 'team logo', 29 'storage' => null, 30 'type' => 'image', 31 'type_config' => Array 26 'team_logo' => Array 32 27 ( 33 'filter_chain' => 'resize(800,600)', 34 'auto_thumbnail' => Array(100,100), 35 'keep_original' => true, 28 'title' => 'team logo', 29 'storage' => null, 30 'type' => 'image', 31 'type_config' => Array 32 ( 33 'filter_chain' => 'resize(800,600)', 34 'auto_thumbnail' => Array(100,100), 35 'keep_original' => true, 36 ), 37 'widget' => 'image', 38 'hidden' => false, 36 39 ), 37 'widget' => 'image',38 'hidden' => false,39 ),40 40 'team_description' => Array 41 41 ( 42 'title' => 'team introduction text',43 'storage' => 'parameter',44 'type' => 'text',45 'widget' => 'textarea',42 'title' => 'team introduction text', 43 'storage' => 'parameter', 44 'type' => 'text', 45 'widget' => 'textarea', 46 46 ), 47 47 'team_location' => Array 48 48 ( 49 'title' => 'team location',50 'storage' => 'parameter',51 'type' => 'text',52 'widget' => 'text',49 'title' => 'team location', 50 'storage' => 'parameter', 51 'type' => 'text', 52 'widget' => 'text', 53 53 ), 54 54 trunk/midcom/net.nemein.teams/handler/admin.php
r11965 r11977 49 49 50 50 $qb = net_nemein_teams_log_dba::new_query_builder(); 51 $qb->add_constraint('teamguid', '=', 'koe');52 $qb->add_order('metadata.created', ' ASC');51 //$qb->add_constraint('teamguid', '=', 'koe'); 52 $qb->add_order('metadata.created', 'DESC'); 53 53 54 $logs = $qb->execute();54 $logs = $qb->execute(); 55 55 56 $this->_request_data['logs'] = $logs;56 $this->_request_data['logs'] = $logs; 57 57 58 58 trunk/midcom/net.nemein.teams/handler/team.php
r11965 r11977 24 24 25 25 var $_controller = null; 26 27 var $_datamanager = null; 26 28 27 29 var $_content_topic = null; 28 30 29 31 var $_team_group = null; 32 33 var $_team_member = null; 34 35 var $_teams_list = Array(); 30 36 31 37 /** … … 46 52 if ($this->_config->get('teams_root_guid') != '') 47 53 { 48 $root_group_guid = $this->_config->get('teams_root_guid');49 $this->_root_group = new midcom_db_group($root_group_guid);50 }51 52 $this->_content_topic =& $this->_request_data['content_topic'];54 $root_group_guid = $this->_config->get('teams_root_guid'); 55 $this->_root_group = new midcom_db_group($root_group_guid); 56 } 57 58 $this->_content_topic =& $this->_request_data['content_topic']; 53 59 } 54 60 55 61 function _is_player() 56 62 { 63 $members = 0; 64 57 65 $qb = midcom_db_group::new_query_builder(); 58 $qb->add_constraint('owner', '=', $this->_root_group->id);59 60 $teams = $qb->execute();61 62 if (count($teams) > 0)63 {64 // Checing if user is a member of a team65 foreach($teams as $team)66 {67 $qb = midcom_db_member::new_query_builder();68 $qb->add_constraint('gid.id', '=', $team->id);69 $qb->add_constraint('uid.id', '=', $_MIDCOM->auth->user->_storage->id);66 $qb->add_constraint('owner', '=', $this->_root_group->id); 67 68 $teams = $qb->execute(); 69 70 if (count($teams) > 0) 71 { 72 // Checing if user is a member of a team 73 foreach($teams as $team) 74 { 75 $qb = midcom_db_member::new_query_builder(); 76 $qb->add_constraint('gid.id', '=', $team->id); 77 $qb->add_constraint('uid.id', '=', $_MIDCOM->auth->user->_storage->id); 70 78 71 $members = $qb->execute(); 72 73 if (count($members) > 0) 74 { 75 return true; 76 } 77 else 78 { 79 return false; 80 } 81 } 82 } 83 84 return false; 79 $members = $qb->execute(); 80 81 if (count($members) > 0) 82 { 83 $members++; 84 } 85 } 86 } 87 88 if ($members > 0) 89 { 90 return false; 91 } 92 93 return false; 85 94 } 86 95 … … 97 106 { 98 107 $this->_load_schemadb(); 99 $this->_controller =& midcom_helper_datamanager2_controller::create('create'); 100 $this->_controller->schemadb =& $this->_schemadb; 101 $this->_controller->schemaname = 'team'; 102 //$this->_controller->defaults = $this->_defaults; 103 $this->_controller->callback_object =& $this; 104 if (! $this->_controller->initialize()) 105 { 106 $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Failed to initialize a DM2 create controller."); 107 // This will exit. 108 $this->_controller =& midcom_helper_datamanager2_controller::create('create'); 109 $this->_controller->schemadb =& $this->_schemadb; 110 $this->_controller->schemaname = 'team'; 111 //$this->_controller->defaults = $this->_defaults; 112 $this->_controller->callback_object =& $this; 113 if (! $this->_controller->initialize()) 114 { 115 $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Failed to initialize a DM2 create controller."); 116 // This will exit. 117 } 118 } 119 120 /** 121 * Internal helper, loads the datamanager for a team group. Any error triggers a 500. 122 * 123 * @access private 124 */ 125 function _load_datamanager($team_group) 126 { 127 $this->_datamanager = new midcom_helper_datamanager2_datamanager($this->_request_data['schemadb']); 128 129 if ( ! $this->_datamanager 130 || ! $this->_datamanager->autoset_storage($team_group)) 131 { 132 $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 133 "Failed to create a DM2 instance for team {$team_group->id}."); 134 // This will exit. 135 } 136 } 137 138 function & dm2_create_callback (&$controller) 139 { 140 $this->_team_group = new midcom_db_group(); 141 $this->_team_group->owner = $this->_root_group->id; 142 143 if (!$this->_team_group->create()) 144 { 145 // TODO: handle error 146 147 } 148 else 149 { 150 $this->_team_member = new midcom_db_member(); 151 $this->_team_member->gid = $this->_team_group->id; 152 $this->_team_member->uid = $_MIDCOM->auth->user->_storage->id; 153 154 if (!$this->_team_member->create()) 155 { 156 // TODO: handle error 157 } 158 else 159 { 160 $this->_logger->log("Team group created by " . $_MIDCOM->auth->user->_storage->username, 161 $this->_team_group->guid); 162 } 163 } 164 165 return $this->_team_group; 166 } 167 168 function _prepare_request_data() 169 { 170 $this->_request_data['controller'] =& $this->_controller; 171 $this->_request_data['datamanager'] =& $this->_datamanager; 172 } 173 174 function _handler_create ($handler_id, $args, &$data) 175 { 176 $title = $this->_l10n_midcom->get('create team'); 177 $_MIDCOM->set_pagetitle(":: {$title}"); 178 179 $this->_load_controller(); 180 181 if ($this->_is_player()) 182 { 183 // TODO: redirect somewhere 184 $_MIDCOM->relocate(''); 185 186 } 187 else 188 { 189 $this->_content_topic->require_do('midgard:create'); 190 191 switch ($this->_controller->process_form()) 192 { 193 case 'save': 194 195 $team = new net_nemein_teams_team_dba(); 196 $team->groupguid = $this->_team_group->guid; 197 $team->managerguid = $_MIDCOM->auth->user->guid; 198 199 if (!$team->create()) 200 { 201 // TODO: Handle error 202 } 203 else 204 { 205 $this->_logger->log("Team object created by " . $_MIDCOM->auth->user->_storage->username, 206 $this->_team_group->guid); 207 208 if ($this->_config->get('create_team_home')) 209 { 210 $plugin_name = $this->_config->get('create_team_home_plugin'); 211 212 if (!empty($plugin_name)) 213 { 214 $_MIDCOM->relocate("plugin/{$plugin_name}"); 215 } 216 else 217 { 218 $_MIDCOM->relocate(''); 219 } 220 } 221 else 222 { 223 $_MIDCOM->relocate(''); 224 } 225 } 226 227 case 'cancel': 228 229 $_MIDCOM->relocate(''); 230 // This will exit. 231 } 232 233 $this->_prepare_request_data(); 108 234 } 109 } 110 111 function & dm2_create_callback (&$controller) 112 { 113 $this->_team_group = new midcom_db_group(); 114 115 if (!$this->_team_group->create()) 116 { 117 // TODO: handle error 118 119 } 120 121 return $this->_team_group; 122 } 123 124 function _prepare_request_data() 125 { 126 $this->_request_data['controller'] =& $this->_controller; 127 } 128 129 function _handler_create ($handler_id, $args, &$data) 235 236 return true; 237 } 238 239 function _handler_application ($handler_id, $args, &$data) 130 240 { 131 241 $title = $this->_l10n_midcom->get('application'); 132 242 $_MIDCOM->set_pagetitle(":: {$title}"); 133 134 if ($this->_is_player()) 135 { 136 // TODO: redirect somewhere 137 } 138 else 139 { 140 $this->_content_topic->require_do('midgard:create'); 141 142 $this->_load_controller(); 143 144 switch ($this->_controller->process_form()) 145 { 146 case 'save': 147 148 $team = new net_nemein_teams_team_dba(); 149 $team->group_guid = $this->_team_group->guid; 150 $team->manager_guid = $_MIDCOM->auth->user->guid; 151 152 if (!$team->crate()) 153 { 154 // TODO: Handle error 155 } 156 else 157 { 158 if ($this->_config->get('create_team_home')) 159 { 160 $_MIDCOM->relocate("/create/home/{$this->_team_group->guid}"); 161 } 162 else 163 { 164 $_MIDCOM->relocate(''); 165 } 166 } 167 168 case 'cancel': 169 170 $_MIDCOM->relocate(''); 171 // This will exit. 172 } 173 174 $this->_prepare_request_data(); 175 } 176 177 return true; 178 } 179 180 function _handler_application ($handler_id, $args, &$data) 181 { 182 $title = $this->_l10n_midcom->get('application'); 183 $_MIDCOM->set_pagetitle(":: {$title}"); 184 243 244 $qb = net_nemein_teams_team_dba::new_query_builder(); 245 $qb->add_constraint('managerguid', '=', $args[0]); 246 247 if (!$teams = $qb->execute()) 248 { 249 250 } 251 252 if (count($teams) > 1) 253 { 254 // TODO: this shouldn't happen...handle error 255 } 256 257 $team_group = new midcom_db_group($teams[0]->groupguid); 258 259 if (!is_object($team_group)) 260 { 261 // TODO: cant find group...handle this 262 } 263 else 264 { 265 $this->_request_data['team_name'] = $team_group->name; 266 $this->_request_data['team_manager'] = $teams[0]->managerguid; 267 } 268 185 269 // TODO: Private message to team manager 186 187 if ($_POST['submit_application']) 188 {270 if (isset($_POST['submit_application'])) 271 { 272 189 273 190 274 $_MIDCOM->relocate(''); 191 }192 193 return true;275 } 276 277 return true; 194 278 } 195 279 … … 200 284 201 285 202 return true;286 return true; 203 287 } 204 288 … … 208 292 $_MIDCOM->set_pagetitle(":: {$title}"); 209 293 210 // TODO: sitewizard magic294 // TODO: sitewizard magic 211 295 212 296 return true; 213 297 } 214 298 299 /** 300 * Populates a lis of all registered teams 301 */ 215 302 function _handler_teams_list($handler_id, $args, &$data) 216 { 217 218 $this->_request_data['teams_list'] = Array(); 303 { 304 $qb = new org_openpsa_qbpager('net_nemein_teams_team_dba', 'net_nemein_teams_team'); 305 $qb->results_per_page = $this->_config->get('display_teams_per_page'); 306 $qb->display_pages = $this->_config->get('display_pages'); 307 308 $data['team_qb'] =& $qb; 309 $this->_teams_list = $qb->execute(); 310 311 $this->_prepare_request_data(); 219 312 220 313 return true; 221 314 } 315 316 function _handler_approve($handler_id, $args, &$data) 317 { 318 319 320 return true; 321 } 322 323 function _show_approve($handler_id, &$data) 324 { 325 326 } 222 327 223 328 function _show_teams_list($handler_id, &$data) 224 { 329 { 330 $member_count = 0; 331 225 332 midcom_show_style('teams_list_start'); 226 227 foreach ($this->_request_data['teams_list'] as $team) 228 { 229 $this->_request_data['team'] = $team; 333 334 foreach($this->_teams_list as $team) 335 { 336 $member_count = $team->count_members(); 337 $team_group = new midcom_db_group($team->groupguid); 338 339 $this->_load_datamanager($team_group); 340 $this->_request_data['view_team'] = $this->_request_data['datamanager']->get_content_html(); 341 $this->_request_data['view_team']['team_member_count'] = $member_count; 342 230 343 midcom_show_style('teams_list_item'); 231 }232 233 midcom_show_style('teams_list_end');344 } 345 346 midcom_show_style('teams_list_end'); 234 347 } 235 348 … … 241 354 function _show_create($handler_id, &$data) 242 355 { 356 $this->_request_data['controller'] = $this->_controller; 357 243 358 midcom_show_style('team_creation_form'); 244 359 } … … 252 367 { 253 368 if ($_MIDCOM->auth->user) 254 {369 { 255 370 if ($this->_is_player()) 256 {371 { 257 372 midcom_show_style('player_index'); 258 } 373 } 374 else 375 { 376 midcom_show_style('registered_index'); 377 } 378 } 259 379 else 260 380 { 261 midcom_show_style('registered_index');262 }263 }264 else265 {266 381 midcom_show_style('index'); 267 }382 } 268 383 } 269 384 trunk/midcom/net.nemein.teams/logger.php
r11965 r11977 14 14 15 15 $log = new net_nemein_teams_log_dba(); 16 $log->message = $message;17 $log->teamguid = $teamguid;16 $log->message = $message; 17 $log->teamguid = $teamguid; 18 18 19 if (!$log->create())20 {19 if (!$log->create()) 20 { 21 21 // TODO: handle error 22 }22 } 23 23 } 24 24 } trunk/midcom/net.nemein.teams/midcom/interfaces.php
r11965 r11977 30 30 //'admin.php', 31 31 'navigation.php', 32 'log.php',33 'logger.php',34 'team.php'32 'log.php', 33 'logger.php', 34 'team.php', 35 35 ); 36 36 … … 38 38 $this->_autoload_libraries = array 39 39 ( 40 'midcom.helper.datamanager2' 40 'midcom.helper.datamanager2', 41 'org.openpsa.qbpager', 42 //'net.nehmer.mail', 41 43 ); 42 44 } trunk/midcom/net.nemein.teams/style/application.php
r11965 r11977 5 5 */ 6 6 //$data =& $_MIDCOM->get_custom_context_data('request_data'); 7 7 8 ?> 8 9 <h1><?php echo $data['l10n']->get('Application'); ?></h1> 10 <h2><?php echo $data['l10n']->get('Apply to team') . " - " . $data['team_name']; ?></h2> 9 11 <p> 10 12 <form method="post" name="team_application" lass="net_nmein_team_application"> 13 <input type="hidden" name="applyee" value="<?php echo $_MIDCOM->auth->user->guid; ?>"/> 14 <input type="hidden" name="manager" value="<?php echo $data['team_manager']; ?>"/> 11 15 Message:<br/> 12 16 <textarea name="private_application"></textarea> trunk/midcom/net.nemein.teams/style/registered_index.php
r11965 r11977 6 6 //$data =& $_MIDCOM->get_custom_context_data('request_data'); 7 7 ?> 8 <h1> Registered</h1>8 <h1><?php echo $data['l10n']->get('registered'); ?></h1> 9 9 10 Create a team / join a team 10 <a class="net_nemein_teams_create" href="create"> 11 <?php echo $data['l10n']->get('create a team'); ?> 12 </a> 11 13 12 14 15 trunk/midcom/net.nemein.teams/style/teams_list_end.php
r11965 r11977 1 <?php 2 //$data =& $_MIDCOM->get_custom_context_data('request_data'); 3 ?> 4 5 </ul> 6 7 <?php 8 $data['team_qb']->show_pages(); 9 ?> trunk/midcom/net.nemein.teams/style/teams_list_item.php
r11965 r11977 1 <?php 2 //$data =& $_MIDCOM->get_custom_context_data('request_data'); 3 ?> 4 5 <li> 6 <?php 7 echo "<pre>"; 8 print_r($data['view_team']); 9 echo "</pre>"; 10 11 ?> 12 </li> trunk/midcom/net.nemein.teams/style/teams_list_start.php
r11965 r11977 1 <?php 2 //$data =& $_MIDCOM->get_custom_context_data('request_data'); 3 ?> 4 5 <h1><?php echo $data['l10n']->get('teams list'); ?></h1> 6 7 <ul class="net_nemein_teams_list"> trunk/midcom/net.nemein.teams/team.php
r11965 r11977 8 8 parent::__net_nemein_teams_team_dba($src); 9 9 } 10 10 11 function count_members() 12 { 13 $qb = midcom_db_member::new_query_builder(); 14 $qb->add_constraint('gid.guid', '=', $this->groupguid); 15 $count = $qb->count(); 16 17 return $count; 18 } 11 19 } 12 20 trunk/midcom/net.nemein.teams/viewer.php
r11965 r11977 55 55 ( 56 56 'handler' => Array('net_nemein_teams_handler_team', 'application'), 57 'fixed_args' => Array('application'), 57 'fixed_args' => Array('application'), 58 'variable_args' => 1, 58 59 ); 59 60 … … 62 63 ( 63 64 'handler' => Array('net_nemein_teams_handler_team', 'shares'), 64 'fixed_args' => Array('shares'),65 'fixed_args' => Array('shares'), 65 66 ); 66 67 … … 69 70 ( 70 71 'handler' => Array('net_nemein_teams_handler_admin', 'log'), 71 'fixed_args' => Array('log'),72 'fixed_args' => Array('log'), 72 73 ); 73 74 … … 76 77 ( 77 78 'handler' => Array('net_nemein_teams_handler_team', 'teams_list'), 78 'fixed_args' => Array('list'),79 ); 80 /* 81 // Log/82 $this->_request_switch[' log'] = array83 ( 84 'handler' => Array('net_nemein_teams_handler_ admin', 'log'),85 'fixed_args' => Array('log'),86 ); 87 */ 79 'fixed_args' => Array('list'), 80 ); 81 82 // Approve / 83 $this->_request_switch['approve'] = array 84 ( 85 'handler' => Array('net_nemein_teams_handler_team', 'approve'), 86 'fixed_args' => Array('approve'), 87 ); 88 88 89 // Create / 89 90 $this->_request_switch['create'] = array 90 91 ( 91 92 'handler' => Array('net_nemein_teams_handler_team', 'create'), 92 'fixed_args' => Array('create'),93 ); 94 93 'fixed_args' => Array('create'), 94 ); 95 /* 95 96 // Create / home 96 97 $this->_request_switch['create_team_home'] = array 97 98 ( 98 99 'handler' => Array('net_nemein_teams_handler_team', 'create_team_home'), 99 'fixed_args' => Array('create', 'home'), 100 'variable_args' => 1, 101 ); 102 100 'fixed_args' => Array('create', 'home'), 101 'variable_args' => 1, 102 ); 103 */ 104 } 105 106 /** 107 * Loads the plugin identified by $name. Only the on-site listing is loaded. 108 * If the plugin has no on-site interface, no changes are made to the request switch. 109 * 110 * Each request handler of the plugin is automatically adjusted as follows: 111 * 112 * - 1st, the registered names of the registered handlers (array keys) are prefixed by 113 * "plugin-{$name}-". 114 * - 2nd, all registered handlers are automatically prefixed by the fixed arguments 115 * ("plugin", $name). 116 * 117 * @param string $name The plugin name as registered in the plugins configuration 118 * option. 119 * @access private 120 */ 121 function _load_nna_plugin($name) 122 { 123 // Validate the plugin name and load the associated configuration 124 $plugins = $this->_config->get('plugins'); 125 if ( ! $plugins 126 || ! array_key_exists($name, $plugins)) 127 { 128 return false; 129 } 130 $plugin_config = $plugins[$name]; 131 132 // Load the plugin class, errors are logged by the callee 133 if (! $this->_load_nna_plugin_class($name, $plugin_config)) 134 { 135 return false; 136 } 137 138 // Load the configuration into the request data, add the configured plugin name as 139 // well so that URLs can be built. 140 if (array_key_exists('config', $plugin_config)) 141 { 142 $this->_request_data['plugin_config'] = $plugin_config['config']; 143 } 144 else 145 { 146 $this->_request_data['plugin_config'] = null; 147 } 148 $this->_request_data['plugin_name'] = $name; 149 150 // Load remaining configuration, and prepare the plugin, errors are logged by the callee. 151 $handlers = call_user_func(array($plugin_config['class'], 'get_plugin_handlers')); 152 if (! $this->_prepare_nna_plugin($name, $plugin_config, $handlers)) 153 { 154 return false; 155 } 156 return true; 157 } 158 159 /** 160 * Prepares the actual plugin by adding all neccessary information to the request 161 * switch. 162 * 163 * @param string $name The plugin name as registered in the plugins configuration 164 * option. 165 * @param Array $plugin_config The configuration associated with the plugin. 166 * @param Array $handlers The plugin specific handlers without the appropriate prefixes. 167 * @access private 168 * @return bool Indicating Success 169 */ 170 function _prepare_nna_plugin ($name, $plugin_config, $handlers) 171 { 172 foreach ($handlers as $identifier => $handler_config) 173 { 174 // First, update the fixed args list (be tolarent here) 175 if (! array_key_exists('fixed_args', $handler_config)) 176 { 177 $handler_config['fixed_args'] = Array('plugin', $name); 178 } 179 else if (! is_array($handler_config['fixed_args'])) 180 { 181 $handler_config['fixed_args'] = Array('plugin', $name, $handler_config['fixed_args']); 182 } 183 else 184 { 185 $handler_config['fixed_args'] = array_merge 186 ( 187 Array('plugin', $name), 188 $handler_config['fixed_args'] 189 ); 190 } 191 192 $this->_request_switch["plugin-{$name}-{$identifier}"] = $handler_config; 193 } 194 195 return true; 196 } 197 198 /** 199 * Loads the file/snippet neccessary for a given plugin, according to its configuration. 200 * 201 * @param string $name The plugin name as registered in the plugins configuration 202 * option. 203 * @param Array $plugin_config The configuration associated with the plugin. 204 * @access private 205 * @return bool Indicating Success 206 */ 207 function _load_nna_plugin_class($name, $plugin_config) 208 { 209 // Sanity check, we return directly if the configured class name is already 210 // available (dynamic_load could trigger this). 211 if (class_exists($plugin_config['class'])) 212 { 213 return true; 214 } 215 216 if (substr($plugin_config['src'], 0, 5) == 'file:') 217 { 218 // Load from file 219 require(MIDCOM_ROOT . substr($plugin_config['src'], 5)); 220 } 221 else 222 { 223 // Load from snippet 224 mgd_include_snippet_php($plugin_config['src']); 225 } 226 227 if (! class_exists($plugin_config['class'])) 228 { 229 return false; 230 } 231 232 return true; 103 233 } 104 234 … … 195 325 return true; 196 326 } 327 328 /** 329 * This event hook will load any on-site plugin that has been recognized in the configuration. 330 * Regardless of success, we always return true; the plugin simply won't start up if, for example, 331 * the name is unknown. 332 * 333 * @access protected 334 */ 335 function _on_can_handle($argc, $argv) 336 { 337 if ( $argc >= 2 338 && $argv[0] == 'plugin') 339 { 340 /** 341 * We do not need to check result of this operation, it populates request switch 342 * if successfull and does nothing if not, this means normal request handling is enough 343 */ 344 $this->_load_nna_plugin($argv[1]); 345 } 346 347 return true; 348 } 197 349 } 198 350
