Merge pull request #404 from CyberDomovoy/hook_priority

Hook priority
This commit is contained in:
friendica 2012-07-23 16:50:22 -07:00
commit ea2c3748f0
4 changed files with 15 additions and 6 deletions

View file

@ -12,7 +12,7 @@ require_once('include/cache.php');
define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_VERSION', '3.0.1412' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1153 );
define ( 'DB_UPDATE_VERSION', 1154 );
define ( 'EOL', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );

View file

@ -456,6 +456,7 @@ CREATE TABLE IF NOT EXISTS `hook` (
`hook` char(255) NOT NULL,
`file` char(255) NOT NULL,
`function` char(255) NOT NULL,
`priority` int(11) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

View file

@ -111,7 +111,7 @@ function reload_plugins() {
if(! function_exists('register_hook')) {
function register_hook($hook,$file,$function) {
function register_hook($hook,$file,$function,$priority=0) {
$r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
dbesc($hook),
@ -121,10 +121,11 @@ function register_hook($hook,$file,$function) {
if(count($r))
return true;
$r = q("INSERT INTO `hook` (`hook`, `file`, `function`) VALUES ( '%s', '%s', '%s' ) ",
$r = q("INSERT INTO `hook` (`hook`, `file`, `function`, `priority`) VALUES ( '%s', '%s', '%s', '%s' ) ",
dbesc($hook),
dbesc($file),
dbesc($function)
dbesc($function),
dbesc($priority)
);
return $r;
}}
@ -145,7 +146,7 @@ if(! function_exists('load_hooks')) {
function load_hooks() {
$a = get_app();
$a->hooks = array();
$r = q("SELECT * FROM `hook` WHERE 1");
$r = q("SELECT * FROM `hook` WHERE 1 ORDER BY `priority` DESC");
if(count($r)) {
foreach($r as $rr) {
if(! array_key_exists($rr['hook'],$a->hooks))

View file

@ -1,6 +1,6 @@
<?php
define( 'UPDATE_VERSION' , 1153 );
define( 'UPDATE_VERSION' , 1154 );
/**
*
@ -1337,3 +1337,10 @@ function update_1152() {
return UPDATE_SUCCESS;
}
function update_1153() {
$r = q("ALTER TABLE `hook` ADD `priority` INT(11) UNSIGNED NOT NULL DEFAULT '0'");
if(!$r) return UPDATE_FAILED;
return UPDATE_SUCCESS;
}