Version 3.2.3

This commit is contained in:
Neo committed 2025-12-19 00:34:03 -08:00
1 parent ae5c01cc78
commit 78706903a2
2641 files changed
+228363 -201264

No files matched your search

@@ -3,19 +3,19 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.1.4
* IP.Board v3.2.3
* Skin Functions
* Last Updated: $Date: 2010-10-13 14:43:52 -0400 (Wed, 13 Oct 2010) $
* Last Updated: $Date: 2011-10-14 10:25:10 -0400 (Fri, 14 Oct 2011) $
* </pre>
*
* Owner: Matt
* @author $Author: mmecham $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/community/board/license.html
* @license This is NULLED!
* @package IP.Board
* @link http://www.invisionpower.com
* @link http://hatynka.in
* @since 9th March 2005 11:03
* @version $Revision: 6972 $
* @version $Revision: 9619 $
*
*/
@@ -39,7 +39,9 @@ class skinFunctions
protected $request;
protected $lang;
protected $member;
protected $memberData;
protected $cache;
protected $caches;
/**#@-*/
/**
@@ -54,26 +56,26 @@ class skinFunctions
* Template count
* Maintains an array: [skin_set_id][group_name][count]
*
* @access private
* @access protected
* @var array
*/
private $_templateCount;
protected $_templateCount;
/**
* Error handle
*
* @access private
* @access protected
* @var array
*/
private $_errorMsgs = array();
protected $_errorMsgs = array();
/**
* Message handle
*
* @access private
* @access protected
* @var array
*/
private $_generalMsgs = array();
protected $_generalMsgs = array();
/**
* IN_DEV remap data
@@ -85,16 +87,16 @@ class skinFunctions
/**
* Set cache
* @var private
* @var protected
*/
private $_seenSet = array();
protected $_seenSet = array();
/**
* Constructor
*
* @access public
* @param object Registry object
* @return void
* @return @e void
*/
public function __construct( ipsRegistry $registry )
{
@@ -127,7 +129,7 @@ class skinFunctions
// Load tier class and init it
//-----------------------------------------
require_once( IPS_ROOT_PATH . 'sources/classes/tiers/recursiveTiers.php' );
require_once( IPS_ROOT_PATH . 'sources/classes/tiers/recursiveTiers.php' );/*noLibHook*/
$this->recursiveTiers = new recursiveTiers( $registry, array( 'sqlPrimaryID' => 'set_id',
'sqlParentID' => 'set_parent_id',
@@ -148,6 +150,32 @@ class skinFunctions
return $this->recursiveTiers;
}
/**
* Make this skin default
* @param int $set_id
*/
public function makeDefault( $set_id )
{
$setData = $this->fetchSkinData( $set_id, true );
/* Make all others non default */
$this->DB->update( 'skin_collections', array( 'set_is_default' => 0 ), 'set_id != ' . $set_id . ' AND set_output_format=\'' . $setData['set_output_format'] . '\'' );
/* Attempt to see if we have any other skin called 'default' */
/* Not using this currently as it causes complications in other areas */
/*
$default = $this->DB->buildAndFetch( array( 'select' => 'set_id',
'from' => 'skin_collections',
'where' => 'set_key=\'default\' AND set_output_format=\'' . $setData['set_output_format'] . '\'' ) );
if ( $set_id != $default['set_id'] )
{
$this->DB->update( 'skin_collections', array( 'set_key' => IPS_UNIX_TIME_NOW ), 'set_id = ' . $default['set_id'] );
}
*/
/* Make this default */
$this->DB->update( 'skin_collections', array( 'set_is_default' => 1/*, 'set_key' => 'default'*/ ), 'set_id = ' . $set_id . ' AND set_output_format=\'' . $setData['set_output_format'] . '\'' );
}
/**
* Fetch highest order
*
@@ -194,7 +222,7 @@ class skinFunctions
else
{
$REMAP = array();
require( DOC_IPS_ROOT_PATH . 'cache/skin_cache/masterMap.php' );
require( DOC_IPS_ROOT_PATH . 'cache/skin_cache/masterMap.php' );/*noLibHook*/
if ( is_array($REMAP) && count($REMAP) )
{
@@ -207,13 +235,14 @@ class skinFunctions
/**
* Returns a skin set ID based on a key
* @param string $key
* @param string $key
* @param boolean $ignoreMasterKeys
*/
public function fetchSetIdByKey( $key )
public function fetchSetIdByKey( $key, $ignoreMasterKeys=false )
{
$masterKeys = $this->fetchMasterKeys();
if ( in_array( $key, $masterKeys ) )
if ( in_array( $key, $masterKeys ) && $ignoreMasterKeys === false )
{
/* Default master keys are always 0 */
return 0;
@@ -253,6 +282,19 @@ class skinFunctions
return ( $this->_seenSet[ 'i-' . $id ]['set_key'] ) ? $this->_seenSet[ 'i-' . $id ]['set_key'] : 0;
}
/**
* Determine if the skin set is a "master" set
*
* @param mixed $id Skin set key or skin set id
* @return bool True if this is a master set, otherwise false
*/
public function isMasterSet( $id )
{
$key = is_numeric($id) ? $this->fetchSetKeyById( $id ) : $id;
return in_array( $key, $this->remapData['masterKeys'] );
}
/**
* Search template bits
*
@@ -418,7 +460,7 @@ class skinFunctions
* Reset error handle
*
* @access protected
* @return void
* @return @e void
*/
final protected function _resetErrorHandle()
{
@@ -428,9 +470,9 @@ class skinFunctions
/**
* Add an error message
*
* @access private
* @access protected
* @param string Error message to add
* @return void
* @return @e void
*/
final protected function _addErrorMessage( $error )
{
@@ -453,7 +495,7 @@ class skinFunctions
* Reset error handle
*
* @access protected
* @return void
* @return @e void
*/
final protected function _resetMessageHandle()
{
@@ -465,7 +507,7 @@ class skinFunctions
*
* @access protected
* @param string Error message to add
* @return void
* @return @e void
*/
final protected function _addMessage( $error )
{
@@ -489,7 +531,7 @@ class skinFunctions
*
* @access public
* @param string Name of skin file
* @return void Evals the skin to add the class in memory
* @return @e void Evals the skin to add the class in memory
*/
public function loadMasterSkinTemplate( $name, $id )
{
@@ -502,7 +544,7 @@ class skinFunctions
$_dir = $this->remapData['templates'][ $_id ];
if( ! file_exists(IPS_CACHE_PATH."cache/skin_cache/" . $_dir . "/".$name.".php") )
if( ! is_file(IPS_CACHE_PATH."cache/skin_cache/" . $_dir . "/".$name.".php") )
{
return;
}
@@ -526,9 +568,9 @@ class skinFunctions
eval($toeval);
$result = ob_get_contents();
ob_end_clean();
if ( strstr( $result, "Parse error" ) OR strstr( $result, 'Catchable fatal error:' ) OR $showme == $name )
{
{
IPSDebug::showTemplateError( $result, $toeval );
}
}
@@ -573,13 +615,14 @@ class skinFunctions
*
* @access public
* @param int Skin set ID
* @param bool Force, even if it is not removable
* @return boolean (True OK to remove, false NOT OK to remove)
*/
public function removeSet( $setID )
public function removeSet( $setID, $force=false )
{
$skinSetData = $this->fetchSkinData( $setID );
if ( $this->canRemoveSet( $setID ) !== TRUE )
if ( $force !== TRUE AND $this->canRemoveSet( $setID ) !== TRUE )
{
return FALSE;
}
@@ -612,10 +655,13 @@ class skinFunctions
$this->DB->delete( 'skin_url_mapping', 'map_skin_set_id=' . $setID );
/* Delete CSS Files */
$this->registry->adminFunctions->removeDirectory( DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_css/css_' . $setID );
$classToLoad = IPSLib::loadLibrary( IPS_KERNEL_PATH . '/classFileManagement.php', 'classFileManagement' );
$fileManagement = new $classToLoad();
$fileManagement->removeDirectory( DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_css/css_' . $setID );
/* Delete PHP Cache Files */
$this->registry->adminFunctions->removeDirectory( IPS_CACHE_PATH . 'cache/skin_cache/cacheid_' . $setID );
$fileManagement->removeDirectory( IPS_CACHE_PATH . 'cache/skin_cache/cacheid_' . $setID );
/* Delete any diff/merge sessions */
$this->DB->build( array( 'select' => '*',
@@ -630,7 +676,23 @@ class skinFunctions
$this->DB->delete('skin_merge_session', 'merge_id=' . $row['merge_id'] );
$this->DB->delete('skin_merge_changes', 'change_session_id=' . $row['merge_id'] );
}
/* Generator stuff */
$this->DB->build( array( 'select' => '*',
'from' => 'skin_generator_sessions',
'where' => 'sg_skin_set_id=' . $setID ) );
$o = $this->DB->execute();
while( $row = $this->DB->fetch( $o ) )
{
/* Delete 'em */
$this->DB->delete('skin_generator_sessions', 'sg_session_id=' . $row['sg_session_id'] );
IPSMember::save( $row['sg_member_id'], array( 'core' => array( 'bw_using_skin_gen' => 0 ) ) );
}
/* Rebuild Tree Information */
$this->rebuildTreeInformation();
@@ -868,8 +930,8 @@ class skinFunctions
//-----------------------------------------
$replacement = $this->DB->buildAndFetch( array( 'select' => '*',
'from' => 'skin_replacements',
'where' => 'replacement_id=' . $replacementID ) );
'from' => 'skin_replacements',
'where' => 'replacement_id=' . $replacementID ) );
if ( ! $replacement['replacement_id'] )
{
@@ -885,8 +947,8 @@ class skinFunctions
if ( $replacement['replacement_key'] != $replacement_key )
{
$replacementTest = $this->DB->buildAndFetch( array( 'select' => '*',
'from' => 'skin_replacements',
'where' => 'replacement_set_id=' . $setID . ' AND replacement_key=\'' . $replacement_key . '\'' ) );
'from' => 'skin_replacements',
'where' => 'replacement_set_id=' . $setID . ' AND replacement_key=\'' . $replacement_key . '\'' ) );
if ( $replacementTest['replacement_id'] )
{
@@ -1033,8 +1095,8 @@ class skinFunctions
//-----------------------------------------
$replacement = $this->DB->buildAndFetch( array( 'select' => '*',
'from' => 'skin_replacements',
'where' => 'replacement_id=' . $replacementID ) );
'from' => 'skin_replacements',
'where' => 'replacement_id=' . $replacementID ) );
if ( ! $replacement['replacement_id'] )
{
@@ -1123,7 +1185,8 @@ class skinFunctions
}
else
{
$skinSetData = $this->fetchSkinData( $setID );
$skinSetData = $this->fetchSkinData( $setID );
$skinSetData['_isMaster'] = $skinSetData['_isMaster'] ? $skinSetData['_isMaster'] : 0;
}
/* Did we get a skin set? */
@@ -1235,7 +1298,7 @@ class skinFunctions
$css['_actualSetID'] = $css['css_set_id'];
$css['_belongsSetID'] = $setID;
$css['_isMaster'] = ( $css['css_master_key'] ) ? true : false;
$css['_isMaster'] = ( $css['css_master_key'] ) ? 1 : 0;
//$css['_css_content'] = $css['css_content'];
//-----------------------------------------
@@ -1280,7 +1343,13 @@ class skinFunctions
$setID = intval( $setID );
$css_group = str_replace( '.css', '', IPSText::alphanumericalClean( $css_group ) );
$css_position = intval( $css_position );
/* Make sure skingen is always on top */
if ( $css_group != 'ipb_skingen' )
{
$css_position = ( $css_position >= 999 ) ? 998 : $css_position;
}
//-----------------------------------------
// Get skin data
//-----------------------------------------
@@ -1375,7 +1444,13 @@ class skinFunctions
$css_group = str_replace( '.css', '', IPSText::alphanumericalClean( $css_group ) );
$css_position = intval( $css_position );
$_goClean = 0;
/* Make sure skingen is always on top */
if ( $css_group != 'ipb_skingen' )
{
$css_position = ( $css_position >= 999 ) ? 998 : $css_position;
}
//-----------------------------------------
// Fetch template data
//-----------------------------------------
@@ -1579,7 +1654,7 @@ class skinFunctions
return $cssData;
}
/**
* Fetch Templates from the tree
*
@@ -1623,7 +1698,8 @@ class skinFunctions
}
else
{
$skinSetData = $this->fetchSkinData( $setID );
$skinSetData = $this->fetchSkinData( $setID );
$skinSetData['_isMaster'] = $skinSetData['_isMaster'] ? $skinSetData['_isMaster'] : 0;
}
/* Did we get a skin set? */
@@ -1848,7 +1924,7 @@ class skinFunctions
$template['_belongsSetID'] = $setID;
$template['_template_content'] = $template['template_content'];
$template['_template_data'] = $template['template_data'];
$template['_isMaster'] = ( $template['template_master_key'] ) ? true : false;
$template['_isMaster'] = ( $template['template_master_key'] ) ? 1 : 0;
//-----------------------------------------
// Update content for editing
@@ -2047,7 +2123,11 @@ class skinFunctions
//-----------------------------------------
// Same template set?
//-----------------------------------------
/* @todo - 'root' is almost certainly what we want but we *should* write a method that traverses up the tree
* from this set ID and looks for the master key of the root set. Especially important if we add any future
* output engines.
*/
$this->DB->insert( 'skin_templates', array( 'template_set_id' => 0,
'template_group' => $template_group,
'template_content' => $template_content,
@@ -2057,7 +2137,8 @@ class skinFunctions
'template_user_edited' => 1,
'template_user_added' => 1,
'template_removable' => 1,
'template_updated' => time() ) );
'template_updated' => time(),
'template_master_key' => 'root' ) );
$template_id_new = $this->DB->getInsertId();
@@ -2169,6 +2250,12 @@ class skinFunctions
# Update count
$this->_templateCount[ $setID ][ $template['template_group'] ]['count']++;
}
/* If this is a user-added template bit and we're editing it in the same skin, update master */
if ( $template['template_id'] && $template['template_user_added'] && $template['template_added_to'] == $setID )
{
$this->DB->update( 'skin_templates', array( 'template_content' => $template_content ), "template_set_id=0 AND template_group='" . $template['template_group'] . "' AND template_name='" . $template['template_name'] . "'" );
}
//-----------------------------------------
// Recache
@@ -2182,6 +2269,82 @@ class skinFunctions
return $template_id_new;
}
/**
* renames a template title
* @param int $templateId
* @param string $newName
*/
public function renameTemplateName( $templateId, $newName )
{
$template = $this->fetchTemplateBitForEdit( $templateId, 0 );
$skinSet = $this->fetchSkinData( $template['template_set_id'] );
$okToSave = true;
$masterKey = 'root';
$update = array( 'template_name' => $newName );
if ( ( $template['template_set_id'] == $template['template_added_to'] ) )
{
$masterTemplates = $this->fetchTemplates( $masterKey, 'allNoContent', $template['template_group'] );
if ( isset( $masterTemplates[ $template['template_group'] ][ $newName ] ) )
{
/* Added by webdav, now attempting to rename */
$update['template_added_to'] = 0;
$update['template_master_key'] = $masterKey;
}
}
if ( ! $template['template_id'] OR $template['_isMaster'] )
{
$okToSave = false;
}
if ( $okToSave )
{
$this->DB->update( 'skin_templates', $update, 'template_name=\'' . $this->DB->addSlashes( $template['template_name'] ) . '\' AND template_group=\'' . $this->DB->addSlashes( $template['template_group'] ) . '\'' );
}
/* rebuild */
$this->rebuildPHPTemplates( $template['template_set_id'], $template['template_group'] );
}
/**
* renames a css title
* @param int $cssId
* @param string $newName
*/
public function renameCssName( $cssId, $newName )
{
$template = $this->fetchCssForEdit( $cssId, 0 );
$okToSave = true;
$update = array( 'css_group' => $newName );
if ( ( $template['css_set_id'] == $template['css_added_to'] ) )
{
$masterCss = $this->fetchCSS( 'root', false );
if ( isset( $masterCss[ $newName ] ) )
{
/* Added by webdav, now attempting to rename */
$update['css_added_to'] = 0;
}
}
if ( ! $template['css_id'] OR $template['_isMaster'] )
{
$okToSave = false;
}
if ( $okToSave )
{
$this->DB->update( 'skin_css', $update, 'css_group=\'' . $this->DB->addSlashes( $template['css_group'] ) . '\'' );
}
/* rebuild */
$this->rebuildCSS( $template['css_set_id'] );
}
/**
* Fetch image directories from the file system
@@ -2304,7 +2467,7 @@ class skinFunctions
{
if ( @mkdir( DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_images/' . $dir ) )
{
@chmod( DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_images/' . $dir, 0777 );
@chmod( DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_images/' . $dir, IPS_FOLDER_PERMISSION );
return TRUE;
}
}
@@ -2357,13 +2520,13 @@ class skinFunctions
continue;
}
if( ! file_exists( $path . '/' . $_name . '/conf.php' ) )
if( ! is_file( $path . '/' . $_name . '/conf.php' ) )
{
continue;
}
$config = array();
require( $path . '/' . $_name . '/conf.php' );
require( $path . '/' . $_name . '/conf.php' );/*noLibHook*/
$formats[ $_name ] = $config;
}
@@ -2413,7 +2576,7 @@ class skinFunctions
foreach( $hooks as $tplHook )
{
/* Check for hook file */
if( file_exists( DOC_IPS_ROOT_PATH . 'hooks/' . $tplHook['filename'] ) )
if( is_file( IPS_HOOKS_PATH . $tplHook['filename'] ) )
{
$tplHook['_commentTag'] = $tplHook['type'] . '.' . $skinGroup . '.' . $tplHook['skinFunction'] . '.' . $tplHook['id'] . '.' . $tplHook['position'];
$myHooks[ $skinGroup ][] = $tplHook;
@@ -2550,19 +2713,19 @@ class skinFunctions
$setId = intval( $setId );
/* Templates */
if ( isset( $which['templates'] ) AND $which['templates'] )
if ( !empty( $which['templates'] ) )
{
$this->DB->delete( 'skin_templates', 'template_set_id=' . $setId );
}
/* CSS */
if ( isset( $which['css'] ) AND $which['css'] )
if ( !empty( $which['css'] ) )
{
$this->DB->delete( 'skin_css', 'css_set_id=' . $setId );
}
/* Replacements */
if ( isset( $which['replacements'] ) AND $which['replacements'] )
if ( !empty( $which['replacements'] ) )
{
$this->DB->delete( 'skin_replacements', 'replacement_set_id=' . $setId );
}
@@ -2675,13 +2838,13 @@ class skinFunctions
/* What to do? */
if ( $type == 'css' )
{
require_once( IPS_PUBLIC_PATH . 'min/lib/Minify/CSS/Compressor.php' );
require_once( IPS_PUBLIC_PATH . 'min/lib/Minify/CSS/Compressor.php' );/*noLibHook*/
$text = Minify_CSS_Compressor::process( $text );
}
else if ( $type == 'html' )
{
require_once( IPS_PUBLIC_PATH . 'min/lib/Minify/HTML.php' );
require_once( IPS_PUBLIC_PATH . 'min/lib/Minify/HTML.php' );/*noLibHook*/
$text = Minify_HTML::minify( $text, array( 'xhtml' => 1 ) );
}
@@ -2753,12 +2916,68 @@ class skinFunctions
$templates = $this->fetchTemplates( 0, 'groupTemplatesNoContent', $_group );
/* Clean out any template bits no longer part of this group */
$this->DB->delete( 'skin_templates', "template_group='" . $_group . "' AND " . $this->DB->buildLower('template_name') . " NOT IN ('" . implode( "','", array_keys( $templates ) ) . "')" );
$this->DB->delete( 'skin_templates', "template_group='" . $_group . "' AND template_user_added=0 AND " . $this->DB->buildLower('template_name') . " NOT IN ('" . implode( "','", array_keys( $templates ) ) . "')" );
$affected += intval( $this->DB->getAffectedRows() );
}
return array( 'cached' => intval( $cached ), 'templates' => intval( $affected ) );
}
/**
* Rebuilds the mobile user agents from the skin set data
*/
public function rebuildMobileSkinUserAgentsFromSetDataXml()
{
/* Init */
$mobileSkinSet = $this->fetchSkinData( $this->fetchSetIdByKey( 'mobile', true ), true );
$xmlData = array();
/* Grab xml */
require_once( IPS_KERNEL_PATH . 'classXML.php' );/*noLibHook*/
$xml = new classXML( 'UTF-8' );
/* Skin Set Data */
$xml->load( IPS_ROOT_PATH . 'setup/xml/skins/setsData.xml' );
foreach( $xml->fetchElements( 'set' ) as $xmlelement )
{
$data = $xml->fetchElementsFromRecord( $xmlelement );
if ( $data['set_key'] == 'mobile' )
{
$xmlData = $data;
break;
}
}
/* Update */
if ( $xmlData['set_key'] && IPSLib::isSerialized( $xmlData['set_locked_uagent'] ) && IPSLib::isSerialized( $mobileSkinSet['set_locked_uagent'] ) )
{
$new = unserialize( $xmlData['set_locked_uagent'] );
$old = unserialize( $mobileSkinSet['set_locked_uagent'] );
/* Merge them */
foreach( $new['groups'] as $group )
{
if ( ! in_array( $group, $old['groups'] ) )
{
$old['groups'][] = $group;
}
}
foreach( $new['uagents'] as $agent => $version )
{
if ( ! in_array( $agent, $new['uagents'] ) )
{
$old['uagents'][ $agent ] = $version;
}
}
}
if ( is_array( $old ) && count( $old ) )
{
$this->DB->update( 'skin_collections', array( 'set_locked_uagent' => serialize( $old ) ), "set_key='mobile'" );
}
}
}