[Customisation Database Commits] r152 - in /trunk/titania: ./ authors/ includes/ includes/authors/ includes/mods/ includes/titania/ mods/
David Lewis
highwayoflife at phpbb.com
Sun Nov 9 03:18:07 CET 2008
Author: HighwayofLife
Date: Sun Nov 9 03:18:07 2008
New Revision: 152
Log:
God gave us brains so we can use them once in a while... this method is soo much better, not sure why I didn't think of it before, this solves the problem with the phpbb_root_path, and with this change, we would not even need the proposed patch that I just sent to Meik, - regardless, the patch would mean less code duplication, which is always a good thing, but now this method is not hackish anymore.
- [feature] Added new class (file): 'titania_modules'
- [fix] proper fix for the proper fix that properly fixed the proper fix for phpbb_root_path being set and reset and set again.
Added:
trunk/titania/includes/titania_modules.php (with props)
Modified:
trunk/titania/authors/index.php
trunk/titania/includes/authors/authors_main.php
trunk/titania/includes/mods/mods_details.php
trunk/titania/includes/mods/mods_faq.php
trunk/titania/includes/mods/mods_main.php
trunk/titania/includes/mods/mods_reviews.php
trunk/titania/includes/mods/mods_support.php
trunk/titania/includes/titania/titania_main.php
trunk/titania/index.php
trunk/titania/mods/index.php
Modified: trunk/titania/authors/index.php
==============================================================================
*** trunk/titania/authors/index.php (original)
--- trunk/titania/authors/index.php Sun Nov 9 03:18:07 2008
***************
*** 15,26 ****
if (!defined('TITANIA_ROOT')) define('TITANIA_ROOT', './../');
if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
include(TITANIA_ROOT . 'common.' . PHP_EXT);
! include(PHPBB_ROOT_PATH . 'includes/functions_module.' . PHP_EXT);
$id = request_var('id', 'main');
$mode = request_var('mode', '');
! $module = new p_master();
// Instantiate module system and generate list of available modules
$module->list_modules('authors');
--- 15,26 ----
if (!defined('TITANIA_ROOT')) define('TITANIA_ROOT', './../');
if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
include(TITANIA_ROOT . 'common.' . PHP_EXT);
! include(TITANIA_ROOT . 'includes/titania_modules.' . PHP_EXT);
$id = request_var('id', 'main');
$mode = request_var('mode', '');
! $module = new titania_modules();
// Instantiate module system and generate list of available modules
$module->list_modules('authors');
***************
*** 30,38 ****
// Load and execute the relevant module
// trick the module class to allow modules to be loaded from the titania includes path.
! $phpbb_root_path = TITANIA_ROOT;
$module->load_active();
- $phpbb_root_path = PHPBB_ROOT_PATH;
// Assign data to the template engine for the list of modules
$module->assign_tpl_vars(append_sid(TITANIA_ROOT . 'authors/index.' . PHP_EXT));
--- 30,37 ----
// Load and execute the relevant module
// trick the module class to allow modules to be loaded from the titania includes path.
! $module->set_custom_include_path(TITANIA_ROOT . 'includes/');
$module->load_active();
// Assign data to the template engine for the list of modules
$module->assign_tpl_vars(append_sid(TITANIA_ROOT . 'authors/index.' . PHP_EXT));
Modified: trunk/titania/includes/authors/authors_main.php
==============================================================================
*** trunk/titania/includes/authors/authors_main.php (original)
--- trunk/titania/includes/authors/authors_main.php Sun Nov 9 03:18:07 2008
***************
*** 46,55 ****
*/
public function main($id, $mode)
{
! global $user, $phpbb_root_path;
!
! // complete the hack to allow our modules to be loaded from the Titania/includes directory.
! $phpbb_root_path = PHPBB_ROOT_PATH;
$user->add_lang(array('titania_contrib', 'titania_authors'));
--- 46,52 ----
*/
public function main($id, $mode)
{
! global $user;
$user->add_lang(array('titania_contrib', 'titania_authors'));
***************
*** 64,74 ****
if (!$found)
{
titania::error_box('ERROR', $user->lang['AUTHOR_NOT_FOUND'], ERROR_ERROR);
!
$this->main($id, 'list');
return;
}
!
break;
case 'list':
--- 61,71 ----
if (!$found)
{
titania::error_box('ERROR', $user->lang['AUTHOR_NOT_FOUND'], ERROR_ERROR);
!
$this->main($id, 'list');
return;
}
!
break;
case 'list':
***************
*** 191,203 ****
'S_ORDER_SELECT' => $sort->get_sort_dir_list(),
));
}
!
private function author_profile()
{
global $db, $template;
!
$author_id = request_var('u', 0);
!
$sql_ary = array(
'SELECT' => 'a.*, u.user_lastvisit, u.username, u.user_posts, u.user_colour',
'FROM' => array(
--- 188,200 ----
'S_ORDER_SELECT' => $sort->get_sort_dir_list(),
));
}
!
private function author_profile()
{
global $db, $template;
!
$author_id = request_var('u', 0);
!
$sql_ary = array(
'SELECT' => 'a.*, u.user_lastvisit, u.username, u.user_posts, u.user_colour',
'FROM' => array(
***************
*** 212,232 ****
'WHERE' => 'a.author_id = ' . $author_id . '
AND a.author_visible <> ' . AUTHOR_HIDDEN
);
!
$sql = $db->sql_build_query('SELECT', $sql_ary);
!
$result = $db->sql_query($sql);
!
if(!($author = $db->sql_fetchrow($result)))
{
return false;
}
!
if(!$author['author_visible'])
{
return false;
}
!
$template->assign_vars(array(
'AUTHOR_NAME' => get_username_string('username', $author['user_id'], $author['username'], $author['user_colour']),
'USER_FULL' => ($author['user_id']) ? get_username_string('full', $author['user_id'], $author['username'], $author['user_colour']) : '',
--- 209,229 ----
'WHERE' => 'a.author_id = ' . $author_id . '
AND a.author_visible <> ' . AUTHOR_HIDDEN
);
!
$sql = $db->sql_build_query('SELECT', $sql_ary);
!
$result = $db->sql_query($sql);
!
if(!($author = $db->sql_fetchrow($result)))
{
return false;
}
!
if(!$author['author_visible'])
{
return false;
}
!
$template->assign_vars(array(
'AUTHOR_NAME' => get_username_string('username', $author['user_id'], $author['username'], $author['user_colour']),
'USER_FULL' => ($author['user_id']) ? get_username_string('full', $author['user_id'], $author['username'], $author['user_colour']) : '',
***************
*** 238,262 ****
'SNIPPET_COUNT' => $this->generate_contrib_string('snippet', 'link', $author['author_snippets'], $author_id),
'MOD_COUNT' => $this->generate_contrib_string('mod', 'link', $author['author_mods'], $author_id),
'STYLE_COUNT' => $this->generate_contrib_string('style', 'link', $author['author_styles'], $author_id),
!
'U_PHPBB_PROFILE' => ($author['phpbb_user_id']) ? U_PHPBBCOM_VIEWPROFILE . '&u=' . $author['phpbb_user_id'] : '',
));
!
return true;
}
!
// Currently this just returns the $rating parameter, but we may want to use an image/image combo for ratings
// This can be changed later if this is decided.
private function generate_rating($rating)
{
return round($rating, 2);
}
!
// This can handle generating links to a contrib list, as well as just text
private function generate_contrib_string($contrib_type, $string_type, $num, $author_id = 0)
{
global $user;
!
$contrib_type = strtoupper($contrib_type);
$lang_key = 'NUM_' . $contrib_type . (($num == 1)?'':'S');
$contrib_string = sprintf($user->lang[$lang_key], $num);
--- 235,259 ----
'SNIPPET_COUNT' => $this->generate_contrib_string('snippet', 'link', $author['author_snippets'], $author_id),
'MOD_COUNT' => $this->generate_contrib_string('mod', 'link', $author['author_mods'], $author_id),
'STYLE_COUNT' => $this->generate_contrib_string('style', 'link', $author['author_styles'], $author_id),
!
'U_PHPBB_PROFILE' => ($author['phpbb_user_id']) ? U_PHPBBCOM_VIEWPROFILE . '&u=' . $author['phpbb_user_id'] : '',
));
!
return true;
}
!
// Currently this just returns the $rating parameter, but we may want to use an image/image combo for ratings
// This can be changed later if this is decided.
private function generate_rating($rating)
{
return round($rating, 2);
}
!
// This can handle generating links to a contrib list, as well as just text
private function generate_contrib_string($contrib_type, $string_type, $num, $author_id = 0)
{
global $user;
!
$contrib_type = strtoupper($contrib_type);
$lang_key = 'NUM_' . $contrib_type . (($num == 1)?'':'S');
$contrib_string = sprintf($user->lang[$lang_key], $num);
***************
*** 270,284 ****
{
case 'MOD':
$url = append_sid(TITANIA_ROOT . 'mods/index.php', 'mode=search&u=' . $author_id);
!
break;
!
default:
$url = '#';
}
$contrib_string = '<a href="' . $url . '">' . $contrib_string . '</a>';
}
!
return $contrib_string;
}
}
\ No newline at end of file
--- 267,281 ----
{
case 'MOD':
$url = append_sid(TITANIA_ROOT . 'mods/index.php', 'mode=search&u=' . $author_id);
!
break;
!
default:
$url = '#';
}
$contrib_string = '<a href="' . $url . '">' . $contrib_string . '</a>';
}
!
return $contrib_string;
}
}
\ No newline at end of file
Modified: trunk/titania/includes/mods/mods_details.php
==============================================================================
*** trunk/titania/includes/mods/mods_details.php (original)
--- trunk/titania/includes/mods/mods_details.php Sun Nov 9 03:18:07 2008
***************
*** 46,55 ****
*/
public function main($id, $mode)
{
! global $user, $template, $cache, $phpbb_root_path;
!
! // complete the hack to allow our modules to be loaded from the Titania/includes directory.
! $phpbb_root_path = PHPBB_ROOT_PATH;
$user->add_lang(array('titania_mods'));
--- 46,52 ----
*/
public function main($id, $mode)
{
! global $user, $template, $cache;
$user->add_lang(array('titania_mods'));
Modified: trunk/titania/includes/mods/mods_faq.php
==============================================================================
*** trunk/titania/includes/mods/mods_faq.php (original)
--- trunk/titania/includes/mods/mods_faq.php Sun Nov 9 03:18:07 2008
***************
*** 46,55 ****
*/
public function main($id, $mode)
{
! global $user, $template, $cache, $phpbb_root_path;
!
! // complete the hack to allow our modules to be loaded from the Titania/includes directory.
! $phpbb_root_path = PHPBB_ROOT_PATH;
$user->add_lang(array('titania_contrib'));
--- 46,52 ----
*/
public function main($id, $mode)
{
! global $user, $template, $cache;
$user->add_lang(array('titania_contrib'));
Modified: trunk/titania/includes/mods/mods_main.php
==============================================================================
*** trunk/titania/includes/mods/mods_main.php (original)
--- trunk/titania/includes/mods/mods_main.php Sun Nov 9 03:18:07 2008
***************
*** 46,55 ****
*/
public function main($id, $mode)
{
! global $user, $template, $cache, $phpbb_root_path;
!
! // complete the hack to allow our modules to be loaded from the Titania/includes directory.
! $phpbb_root_path = PHPBB_ROOT_PATH;
$user->add_lang(array('titania_contrib', 'titania_mods'));
--- 46,52 ----
*/
public function main($id, $mode)
{
! global $user, $template, $cache;
$user->add_lang(array('titania_contrib', 'titania_mods'));
Modified: trunk/titania/includes/mods/mods_reviews.php
==============================================================================
*** trunk/titania/includes/mods/mods_reviews.php (original)
--- trunk/titania/includes/mods/mods_reviews.php Sun Nov 9 03:18:07 2008
***************
*** 46,55 ****
*/
public function main($id, $mode)
{
! global $user, $template, $cache, $phpbb_root_path;
!
! // complete the hack to allow our modules to be loaded from the Titania/includes directory.
! $phpbb_root_path = PHPBB_ROOT_PATH;
$user->add_lang(array('titania_reviews'));
--- 46,52 ----
*/
public function main($id, $mode)
{
! global $user, $template, $cache;
$user->add_lang(array('titania_reviews'));
Modified: trunk/titania/includes/mods/mods_support.php
==============================================================================
*** trunk/titania/includes/mods/mods_support.php (original)
--- trunk/titania/includes/mods/mods_support.php Sun Nov 9 03:18:07 2008
***************
*** 46,55 ****
*/
public function main($id, $mode)
{
! global $user, $template, $cache, $phpbb_root_path;
!
! // complete the hack to allow our modules to be loaded from the Titania/includes directory.
! $phpbb_root_path = PHPBB_ROOT_PATH;
$user->add_lang(array('titania_support'));
--- 46,52 ----
*/
public function main($id, $mode)
{
! global $user, $template, $cache;
$user->add_lang(array('titania_support'));
Modified: trunk/titania/includes/titania/titania_main.php
==============================================================================
*** trunk/titania/includes/titania/titania_main.php (original)
--- trunk/titania/includes/titania/titania_main.php Sun Nov 9 03:18:07 2008
***************
*** 46,54 ****
*/
public function main($id, $mode)
{
! global $user, $template, $cache, $phpbb_root_path;
!
! $phpbb_root_path = PHPBB_ROOT_PATH;
$user->add_lang('titania_contrib');
--- 46,52 ----
*/
public function main($id, $mode)
{
! global $user, $template, $cache;
$user->add_lang('titania_contrib');
Added: trunk/titania/includes/titania_modules.php
==============================================================================
*** trunk/titania/includes/titania_modules.php (added)
--- trunk/titania/includes/titania_modules.php Sun Nov 9 03:18:07 2008
***************
*** 0 ****
--- 1,144 ----
+ <?php
+ /**
+ *
+ * @package titania
+ * @version $Id$
+ * @copyright (c) 2008 phpBB Customisation Database Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
+ */
+
+ /**
+ * @ignore
+ */
+ if (!defined('IN_TITANIA'))
+ {
+ exit;
+ }
+
+ require_once(PHPBB_ROOT_PATH . 'includes/functions_module.' . PHP_EXT);
+
+ /**
+ * @package modules
+ */
+ class titania_modules extends p_master
+ {
+ public $include_path;
+
+ /**
+ * Constructor to set the custom module include path
+ */
+ public function __construct()
+ {
+ global $phpbb_root_path;
+
+ $this->include_path = $phpbb_root_path . 'includes/';
+ }
+
+ /**
+ * Function to set custom module include path (able to use directory outside of phpBB)
+ *
+ * @param string $include_path include path to be used.
+ * @access public
+ */
+ function set_custom_include_path($include_path)
+ {
+ $this->include_path = $include_path;
+
+ if (substr($this->include_path, -1) != '/')
+ {
+ $this->include_path .= '/';
+ }
+ }
+
+ /**
+ * Loads currently active module
+ *
+ * This method loads a given module, passing it the relevant id and mode.
+ */
+ public function load_active($mode = false, $module_url = false, $execute_module = true)
+ {
+ global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user;
+
+ $module_path = $this->include_path . $this->p_class;
+ $icat = request_var('icat', '');
+
+ if ($this->active_module === false)
+ {
+ trigger_error('Module not accessible', E_USER_ERROR);
+ }
+
+ if (!class_exists("{$this->p_class}_$this->p_name"))
+ {
+ if (!file_exists("$module_path/{$this->p_class}_$this->p_name.$phpEx"))
+ {
+ trigger_error("Cannot find module $module_path/{$this->p_class}_$this->p_name.$phpEx", E_USER_ERROR);
+ }
+
+ include("$module_path/{$this->p_class}_$this->p_name.$phpEx");
+
+ if (!class_exists("{$this->p_class}_$this->p_name"))
+ {
+ 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);
+ }
+
+ if (!empty($mode))
+ {
+ $this->p_mode = $mode;
+ }
+
+ // 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);
+
+ // We pre-define the action parameter we are using all over the place
+ if (defined('IN_ADMIN'))
+ {
+ // 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'];
+ }
+
+ // Not being able to overwrite ;)
+ $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}";
+ }
+ else
+ {
+ // If user specified the module url we will use it...
+ if ($module_url !== false)
+ {
+ $this->module->u_action = $module_url;
+ }
+ else
+ {
+ $this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name'];
+ }
+
+ $this->module->u_action = append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}";
+ }
+
+ // Add url_extra parameter to u_action url
+ if (!empty($this->module_ary) && $this->active_module !== false && $this->module_ary[$this->active_module_row_id]['url_extra'])
+ {
+ $this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra'];
+ }
+
+ // 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)
+ {
+ $this->module->main($this->p_name, $this->p_mode);
+ }
+
+ return;
+ }
+ }
+ }
+
+ ?>
\ No newline at end of file
Propchange: trunk/titania/includes/titania_modules.php
------------------------------------------------------------------------------
svn:eol-style = LF
Propchange: trunk/titania/includes/titania_modules.php
------------------------------------------------------------------------------
svn:keywords = Id
Modified: trunk/titania/index.php
==============================================================================
*** trunk/titania/index.php (original)
--- trunk/titania/index.php Sun Nov 9 03:18:07 2008
***************
*** 15,37 ****
if (!defined('TITANIA_ROOT')) define('TITANIA_ROOT', './');
if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
include(TITANIA_ROOT . 'common.' . PHP_EXT);
! include(PHPBB_ROOT_PATH . 'includes/functions_module.' . PHP_EXT);
$id = request_var('id', 'main');
$mode = request_var('mode', '');
! $module = new p_master();
// Instantiate module system and generate list of available modules
$module->list_modules('titania');
// Select the active module
$module->set_active($id, $mode);
// Load and execute the relevant module
// trick the module class to allow modules to be loaded from the titania includes path.
! $phpbb_root_path = TITANIA_ROOT;
$module->load_active();
- $phpbb_root_path = PHPBB_ROOT_PATH;
// Assign data to the template engine for the list of modules
$module->assign_tpl_vars(append_sid(TITANIA_ROOT . 'index.' . PHP_EXT));
--- 15,37 ----
if (!defined('TITANIA_ROOT')) define('TITANIA_ROOT', './');
if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
include(TITANIA_ROOT . 'common.' . PHP_EXT);
! include(TITANIA_ROOT . 'includes/titania_modules.' . PHP_EXT);
$id = request_var('id', 'main');
$mode = request_var('mode', '');
! $module = new titania_modules();
// Instantiate module system and generate list of available modules
$module->list_modules('titania');
// Select the active module
$module->set_active($id, $mode);
+
// Load and execute the relevant module
// trick the module class to allow modules to be loaded from the titania includes path.
! $module->set_custom_include_path(TITANIA_ROOT . 'includes/');
$module->load_active();
// Assign data to the template engine for the list of modules
$module->assign_tpl_vars(append_sid(TITANIA_ROOT . 'index.' . PHP_EXT));
Modified: trunk/titania/mods/index.php
==============================================================================
*** trunk/titania/mods/index.php (original)
--- trunk/titania/mods/index.php Sun Nov 9 03:18:07 2008
***************
*** 15,21 ****
if (!defined('TITANIA_ROOT')) define('TITANIA_ROOT', './../');
if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
include(TITANIA_ROOT . 'common.' . PHP_EXT);
! include(PHPBB_ROOT_PATH . 'includes/functions_module.' . PHP_EXT);
include(TITANIA_ROOT . 'includes/titania_cache.' . PHP_EXT);
$cache = new titania_cache();
--- 15,21 ----
if (!defined('TITANIA_ROOT')) define('TITANIA_ROOT', './../');
if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
include(TITANIA_ROOT . 'common.' . PHP_EXT);
! include(TITANIA_ROOT . 'includes/titania_modules.' . PHP_EXT);
include(TITANIA_ROOT . 'includes/titania_cache.' . PHP_EXT);
$cache = new titania_cache();
***************
*** 50,56 ****
}
}
! $module = new p_master();
// Instantiate module system and generate list of available modules
$module->list_modules('mods');
--- 50,56 ----
}
}
! $module = new titania_modules();
// Instantiate module system and generate list of available modules
$module->list_modules('mods');
***************
*** 60,68 ****
// Load and execute the relevant module
// trick the module class to allow modules to be loaded from the titania includes path.
! $phpbb_root_path = TITANIA_ROOT;
$module->load_active();
- $phpbb_root_path = PHPBB_ROOT_PATH;
// Assign data to the template engine for the list of modules
$module->assign_tpl_vars(append_sid(TITANIA_ROOT . 'mods/index.' . PHP_EXT));
--- 60,67 ----
// Load and execute the relevant module
// trick the module class to allow modules to be loaded from the titania includes path.
! $module->set_custom_include_path(TITANIA_ROOT . 'includes/');
$module->load_active();
// Assign data to the template engine for the list of modules
$module->assign_tpl_vars(append_sid(TITANIA_ROOT . 'mods/index.' . PHP_EXT));
More information about the customisationdb-commits
mailing list