Ejemplo n.º 1
0
	ATTENTION: If you are trying to install this manually, you should try
	the package manager. If that does not work, you can run this file by
	accessing it by url. Please ensure it is in the same location as your
	forum's SSI.php file.
*******************************************************************************/
//	Pretty URLs Extras 1.0
//	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 uninstall - please verify you put this in the same place as SMF\'s SSI.php.');
}
require_once $sourcedir . '/Subs-PrettyUrls.php';
//	Remove these filters
$prettyFilters = unserialize($modSettings['pretty_filters']);
unset($prettyFilters['arcade']);
unset($prettyFilters['seo4smf']);
unset($prettyFilters['tp-articles']);
unset($prettyFilters['smftags']);
unset($prettyFilters['downloadsystem']);
unset($prettyFilters['smfgallery']);
unset($prettyFilters['smfarticles']);
unset($prettyFilters['smfstore']);
unset($prettyFilters['smfclassifieds']);
unset($prettyFilters['ezportalpages']);
unset($prettyFilters['aeva']);
unset($prettyFilters['googletagged']);
updateSettings(array('pretty_filters' => isset($smcFunc) ? serialize($prettyFilters) : addslashes(serialize($prettyFilters))));
//	Update everything now
pretty_update_filters();
Ejemplo n.º 2
0
function pretty_run_maintenance($installing = false)
{
    global $boarddir, $context, $modSettings, $smcFunc;
    $context['pretty']['maintenance_tasks'] = array();
    //	Get the array of actions
    $indexphp = file_get_contents($boarddir . '/index.php');
    preg_match('~actionArray\\s*=\\s*array[^;]+~', $indexphp, $actionArrayText);
    preg_match_all('~\'([^\']+)\'\\s*=>~', $actionArrayText[0], $actionArray, PREG_PATTERN_ORDER);
    $context['pretty']['action_array'] = $actionArray[1];
    if (function_exists('call_integration_hook')) {
        $dummy = array();
        call_integration_hook('integrate_actions', array(&$dummy));
        $context['pretty']['action_array'] += array_keys($dummy);
    }
    $context['pretty']['maintenance_tasks'][] = 'Updating the array of actions';
    //	Update the list of boards
    //	Get the current pretty board urls, or make new arrays if there are none
    $pretty_board_urls = isset($modSettings['pretty_board_urls']) ? unserialize($modSettings['pretty_board_urls']) : array();
    $pretty_board_lookup_old = isset($modSettings['pretty_board_lookup']) ? unserialize($modSettings['pretty_board_lookup']) : array();
    //	Fix old boards by replacing ' with \x12
    $pretty_board_urls = str_replace("'", "", $pretty_board_urls);
    $pretty_board_lookup = array();
    foreach ($pretty_board_lookup_old as $board => $id) {
        $pretty_board_lookup[str_replace("'", "", $board)] = $id;
    }
    //	Fix old topics too
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}pretty_topic_urls
		SET pretty_url = REPLACE(pretty_url, {string:old_quote}, {string:new_quote})', array('old_quote' => "'", 'new_quote' => "", 'db_error_skip' => true));
    $context['pretty']['maintenance_tasks'][] = 'Fixing any old boards and topics with broken quotes';
    //	Get the board names
    $query = $smcFunc['db_query']('', "\n\t\tSELECT id_board, name\n\t\tFROM {db_prefix}boards");
    //	Process each board
    while ($row = $smcFunc['db_fetch_assoc']($query)) {
        //	Don't replace the board urls if they already exist
        if (!isset($pretty_board_urls[$row['id_board']]) || $pretty_board_urls[$row['id_board']] == '' || in_array($row['id_board'], $pretty_board_lookup) === false) {
            $pretty_text = pretty_generate_url($row['name']);
            //	We need to have something to refer to this board by...
            if ($pretty_text == '') {
                //	... so use 'bID_BOARD'
                $pretty_text = 'b' . $row['id_board'];
            }
            //	Numerical or duplicate URLs aren't allowed!
            if (is_numeric($pretty_text) || isset($pretty_board_lookup[$pretty_text]) || in_array($pretty_text, $context['pretty']['action_array'])) {
                //	Add suffix '-ID_BOARD' to the pretty url
                $pretty_text .= ($pretty_text != '' ? '-' : 'b') . $row['id_board'];
            }
            //	Update the arrays
            $pretty_board_urls[$row['id_board']] = $pretty_text;
            $pretty_board_lookup[$pretty_text] = $row['id_board'];
        } elseif (in_array($pretty_board_urls[$row['id_board']], $context['pretty']['action_array'])) {
            $pretty_text = $pretty_board_urls[$row['id_board']] . '-' . $row['id_board'];
            $pretty_board_urls[$row['id_board']] = $pretty_text;
            $pretty_board_lookup[$pretty_text] = $row['id_board'];
        }
    }
    $smcFunc['db_free_result']($query);
    $context['pretty']['maintenance_tasks'][] = 'Updating board URLs';
    //	Update the database
    updateSettings(array('pretty_action_array' => serialize($context['pretty']['action_array']), 'pretty_board_lookup' => serialize($pretty_board_lookup), 'pretty_board_urls' => serialize($pretty_board_urls)));
    //	Update the filter callbacks
    pretty_update_filters($installing);
    $context['pretty']['maintenance_tasks'][] = 'Update the filters';
}
Ejemplo n.º 3
0
function pretty_edit_filters()
{
    global $context, $modSettings, $sourcedir, $txt;
    //	Check the JSON extension is installed
    if (!function_exists('json_encode')) {
        unset($context['template_layers']['pretty_chrome']);
        fatal_lang_error('pretty_no_json', false);
    }
    //	Save the filters array
    if (isset($_REQUEST['save'])) {
        //	Try to process the edited JSON array
        $json_filters = isset($_POST['pretty_json_filters']) ? $_POST['pretty_json_filters'] : '';
        $json_filters = stripslashes($json_filters);
        $filters_array = json_decode($json_filters, true);
        //	Was that successful or not?
        if ($filters_array == NULL) {
            $_SESSION['pretty']['notice'] = 'There was an error with the JSON array you submitted';
            $_SESSION['pretty']['json_filters'] = $json_filters;
        } else {
            require_once $sourcedir . '/Subs-PrettyUrls.php';
            updateSettings(array('pretty_filters' => serialize($filters_array)));
            pretty_update_filters();
            $_SESSION['pretty']['notice'] = 'Filters saved and updated';
        }
        redirectexit('action=admin;area=pretty;sa=filters');
    }
    //	Action-specific chrome
    $context['page_title'] = $txt['pretty_chrome_page_title_filters'];
    $context['sub_template'] = 'pretty_filters';
    $context['pretty']['chrome']['page_title'] = $txt['pretty_chrome_title_filters'];
    $context['pretty']['chrome']['caption'] = $txt['pretty_chrome_caption_filters'];
    if (isset($_SESSION['pretty']['json_filters'])) {
        //	We're working on something already
        $context['pretty']['json_filters'] = $_SESSION['pretty']['json_filters'];
        unset($_SESSION['pretty']['json_filters']);
    } else {
        //	Convert the filters array to JSON and format it nicely
        require_once $sourcedir . '/Subs-PrettyUrls.php';
        $context['pretty']['json_filters'] = json_encode(unserialize($modSettings['pretty_filters']));
        $context['pretty']['json_filters'] = pretty_json($context['pretty']['json_filters']);
        $context['pretty']['json_filters'] = str_replace('\\/', '/', $context['pretty']['json_filters']);
    }
    //	Any new notices?
    if (isset($_SESSION['pretty']['notice'])) {
        $context['pretty']['chrome']['notice'] = $_SESSION['pretty']['notice'];
        unset($_SESSION['pretty']['notice']);
    }
}
Ejemplo n.º 4
0
function pretty_run_maintenance($installing = false)
{
    global $boarddir, $context, $db_prefix, $modSettings;
    $context['pretty']['maintenance_tasks'] = array();
    //	Get the array of actions
    $indexphp = file_get_contents($boarddir . '/index.php');
    preg_match('~actionArray\\s*=\\s*array[^;]+~', $indexphp, $actionArrayText);
    preg_match_all('~\'([^\']+)\'\\s*=>~', $actionArrayText[0], $actionArray, PREG_PATTERN_ORDER);
    $context['pretty']['action_array'] = $actionArray[1];
    $context['pretty']['maintenance_tasks'][] = 'Updating the array of actions';
    //	Update the list of boards
    //	Get the current pretty board urls, or make new arrays if there are none
    $pretty_board_urls = isset($modSettings['pretty_board_urls']) ? unserialize($modSettings['pretty_board_urls']) : array();
    $pretty_board_lookup_old = isset($modSettings['pretty_board_lookup']) ? unserialize($modSettings['pretty_board_lookup']) : array();
    //	Fix old boards by replacing ' with \x12
    $pretty_board_urls = str_replace("'", "", $pretty_board_urls);
    $pretty_board_lookup = array();
    foreach ($pretty_board_lookup_old as $board => $id) {
        $pretty_board_lookup[str_replace("'", "", $board)] = $id;
    }
    //	Fix old topics too
    db_query("\n\t\tUPDATE {$db_prefix}pretty_topic_urls\n\t\tSET pretty_url = REPLACE(pretty_url, '\\'', '" . chr(18) . "')", __FILE__, __LINE__);
    $context['pretty']['maintenance_tasks'][] = 'Fixing any old boards and topics with broken quotes';
    //	Get the board names
    $query = db_query("\n\t\tSELECT ID_BOARD, name\n\t\tFROM {$db_prefix}boards", __FILE__, __LINE__);
    //	Process each board
    while ($row = mysql_fetch_assoc($query)) {
        //	Don't replace the board urls if they already exist
        if (!isset($pretty_board_urls[$row['ID_BOARD']]) || $pretty_board_urls[$row['ID_BOARD']] == '' || in_array($row['ID_BOARD'], $pretty_board_lookup) === false) {
            $pretty_text = pretty_generate_url($row['name']);
            //	We need to have something to refer to this board by...
            if ($pretty_text == '') {
                //	... so use 'bID_BOARD'
                $pretty_text = 'b' . $row['ID_BOARD'];
            }
            //	Numerical or duplicate URLs aren't allowed!
            if (is_numeric($pretty_text) || isset($pretty_board_lookup[$pretty_text]) || in_array($pretty_text, $context['pretty']['action_array'])) {
                //	Add suffix '-ID_BOARD' to the pretty url
                $pretty_text .= ($pretty_text != '' ? '-' : 'b') . $row['ID_BOARD'];
            }
            //	Update the arrays
            $pretty_board_urls[$row['ID_BOARD']] = $pretty_text;
            $pretty_board_lookup[$pretty_text] = $row['ID_BOARD'];
        } elseif (in_array($pretty_board_urls[$row['ID_BOARD']], $context['pretty']['action_array'])) {
            $pretty_text = $pretty_board_urls[$row['ID_BOARD']] . '-' . $row['ID_BOARD'];
            $pretty_board_urls[$row['ID_BOARD']] = $pretty_text;
            $pretty_board_lookup[$pretty_text] = $row['ID_BOARD'];
        }
    }
    mysql_free_result($query);
    $context['pretty']['maintenance_tasks'][] = 'Updating board URLs';
    //	Update the database
    updateSettings(array('pretty_action_array' => addslashes(serialize($context['pretty']['action_array'])), 'pretty_board_lookup' => addslashes(serialize($pretty_board_lookup)), 'pretty_board_urls' => addslashes(serialize($pretty_board_urls))));
    //	Update the filter callbacks
    pretty_update_filters($installing);
    $context['pretty']['maintenance_tasks'][] = 'Update the filters';
}