Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

217 lines (181 sloc) 6.822 kb
<?php /*
ocPortal
Copyright (c) ocProducts, 2004-2012
See text/EN/licence.txt for full licencing information.
NOTE TO PROGRAMMERS:
Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
**** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****
*/
/**
* @license http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
* @copyright ocProducts Ltd
* @package core_themeing
*/
/**
* Delete a theme image.
*
* @param SHORT_TEXT The theme image ID
* @param ?ID_TEXT The theme to delete in (NULL: all themes)
* @param ?LANGUAGE_NAME The language to delete in (NULL: all languages) (blank: all languages)
*/
function actual_delete_theme_image($id,$theme=NULL,$lang=NULL)
{
if (!is_null($theme))
{
$old_url=find_theme_image($id,true,true,$theme,$lang);
$where_map=array('theme'=>$theme,'id'=>$id);
if (($lang!='') && (!is_null($lang))) $where_map['lang']=$lang;
$test=$GLOBALS['SITE_DB']->query_value_null_ok('theme_images','path',$where_map);
if (!is_null($test))
{
$GLOBALS['SITE_DB']->query_delete('theme_images',array('id'=>$id,'path'=>$test));
}
} else
{
$old_url=find_theme_image($id,true,true);
$GLOBALS['SITE_DB']->query_delete('theme_images',array('id'=>$id));
}
if ($old_url!='') cleanup_theme_images($old_url);
log_it('DELETE_THEME_IMAGE',$id);
}
/**
* Regenerate all the theme image paths in the database.
*
* @param ID_TEXT The theme we're searching in.
* @param ?array A map of languages (lang=>1) (NULL: find it in-function).
* @param ?ID_TEXT The theme we're storing in (NULL: same as $theme).
*/
function regen_theme_images($theme,$langs=NULL,$target_theme=NULL)
{
if (is_null($langs)) $langs=find_all_langs(true);
if (is_null($target_theme)) $target_theme=$theme;
$images=find_images_do_dir($theme,'images/',$langs);
foreach (array_keys($langs) as $lang)
{
$existing=$GLOBALS['SITE_DB']->query_select('theme_images',array('id'),array('lang'=>$lang,'theme'=>$target_theme));
foreach ($images as $id=>$path)
{
$found=false;
foreach ($existing as $e)
{
if ($e['id']==$id)
{
$found=true;
break;
}
}
if (!$found)
{
$nql_backup=$GLOBALS['NO_QUERY_LIMIT'];
$GLOBALS['NO_QUERY_LIMIT']=true;
$correct_path=find_theme_image($id,false,true,$theme,$lang);
$GLOBALS['SITE_DB']->query_insert('theme_images',array('id'=>$id,'lang'=>$lang,'theme'=>$target_theme,'path'=>$correct_path),false,true); // race conditions
$GLOBALS['NO_QUERY_LIMIT']=$nql_backup;
}
}
}
persistant_cache_delete('THEME_IMAGES');
}
/**
* Delete uploaded theme image if not tied into anything.
*
* @param URLPATH The URL to the theme image being deleted
*/
function cleanup_theme_images($old_url)
{
$files_referenced=collapse_1d_complexity('path',$GLOBALS['SITE_DB']->query_select('theme_images',array('DISTINCT path')));
$themes=find_all_themes();
foreach (array_keys($themes) as $theme)
{
$files_existing=get_image_paths(get_custom_base_url().'/themes/'.rawurlencode($theme).'/images_custom/',get_custom_file_base().'/themes/'.$theme.'/images_custom/');
foreach (array_keys($files_existing) as $path)
{
$path=str_replace(get_custom_file_base().'/','',filter_naughty($path));
$encoded_path=substr($path,0,strrpos($path,'/')+1).rawurlencode(substr($path,strrpos($path,'/')+1));
if ((!in_array($path,$files_referenced)) && (!in_array($encoded_path,$files_referenced)) && (($old_url==$path) || ($old_url==$encoded_path)))
{
@unlink(get_custom_file_base().'/'.$path);
sync_file($path);
}
}
}
}
/**
* Rename a theme.
*
* @param ID_TEXT The original theme name
* @param ID_TEXT The new theme name
*/
function actual_rename_theme($theme,$to)
{
if ($theme=='default') fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
if ((file_exists(get_custom_file_base().'/themes/'.$to)) || ($to=='default'))
{
warn_exit(do_lang_tempcode('ALREADY_EXISTS',escape_html($to)));
}
global $CACHED_THEME;
if ((!is_null($CACHED_THEME)) && ($CACHED_THEME==$theme)) $CACHED_THEME=$to;
require_code('abstract_file_manager');
force_have_afm_details();
afm_move('themes/'.$theme,'themes/'.$to);
$GLOBALS['SITE_DB']->query_update('theme_images',array('theme'=>$to),array('theme'=>$theme));
$theme_images=$GLOBALS['SITE_DB']->query('SELECT path FROM '.$GLOBALS['SITE_DB']->get_table_prefix().'theme_images WHERE path LIKE \'themes/'.db_encode_like($theme).'/%\'');
foreach ($theme_images as $image)
{
$new_path=str_replace('themes/'.$theme.'/','themes/'.$to.'/',$image['path']);
$GLOBALS['SITE_DB']->query_update('theme_images',array('path'=>$new_path),array('path'=>$image['path']),'',1);
}
if (get_forum_type()=='ocf') $GLOBALS['FORUM_DB']->query_update('f_members',array('m_theme'=>$to),array('m_theme'=>$theme));
$GLOBALS['SITE_DB']->query_update('zones',array('zone_theme'=>$to),array('zone_theme'=>$theme));
log_it('RENAME_THEME',$theme,$to);
}
/**
* Copy a theme.
*
* @param ID_TEXT The original theme name
* @param ID_TEXT The copy's theme name
*/
function actual_copy_theme($theme,$to)
{
if ($theme=='default') fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
if ((file_exists(get_custom_file_base().'/themes/'.$to)) || ($to=='default'))
{
warn_exit(do_lang_tempcode('ALREADY_EXISTS',escape_html($to)));
}
require_code('abstract_file_manager');
require_code('files2');
force_have_afm_details();
$contents=get_directory_contents(get_custom_file_base().'/themes/'.$theme,'',true);
foreach ($contents as $c)
{
afm_make_directory(dirname('themes/'.$to.'/'.$c),true,true);
afm_copy('themes/'.$theme.'/'.$c,'themes/'.$to.'/'.$c,true);
}
$needed=array('css','css_custom','images','images_custom','templates','templates_cached/'.get_site_default_lang(),'templates_custom');
foreach ($needed as $n)
afm_make_directory(dirname('themes/'.$to.'/'.$n),true,true);
$images=$GLOBALS['SITE_DB']->query_select('theme_images',array('*'),array('theme'=>$theme));
foreach ($images as $i)
{
$i['theme']=$to;
$i['path']=str_replace('themes/'.$theme.'/','themes/'.$to.'/',$i['path']);
$GLOBALS['SITE_DB']->query_insert('theme_images',$i);
}
log_it('COPY_THEME',$theme,$to);
}
/**
* Delete a theme.
*
* @param ID_TEXT The theme name
*/
function actual_delete_theme($theme)
{
if ($theme=='default') fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
global $CACHED_THEME;
if ((!is_null($CACHED_THEME)) && ($CACHED_THEME==$theme)) $CACHED_THEME='default';
require_code('abstract_file_manager');
force_have_afm_details();
afm_delete_directory('themes/'.$theme,true);
$GLOBALS['SITE_DB']->query_delete('theme_images',array('theme'=>$theme));
log_it('DELETE_THEME',$theme);
}
Jump to Line
Something went wrong with that request. Please try again.