예제 #1
0
 /**
  * UI for a setup wizard step (done).
  *
  * @return tempcode		The UI
  */
 function step10()
 {
     $title = get_page_title('SETUP_WIZARD_STEP', true, array(integer_format(10), integer_format(10)));
     $GLOBALS['NO_QUERY_LIMIT'] = true;
     require_code('abstract_file_manager');
     force_have_afm_details();
     if (function_exists('set_time_limit')) {
         @set_time_limit(600);
     }
     require_code('config2');
     require_code('menus2');
     require_code('themes2');
     require_lang('zones');
     $header_text = post_param('header_text');
     $name = post_param('site_name');
     $theme = substr(preg_replace('#[^A-Za-z\\d]#', '_', $name), 0, 40);
     $installprofile = post_param('installprofile', '');
     if ($installprofile != '') {
         // Simplify down to a single menu
         foreach (array('main_community', 'main_content', 'main_features', 'main_website', 'root_website') as $merge_item) {
             $GLOBALS['SITE_DB']->query_update('menu_items', array('i_menu' => 'site'), array('i_menu' => $merge_item));
         }
         $duplicates = $GLOBALS['SITE_DB']->query_select('menu_items', array('id', 'COUNT(*) AS cnt'), array('i_menu' => 'site'), 'GROUP BY i_url');
         foreach ($duplicates as $duplicate) {
             if ($duplicate['cnt'] > 1) {
                 delete_menu_item($duplicate['id']);
             }
         }
         delete_menu_item_simple('site:');
         // Remove panel_top
         if (addon_installed('redirects_editor')) {
             $GLOBALS['SITE_DB']->query_delete('redirects', array('r_to_page' => 'panel_top'));
         }
         $fullpath = get_custom_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/panel_top.txt';
         if (file_exists($fullpath)) {
             @copy($fullpath, $fullpath . '.' . strval(time()));
         }
         $myfile = @fopen($fullpath, 'wt');
         if ($myfile !== false) {
             fwrite($myfile, '');
             fclose($myfile);
             fix_permissions($fullpath);
             sync_file($fullpath);
         }
         // Run any specific code for the profile
         $object = mixed();
         if (is_file(get_file_base() . '/sources/hooks/modules/admin_setupwizard_installprofiles/' . $installprofile . '.php') || is_file(get_file_base() . '/sources_custom/hooks/modules/admin_setupwizard_installprofiles/' . $installprofile . '.php')) {
             require_code('hooks/modules/admin_setupwizard_installprofiles/' . $installprofile);
             $object = object_factory('Hook_admin_setupwizard_installprofiles_' . $installprofile, true);
         }
         if (!is_null($object)) {
             $object->install_code();
             $installprofileblocks = $object->default_blocks();
         } else {
             $installprofileblocks = array();
         }
     } else {
         $installprofileblocks = array();
     }
     if (post_param_integer('skip_8', 0) == 0 && function_exists('imagecreatefromstring') && addon_installed('themewizard')) {
         require_code('themewizard');
         // Make theme
         global $IMG_CODES;
         $old_img_codes_site = $GLOBALS['SITE_DB']->query_select('theme_images', array('id', 'path'), array('theme' => $GLOBALS['FORUM_DRIVER']->get_theme(), 'lang' => user_lang()));
         if (!file_exists(get_custom_file_base() . '/themes/' . $theme)) {
             make_theme($theme, 'default', 'equations', post_param('seed_hex'), true, post_param_integer('dark', 0) == 1);
         }
         foreach (array($theme, 'default') as $logo_save_theme) {
             $logo = generate_logo($name, $header_text, false, $logo_save_theme, 'logo-template');
             $path = 'themes/' . $logo_save_theme . '/images_custom/-logo.png';
             @imagepng($logo, get_custom_file_base() . '/' . $path) or intelligent_write_error($path);
             actual_edit_theme_image('logo/-logo', $logo_save_theme, get_site_default_lang(), 'logo/-logo', $path, true);
             if (addon_installed('collaboration_zone')) {
                 actual_edit_theme_image('logo/collaboration-logo', $logo_save_theme, get_site_default_lang(), 'logo/collaboration-logo', $path, true);
             }
             imagedestroy($logo);
             $logo = generate_logo($name, $header_text, false, $logo_save_theme, 'trimmed-logo-template');
             $path = 'themes/' . $logo_save_theme . '/images_custom/trimmed-logo.png';
             @imagepng($logo, get_custom_file_base() . '/' . $path) or intelligent_write_error($path);
             actual_edit_theme_image('logo/trimmed-logo', $logo_save_theme, get_site_default_lang(), 'logo/trimmed-logo', $path, true);
             imagedestroy($logo);
         }
         $myfile = fopen(get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/theme.ini', 'wt');
         fwrite($myfile, 'title=' . $name . chr(10));
         fwrite($myfile, 'description=' . do_lang('NA') . chr(10));
         if (fwrite($myfile, 'author=ocPortal' . chr(10)) == 0) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         sync_file(get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/theme.ini');
         $IMG_CODES['site'] = $old_img_codes_site;
         // Just so it renders with the old theme
     }
     // Set options
     if (post_param_integer('skip_3', 0) == 0) {
         set_option('site_name', $name);
         set_option('copyright', 'Copyright © ' . $name . ' ' . date('Y'));
         set_option('description', post_param('description'));
         set_option('site_scope', post_param('site_scope'));
         set_option('copyright', post_param('copyright'));
         set_option('staff_address', post_param('staff_address'));
         set_option('keywords', post_param('keywords'));
         set_option('google_analytics', post_param('google_analytics'));
         set_option('fixed_width', post_param('fixed_width', '0'));
         $a = $GLOBALS['SITE_DB']->query_value('zones', 'zone_header_text', array('zone_name' => ''));
         lang_remap($a, $header_text);
         $b = $GLOBALS['SITE_DB']->query_value_null_ok('zones', 'zone_header_text', array('zone_name' => 'site'));
         if (!is_null($b)) {
             lang_remap($b, $header_text);
         }
     }
     if (post_param_integer('skip_9', 0) == 0) {
         set_option('site_closed', strval(post_param_integer('site_closed', 0)));
         set_option('closed', post_param('closed', ''));
     }
     // Set addons
     if (post_param_integer('skip_4', 0) == 0 && get_file_base() == get_custom_file_base()) {
         require_lang('addons');
         require_code('addons');
         $addons_installed = find_installed_addons();
         $uninstalling = array();
         foreach ($addons_installed as $addon_row) {
             if (post_param_integer('addon_' . $addon_row['addon_name'], 0) == 0) {
                 $uninstalling[$addon_row['addon_name']] = $addon_row;
             }
         }
         if (!file_exists(get_file_base() . '/.svn')) {
             do {
                 $cnt = count($uninstalling);
                 foreach ($addons_installed as $addon_row) {
                     if (array_key_exists($addon_row['addon_name'], $uninstalling)) {
                         $addon_row += read_addon_info($addon_row['addon_name']);
                         $addon_row['addon_author'] = '';
                         // Fudge, to stop it dying on warnings for official addons
                         // Check dependencies
                         $dependencies = $addon_row['addon_dependencies_on_this'];
                         foreach (array_keys($uninstalling) as $d) {
                             if (in_array($d, $dependencies)) {
                                 // Can mark this dependency as irrelevant, as we are uninstalling the addon for it anyway
                                 unset($dependencies[array_search($d, $dependencies)]);
                             }
                         }
                         if (count($dependencies) != 0) {
                             unset($uninstalling[$addon_row['addon_name']]);
                         }
                     }
                 }
             } while ($cnt != count($uninstalling));
             // Dependency chains can be complex, so loop until we're stopped finding anything changing
             foreach ($uninstalling as $addon_row) {
                 // Archive it off to exports/addons
                 if ($addon_row['addon_files'] != '') {
                     $file = preg_replace('#^[\\_\\.\\-]#', 'x', preg_replace('#[^\\w\\.\\-]#', '_', $addon_row['addon_name'])) . '.tar';
                     create_addon($file, explode(chr(10), $addon_row['addon_files']), $addon_row['addon_name'], implode(',', $addon_row['addon_incompatibilities']), implode(',', $addon_row['addon_dependencies']), $addon_row['addon_author'], $addon_row['addon_organisation'], $addon_row['addon_version'], $addon_row['addon_description'], 'imports/addons');
                 }
                 uninstall_addon($addon_row['addon_name']);
             }
         }
     }
     // Set features
     if (post_param_integer('skip_5', 0) == 0) {
         $hooks = find_all_hooks('modules', 'admin_setupwizard');
         foreach (array_keys($hooks) as $hook) {
             if (post_param_integer('addon_' . $hook, 0) == 1) {
                 $path = get_file_base() . '/sources_custom/modules/systems/admin_setupwizard/' . filter_naughty_harsh($hook) . '.php';
                 if (!file_exists($path)) {
                     $path = get_file_base() . '/sources/hooks/modules/admin_setupwizard/' . filter_naughty_harsh($hook) . '.php';
                 }
                 $_hook_bits = extract_module_functions($path, array('set_fields'));
                 if (is_array($_hook_bits[0])) {
                     call_user_func_array($_hook_bits[0][0], $_hook_bits[0][1]);
                 } else {
                     @eval($_hook_bits[0]);
                 }
             }
         }
         set_option('show_content_tagging', post_param('show_content_tagging', '0'));
         set_option('show_content_tagging_inline', post_param('show_content_tagging_inline', '0'));
         set_option('show_screen_actions', post_param('show_screen_actions', '0'));
     }
     // Zone structure
     $collapse_zones = post_param_integer('collapse_user_zones', 0) == 1;
     if (post_param_integer('skip_5', 0) == 0) {
         require_code('config2');
         set_option('collapse_user_zones', strval($collapse_zones));
         /*if (addon_installed('redirects_editor')) Old method
         		{
         			if ($collapse_zones)
         			{
         				$test=$GLOBALS['SITE_DB']->query_value_null_ok('redirects','r_from_page',array('r_from_page'=>'panel_left','r_from_zone'=>'site'));
         				if (is_null($test)) $GLOBALS['SITE_DB']->query_insert('redirects',array('r_from_page'=>'panel_left','r_from_zone'=>'site','r_to_page'=>'panel_left','r_to_zone'=>'','r_is_transparent'=>1));
         				$test=$GLOBALS['SITE_DB']->query_value_null_ok('redirects','r_from_page',array('r_from_page'=>'panel_right','r_from_zone'=>'site'));
         				if (is_null($test)) $GLOBALS['SITE_DB']->query_insert('redirects',array('r_from_page'=>'panel_right','r_from_zone'=>'site','r_to_page'=>'panel_right','r_to_zone'=>'','r_is_transparent'=>1));
         				$test=$GLOBALS['SITE_DB']->query_value_null_ok('redirects','r_from_page',array('r_from_page'=>'start','r_from_zone'=>'site'));
         				if (is_null($test)) $GLOBALS['SITE_DB']->query_insert('redirects',array('r_from_page'=>'start','r_from_zone'=>'site','r_to_page'=>'start','r_to_zone'=>'','r_is_transparent'=>1));
         			} else
         			{
         				$GLOBALS['SITE_DB']->query_delete('redirects',array('r_from_page'=>'panel_left','r_from_zone'=>'site','r_to_page'=>'panel_left','r_to_zone'=>''),'',1);
         				$GLOBALS['SITE_DB']->query_delete('redirects',array('r_from_page'=>'panel_right','r_from_zone'=>'site','r_to_page'=>'panel_right','r_to_zone'=>''),'',1);
         				$GLOBALS['SITE_DB']->query_delete('redirects',array('r_from_page'=>'start','r_from_zone'=>'site','r_to_page'=>'start','r_to_zone'=>''),'',1);
         			}
         		}*/
         if (post_param_integer('guest_zone_access', 0) == 1) {
             $guest_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups($GLOBALS['FORUM_DRIVER']->get_guest_id());
             $test = $GLOBALS['SITE_DB']->query_value_null_ok('group_zone_access', 'zone_name', array('zone_name' => 'site', 'group_id' => $guest_groups[0]));
             if (is_null($test)) {
                 $GLOBALS['SITE_DB']->query_insert('group_zone_access', array('zone_name' => 'site', 'group_id' => $guest_groups[0]));
             }
         }
     }
     // Rules
     if (post_param_integer('skip_7', 0) == 0) {
         $fullpath = get_custom_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/rules.txt';
         if (file_exists($fullpath)) {
             @copy($fullpath, $fullpath . '.' . strval(time()));
             fix_permissions($fullpath . '.' . strval(time()));
             sync_file($fullpath . '.' . strval(time()));
         }
         $myfile = @fopen($fullpath, 'wt') or intelligent_write_error(get_custom_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/rules.txt');
         $rf = $this->get_rules_file(post_param('rules'));
         if (fwrite($myfile, $rf) < strlen($rf)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         fix_permissions($fullpath);
         sync_file($fullpath);
     }
     $block_options = mixed();
     if ($installprofile != '' && !is_null($object)) {
         $block_options = $object->block_options();
     }
     // Blocks
     if (post_param_integer('skip_6', 0) == 0) {
         require_code('setupwizard');
         $page_structure = _get_zone_pages($installprofileblocks, $block_options, $collapse_zones, $installprofile);
         foreach ($page_structure as $zone => $zone_pages) {
             // Start
             $fullpath = get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/start.txt';
             if (file_exists($fullpath)) {
                 @copy($fullpath, $fullpath . '.' . strval(time()));
             }
             $myfile = @fopen($fullpath, 'wt') or intelligent_write_error($fullpath);
             if ($myfile !== false) {
                 if ($zone_pages['start'] != '') {
                     if (fwrite($myfile, $zone_pages['start']) == 0) {
                         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                     }
                 }
                 fclose($myfile);
                 fix_permissions($fullpath);
                 sync_file($fullpath);
             }
             // Left
             $fullpath = get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/panel_left.txt';
             if (file_exists($fullpath)) {
                 @copy($fullpath, $fullpath . '.' . strval(time()));
             }
             $myfile = @fopen($fullpath, 'wt');
             if ($myfile !== false) {
                 if ($zone_pages['left'] != '') {
                     if (fwrite($myfile, $zone_pages['left']) == 0) {
                         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                     }
                 }
                 fclose($myfile);
                 fix_permissions($fullpath);
                 sync_file($fullpath);
             }
             // Right
             $fullpath = get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/panel_right.txt';
             if (file_exists($fullpath)) {
                 @copy($fullpath, $fullpath . '.' . strval(time()));
             }
             $myfile = fopen($fullpath, 'wt');
             if ($myfile !== false) {
                 if ($zone_pages['right'] != '') {
                     if (fwrite($myfile, $zone_pages['right']) == 0) {
                         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                     }
                 }
                 fclose($myfile);
                 fix_permissions($fullpath);
                 sync_file($fullpath);
             }
         }
     }
     // We're done
     set_value('setup_wizard_completed', '1');
     // Clear some cacheing
     require_code('view_modes');
     require_code('zones3');
     erase_comcode_page_cache();
     erase_tempcode_cache();
     //persistant_cache_delete('OPTIONS');  Done by set_option
     persistant_cache_empty();
     erase_cached_templates();
     //breadcrumb_set_parents(array(array('_SELF:_SELF:misc',do_lang_tempcode('START'))));
     //breadcrumb_set_self(do_lang_tempcode('SETUP_WIZARD_STEP',integer_format(10),integer_format(10)));
     $url = build_url(array('page' => '_SELF', 'type' => 'step11'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
예제 #2
0
 /**
  * The main UI.
  *
  * @return tempcode		The UI
  */
 function gui()
 {
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/addons';
     $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_adv_configuration';
     if (function_exists('set_time_limit')) {
         @set_time_limit(180);
     }
     // So it can scan inside addons
     $title = get_page_title('ADDONS');
     $addons_installed = find_installed_addons();
     $addons_available_for_installation = find_available_addons();
     $_tpl_addons = array();
     // Show installed addons
     foreach ($addons_installed as $row) {
         $actions = do_template('TABLE_TABLE_ACTION_DELETE_ENTRY', array('GET' => true, 'NAME' => $row['addon_name'], 'URL' => build_url(array('page' => '_SELF', 'type' => 'addon_uninstall', 'name' => $row['addon_name']), '_SELF')));
         $status = do_lang_tempcode('STATUS_INSTALLED');
         $description = $row['addon_description'];
         $file_list = $row['addon_files'];
         $_tpl_addons[$row['addon_name']] = do_template('ADDON_SCREEN_ADDON', array('_GUID' => '9a06f5a9c9e3085c10ab7fb17c3efcd1', 'DESCRIPTION' => $description, 'FILE_LIST' => $file_list, 'COLOUR' => 'green', 'STATUS' => $status, 'NAME' => $row['addon_name'], 'FILENAME' => do_lang_tempcode('NA_EM'), 'AUTHOR' => $row['addon_author'], 'ORGANISATION' => $row['addon_organisation'], 'VERSION' => $row['addon_version'], 'ACTIONS' => $actions, 'TYPE' => 'uninstall', 'PASSTHROUGH' => $row['addon_name']));
     }
     // Show addons available for installation
     foreach ($addons_available_for_installation as $filename => $addon) {
         if (!array_key_exists($addon['name'], $addons_installed)) {
             $actions = do_template('TABLE_TABLE_ACTION_INSTALL_ENTRY', array('_GUID' => 'e6e2bdac62c0d3afcd5251b3d525a1c9', 'GET' => true, 'NAME' => $addon['name'], 'HIDDEN' => '', 'URL' => build_url(array('page' => '_SELF', 'type' => 'addon_install', 'file' => $filename), '_SELF')));
             $status = do_lang_tempcode('STATUS_NOT_INSTALLED');
             $description = $addon['description'];
             $file_list = $addon['files'];
             if ($addon['version'] == '(version-synched)') {
                 $addon['version'] = float_to_raw_string(ocp_version_number());
             }
             $_tpl_addons[$addon['name']] = do_template('ADDON_SCREEN_ADDON', array('_GUID' => 'cb61bdb9ce0cef5cd520440c5f62008f', 'DESCRIPTION' => $description, 'FILE_LIST' => $file_list, 'COLOUR' => 'orange', 'STATUS' => $status, 'NAME' => $addon['name'], 'FILENAME' => $filename, 'AUTHOR' => $addon['author'], 'ORGANISATION' => $addon['organisation'], 'VERSION' => $addon['version'], 'ACTIONS' => $actions, 'TYPE' => 'install', 'PASSTHROUGH' => $filename));
         }
     }
     ksort($_tpl_addons);
     $tpl_addons = new ocp_tempcode();
     foreach ($_tpl_addons as $t) {
         $tpl_addons->attach($t);
     }
     $multi_action = build_url(array('page' => '_SELF', 'type' => 'multi_action'), '_SELF');
     return do_template('ADDON_SCREEN', array('_GUID' => 'ed6c80c29fcae333323ef03619954b6b', 'TITLE' => $title, 'ADDONS' => $tpl_addons, 'MULTI_ACTION' => $multi_action));
 }