Example #1
0
/**
 * Installs a plugin.
 */
function plugin_install()
{
    $plugin = assert_string(ps('plugin64'));
    if (strpos($plugin, '$plugin=\'') !== false) {
        @ini_set('pcre.backtrack_limit', '1000000');
        $plugin = preg_replace('@.*\\$plugin=\'([\\w=+/]+)\'.*@s', '$1', $plugin);
    }
    $plugin = preg_replace('/^#.*$/m', '', $plugin);
    if (trim($plugin)) {
        $plugin = base64_decode($plugin);
        if (strncmp($plugin, "‹", 2) === 0) {
            $plugin = gzinflate(substr($plugin, 10));
        }
        if ($plugin = unserialize($plugin)) {
            if (is_array($plugin)) {
                extract($plugin);
                $type = empty($type) ? 0 : min(max(intval($type), 0), 5);
                $order = empty($order) ? 5 : min(max(intval($order), 1), 9);
                $flags = empty($flags) ? 0 : intval($flags);
                $exists = fetch('name', 'txp_plugin', 'name', $name);
                if (isset($help_raw) && empty($plugin['allow_html_help'])) {
                    // Default: help is in Textile format.
                    $textile = new \Textpattern\Textile\Parser();
                    $help = $textile->textileRestricted($help_raw, 0, 0);
                }
                if ($exists) {
                    $rs = safe_update('txp_plugin', "type        = {$type},\n                        author       = '" . doSlash($author) . "',\n                        author_uri   = '" . doSlash($author_uri) . "',\n                        version      = '" . doSlash($version) . "',\n                        description  = '" . doSlash($description) . "',\n                        help         = '" . doSlash($help) . "',\n                        code         = '" . doSlash($code) . "',\n                        code_restore = '" . doSlash($code) . "',\n                        code_md5     = '" . doSlash($md5) . "',\n                        flags        = {$flags}", "name        = '" . doSlash($name) . "'");
                } else {
                    $rs = safe_insert('txp_plugin', "name         = '" . doSlash($name) . "',\n                        status       = 0,\n                        type         = {$type},\n                        author       = '" . doSlash($author) . "',\n                        author_uri   = '" . doSlash($author_uri) . "',\n                        version      = '" . doSlash($version) . "',\n                        description  = '" . doSlash($description) . "',\n                        help         = '" . doSlash($help) . "',\n                        code         = '" . doSlash($code) . "',\n                        code_restore = '" . doSlash($code) . "',\n                        code_md5     = '" . doSlash($md5) . "',\n                        load_order   = '" . $order . "',\n                        flags        = {$flags}");
                }
                if ($rs and $code) {
                    if (!empty($textpack)) {
                        // Plugins tag their Textpack by plugin name.
                        // The ownership may be overridden in the Textpack itself.
                        $textpack = "#@owner {$name}" . n . $textpack;
                        install_textpack($textpack, false);
                    }
                    if ($flags & PLUGIN_LIFECYCLE_NOTIFY) {
                        load_plugin($name, true);
                        $message = callback_event("plugin_lifecycle.{$name}", 'installed');
                    }
                    if (empty($message)) {
                        $message = gTxt('plugin_installed', array('{name}' => $name));
                    }
                    plugin_list($message);
                    return;
                } else {
                    $message = array(gTxt('plugin_install_failed', array('{name}' => $name)), E_ERROR);
                    plugin_list($message);
                    return;
                }
            }
        }
    }
    plugin_list(array(gTxt('bad_plugin_code'), E_ERROR));
}
Example #2
0
/**
 * Parses and formats comment message using Textile.
 *
 * @param   string $msg The comment message
 * @return  string HTML markup
 * @package Comment
 */
function markup_comment($msg)
{
    $textile = new \Textpattern\Textile\Parser();
    return $textile->textileRestricted($msg);
}