289
* Count # of registrations of same plugin.
289
* Count # of registrations of same plugin. Optionally returns the sequence
290
* number to be used for the next instance of a plugin as well.
291
292
* Plugins with negative ID (auto-generated; not installed (yet)) will not get considered.
293
294
* @param string class name
294
* @return int # of regs
295
* @param boolean Return next sequence number as well (will be 1 if there are no other
296
* instances of this plugin).
297
* @return int|array # of regs or array( $regs, $next_seq_number ) if $get_seq_number is true
296
function count_regs( $classname )
299
function count_regs( $classname, $get_seq_number = false )
302
$highest_seq_number = 0;
300
304
foreach( $this->sorted_IDs as $plugin_ID )
302
$Plugin = & $this->get_by_ID( $plugin_ID );
306
$Plugin = $this->get_by_ID( $plugin_ID );
303
307
if( $Plugin && $Plugin->classname == $classname && $Plugin->ID > 0 )
311
// We assume that nobody has tinkered with the plugin codes in the DB here!
312
if( $get_seq_number && $Plugin->code !== NULL &&
313
preg_match( '/_(\d+)$/', $Plugin->code, $m ) &&
314
$m[1] > $highest_seq_number )
316
$highest_seq_number = $m[1];
321
if( $get_seq_number )
323
return array( $count, ( $highest_seq_number ? $highest_seq_number : $count ) + 1 );
491
509
$this->load_plugins_table();
493
511
// Register the plugin:
494
$Plugin = & $this->register( $classname, 0, -1, NULL, $classfile_path ); // Auto-generates negative ID; New ID will be set a few lines below
512
// Auto-generates negative ID; New ID will be set a few lines below
513
$Plugin = $this->register( $classname, 0, -1, NULL, $classfile_path,
496
516
if( is_string($Plugin) )
497
517
{ // return error message from register()
521
list( $regs, $seq_number ) = $this->count_regs( $Plugin->classname, true );
501
522
if( isset($Plugin->number_of_installs)
502
&& ( $this->count_regs( $Plugin->classname ) >= $Plugin->number_of_installs ) )
523
&& ( $regs >= $Plugin->number_of_installs ) )
504
525
$this->unregister( $Plugin, true );
505
526
$r = T_('The plugin cannot be installed again.');
540
561
$Plugin->code = NULL;
564
// Do we have multiple instances of this plugin installed? If yes, we
565
// want a sequential name and code to make the admin's life a bit easier.
566
if( $seq_number > 1 )
568
if( $Plugin->code === NULL )
570
$Plugin->code = ! empty( $orig_code ) ? $orig_code : $classname;
573
$instance_name = $Plugin->name.' #'.$seq_number;
574
$Plugin->name = $instance_name;
575
$Plugin->code .= '_'.$seq_number;
543
578
$Plugin->status = $plug_status;
545
580
// Record into DB
549
INSERT INTO T_plugins( plug_classname, plug_priority, plug_code, plug_apply_rendering, plug_version, plug_status )
550
VALUES( "'.$classname.'", '.$Plugin->priority.', '.$DB->quote($Plugin->code).', '.$DB->quote($Plugin->apply_rendering).', '.$DB->quote($Plugin->version).', '.$DB->quote($Plugin->status).' ) ' );
584
INSERT INTO T_plugins( plug_classname, plug_priority, plug_code, plug_apply_rendering, plug_version, plug_name, plug_status )
585
VALUES( "'.$classname.'", '.$Plugin->priority.', '.$DB->quote($Plugin->code).', '.$DB->quote($Plugin->apply_rendering).', '.$DB->quote($Plugin->version).', '.$DB->quote($Plugin->name).', '.$DB->quote($Plugin->status).' ) ' );
552
587
// Unset auto-generated ID info
553
588
unset( $this->index_ID_Plugins[ $Plugin->ID ] );
562
597
'plug_classname' => $Plugin->classname,
563
598
'plug_code' => $Plugin->code,
564
599
'plug_apply_rendering' => $Plugin->apply_rendering,
600
'plug_version' => $Plugin->version,
601
'plug_name' => $Plugin->name,
565
602
'plug_status' => $Plugin->status,
566
'plug_version' => $Plugin->version,
568
604
$this->sorted_IDs[$key] = $Plugin->ID;
589
625
$Debuglog->add( 'Unregistered plugin, because PluginInit returned false.', 'plugins' );
628
else if( isset( $instance_name ) )
629
{ // $Plugin->PluginInit( $tmp_params ) lost our new name :(
630
$Plugin->name = $instance_name;
593
633
if( ! defined('QP_IS_INSTALLING') || ! QP_IS_INSTALLING )
594
634
{ // do not sort, if we're installing/upgrading.. instantiating Plugins might cause a fatal error!