Now regenerate template.sql, using something like '.escape_html($cmd).' > ~/public_html/uploads/website_specific/ocportal.com/myocp/template.sql

'; up_do_footer(); return; } } $show_more_link=true; switch ($type) { case 'misc': clear_caches_1(); $l_choices=do_lang('FU_CHOICES'); $oc=(get_option('site_closed')=='0')?do_lang('SITE_OPEN'):do_lang('SITE_CLOSED'); $a=float_to_raw_string(ocp_version_number(),10,true); $b=get_value('version'); $b=float_to_raw_string(floatval($b),10,true); // Normalise decimal places $l_up_info=do_lang('FU_UP_INFO'.(($a==$b)?'_1':'_2'),$a,$b); $l_fu_closedness=do_lang('FU_CLOSENESS',$oc); $l_maintenance=do_lang('FU_MAINTENANCE'); $l_upgrading=do_lang('FU_UPGRADING'); $l_take_backup=do_lang('FU_TAKE_BACKUP'); $l_clear_caches=fu_link('upgrader.php?type=decache',do_lang('FU_CLEAR_CACHES')); $l_check_permissions=fu_link('upgrader.php?type=check_perms',do_lang('FU_CHECK_PERMISSIONS')); $l_fix_permissions=fu_link('upgrader.php?type=fix_perms',do_lang('FU_FIX_PERMISSIONS')); $l_close_site=fu_link('upgrader.php?type=close_site',do_lang('FU_CLOSE_SITE'),get_option('site_closed')=='1'); $l_integrity_scan=fu_link('upgrader.php?type=integrity_scan&allow_merging=1',do_lang('FU_INTEGRITY_SCAN'),false,do_lang('FU_WILL_MERGE')); $l_integrity_scan_no_merging=fu_link('upgrader.php?type=integrity_scan',do_lang('FU_INTEGRITY_SCAN_NO_CSS_MERGE')); $l_database_upgrade=fu_link('upgrader.php?type=db_upgrade',do_lang('FU_DATABASE_UPGRADE')); $l_theme_upgrade=fu_link('upgrader.php?type=theme_upgrade',do_lang('FU_THEME_UPGRADE')); $l_open_site=fu_link('upgrader.php?type=open_site',do_lang('FU_OPEN_SITE'),get_option('site_closed')=='0'); $l_error_correction=do_lang('FU_ERROR_CORRECTION'); $l_not_for_patch=do_lang('FU_NOT_FOR_PATCH'); $l_tutorial=fu_link('http://ocportal.com/docs/tut_upgrade.htm',do_lang('FU_TUTORIAL')); $l_release_notes=do_lang('FU_RELEASE_NOTES'); $l_refer_release_notes=do_lang('FU_REFER_RELEASE_NOTES'); $news_id=post_param_integer('news_id',NULL); $tar_url=''; if (!is_null($news_id)) { require_code('files'); $fetch_url='http://ocportal.com/uploads/website_specific/ocportal.com/scripts/fetch_release_details.php?news_id='.strval($news_id).'&from_version='.urlencode(strval(ocp_version()).'.'.ocp_version_minor()); $news=http_download_file($fetch_url,NULL,true,false,'ocPortal',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,30.0); $details=unserialize($news); if ($details[0]!='') $l_refer_release_notes=$details[0].'
'.$details[2].'
'; $tar_url=$details[1]; } $l_download=fu_link('upgrader.php?type=file_upgrade&tar_url='.urlencode(base64_encode($tar_url)),do_lang('FU_DOWNLOAD')); $l_important=do_lang('IMPORTANT'); $l_bugs=do_lang('FU_BUGS'); $l_upgrade_steps=do_lang('FU_UPGRADE_STEPS'); $l_action=do_lang('ACTION'); $l_step=do_lang('FU_STEP'); $l_estimated_time=do_lang('FU_ESTIMATED_TIME'); $l_safe_mode=fu_link('index.php?keep_safe_mode=1',do_lang('FU_SAFE_MODE')); $num_addons=$GLOBALS['SITE_DB']->query_value('addons','COUNT(*)'); $l_addon_management=fu_link('adminzone/index.php?page=admin_addons&keep_safe_mode=1',do_lang('FU_ADDON_MANAGEMENT',integer_format($num_addons)),$num_addons==0); $l_customisations=do_lang('FU_CUSTOMISATIONS'); $closed=comcode_to_tempcode(get_option('closed'),NULL,true); $closed_url=build_url(array('page'=>'admin_config','type'=>'category','id'=>'SITE'),get_module_zone('admin_config'),NULL,false,false,false,'group_CLOSED_SITE'); $l_columned_table=do_lang('COLUMNED_TABLE'); echo "

{$l_choices}

{$l_maintenance}…

{$l_upgrading}…

{$l_important}

{$l_bugs}

{$l_release_notes}

{$l_refer_release_notes}

{$l_upgrade_steps}

{$l_step} {$l_action} {$l_estimated_time}
X{$l_not_for_patch} {$l_tutorial}".escape_html(display_time_period(60*120))."
1{$l_take_backup}".escape_html(display_time_period(60*120))."
2{$l_close_site} {$l_fu_closedness}
".$closed->evaluate()." [evaluate())."\" title=\"(this link will open in a new window)\" target=\"_blank\">".do_lang('CHANGE')."]
".escape_html(display_time_period(60))."
3{$l_download}".escape_html(display_time_period(60*5))."
4{$l_not_for_patch} {$l_integrity_scan_no_merging}".str_replace(' ',' ',escape_html(display_time_period(60*10)))." †
5{$l_not_for_patch} {$l_database_upgrade}
{$l_up_info}
".escape_html(display_time_period(60*5))."
6{$l_not_for_patch} {$l_theme_upgrade}".escape_html(display_time_period(60*5))."
7{$l_clear_caches}1 minute
8{$l_open_site} {$l_fu_closedness}1 minute

† {$l_customisations}

{$l_error_correction}…

"; $show_more_link=false; break; case 'decache': clear_caches_2(); echo '

'.do_lang('SUCCESS').'

'; break; case 'check_perms': echo check_perms(); break; case 'fix_perms': echo fix_perms(); break; case 'open_site': set_option('site_closed','0'); echo '

'.do_lang('SUCCESS').'

'; break; case 'close_site': set_option('closed',do_lang('FU_CLOSED_FOR_UPGRADES',get_site_name())); set_option('site_closed','1'); echo '

'.do_lang('SUCCESS').'

'; break; case 'file_upgrade': require_code('version2'); $personal_upgrader_url='http://compo.sr/uploads/website_specific/compo.sr/scripts/build_personal_upgrader.php?from='.urlencode(get_version_dotted()); $hooks=find_all_hooks('systems','addon_registry'); foreach (array_keys($hooks) as $hook) { if (is_file(get_file_base().'/sources/hooks/systems/addon_registry/'.$hook.'.php')) { $personal_upgrader_url.='&addon_'.$hook.'=1'; } } if (get_param('tar_url','')=='') echo do_lang('FU_FILE_UPGRADE_INFO'); echo do_lang('FU_FILE_UPGRADE_INFO_MANUAL',escape_html($personal_upgrader_url)); echo '
'.post_fields_relay(); echo ' '; if ((ocp_srv('HTTP_HOST')=='ocportal.com') || ($GLOBALS['DEV_MODE'])) // for ocProducts to use on own site, for testing { echo '
'; } echo ''; echo '
'; $show_more_link=false; break; case '_file_upgrade': require_code('tar'); if (function_exists('set_time_limit')) @set_time_limit(0); if ((post_param('url','')=='') && ((ocp_srv('HTTP_HOST')=='ocportal.com') || ($GLOBALS['DEV_MODE']))) { $temp_path=$_FILES['upload']['tmp_name']; } else { if (post_param('url','')=='') warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); $temp_path=ocp_tempnam('ocpfu'); $url=post_param('url'); if (substr($url,0,strlen(get_base_url().'/'))==get_base_url().'/') { unlink($temp_path); copy(get_custom_file_base().'/'.rawurldecode(substr($url,strlen(get_base_url().'/'))),$temp_path); } else { $myfile=fopen($temp_path,'wb'); http_download_file($url,NULL,true,false,'ocPortal',NULL,NULL,NULL,NULL,NULL,$myfile); fclose($myfile); } } $upgrade_resource=tar_open($temp_path,'rb'); //tar_extract_to_folder($upgrade_resource,'',true); disable_php_memory_limit(); $directory=tar_get_directory($upgrade_resource); // Uses up to around 5MB $data=array('todo'=>array()); $popup_simple_extract=(_ftp_info()===false); if (!$popup_simple_extract) echo '

'.do_lang('EXTRACTING_MESSAGE').'

'; $addon_contents=array(); // Find addons foreach ($directory as $upgrade_file2) { // See if we can find an addon registry file in our upgrade TAR if ((strpos($upgrade_file2['path'],'/addon_registry/')!==false) && (substr($upgrade_file2['path'],-4)=='.php')) { $file_data=tar_get_file($upgrade_resource,$upgrade_file2['path']); $addon_contents[basename($upgrade_file2['path'],'.php')]=$file_data['data']; } } // Process files foreach ($directory as $offset=>$upgrade_file) { // skip over these, from manually installer package (which may be used for an upgrade) if ($upgrade_file['path']=='info.php') continue; if ($upgrade_file['path']=='install.php') continue; if ($upgrade_file['path']=='install.sql') continue; if ($upgrade_file['path']=='info.php.template') continue; if (!$popup_simple_extract) { // See if we can skip the file, if the on-disk version is identical? if ((file_exists(get_file_base().'/'.$upgrade_file['path'])) && (filesize(get_file_base().'/'.$upgrade_file['path'])==$upgrade_file['size'])) { $tar_data=tar_get_file($upgrade_resource,$upgrade_file['path']); if (file_get_contents(get_file_base().'/'.$upgrade_file['path'])==$tar_data['data']) { echo do_lang('U_SKIPPING_MESSAGE',escape_html($upgrade_file['path'])).'
'; continue; } } } // Addon registry file, for installed addon if ((strpos($upgrade_file['path'],'/addon_registry/')!==false) && (file_exists(get_file_base().'/'.$upgrade_file['path']))) { if (substr($upgrade_file['path'],-1)!='/') { if ($popup_simple_extract) { $data['todo'][]=array($upgrade_file['path'],$upgrade_file['mtime'],$offset+512,$upgrade_file['size'],($upgrade_file['mode'] & 0002)!=0); } else { $file_data=tar_get_file($upgrade_resource,$upgrade_file['path']); afm_make_file($upgrade_file['path'],$file_data['data'],($file_data['mode'] & 0002)!=0); echo do_lang('U_EXTRACTING_MESSAGE',escape_html($upgrade_file['path'])).'
'; } } } else { // Some other file $found=NULL; if (substr($upgrade_file['path'],-1)!='/') { foreach ($addon_contents as $addon_name=>$addon_data) { // See if this is the addon for the file $shortened_path=$upgrade_file['path']; $shortened_path=preg_replace('#^themes/default/(templates|css)/#','',$shortened_path); if (strpos($addon_data,'\''.addslashes($shortened_path).'\'')!==false) { $found=$addon_name; break; } } } // Install if either of the following is true: // - it's some file not in any addon (shouldn't actually happen) // - it's a new addon (addon that is not installed or uninstalled i.e. does not have an import-ready addon file [created at uninstallation], and not showing up as uninstalled in log) // - it's a file in an addon we have installed if ((is_null($found)) || ((!file_exists(get_file_base().'/imports/addons/'.$found.'.tar')) && (is_null($GLOBALS['SITE_DB']->query_value_null_ok('adminlogs','id',array('the_type'=>'UNINSTALL_ADDON','param_a'=>$found))))) || (file_exists(get_file_base().'/sources/hooks/systems/addon_registry/'.$found.'.php'))) { if (substr($upgrade_file['path'],-1)=='/') { afm_make_directory($upgrade_file['path'],false,true); } else { if ($popup_simple_extract) { $data['todo'][]=array($upgrade_file['path'],$upgrade_file['mtime'],$offset+512,$upgrade_file['size'],($upgrade_file['mode'] & 0002)!=0); } else { $file_data=tar_get_file($upgrade_resource,$upgrade_file['path']); if (!file_exists(get_file_base().'/'.dirname($upgrade_file['path']))) afm_make_directory(dirname($upgrade_file['path']),false,true); afm_make_file($upgrade_file['path'],$file_data['data'],($file_data['mode'] & 0002)!=0); echo do_lang('U_EXTRACTING_MESSAGE',escape_html($upgrade_file['path'])).'
'; } } } if (substr($upgrade_file['path'],-1)!='/') { // If true: We need to copy it into our archived addon so that addon is kept up-to-date if ((!is_null($found)) && (file_exists(get_file_base().'/imports/addons/'.$found.'.tar'))) { $old_mod_file=tar_open(get_file_base().'/imports/addons/'.$found.'.tar','rb'); $directory2=tar_get_directory($old_mod_file,true); if (!is_null($directory2)) { $old_file_data=tar_get_file($old_mod_file,$upgrade_file['path']); $file_data=tar_get_file($upgrade_resource,$upgrade_file['path']); if (($old_file_data!==NULL) && ($old_file_data['data']==$file_data['data'])) { // No change needed, maybe already packed continue; } $new_mod_file=tar_open(get_file_base().'/imports/addons/'.$found.'.new.tar','wb'); foreach ($directory2 as $d) { if ($d['path']==$upgrade_file['path']) continue; $file_data=tar_get_file($old_mod_file,$d['path']); if ($d['path']=='mod.inf') { $file_data['data']=preg_replace('#^version=.*#m','version=(version-synched)',$file_data['data']); } tar_add_file($new_mod_file,$d['path'],$file_data['data'],$d['mode'],$d['mtime']); } $file_data=tar_get_file($upgrade_resource,$upgrade_file['path']); tar_add_file($new_mod_file,$upgrade_file['path'],$file_data['data'],$upgrade_file['mode'],$upgrade_file['mtime']); tar_close($new_mod_file); tar_close($old_mod_file); unlink(get_file_base().'/imports/addons/'.$found.'.tar'); rename(get_file_base().'/imports/addons/'.$found.'.new.tar',get_file_base().'/imports/addons/'.$found.'.tar'); echo do_lang('U_PACKING_MESSAGE',escape_html($upgrade_file['path'])).'
'; } } } } } tar_close($upgrade_resource); if ($popup_simple_extract) { @unlink(get_custom_file_base().'/data_custom/upgrader.tar.tmp'); @unlink(get_custom_file_base().'/data_custom/upgrader.tmp'); $test=@copy($temp_path,get_custom_file_base().'/data_custom/upgrader.tar.tmp'); if ($test===false) fatal_exit(do_lang_tempcode('FU_FTP_NEEDED')); @unlink($temp_path); $temp_path=get_custom_file_base().'/data_custom/upgrader.tar.tmp'; $tmp_data_path=get_custom_file_base().'/data_custom/upgrader.tmp'; $tmp_data_file=fopen($tmp_data_path,'wb'); fwrite($tmp_data_file,serialize($data)); fclose($tmp_data_file); global $SITE_INFO; $extract_url=get_base_url().'/data/upgrader2.php?hashed_password='.urlencode($SITE_INFO['admin_password']).'&tmp_path='.urlencode($temp_path).'&file_offset=0&tmp_data_path='.urlencode($tmp_data_path).'&done='.urlencode(do_lang('DONE')); echo '

'.do_lang('FU_EXTRACTING_WINDOW',integer_format(count($data['todo']))).'

'; echo ''; } else { echo '

'.do_lang('SUCCESS').'

'; @unlink($temp_path); } unset($_POST['news_id']); break; case 'integrity_scan': $allow_merging=either_param_integer('allow_merging',0); echo run_integrity_check(false,$allow_merging==1); break; case '_integrity_scan': _integrity_scan(); echo '

'.do_lang('SUCCESS').'

'; break; case 'db_upgrade': $something_done=false; clear_caches_2(); if (version_specific()) { echo do_lang('FU_UPGRADED_CORE_TABLES'); $something_done=true; } $done=upgrade_modules(); if ($done!='') { echo do_lang('FU_UPGRADE_MODULES',$done); $something_done=true; } if (!$something_done) echo do_lang('NO_UPGRADE_DONE'); $version_files=ocp_version_number(); $_version_database=get_value('ocf_version'); $version_database=floatval($_version_database); if (is_null($_version_database)) $version_database=2.1; // Either 2.0 or 2.1, and they are equivalent in terms of what we need to do if ($version_database<$version_files) echo do_lang('FU_MUST_UPGRADE_OCF',fu_link('upgrader.php?type=ocf',do_lang('FU_UPGRADE_OCF'))); break; case 'theme_upgrade': echo upgrade_themes(); break; case 'ocf': // Only to be launched as a consequent of db_upgrade if (ocf_upgrade()) echo '

'.do_lang('SUCCESS').'

'; else echo do_lang('FU_NO_OCF_UPGRADE'); break; } if ($show_more_link) { echo '
'.fu_link('upgrader.php?type=misc',do_lang('MORE_OPTIONS')).'
'; } } else { up_do_header(); up_do_login(do_lang('USER_BAD_PASSWORD')); } } else { up_do_header(); up_do_login(); } up_do_footer(); } /** * Get hidden form fields for relaying POST information. * * @return string The hidden form fields for relaying POST information. */ function post_fields_relay() { $hidden=''; foreach (array_keys($_POST) as $key) { $hidden.=''; } return $hidden; } /** * Generate a form-based link to relay POST information to a URL. * * @param string The URL (something like 'upgrader.php?type=ocf') * @param string The URL caption text * @param boolean Whether it is disabled * @param string Extra Javascript * @return string The form-based link */ function fu_link($url,$text,$disabled=false,$js='') { $hidden=(strpos($url,'http://ocportal.com')!==false)?'':post_fields_relay(); if (get_param_integer('keep_safe_mode',0)==1) $url.='&keep_safe_mode=1'; if (get_param_integer('keep_show_loading',0)==1) $url.='&keep_show_loading=1'; return '
'.$hidden.'
'; } /** * Output a login page. * * @param ?string Error message (NULL: none) */ function up_do_login($message=NULL) { $type=get_param('type','misc'); global $SITE_INFO; $ftp_username=get_value('ftp_username'); $ftp_folder=get_value('ftp_directory'); $ftp_domain=get_value('ftp_domain'); if (is_null($ftp_domain)) $ftp_domain=array_key_exists('ftp_domain',$SITE_INFO)?$SITE_INFO['ftp_domain']:'localhost'; if (is_null($ftp_username)) { if (!array_key_exists('ftp_username',$SITE_INFO)) { if ((function_exists('posix_getpwuid')) && (strpos(@ini_get('disable_functions'),'posix_getpwuid')===false)) { $u_info=posix_getpwuid(fileowner(get_file_base().'/index.php')); $ftp_username=$u_info['name']; } else $ftp_username=''; if (is_null($ftp_username)) $ftp_username=''; } else $ftp_username=$SITE_INFO['ftp_username']; } if (is_null($ftp_folder)) { if (!array_key_exists('ftp_folder',$SITE_INFO)) { $dr=array_key_exists('DOCUMENT_ROOT',$_SERVER)?$_SERVER['DOCUMENT_ROOT']:(array_key_exists('DOCUMENT_ROOT',$_ENV)?$_ENV['DOCUMENT_ROOT']:''); if (strpos($dr,'/')!==false) $dr_parts=explode('/',$dr); else $dr_parts=explode('\\',$dr); $webdir_stub=$dr_parts[count($dr_parts)-1]; $pos=strpos($_SERVER['PHP_SELF'],'upgrader.php'); if ($pos===false) $pos=strlen($_SERVER['PHP_SELF']); else $pos--; $ftp_folder='/'.$webdir_stub.substr($_SERVER['PHP_SELF'],0,$pos); } else $ftp_folder=$SITE_INFO['ftp_folder']; } require_lang('installer'); $l_password=do_lang('MASTER_PASSWORD'); $l_ftp_info=do_lang('FU_FTP_INFO'); $l_ftp_domain=do_lang('FTP_DOMAIN'); $l_ftp_directory=do_lang('FTP_DIRECTORY'); $l_ftp_username=do_lang('FTP_USERNAME'); $l_ftp_password=do_lang('FTP_PASSWORD'); $l_login=do_lang('_LOGIN'); $l_login_info=do_lang('FU_LOGIN_INFO'); $l_login_info_pass_forget=do_lang('FU_LOGIN_INFO_PASS_FORGET'); $l_login_forgot_password_q=do_lang('FU_LOGIN_FORGOT_PASSWORD_Q'); if (!is_null($message)) echo '

'.$message.'

'; $news_id=get_param_integer('news_id',NULL); $url="upgrader.php?type=".escape_html($type); if (get_param_integer('keep_safe_mode',0)==1) $url.='&keep_safe_mode=1'; if (get_param_integer('keep_show_loading',0)==1) $url.='&keep_show_loading=1'; echo "

{$l_login_info}

".(is_null($news_id)?'':(''))."

{$l_password}:

"; require_code('files'); if ((is_suexec_like()) || ((!function_exists('ftp_ssl_connect')) && (!function_exists('ftp_connect')))) { } else { echo "
{$l_ftp_info}
{$l_ftp_domain}:
{$l_ftp_directory}:
{$l_ftp_username}:
{$l_ftp_password}:

"; } echo "

"; echo "

{$l_login_forgot_password_q}

{$l_login_info_pass_forget}

"; } /** * Output the upgrader page header. */ function up_do_header() { $upgrader_title=do_lang('FU_UPGRADER_TITLE'); $upgrader_intro=do_lang('FU_UPGRADER_INTRO'); $charset=get_charset(); $lang=user_lang(); $dir=do_lang('dir'); @ob_end_clean(); echo << {$upgrader_title}

{$upgrader_title}

{$upgrader_intro}


END; } /** * Output the upgrader page footer. */ function up_do_footer() { echo << END; } /** * Clear many caches. */ function clear_caches_1() // These have to happen early - to prevent things that could kill the update process { require_code('view_modes'); erase_cached_templates(); erase_cached_language(); } /** * Clear more caches. This is intentionally done after db upgrading. */ function clear_caches_2() { require_code('view_modes'); require_code('zones2'); require_code('zones3'); erase_comcode_cache(); erase_tempcode_cache(); erase_comcode_page_cache(); persistent_cache_empty(); } /** * Find extra directories to chmod * * @return array Extra directories to chmod */ function get_chmod_array_2() { $hooks=find_all_hooks('systems','chmod'); $directories=array(); foreach (array_keys($hooks) as $hook) { require_code('hooks/systems/chmod/'.filter_naughty_harsh($hook)); $ob=object_factory('Hook_chmod_'.filter_naughty_harsh($hook),true); if (is_null($ob)) continue; $directories=array_merge($directories,$ob->run()); } return $directories; } /** * Do permission checking * * @return string Output messages */ function check_perms() { require_code('inst_special'); $super_out=''; global $LANG; $LANG='EN'; // Make it simple if (array_key_exists('lang',$_GET)) $LANG=$_GET['lang']; if (preg_match('#\w+#A',$LANG)==0) return ''; $array=array_merge(get_chmod_array(),get_chmod_array_2()); require_code('themes2'); $themes=find_all_themes(); $out=''; for ($i=0;$i'.escape_html($_chmod).'').''; } } else {*/ if (!file_exists(get_file_base().'/'.$chmod)) continue; if (!is_writable_wrap(get_file_base().'/'.$chmod)) $out.='
  • '.do_lang('FU_NEEDS_CHMOD',''.escape_html($chmod).'').'
  • '; //} } $out.=check_excess_perms($array); if ($out=='') { $super_out=do_lang('FU_ALL_CHMODDED_GOOD'); } else { $super_out=do_lang('WARNING_FILE_CHMOD',$out); } return $super_out; } /** * Do permission setting * * @return string Output messages */ function fix_perms() { require_code('inst_special'); $super_out=''; global $LANG; $LANG=get_param('lang','EN'); $array=array_merge(get_chmod_array(),get_chmod_array_2()); require_code('themes2'); $themes=find_all_themes(); $GLOBALS['SUPPRESS_ERROR_DEATH']=true; for ($i=0;$ievaluate(); $super_out.='

    '.$error.'

    '; } $super_out.='

    '.do_lang('SUCCESS').'

    '; $GLOBALS['SUPPRESS_ERROR_DEATH']=false; return $super_out; } /** * Tell the user about any modules that need moving again (because the ocp ones haven't moved). * * @return array Pair: HTML list of moved files, raw list */ function move_modules() { $out=''; $outr=array(); $zones=find_all_zones(); foreach ($zones as $zone) { $pages=find_all_pages($zone,'modules'); foreach (array_keys($pages) as $page) { // See if this isn't the true home of the module foreach ($zones as $zone2) { $_path_a=$zone2.'/pages/modules/'.$page.'.php'; // potential true home $_path_b=$zone.'/pages/modules/'.$page.'.php'; // where it is now $path_a=zone_black_magic_filterer(get_file_base().'/'.$_path_a); $path_b=zone_black_magic_filterer(get_file_base().'/'.$_path_b); if (($zone2!=$zone) && (file_exists($path_a)) && (filemtime($path_a)>=filemtime($path_b))) { if (($page=='filedump') && ($zone2=='cms')) continue; // This has moved between versions $out.='
  • '.do_lang('FILE_MOVED',''.escape_html($page).'',''.escape_html($zone2).'',''.escape_html($zone).'').'
  • '; $outr[]=$path_b; } } } } return array($out,$outr); } /** * Find any excess permissions * * @param array Permissions that DO need to be set * @param string Where we are searching under * @return string Messages */ function check_excess_perms($array,$rel='') { $out=''; $dir=get_file_base().'/'.$rel.'/'; $dh=@opendir($dir); if ($dh!==false) { while (($file=readdir($dh))!==false) { if (($file=='.') || ($file=='..')) continue; $is_dir=@is_dir($dir.$file); if ((should_ignore_file($dir.$file,IGNORE_ACCESS_CONTROLLERS | IGNORE_NONBUNDLED_SCATTERED)) && ($is_dir)) continue; $relpath=$rel.(($rel=='')?'':'/').$file; $ok=(in_array($relpath,$array)) || (in_array(preg_replace('#^[^/]+/#','site/',$relpath),$array)) || (in_array(preg_replace('#^themes/[^/]+/#','themes/default/',$relpath),$array)); if ((is_writable_wrap($dir.$file)) && ((!function_exists('posix_getuid')) || (fileowner($dir.$file)!=posix_getuid()))) { if (!$ok) { $out.='
  • '.do_lang('FU_NEEDS_UNCHMOD',''.escape_html($rel.(($rel=='')?'':'/').$file)).'
  • '; } } if (($is_dir) && (!$ok)) $out.=check_excess_perms($array,escape_html($rel.(($rel=='')?'':'/').$file)); } } return $out; } /** * Do an integrity check. This does not include an alien check in basic mode; otherwise check_alien() is called within this function. * * @param boolean Whether to just do the minimum basic scan. * @param boolean Whether merging of CSS changes is allowed. * @param boolean Whether to give some help to unix people. * @return string Results. */ function run_integrity_check($basic=false,$allow_merging=true,$unix_help=false) { $ret_str=''; // We'll need to know about stuff in our addon registry, and file manifest if (function_exists('find_all_hooks')) { $hooks=find_all_hooks('systems','addon_registry'); } else { $hooks=array(); $dir=get_file_base().'/sources/hooks/systems/addon_registry'; $dh=@opendir($dir); if ($dh!==false) { while (($file=readdir($dh))!==false) { if ((substr($file,-4)=='.php') && (preg_match('#^[\w\-]*$#',substr($file,0,strlen($file)-4))!=0)) { $hooks[substr($file,0,strlen($file)-4)]='sources'; } } closedir($dh); } } $master_data=@unserialize(file_get_contents(get_file_base().'/data/files.dat')); if ($master_data===false) $master_data=array(); $hook_keys=array_keys($hooks); $hook_files=array(); foreach ($hook_keys as $hook) { if (!isset($master_data['sources/hooks/systems/addon_registry/'.filter_naughty_harsh($hook).'.php'])) continue; // Old addon $path=get_custom_file_base().'/sources/hooks/systems/addon_registry/'.filter_naughty_harsh($hook).'.php'; if (!file_exists($path)) { $path=get_file_base().'/sources/hooks/systems/addon_registry/'.filter_naughty_harsh($hook).'.php'; } $hook_files[$hook]=file_get_contents($path); } unset($hook_keys); // Moved module handling if ($basic) { $not_missing=array(); } else { $hidden=post_fields_relay(); $ret_str.='
    '.$hidden; list($moved,$not_missing)=move_modules(); if ($moved!='') { $ret_str.=do_lang('WARNING_MOVED_MODULES',$moved); } } // Override handling list($outdated__outdated_original_and_override,$outdated__possibly_outdated_override,$outdated__missing_original_but_has_override,$outdated__uninstalled_addon_but_has_override)=check_outdated__handle_overrides(get_file_base().'/','',$master_data,$hook_files,$allow_merging); // Look for missing files, wrt bundled addons $outdated__outdated_original=''; $outdated__missing_file_entirely=''; $outdated__future_files=''; $files_determined_to_upload=array(); $files_to_check=array(); foreach ($hook_files as $addon_name=>$hook_file) { $matches=array(); if (preg_match('#function get_file_list\(\)\s*\{([^\}]*)\}#',$hook_file,$matches)!=0) { if (!defined('HIPHOP_PHP')) { $files_to_check=array_merge($files_to_check,eval($matches[1])); } else { require_code('hooks/systems/addon_registry/'.$addon_name); $hook=object_factory('Hook_addon_registry_'.$addon_name); $files_to_check=array_merge($files_to_check,$hook->get_file_list()); } } } unset($hook_files); sort($files_to_check); foreach ($files_to_check as $file) { if (($basic) && (time()-$_SERVER['REQUEST_TIME']>5)) return ''; // Taking too long if (should_ignore_file($file,IGNORE_BUNDLED_VOLATILE | IGNORE_NONBUNDLED_SCATTERED)) continue; if (preg_match('#^[^/]+\.tpl$#',$file)!=0) $real_file='themes/default/templates/'.$file; elseif (preg_match('#^[^/]+\.css$#',$file)!=0) $real_file='themes/default/css/'.$file; else $real_file=$file; if ((!isset($master_data[$real_file])) && (strpos($real_file,'_custom')!==false)) continue; // These won't be in the manifest if ($file=='data/files.dat') continue; // Can't check integrity against self! if ($file=='data/files_previous.dat') continue; // Comes in outside scope of files.dat if (($file=='recommended.htaccess') || ($file=='plain.htaccess')) continue; // May be renamed $file_info=@$master_data[$real_file]; if (!file_exists(get_file_base().'/'.$real_file)) { if (!in_array(get_file_base().'/'.$real_file,$not_missing)) { $outdated__missing_file_entirely.='
  • '.escape_html($real_file).'
  • '; $files_determined_to_upload[]=$real_file; } } elseif (!is_null($file_info)) { if (@filesize(get_file_base().'/'.$real_file)>1024*1024) continue; // Too big, so special exception $file_contents=@file_get_contents(get_file_base().'/'.$real_file); if ($file_contents===false) continue; if (strpos($real_file,'/version.php')!==false) $file_contents=preg_replace('/\d{10}/','',$file_contents); $true_hash=sprintf('%u',crc32(preg_replace('#[\r\n\t ]#','',$file_contents))); if ($true_hash!=$file_info[0]) { if (filemtime(get_file_base().'/'.$real_file)'; // [disk-hash: '.$true_hash.', required-hash: '.$file_info[0].'] $files_determined_to_upload[]=$real_file; } else { $outdated__future_files.='
  • '.escape_html($real_file).'
  • '; } } } } // Output integrity check results if ($outdated__possibly_outdated_override!='') { if ($basic) { $ret_str.='

    The following files have been superseded by new versions, but you have overrides/customisations blocking the new versions. Look into this and consider reincorporating your changes into our new version. If this is not done, bugs (potentially security holes) may occur, or be left unfixed. If you edited using an inbuilt editor, the file on which you based it will be saved as file.editfrom: you may use a tool such as WinMerge to compare the editfrom file to your own, and then apply those same changes to the latest version of the file.

      '.$outdated__possibly_outdated_override.'
    '; } else { $ret_str.=do_lang('WARNING_FILE_OUTDATED',$outdated__possibly_outdated_override); } } if ($outdated__outdated_original_and_override!='') { if ($basic) { $ret_str.='

    The following non-overridden files are outdated, as are the corresponding overridden files (you can find the correct versions for the original in the manual installer ZIP for the version you\'re running, but the overrides may still cause problems and might need removing/replacing):

      '.$outdated__outdated_original_and_override.'
    '; } else { $ret_str.=do_lang('WARNING_FILE_OUTDATED_ORIGINAL_AND_OVERRIDE',$outdated__outdated_original_and_override); } } if ($outdated__missing_original_but_has_override!='') { if ($basic) { $ret_str.='

    The following original files to these overridden files are actually missing (you can find them in the manual installer ZIP for the version you\'re running):

      '.$outdated__missing_original_but_has_override.'
    '; } else { $ret_str.=do_lang('WARNING_FILE_MISSING_ORIGINAL_BUT_HAS_OVERRIDE',$outdated__missing_original_but_has_override); } } if (($outdated__uninstalled_addon_but_has_override!='') && (!$basic)) { $ret_str.=do_lang('WARNING_FILE_FROM_UNINSTALLED_ADDON',$outdated__uninstalled_addon_but_has_override); } if ($outdated__missing_file_entirely!='') { if ($basic) { $ret_str.='

    These files are actually missing and need uploading (you can find them in the manual installer ZIP for the version you\'re running):

      '.$outdated__missing_file_entirely.'
    '; } else { $ret_str.=do_lang('WARNING_FILE_MISSING_FILE_ENTIRELY',$outdated__missing_file_entirely); } } if ($outdated__outdated_original!='') { if ($basic) { $ret_str.='

    These files are outdated (you can find the correct versions in the manual installer ZIP for the version you\'re running):

      '.$outdated__outdated_original.'
    '; } else { $ret_str.=do_lang('WARNING_FILE_OUTDATED_ORIGINAL',$outdated__outdated_original); } } if ($outdated__future_files!='') { if ($basic) { $ret_str.='

    These files do not match the ones bundled with your version, but claim to be newer (so these might be bug fixes someone has put here):

      '.$outdated__future_files.'
    '; } else { $ret_str.=do_lang('WARNING_FILE_FUTURE_FILES',$outdated__future_files); } } // And some special help for unix geeks if (($unix_help) && (function_exists('escapeshellcmd')) && (strpos(@ini_get('disable_functions'),'escapeshellcmd')===false)) { $unix_out='OCP_EXTRACTED_AT="";'."\n".'cd "";'."\n"; $directories_to_make=array(); foreach ($files_determined_to_upload as $file) { $dirname=dirname($file); if ($dirname=='.') $dirname=''; $directories_to_make[$dirname]=1; } foreach (array_keys($directories_to_make) as $directory) { $unix_out.='mkdir -p '.escapeshellcmd($directory).';'."\n"; } foreach ($files_determined_to_upload as $file) { $dirname=dirname($file); if ($dirname=='.') $dirname=''; $unix_out.='cp "$OCP_EXTRACTED_AT/'.escapeshellcmd($file).'" "'.escapeshellcmd($dirname).'"/;'."\n"; } require_lang('upgrade'); $ret_str.=do_lang('SH_COMMAND',nl2br(escape_html($unix_out))); } // Alien files if (!$basic) { $master_data=array(); foreach ($files_to_check as $file) { if ((substr($file,-4)=='.tpl') && (strpos($file,'/')===false)) { $master_data['themes/default/templates/'.$file]=1; } elseif ((substr($file,-4)=='.css') && (strpos($file,'/')===false)) { $master_data['themes/default/css/'.$file]=1; } else { $master_data[$file]=1; } } $addon_files=collapse_2d_complexity('filename','addon_name',$GLOBALS['SITE_DB']->query_select('addons_files',array('filename','addon_name'))); list($alien,$addon)=check_alien($addon_files,file_exists(get_file_base().'/data/files_previous.dat')?unserialize(file_get_contents(get_file_base().'/data/files_previous.dat')):array(),$master_data,get_file_base().'/'); if (($moved!='') || ($alien!='')) { $ret_str.='
    '; if ($alien!='') { $ret_str.=do_lang('WARNING_FILE_ALIEN',$alien); } if ($addon!='') { $ret_str.=do_lang('WARNING_FILE_ADDON',$addon); } $ret_str.='

    '.do_lang('FU_CHECK_ALL').'

    '; $ret_str.=''; $ret_str.='
    '; } $ret_str.=''; } return $ret_str; } /** * Check for out-dated files. * * @param SHORT_TEXT The directory we are scanning relative to * @param SHORT_TEXT The directory (relative) we are scanning * @param array Unserialised data/files.dat * @param array A list of the contents of our addon registry hook files * @param boolean Whether merging of CSS changes is allowed * @return array Tuple of various kinds of outdated/missing files */ function check_outdated__handle_overrides($dir,$rela,&$master_data,&$hook_files,$allow_merging) { $outdated__outdated_original_and_override=''; $outdated__possibly_outdated_override=''; $outdated__missing_original_but_has_override=''; $outdated__uninstalled_addon_but_has_override=''; require_code('diff'); require_code('files'); $dh=@opendir($dir); if ($dh!==false) { while (($file=readdir($dh))!==false) { if (should_ignore_file($rela.$file,IGNORE_ACCESS_CONTROLLERS | IGNORE_CUSTOM_THEMES | IGNORE_USER_CUSTOMISE | IGNORE_BUNDLED_VOLATILE | IGNORE_NONBUNDLED_SCATTERED)) continue; $is_dir=@is_dir($dir.$file); if (($is_dir) && (is_readable($dir.$file))) { list($_outdated__outdated_original_and_override,$_outdated__possibly_outdated_override,$_outdated__missing_original_but_has_override,$_outdated__uninstalled_addon_but_has_override)=check_outdated__handle_overrides($dir.$file.'/',$rela.$file.'/',$master_data,$hook_files,$allow_merging); $outdated__outdated_original_and_override.=$_outdated__outdated_original_and_override; $outdated__possibly_outdated_override.=$_outdated__possibly_outdated_override; $outdated__missing_original_but_has_override.=$_outdated__missing_original_but_has_override; $outdated__uninstalled_addon_but_has_override.=$_outdated__uninstalled_addon_but_has_override; } else { if (strpos($rela,'_custom')!==false) { $equiv_file=get_file_base().'/'.str_replace('_custom','',$rela).$file; if ((!file_exists($equiv_file)) && (substr($rela,0,7)=='themes/') && (substr_count($rela,'/')==3)) { $equiv_file=get_file_base().'/'.str_replace('_custom','',preg_replace('#themes/[^/]*/#','themes/default/',$rela)).$file; } if (file_exists($equiv_file)) { if ($allow_merging) { if (file_exists($dir.$file.'.editfrom')) // If we edited-from, then we use that to do the compare { $hash_on_disk=sprintf('%u',crc32(preg_replace('#[\r\n\t ]#','',file_get_contents($dir.$file.'.editfrom')))); $only_if_noncustom=false; } else { $hash_on_disk=sprintf('%u',crc32(preg_replace('#[\r\n\t ]#','',file_get_contents($dir.$file)))); $only_if_noncustom=true; } $_true_hash=sprintf('%u',crc32(preg_replace('#[\r\n\t ]#','',file_get_contents($equiv_file)))); if (array_key_exists($file,$master_data)) // Get hash from perfection table { $true_hash=$master_data[$rela.$file][0]; if ($true_hash!=$_true_hash) { $outdated__outdated_original_and_override.='
  • '.escape_html($rela.$file).'
  • '; unset($master_data[$rela.$file]); continue; } } else // Get hash from non-overridden file (equiv file) { if ($only_if_noncustom) $true_hash=NULL; // Except we can't as we're not looking at the .editfrom and thus can't expect equality else $true_hash=$_true_hash; } if ((!is_null($true_hash)) && ($hash_on_disk!=$true_hash)) { if ((function_exists('diff_compute_new')) && (substr($file,-4)=='.css') && ($true_hash!==2) && (file_exists($dir.$file.'.editfrom')) && (is_writable_wrap($dir.$file))) { $new=diff_compute_new($equiv_file,$dir.$file.'.editfrom',$dir.$file); $myfile=fopen($dir.$file.'.'.strval(time()),'wb'); fwrite($myfile,file_get_contents($dir.$file)); fclose($myfile); $myfile=fopen($dir.$file,'wb'); fwrite($myfile,$new); fclose($myfile); $outdated__possibly_outdated_override.='
  • '.escape_html($rela.$file).' '.do_lang('AUTO_MERGED').'
  • '; $myfile=fopen($dir.$file.'.editfrom','wb'); fwrite($myfile,file_get_contents($equiv_file)); fclose($myfile); } else { $outdated__possibly_outdated_override.='
  • '.escape_html($rela.$file).'
  • '; } } } else { $outdated__possibly_outdated_override.='
  • '.escape_html($rela.$file).'
  • '; } unset($master_data[$rela.$file]); } elseif (array_key_exists(str_replace('_custom','',preg_replace('#themes/[^/]*/#','themes/default/',$rela)).$file,$master_data)) { $known_in_addon=false; foreach ($hook_files as $hook_file) { if (strpos($hook_file,str_replace('themes/default/css/','',str_replace('themes/default/templates/','',str_replace('_custom','',preg_replace('#themes/[^/]*/#','themes/default/',$rela)))).$file)!==false) { $known_in_addon=true; break; } } if ($known_in_addon) { $outdated__missing_original_but_has_override.='
  • '.escape_html($rela.$file).'
  • '; } else { $outdated__uninstalled_addon_but_has_override.='
  • '.escape_html($rela.$file).'
  • '; } unset($master_data[$rela.$file]); } } } } } return array($outdated__outdated_original_and_override,$outdated__possibly_outdated_override,$outdated__missing_original_but_has_override,$outdated__uninstalled_addon_but_has_override); } /** * Check for alien files. * * @param array List of files from non-bundled addons (a map: relative file paths as keys of map) * @param array List of files from old version * @param array List of verbatim files * @param SHORT_TEXT The directory we are scanning relative to * @param SHORT_TEXT The directory (relative) we are scanning * @param boolean Whether to give raw output (no UI) * @return array A pair: HTML list of alien files, HTML list of addon files */ function check_alien($addon_files,$old_files,$files,$dir,$rela='',$raw=false) { $alien=''; $addon=''; $dh=@opendir($dir); if ($dh!==false) { if ($rela=='') { $old_addons_now_gone=array( 'sources/hooks/systems/addon_registry/core_installation_uninstallation.php', ); $modules_moved_intentionally=array( 'collaboration/pages/modules/filedump.php', ); foreach (array_merge($old_addons_now_gone,$modules_moved_intentionally) as $x) { if (file_exists(get_file_base().'/'.$x)) { $alien.='
  • '; if (!$raw) $alien.=' '; $alien.=''.escape_html($x).'
  • '; } } } $dir_files=array(); while (($file=readdir($dh))!==false) { $dir_files[]=$file; } sort($dir_files); foreach ($dir_files as $file) { if (should_ignore_file($rela.$file,IGNORE_ACCESS_CONTROLLERS | IGNORE_USER_CUSTOMISE | IGNORE_CUSTOM_THEMES | IGNORE_CUSTOM_ZONES | IGNORE_NON_REGISTERED)) continue; $is_dir=@is_dir($dir.$file); if (!is_readable($dir.$file)) continue; if ($rela=='lang_cached/') continue; if ($rela=='uploads/') continue; if ($rela=='data_custom/modules/') continue; if ($is_dir) { if (!file_exists($dir.$file.'/info.php')) { if (($rela=='') && (!file_exists($dir.$file.'/pages'))) // Scan to make sure it's not some other system placed under the webroot { $ok=false; foreach (array_keys($files) as $f) { if (substr($f,0,strlen($rela.$file.'/'))==$rela.$file.'/') { $ok=true; break; } } if (!$ok) continue; } list($_alien,$_addon)=check_alien($addon_files,$old_files,$files,$dir.$file.'/',$rela.$file.'/',$raw); $alien.=$_alien; $addon.=$_addon; } } else { if (!array_key_exists($rela.$file,$files)) { if (strpos($rela,'pages/modules')!==false) // Check it isn't a moved module { $zones=find_all_zones(); $matches=array(); preg_match('#(.*)pages/modules#',$rela,$matches); $current_zone=str_replace('/','',$matches[1]); foreach ($zones as $zone) { if (array_key_exists(str_replace($current_zone.'/',$zone.'/',$rela.$file),$files)) continue 2; } } $disabled=''; //if ((is_dir($dir.'/'.$file=='')) && ()) Not needed as this is only for files $checked=''; if (array_key_exists($rela.$file,$old_files)) $checked='checked="checked" '; $file_html=''; $file_html.='
  • '; if (!$raw) $file_html.=' '; $file_html.=''.escape_html($rela.$file).'
  • '; if (array_key_exists($rela.$file,$addon_files)) { $addon.=$file_html; } else { if (strlen($alien)<=100000) // Reasonable limit $alien.=$file_html; } } } } } if (strlen($alien)>100000) $alien=''; // Reasonable limit return array($alien,$addon); } /** * Move/delete certain selected things, in follow up to an integrity scan. */ function _integrity_scan() { foreach (array_keys($_POST) as $key) { $val=post_param($key); if (strpos($val,':')!==false) { $bits=explode(':',$val); if ($bits[0]=='delete') { afm_delete_file($bits[1]); } elseif ($bits[0]=='move') { afm_delete_file($bits[2]); afm_move($bits[1],$bits[2]); } } } } /** * Version specific upgrading. These are things that are relatively major structural changes and therefore will get done outside the module upgrade system. * * @return boolean Whether anything was done */ function version_specific() { // Version specific (rather than component specific) upgrading $version_files=ocp_version_number(); $_version_database=get_value('version'); $version_database=floatval($_version_database); if (is_null($_version_database)) $version_database=2.1; // Either 2.0 or 2.1, and they are equivalent in terms of what we need to do if ($version_database<$version_files) { if ($version_database<2.5) { $GLOBALS['SITE_DB']->query('DELETE FROM '.get_table_prefix().'chat_messages'); $GLOBALS['SITE_DB']->query_update('modules',array('module_the_name'=>'galleries'),array('module_the_name'=>'images')); $GLOBALS['SITE_DB']->query_update('group_page_access',array('page_name'=>'galleries'),array('page_name'=>'images')); $GLOBALS['SITE_DB']->alter_table_field('zones','zone_wide','?BINARY'); $GLOBALS['SITE_DB']->alter_table_field('theme_images','id','SHORT_TEXT'); $GLOBALS['SITE_DB']->refresh_field_definition('URLPATH'); $GLOBALS['SITE_DB']->query('ALTER TABLE '.get_table_prefix().'translate TYPE=MYISAM'); // Just in case it's not $GLOBALS['SITE_DB']->create_index('translate','#search',array('text_original')); $trans4=insert_lang(do_lang('A_SITE_ABOUT','???'),1); $trans8=insert_lang(do_lang('GUIDES'),1); $GLOBALS['SITE_DB']->query_insert('zones',array(/*'zone_title'=>insert_lang(do_lang('SITE'),1),*/'zone_name'=>'membersonly','zone_default_page'=>'start','zone_header_text'=>$trans4,'zone_theme'=>'-1','zone_wide'=>0,'zone_require_session'=>0)); $GLOBALS['SITE_DB']->query_insert('zones',array(/*'zone_title'=>insert_lang(do_lang('GUIDES'),1),*/'zone_default_page'=>'userguide','zone_header_text'=>$trans8,'zone_theme'=>'-1','zone_wide'=>0,'zone_require_session'=>0)); } if ($version_database<3.0) { fu_rename_zone('membersonly','site'); fu_rename_zone('admincentre','adminzone'); if (file_exists(get_file_base().'/collaboration')) fu_rename_zone('supermembercentre','collaboration'); fu_rename_zone('membercentre','site',true); // Merged into 'site' (formerly membersonly) actual_delete_zone_lite('seedy'); $GLOBALS['SITE_DB']->query_insert('zones',array('zone_name'=>'cms','zone_title'=>insert_lang(do_lang('CMS'),1),'zone_default_page'=>'cms','zone_header_text'=>insert_lang(do_lang('CMS'),1),'zone_theme'=>'-1','zone_wide'=>0,'zone_require_session'=>1)); $GLOBALS['SITE_DB']->query_update('modules',array('module_the_name'=>'admin_cleanup'),array('module_the_name'=>'admin_caches')); $GLOBALS['SITE_DB']->query_update('modules',array('module_the_name'=>'seedy_page'),array('module_the_name'=>'cedi')); $GLOBALS['SITE_DB']->query_update('attachment_refs',array('r_referer_type'=>'cedi_page'),array('r_referer_type'=>'seedy_page')); $GLOBALS['SITE_DB']->query_update('attachment_refs',array('r_referer_type'=>'cedi_post'),array('r_referer_type'=>'seedy_post')); $modules_gone=array('seedy_move','seedy_changes','seedy_edit_page','seedy_manage_tree','seedy_move','seedy_post','seedy_show_tree','seedy_merge','admin_seedy','admin_pages','admin_ftp_downloads','admin_timezone','admin_modules','admin_ocf_moderator_logs','admin_submitban'); foreach ($modules_gone as $module) { $GLOBALS['SITE_DB']->query_delete('modules',array('module_the_name'=>$module),'',1); } $GLOBALS['SITE_DB']->query_update('modules',array('module_the_name'=>'galleries'),array('module_the_name'=>'images'),'',1); $GLOBALS['SITE_DB']->query_update('modules',array('module_the_name'=>'admin_sitetree'),array('module_the_name'=>'admin_comcode_pages'),'',1); $GLOBALS['SITE_DB']->query_update('modules',array('module_the_name'=>'admin_addons'),array('module_the_name'=>'admin_mods'),'',1); $GLOBALS['SITE_DB']->query_update('modules',array('module_the_name'=>'admin_awards'),array('module_the_name'=>'admin_dotws'),'',1); } if ($version_database<4.0) { $GLOBALS['SITE_DB']->query('ALTER TABLE '.get_table_prefix().'translate CHANGE id id INT(10) UNSIGNED AUTO_INCREMENT'); } if ($version_database<5.1) { // Installaton code got moved over $sitetree_version=$GLOBALS['SITE_DB']->query_value('modules','module_version',array('module_the_name'=>'admin_sitetree')); $GLOBALS['SITE_DB']->query_update('modules',array('module_version'=>$sitetree_version),array('module_the_name'=>'cms_comcode_pages'),'',1); } if ($version_database<8.0) { actual_delete_zone_lite('personalzone'); } if ($version_database<9.0) { $dh=@opendir(get_custom_file_base().'/imports/mods'); if ($dh!==false) { while (($f=readdir($dh))!==false) { if (substr($f,-4)=='.tar') @rename(get_custom_file_base().'/imports/mods/'.$f,get_file_base().'/imports/addons/'.$f); } } } set_value('version',float_to_raw_string($version_files,10,true)); return true; } return false; } /** * Rename a zone in the database and move any custom pages in it. * * @param ID_TEXT The old name of the zone * @param ID_TEXT The new name of the zone * @param boolean Whether to assume the main zone row has already been renamed as part of a wider editing operation */ function fu_rename_zone($zone,$new_zone,$dont_bother_with_main_row=false) { if (function_exists('set_time_limit')) @set_time_limit(0); require_code('zones2'); if (file_exists(get_file_base().'/sources/zones3.php')) require_code('zones3'); actual_rename_zone_lite($zone,$new_zone,$dont_bother_with_main_row); $pages=find_all_pages_wrap($zone,true,false,FIND_ALL_PAGES__ALL); foreach ($pages as $page=>$type) { $path=get_file_base().'/'.$zone.'/pages/'.$type.'/'.$page; $new_path=get_file_base().'/'.$new_zone.'/pages/'.$type.'/'.$page; if ((is_writable_wrap($path)) && (is_writable_wrap($new_path))) { rename($path,$new_path); sync_file_move($path,$new_path); } } } /** * Upgrade all modules. * * @return string List of upgraded/installed modules/blocks */ function upgrade_modules() { $out=''; require_code('zones2'); if (file_exists(get_file_base().'/sources/zones3.php')) require_code('zones3'); $ret=upgrade_module('adminzone','admin_version'); if ($ret==1) $out.='
  • '.do_lang('FU_UPGRADED_MODULE','admin_version').'
  • '; $zones=find_all_zones(); if (!in_array('adminzone',$zones)) $zones[]='adminzone'; if (!in_array('cms',$zones)) $zones[]='cms'; if (!in_array('site',$zones)) $zones[]='site'; foreach ($zones as $zone) { $modules=find_all_modules($zone); foreach ($modules as $module=>$type) { $ret=upgrade_module($zone,$module); if ($ret==1) $out.='
  • '.do_lang('FU_UPGRADED_MODULE',''.escape_html($module).'').'
  • '; elseif ($ret==-2) { if ($type=='modules_custom') continue; if (reinstall_module($zone,$module)) { $out.='
  • '.do_lang('FU_INSTALLED_MODULE',''.escape_html($module).'').'
  • '; } } } } require_code('zones2'); if (file_exists(get_file_base().'/sources/zones3.php')) require_code('zones3'); $blocks=find_all_blocks(); foreach ($blocks as $block=>$type) { $ret=upgrade_block($block); if ($ret==1) $out.='
  • '.do_lang('FU_UPGRADED_BLOCK',''.escape_html($block).'').'
  • '; elseif ($ret==-2) { if ($type=='sources_custom') continue; if (reinstall_block($block)) { $out.='
  • '.do_lang('FU_INSTALLED_BLOCK',''.escape_html($block).'').'
  • '; } } } return $out; } /** * Upgrade OCF if appropriate. * * @return boolean Whether anything was done */ function ocf_upgrade() { $version_files=ocp_version_number(); $version_database=floatval(get_value('ocf_version')); if (is_null($version_database)) $version_database=2.1; if ($version_files!=$version_database) { global $SITE_INFO; $SITE_INFO['db_forums']=$SITE_INFO['db_site']; $SITE_INFO['db_forums_host']=array_key_exists('db_site_host',$SITE_INFO)?$SITE_INFO['db_site_host']:'localhost'; $SITE_INFO['db_forums_user']=array_key_exists('db_site_user',$SITE_INFO)?$SITE_INFO['db_site_user']:'root'; $SITE_INFO['db_forums_password']=array_key_exists('db_site_password',$SITE_INFO)?$SITE_INFO['db_site_password']:''; $GLOBALS['FORUM_DB']=$GLOBALS['SITE_DB']; require_code('forum/ocf'); $GLOBALS['FORUM_DRIVER']=object_factory('forum_driver_ocf'); $GLOBALS['FORUM_DRIVER']->connection=$GLOBALS['SITE_DB']; require_code('ocf_install'); install_ocf($version_database); set_value('ocf_version',float_to_raw_string($version_files)); return true; } return false; } /** * Make sure the site database has the correct character set internally. ocPortal already ensures the communication charset makes sense for what ocPortal is using, this makes sure it stores sanely too. */ function fix_mysql_database_charset() { global $SITE_INFO; if (!array_key_exists('database_charset',$SITE_INFO)) $SITE_INFO['database_charset']=(strtolower(get_charset())=='utf-8')?'utf8':'latin1'; change_mysql_database_charset($SITE_INFO['database_charset'],$GLOBALS['SITE_DB']); } /** * Refresh a MySQL database's character set is correct. * * @param ID_TEXT Character set * @param object Database * @param boolean Whether to let MySQL do a reencoding of the characters (if this is set to false we actually are adjusting the interpretation whilst leaving the disk data the same) */ function change_mysql_database_charset($new_charset,$db,$reencode=false) { @ob_end_clean(); if (function_exists('set_time_limit')) @set_time_limit(0); $bak=$GLOBALS['NO_DB_SCOPE_CHECK']; $GLOBALS['NO_DB_SCOPE_CHECK']=true; $fulltext_indices=$GLOBALS['SITE_DB']->query_select('db_meta_indices',array('*')); foreach ($fulltext_indices as $index) { if (substr($index['i_name'],0,1)=='#') { echo 'Deleting index: '.$index['i_table'].'/'.$index['i_name']."\n"; flush(); $GLOBALS['SITE_DB']->delete_index_if_exists($index['i_table'],$index['i_name']); } } echo 'Changing overall character set for database'."\n"; flush(); $db->query('ALTER DATABASE '.get_db_site().' CHARACTER SET '.$new_charset); $remap=$db->static_ob->db_get_type_remap(); $tables=collapse_1d_complexity('m_table',$db->query_select('db_meta',array('DISTINCT m_table'))); foreach ($tables as $table) { echo 'Changing character sets for: '.$table."\n"; flush(); $fields=$db->query_select('db_meta',array('m_name','m_table','m_type'),array('m_table'=>$table)); $db->query('ALTER TABLE '.$db->get_table_prefix().$table.' CHARACTER SET '.$new_charset); foreach ($fields as $field) { $db_type=strtoupper($remap[str_replace(array('*','?'),array('',''),$field['m_type'])]); if ((strpos($db_type,'TEXT')!==false) || (strpos($db_type,'CHAR')!==false)) { $db_type_temp=$db_type; if (substr($db_type,0,4)=='CHAR') $db_type_temp=str_replace('CHAR','BINARY',$db_type); elseif (substr($db_type,0,7)=='VARCHAR') $db_type_temp=str_replace('VARCHAR','VARBINARY',$db_type); elseif (substr($db_type,0,4)=='LONGTEXT') $db_type_temp=str_replace('LONGTEXT','LONGBLOB',$db_type); foreach ($reencode?array($db_type):array($db_type_temp,$db_type) as $i=>$db_type) { $query='ALTER TABLE '.$db->get_table_prefix().$table.' CHANGE '.$field['m_name'].' '.$field['m_name'].' '.$db_type; if ($i==1 || $reencode) $query.=' CHARACTER SET '.$new_charset; $query.=' '.((strpos($field['m_name'],'?')!==false)?'NULL':'NOT NULL'); $db->query($query); } } } } foreach ($fulltext_indices as $index) { if (substr($index['i_name'],0,1)=='#') { echo 'Rebuilding index: '.$index['i_table'].'/'.$index['i_name']."\n"; flush(); $GLOBALS['SITE_DB']->create_index($index['i_table'],$index['i_name'],explode(',',$index['i_fields'])); } } $GLOBALS['NO_DB_SCOPE_CHECK']=$bak; } /** * Upgrade all themes. * * @return string HTML output */ function upgrade_themes() { $test_run=(get_param_integer('live_run',0)==0); $str=''; $str.='

    Theme upgrade: '.($test_run?'test run':'live results').'

    '; require_code('themes2'); $themes=find_all_themes(); $has_errors=false; foreach (array_keys($themes) as $theme) { $from=round(ocp_version_number())-1; $to=ocp_version_number(); list($errors,$successes)=upgrade_theme($theme,$from,$to,$test_run); $str.='

    '.escape_html($theme).'

    '; foreach ($errors as $error) { $str.='

    ✗ '.$error->evaluate().'

    '; $has_errors=true; } foreach ($successes as $success) { $str.='

    ✓ '.$success->evaluate().'

    '; } } if ($test_run) { if ($has_errors) { $str.='

    '.do_lang('FU_THEME_ERRORS').'

    '; } $l_theme_upgrade=fu_link('upgrader.php?type=theme_upgrade&live_run=1',do_lang('FU_THEME_UPGRADE_FINAL')); $str.=$l_theme_upgrade; } return $str; } /** * Upgrade a theme automatically, using hand-coded migration arrays. * * @param ID_TEXT Theme to be upgraded * @param float From version * @param float Target version * @param boolean Whether executing a test run (i.e. not do anything) * @return array A pair: List of errors, List of successes */ function upgrade_theme($theme,$from_version,$to_version,$test_run=true) { $errors=array(); $successes=array(); if (!$test_run) { require_code('abstract_file_manager'); force_have_afm_details(); } $css_replace__single_match=array(); $css_prepend__single_match=array(); $css_append__single_match=array(); $css_replace__multi_match=array(); $css_prepend__multi_match=array(); $css_append__multi_match=array(); $css_file_append=array(); $theme_images_new=array(); $theme_images_renames=array(); $templates_replace=array(); $templates_rename=array(); $templates_borked=array(); // TODO: Implement upgrade for next version if (false) { $css_recognition_string='2004-2011'; // Must be defined. Ensures theme is right version. $css_replace__multi_match=array( '*'=>array( ), 'global.css'=>array( ), ); $css_replace__single_match=array( ); $css_prepend__single_match=array( ); $css_append__single_match=array( ); $css_file_append=array( ); // NB: This UNIX command can work out what theme images are added... // OLD=/Library/WebServer/Documents/test/themes/default/images ; NEW=/Library/WebServer/Documents/git/themes/default/images ; diff -r $OLD $NEW | grep "Only in $NEW" | grep -v .DS_Store | sed "s#Only in "$NEW"##g" | sed "s#: #/#g" | sed "s#^/##g" | sed "s#^EN/##g" | sed "s#\.*$##" // Obviously only theme-wizable images should go here $theme_images_new=array( ); $theme_images_renames=array( ); $templates_replace=array( '*'=>array( ), ); /*Find deleted/renamed templates: OLD=/Library/WebServer/Documents/test/themes/default/templates ; NEW=/Library/WebServer/Documents/git/themes/default/templates ; diff -r $OLD $NEW | grep .tpl$ | grep "Only in "$OLD | sed "s#Only in "$OLD": ##"*/ $templates_rename=array( ); /*Find diff of changes templates OLD=/Library/WebServer/Documents/test/themes/default/templates ; NEW=/Library/WebServer/Documents/git/themes/default/templates ; diff -u $OLD $NEW > ~/Desktop/diff.txt*/ $templates_borked=array( ); } else { $errors[]=do_lang_tempcode('NO_DEFINED_THEME_UPGRADER'); return array($errors,array()); } if (addon_installed('themewizard')) { require_code('themewizard'); $seed=find_theme_seed($theme); $dark=find_theme_dark($theme); list($colours,$landscape)=calculate_theme($seed,'default','equations','colours',$dark); } // CSS $css_dir=get_custom_file_base().'/themes/'.filter_naughty($theme).'/css_custom/'; $dh=@opendir($css_dir); if ($dh!==false) { while (($css_file=readdir($dh))!==false) { if (substr($css_file,-4)!='.css') continue; if (substr($css_file,0,1)=='.') continue; $css_file_contents=file_get_contents($css_dir.$css_file); $orig_css_file_contents=$css_file_contents; if (strpos($css_file_contents,$css_recognition_string)===false) { $errors[]=do_lang_tempcode('NON_RECOGNISED_CSS_FILE',escape_html($css_file),escape_html(float_to_raw_string($from_version))); //continue; Actually we'll let it pass } // Apply single match rules. First check single match rules apply exactly once (means rule is bogus if it matches more than once, or unusable if not at all) foreach (array('css_replace'=>$css_replace__single_match,'css_prepend'=>$css_prepend__single_match,'css_append'=>$css_append__single_match) as $rule_set_type=>$rule_set) { foreach ($rule_set as $target_file=>$_rule_set) { // If people have moved CSS into global.css, to optimise page load times if (($target_file!='*') && ($target_file!='global.css') && ($css_file=='global.css')) { if ((file_exists($css_dir.$target_file)) && (strlen(trim(file_get_contents($css_dir.$target_file)))==0)) { $target_file='global.css'; } } if (($target_file=='*') || ($target_file==$css_file)) { foreach ($_rule_set as $from=>$to) { // Apply theme wizard to $to if (addon_installed('themewizard')) $to=theme_wizard_colours_to_css($to,$landscape,'default','equations',$seed); $occurrences=substr_count($css_file_contents,$from); if ($occurrences==0) // Try after applying theme wizard { if (addon_installed('themewizard')) { $from=theme_wizard_colours_to_css($from,$landscape,'default','equations',$seed); $occurrences=substr_count($css_file_contents,$from); } } if ($occurrences==0) { $errors[]=do_lang_tempcode('CSS_RULE_UNMATCHED_'.$rule_set_type,escape_html($from),escape_html($to),escape_html($target_file)); } elseif ($occurrences>1) { $errors[]=do_lang_tempcode('CSS_RULE_OVERMATCHED_'.$rule_set_type,escape_html($from),escape_html($to),escape_html($target_file)); } else { switch ($rule_set_type) { case 'css_replace': $css_file_contents=str_replace($from,$to,$css_file_contents); break; case 'css_prepend': $pos=strpos($css_file_contents,$from); if (substr($css_file_contents,$pos-strlen($to),strlen($to))!=$to) { $css_file_contents=substr($css_file_contents,0,$pos).$to.substr($css_file_contents,$pos); } break; case 'css_append': $pos=strpos($css_file_contents,$from)+strlen($from); if (substr($css_file_contents,$pos,strlen($to))!=$to) { $css_file_contents=substr($css_file_contents,0,$pos).$to.substr($css_file_contents,$pos); } break; } } } } } } // Apply multi-match rules foreach (array('css_replace'=>$css_replace__multi_match,'css_prepend'=>$css_prepend__multi_match,'css_append'=>$css_append__multi_match) as $rule_set_type=>$rule_set) { foreach ($rule_set as $target_file=>$_rule_set) { if (($target_file=='*') || ($target_file==$css_file)) { foreach ($_rule_set as $from_a=>$to) { // Apply theme wizard to $to if (addon_installed('themewizard')) $to=theme_wizard_colours_to_css($to,$landscape,'default','equations',$seed); $froms=array($from_a); if (addon_installed('themewizard')) $froms[]=theme_wizard_colours_to_css($from_a,$landscape,'default','equations',$seed); foreach ($froms as $from) { switch ($rule_set_type) { case 'css_replace': $css_file_contents=str_replace($from,$to,$css_file_contents); break; case 'css_prepend': $pos=0; do { $pos=strpos($css_file_contents,$from,$pos); if ($pos!==false) { if (substr($css_file_contents,$pos,-strlen($to))!=$to) { $css_file_contents=substr($css_file_contents,0,$pos).$to.substr($css_file_contents,$pos); $pos+=strlen($to)+strlen($from); } else { $pos+=strlen($from); } } } while ($pos!==false); break; case 'css_append': $pos=0; do { $pos=strpos($css_file_contents,$from,$pos); if ($pos!==false) { if (substr($css_file_contents,$pos,strlen($to))!=$to) { $pos+=strlen($from); $css_file_contents=substr($css_file_contents,0,$pos).$to.substr($css_file_contents,$pos); $pos+=strlen($to); } else { $pos+=strlen($from); } } } while ($pos!==false); break; } } } } } } // Apply unmatched rules foreach ($css_file_append as $target_file=>$rule_set) { if (($target_file=='*') || ($target_file==$css_file)) { foreach ($rule_set as $to) { $css_file_contents.=$to; } } } if (!$test_run) { // Take revision $revision_file=$css_dir.$css_file.'.'.strval(time()); if (@copy($css_dir.$css_file,$revision_file)!==false) { fix_permissions($revision_file); sync_file($revision_file); } // Save if ($orig_css_file_contents!=$css_file_contents) { $outfile=@fopen($css_dir.$css_file,'wb') OR intelligent_write_error($css_dir.$css_file); fwrite($outfile,$css_file_contents); fclose($outfile); } $successes[]=do_lang_tempcode('CSS_FILE_UPGRADED',escape_html($css_file)); } } closedir($dh); } // Theme images require_code('themes2'); $langs=array('EN'=>'lang');//find_all_langs(); foreach ($theme_images_renames as $old=>$new) { foreach (array_keys($langs) as $lang) { $path=urldecode(find_theme_image($old,true,true,$theme,$lang)); if ($path!='') { $new_path=str_replace('/'.$old,'/'.$new,$path); if (!$test_run) { if (!file_exists(get_custom_file_base().'/'.$new_path)) { if (file_exists($path)) afm_move($path,$new_path); $where_map=array('theme'=>$theme,'id'=>$new); if (($lang!='') && (!is_null($lang))) $where_map['lang']=$lang; $GLOBALS['SITE_DB']->query_delete('theme_images',$where_map); actual_edit_theme_image($old,$theme,$lang,$new,$new_path); $successes[]=do_lang_tempcode('THEME_IMAGE_RENAMED',escape_html($old),escape_html($new)); } } } } } if (addon_installed('themewizard')) { if ($theme!='default') { foreach ($theme_images_new as $new) { foreach (array_keys($langs) as $lang) { $path=urldecode(find_theme_image($new,true,true,'default',$lang)); if ($path!='') { $new_path=str_replace('themes/default/images/','themes/'.$theme.'/images/',$path); if (!file_exists(get_custom_file_base().'/'.$new_path)) { if (!$test_run) { afm_make_directory(dirname($new_path),true,true); } $image=calculate_theme($seed,'default','equations',$new,$dark,$colours,$landscape,$lang); if (!is_null($image)) { if (!$test_run) { @imagepng($image,get_custom_file_base().'/'.$new_path) OR intelligent_write_error(get_custom_file_base().'/'.$new_path); imagedestroy($image); fix_permissions(get_custom_file_base().'/'.$new_path); sync_file(get_custom_file_base().'/'.$new_path); $successes[]=do_lang_tempcode('THEME_IMAGE_NEW',escape_html($new)); } } } } } } } } // Templates $templates_dir=get_custom_file_base().'/themes/'.filter_naughty($theme).'/templates_custom/'; $dh=@opendir($templates_dir); if ($dh!==false) { while (($templates_file=readdir($dh))!==false) { if (substr($templates_file,-4)!='.tpl') continue; $templates_file_contents=file_get_contents($templates_dir.$templates_file); $orig_templates_file_contents=$templates_file_contents; foreach ($templates_replace as $target_file=>$rule_set) { if (($target_file=='*') || ($target_file==$templates_file)) { foreach ($rule_set as $from=>$to) { $templates_file_contents=str_replace($from,$to,$templates_file_contents); } } } if (array_key_exists($templates_file,$templates_rename)) { if (!$test_run) { @rename($templates_dir.$templates_file,$templates_dir.$templates_rename[$templates_file]) OR intelligent_write_error($templates_dir.$templates_rename[$templates_file]); $successes[]=do_lang_tempcode('TEMPLATE_RENAMED',escape_html($templates_file),escape_html($templates_rename[$templates_file])); } $templates_file=$templates_rename[$templates_file]; } if ($templates_file_contents!=$orig_templates_file_contents) { if (!$test_run) { $successes[]=do_lang_tempcode('TEMPLATE_ALTERED',escape_html($templates_file)); // Save $outfile=@fopen($templates_dir.$templates_file,'wb') OR intelligent_write_error($templates_dir.$templates_file); fwrite($outfile,$templates_file_contents); fclose($outfile); } } if (in_array($templates_file,$templates_borked)) { $errors[]=do_lang_tempcode('TEMPLATE_WILL_NEED_RESTORING',escape_html($templates_file)); } } closedir($dh); } return array($errors,$successes); } /** * Upgrade shared installs. * * @param integer Position to proceed from */ function upgrade_sharedinstall_sites($from=0) { global $CURRENT_SHARE_USER,$SITE_INFO,$TABLE_LANG_FIELDS; // Find sites $sites=array(); foreach (array_keys($SITE_INFO) as $key) { $matches=array(); if (preg_match('#^custom_user_(.*)#',$key,$matches)!=0) { $sites[]=$matches[1]; } } disable_php_memory_limit(); $total=count($sites); foreach ($sites as $i=>$site) { if (function_exists('set_time_limit')) @set_time_limit(0); if (($i<$from) && ($site!='shareddemo')) continue; // Change active site $CURRENT_SHARE_USER=$site; $TABLE_LANG_FIELDS=array(); _general_db_init(); // Reset DB $GLOBALS['SITE_DB']=new database_driver(get_db_site(),get_db_site_host(),get_db_site_user(),get_db_site_password(),get_table_prefix()); $GLOBALS['FORUM_DB']=$GLOBALS['SITE_DB']; // NB: File path will be ok // NB: Other internal caching could need changing in the future, but works at time of writing // Go! automate_upgrade(); echo 'Upgraded '.escape_html($site).' ('.escape_html(number_format($i+1).' of '.number_format($total)).')
    '; flush(); } } /** * Automatically go through full upgrade for current site. */ function automate_upgrade() { // Database clear_caches_1(); clear_caches_2(); version_specific(); upgrade_modules(); // OCF ocf_upgrade(); // Themes require_code('themes2'); $themes=find_all_themes(); foreach (array_keys($themes) as $theme) { $from=round(ocp_version_number())-1; $to=ocp_version_number(); upgrade_theme($theme,$from,$to,false); } }