2005-04-09 12:26:45 +00:00
< ? php
/**
*
* @ package phpBB3
* @ version $Id $
* @ copyright ( c ) 2005 phpBB Group
* @ license http :// opensource . org / licenses / gpl - license . php GNU Public License
*
*/
2004-10-31 13:26:38 +00:00
2005-04-09 12:26:45 +00:00
/**
2005-10-04 21:24:51 +00:00
* Class handling all types of 'plugins' ( a future term )
2006-03-09 18:32:50 +00:00
* @ package phpBB3
2005-04-09 12:26:45 +00:00
*/
2005-10-04 21:24:51 +00:00
class p_master
2004-10-31 13:26:38 +00:00
{
2005-10-04 21:24:51 +00:00
var $p_id ;
var $p_class ;
var $p_name ;
var $p_mode ;
var $p_parent ;
2006-07-01 19:11:52 +00:00
var $active_module = false ;
2007-01-22 17:05:23 +00:00
var $active_module_row_id = false ;
2006-06-06 20:53:46 +00:00
var $acl_forum_id = false ;
2004-10-31 13:26:38 +00:00
var $module_ary = array ();
2005-10-04 21:24:51 +00:00
/**
* List modules
*
* This creates a list , stored in $this -> module_ary of all available
* modules for the given class ( ucp , mcp and acp ) . Additionally
* $this -> module_y_ary is created with indentation information for
* displaying the module list appropriately . Only modules for which
* the user has access rights are included in these lists .
*/
function list_modules ( $p_class )
2004-10-31 13:26:38 +00:00
{
2006-03-09 18:32:50 +00:00
global $auth , $db , $user , $cache ;
2005-10-04 21:24:51 +00:00
global $config , $phpbb_root_path , $phpEx ;
2004-10-31 13:26:38 +00:00
2005-10-04 21:24:51 +00:00
// Sanitise for future path use, it's escaped as appropriate for queries
$this -> p_class = str_replace ( array ( '.' , '/' , '\\' ), '' , basename ( $p_class ));
2004-10-31 13:26:38 +00:00
2006-03-09 18:32:50 +00:00
// Get cached modules
2006-05-17 16:26:54 +00:00
if (( $this -> module_cache = $cache -> get ( '_modules_' . $this -> p_class )) === false )
2005-10-09 17:59:27 +00:00
{
2006-02-18 13:54:12 +00:00
// Get modules
2005-10-09 17:59:27 +00:00
$sql = ' SELECT *
FROM ' . MODULES_TABLE . "
2006-03-09 18:32:50 +00:00
WHERE module_class = '" . $db->sql_escape($this->p_class) . "'
2005-10-09 17:59:27 +00:00
ORDER BY left_id ASC " ;
$result = $db -> sql_query ( $sql );
2006-02-18 13:54:12 +00:00
$rows = array ();
2005-10-09 17:59:27 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
{
2006-02-18 13:54:12 +00:00
$rows [ $row [ 'module_id' ]] = $row ;
2006-02-03 20:59:39 +00:00
}
2006-03-09 18:32:50 +00:00
$db -> sql_freeresult ( $result );
2006-02-03 20:59:39 +00:00
2006-02-18 13:54:12 +00:00
$this -> module_cache = array ();
foreach ( $rows as $module_id => $row )
2005-10-09 17:59:27 +00:00
{
2006-02-18 13:54:12 +00:00
$this -> module_cache [ 'modules' ][] = $row ;
$this -> module_cache [ 'parents' ][ $row [ 'module_id' ]] = $this -> get_parents ( $row [ 'parent_id' ], $row [ 'left_id' ], $row [ 'right_id' ], $rows );
2005-10-09 17:59:27 +00:00
}
2006-02-18 13:54:12 +00:00
unset ( $rows );
2005-10-09 17:59:27 +00:00
2006-03-09 18:32:50 +00:00
$cache -> put ( '_modules_' . $this -> p_class , $this -> module_cache );
2005-10-09 17:59:27 +00:00
}
2004-10-31 13:26:38 +00:00
2006-12-24 13:11:54 +00:00
if ( empty ( $this -> module_cache ))
{
$this -> module_cache = array ( 'modules' => array (), 'parents' => array ());
}
2006-02-18 13:54:12 +00:00
// We "could" build a true tree with this function - maybe mod authors want to use this...
// Functions for traversing and manipulating the tree are not available though
// We might re-structure the module system to use true trees in 3.2.x...
// $tree = $this->build_tree($this->module_cache['modules'], $this->module_cache['parents']);
2005-10-04 21:24:51 +00:00
2006-02-18 13:54:12 +00:00
// Clean up module cache array to only let survive modules the user can access
$right_id = false ;
2005-12-30 17:56:28 +00:00
foreach ( $this -> module_cache [ 'modules' ] as $key => $row )
2004-10-31 13:26:38 +00:00
{
2005-12-30 17:56:28 +00:00
// Not allowed to view module?
if ( ! $this -> module_auth ( $row [ 'module_auth' ]))
2004-10-31 13:26:38 +00:00
{
2006-02-03 20:59:39 +00:00
unset ( $this -> module_cache [ 'modules' ][ $key ]);
2005-12-30 17:56:28 +00:00
continue ;
2004-10-31 13:26:38 +00:00
}
2005-10-04 21:24:51 +00:00
// Category with no members, ignore
- renamed the following columns:
comment -> attach_comment
new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted
module_name -> module_basename
value -> lang_value
- every column is now NOT NULL
- every column is now having a DEFAULT value
- hopefully mostly consistent across every db schema
- untested schemas: sqlite, oracle, firebird
git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0
2006-07-13 12:51:56 +00:00
if ( ! $row [ 'module_basename' ] && ( $row [ 'left_id' ] + 1 == $row [ 'right_id' ]))
2004-10-31 13:26:38 +00:00
{
2006-02-18 13:54:12 +00:00
unset ( $this -> module_cache [ 'modules' ][ $key ]);
2004-10-31 13:26:38 +00:00
continue ;
}
2006-02-18 13:54:12 +00:00
// Skip branch
if ( $right_id !== false )
2005-12-30 17:56:28 +00:00
{
2006-02-18 13:54:12 +00:00
if ( $row [ 'left_id' ] < $right_id )
2005-12-30 17:56:28 +00:00
{
2006-02-18 13:54:12 +00:00
unset ( $this -> module_cache [ 'modules' ][ $key ]);
2005-12-30 17:56:28 +00:00
continue ;
}
2006-02-18 13:54:12 +00:00
$right_id = false ;
2005-12-30 17:56:28 +00:00
}
2005-12-25 11:10:06 +00:00
// Not enabled?
if ( ! $row [ 'module_enabled' ])
{
// If category is disabled then disable every child too
2006-02-18 13:54:12 +00:00
unset ( $this -> module_cache [ 'modules' ][ $key ]);
$right_id = $row [ 'right_id' ];
2005-12-25 11:10:06 +00:00
continue ;
}
2006-02-18 13:54:12 +00:00
}
// Re-index (this is needed, else we are not able to array_slice later)
$this -> module_cache [ 'modules' ] = array_merge ( $this -> module_cache [ 'modules' ]);
// Now build the module array, but exclude completely empty categories...
$right_id = false ;
$names = array ();
foreach ( $this -> module_cache [ 'modules' ] as $key => $row )
{
// Skip branch
if ( $right_id !== false )
2005-12-25 11:10:06 +00:00
{
2006-02-18 13:54:12 +00:00
if ( $row [ 'left_id' ] < $right_id )
2005-12-25 11:10:06 +00:00
{
continue ;
}
2006-02-18 13:54:12 +00:00
$right_id = false ;
2005-12-25 11:10:06 +00:00
}
2006-02-18 13:54:12 +00:00
// Category with no members on their way down (we have to check every level)
- renamed the following columns:
comment -> attach_comment
new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted
module_name -> module_basename
value -> lang_value
- every column is now NOT NULL
- every column is now having a DEFAULT value
- hopefully mostly consistent across every db schema
- untested schemas: sqlite, oracle, firebird
git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0
2006-07-13 12:51:56 +00:00
if ( ! $row [ 'module_basename' ])
2004-10-31 13:26:38 +00:00
{
2006-02-18 13:54:12 +00:00
$empty_category = true ;
// We go through the branch and look for an activated module
foreach ( array_slice ( $this -> module_cache [ 'modules' ], $key + 1 ) as $temp_row )
2005-10-04 21:24:51 +00:00
{
2006-02-18 13:54:12 +00:00
if ( $temp_row [ 'left_id' ] > $row [ 'left_id' ] && $temp_row [ 'left_id' ] < $row [ 'right_id' ])
{
2006-06-06 10:38:14 +00:00
// Module there
- renamed the following columns:
comment -> attach_comment
new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted
module_name -> module_basename
value -> lang_value
- every column is now NOT NULL
- every column is now having a DEFAULT value
- hopefully mostly consistent across every db schema
- untested schemas: sqlite, oracle, firebird
git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0
2006-07-13 12:51:56 +00:00
if ( $temp_row [ 'module_basename' ] && $temp_row [ 'module_enabled' ])
2006-02-18 13:54:12 +00:00
{
$empty_category = false ;
break ;
}
continue ;
}
break ;
2005-10-04 21:24:51 +00:00
}
2006-02-18 13:54:12 +00:00
// Skip the branch
if ( $empty_category )
2005-10-04 21:24:51 +00:00
{
2006-02-18 13:54:12 +00:00
$right_id = $row [ 'right_id' ];
continue ;
2005-10-04 21:24:51 +00:00
}
2004-10-31 13:26:38 +00:00
}
2006-02-18 13:54:12 +00:00
$depth = sizeof ( $this -> module_cache [ 'parents' ][ $row [ 'module_id' ]]);
2004-10-31 13:26:38 +00:00
2005-12-10 23:20:21 +00:00
// We need to prefix the functions to not create a naming conflict
2006-12-21 10:37:50 +00:00
2006-04-08 13:01:04 +00:00
// Function for building 'url_extra'
- renamed the following columns:
comment -> attach_comment
new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted
module_name -> module_basename
value -> lang_value
- every column is now NOT NULL
- every column is now having a DEFAULT value
- hopefully mostly consistent across every db schema
- untested schemas: sqlite, oracle, firebird
git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0
2006-07-13 12:51:56 +00:00
$url_func = '_module_' . $row [ 'module_basename' ] . '_url' ;
2006-04-08 13:01:04 +00:00
// Function for building the language name
- renamed the following columns:
comment -> attach_comment
new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted
module_name -> module_basename
value -> lang_value
- every column is now NOT NULL
- every column is now having a DEFAULT value
- hopefully mostly consistent across every db schema
- untested schemas: sqlite, oracle, firebird
git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0
2006-07-13 12:51:56 +00:00
$lang_func = '_module_' . $row [ 'module_basename' ] . '_lang' ;
2006-04-08 13:01:04 +00:00
// Custom function for calling parameters on module init (for example assigning template variables)
- renamed the following columns:
comment -> attach_comment
new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted
module_name -> module_basename
value -> lang_value
- every column is now NOT NULL
- every column is now having a DEFAULT value
- hopefully mostly consistent across every db schema
- untested schemas: sqlite, oracle, firebird
git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0
2006-07-13 12:51:56 +00:00
$custom_func = '_module_' . $row [ 'module_basename' ];
2005-11-17 21:54:11 +00:00
- renamed the following columns:
comment -> attach_comment
new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted
module_name -> module_basename
value -> lang_value
- every column is now NOT NULL
- every column is now having a DEFAULT value
- hopefully mostly consistent across every db schema
- untested schemas: sqlite, oracle, firebird
git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0
2006-07-13 12:51:56 +00:00
$names [ $row [ 'module_basename' ] . '_' . $row [ 'module_mode' ]][] = true ;
2006-02-18 13:54:12 +00:00
2006-04-08 13:01:04 +00:00
$module_row = array (
2005-10-09 17:59:27 +00:00
'depth' => $depth ,
'id' => ( int ) $row [ 'module_id' ],
'parent' => ( int ) $row [ 'parent_id' ],
'cat' => ( $row [ 'right_id' ] > $row [ 'left_id' ] + 1 ) ? true : false ,
2004-10-31 13:26:38 +00:00
- renamed the following columns:
comment -> attach_comment
new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted
module_name -> module_basename
value -> lang_value
- every column is now NOT NULL
- every column is now having a DEFAULT value
- hopefully mostly consistent across every db schema
- untested schemas: sqlite, oracle, firebird
git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0
2006-07-13 12:51:56 +00:00
'is_duplicate' => ( $row [ 'module_basename' ] && sizeof ( $names [ $row [ 'module_basename' ] . '_' . $row [ 'module_mode' ]]) > 1 ) ? true : false ,
2006-02-18 13:54:12 +00:00
- renamed the following columns:
comment -> attach_comment
new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted
module_name -> module_basename
value -> lang_value
- every column is now NOT NULL
- every column is now having a DEFAULT value
- hopefully mostly consistent across every db schema
- untested schemas: sqlite, oracle, firebird
git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0
2006-07-13 12:51:56 +00:00
'name' => ( string ) $row [ 'module_basename' ],
2005-10-09 17:59:27 +00:00
'mode' => ( string ) $row [ 'module_mode' ],
2005-11-08 19:24:19 +00:00
'display' => ( int ) $row [ 'module_display' ],
2005-11-17 21:54:11 +00:00
2006-12-21 10:37:50 +00:00
'url_extra' => ( function_exists ( $url_func )) ? $url_func ( $row [ 'module_mode' ], $row ) : '' ,
2005-10-09 17:59:27 +00:00
- renamed the following columns:
comment -> attach_comment
new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted
module_name -> module_basename
value -> lang_value
- every column is now NOT NULL
- every column is now having a DEFAULT value
- hopefully mostly consistent across every db schema
- untested schemas: sqlite, oracle, firebird
git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0
2006-07-13 12:51:56 +00:00
'lang' => ( $row [ 'module_basename' ] && function_exists ( $lang_func )) ? $lang_func ( $row [ 'module_mode' ], $row [ 'module_langname' ]) : (( ! empty ( $user -> lang [ $row [ 'module_langname' ]])) ? $user -> lang [ $row [ 'module_langname' ]] : $row [ 'module_langname' ]),
2005-10-09 17:59:27 +00:00
'langname' => $row [ 'module_langname' ],
2005-10-04 21:24:51 +00:00
2005-10-09 17:59:27 +00:00
'left' => $row [ 'left_id' ],
'right' => $row [ 'right_id' ],
);
2006-04-08 13:01:04 +00:00
if ( function_exists ( $custom_func ))
{
$custom_func ( $row [ 'module_mode' ], $module_row );
}
$this -> module_ary [] = $module_row ;
2005-10-04 21:24:51 +00:00
}
2005-10-09 17:59:27 +00:00
2006-02-18 13:54:12 +00:00
unset ( $this -> module_cache [ 'modules' ], $names );
2005-10-04 21:24:51 +00:00
}
2004-10-31 13:26:38 +00:00
2007-01-22 17:05:23 +00:00
/**
* Check if a certain main module is accessible / loaded
* By giving the module mode you are able to additionally check for only one mode within the main module
*
* @ param string $module_basename The module base name , for example logs , reports , main ( for the mcp ) .
* @ param mixed $module_mode The module mode to check . If provided the mode will be checked in addition for presence .
*
* @ return bool Returns true if module is loaded and accessible , else returns false
*/
function loaded ( $module_basename , $module_mode = false )
{
if ( empty ( $this -> loaded_cache ))
{
$this -> loaded_cache = array ();
foreach ( $this -> module_ary as $row )
{
if ( ! $row [ 'name' ])
{
continue ;
}
if ( ! isset ( $this -> loaded_cache [ $row [ 'name' ]]))
{
$this -> loaded_cache [ $row [ 'name' ]] = array ();
}
if ( ! $row [ 'mode' ])
{
continue ;
}
$this -> loaded_cache [ $row [ 'name' ]][ $row [ 'mode' ]] = true ;
}
}
if ( $module_mode === false )
{
return ( isset ( $this -> loaded_cache [ $module_basename ])) ? true : false ;
}
return ( ! empty ( $this -> loaded_cache [ $module_basename ][ $module_mode ])) ? true : false ;
}
2005-12-30 17:56:28 +00:00
/**
* Check module authorisation
*/
2006-11-21 18:15:53 +00:00
function module_auth ( $module_auth , $forum_id = false )
2005-12-30 17:56:28 +00:00
{
global $auth , $config ;
2006-11-21 18:15:53 +00:00
2005-12-30 17:56:28 +00:00
$module_auth = trim ( $module_auth );
// Generally allowed to access module if module_auth is empty
if ( ! $module_auth )
{
return true ;
}
2006-11-19 21:00:48 +00:00
// With the code below we make sure only those elements get eval'd we really want to be checked
preg_match_all ( ' / ( ? :
" [^ " \\\\ ] * ( ? : \\\\ . [ ^ " \\ \\ ]*)* " |
\ ' [ ^ \ ' \\\\ ] * ( ? : \\\\ . [ ^ \ ' \\\\ ] * ) * \ ' |
[(),] |
[ ^ \s (),] + ) / x ' , $module_auth , $match );
$tokens = $match [ 0 ];
for ( $i = 0 , $size = sizeof ( $tokens ); $i < $size ; $i ++ )
{
$token = & $tokens [ $i ];
switch ( $token )
{
case ')' :
case '(' :
case '&&' :
case '||' :
2006-11-20 16:40:44 +00:00
case ',' :
2006-11-19 21:00:48 +00:00
break ;
default :
if ( ! preg_match ( '#(?:acl_([a-z_]+)(,\$id)?)|(?:\$id)|(?:aclf_([a-z_]+))|(?:cfg_([a-z_]+))#' , $token ))
{
$token = '' ;
}
break ;
}
}
2006-11-20 16:40:44 +00:00
2006-11-19 21:00:48 +00:00
$module_auth = implode ( ' ' , $tokens );
2006-11-20 16:40:44 +00:00
// Make sure $id seperation is working fine
$module_auth = str_replace ( ' , ' , ',' , $module_auth );
2006-11-21 18:15:53 +00:00
$forum_id = ( $forum_id === false ) ? $this -> acl_forum_id : $forum_id ;
2005-12-30 17:56:28 +00:00
$is_auth = false ;
2006-11-21 18:23:43 +00:00
eval ( '$is_auth = (int) (' . preg_replace ( array ( '#acl_([a-z_]+)(,\$id)?#' , '#\$id#' , '#aclf_([a-z_]+)#' , '#cfg_([a-z_]+)#' ), array ( '(int) $auth->acl_get(\'\\1\'\\2)' , '(int) $forum_id' , '(int) $auth->acl_getf_global(\'\\1\')' , '(int) $config[\'\\1\']' ), $module_auth ) . ');' );
2006-01-06 22:38:18 +00:00
2005-12-30 17:56:28 +00:00
return $is_auth ;
}
2006-02-18 13:54:12 +00:00
/**
* Set active module
*/
2005-10-04 21:24:51 +00:00
function set_active ( $id = false , $mode = false )
{
2006-02-18 13:54:12 +00:00
$icat = false ;
2006-07-01 19:11:52 +00:00
$this -> active_module = false ;
2006-02-18 13:54:12 +00:00
if ( request_var ( 'icat' , '' ))
{
$icat = $id ;
$id = request_var ( 'icat' , '' );
}
2005-10-04 21:24:51 +00:00
$category = false ;
2006-07-01 19:11:52 +00:00
foreach ( $this -> module_ary as $row_id => $item_ary )
2005-10-04 21:24:51 +00:00
{
2004-10-31 13:26:38 +00:00
// If this is a module and it's selected, active
// If this is a category and the module is the first within it, active
2005-10-04 21:24:51 +00:00
// If this is a module and no mode selected, select first mode
2004-10-31 13:26:38 +00:00
// If no category or module selected, go active for first module in first category
2005-12-30 17:56:28 +00:00
if (
2006-07-01 19:11:52 +00:00
(( $item_ary [ 'name' ] === $id || $item_ary [ 'id' ] === ( int ) $id ) && (( $item_ary [ 'mode' ] == $mode && ! $item_ary [ 'cat' ]) || ( $icat && $item_ary [ 'cat' ]))) ||
2006-10-19 13:55:48 +00:00
( $item_ary [ 'parent' ] === $category && ! $item_ary [ 'cat' ] && ! $icat && $item_ary [ 'display' ]) ||
2006-07-01 19:11:52 +00:00
(( $item_ary [ 'name' ] === $id || $item_ary [ 'id' ] === ( int ) $id ) && ! $mode && ! $item_ary [ 'cat' ]) ||
2006-10-19 13:55:48 +00:00
( ! $id && ! $mode && ! $item_ary [ 'cat' ] && $item_ary [ 'display' ])
2005-10-04 21:24:51 +00:00
)
2004-10-31 13:26:38 +00:00
{
2006-07-01 19:11:52 +00:00
if ( $item_ary [ 'cat' ])
2006-02-18 13:54:12 +00:00
{
$id = $icat ;
$icat = false ;
continue ;
}
2006-07-01 19:11:52 +00:00
$this -> p_id = $item_ary [ 'id' ];
$this -> p_parent = $item_ary [ 'parent' ];
$this -> p_name = $item_ary [ 'name' ];
$this -> p_mode = $item_ary [ 'mode' ];
$this -> p_left = $item_ary [ 'left' ];
$this -> p_right = $item_ary [ 'right' ];
2005-10-09 17:59:27 +00:00
$this -> module_cache [ 'parents' ] = $this -> module_cache [ 'parents' ][ $this -> p_id ];
2006-07-01 19:11:52 +00:00
$this -> active_module = $item_ary [ 'id' ];
2007-01-22 17:05:23 +00:00
$this -> active_module_row_id = $row_id ;
2004-10-31 13:26:38 +00:00
2005-10-04 21:24:51 +00:00
break ;
2004-10-31 13:26:38 +00:00
}
2006-07-01 19:11:52 +00:00
else if (( $item_ary [ 'cat' ] && $item_ary [ 'id' ] === ( int ) $id ) || ( $item_ary [ 'parent' ] === $category && $item_ary [ 'cat' ]))
2004-10-31 13:26:38 +00:00
{
2006-07-01 19:11:52 +00:00
$category = $item_ary [ 'id' ];
2004-10-31 13:26:38 +00:00
}
}
}
2005-10-04 21:24:51 +00:00
/**
* Loads currently active module
*
* This method loads a given module , passing it the relevant id and mode .
*/
2006-06-01 13:47:42 +00:00
function load_active ( $mode = false , $module_url = false , $execute_module = true )
2004-10-31 13:26:38 +00:00
{
2006-06-06 20:53:46 +00:00
global $phpbb_root_path , $phpbb_admin_path , $phpEx , $user ;
2004-10-31 13:26:38 +00:00
2005-10-04 21:24:51 +00:00
$module_path = $phpbb_root_path . 'includes/' . $this -> p_class ;
2006-02-18 13:54:12 +00:00
$icat = request_var ( 'icat' , '' );
2005-10-04 21:24:51 +00:00
2006-07-01 19:11:52 +00:00
if ( $this -> active_module === false )
{
trigger_error ( 'Module not accessible' , E_USER_ERROR );
}
2005-10-04 21:24:51 +00:00
if ( ! class_exists ( " { $this -> p_class } _ $this->p_name " ))
2004-10-31 13:26:38 +00:00
{
2005-10-04 21:24:51 +00:00
if ( ! file_exists ( " $module_path / { $this -> p_class } _ $this->p_name . $phpEx " ))
{
2006-09-01 13:16:22 +00:00
trigger_error ( " Cannot find module $module_path / { $this -> p_class } _ $this->p_name . $phpEx " , E_USER_ERROR );
2005-10-04 21:24:51 +00:00
}
include ( " $module_path / { $this -> p_class } _ $this->p_name . $phpEx " );
2004-10-31 13:26:38 +00:00
2005-10-04 21:24:51 +00:00
if ( ! class_exists ( " { $this -> p_class } _ $this->p_name " ))
2004-10-31 13:26:38 +00:00
{
2006-09-01 13:16:22 +00:00
trigger_error ( " Module file $module_path / { $this -> p_class } _ $this->p_name . $phpEx does not contain correct class [ { $this -> p_class } _ $this->p_name ] " , E_USER_ERROR );
2005-10-04 21:24:51 +00:00
}
2004-10-31 13:26:38 +00:00
2005-10-04 21:24:51 +00:00
if ( ! empty ( $mode ))
{
$this -> p_mode = $mode ;
2004-10-31 13:26:38 +00:00
}
2005-10-04 21:24:51 +00:00
// Create a new instance of the desired module ... if it has a
// constructor it will of course be executed
$instance = " { $this -> p_class } _ $this->p_name " ;
$this -> module = new $instance ( $this );
2006-02-18 13:54:12 +00:00
// We pre-define the action parameter we are using all over the place
2006-03-15 13:03:57 +00:00
if ( defined ( 'IN_ADMIN' ))
{
2007-01-22 17:05:23 +00:00
// Is first module automatically enabled a duplicate and the category not passed yet?
if ( ! $icat && $this -> module_ary [ $this -> active_module_row_id ][ 'is_duplicate' ])
{
$icat = $this -> module_ary [ $this -> active_module_row_id ][ 'parent' ];
}
2006-06-01 13:47:42 +00:00
// Not being able to overwrite ;)
2006-12-24 13:11:54 +00:00
$this -> module -> u_action = append_sid ( " { $phpbb_admin_path } index. $phpEx " , " i= { $this -> p_name } " ) . (( $icat ) ? '&icat=' . $icat : '' ) . " &mode= { $this -> p_mode } " ;
2006-03-15 13:03:57 +00:00
}
else
{
2006-06-01 13:47:42 +00:00
// If user specified the module url we will use it...
if ( $module_url !== false )
{
$this -> module -> u_action = $module_url ;
}
else
{
2006-06-06 20:53:46 +00:00
$this -> module -> u_action = $phpbb_root_path . (( $user -> page [ 'page_dir' ]) ? $user -> page [ 'page_dir' ] . '/' : '' ) . $user -> page [ 'page_name' ];
2006-06-01 13:47:42 +00:00
}
2006-12-24 13:11:54 +00:00
$this -> module -> u_action = append_sid ( $this -> module -> u_action , " i= { $this -> p_name } " ) . (( $icat ) ? '&icat=' . $icat : '' ) . " &mode= { $this -> p_mode } " ;
2006-03-15 13:03:57 +00:00
}
2006-02-18 13:54:12 +00:00
2007-01-22 17:05:23 +00:00
// Add url_extra parameter to u_action url
2007-01-24 11:29:56 +00:00
if ( ! empty ( $this -> module_ary ) && $this -> active_module !== false && $this -> module_ary [ $this -> active_module_row_id ][ 'url_extra' ])
2007-01-22 17:05:23 +00:00
{
$this -> module -> u_action .= $this -> module_ary [ $this -> active_module_row_id ][ 'url_extra' ];
}
2006-06-01 13:47:42 +00:00
// Assign the module path for re-usage
$this -> module -> module_path = $module_path . '/' ;
// Execute the main method for the new instance, we send the module id and mode as parameters
// Users are able to call the main method after this function to be able to assign additional parameters manually
if ( $execute_module )
{
2006-12-24 13:11:54 +00:00
$this -> module -> main ( $this -> p_name , $this -> p_mode );
2006-06-01 13:47:42 +00:00
}
2005-10-04 21:24:51 +00:00
return ;
2004-10-31 13:26:38 +00:00
}
}
#10005, #10003, #10001, #9999, #9945, #9965, #9909, #9906, #9877, #9861, #9831, #9830, #9815, #9665, #9624
prosilver adjustments for important announcements in ucp - #9995
MCP fixes for user notes/warnings - #9981
Preserving imageset values on save/edit
find a member link for Mass PM's - #9925
syndicate window.onload events where necessary - #9878
Duplicate topics in forums with announcements - #9840
Email template for forced re-activation - #9808
Topic pagination adjustment - #9763
Changed compose message layout in UCP - #9706, #9702
Fixed inline attachment font size (hopefully)
git-svn-id: file:///svn/phpbb/trunk@7384 89ea8834-ac86-4346-8a33-228a782c2dd0
2007-04-22 15:27:40 +00:00
/**
* Appending url parameter to the currently active module .
*
* This function is called for adding specific url parameters while executing the current module .
* It is doing the same as the _module_ { name } _url () function , apart from being able to be called after
* having dynamically parsed specific parameters . This allows more freedom in choosing additional parameters .
* One example can be seen in / includes / mcp / mcp_notes . php - $this -> p_master -> adjust_url () call .
*
* @ param string $url_extra Extra url parameters , e . g .: & amp ; u = $user_id
*
*/
function adjust_url ( $url_extra )
{
if ( empty ( $this -> module_ary [ $this -> active_module_row_id ]))
{
return ;
}
$row = & $this -> module_ary [ $this -> active_module_row_id ];
// We check for the same url_extra in $row['url_extra'] to overcome doubled additions...
if ( strpos ( $row [ 'url_extra' ], $url_extra ) === false )
{
$row [ 'url_extra' ] .= $url_extra ;
}
}
2007-03-24 18:00:21 +00:00
/**
* Check if a module is active
*/
2007-03-26 15:42:05 +00:00
function is_active ( $id , $mode = false )
2007-03-24 18:00:21 +00:00
{
2007-03-26 15:42:05 +00:00
// If we find a name by this id and being enabled we have our active one...
2007-03-24 18:00:21 +00:00
foreach ( $this -> module_ary as $row_id => $item_ary )
{
2007-03-26 15:42:05 +00:00
if (( $item_ary [ 'name' ] === $id || $item_ary [ 'id' ] === ( int ) $id ) && $item_ary [ 'display' ])
2007-03-24 18:00:21 +00:00
{
2007-03-26 15:42:05 +00:00
if ( $mode === false || $mode === $item_ary [ 'mode' ])
2007-03-24 18:00:21 +00:00
{
2007-03-26 15:42:05 +00:00
return true ;
2007-03-24 18:00:21 +00:00
}
}
}
2007-03-26 15:42:05 +00:00
return false ;
2007-03-24 18:00:21 +00:00
}
2006-02-18 13:54:12 +00:00
/**
* Get parents
*/
2006-02-03 20:59:39 +00:00
function get_parents ( $parent_id , $left_id , $right_id , & $all_parents )
2005-10-09 17:59:27 +00:00
{
global $db ;
$parents = array ();
if ( $parent_id > 0 )
{
2006-02-03 20:59:39 +00:00
foreach ( $all_parents as $module_id => $row )
2005-10-09 17:59:27 +00:00
{
2006-02-03 20:59:39 +00:00
if ( $row [ 'left_id' ] < $left_id && $row [ 'right_id' ] > $right_id )
{
$parents [ $module_id ] = $row [ 'parent_id' ];
}
if ( $row [ 'left_id' ] > $left_id )
{
break ;
}
2005-10-09 17:59:27 +00:00
}
}
return $parents ;
}
2006-02-18 13:54:12 +00:00
/**
* Get tree branch
*/
function get_branch ( $left_id , $right_id , $remaining )
{
$branch = array ();
foreach ( $remaining as $key => $row )
{
if ( $row [ 'left_id' ] > $left_id && $row [ 'left_id' ] < $right_id )
{
$branch [] = $row ;
continue ;
}
break ;
}
2006-06-06 20:53:46 +00:00
2006-02-18 13:54:12 +00:00
return $branch ;
}
/**
* Build true binary tree from given array
2006-06-01 13:47:42 +00:00
* Not in use
2006-02-18 13:54:12 +00:00
*/
function build_tree ( & $modules , & $parents )
{
$tree = array ();
foreach ( $modules as $row )
{
$branch = & $tree ;
if ( $row [ 'parent_id' ])
{
// Go through the tree to find our branch
$parent_tree = $parents [ $row [ 'module_id' ]];
2006-06-06 20:53:46 +00:00
2006-02-18 13:54:12 +00:00
foreach ( $parent_tree as $id => $value )
{
if ( ! isset ( $branch [ $id ]) && isset ( $branch [ 'child' ]))
{
$branch = & $branch [ 'child' ];
}
$branch = & $branch [ $id ];
}
$branch = & $branch [ 'child' ];
}
$branch [ $row [ 'module_id' ]] = $row ;
if ( ! isset ( $branch [ $row [ 'module_id' ]][ 'child' ]))
{
$branch [ $row [ 'module_id' ]][ 'child' ] = array ();
}
}
2006-06-06 20:53:46 +00:00
2006-02-18 13:54:12 +00:00
return $tree ;
}
/**
* Build navigation structure
*/
2005-10-04 21:24:51 +00:00
function assign_tpl_vars ( $module_url )
2004-10-31 13:26:38 +00:00
{
2005-10-19 18:00:10 +00:00
global $template ;
2004-10-31 13:26:38 +00:00
2006-06-06 10:45:43 +00:00
$current_id = $right_id = false ;
2006-02-18 13:54:12 +00:00
2006-06-01 13:47:42 +00:00
// Make sure the module_url has a question mark set, effectively determining the delimiter to use
$delim = ( strpos ( $module_url , '?' ) === false ) ? '?' : '&' ;
2005-10-04 21:24:51 +00:00
$current_padding = $current_depth = 0 ;
2004-10-31 13:26:38 +00:00
$linear_offset = 'l_block1' ;
$tabular_offset = 't_block2' ;
// Generate the list of modules, we'll do this in two ways ...
// 1) In a linear fashion
// 2) In a combined tabbed + linear fashion ... tabs for the categories
// and a linear list for subcategories/items
2006-07-01 19:11:52 +00:00
foreach ( $this -> module_ary as $row_id => $item_ary )
2004-10-31 13:26:38 +00:00
{
2006-06-06 10:45:43 +00:00
// Skip hidden modules
2006-07-01 19:11:52 +00:00
if ( ! $item_ary [ 'display' ])
2005-11-08 19:24:19 +00:00
{
continue ;
}
2006-06-06 10:45:43 +00:00
// Skip branch
if ( $right_id !== false )
{
2006-07-01 19:11:52 +00:00
if ( $item_ary [ 'left' ] < $right_id )
2006-06-06 10:45:43 +00:00
{
continue ;
}
$right_id = false ;
}
// Category with no members on their way down (we have to check every level)
2006-07-01 19:11:52 +00:00
if ( ! $item_ary [ 'name' ])
2006-06-06 10:45:43 +00:00
{
$empty_category = true ;
// We go through the branch and look for an activated module
foreach ( array_slice ( $this -> module_ary , $row_id + 1 ) as $temp_row )
{
2006-07-01 19:11:52 +00:00
if ( $temp_row [ 'left' ] > $item_ary [ 'left' ] && $temp_row [ 'left' ] < $item_ary [ 'right' ])
2006-06-06 10:45:43 +00:00
{
// Module there and displayed?
if ( $temp_row [ 'name' ] && $temp_row [ 'display' ])
{
$empty_category = false ;
break ;
}
continue ;
}
break ;
}
// Skip the branch
if ( $empty_category )
{
2006-07-01 19:11:52 +00:00
$right_id = $item_ary [ 'right' ];
2006-06-06 10:45:43 +00:00
continue ;
}
}
2006-02-18 13:54:12 +00:00
// Select first id we can get
2006-07-01 19:11:52 +00:00
if ( ! $current_id && ( in_array ( $item_ary [ 'id' ], array_keys ( $this -> module_cache [ 'parents' ])) || $item_ary [ 'id' ] == $this -> p_id ))
2006-02-18 13:54:12 +00:00
{
2006-07-01 19:11:52 +00:00
$current_id = $item_ary [ 'id' ];
2006-02-18 13:54:12 +00:00
}
2006-07-01 19:11:52 +00:00
$depth = $item_ary [ 'depth' ];
2004-10-31 13:26:38 +00:00
2005-10-04 21:24:51 +00:00
if ( $depth > $current_depth )
2004-10-31 13:26:38 +00:00
{
2005-10-04 21:24:51 +00:00
$linear_offset = $linear_offset . '.l_block' . ( $depth + 1 );
$tabular_offset = ( $depth + 1 > 2 ) ? $tabular_offset . '.t_block' . ( $depth + 1 ) : $tabular_offset ;
2004-10-31 13:26:38 +00:00
}
2005-10-04 21:24:51 +00:00
else if ( $depth < $current_depth )
2004-10-31 13:26:38 +00:00
{
2005-10-04 21:24:51 +00:00
for ( $i = $current_depth - $depth ; $i > 0 ; $i -- )
2004-10-31 13:26:38 +00:00
{
$linear_offset = substr ( $linear_offset , 0 , strrpos ( $linear_offset , '.' ));
2005-10-04 21:24:51 +00:00
$tabular_offset = ( $i + $depth > 1 ) ? substr ( $tabular_offset , 0 , strrpos ( $tabular_offset , '.' )) : $tabular_offset ;
2004-10-31 13:26:38 +00:00
}
}
2006-07-01 19:11:52 +00:00
$u_title = $module_url . $delim . 'i=' . (( $item_ary [ 'cat' ]) ? $item_ary [ 'id' ] : $item_ary [ 'name' ] . (( $item_ary [ 'is_duplicate' ]) ? '&icat=' . $current_id : '' ) . '&mode=' . $item_ary [ 'mode' ]);
2006-12-21 10:37:50 +00:00
// Was not allowed in categories before - /*!$item_ary['cat'] && */
$u_title .= ( isset ( $item_ary [ 'url_extra' ])) ? $item_ary [ 'url_extra' ] : '' ;
2006-06-01 13:47:42 +00:00
2004-10-31 13:26:38 +00:00
// Only output a categories items if it's currently selected
2006-07-01 19:11:52 +00:00
if ( ! $depth || ( $depth && ( in_array ( $item_ary [ 'parent' ], array_values ( $this -> module_cache [ 'parents' ])) || $item_ary [ 'parent' ] == $this -> p_parent )))
2004-10-31 13:26:38 +00:00
{
2005-10-04 21:24:51 +00:00
$use_tabular_offset = ( ! $depth ) ? 't_block1' : $tabular_offset ;
2006-06-01 13:47:42 +00:00
2005-10-09 17:59:27 +00:00
$tpl_ary = array (
2006-07-01 19:11:52 +00:00
'L_TITLE' => $item_ary [ 'lang' ],
'S_SELECTED' => ( in_array ( $item_ary [ 'id' ], array_keys ( $this -> module_cache [ 'parents' ])) || $item_ary [ 'id' ] == $this -> p_id ) ? true : false ,
2005-11-08 19:24:19 +00:00
'U_TITLE' => $u_title
2005-10-09 17:59:27 +00:00
);
2006-07-01 19:11:52 +00:00
$template -> assign_block_vars ( $use_tabular_offset , array_merge ( $tpl_ary , array_change_key_case ( $item_ary , CASE_UPPER )));
2004-10-31 13:26:38 +00:00
}
2005-10-09 17:59:27 +00:00
$tpl_ary = array (
2006-07-01 19:11:52 +00:00
'L_TITLE' => $item_ary [ 'lang' ],
'S_SELECTED' => ( in_array ( $item_ary [ 'id' ], array_keys ( $this -> module_cache [ 'parents' ])) || $item_ary [ 'id' ] == $this -> p_id ) ? true : false ,
2005-11-08 19:24:19 +00:00
'U_TITLE' => $u_title
2005-10-09 17:59:27 +00:00
);
2006-07-01 19:11:52 +00:00
$template -> assign_block_vars ( $linear_offset , array_merge ( $tpl_ary , array_change_key_case ( $item_ary , CASE_UPPER )));
2005-10-04 21:24:51 +00:00
$current_depth = $depth ;
2004-10-31 13:26:38 +00:00
}
2005-10-04 21:24:51 +00:00
}
2004-10-31 13:26:38 +00:00
2005-10-04 21:24:51 +00:00
/**
* Returns desired template name
*/
function get_tpl_name ()
{
return $this -> module -> tpl_name . '.html' ;
}
2005-11-20 18:58:34 +00:00
/**
* Returns the desired page title
*/
function get_page_title ()
{
global $user ;
2005-11-28 18:38:49 +00:00
if ( ! isset ( $this -> module -> page_title ))
{
return '' ;
}
2005-11-20 18:58:34 +00:00
return ( isset ( $user -> lang [ $this -> module -> page_title ])) ? $user -> lang [ $this -> module -> page_title ] : $this -> module -> page_title ;
}
2005-10-04 21:24:51 +00:00
/**
* Load module as the current active one without the need for registering it
*/
function load ( $class , $name , $mode = false )
{
$this -> p_class = $class ;
$this -> p_name = $name ;
2006-07-01 19:11:52 +00:00
// Set active module to true instead of using the id
$this -> active_module = true ;
2005-10-04 21:24:51 +00:00
$this -> load_active ( $mode );
}
/**
* Display module
*/
2006-06-12 22:16:27 +00:00
function display ( $page_title , $display_online_list = true )
2005-10-04 21:24:51 +00:00
{
2005-12-04 20:25:51 +00:00
global $template , $user ;
2005-10-04 21:24:51 +00:00
// Generate the page
2005-12-04 20:25:51 +00:00
if ( defined ( 'IN_ADMIN' ) && isset ( $user -> data [ 'session_admin' ]) && $user -> data [ 'session_admin' ])
{
adm_page_header ( $page_title );
}
else
{
2006-06-12 22:16:27 +00:00
page_header ( $page_title , $display_online_list );
2005-12-04 20:25:51 +00:00
}
2004-10-31 13:26:38 +00:00
$template -> set_filenames ( array (
2005-10-04 21:24:51 +00:00
'body' => $this -> get_tpl_name ())
2004-10-31 13:26:38 +00:00
);
2005-12-04 20:25:51 +00:00
if ( defined ( 'IN_ADMIN' ) && isset ( $user -> data [ 'session_admin' ]) && $user -> data [ 'session_admin' ])
{
adm_page_footer ();
}
else
{
page_footer ();
}
2004-10-31 13:26:38 +00:00
}
2005-11-17 21:54:11 +00:00
/**
* Toggle whether this module will be displayed or not
*/
2006-02-22 11:39:27 +00:00
function set_display ( $id , $mode = false , $display = true )
2005-11-17 21:54:11 +00:00
{
2006-07-01 19:11:52 +00:00
foreach ( $this -> module_ary as $row_id => $item_ary )
2005-11-17 21:54:11 +00:00
{
2006-07-01 19:11:52 +00:00
if (( $item_ary [ 'name' ] === $id || $item_ary [ 'id' ] === ( int ) $id ) && ( ! $mode || $item_ary [ 'mode' ] === $mode ))
2005-11-17 21:54:11 +00:00
{
$this -> module_ary [ $row_id ][ 'display' ] = ( int ) $display ;
}
}
}
2005-10-04 21:24:51 +00:00
}
2004-10-31 13:26:38 +00:00
?>