Version 3.4.5

This commit is contained in:
Neo committed 2025-12-19 00:38:12 -08:00
1 parent fb6b5baabc
commit e4478369d8
1360 files changed
+228921 -179445

No files matched your search

@@ -3,17 +3,17 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.3.4
* IP.Board v3.4.5
* Admin Output Library
* Last Updated: $LastChangedDate: 2012-07-03 10:29:35 -0400 (Tue, 03 Jul 2012) $
* Last Updated: $LastChangedDate: 2013-05-20 16:38:23 -0400 (Mon, 20 May 2013) $
* </pre>
*
* @author $Author: ips_terabyte $
* @author $Author: bfarber $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/company/standards.php#license
* @package IP.Board
* @link http://www.invisionpower.com
* @version $Rev: 11026 $
* @version $Rev: 12261 $
*
*/
@@ -31,8 +31,8 @@ class adminOutput extends output
*
* @var object
*/
public $global_template = '';
public $global_template = '';
/**#@+
* HTML variables
*
@@ -90,7 +90,15 @@ class adminOutput extends output
*
* @var array
*/
protected $tabKeys = array( 'core', 'forums', 'members', 'lookfeel', 'support', 'reports', 'other' );
private $tabKeys = array();
private $otherTabKeys = array();
private $tabPrefs = array();
/**
* Is bookmarkable
* @var boolean
*/
protected $_canBookmark = true;
/**
* Constructor
@@ -108,6 +116,10 @@ class adminOutput extends output
$this->settings['base_url'] = $this->settings['_original_base_url'];
$this->settings['public_url'] = $this->settings['_original_base_url'] . '/index.php?';
$this->settings['public_dir'] = $this->settings['_original_base_url'] . '/' . PUBLIC_DIRECTORY . '/';
$this->settings['public_cdn_url'] = rtrim( $this->settings['ipb_img_url'] ? $this->settings['ipb_img_url'] : $this->settings['_original_base_url'], '/' ) . '/' . PUBLIC_DIRECTORY . '/';
$this->settings['css_base_url'] = rtrim( $this->settings['ipb_css_url'] ? $this->settings['ipb_css_url'] : $this->settings['_original_base_url'], '/' ) . '/' . PUBLIC_DIRECTORY . '/';
$this->settings['js_base_url'] = rtrim( $this->settings['ipb_js_url'] ? $this->settings['ipb_js_url'] : $this->settings['_original_base_url'], '/' ) . '/' . PUBLIC_DIRECTORY . '/';
$this->settings['base_acp_url'] = $this->settings['base_url'] . '/' . CP_DIRECTORY;
$this->settings['skin_acp_url'] = $this->settings['base_url'] . '/' . CP_DIRECTORY . "/skin_cp";
@@ -139,6 +151,234 @@ class adminOutput extends output
$this->settings['extraJsModules'] = '';
}
/**
* Called in admin function constructor to prevent output init clashes
*/
public function initTabKeys()
{
/* Get tab prefs first */
$this->tabPrefs = $this->registry->adminFunctions->staffGetCookie( 'tabPrefs' );
/* Set up default tab keys */
$this->getMainTabKeys();
}
/**
* Returns keys for use in the main tab bar
* @return array:
*/
public function getMainTabKeys()
{
if ( ! count( $this->tabKeys ) )
{
if ( isset( $this->tabPrefs['tabBar'] ) && is_array( $this->tabPrefs['tabBar'] ) && count( $this->tabPrefs['tabBar'] ) )
{
$this->tabKeys = array_values( $this->tabPrefs['tabBar'] );
}
else
{
$this->tabKeys = array( 'core', 'forums', 'members', 'lookfeel', 'support', 'reports', 'other' );
}
}
return $this->tabKeys;
}
/**
* Returns keys for use in the other apps menu
* @return array:
*/
public function getOtherTabKeys()
{
$tmp = $this->registry->getClass('class_permissions')->return;
$this->registry->getClass('class_permissions')->return = TRUE; // We have to do this to stop the checkForAppAccess call below to end up sending a showError screen
$mainTabKeys = $this->getMainTabKeys();
if ( ! count( $this->otherTabKeys ) )
{
if ( isset( $this->tabPrefs['otherMenu'] ) && is_array( $this->tabPrefs['otherMenu'] ) && count( $this->tabPrefs['otherMenu'] ) )
{
$this->otherTabKeys = array_values( $this->tabPrefs['otherMenu'] );
/* Got all apps? Some could have been added after we last re-arranged tabs */
foreach( ipsRegistry::$applications as $app_dir => $app_data )
{
if ( $this->registry->getClass('class_permissions')->checkForAppAccess( $app_data['app_directory'] ) !== TRUE || ! $app_data['app_enabled'] )
{
continue;
}
if ( ! in_array( $app_dir, $mainTabKeys ) && ! in_array( $app_dir, $this->otherTabKeys ) )
{
$this->otherTabKeys[] = $app_data['app_directory'];
}
}
}
else
{
foreach( ipsRegistry::$applications as $app_dir => $app_data )
{
if ( in_array( $app_data['app_directory'], array( 'core', 'forums', 'members' ) ) || in_array( $app_data['app_directory'], $mainTabKeys ) || $this->registry->getClass('class_permissions')->checkForAppAccess( $app_data['app_directory'] ) !== TRUE || ! $app_data['app_enabled'] )
{
continue;
}
$this->otherTabKeys[] = $app_data['app_directory'];
}
}
}
$this->registry->getClass('class_permissions')->return = $tmp;
return $this->otherTabKeys;
}
/**
* Get tab data from keys
* @param array Array of keys to fetch data from
*/
public function getTabDataFromKeys( $keys )
{
$tmp = $this->registry->getClass('class_permissions')->return;
$this->registry->getClass('class_permissions')->return = TRUE; // We have to do this to stop the checkForAppAccess call below to end up sending a showError screen
$fakeApps = $this->fetchFakeApps();
$applications = ipsRegistry::$applications;
$defaultFakeApp = array();
$tabs = array();
$fakeActive = false;
/* Set up fake apps stuff */
foreach( $fakeApps as $fa => $data )
{
$_active = false;
$fakeAppAccess[ $fa ] = false;
$fakeAppActive[ $fa ] = false;
foreach( $data as $appData )
{
if ( ! $defaultFakeApp[ $fa ] )
{
$defaultFakeApp[ $fa ] = $appData['app'];
$defaultFakeModule[ $fa ] = $appData['module'];
}
if ( ! $fakeAppAccess[ $fa ] and ipsRegistry::getClass('class_permissions')->checkForModuleAccess( $appData['app'], $appData['module'] ) )
{
$fakeAppAccess[ $fa ] = true;
}
if ( $appData['app'] == ipsRegistry::$current_application && $appData['module'] == ipsRegistry::$current_module )
{
$fakeAppActive[ $fa ] = true;
$fakeActive = true;
}
}
}
foreach( $keys as $tabkey )
{
$gotIt = false;
/* Try 'other' first */
if ( $tabkey == 'other' )
{
$gotIt = true;
$tabs[ $tabkey ] = array( 'title' => $this->lang->words['other_applications'],
'active' => false,
'appDir' => false,
'isEnabled' => true,
'permCheck' => true,
'url' => "{$this->settings['_base_url']}app=core&amp;module=applications&amp;section=applications&amp;do=applications_overview" );
}
/* Try fake apps first */
foreach( $fakeApps as $fa => $data )
{
if ( $fa == $tabkey )
{
$gotIt = true;
switch( $fa )
{
case 'lookfeel':
$title = $this->lang->words['gl_lookandfeel'];
$link = "{$this->settings['_base_url']}app={$defaultFakeApp['lookfeel']}&amp;module={$defaultFakeModule['lookfeel']}";
break;
case 'support':
$title = $this->lang->words['gl_support'];
$link = "{$this->settings['_base_url']}app=core&amp;module=diagnostics";
break;
case 'reports':
$title = $this->lang->words['gl_reportsmenu'];
$link = "{$this->settings['_base_url']}app={$defaultFakeApp['reports']}&amp;module={$defaultFakeModule['reports']}";
break;
}
$tabs[ $tabkey ] = array( 'title' => $title,
'permCheck' => $fakeAppAccess[ $fa ],
'active' => $fakeAppActive[ $fa ],
'appDir' => $defaultFakeApp[ $fa ],
'isEnabled' => true,
'url' => $link );
}
}
/* Try normal apps next */
if ( $gotIt === false )
{
/* Loop */
foreach( $applications as $app_dir => $app_data )
{
switch( $app_data['app_directory'] )
{
case 'core':
$app_data['app_title'] = $this->lang->words['gl_system'];
break;
case 'forums':
$app_data['app_title'] = $this->lang->words['gl_forums'];
break;
case 'members':
$app_data['app_title'] = $this->lang->words['gl_members'];
break;
}
if ( $tabkey == $app_data['app_directory'] )
{
$tabs[ $tabkey ] = array( 'title' => $app_data['app_title'],
'active' => ( $fakeActive === false && ipsRegistry::$current_application == $app_data['app_directory'] ) ? true : false,
'permCheck' => ipsRegistry::getClass('class_permissions')->checkForAppAccess( $app_data['app_directory'] ),
'isEnabled' => (boolean) $app_data['app_enabled'],
'appDir' => $app_data['app_directory'],
'url' => "{$this->settings['_base_url']}app={$app_data['app_directory']}" );
}
}
}
}
$this->registry->getClass('class_permissions')->return = $tmp;
return $tabs;
}
/**
* Can bookmark this page
* @param boolean
*/
public function canBookmark( $bool )
{
$this->_canBookmark = (boolean) $bool;
}
/**
* Set a global message to be used
*
@@ -184,13 +424,42 @@ class adminOutput extends output
IPSDebug::setMemoryDebugFlag( "CORE: Template Loaded ({$classToLoad})", $_pre_load );
return new $classToLoad( $this->registry );
$class = new $classToLoad( $this->registry );
$this->compiled_templates[ $app . '.' . $template ] = $class;
return $class;
}
else
{
$this->showError( sprintf( $this->lang->words['notemplatefiletoload'], $template ), 4100, true );
}
}
/**
* Returns a template class; loading if required
*
* @access public
* @param string template name
* @param boolean [Test only, TRUE for yes, FALSE for no]
* @return mixed Object, or null
*/
public function getXTemplate( $groupName )
{
if ( ! isset( $this->compiled_templates[ $groupName ] ) || ! is_object( $this->compiled_templates[ $groupName ] ) )
{
//-----------------------------------------
// Using self:: so that we can load public
// skins inside ACP when necessary
//-----------------------------------------
list( $app, $template ) = explode( '.', $groupName );
self::loadTemplate( $template, $app );
}
return isset( $this->compiled_templates[ $groupName ] ) ? $this->compiled_templates[ $groupName ] : NULL;
}
/**
* Show a download dialog box
@@ -387,7 +656,7 @@ class adminOutput extends output
* @param string Text to display
* @return @e void
*/
public function multipleRedirectFinish($text='Completed!')
public function multipleRedirectFinish($text='Завершено!')
{
print $this->global_template->global_redirect_done( $text );
exit();
@@ -403,7 +672,7 @@ class adminOutput extends output
* @param integer Header code to send (ignored for ACP)
* @return @e void
*/
public function showError( $message, $code=0, $logError=FALSE, $logExtra='', $header=500 )
public function showError( $message, $code=0, $logError=FALSE, $logExtra='', $header=401 )
{
$this->_sendOutputSetUp( 'error' );
@@ -433,7 +702,7 @@ class adminOutput extends output
}
}
}
//-----------------------------------------
// Log the error, if needed
//-----------------------------------------
@@ -449,13 +718,13 @@ class adminOutput extends output
$this->logErrorMessage( $_logMessage, $code );
}
//-----------------------------------------
// Send notification if needed
//-----------------------------------------
$this->sendErrorNotification( $message, $code );
//-----------------------------------------
// Finally, output
//-----------------------------------------
@@ -474,6 +743,15 @@ class adminOutput extends output
public function sendOutput( $return=false )
{
$this->_sendOutputSetUp( 'normal' );
//-----------------------------------------
// Hang on, is IP.SEO still installed?
//-----------------------------------------
if ( IPSLib::appIsInstalled('ipseo') and !in_array( ipsRegistry::$request['section'], array( 'upgrade', 'applications' ) ) )
{
$this->silentRedirect( $this->settings['_base_url'] . 'app=core&amp;module=seo&amp;section=upgrade' );
}
//---------------------------------------
// INIT
@@ -494,7 +772,7 @@ class adminOutput extends output
$this->printPopupWindow();
exit();
}
//-----------------------------------------
// Debug?
//-----------------------------------------
@@ -541,19 +819,31 @@ class adminOutput extends output
}
}
/**
* Add in bookmarkables
*/
require_once( IPS_ROOT_PATH . 'sources/classes/admin/bookmarks.php' );
$bookmarks = new classes_admin_bookmarks();
$_bookmarkData = array( 'url' => $bookmarks->cleanUrl( $this->settings['query_string_safe'] ),
'can' => ( $this->_canBookmark ? 'true' : 'false' ),
'has' => ( $bookmarks->hasBookmarked( $this->settings['query_string_safe'] ) ? 'true' : 'false' ),
'jsn' => $bookmarks->asJson() );
//-----------------------------------------
// Get tab order
//-----------------------------------------
$applications = ipsRegistry::$applications;
$mainTabs = $this->registry->output->getMainTabKeys();
$otherTabs = $this->registry->output->getOtherTabKeys();
$mainTabData = $this->registry->output->getTabDataFromKeys( $mainTabs );
$otherTabData = $this->registry->output->getTabDataFromKeys( $otherTabs );
$_tabOrder = ipsRegistry::getClass('adminFunctions')->staffGetCookie( 'tabOrder' );
if( !count($_tabOrder) OR !is_array($_tabOrder) )
{
$_tabOrder = $this->tabKeys;
}
$gbl_sub_menu = $this->_buildGlobalSubMenu();
$html = str_replace( '<%CONTENT%>', $this->html_main, $this->global_template->global_main_wrapper( IPS_DOC_CHAR_SET, $this->_css, $gbl_sub_menu, $_tabOrder ) );
$html = str_replace( '<%CONTENT%>', $this->html_main, $this->global_template->global_main_wrapper( IPS_DOC_CHAR_SET, $this->_css, $gbl_sub_menu, $mainTabData, $otherTabData, $_bookmarkData ) );
//------------------------------------------------
// Message in a bottle?
@@ -700,9 +990,12 @@ class adminOutput extends output
//-----------------------------------------
// Last thing, the nav element...
//-----------------------------------------
$html = str_replace( "<%PAGE_NAV%>", $_last_nav['title'], $html );
if ( isset( $_last_nav['title'] ) )
{
$html = str_replace( "<%PAGE_NAV%>", $_last_nav['title'], $html );
}
$query_html = "";
//-----------------------------------------
@@ -775,7 +1068,7 @@ class adminOutput extends output
}
$html = str_replace( "<%QUERIES%>" , $query_html , $html );
//-----------------------------------------
// Got BODY EXTRA?
//-----------------------------------------
@@ -791,6 +1084,9 @@ class adminOutput extends output
$html = str_replace( "<#EMO_DIR#>" , 'default' , $html );
/* Remove any public side hooks */
$html = preg_replace( '#<!--hook\.([^\>]+?)-->#', '', $html );
//-----------------------------------------
// Gzip?
//-----------------------------------------
@@ -1111,7 +1407,7 @@ class adminOutput extends output
if ( IN_DEV )
{
ipsRegistry::cache()->updateCacheWithoutSaving( 'app_menu_cache', array() );
//ipsRegistry::cache()->updateCacheWithoutSaving( 'app_menu_cache', array() );
}
if ( ! is_array( ipsRegistry::cache()->getCache('app_menu_cache') ) OR ! count( ipsRegistry::cache()->getCache('app_menu_cache') ) )
@@ -1236,7 +1532,7 @@ class adminOutput extends output
{
if( !$this->ignoreCoreNav )
{
$this->core_nav[] = array( $this->settings['base_url'] . 'module=' . $_current_module . '&amp;section=' . $item['section'], $module_data['title'] );
$this->core_nav[] = array( $this->settings['base_url'] . 'module=' . $_current_module . '&amp;section=' . $item['section'], $item['title'] );
}
$_nav_main_done = 1;
@@ -1260,11 +1556,11 @@ class adminOutput extends output
}
}
/* Reset */
$_ok = 0;
if ( $item['url'] )
{
/* Reset */
$_ok = 0;
/* Trying something a little different with the nav */
$_url = explode( '=', $item['url'] );
@@ -1338,7 +1634,7 @@ class adminOutput extends output
if ( IN_DEV )
{
ipsRegistry::cache()->updateCacheWithoutSaving( 'app_menu_cache', array() );
//ipsRegistry::cache()->updateCacheWithoutSaving( 'app_menu_cache', array() );
}
if ( ! is_array( ipsRegistry::cache()->getCache('app_menu_cache') ) OR ! count( ipsRegistry::cache()->getCache('app_menu_cache') ) )
@@ -1980,7 +2276,7 @@ class adminOutput extends output
$yes = "<span class='yesno_yes {$css}'><input type='radio' name='{$name}' value='1' {$y_js}{$id_yes} /><label for='{$id}_yes'>{$this->lang->words['yesno_yes']}</label></span>";
$no = "<span class='yesno_no {$css}'><input type='radio' name='{$name}' value='0' {$n_js}{$id_no} /><label for='{$id}_no'>{$this->lang->words['yesno_no']}</label></span>";
if ( $default_val == 1 )
if ( $default_val == "1" )
{
$yes = "<span class='yesno_yes {$css}'><input type='radio'{$id_yes} name='{$name}' value='1' {$y_js} checked='checked' /><label for='{$id}_yes'>{$this->lang->words['yesno_yes']}</label></span>";
}
@@ -3,19 +3,19 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.3.4
* IP.Board v3.4.5
* Ouput format: HTML
* (Matt Mecham)
* Last Updated: $Date: 2012-06-12 10:14:49 -0400 (Tue, 12 Jun 2012) $
* Last Updated: $Date: 2013-03-12 16:14:42 -0400 (Tue, 12 Mar 2013) $
* </pre>
*
* @author $Author: bfarber $
* @author $Author: mmecham $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/company/standards.php#license
* @package IP.Board
* @link http://www.invisionpower.com
* @since 9th March 2005 11:03
* @version $Revision: 10914 $
* @version $Revision: 12075 $
*
*/
@@ -230,6 +230,10 @@ class coreOutput
$this->_headerStatus = 'Moved Temporarily';
break;
case 401:
$this->_headerStatus = 'Unauthorized';
break;
case 403:
$this->_headerStatus = 'Forbidden';
break;
@@ -308,7 +312,7 @@ class coreOutput
{
$encode = ( $encode === FALSE ) ? FALSE : TRUE;
$trimLen = ( $trimLen - 3 );
$tag = strtolower($tag); // 'ROBOTS' should overwrite 'robots'
$tag = trim( strtolower( $tag ) ); // 'ROBOTS' should overwrite 'robots'
switch( $tag )
{
@@ -330,13 +334,17 @@ class coreOutput
$content = IPSText::truncate( $content, $trimLen );
break;
case 'keywords':
/* @link http://community.invisionpower.com/resources/bugs.html/_/ip-board/seo-meta-keyworks-doesnt-work-correctly-r38420
@link http://community.invisionpower.com/resources/bugs.html/_/ip-board/meta-issues-r39358
When encode is passed as true, we should assume the block of text has not been formatted, and that we need to convert spaces to commas basically.
When encode is passed as false, we should assume that the keywords coming in have been explicitly set (with commas) and not change that */
if ( $encode === TRUE )
{
$content = IPSText::stripAttachTag( $content );
//Bug #15323 breaks accented characters, etc
//$content = strtolower( preg_replace( "/[^0-9a-zA-Z ]/", "", preg_replace( "/&([^;]+?);/", "", $content ) ) );
$content = str_replace( array( '.', ',', '!', ':', ';', "'", '"', '@', '%', '*', '(', ')' ), '', preg_replace( "/&([^;]+?);/", "", $content ) );
$content = str_replace( array( '.', '!', ':', ';', ',', '"', '@', '%', '*', '(', ')' ), '', preg_replace( "/&([^;]+?);/", "", $content ) );
//Also breaks accented characters
//$_vals = preg_split( '/\s+?/', $content, -1, PREG_SPLIT_NO_EMPTY );
$_vals = explode( ' ', $content );
@@ -367,15 +375,15 @@ class coreOutput
}
else
{
$content = str_replace( array( '.', ',', '!', ':', ';', "'", '"', '@', '%', '*', '(', ')' ), '', preg_replace( "/&([^;]+?);/", "", $content ) );
$content = str_replace( array( '.', '!', ':', ';', "'", '"', '@', '%', '*', '(', ')' ), '', preg_replace( "/&([^;]+?);/", "", $content ) );
}
$content = IPSText::truncate( $content, $trimLen );
break;
}
$this->_metaTags[ $tag ] = ( $encode === TRUE ) ? $this->encodeMetaTagContent( preg_replace( '/&amp;#(\d+?);/', "&#\\1;", htmlspecialchars( $content ) ) ) : $content;
$this->_metaTags[ $tag ][0] = ( $encode === TRUE ) ? preg_replace( '#&amp;(amp|gt|lt|quot);#', '&\1;', $this->encodeMetaTagContent(preg_replace( '/&amp;#(\d+?);/', "&#\\1;", htmlspecialchars( $content ) ) ) ) : preg_replace( '#&amp;(amp|gt|lt|quot);#', '&\1;', $content );
}
/**
@@ -529,6 +537,13 @@ class coreOutput
{
$link .= "&amp;module={$tab['module']}";
}
/* http://community.invisionpower.com/resources/bugs.html/_/ip-board/ips-default-public-app-and-navigation-r41028 */
if ( $tab['app'] == IPS_DEFAULT_PUBLIC_APP )
{
$link = "";
}
break;
}
@@ -3,10 +3,10 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.3.4
* IP.Board v3.4.5
* Ouput format: HTML
* (Matt Mecham)
* Last Updated: $Date: 2012-06-12 10:14:49 -0400 (Tue, 12 Jun 2012) $
* Last Updated: $Date: 2012-05-10 16:10:13 -0400 (Thu, 10 May 2012) $
* </pre>
*
* @author $Author: bfarber $
@@ -15,7 +15,7 @@
* @package IP.Board
* @link http://www.invisionpower.com
* @since 9th March 2005 11:03
* @version $Revision: 10914 $
* @version $Revision: 10721 $
*
*/
$config = array();
File diff suppressed because it is too large. Load diff
@@ -3,10 +3,10 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.3.4
* IP.Board v3.4.5
* Ouput format: XML
* (Matt Mecham)
* Last Updated: $Date: 2012-06-12 10:14:49 -0400 (Tue, 12 Jun 2012) $
* Last Updated: $Date: 2012-05-10 16:10:13 -0400 (Thu, 10 May 2012) $
* </pre>
*
* @author $Author: bfarber $
@@ -15,7 +15,7 @@
* @package IP.Board
* @link http://www.invisionpower.com
* @since 9th March 2005 11:03
* @version $Revision: 10914 $
* @version $Revision: 10721 $
*
*/
@@ -3,10 +3,10 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.3.4
* IP.Board v3.4.5
* Ouput format: HTML
* (Matt Mecham)
* Last Updated: $Date: 2012-06-12 10:14:49 -0400 (Tue, 12 Jun 2012) $
* Last Updated: $Date: 2012-05-10 16:10:13 -0400 (Thu, 10 May 2012) $
* </pre>
*
* @author $Author: bfarber $
@@ -15,7 +15,7 @@
* @package IP.Board
* @link http://www.invisionpower.com
* @since 9th March 2005 11:03
* @version $Revision: 10914 $
* @version $Revision: 10721 $
*
*/
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,245 @@
<?php
/**
* <pre>
* Invision Power Services
* IP.Board v3.4.5
* System Templates
* Last Updated: $Date: 2012-05-10 21:10:13 +0100 (Thu, 10 May 2012) $
* </pre>
*
* @author Mark Wade
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/company/standards.php#license
* @package IP.Board
* @link http://www.invisionpower.com
* @since 5th September 2012
* @version $Rev: 10721 $
*
*/
/**
* System Templates
*/
class systemTemplates
{
/**
* Get Templates
*
* @return array
*/
public function getList()
{
$templates = array();
$directoryIterator = new DirectoryIterator( IPS_CACHE_PATH . 'cache/skin_cache/system' );
foreach ( $directoryIterator as $file )
{
if ( !$file->isDot() and $file->isFile() and substr( $file, -4 ) === '.php' )
{
require_once $file->getPathName();
$className = substr( $file, 0, -4 );
if ( class_exists( $className ) )
{
$class = new $className;
if ( $class instanceof systemTemplate )
{
$templates[ $className ] = $className;
}
}
}
}
return $templates;
}
/**
* Get Class
*
* @param string Key
* @return systemTemplate
* @throws Exception
*/
public function getClass( $key )
{
/* If IPS_CACHE_PATH isn't set up quite yet */
if ( ! defined( 'IPS_CACHE_PATH' ) )
{
define( 'IPS_CACHE_PATH', IPS_TEMP_CACHE_PATH );
}
$file = IPS_CACHE_PATH . 'cache/skin_cache/system/' . $key . '.php';
if ( !file_exists( $file ) )
{
$this->writeDefaults();
if( !file_exists( $file ) )
{
throw new Exception('NO_FILE');
}
}
require_once $file;
if ( !class_exists( $key ) )
{
throw new Exception('NO_CLASS');
}
$class = new $key;
if ( !( $class instanceof systemTemplate ) )
{
throw new Exception('BAD_TEMPLATE');
}
if ( !method_exists( $class, 'getTemplate' ) )
{
throw new Exception( 'NO_GETTEMPLATE_METHOD' );
}
return $class;
}
/**
* Write
*
* @param string Key
* @param array Param Names
* @param string Content
* @return int|false Data written
*/
public function write( $key, $paramNames, $content )
{
$implodedParamNames = implode( ', ', $paramNames );
$fileContents = <<<CONTENT
<?php
class {$key} extends systemTemplate
{
public function getTemplate( {$implodedParamNames} )
{
return <<<EOF
{$content}
EOF;
}
}
CONTENT;
if ( ! defined('IPS_CACHE_PATH') )
{
define( 'IPS_CACHE_PATH', DOC_IPS_ROOT_PATH );
}
return file_put_contents( IPS_CACHE_PATH . 'cache/skin_cache/system/' . $key . '.php', $fileContents );
}
/**
* Revert
*
* @param string Key
* @return int|false Data written
*/
public function revert( $key )
{
$defaultTemplates = file_get_contents( IPS_ROOT_PATH . 'setup/xml/system_templates.xml' );
require_once IPS_KERNEL_PATH . 'classXML.php';
$xml = new classXML( 'utf-8' );
$xml->loadXML( $defaultTemplates );
$array = $xml->fetchXMLAsArray();
foreach ( $array['system_templates']['template'] as $template )
{
if ( $template['key']['#alltext'] == $key )
{
$params = array();
foreach ( $template['params']['param'] as $p )
{
$params[] = $p['#alltext'];
}
return $this->write( $key, $params, $template['content']['#alltext'] );
}
}
throw new Exception('NO_DEFAULT_VALUE');
}
/**
* Write Default Values
*/
public function writeDefaults()
{
$defaultTemplates = file_get_contents( IPS_ROOT_PATH . 'setup/xml/system_templates.xml' );
if ( !class_exists( 'classXML' ) )
{
require_once IPS_KERNEL_PATH . 'classXML.php';
}
$xml = new classXML( 'utf-8' );
$xml->loadXML( $defaultTemplates );
$array = $xml->fetchXMLAsArray();
foreach ( $array['system_templates']['template'] as $template )
{
$params = array();
foreach ( $template['params']['param'] as $p )
{
$params[] = $p['#alltext'];
}
$this->write( $template['key']['#alltext'], $params, $template['content']['#alltext'] );
}
}
}
/**
* Abstract System Template Class
*/
abstract class systemTemplate
{
/**
* Constructor
*
* @access public
* @return @e void
*/
public function __construct()
{
}
}
/**
* Passthrough variable for displaying in templates
*/
class fakeArray implements ArrayAccess
{
public function __construct( $name )
{
$this->name = $name;
}
public function offsetExists ( $offset )
{
return true;
}
public function offsetGet ( $offset )
{
return '{$'.$this->name.'[\'' . $offset . '\']}';
}
public function offsetSet ( $offset , $value )
{
}
public function offsetUnset ( $offset )
{
}
}