/**
 * Load all needed hooks
 */
function loadMenuButtonWithBoardsListHooks()
{
    add_integration_function('integrate_admin_areas', 'addMenuButtonWithBoardsListAdminArea', false);
    add_integration_function('integrate_modify_modifications', 'addMenuButtonWithBoardsListAdminAction', false);
    add_integration_function('integrate_menu_buttons', 'addMenuButtonWithBoardsList', false);
    add_integration_function('integrate_menu_buttons', 'addMenuButtonWithBoardsListCopyright', false);
}
/**
 * Load all needed hooks
 */
function loadMathJaxHooks()
{
    add_integration_function('integrate_load_theme', 'loadMathJaxJs', false);
    add_integration_function('integrate_bbc_buttons', 'addMathJaxBbcButton', false);
    add_integration_function('integrate_bbc_codes', 'addMathJaxBbcCode', false);
    add_integration_function('integrate_menu_buttons', 'addMathJaxCopyright', false);
}
Example #3
0
 public function installIntegration($forumDirectoryPath)
 {
     try {
         //Using SMF native functions
         $smfSSI = DRUPAL_ROOT . '/' . $forumDirectoryPath . '/SSI.php';
         if (file_exists($smfSSI)) {
             require_once $smfSSI;
             add_integration_function('integrate_pre_include', DRUPAL_ROOT . '/' . drupal_get_path('module', 'smfbridge') . '/src/Smf/Hooks.php');
             add_integration_function('integrate_actions', 'Drupal\\smfbridge\\Smf\\Hooks::actions', TRUE);
             add_integration_function('integrate_menu_buttons', 'Drupal\\smfbridge\\Smf\\Hooks::smfMenuButtons', TRUE);
             //Use database driven sessions - on
             $this->updateSmfSettingsValues('databaseSession_enable', '1');
             /**
              * @var \Drupal\Core\Session\SessionConfiguration $sessionConfiguration
              */
             $sessionConfiguration = \Drupal::service('session_configuration');
             $options = $sessionConfiguration->getOptions(\Drupal::request());
             $this->updateSmfSettingsValues('databaseSession_lifetime', $options['gc_maxlifetime']);
         } else {
             throw new \Exception(t('Can\'t forum/SSI.php. Please, place SMF sources into DRUPAL_ROOT/forum folder.'));
         }
         return TRUE;
     } catch (\Exception $e) {
         $errorMsg = t('Error while enabling smfbridge. @message', ['@message' => $e->getMessage()]);
         \Drupal::logger('smfbridge')->error($errorMsg);
         drupal_set_message($errorMsg, 'error');
         return FALSE;
     }
 }
Example #4
0
 /**
  * Tests adding hooks in some different ways
  */
 function testAddHooks()
 {
     global $modSettings;
     foreach ($this->_tests as $test) {
         add_integration_function($this->_hook_name, $test['call'], $test['file'], $test['perm']);
         $this->assertTrue($this->_hook_exists($test, $test['perm']));
     }
 }
/**
 * Load all needed hooks
 */
function loadLegacyKarmaHooks()
{
    global $modSettings;
    add_integration_function('integrate_general_mod_settings', 'changeLegacyKarmaSettings', false);
    add_integration_function('integrate_menu_buttons', 'addLegacyKarmaCopyright', false);
    if (empty($modSettings['legacy_karma_enabled'])) {
        return;
    }
    add_integration_function('integrate_menu_buttons', 'printLegacyKarmaForMember', false);
    //add_integration_function('integrate_query_message', 'showLegacyKarmaInMessage', false);
    // TODO calculate summary likes and show it or sum with legacy
}
Example #6
0
/**
 * Load the $modSettings array and many necessary forum settings.
 *
 * What it does:
 * - load the settings from cache if available, otherwse from the database.
 * - sets the timezone
 * - checks the load average settings if available.
 * - check whether post moderation is enabled.
 * - calls add_integration_function
 * - calls integrate_pre_include, integrate_pre_load,
 *
 * @global array $modSettings is a giant array of all of the forum-wide settings and statistics.
 */
function reloadSettings()
{
    global $modSettings;
    $db = database();
    // Try to load it from the cache first; it'll never get cached if the setting is off.
    if (($modSettings = cache_get_data('modSettings', 90)) == null) {
        $request = $db->query('', '
			SELECT variable, value
			FROM {db_prefix}settings', array());
        $modSettings = array();
        if (!$request) {
            display_db_error();
        }
        while ($row = $db->fetch_row($request)) {
            $modSettings[$row[0]] = $row[1];
        }
        $db->free_result($request);
        // Do a few things to protect against missing settings or settings with invalid values...
        if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
            $modSettings['defaultMaxTopics'] = 20;
        }
        if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
            $modSettings['defaultMaxMessages'] = 15;
        }
        if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
            $modSettings['defaultMaxMembers'] = 30;
        }
        if (empty($modSettings['subject_length'])) {
            $modSettings['subject_length'] = 24;
        }
        $modSettings['warning_enable'] = $modSettings['warning_settings'][0];
        if (!empty($modSettings['cache_enable'])) {
            cache_put_data('modSettings', $modSettings, 90);
        }
    }
    // Setting the timezone is a requirement for some functions in PHP >= 5.1.
    if (isset($modSettings['default_timezone'])) {
        date_default_timezone_set($modSettings['default_timezone']);
    }
    // Check the load averages?
    if (!empty($modSettings['loadavg_enable'])) {
        if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) {
            $modSettings['load_average'] = detectServerLoad();
            cache_put_data('loadavg', $modSettings['load_average'], 90);
        }
        if ($modSettings['load_average'] !== false) {
            call_integration_hook('integrate_load_average', array($modSettings['load_average']));
        }
        // Let's have at least a zero
        if (empty($modSettings['loadavg_forum']) || $modSettings['load_average'] === false) {
            $modSettings['current_load'] = 0;
        } else {
            $modSettings['current_load'] = $modSettings['load_average'];
        }
        if (!empty($modSettings['loadavg_forum']) && $modSettings['current_load'] >= $modSettings['loadavg_forum']) {
            display_loadavg_error();
        }
    } else {
        $modSettings['current_load'] = 0;
    }
    // Is post moderation alive and well?
    $modSettings['postmod_active'] = isset($modSettings['admin_features']) ? in_array('pm', explode(',', $modSettings['admin_features'])) : true;
    // Here to justify the name of this function. :P
    // It should be added to the install and upgrade scripts.
    // But since the convertors need to be updated also. This is easier.
    if (empty($modSettings['currentAttachmentUploadDir'])) {
        updateSettings(array('attachmentUploadDir' => serialize(array(1 => $modSettings['attachmentUploadDir'])), 'currentAttachmentUploadDir' => 1));
    }
    // Integration is cool.
    if (defined('ELK_INTEGRATION_SETTINGS')) {
        $integration_settings = unserialize(ELK_INTEGRATION_SETTINGS);
        foreach ($integration_settings as $hook => $function) {
            add_integration_function($hook, $function);
        }
    }
    // Any files to pre include?
    call_integration_include_hook('integrate_pre_include');
    // Call pre load integration functions.
    call_integration_hook('integrate_pre_load');
}
        $found['id'] = $row['id_install'];
        $found['themes'] = $row['themes_installed'];
    }
    $smcFunc['db_free_result']($request);
    if (!empty($found['id'])) {
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}log_packages
			SET package_id = {string:pkgid}, db_changes = {string:dbchg},' . (!empty($found['themes']) ? ' themes_installed = {string:thchg},' : '') . ' install_state = 1
			WHERE id_install = {int:id}', array('id' => $found['id'], 'pkgid' => 'portamx_corp:PortaMx', 'thchg' => !empty($found['themes']) ? $found['themes'] : '', 'dbchg' => serialize($dbupdates)));
    }
}
// setup all the hooks we use
_dbinst_write($newline . 'Setup integration functions.' . $newline);
$hooklist = array('integrate_pre_include' => '$sourcedir/PortaMx/PortaMxLoader.php', 'integrate_buffer' => 'ob_portamx', 'integrate_actions' => 'PortaMx_Actions', 'integrate_admin_areas' => 'PortaMx_AdminMenu', 'integrate_dynamic_buttons' => 'PortaMx_MenuContext', 'integrate_whos_online' => 'PortaMx_whos_online', 'integrate_load_theme' => 'pmx_eclnonemodal', 'integrate_pre_css_output' => 'PortaMx_loadCSS');
foreach ($hooklist as $hook => $function) {
    add_integration_function($hook, $function, true, '', false);
}
// update pmxsef settings
_dbinst_write('Setup SEF settings.' . $newline);
$sefsettings = array('pmxsef_autosave' => '0', 'pmxsef_singletoken' => 'add,advanced,all,asc,calendar,check,children,conversation,desc,home,image,kstart,moderate,nw,profile,save,sound,togglebar,topicseen,view,viewweek,xml', 'pmxsef_actions' => 'about:mozilla,about:unknown,activate,announce,attachapprove,buddy,calendar,clock,collapse,community,coppa,credits,deletemsg,display,dlattach,editpoll,editpoll2,emailuser,findmember,groups,help,helpadmin,im,jseditor,jsmodify,jsoption,keepalive,lock,lockvoting,login,login2,logout,markasread,mergetopics,mlist,moderate,modifycat,modifykarma,movetopic,movetopic2,notify,notifyboard,openidreturn,pm,post,post2,printpage,profile,promote,quotefast,quickmod,quickmod2,recent,register,register2,reminder,removepoll,removetopic2,reporttm,requestmembers,restoretopic,search,search2,sendtopic,smstats,suggest,spellcheck,splittopics,stats,sticky,trackip,unread,unreadreplies,verificationcode,viewprofile,vote,viewquery,viewsmfile,who,.xml,xmlhttp,theme,notifytopic,likes,signup,loadeditorlocale,xml', 'pmxsef_ignoreactions' => '', 'pmxsef_aliasactions' => serialize(array()), 'pmxsef_ignorerequests' => serialize(array()), 'pmxsef_codepages' => '/PortaMx/sefcodepages/x');
foreach ($sefsettings as $sefname => $value) {
    $smcFunc['db_insert']('replace', '
		{db_prefix}settings', array('variable' => 'string', 'value' => 'string'), array($sefname, $value), array('variable'));
}
// other settings
_dbinst_write('Setup global settings.' . $newline);
$othersettings = array('pmx_ecl' => '0', 'pmx_eclmodal' => '0', 'pmx_eclmodalaction' => 'calendar,markasread,mlist,search,search2,stats,who,post', 'pmx_eclmodalmobi' => '0', 'pmx_eclmodaltop' => '32', 'pmx_frontmode' => '1', 'pmx_fronttheme' => '0', 'pmx_frontthempg' => '0');
foreach ($othersettings as $name => $value) {
    $smcFunc['db_insert']('replace', '
		{db_prefix}settings', array('variable' => 'string', 'value' => 'string'), array($name, $value), array('variable'));
}
Example #8
0
<?php

add_integration_function('integrate_load_theme', 'cleantalk_load');
// flush settings cache
cache_put_data('modSettings', null, 1);
Example #9
0
function integrate_chars()
{
    global $user_info, $user_settings, $txt, $modSettings;
    $user_info += ['id_character' => isset($user_settings['id_character']) ? (int) $user_settings['id_character'] : 0, 'character_name' => isset($user_settings['character_name']) ? $user_settings['character_name'] : (isset($user_settings['real_name']) ? $user_settings['real_name'] : ''), 'char_avatar' => isset($user_settings['char_avatar']) ? $user_settings['char_avatar'] : '', 'char_signature' => isset($user_settings['char_signature']) ? $user_settings['char_signature'] : '', 'char_is_main' => !empty($user_settings['is_main']), 'immersive_mode' => !empty($user_settings['immersive_mode'])];
    // Because we're messing with member groups, we need to tweak a few things.
    // We need to glue their groups together for the purposes of permissions.
    // But we also need to consider whether they're in immersive mode or not
    // to recalculate board access.
    $original_groups = $user_info['groups'];
    $with_char_groups = $user_info['groups'];
    if (!empty($user_settings['main_char_group'])) {
        $with_char_groups[] = $user_settings['main_char_group'];
    }
    if (!empty($user_settings['char_groups'])) {
        $with_char_groups = array_merge($with_char_groups, array_diff(array_map('intval', explode(',', $user_settings['char_groups'])), [0]));
    }
    // At this point, we already built access based on account level groups
    // but if we're in immersive mode we need to include character groups
    // - unless admin, because admin implicitly has everything anyway.
    if ($user_info['immersive_mode'] && !$user_info['is_admin']) {
        $user_info['original_query_see_board'] = $user_info['query_see_board'];
        $user_info['original_query_wanna_see_board'] = $user_info['query_wanna_see_board'];
        $user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $with_char_groups) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $with_char_groups) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
        if (empty($user_info['ignoreboards'])) {
            $user_info['query_wanna_see_board'] = $user_info['query_see_board'];
        } else {
            $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
        }
    }
    // And now glue account plus current character together for permissions.
    $user_info['groups'] = $with_char_groups;
    // And since this is now done early in the process, but after language is identified...
    loadLanguage('characters/Characters');
    // We can now also hook the rest of the characters stuff, meaning we
    // only need to remember and manage one hook in the installer.
    add_integration_function('integrate_buffer', 'integrate_chars_buffer', false);
    add_integration_function('integrate_pre_profile_areas', 'chars_profile_menu', false, '$sourcedir/Profile-Chars.php');
    add_integration_function('integrate_admin_areas', 'integrate_chars_admin_actions', false, '$sourcedir/Admin-Chars.php');
    add_integration_function('integrate_load_profile_fields', 'chars_profile_field', false, '$sourcedir/Profile-Chars.php');
    add_integration_function('integrate_autosuggest', 'integrate_character_autosuggest', false, '$sourcedir/AutoSuggest-Chars.php');
    add_integration_function('integrate_menu_buttons', 'integrate_chars_main_menu', false);
    add_integration_function('integrate_query_message', 'integrate_get_chars_messages', false);
    add_integration_function('integrate_prepare_display_context', 'integrate_display_chars_messages', false);
    add_integration_function('integrate_create_post', 'integrate_create_post_character', false);
    add_integration_function('integrate_load_member_data', 'integrate_load_member_data_chars', false);
    add_integration_function('integrate_member_context', 'integrate_membercontext_chars', false);
    add_integration_function('integrate_after_create_post', 'integrate_character_post_count', false);
    add_integration_function('integrate_load_permissions', 'integrate_chars_permissions', false, '$sourcedir/Admin-Chars.php');
    add_integration_function('integrate_create_board', 'integrate_chars_create_board', false, '$sourcedir/Admin-Chars.php');
    add_integration_function('integrate_message_index', 'integrate_message_index_chars', false);
    add_integration_function('integrate_display_topic', 'integrate_display_topic_chars', false);
    add_integration_function('integrate_search_message_context', 'integrate_search_message_chars', false);
    add_integration_function('integrate_actions', 'integrate_chars_actions', false);
    add_integration_function('integrate_delete_members', 'integrate_delete_members_chars', false, '$sourcedir/Admin-Chars.php');
    add_integration_function('integrate_register_check', 'integrate_register_check_chars', false);
    add_integration_function('integrate_register', 'integrate_register_chars', false);
    add_integration_function('integrate_post_register', 'integrate_post_register_chars', false);
    add_integration_function('integrate_change_member_data', 'integrate_chars_change_member_data', false);
}
Example #10
0
 /**
  * Apply another type of (avatar, language, etc.) package.
  */
 public function action_install2()
 {
     global $txt, $context, $boardurl, $scripturl, $modSettings;
     // Make sure we don't install this mod twice.
     checkSubmitOnce('check');
     checkSession();
     // If there's no file, what are we installing?
     if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
         redirectexit('action=admin;area=packages');
     }
     $context['filename'] = $_REQUEST['package'];
     // If this is an uninstall, we'll have an id.
     $context['install_id'] = isset($_REQUEST['pid']) ? (int) $_REQUEST['pid'] : 0;
     require_once SUBSDIR . '/Package.subs.php';
     require_once SUBSDIR . '/Themes.subs.php';
     // @todo Perhaps do it in steps, if necessary?
     $context['uninstalling'] = $_REQUEST['sa'] == 'uninstall2';
     // Set up the linktree for other.
     $context['linktree'][count($context['linktree']) - 1] = array('url' => $scripturl . '?action=admin;area=packages;sa=browse', 'name' => $context['uninstalling'] ? $txt['uninstall'] : $txt['extracting']);
     $context['page_title'] .= ' - ' . ($context['uninstalling'] ? $txt['uninstall'] : $txt['extracting']);
     $context['sub_template'] = 'extract_package';
     if (!file_exists(BOARDDIR . '/packages/' . $context['filename'])) {
         fatal_lang_error('package_no_file', false);
     }
     // Load up the package FTP information?
     create_chmod_control(array(), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package']));
     // Make sure temp directory exists and is empty!
     if (file_exists(BOARDDIR . '/packages/temp')) {
         deltree(BOARDDIR . '/packages/temp', false);
     } else {
         mktree(BOARDDIR . '/packages/temp', 0777);
     }
     // Let the unpacker do the work.
     if (is_file(BOARDDIR . '/packages/' . $context['filename'])) {
         $context['extracted_files'] = read_tgz_file(BOARDDIR . '/packages/' . $context['filename'], BOARDDIR . '/packages/temp');
         if (!file_exists(BOARDDIR . '/packages/temp/package-info.xml')) {
             foreach ($context['extracted_files'] as $file) {
                 if (basename($file['filename']) == 'package-info.xml') {
                     $context['base_path'] = dirname($file['filename']) . '/';
                     break;
                 }
             }
         }
         if (!isset($context['base_path'])) {
             $context['base_path'] = '';
         }
     } elseif (is_dir(BOARDDIR . '/packages/' . $context['filename'])) {
         copytree(BOARDDIR . '/packages/' . $context['filename'], BOARDDIR . '/packages/temp');
         $context['extracted_files'] = listtree(BOARDDIR . '/packages/temp');
         $context['base_path'] = '';
     } else {
         fatal_lang_error('no_access', false);
     }
     // Are we installing this into any custom themes?
     $custom_themes = array(1);
     $known_themes = explode(',', $modSettings['knownThemes']);
     if (!empty($_POST['custom_theme'])) {
         foreach ($_POST['custom_theme'] as $tid) {
             if (in_array($tid, $known_themes)) {
                 $custom_themes[] = (int) $tid;
             }
         }
     }
     // Now load up the paths of the themes that we need to know about.
     $theme_paths = getThemesPathbyID($custom_themes);
     $themes_installed = array(1);
     // Are there any theme copying that we want to take place?
     $context['theme_copies'] = array('require-file' => array(), 'require-dir' => array());
     if (!empty($_POST['theme_changes'])) {
         foreach ($_POST['theme_changes'] as $change) {
             if (empty($change)) {
                 continue;
             }
             $theme_data = unserialize(base64_decode($change));
             if (empty($theme_data['type'])) {
                 continue;
             }
             $themes_installed[] = $theme_data['id'];
             $context['theme_copies'][$theme_data['type']][$theme_data['orig']][] = $theme_data['future'];
         }
     }
     // Get the package info...
     $packageInfo = getPackageInfo($context['filename']);
     if (!is_array($packageInfo)) {
         fatal_lang_error($packageInfo);
     }
     $packageInfo['filename'] = $context['filename'];
     // Set the type of extraction...
     $context['extract_type'] = isset($packageInfo['type']) ? $packageInfo['type'] : 'modification';
     // Create a backup file to roll back to! (but if they do this more than once, don't run it a zillion times.)
     if (!empty($modSettings['package_make_full_backups']) && (!isset($_SESSION['last_backup_for']) || $_SESSION['last_backup_for'] != $context['filename'] . ($context['uninstalling'] ? '$$' : '$'))) {
         $_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$');
         // @todo Internationalize this?
         package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.'));
     }
     // The mod isn't installed.... unless proven otherwise.
     $context['is_installed'] = false;
     // Is it actually installed?
     $package_installed = isPackageInstalled($packageInfo['id']);
     // Wait, it's not installed yet!
     // @todo Replace with a better error message!
     if (!isset($package_installed['old_version']) && $context['uninstalling']) {
         deltree(BOARDDIR . '/packages/temp');
         fatal_error('Hacker?', false);
     } elseif ($context['uninstalling']) {
         $install_log = parsePackageInfo($packageInfo['xml'], false, 'uninstall');
         // Gadzooks!  There's no uninstaller at all!?
         if (empty($install_log)) {
             fatal_lang_error('package_uninstall_cannot', false);
         }
         // They can only uninstall from what it was originally installed into.
         foreach ($theme_paths as $id => $data) {
             if ($id != 1 && !in_array($id, $package_installed['old_themes'])) {
                 unset($theme_paths[$id]);
             }
         }
     } elseif (isset($package_installed['old_version']) && $package_installed['old_version'] != $packageInfo['version']) {
         // Look for an upgrade...
         $install_log = parsePackageInfo($packageInfo['xml'], false, 'upgrade', $package_installed['old_version']);
         // There was no upgrade....
         if (empty($install_log)) {
             $context['is_installed'] = true;
         } else {
             // Upgrade previous themes only!
             foreach ($theme_paths as $id => $data) {
                 if ($id != 1 && !in_array($id, $package_installed['old_themes'])) {
                     unset($theme_paths[$id]);
                 }
             }
         }
     } elseif (isset($package_installed['old_version']) && $package_installed['old_version'] == $packageInfo['version']) {
         $context['is_installed'] = true;
     }
     if (!isset($package_installed['old_version']) || $context['is_installed']) {
         $install_log = parsePackageInfo($packageInfo['xml'], false, 'install');
     }
     $context['install_finished'] = false;
     // We're gonna be needing the table db functions! ...Sometimes.
     $table_installer = db_table();
     // @todo Make a log of any errors that occurred and output them?
     if (!empty($install_log)) {
         $failed_steps = array();
         $failed_count = 0;
         foreach ($install_log as $action) {
             $failed_count++;
             if ($action['type'] == 'modification' && !empty($action['filename'])) {
                 if ($action['boardmod']) {
                     $mod_actions = parseBoardMod(file_get_contents(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
                 } else {
                     $mod_actions = parseModification(file_get_contents(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
                 }
                 // Any errors worth noting?
                 foreach ($mod_actions as $key => $action) {
                     if ($action['type'] == 'failure') {
                         $failed_steps[] = array('file' => $action['filename'], 'large_step' => $failed_count, 'sub_step' => $key, 'theme' => 1);
                     }
                     // Gather the themes we installed into.
                     if (!empty($action['is_custom'])) {
                         $themes_installed[] = $action['is_custom'];
                     }
                 }
             } elseif ($action['type'] == 'code' && !empty($action['filename'])) {
                 // This is just here as reference for what is available.
                 global $txt, $modSettings, $context;
                 // Now include the file and be done with it ;).
                 if (file_exists(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename'])) {
                     require BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename'];
                 }
             } elseif ($action['type'] == 'credits') {
                 // Time to build the billboard
                 $credits_tag = array('url' => $action['url'], 'license' => $action['license'], 'copyright' => $action['copyright'], 'title' => $action['title']);
             } elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function'])) {
                 if ($action['reverse']) {
                     remove_integration_function($action['hook'], $action['function'], $action['include_file']);
                 } else {
                     add_integration_function($action['hook'], $action['function'], $action['include_file']);
                 }
             } elseif ($action['type'] == 'database' && !empty($action['filename']) && (!$context['uninstalling'] || !empty($_POST['do_db_changes']))) {
                 // These can also be there for database changes.
                 global $txt, $modSettings, $context;
                 // Let the file work its magic ;)
                 if (file_exists(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename'])) {
                     require BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename'];
                 }
             } elseif ($action['type'] == 'redirect' && !empty($action['redirect_url'])) {
                 $context['redirect_url'] = $action['redirect_url'];
                 $context['redirect_text'] = !empty($action['filename']) && file_exists(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename']) ? file_get_contents(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename']) : ($context['uninstalling'] ? $txt['package_uninstall_done'] : $txt['package_installed_done']);
                 $context['redirect_timeout'] = $action['redirect_timeout'];
                 // Parse out a couple of common urls.
                 $urls = array('$boardurl' => $boardurl, '$scripturl' => $scripturl, '$session_var' => $context['session_var'], '$session_id' => $context['session_id']);
                 $context['redirect_url'] = strtr($context['redirect_url'], $urls);
             }
         }
         package_flush_cache();
         // First, ensure this change doesn't get removed by putting a stake in the ground (So to speak).
         package_put_contents(BOARDDIR . '/packages/installed.list', time());
         // See if this is already installed
         $is_upgrade = false;
         $old_db_changes = array();
         $package_check = isPackageInstalled($packageInfo['id']);
         // Change the installed state as required.
         if (!empty($package_check['install_state'])) {
             if ($context['uninstalling']) {
                 setPackageState($package_check['package_id']);
             } else {
                 // not uninstalling so must be an upgrade
                 $is_upgrade = true;
                 $old_db_changes = empty($package_check['db_changes']) ? array() : $package_check['db_changes'];
             }
         }
         // Assuming we're not uninstalling, add the entry.
         if (!$context['uninstalling']) {
             // Any db changes from older version?
             $table_log = $table_installer->package_log();
             if (!empty($old_db_changes)) {
                 $db_package_log = empty($table_log) ? $old_db_changes : array_merge($old_db_changes, $table_log);
             } else {
                 $db_package_log = $table_log;
             }
             // If there are some database changes we might want to remove then filter them out.
             if (!empty($db_package_log)) {
                 // We're really just checking for entries which are create table AND add columns (etc).
                 $tables = array();
                 usort($db_package_log, array($this, '_sort_table_first'));
                 foreach ($db_package_log as $k => $log) {
                     if ($log[0] == 'remove_table') {
                         $tables[] = $log[1];
                     } elseif (in_array($log[1], $tables)) {
                         unset($db_package_log[$k]);
                     }
                 }
                 $package_installed['db_changes'] = serialize($db_package_log);
             } else {
                 $package_installed['db_changes'] = '';
             }
             // What themes did we actually install?
             $themes_installed = array_unique($themes_installed);
             $themes_installed = implode(',', $themes_installed);
             // What failed steps?
             $failed_step_insert = serialize($failed_steps);
             // Credits tag?
             $credits_tag = empty($credits_tag) ? '' : serialize($credits_tag);
             // Add to the log packages
             addPackageLog($packageInfo, $failed_step_insert, $themes_installed, $package_installed['db_changes'], $is_upgrade, $credits_tag);
         }
         $context['install_finished'] = true;
     }
     // If there's database changes - and they want them removed - let's do it last!
     if (!empty($package_installed['db_changes']) && !empty($_POST['do_db_changes'])) {
         foreach ($package_installed['db_changes'] as $change) {
             if ($change[0] == 'remove_table' && isset($change[1])) {
                 $table_installer->db_drop_table($change[1]);
             } elseif ($change[0] == 'remove_column' && isset($change[2])) {
                 $table_installer->db_remove_column($change[1], $change[2]);
             } elseif ($change[0] == 'remove_index' && isset($change[2])) {
                 $table_installer->db_remove_index($change[1], $change[2]);
             }
         }
     }
     // Clean house... get rid of the evidence ;).
     if (file_exists(BOARDDIR . '/packages/temp')) {
         deltree(BOARDDIR . '/packages/temp');
     }
     // Log what we just did.
     logAction($context['uninstalling'] ? 'uninstall_package' : (!empty($is_upgrade) ? 'upgrade_package' : 'install_package'), array('package' => Util::htmlspecialchars($packageInfo['name']), 'version' => Util::htmlspecialchars($packageInfo['version'])), 'admin');
     // Just in case, let's clear the whole cache to avoid anything going up the swanny.
     clean_cache();
     // Restore file permissions?
     create_chmod_control(array(), array(), true);
 }
Example #11
0
				ALTER TABLE ' . $table['table_name'] . '
				ADD FULLTEXT {raw:index} ({raw:index})', ['index' => $index]);
        }
    }
}
// Create new rows, if any
foreach ($rows as $row) {
    $smcFunc['db_insert']($row['method'], $row['table_name'], $row['columns'], $row['data'], $row['keys']);
}
// Create new columns, if any
foreach ($columns as $column) {
    $smcFunc['db_add_column']($column['table_name'], $column['column_info'], $column['parameters'], $column['if_exists'], $column['error']);
}
// Add integration hooks, if any
foreach ($hooks as $hook) {
    add_integration_function($hook['hook'], $hook['function'], $hook['perm'], !empty($hook['file']) ? $hook['file'] : '');
}
// Create characters if an account doesn't have characters
$insert_rows = [];
$result = $smcFunc['db_query']('', '
	SELECT mem.id_member, mem.real_name, COUNT(id_character) AS count
	FROM {db_prefix}members AS mem
	LEFT JOIN {db_prefix}characters AS chars ON (mem.id_member = chars.id_member)
	GROUP BY mem.id_member HAVING count = 0');
while ($row = $smcFunc['db_fetch_assoc']($result)) {
    $insert_rows[] = [$row['id_member'], $row['real_name'], '', '', 0, 0, '', time(), 0, 1, 0, ''];
}
$smcFunc['db_free_result']($result);
if (!empty($insert_rows)) {
    foreach ($insert_rows as $new_row) {
        $smcFunc['db_insert']('insert', '{db_prefix}characters', ['id_member' => 'int', 'character_name' => 'string', 'avatar' => 'string', 'signature' => 'string', 'id_theme' => 'int', 'posts' => 'int', 'age' => 'string', 'date_created' => 'int', 'last_active' => 'int', 'is_main' => 'int', 'main_char_group' => 'int', 'char_groups' => 'string'], $new_row, []);
Example #12
0
 /**
  * Installs the hooks to be used by this module.
  */
 public function installHooks()
 {
     foreach ($this->hooks as $hook) {
         add_integration_function($hook, __CLASS__ . '::handleHook', $this->persistHooks);
     }
 }
Example #13
0
<?php

if (!defined('SMF')) {
    require_once 'SSI.php';
}
add_integration_function('integrate_pre_include', '$sourcedir/og.php');
add_integration_function('integrate_bbc_codes', 'og_bbc');
add_integration_function('integrate_modify_modifications', 'og_admin');
add_integration_function('integrate_admin_areas', 'og_admin_areas');
$smcFunc['db_query']('', "INSERT INTO {db_prefix}scheduled_tasks (time_offset, time_regularity, time_unit, disabled, task) VALUES ('0', '1', 'w', '0', 'og_prune')");
Example #14
0
	FROM {db_prefix}arcade_categories');
list($count) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
if ($count == 0 || $forced) {
    $smcFunc['db_insert']('insert', '{db_prefix}arcade_categories', array('cat_name' => 'string', 'member_groups' => 'string', 'cat_order' => 'int'), array('Default', '-2,-1,0,1,2', 1), array('id_cat'));
}
// Step 8: Update Arcade Version in Database
updateSettings(array('arcadeVersion' => $arcade_version));
// Step 9: Hooks
add_integration_function('integrate_pre_include', '$sourcedir/ArcadeHooks.php');
add_integration_function('integrate_actions', 'Arcade_actions');
add_integration_function('integrate_core_features', 'Arcade_core_features');
add_integration_function('integrate_load_permissions', 'Arcade_load_permissions');
add_integration_function('integrate_profile_areas', 'Arcade_profile_areas');
add_integration_function('integrate_menu_buttons', 'Arcade_menu_buttons');
add_integration_function('integrate_admin_areas', 'Arcade_admin_areas');
function doRenameTables()
{
    global $smcFunc, $db_prefix, $db_type;
    if ($db_type != 'mysql') {
        return;
    }
    $tables = $smcFunc['db_list_tables']();
    // Detect eeks mod from unique table name
    if (in_array($db_prefix . 'arcade_shouts', $tables)) {
        $tables = array('arcade_games' => 'earcade_games', 'arcade_personalbest' => 'earcade_personalbest', 'arcade_scores' => 'earcade_scores', 'arcade_categories' => 'earcade_categories', 'arcade_favorite' => 'earcade_favorite', 'arcade_rates' => 'earcade_rates', 'arcade_settings' => 'earcade_settings', 'arcade_v3temp' => 'earcade_v3temp', 'arcade_shouts' => 'earcade_shouts', 'arcade_tournament_rounds' => 'earcade_tournament_rounds', 'arcade_tournament_players' => 'earcade_tournament_players', 'arcade_tournament_scores' => 'earcade_tournament_scores', 'arcade_tournament' => 'earcade_tournament');
        foreach ($tables as $old => $new) {
            // Drop old copies of earcade tables if exists
            $smcFunc['db_query']('', '
				DROP TABLE IF EXISTS {db_prefix}{raw:new}', array('old' => $old, 'new' => $new));
            $smcFunc['db_query']('', '
Example #15
0
 /**
  * * Add integration functions to SMF
  */
 public function smfAddHooks()
 {
     global $modSettings;
     $controller = $this->config['corePath'] . 'controllers/smf-include.php';
     /**@var array $modSettings */
     if (empty($modSettings['integrate_pre_include']) || $modSettings['integrate_pre_include'] != $controller) {
         if (!function_exists('add_integration_function')) {
             $smfPath = $this->config['smfPath'];
             /** @noinspection PhpIncludeInspection */
             require $smfPath . 'Sources/Subs.php';
             /** @noinspection PhpIncludeInspection */
             require $smfPath . 'Sources/Load.php';
         }
         $hooks = $this->_smfHooks;
         $hooks['integrate_pre_include'] = $controller;
         foreach ($hooks as $hook => $value) {
             if (!empty($modSettings[$hook])) {
                 $tmp = explode(',', $modSettings[$hook]);
                 foreach ($tmp as $v) {
                     remove_integration_function($hook, $v);
                 }
             }
             add_integration_function($hook, $value);
         }
     }
 }
Example #16
0
    // So, for every column, add it to the columns addition - and let SMF deal with it that way.
    foreach ($table['columns'] as $table_info) {
        $columns[] = array('table_name' => $table['table_name'], 'column_info' => $table_info, 'parameters' => array(), 'if_exists' => 'ignore', 'error' => 'fatal');
    }
}
// Create new rows, if any
foreach ($rows as $row) {
    $smcFunc['db_insert']($row['method'], $row['table_name'], $row['columns'], $row['data'], $row['keys']);
}
// Create new columns, if any
foreach ($columns as $column) {
    $smcFunc['db_add_column']($column['table_name'], $column['column_info'], $column['parameters'], $column['if_exists'], $column['error']);
}
// Add integration hooks, if any
foreach ($hooks as $hook) {
    add_integration_function($hook['hook'], $hook['function'], $hook['perm'], !isset($hook['file']) ? '' : $hook['file'], !isset($hook['object']) ? false : $hook['object']);
}
// SimpleDesk specific, after schema changes
// If this is an upgraded 1.0 installation, we won't have any departments. Make sure we create one, if possible using the right language strings.
loadLanguage('SimpleDesk', 'english', false);
loadLanguage('SimpleDesk', '', false);
$query = $smcFunc['db_query']('', 'SELECT COUNT(*) FROM {db_prefix}helpdesk_depts');
list($count) = $smcFunc['db_fetch_row']($query);
$smcFunc['db_free_result']($query);
if (empty($count)) {
    $smcFunc['db_insert']('replace', '{db_prefix}helpdesk_depts', array('dept_name' => 'string', 'board_cat' => 'int', 'description' => 'string', 'before_after' => 'int', 'dept_order' => 'int', 'dept_theme' => 'int'), array(!empty($txt['shd_helpdesk']) ? $txt['shd_helpdesk'] : 'Helpdesk', 0, '', 0, 1, 0), array('id_dept'));
}
// Move any outstanding tickets into the last department we had, which will be the last one we created.
$query = $smcFunc['db_query']('', 'SELECT MAX(id_dept) FROM {db_prefix}helpdesk_depts');
list($new_dept) = $smcFunc['db_fetch_row']($query);
$smcFunc['db_free_result']($query);
function shd_add_to_boardindex(&$boardIndexOptions, &$categories)
{
    global $context, $modSettings, $smcFunc, $board, $txt, $scripturl, $settings;
    // Does the category exist? If it has no boards, it actually might not exist, daft as it sounds.
    // But it's more tricky than that, too! We need to be at the board index, not in a child board.
    if (!empty($board)) {
        return;
    }
    call_integration_hook('shd_hook_boardindex_before', array(&$boardIndexOptions, &$categories));
    // OK, so what helpdesks are we displaying?
    $depts = shd_allowed_to('access_helpdesk', false);
    if (empty($depts)) {
        return;
    }
    $cat_list = array();
    $query = $smcFunc['db_query']('', '
		SELECT id_dept, dept_name, description, board_cat, before_after
		FROM {db_prefix}helpdesk_depts
		WHERE id_dept IN ({array_int:depts})
		ORDER BY before_after DESC, dept_order', array('depts' => $depts));
    $depts = array_flip($depts);
    while ($row = $smcFunc['db_fetch_assoc']($query)) {
        if ($row['board_cat'] == 0) {
            unset($depts[$row['id_dept']]);
            continue;
        }
        $depts[$row['id_dept']] = $row;
        $cat_list[] = $row['board_cat'];
        $context['dept_list'][$row['id_dept']] = array('id_dept' => $row['id_dept'], 'dept_name' => $row['dept_name'], 'dept_desc' => $row['description'], 'tickets' => array('open' => 0, 'closed' => 0, 'assigned' => 0), 'new' => false);
    }
    if (empty($context['dept_list'])) {
        return;
    }
    $cat_list = array_unique($cat_list);
    // Do we have all these categories?
    foreach ($cat_list as $k => $v) {
        if (!empty($categories[$v])) {
            unset($cat_list[$k]);
        }
    }
    if (!empty($cat_list)) {
        // Uh oh, we have to load a category or two.
        $new_cats = array();
        $request = $smcFunc['db_query']('', '
			SELECT c.id_cat, c.name, c.can_collapse, IFNULL(cc.id_member, 0) AS is_collapsed
			FROM {db_prefix}categories AS c
				LEFT JOIN {db_prefix}collapsed_categories AS cc ON (cc.id_cat = c.id_cat AND cc.id_member = {int:current_member})
			WHERE c.id_cat IN ({array_int:cat})', array('cat' => $cat_list, 'current_member' => $context['user']['id']));
        while ($this_cat = $smcFunc['db_fetch_assoc']($request)) {
            $new_cats[$this_cat['id_cat']] = array('id' => $this_cat['id_cat'], 'name' => $this_cat['name'], 'is_collapsed' => isset($this_cat['can_collapse']) && $this_cat['can_collapse'] == 1 && $this_cat['is_collapsed'] > 0, 'can_collapse' => isset($this_cat['can_collapse']) && $this_cat['can_collapse'] == 1, 'collapse_href' => isset($this_cat['can_collapse']) ? $scripturl . '?action=collapse;c=' . $this_cat['id_cat'] . ';sa=' . ($this_cat['is_collapsed'] > 0 ? 'expand;' : 'collapse;') . $context['session_var'] . '=' . $context['session_id'] . '#c' . $this_cat['id_cat'] : '', 'collapse_image' => isset($this_cat['can_collapse']) ? '<img src="' . $settings['images_url'] . '/' . ($this_cat['is_collapsed'] > 0 ? 'expand.png" alt="+"' : 'collapse.png" alt="-"') . ' />' : '', 'href' => $scripturl . '#c' . $this_cat['id_cat'], 'boards' => array(), 'new' => false);
            $new_cats[$this_cat['id_cat']]['link'] = '<a id="c' . $this_cat['id_cat'] . '" href="' . (isset($this_cat['can_collapse']) ? $new_cats[$this_cat['id_cat']]['collapse_href'] : $new_cats[$this_cat['id_cat']]['href']) . '">' . $this_cat['name'] . '</a>';
        }
        $smcFunc['db_free_result']($request);
        // So, did we add any new categories? If we didn't, something's wrong - abort safely NOW.
        if (empty($new_cats)) {
            return;
        }
        // OK, so we have some categories to integrate.
        $old_cats = $categories;
        $categories = array();
        $request = $smcFunc['db_query']('', '
			SELECT id_cat
			FROM {db_prefix}categories
			ORDER BY cat_order');
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            if (isset($old_cats[$row['id_cat']])) {
                $categories[$row['id_cat']] = $old_cats[$row['id_cat']];
            } elseif (isset($new_cats[$row['id_cat']])) {
                $categories[$row['id_cat']] = $new_cats[$row['id_cat']];
            }
        }
        $smcFunc['db_free_result']($request);
    }
    // So, OK, the categories exist. Now we need to create our magic boards, and integrate them.
    // First we do the after's, in order.
    foreach ($depts as $dept) {
        if (empty($dept['before_after'])) {
            continue;
        }
        $dept['link'] = count($depts) != 0 ? ';dept=' . $dept['id_dept'] : '';
        $new_board = shd_dept_board($dept);
        $categories[$dept['board_cat']]['boards'][$new_board['id']] = $new_board;
    }
    // OK, now for the before's. Because we're merging, that means we're doing them last-first.
    $depts = array_reverse($depts);
    foreach ($depts as $dept) {
        if (!empty($dept['before_after'])) {
            continue;
        }
        $dept['link'] = count($depts) != 0 ? ';dept=' . $dept['id_dept'] : '';
        $new_board = shd_dept_board($dept);
        $categories[$dept['board_cat']]['boards'] = array_merge(array($new_board['id'] => $new_board), $categories[$dept['board_cat']]['boards']);
    }
    // Last but not least, fix up the replacements and some figuring out.
    shd_get_ticket_counts();
    shd_get_unread_departments();
    if (empty($context['shd_buffer_preg_replacements'])) {
        $context['shd_buffer_preg_replacements'] = array();
    }
    foreach ($context['dept_list'] as $dept => $dept_details) {
        // Inject the count of tickets.
        $dept_id = '~' . preg_quote(comma_format(-$dept), '~') . '\\s+' . preg_quote($txt['redirects'], '~') . '~';
        $context['shd_buffer_preg_replacements'][$dept_id] = $dept_details['tickets']['open'] . ' ' . ($dept_details['tickets']['open'] == 1 ? $txt['shd_open_ticket'] : $txt['shd_open_tickets']);
    }
    // Call the relevant function via hook.
    add_integration_function('shd_hook_buffer', 'shd_buffer_boardindex', false);
    call_integration_hook('shd_hook_boardindex_after', array(&$categories));
}
 * Developers:
 * 		Juarez, Lucas Javier
 * 		Clavijo, Pablo
 *
 */
$direct_install = false;
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF')) {
    require_once dirname(__FILE__) . '/SSI.php';
    $direct_install = true;
} elseif (!defined('SMF')) {
    die('Adk portal wasn\'t able to conect to smf');
}
//Hooks Integration
$hooks = array('integrate_actions' => 'Adk_portal_add_index_actions', 'integrate_admin_areas' => 'Adk_portal_add_admin_areas', 'integrate_menu_buttons' => 'Adk_portal_add_menu_buttons', 'integrate_display_buttons' => 'Adk_portal_display_buttons', 'integrate_load_permissions' => 'Adk_portal_Permissions', 'integrate_whos_online' => 'Adk_portal_who', 'integrate_buffer' => 'Adk_portal_change_buffer', 'integrate_load_theme' => 'Adk_portal_load_from_theme', 'integrate_pre_include' => '$sourcedir/AdkPortal/Subs-adkfunction.php', 'integrate_pre_load' => 'Adk_portal_pre_load', 'integrate_redirect' => 'Adk_portal_redirect');
foreach ($hooks as $hook => $call) {
    add_integration_function($hook, $call);
}
if ($direct_install) {
    exit('Hooks added');
}
/*elseif(!$direct_install && empty($context['uninstalling'])){

	//Load Adk portal post-installation
	global $txt, $context, $sourcedir;
	require_once($sourcedir.'/AdkPortal/Subs-adkfunction.php');

	adkTemplate('Adk-Admin');
	adkLanguage('Adk-Admin');

	$context['template_layers'][] = 'adk_post_install';
	$context['page_title'] = $txt['adk_post_install'];
Example #19
0
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** */
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF')) {
    require_once dirname(__FILE__) . '/SSI.php';
} elseif (!defined('SMF')) {
    die('<strong>Error:</strong> Cannot install - please verify you put this in the same place as SMF\'s index.php.');
}
global $db_prefix, $modSettings, $smcFunc;
// First load the SMF 2's Extra DB Functions
db_extend('packages');
db_extend('extra');
pre_installCheck();
$GplusHooks = array('integrate_pre_include' => '$sourcedir/GPlus/GPlusHooks.php', 'integrate_buffer' => 'ob_gplus', 'integrate_actions' => 'gplus_actions', 'integrate_profile_areas' => 'gplus_profile_areas', 'integrate_admin_areas' => 'gplus_admin_areas', 'integrate_login' => 'gplus_integrate_login', 'integrate_logout' => 'gplus_integrate_logout', 'integrate_load_theme' => 'gplus_loadTheme');
foreach ($GplusHooks as $hook => $function) {
    add_integration_function($hook, $function);
}
db_add_col('members', 'gpname', 'varchar', 255);
db_add_col('members', 'gpid', 'varchar', 255);
function pre_installCheck()
{
    if (version_compare(PHP_VERSION, '5.2.0', '<')) {
        fatal_error('<strong>PHP 5 or geater is required to install SA Google+.  Please advise your host that PHP4 is no longer maintained and ask that they upgrade you to PHP5.</strong><br />');
    }
}
function db_add_col($table, $col, $type, $size)
{
    global $smcFunc;
    $smcFunc['db_add_column']('{db_prefix}' . $table, array('name' => $col, 'type' => $type, 'size' => $size, 'default' => 0));
}
Example #20
0
<?php

if (!defined('SMF')) {
    die('No direct access...');
}
function mod_loginbutton_addbutton(&$buttons)
{
    global $scripturl, $user_info, $txt;
    $buttons['login'] = array('title' => $txt['login'], 'href' => $scripturl . '?action=login', 'show' => $user_info['is_guest'], 'sub_buttons' => array());
}
add_integration_function('integrate_menu_buttons', 'mod_loginbutton_addbutton', false);
Example #21
0
    // So, for every column, add it to the columns addition - and let SMF deal with it that way.
    foreach ($table['columns'] as $table_info) {
        $columns[] = array('table_name' => $table['table_name'], 'column_info' => $table_info, 'parameters' => array(), 'if_exists' => 'ignore', 'error' => 'fatal');
    }
}
// Create new rows, if any
foreach ($rows as $row) {
    $smcFunc['db_insert']($row['method'], $row['table_name'], $row['columns'], $row['data'], $row['keys']);
}
// Create new columns, if any
foreach ($columns as $column) {
    $smcFunc['db_add_column']($column['table_name'], $column['column_info'], $column['parameters'], $column['if_exists'], $column['error']);
}
// Add integration hooks, if any
foreach ($hooks as $hook) {
    add_integration_function($hook['hook'], $hook['function'], $hook['perm']);
}
// SimpleDesk specific, after schema changes
// If this is an upgraded 1.0 installation, we won't have any departments. Make sure we create one, if possible using the right language strings.
loadLanguage('SimpleDesk', 'english', false);
loadLanguage('SimpleDesk', '', false);
$query = $smcFunc['db_query']('', 'SELECT COUNT(*) FROM {db_prefix}helpdesk_depts');
list($count) = $smcFunc['db_fetch_row']($query);
$smcFunc['db_free_result']($query);
if (empty($count)) {
    $smcFunc['db_insert']('replace', '{db_prefix}helpdesk_depts', array('dept_name' => 'string', 'board_cat' => 'int', 'description' => 'string', 'before_after' => 'int', 'dept_order' => 'int', 'dept_theme' => 'int'), array(!empty($txt['shd_helpdesk']) ? $txt['shd_helpdesk'] : 'Helpdesk', 0, '', 0, 1, 0), array('id_dept'));
}
// Move any outstanding tickets into the last department we had, which will be the last one we created.
$query = $smcFunc['db_query']('', 'SELECT MAX(id_dept) FROM {db_prefix}helpdesk_depts');
list($new_dept) = $smcFunc['db_fetch_row']($query);
$smcFunc['db_free_result']($query);
Example #22
0
<?php

if (!defined('SMF'))
{
	require_once(dirname(dirname(__FILE__)) . '/SSI.php');
	require_once(dirname(__FILE__) . '/Database.php');
	require_once(dirname(__FILE__) . '/Subs-Install.php');
}

global $txt, $smcFunc, $db_prefix, $modSettings;
global $addSettings, $permissions, $tables, $sourcedir;

// Step 1: Do tables
doTables($tables);

// Step 2: Do Settings
doSettings($addSettings);

// Step 3: Update admin features
updateAdminFeatures('posthistory', !empty($modSettings['posthistoryEnabled']));

//
add_integration_function('integrate_pre_include', '$sourcedir/PostHistory.php');
add_integration_function('integrate_actions', 'PH_actions');
add_integration_function('integrate_core_features', 'PH_core_features');
add_integration_function('integrate_load_permissions', 'PH_load_permissions');

?>
Example #23
0
<?php

//Last modified: 2012/04/16
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF')) {
    $ssi = true;
    require_once dirname(__FILE__) . '/SSI.php';
} elseif (!defined('SMF')) {
    exit('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');
}
add_integration_function('integrate_pre_include', '$sourcedir/cls.php');
add_integration_function('integrate_modify_modifications', 'cls_int_modify_modifications');
add_integration_function('integrate_admin_areas', 'cls_int_admin_area');
if (!empty($ssi)) {
    echo 'Database installation complete!';
}
Example #24
0
function list_integration_hooks()
{
    global $sourcedir, $scripturl, $context, $txt, $modSettings, $settings;
    $context['filter'] = '';
    $currentHooks = get_integration_hooks();
    if (isset($_GET['filter']) && in_array($_GET['filter'], array_keys($currentHooks))) {
        $context['filter'] = ';filter=' . $_GET['filter'];
    }
    if (!empty($modSettings['handlinghooks_enabled'])) {
        if (!empty($_REQUEST['do']) && isset($_REQUEST['hook']) && isset($_REQUEST['function'])) {
            checkSession('request');
            validateToken('admin-hook', 'request');
            if ($_REQUEST['do'] == 'remove') {
                remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function']));
            } else {
                if ($_REQUEST['do'] == 'disable') {
                    // It's a hack I know...but I'm way too lazy!!!
                    $function_remove = $_REQUEST['function'];
                    $function_add = $_REQUEST['function'] . ']';
                } else {
                    $function_remove = $_REQUEST['function'] . ']';
                    $function_add = $_REQUEST['function'];
                }
                $file = !empty($_REQUEST['includedfile']) ? urldecode($_REQUEST['includedfile']) : '';
                remove_integration_function($_REQUEST['hook'], $function_remove, $file);
                add_integration_function($_REQUEST['hook'], $function_add, $file);
                redirectexit('action=admin;area=modsettings;sa=hooks' . $context['filter']);
            }
        }
    }
    $list_options = array('id' => 'list_integration_hooks', 'title' => $txt['hooks_title_list'], 'items_per_page' => 20, 'base_href' => $scripturl . '?action=admin;area=modsettings;sa=hooks' . $context['filter'] . ';' . $context['session_var'] . '=' . $context['session_id'], 'default_sort_col' => 'hook_name', 'get_items' => array('function' => 'get_integration_hooks_data'), 'get_count' => array('function' => 'get_integration_hooks_count'), 'no_items_label' => $txt['hooks_no_hooks'], 'columns' => array('hook_name' => array('header' => array('value' => $txt['hooks_field_hook_name']), 'data' => array('db' => 'hook_name'), 'sort' => array('default' => 'hook_name', 'reverse' => 'hook_name DESC')), 'function_name' => array('header' => array('value' => $txt['hooks_field_function_name']), 'data' => array('function' => create_function('$data', '
						global $txt;

						if (!empty($data[\'included_file\']))
							return $txt[\'hooks_field_function\'] . \': \' . $data[\'real_function\'] . \'<br />\' . $txt[\'hooks_field_included_file\'] . \': \' . $data[\'included_file\'];
						else
							return $data[\'real_function\'];
					')), 'sort' => array('default' => 'function_name', 'reverse' => 'function_name DESC')), 'file_name' => array('header' => array('value' => $txt['hooks_field_file_name']), 'data' => array('db' => 'file_name'), 'sort' => array('default' => 'file_name', 'reverse' => 'file_name DESC')), 'status' => array('header' => array('value' => $txt['hooks_field_hook_exists'], 'style' => 'width:3%'), 'data' => array('function' => create_function('$data', '
						global $txt, $settings, $scripturl, $context;

						$change_status = array(\'before\' => \'\', \'after\' => \'\');
						if ($data[\'can_be_disabled\'] && $data[\'status\'] != \'deny\')
						{
							$change_status[\'before\'] = \'<a href="\' . $scripturl . \'?action=admin;area=modsettings;sa=hooks;do=\' . ($data[\'enabled\'] ? \'disable\' : \'enable\') . \';hook=\' . $data[\'hook_name\'] . \';function=\' . $data[\'real_function\'] . (!empty($data[\'included_file\']) ? \';includedfile=\' . urlencode($data[\'included_file\']) : \'\') . $context[\'filter\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');">\';
							$change_status[\'after\'] = \'</a>\';
						}
						return $change_status[\'before\'] . \'<img src="\' . $settings[\'images_url\'] . \'/admin/post_moderation_\' . $data[\'status\'] . \'.png" alt="\' . $data[\'img_text\'] . \'" title="\' . $data[\'img_text\'] . \'" />\' . $change_status[\'after\'];
					'), 'class' => 'centertext'), 'sort' => array('default' => 'status', 'reverse' => 'status DESC'))), 'additional_rows' => array(array('position' => 'after_title', 'value' => $txt['hooks_disable_instructions'] . '<br />
					' . $txt['hooks_disable_legend'] . ':
									<ul style="list-style: none;">
					<li><img src="' . $settings['images_url'] . '/admin/post_moderation_allow.png" alt="' . $txt['hooks_active'] . '" title="' . $txt['hooks_active'] . '" /> ' . $txt['hooks_disable_legend_exists'] . '</li>
					<li><img src="' . $settings['images_url'] . '/admin/post_moderation_moderate.png" alt="' . $txt['hooks_disabled'] . '" title="' . $txt['hooks_disabled'] . '" /> ' . $txt['hooks_disable_legend_disabled'] . '</li>
					<li><img src="' . $settings['images_url'] . '/admin/post_moderation_deny.png" alt="' . $txt['hooks_missing'] . '" title="' . $txt['hooks_missing'] . '" /> ' . $txt['hooks_disable_legend_missing'] . '</li>
				</ul>')));
    if (!empty($modSettings['handlinghooks_enabled'])) {
        createToken('admin-hook', 'request');
        $list_options['columns']['remove'] = array('header' => array('value' => $txt['hooks_button_remove'], 'style' => 'width:3%'), 'data' => array('function' => create_function('$data', '
					global $txt, $settings, $scripturl, $context;

					if (!$data[\'hook_exists\'])
						return \'
						<a href="\' . $scripturl . \'?action=admin;area=modsettings;sa=hooks;do=remove;hook=\' . $data[\'hook_name\'] . \';function=\' . urlencode($data[\'function_name\']) . $context[\'filter\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');">
							<img src="\' . $settings[\'images_url\'] . \'/icons/quick_remove.png" alt="\' . $txt[\'hooks_button_remove\'] . \'" title="\' . $txt[\'hooks_button_remove\'] . \'" />
						</a>\';
				'), 'class' => 'centertext'));
        $list_options['form'] = array('href' => $scripturl . '?action=admin;area=modsettings;sa=hooks' . $context['filter'] . ';' . $context['session_var'] . '=' . $context['session_id'], 'name' => 'list_integration_hooks');
    }
    require_once $sourcedir . '/Subs-List.php';
    createList($list_options);
    $context['page_title'] = $txt['hooks_title_list'];
    $context['sub_template'] = 'show_list';
    $context['default_list'] = 'list_integration_hooks';
}
Example #25
0
<?php

// If SSI.php is in the same place as this file, and SMF isn't defined, this is being run standalone.
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF')) {
    require_once dirname(__FILE__) . '/SSI.php';
} elseif (!defined('SMF')) {
    die('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');
}
add_integration_function('integrate_pre_include', '$sourcedir/Subs-Ldap.php');
add_integration_function('integrate_register', 'ldap_register');
add_integration_function('integrate_verify_password', 'ldap_verify_password');
add_integration_function('integrate_reset_pass', 'ldap_reset_pass');
add_integration_function('integrate_change_member_data', 'ldap_change_member_data');
add_integration_function('integrate_delete_member', 'ldap_delete_member');
echo "Done!";
Example #26
0
function reloadSettings()
{
    global $modSettings, $boarddir, $smcFunc, $txt, $db_character_set, $context, $sourcedir;
    // Most database systems have not set UTF-8 as their default input charset.
    if (!empty($db_character_set)) {
        $smcFunc['db_query']('set_character_set', '
			SET NAMES ' . $db_character_set, array());
    }
    // Try to load it from the cache first; it'll never get cached if the setting is off.
    if (($modSettings = cache_get_data('modSettings', 90)) == null) {
        $request = $smcFunc['db_query']('', '
			SELECT variable, value
			FROM {db_prefix}settings', array());
        $modSettings = array();
        if (!$request) {
            db_fatal_error();
        }
        while ($row = $smcFunc['db_fetch_row']($request)) {
            $modSettings[$row[0]] = $row[1];
        }
        $smcFunc['db_free_result']($request);
        // Do a few things to protect against missing settings or settings with invalid values...
        if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
            $modSettings['defaultMaxTopics'] = 20;
        }
        if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
            $modSettings['defaultMaxMessages'] = 15;
        }
        if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
            $modSettings['defaultMaxMembers'] = 30;
        }
        if (!empty($modSettings['cache_enable'])) {
            cache_put_data('modSettings', $modSettings, 90);
        }
    }
    // UTF-8 in regular expressions is unsupported on PHP(win) versions < 4.2.3.
    $utf8 = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8' && (strpos(strtolower(PHP_OS), 'win') === false || @version_compare(PHP_VERSION, '4.2.3') != -1);
    // Set a list of common functions.
    $ent_list = empty($modSettings['disableEntityCheck']) ? '&(#\\d{1,7}|quot|amp|lt|gt|nbsp);' : '&(#021|quot|amp|lt|gt|nbsp);';
    $ent_check = empty($modSettings['disableEntityCheck']) ? array('preg_replace(\'~(&#(\\d{1,7}|x[0-9a-fA-F]{1,6});)~e\', \'$smcFunc[\\\'entity_fix\\\'](\\\'\\2\\\')\', ', ')') : array('', '');
    // Preg_replace can handle complex characters only for higher PHP versions.
    $space_chars = $utf8 ? @version_compare(PHP_VERSION, '4.3.3') != -1 ? '\\x{A0}\\x{AD}\\x{2000}-\\x{200F}\\x{201F}\\x{202F}\\x{3000}\\x{FEFF}' : " ­ -‏‟ ‟ " : '\\x00-\\x08\\x0B\\x0C\\x0E-\\x19\\xA0';
    $smcFunc += array('entity_fix' => create_function('$string', '
			$num = substr($string, 0, 1) === \'x\' ? hexdec(substr($string, 1)) : (int) $string;
			return $num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202E || $num === 0x202D ? \'\' : \'&#\' . $num . \';\';'), 'htmlspecialchars' => create_function('$string, $quote_style = ENT_COMPAT, $charset = \'ISO-8859-1\'', '
			global $smcFunc;
			return ' . strtr($ent_check[0], array('&' => '&amp;')) . 'htmlspecialchars($string, $quote_style, ' . ($utf8 ? '\'UTF-8\'' : '$charset') . ')' . $ent_check[1] . ';'), 'htmltrim' => create_function('$string', '
			global $smcFunc;
			return preg_replace(\'~^(?:[ \\t\\n\\r\\x0B\\x00' . $space_chars . ']|&nbsp;)+|(?:[ \\t\\n\\r\\x0B\\x00' . $space_chars . ']|&nbsp;)+$~' . ($utf8 ? 'u' : '') . '\', \'\', ' . implode('$string', $ent_check) . ');'), 'strlen' => create_function('$string', '
			global $smcFunc;
			return strlen(preg_replace(\'~' . $ent_list . ($utf8 ? '|.~u' : '~') . '\', \'_\', ' . implode('$string', $ent_check) . '));'), 'strpos' => create_function('$haystack, $needle, $offset = 0', '
			global $smcFunc;
			$haystack_arr = preg_split(\'~(&#' . (empty($modSettings['disableEntityCheck']) ? '\\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '\', ' . implode('$haystack', $ent_check) . ', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
			$haystack_size = count($haystack_arr);
			if (strlen($needle) === 1)
			{
				$result = array_search($needle, array_slice($haystack_arr, $offset));
				return is_int($result) ? $result + $offset : false;
			}
			else
			{
				$needle_arr = preg_split(\'~(&#' . (empty($modSettings['disableEntityCheck']) ? '\\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '\',  ' . implode('$needle', $ent_check) . ', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
				$needle_size = count($needle_arr);

				$result = array_search($needle_arr[0], array_slice($haystack_arr, $offset));
				while (is_int($result))
				{
					$offset += $result;
					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
						return $offset;
					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
				}
				return false;
			}'), 'substr' => create_function('$string, $start, $length = null', '
			global $smcFunc;
			$ent_arr = preg_split(\'~(&#' . (empty($modSettings['disableEntityCheck']) ? '\\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '\', ' . implode('$string', $ent_check) . ', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
			return $length === null ? implode(\'\', array_slice($ent_arr, $start)) : implode(\'\', array_slice($ent_arr, $start, $length));'), 'strtolower' => $utf8 ? function_exists('mb_strtolower') ? create_function('$string', '
			return mb_strtolower($string, \'UTF-8\');') : create_function('$string', '
			global $sourcedir;
			require_once($sourcedir . \'/Subs-Charset.php\');
			return utf8_strtolower($string);') : 'strtolower', 'strtoupper' => $utf8 ? function_exists('mb_strtoupper') ? create_function('$string', '
			return mb_strtoupper($string, \'UTF-8\');') : create_function('$string', '
			global $sourcedir;
			require_once($sourcedir . \'/Subs-Charset.php\');
			return utf8_strtoupper($string);') : 'strtoupper', 'truncate' => create_function('$string, $length', (empty($modSettings['disableEntityCheck']) ? '
			global $smcFunc;
			$string = ' . implode('$string', $ent_check) . ';' : '') . '
			preg_match(\'~^(' . $ent_list . '|.){\' . $smcFunc[\'strlen\'](substr($string, 0, $length)) . \'}~' . ($utf8 ? 'u' : '') . '\', $string, $matches);
			$string = $matches[0];
			while (strlen($string) > $length)
				$string = preg_replace(\'~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : '') . '\', \'\', $string);
			return $string;'), 'ucfirst' => $utf8 ? create_function('$string', '
			global $smcFunc;
			return $smcFunc[\'strtoupper\']($smcFunc[\'substr\']($string, 0, 1)) . $smcFunc[\'substr\']($string, 1);') : 'ucfirst', 'ucwords' => $utf8 ? create_function('$string', '
			global $smcFunc;
			$words = preg_split(\'~([\\s\\r\\n\\t]+)~\', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
			for ($i = 0, $n = count($words); $i < $n; $i += 2)
				$words[$i] = $smcFunc[\'ucfirst\']($words[$i]);
			return implode(\'\', $words);') : 'ucwords');
    // Setting the timezone is a requirement for some functions in PHP >= 5.1.
    if (isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set')) {
        date_default_timezone_set($modSettings['default_timezone']);
    }
    // Check the load averages?
    if (!empty($modSettings['loadavg_enable'])) {
        if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) {
            $modSettings['load_average'] = @file_get_contents('/proc/loadavg');
            if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
                $modSettings['load_average'] = (double) $matches[1];
            } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\\d+\\.\\d+), (\\d+\\.\\d+), (\\d+\\.\\d+)~i', $modSettings['load_average'], $matches) != 0) {
                $modSettings['load_average'] = (double) $matches[1];
            } else {
                unset($modSettings['load_average']);
            }
            if (!empty($modSettings['load_average'])) {
                cache_put_data('loadavg', $modSettings['load_average'], 90);
            }
        }
        if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
            db_fatal_error(true);
        }
    }
    // Is post moderation alive and well?
    $modSettings['postmod_active'] = isset($modSettings['admin_features']) ? in_array('pm', explode(',', $modSettings['admin_features'])) : true;
    // Integration is cool.
    if (defined('SMF_INTEGRATION_SETTINGS')) {
        $integration_settings = unserialize(SMF_INTEGRATION_SETTINGS);
        foreach ($integration_settings as $hook => $function) {
            add_integration_function($hook, $function, false);
        }
    }
    // Any files to pre include?
    if (!empty($modSettings['integrate_pre_include'])) {
        $pre_includes = explode(',', $modSettings['integrate_pre_include']);
        foreach ($pre_includes as $include) {
            $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
            if (file_exists($include)) {
                require_once $include;
            }
        }
    }
    // Call pre load integration functions.
    call_integration_hook('integrate_pre_load');
}
Example #27
0
/**
 * Apply another type of (avatar, language, etc.) package.
 */
function PackageInstall()
{
    global $boarddir, $txt, $context, $boardurl, $scripturl, $sourcedir, $modSettings;
    global $user_info, $smcFunc;
    // Make sure we don't install this mod twice.
    checkSubmitOnce('check');
    checkSession();
    // If there's no file, what are we installing?
    if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
        redirectexit('action=admin;area=packages');
    }
    $context['filename'] = $_REQUEST['package'];
    // If this is an uninstall, we'll have an id.
    $context['install_id'] = isset($_REQUEST['pid']) ? (int) $_REQUEST['pid'] : 0;
    require_once $sourcedir . '/Subs-Package.php';
    // @todo Perhaps do it in steps, if necessary?
    $context['uninstalling'] = $_REQUEST['sa'] == 'uninstall2';
    // Set up the linktree for other.
    $context['linktree'][count($context['linktree']) - 1] = array('url' => $scripturl . '?action=admin;area=packages;sa=browse', 'name' => $context['uninstalling'] ? $txt['uninstall'] : $txt['extracting']);
    $context['page_title'] .= ' - ' . ($context['uninstalling'] ? $txt['uninstall'] : $txt['extracting']);
    $context['sub_template'] = 'extract_package';
    if (!file_exists($boarddir . '/Packages/' . $context['filename'])) {
        fatal_lang_error('package_no_file', false);
    }
    // Load up the package FTP information?
    create_chmod_control(array(), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package']));
    // Make sure temp directory exists and is empty!
    if (file_exists($boarddir . '/Packages/temp')) {
        deltree($boarddir . '/Packages/temp', false);
    } else {
        mktree($boarddir . '/Packages/temp', 0777);
    }
    // Let the unpacker do the work.
    if (is_file($boarddir . '/Packages/' . $context['filename'])) {
        $context['extracted_files'] = read_tgz_file($boarddir . '/Packages/' . $context['filename'], $boarddir . '/Packages/temp');
        if (!file_exists($boarddir . '/Packages/temp/package-info.xml')) {
            foreach ($context['extracted_files'] as $file) {
                if (basename($file['filename']) == 'package-info.xml') {
                    $context['base_path'] = dirname($file['filename']) . '/';
                    break;
                }
            }
        }
        if (!isset($context['base_path'])) {
            $context['base_path'] = '';
        }
    } elseif (is_dir($boarddir . '/Packages/' . $context['filename'])) {
        copytree($boarddir . '/Packages/' . $context['filename'], $boarddir . '/Packages/temp');
        $context['extracted_files'] = listtree($boarddir . '/Packages/temp');
        $context['base_path'] = '';
    } else {
        fatal_lang_error('no_access', false);
    }
    // Are we installing this into any custom themes?
    $custom_themes = array(1);
    $known_themes = explode(',', $modSettings['knownThemes']);
    if (!empty($_POST['custom_theme'])) {
        foreach ($_POST['custom_theme'] as $tid) {
            if (in_array($tid, $known_themes)) {
                $custom_themes[] = (int) $tid;
            }
        }
    }
    // Now load up the paths of the themes that we need to know about.
    $request = $smcFunc['db_query']('', '
		SELECT id_theme, variable, value
		FROM {db_prefix}themes
		WHERE id_theme IN ({array_int:custom_themes})
			AND variable IN ({string:name}, {string:theme_dir})', array('custom_themes' => $custom_themes, 'name' => 'name', 'theme_dir' => 'theme_dir'));
    $theme_paths = array();
    $themes_installed = array(1);
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
    }
    $smcFunc['db_free_result']($request);
    // Are there any theme copying that we want to take place?
    $context['theme_copies'] = array('require-file' => array(), 'require-dir' => array());
    if (!empty($_POST['theme_changes'])) {
        foreach ($_POST['theme_changes'] as $change) {
            if (empty($change)) {
                continue;
            }
            $theme_data = unserialize(base64_decode($change));
            if (empty($theme_data['type'])) {
                continue;
            }
            $themes_installed[] = $theme_data['id'];
            $context['theme_copies'][$theme_data['type']][$theme_data['orig']][] = $theme_data['future'];
        }
    }
    // Get the package info...
    $packageInfo = getPackageInfo($context['filename']);
    if (!is_array($packageInfo)) {
        fatal_lang_error($packageInfo);
    }
    $packageInfo['filename'] = $context['filename'];
    // Set the type of extraction...
    $context['extract_type'] = isset($packageInfo['type']) ? $packageInfo['type'] : 'modification';
    // Create a backup file to roll back to! (but if they do this more than once, don't run it a zillion times.)
    if (!empty($modSettings['package_make_full_backups']) && (!isset($_SESSION['last_backup_for']) || $_SESSION['last_backup_for'] != $context['filename'] . ($context['uninstalling'] ? '$$' : '$'))) {
        $_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$');
        // @todo Internationalize this?
        package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.'));
    }
    // The mod isn't installed.... unless proven otherwise.
    $context['is_installed'] = false;
    // Is it actually installed?
    $request = $smcFunc['db_query']('', '
		SELECT version, themes_installed, db_changes
		FROM {db_prefix}log_packages
		WHERE package_id = {string:current_package}
			AND install_state != {int:not_installed}
		ORDER BY time_installed DESC
		LIMIT 1', array('not_installed' => 0, 'current_package' => $packageInfo['id']));
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $old_themes = explode(',', $row['themes_installed']);
        $old_version = $row['version'];
        $db_changes = empty($row['db_changes']) ? array() : unserialize($row['db_changes']);
    }
    $smcFunc['db_free_result']($request);
    // Wait, it's not installed yet!
    // @todo Replace with a better error message!
    if (!isset($old_version) && $context['uninstalling']) {
        deltree($boarddir . '/Packages/temp');
        fatal_error('Hacker?', false);
    } elseif ($context['uninstalling']) {
        $install_log = parsePackageInfo($packageInfo['xml'], false, 'uninstall');
        // Gadzooks!  There's no uninstaller at all!?
        if (empty($install_log)) {
            fatal_lang_error('package_uninstall_cannot', false);
        }
        // They can only uninstall from what it was originally installed into.
        foreach ($theme_paths as $id => $data) {
            if ($id != 1 && !in_array($id, $old_themes)) {
                unset($theme_paths[$id]);
            }
        }
    } elseif (isset($old_version) && $old_version != $packageInfo['version']) {
        // Look for an upgrade...
        $install_log = parsePackageInfo($packageInfo['xml'], false, 'upgrade', $old_version);
        // There was no upgrade....
        if (empty($install_log)) {
            $context['is_installed'] = true;
        } else {
            // Upgrade previous themes only!
            foreach ($theme_paths as $id => $data) {
                if ($id != 1 && !in_array($id, $old_themes)) {
                    unset($theme_paths[$id]);
                }
            }
        }
    } elseif (isset($old_version) && $old_version == $packageInfo['version']) {
        $context['is_installed'] = true;
    }
    if (!isset($old_version) || $context['is_installed']) {
        $install_log = parsePackageInfo($packageInfo['xml'], false, 'install');
    }
    $context['install_finished'] = false;
    // @todo Make a log of any errors that occurred and output them?
    if (!empty($install_log)) {
        $failed_steps = array();
        $failed_count = 0;
        foreach ($install_log as $action) {
            $failed_count++;
            if ($action['type'] == 'modification' && !empty($action['filename'])) {
                if ($action['boardmod']) {
                    $mod_actions = parseBoardMod(file_get_contents($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
                } else {
                    $mod_actions = parseModification(file_get_contents($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
                }
                // Any errors worth noting?
                foreach ($mod_actions as $key => $action) {
                    if ($action['type'] == 'failure') {
                        $failed_steps[] = array('file' => $action['filename'], 'large_step' => $failed_count, 'sub_step' => $key, 'theme' => 1);
                    }
                    // Gather the themes we installed into.
                    if (!empty($action['is_custom'])) {
                        $themes_installed[] = $action['is_custom'];
                    }
                }
            } elseif ($action['type'] == 'code' && !empty($action['filename'])) {
                // This is just here as reference for what is available.
                global $txt, $boarddir, $sourcedir, $modSettings, $context, $settings, $forum_version, $smcFunc;
                // Now include the file and be done with it ;).
                if (file_exists($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename'])) {
                    require $boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename'];
                }
            } elseif ($action['type'] == 'credits') {
                // Time to build the billboard
                $credits_tag = array('url' => $action['url'], 'license' => $action['license'], 'copyright' => $action['copyright'], 'title' => $action['title']);
            } elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function'])) {
                if ($action['reverse']) {
                    remove_integration_function($action['hook'], $action['function'], $action['include_file']);
                } else {
                    add_integration_function($action['hook'], $action['function'], $action['include_file']);
                }
            } elseif ($action['type'] == 'database' && !empty($action['filename']) && (!$context['uninstalling'] || !empty($_POST['do_db_changes']))) {
                // These can also be there for database changes.
                global $txt, $boarddir, $sourcedir, $modSettings, $context, $settings, $forum_version, $smcFunc;
                global $db_package_log;
                // We'll likely want the package specific database functionality!
                db_extend('packages');
                // Let the file work its magic ;)
                if (file_exists($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename'])) {
                    require $boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename'];
                }
            } elseif ($action['type'] == 'redirect' && !empty($action['redirect_url'])) {
                $context['redirect_url'] = $action['redirect_url'];
                $context['redirect_text'] = !empty($action['filename']) && file_exists($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename']) ? file_get_contents($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename']) : ($context['uninstalling'] ? $txt['package_uninstall_done'] : $txt['package_installed_done']);
                $context['redirect_timeout'] = $action['redirect_timeout'];
                // Parse out a couple of common urls.
                $urls = array('$boardurl' => $boardurl, '$scripturl' => $scripturl, '$session_var' => $context['session_var'], '$session_id' => $context['session_id']);
                $context['redirect_url'] = strtr($context['redirect_url'], $urls);
            }
        }
        package_flush_cache();
        // First, ensure this change doesn't get removed by putting a stake in the ground (So to speak).
        package_put_contents($boarddir . '/Packages/installed.list', time());
        // See if this is already installed, and change it's state as required.
        $request = $smcFunc['db_query']('', '
			SELECT package_id, install_state, db_changes
			FROM {db_prefix}log_packages
			WHERE install_state != {int:not_installed}
				AND package_id = {string:current_package}
				' . ($context['install_id'] ? ' AND id_install = {int:install_id} ' : '') . '
			ORDER BY time_installed DESC
			LIMIT 1', array('not_installed' => 0, 'install_id' => $context['install_id'], 'current_package' => $packageInfo['id']));
        $is_upgrade = false;
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            // Uninstalling?
            if ($context['uninstalling']) {
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}log_packages
					SET install_state = {int:not_installed}, member_removed = {string:member_name}, id_member_removed = {int:current_member},
						time_removed = {int:current_time}
					WHERE package_id = {string:package_id}
						AND id_install = {int:install_id}', array('current_member' => $user_info['id'], 'not_installed' => 0, 'current_time' => time(), 'package_id' => $row['package_id'], 'member_name' => $user_info['name'], 'install_id' => $context['install_id']));
            } else {
                $is_upgrade = true;
                $old_db_changes = empty($row['db_changes']) ? array() : unserialize($row['db_changes']);
            }
        }
        // Assuming we're not uninstalling, add the entry.
        if (!$context['uninstalling']) {
            // Any db changes from older version?
            if (!empty($old_db_changes)) {
                $db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log);
            }
            // If there are some database changes we might want to remove then filter them out.
            if (!empty($db_package_log)) {
                // We're really just checking for entries which are create table AND add columns (etc).
                $tables = array();
                function sort_table_first($a, $b)
                {
                    if ($a[0] == $b[0]) {
                        return 0;
                    }
                    return $a[0] == 'remove_table' ? -1 : 1;
                }
                usort($db_package_log, 'sort_table_first');
                foreach ($db_package_log as $k => $log) {
                    if ($log[0] == 'remove_table') {
                        $tables[] = $log[1];
                    } elseif (in_array($log[1], $tables)) {
                        unset($db_package_log[$k]);
                    }
                }
                $db_changes = serialize($db_package_log);
            } else {
                $db_changes = '';
            }
            // What themes did we actually install?
            $themes_installed = array_unique($themes_installed);
            $themes_installed = implode(',', $themes_installed);
            // What failed steps?
            $failed_step_insert = serialize($failed_steps);
            // Credits tag?
            $credits_tag = empty($credits_tag) ? '' : serialize($credits_tag);
            $smcFunc['db_insert']('', '{db_prefix}log_packages', array('filename' => 'string', 'name' => 'string', 'package_id' => 'string', 'version' => 'string', 'id_member_installed' => 'int', 'member_installed' => 'string', 'time_installed' => 'int', 'install_state' => 'int', 'failed_steps' => 'string', 'themes_installed' => 'string', 'member_removed' => 'int', 'db_changes' => 'string', 'credits' => 'string'), array($packageInfo['filename'], $packageInfo['name'], $packageInfo['id'], $packageInfo['version'], $user_info['id'], $user_info['name'], time(), $is_upgrade ? 2 : 1, $failed_step_insert, $themes_installed, 0, $db_changes, $credits_tag), array('id_install'));
        }
        $smcFunc['db_free_result']($request);
        $context['install_finished'] = true;
    }
    // If there's database changes - and they want them removed - let's do it last!
    if (!empty($db_changes) && !empty($_POST['do_db_changes'])) {
        // We're gonna be needing the package db functions!
        db_extend('packages');
        foreach ($db_changes as $change) {
            if ($change[0] == 'remove_table' && isset($change[1])) {
                $smcFunc['db_drop_table']($change[1]);
            } elseif ($change[0] == 'remove_column' && isset($change[2])) {
                $smcFunc['db_remove_column']($change[1], $change[2]);
            } elseif ($change[0] == 'remove_index' && isset($change[2])) {
                $smcFunc['db_remove_index']($change[1], $change[2]);
            }
        }
    }
    // Clean house... get rid of the evidence ;).
    if (file_exists($boarddir . '/Packages/temp')) {
        deltree($boarddir . '/Packages/temp');
    }
    // Log what we just did.
    logAction($context['uninstalling'] ? 'uninstall_package' : (!empty($is_upgrade) ? 'upgrade_package' : 'install_package'), array('package' => $smcFunc['htmlspecialchars']($packageInfo['name']), 'version' => $smcFunc['htmlspecialchars']($packageInfo['version'])), 'admin');
    // Just in case, let's clear the whole cache to avoid anything going up the swanny.
    clean_cache();
    // Restore file permissions?
    create_chmod_control(array(), array(), true);
}
Example #28
0
<?php

if (!defined('SMF') && file_exists(dirname(__FILE__) . '/SSI.php')) {
    require_once dirname(__FILE__) . '/SSI.php';
} elseif (!defined('SMF')) {
    die('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');
}
add_integration_function('integrate_pre_include', '$sourcedir/Subs-iflychat.php', TRUE);
add_integration_function('integrate_actions', 'iflychat_add_hook', TRUE);
add_integration_function('integrate_buffer', 'iflychat_template_init', TRUE);
add_integration_function('inetgrate_load_permissions', 'iflychat_load_permissions', TRUE);
Example #29
0
/**
 *	Configuration options for Standalone mode.
 *
 *	<ul>
 *	<li>'shd_helpdesk_only' (checkbox) - if checked, Standalone mode is active.</li>
 *	<li>'shd_disable_pm' (checkbox) - if checked, personal messages will not be available at all when SimpleDesk is in (active) Standalone mode</li>
 *	<li>'shd_disable_mlist' (checkbox) - if checked, the memberlist will not be available at all when SimpleDesk is in (active) Standalone mode</li>
 *	</ul>
 *
 *	@param bool $return_config Whether to return configuration items or not; this is provided solely for SMF ACP compatibility (it expects to pass bool true in to get a list of options)
 *
 *	@return array An array of items that make up the search options on the given admin page, each item is itself an array of (type, option name/language string, [other related information])
 *	@since 1.0
 *	@see shd_admin_options()
*/
function shd_modify_standalone_options($return_config)
{
    global $context, $modSettings, $txt;
    $config_vars = array(array('check', 'shd_helpdesk_only', 'subtext' => $txt['shd_helpdesk_only_note'], 'javascript' => ' onchange="javascript:switchitems();"'), array('check', 'shd_disable_pm', 'disabled' => empty($modSettings['shd_helpdesk_only'])), array('check', 'shd_disable_mlist', 'disabled' => empty($modSettings['shd_helpdesk_only'])));
    $context['settings_title'] = $txt['shd_admin_options_standalone'];
    $context['settings_icon'] = 'standalone.png';
    if (empty($context['settings_pre_javascript'])) {
        $context['settings_pre_javascript'] = '';
    }
    $context['settings_pre_javascript'] .= '
		function switchitems()
		{
			var state = !document.getElementById("shd_helpdesk_only").checked;
			shd_switchable_item("shd_disable_pm", state);
			shd_switchable_item("shd_disable_mlist", state);
		}';
    if ($return_config) {
        call_integration_hook('shd_hook_admin_standalone', array(&$config_vars, &$return_config));
        return $config_vars;
    }
    // We saving?
    if (isset($_GET['save'])) {
        // SMF 2.1 has a hook for the default action. Lets trigger it.
        if (isset($_POST['shd_helpdesk_only'])) {
            add_integration_function('integrate_default_action', 'shd_main', true, '$sourcedir/sd_source/SimpleDesk.php');
            add_integration_function('integrate_fallback_action', 'shd_main', true, '$sourcedir/sd_source/SimpleDesk.php');
        }
    }
    return $config_vars;
}