Ejemplo n.º 1
0
/**
 * Parses article fields using Textile.
 *
 * @param  array $incoming
 * @return array
 */
function textile_main_fields($incoming)
{
    $textile = new Textpattern_Textile_Parser();
    $incoming['Title_plain'] = trim($incoming['Title']);
    $incoming['Title_html'] = '';
    // not used
    $incoming['Title'] = $textile->textileEncode($incoming['Title_plain']);
    $incoming['Body_html'] = Txp::get('Textpattern_Textfilter_Registry')->filter($incoming['textile_body'], $incoming['Body'], array('field' => 'Body', 'options' => array('lite' => false), 'data' => $incoming));
    $incoming['Excerpt_html'] = Txp::get('Textpattern_Textfilter_Registry')->filter($incoming['textile_excerpt'], $incoming['Excerpt'], array('field' => 'Excerpt', 'options' => array('lite' => false), 'data' => $incoming));
    return $incoming;
}
Ejemplo n.º 2
0
/**
 * Imports a WordPress database.
 *
 * This function imports users, categories, articles and
 * links from a WordPress installation.
 *
 * Returns results as a <ul> list.
 *
 * @param  string $b2dblogin              The user
 * @param  string $b2db                   The database
 * @param  string $b2dbpass               The password
 * @param  string $b2dbhost               The hostname
 * @param  string $wpdbprefix             The WordPress table prefix
 * @param  string $insert_into_section    Article section
 * @param  int    $insert_with_status     Article status
 * @param  string $default_comment_invite Article comments invite
 * @param  string $wpdbcharset            WordPress database charset
 * @return string HTML
 */
function doImportWP($b2dblogin, $b2db, $b2dbpass, $b2dbhost, $wpdbprefix, $insert_into_section, $insert_with_status, $default_comment_invite, $wpdbcharset)
{
    global $txpcfg;
    $b2link = mysql_connect($b2dbhost, $b2dblogin, $b2dbpass, true);
    if (!$b2link) {
        return 'WordPress database values don’t work. Go back, replace them and try again.';
    }
    mysql_select_db($b2db, $b2link);
    if (!mysql_query('SET NAMES ' . doslash($wpdbcharset), $b2link)) {
        return 'WordPress database does not support the requested character set. Aborting.';
    }
    // Keep some response on some part.
    $results = array();
    $errors = array();
    $results[] = hed('Connected to WordPress database. Importing Data…', 1);
    /*
    export users
    */
    $users = array();
    $user_query = mysql_query("\n        select\n            ID as user_id,\n            user_login as name,\n            user_email as email,\n            display_name as RealName\n        from " . $wpdbprefix . "users\n    ", $b2link) or $errors[] = mysql_error();
    while ($user = mysql_fetch_array($user_query)) {
        $user_privs_query = mysql_query("\n            select\n                meta_value\n            from " . $wpdbprefix . "usermeta\n            where user_id = " . $user['user_id'] . " and meta_key = '" . $wpdbprefix . "capabilities'\n        ", $b2link) or $errors[] = mysql_error();
        $privs = unserialize(mysql_result($user_privs_query, 0));
        foreach ($privs as $key => $val) {
            // Convert the built-in WordPress roles to their Textpattern equivalent.
            switch ($key) {
                // Publisher.
                case 'administrator':
                    $user['privs'] = 1;
                    break;
                    // Managing editor.
                // Managing editor.
                case 'editor':
                    $user['privs'] = 2;
                    break;
                    // Staff writer.
                // Staff writer.
                case 'author':
                    $user['privs'] = 4;
                    break;
                    // Freelancer.
                // Freelancer.
                case 'contributor':
                    $user['privs'] = 5;
                    break;
                    // None.
                // None.
                case 'subscriber':
                default:
                    $user['privs'] = 0;
                    break;
            }
        }
        $users[] = $user;
    }
    /*
    export article and link categories
    */
    $categories = array();
    $category_query = mysql_query("\n        select\n            t.slug as name,\n            t.name as title,\n            tt.taxonomy as type,\n            tt.parent as parent\n        from " . $wpdbprefix . "terms as t inner join " . $wpdbprefix . "term_taxonomy as tt\n            on(t.term_id = tt.term_id)\n        order by field(tt.taxonomy, 'category', 'post_tag', 'link_category'), tt.parent asc, t.name asc\n    ", $b2link) or $errors[] = mysql_error();
    while ($category = mysql_fetch_array($category_query)) {
        if ($category['parent'] != 0) {
            $category_parent_query = mysql_query("\n                select\n                    slug as name\n                from " . $wpdbprefix . "terms\n                where term_id = '" . doSlash($category['parent']) . "'\n            ", $b2link) or $errors[] = mysql_error();
            while ($parent = mysql_fetch_array($category_parent_query)) {
                $category['parent'] = $parent['name'];
            }
        } else {
            $category['parent'] = 'root';
        }
        switch ($category['type']) {
            case 'post_tag':
            case 'category':
                $category['type'] = 'article';
                break;
            case 'link_category':
                $category['type'] = 'link';
                break;
        }
        $categories[] = $category;
    }
    /*
    export articles - do not export post revisions from WordPress 2.6+
    */
    $article_query = mysql_query("\n        select\n            p.ID as ID,\n            p.post_status as Status,\n            p.post_date as Posted,\n            p.post_modified as LastMod,\n            p.post_title as Title,\n            p.post_content as Body,\n            p.comment_status as Annotate,\n            p.comment_count as comments_count,\n            p.post_name as url_title,\n            u.user_login as AuthorID\n        from " . $wpdbprefix . "posts as p left join " . $wpdbprefix . "users as u\n            on u.ID = p.post_author\n        where p.post_type = 'post'\n        order by p.ID asc\n    ", $b2link) or $errors[] = mysql_error();
    while ($article = mysql_fetch_array($article_query)) {
        // Convert WordPress article status to Textpattern equivalent.
        switch ($article['Status']) {
            case 'draft':
                $article['Status'] = 1;
                break;
                // Hidden.
            // Hidden.
            case 'private':
                $article['Status'] = 2;
                break;
            case 'pending':
                $article['Status'] = 3;
                break;
                // Live.
            // Live.
            case 'publish':
                $article['Status'] = 4;
                break;
            default:
                $article['Status'] = $insert_with_status;
                break;
        }
        // Convert WordPress comment status to Textpattern equivalent.
        switch ($article['Annotate']) {
            // On.
            case 'open':
                $article['Annotate'] = 1;
                break;
                // Off.
            // Off.
            case 'closed':
            case 'registered_only':
                $article['Annotate'] = 0;
                break;
        }
        // Article commments.
        $comments = array();
        $comment_query = mysql_query("\n            select\n                comment_author_IP as ip,\n                comment_author as name,\n                comment_author_email as email,\n                comment_author_url as web,\n                comment_content as message,\n                comment_date as posted\n            from " . $wpdbprefix . "comments\n            where comment_post_ID = '" . $article['ID'] . "'\n            order by comment_ID asc\n        ", $b2link) or $errors[] = mysql_error();
        while ($comment = mysql_fetch_assoc($comment_query)) {
            $comments[] = $comment;
        }
        $article['comments'] = $comments;
        // Article categories.
        $article_categories = array();
        $article_category_query = mysql_query("\n            select\n                t.name as title,\n                t.slug as name\n            from " . $wpdbprefix . "terms as t inner join " . $wpdbprefix . "term_taxonomy as tt\n                on(t.term_id = tt.term_id)\n            inner join " . $wpdbprefix . "term_relationships as tr\n                on(tt.term_taxonomy_id = tr.term_taxonomy_id)\n            where tr.object_id = '" . $article['ID'] . "' and tt.taxonomy in('post_tag', 'category')\n            order by tr.object_id asc, t.name asc\n            limit 2;\n        ", $b2link) or $errors[] = mysql_error();
        while ($category = mysql_fetch_array($article_category_query)) {
            $article_categories[] = $category;
        }
        $article['Category1'] = !empty($article_categories[0]) ? $article_categories[0]['name'] : '';
        $article['Category2'] = !empty($article_categories[1]) ? $article_categories[1]['name'] : '';
        // Article images.
        $article_images = array();
        $article_image_query = mysql_query("\n        select\n            guid\n        from " . $wpdbprefix . "posts\n        where post_type = 'attachment' and post_mime_type like 'image/%' and post_parent=" . $article['ID'], $b2link) or $errors[] = mysql_error();
        while ($image = mysql_fetch_array($article_image_query)) {
            $article_images[] = $image['guid'];
        }
        // Comma-separated image URLs preserve multiple attachments.
        // Note: If more than one image is attached, <txp:article_image /> will
        // not work out of the box.
        $article['Image'] = join(',', $article_images);
        $articles[] = $article;
    }
    /*
    export links
    */
    $links = array();
    $link_query = mysql_query("\n        select\n            link_id as id,\n            link_name as linkname,\n            link_description as description,\n            link_updated as date,\n            link_url as url\n        from " . $wpdbprefix . "links\n        order by link_id asc\n    ", $b2link) or $errors[] = mysql_error();
    while ($link = mysql_fetch_array($link_query)) {
        // Link categories.
        $link_categories = array();
        $link_category_query = mysql_query("\n            select\n                t.name as title,\n                t.slug as name\n            from " . $wpdbprefix . "terms as t inner join " . $wpdbprefix . "term_taxonomy as tt\n                on(t.term_id = tt.term_id)\n            inner join " . $wpdbprefix . "term_relationships as tr\n                on(tt.term_taxonomy_id = tr.term_taxonomy_id)\n            where tr.object_id = '" . $link['id'] . "' and tt.taxonomy = 'link_category'\n            order by tr.object_id asc, t.name asc\n        ", $b2link) or $errors[] = mysql_error();
        while ($category = mysql_fetch_array($link_category_query)) {
            $link['category'] = $category['name'];
        }
        $links[] = $link;
    }
    mysql_close($b2link);
    /*
    begin import
    */
    // Keep a handy copy of txpdb values.
    $txpdb = $txpcfg['db'];
    $txpdblogin = $txpcfg['user'];
    $txpdbpass = $txpcfg['pass'];
    $txpdbhost = $txpcfg['host'];
    // Yes, we have to make a new connection, otherwise doArray complains.
    $DB = new DB();
    $txplink =& $DB->link;
    mysql_select_db($txpdb, $txplink);
    /*
    import users
    */
    if ($users) {
        include_once txpath . '/lib/txplib_admin.php';
        $results[] = hed('Imported Users:', 2) . graf('Because WordPress uses a different password mechanism than Textpattern, you will need to reset each user&#8217;s password from <a href="index.php?event=admin">the Users tab</a>.') . n . '<ul>';
        foreach ($users as $user) {
            extract($user);
            if (!safe_row('user_id', 'txp_users', "name = '" . doSlash($name) . "'")) {
                $pass = doSlash(generate_password(6));
                $nonce = doSlash(md5(uniqid(mt_rand(), true)));
                $rs = mysql_query("\n                    insert into " . safe_pfx('txp_users') . " set\n                        name     = '" . doSlash($name) . "',\n                        pass     = '******',\n                        email    = '" . doSlash($email) . "',\n                        RealName = '" . doSlash($RealName) . "',\n                        privs    = " . $privs . ",\n                        nonce    = '" . doSlash($nonce) . "'\n                ", $txplink) or $errors[] = mysql_error();
                if (mysql_insert_id()) {
                    $results[] = '<li>' . $name . ' (' . $RealName . ')</li>';
                }
            }
        }
        $results[] = '</ul>';
    }
    /*
    import categories
    */
    if ($categories) {
        $results[] = hed('Imported Categories:', 2) . n . '<ul>';
        foreach ($categories as $category) {
            extract($category);
            if (!safe_row('id', 'txp_category', "name = '" . doSlash($name) . "' and type = '" . doSlash($type) . "' and parent = '" . doSlash($parent) . "'")) {
                $rs = mysql_query("\n                    insert into " . safe_pfx('txp_category') . " set\n                        name   = '" . doSlash($name) . "',\n                        title  = '" . doSlash($title) . "',\n                        type   = '" . doSlash($type) . "',\n                        parent = '" . doSlash($parent) . "'\n                ", $txplink) or $errors[] = mysql_error();
                if (mysql_insert_id()) {
                    $results[] = '<li>' . $title . ' (' . $type . ')</li>';
                }
            }
        }
        rebuild_tree_full('article');
        rebuild_tree_full('link');
        $results[] = '</ul>';
    }
    /*
    import articles
    */
    if ($articles) {
        $results[] = hed('Imported Articles and Comments:', 2) . n . '<ul>';
        $textile = new Textpattern_Textile_Parser();
        foreach ($articles as $article) {
            extract($article);
            // Ugly, really ugly way to workaround the slashes WordPress gotcha.
            $Body = str_replace('<!--more-->', '', $Body);
            $Body_html = $textile->textileThis($Body);
            // Can not use array slash due to way on which comments are selected.
            $rs = mysql_query("\n                insert into " . safe_pfx('textpattern') . " set\n                    Posted         = '" . doSlash($Posted) . "',\n                    LastMod        = '" . doSlash($LastMod) . "',\n                    Title          = '" . doSlash($textile->TextileThis($Title, 1)) . "',\n                    url_title      = '" . doSlash($url_title) . "',\n                    Body           = '" . doSlash($Body) . "',\n                    Body_html      = '" . doSlash($Body_html) . "',\n                    Image          = '" . doSlash($Image) . "',\n                    AuthorID       = '" . doSlash($AuthorID) . "',\n                    Category1      = '" . doSlash($Category1) . "',\n                    Category2      = '" . doSlash($Category2) . "',\n                    Section        = '{$insert_into_section}',\n                    uid            = '" . md5(uniqid(rand(), true)) . "',\n                    feed_time      = '" . substr($Posted, 0, 10) . "',\n                    Annotate       = '" . doSlash($Annotate) . "',\n                    AnnotateInvite = '{$default_comment_invite}',\n                    Status         = '" . doSlash($Status) . "'\n            ", $txplink) or $errors[] = mysql_error();
            if ((int) ($insert_id = mysql_insert_id($txplink))) {
                $results[] = '<li>' . $Title . '</li>';
                if (!empty($comments)) {
                    $inserted_comments = 0;
                    foreach ($comments as $comment) {
                        extract(array_slash($comment));
                        // The ugly workaround again.
                        $message = nl2br($message);
                        $rs = mysql_query("\n                            insert into " . safe_pfx('txp_discuss') . " set\n                                parentid = '{$insert_id}',\n                                name     = '" . doSlash($name) . "',\n                                email    = '" . doSlash($email) . "',\n                                web      = '" . doSlash($web) . "',\n                                ip       = '" . doSlash($ip) . "',\n                                posted   = '" . doSlash($posted) . "',\n                                message  = '" . doSlash($message) . "',\n                                visible  = 1\n                        ", $txplink) or $results[] = mysql_error();
                        if (mysql_insert_id()) {
                            $inserted_comments++;
                        }
                    }
                    $results[] = '<li>- ' . $inserted_comments . ' of ' . $comments_count . ' comment(s)</li>';
                }
            }
        }
        $results[] = '</ul>';
    }
    /*
    import links
    */
    if ($links) {
        $results[] = hed('Imported Links:', 2) . n . '<ul>';
        foreach ($links as $link) {
            extract($link);
            $rs = mysql_query("\n                insert into " . safe_pfx('txp_link') . " set\n                    linkname    = '" . doSlash($linkname) . "',\n                    linksort    = '" . doSlash($linkname) . "',\n                    description = '" . doSlash($description) . "',\n                    category    = '" . doSlash($category) . "',\n                    date        = '" . doSlash($date) . "',\n                    url         = '" . doSlash($url) . "'\n            ", $txplink) or $errors[] = mysql_error();
            if (mysql_insert_id()) {
                $results[] = '<li>' . $linkname . '</li>';
            }
        }
        $results[] = '</ul>';
    }
    /*
    show any errors we encountered
    */
    if ($errors) {
        $results[] = hed('Errors Encountered:', 2) . n . '<ul>';
        foreach ($errors as $error) {
            $results[] = '<li>' . $error . '</li>';
        }
        $results[] = '</ul>';
    }
    return join(n, $results);
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
0
/**
 * Imports articles from b2 database.
 *
 * Absolutely untested. Any volunteer with a b2 db dump to collaborate?
 *
 * @param  string $b2dblogin              The user
 * @param  string $b2db                   The database
 * @param  string $b2dbpass               The password
 * @param  string $b2dbhost               The hostname
 * @param  string $insert_into_section    Article section
 * @param  int    $insert_with_status     Article status
 * @param  string $default_comment_invite Article comments invite
 * @return string HTML
 */
function doImportB2($b2dblogin, $b2db, $b2dbpass, $b2dbhost, $insert_into_section, $insert_with_status, $default_comment_invite)
{
    global $txpcfg;
    // Keep some response on some part.
    $results = array();
    $b2link = mysql_connect($b2dbhost, $b2dblogin, $b2dbpass, true);
    if (!$b2link) {
        return 'b2 database values don&#8217;t work. Go back, replace them and try again';
    }
    mysql_select_db($b2db, $b2link);
    $results[] = 'connected to b2 database. Importing Data';
    // Copy and paste your table-definitions from b2config.php.
    $tableposts = 'b2posts';
    $tableusers = 'b2users';
    $tablecategories = 'b2categories';
    $tablecomments = 'b2comments';
    $a = mysql_query("\n        select\n        " . $tableposts . ".ID as ID,\n        " . $tableposts . ".post_date as Posted,\n        " . $tableposts . ".post_title as Title,\n        " . $tableposts . ".post_content as Body,\n        " . $tablecategories . ".cat_name as Category1,\n        " . $tableusers . ".user_login as AuthorID\n        from " . $tableposts . "\n        left join " . $tablecategories . " on\n            " . $tablecategories . ".cat_ID = " . $tableposts . ".post_category\n        left join " . $tableusers . " on\n            " . $tableusers . ".ID = " . $tableposts . ".post_author\n        ORDER BY post_date DESC\n    ", $b2link) or $results[] = mysql_error();
    while ($b = mysql_fetch_array($a)) {
        $articles[] = $b;
    }
    $a = mysql_query("\n        select\n        " . $tablecomments . ".comment_ID as discussid,\n        " . $tablecomments . ".comment_post_ID as parentid,\n        " . $tablecomments . ".comment_author_IP as ip,\n        " . $tablecomments . ".comment_author as name,\n        " . $tablecomments . ".comment_author_email as email,\n        " . $tablecomments . ".comment_author_url as web,\n        " . $tablecomments . ".comment_content as message,\n        " . $tablecomments . ".comment_date as posted\n        from " . $tablecomments . "\n    ", $b2link) or $results[] = mysql_error();
    while ($b = mysql_fetch_assoc($a)) {
        $comments[] = $b;
    }
    mysql_close($b2link);
    // Keep a handy copy of txpdb values.
    $txpdb = $txpcfg['db'];
    $txpdblogin = $txpcfg['user'];
    $txpdbpass = $txpcfg['pass'];
    $txpdbhost = $txpcfg['host'];
    // Yes, we have to make a new connection, otherwise doArray complains.
    $DB = new DB();
    $txplink =& $DB->link;
    mysql_select_db($txpdb, $txplink);
    $textile = new Textpattern_Textile_Parser();
    if (!empty($articles)) {
        foreach ($articles as $a) {
            if (is_callable('utf8_encode')) {
                // Also fixing break-tags for users with b2s Auto-BR.
                $a['Body'] = utf8_encode(str_replace("<br />\n", "\n", stripslashes($a['Body'])));
                $a['Title'] = utf8_encode(stripslashes($a['Title']));
                $a['Title'] = $textile->TextileThis($a['Title'], '', 1);
            }
            // b2 uses the magic word "<!--more-->" to generate excerpts.
            if (strpos($a['Body'], '<!--more-->')) {
                // Everything that is before "more" can be treated as the excerpt.
                $pos = strpos($a['Body'], '<!--more-->');
                $a['Excerpt'] = substr($a['Body'], 0, $pos);
                $a['Excerpt_html'] = $textile->textileThis($a['Excerpt']);
                $a['Body'] = str_replace('<!--more-->', '', $a['Body']);
            } else {
                $a['Excerpt'] = '';
                $a['Excerpt_html'] = '';
            }
            $a['url_title'] = stripSpace($a['Title'], 1);
            $a['Body_html'] = $textile->textileThis($a['Body']);
            extract(array_slash($a));
            $q = mysql_query("\n                insert into `" . PFX . "textpattern` set\n                ID           = '{$ID}',\n                Posted       = '{$Posted}',\n                Title        = '{$Title}',\n                url_title    = '{$url_title}',\n                Body         = '{$Body}',\n                Body_html    = '{$Body_html}',\n                Excerpt      = '{$Excerpt}',\n                Excerpt_html = '{$Excerpt_html}',\n                Category1    = '{$Category1}',\n                AuthorID     = '{$AuthorID}',\n                Section      = '{$insert_into_section}',\n                AnnotateInvite = '{$default_comment_invite}',\n                uid='" . md5(uniqid(rand(), true)) . "',\n                feed_time='" . substr($Posted, 0, 10) . "',\n                Status    = '{$insert_with_status}',\n            ", $txplink) or $results[] = mysql_error();
            if (mysql_insert_id()) {
                $results[] = 'inserted b2 entry ' . $Title . ' into Textpattern as article ' . $ID . '';
            }
        }
    }
    if (!empty($comments)) {
        foreach ($comments as $comment) {
            extract(array_slash($comment));
            if (is_callable('utf8_encode')) {
                $message = utf8_encode($message);
            }
            $message = nl2br($message);
            $q = mysql_query("insert into `" . PFX . "txp_discuss` values\n                ({$discussid}, {$parentid}, '{$name}', '{$email}', '{$web}', '{$ip}', '{$posted}', '{$message}', 1)", $txplink) or $results[] = mysql_error($q);
            if (mysql_insert_id()) {
                $results[] = 'inserted b2 comment ' . strong($parentid) . ' into txp_discuss';
            }
        }
    }
    return join('<br />', $results);
}
Ejemplo n.º 5
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));
}
Ejemplo n.º 6
0
/**
 * Inserts a parsed item to the database.
 *
 * This import code is untested.
 *
 * @param  array  $item
 * @param  string $section
 * @param  int    $status
 * @param  string $invite
 * @return string A feedback message
 * @access private
 */
function import_blogger_item($item, $section, $status, $invite)
{
    if (empty($item)) {
        return;
    }
    $textile = new Textpattern_Textile_Parser();
    $title = $textile->TextileThis($item['TITLE'], 1);
    $url_title = stripSpace($title, 1);
    $body = $item['BODY'][0]['content'];
    $body_html = $textile->textileThis($body, 1);
    $date = strtotime($item['DATE']);
    $date = date('Y-m-d H:i:s', $date);
    if (isset($item['STATUS'])) {
        $post_status = $item['STATUS'] == 'Draft' ? 1 : 4;
    } else {
        $post_status = $status;
    }
    // Blogger can use special characters on author names. Strip them and check
    // for realname.
    $authorid = safe_field('user_id', 'txp_users', "RealName = '" . doSlash($item['AUTHOR']) . "'");
    if (!$authorid) {
        //        $authorid = safe_field('user_id', 'txp_users', 'order by user_id asc limit 1');
        // Add new authors.
        safe_insert('txp_users', "name='" . doSlash(stripSpace($textile->TextileThis($item['AUTHOR'], 1))) . "', RealName='" . doSlash($item['AUTHOR']) . "'");
    }
    if (!safe_field("ID", "textpattern", "Title = '" . doSlash($title) . "' AND Posted = '" . doSlash($date) . "'")) {
        $ok = safe_insert('textpattern', "Posted='" . doSlash($date) . "'," . "LastMod='" . doSlash($date) . "'," . "AuthorID='" . doSlash($item['AUTHOR']) . "'," . "LastModID='" . doSlash($item['AUTHOR']) . "'," . "Title='" . doSlash($title) . "'," . "Body='" . doSlash($body) . "'," . "Body_html='" . doSlash($body_html) . "'," . "AnnotateInvite='" . doSlash($invite) . "'," . "Status='" . doSlash($post_status) . "'," . "Section='" . doSlash($section) . "'," . "uid='" . md5(uniqid(rand(), true)) . "'," . "feed_time='" . substr($date, 0, 10) . "'," . "url_title='" . doSlash($url_title) . "'");
        if ($ok) {
            $parentid = $ok;
            if (!empty($item['COMMENT'])) {
                foreach ($item['COMMENT'] as $comment) {
                    $comment_date = date('Y-m-d H:i:s', strtotime(@$comment['DATE']));
                    $comment_content = $textile->TextileThis(nl2br(@$comment['content']), 1);
                    // Check for Comments authors.
                    if (preg_match('/<a href="(.*)">(.*)<\\/a>/', @$comment['AUTHOR'], $match)) {
                        @($comment['URL'] = $match[1]);
                        @($comment['AUTHOR'] = $match[2]);
                    }
                    if (!safe_field("discussid", "txp_discuss", "posted = '" . doSlash($comment_date) . "' AND message = '" . doSlash($comment_content) . "'")) {
                        safe_insert('txp_discuss', "parentid='" . doSlash($parentid) . "'," . "name='" . doSlash(strip_tags(@$comment['AUTHOR'])) . "'," . "web='" . doSlash(@$comment['URL']) . "'," . "posted='" . doSlash($comment_date) . "'," . "message='" . doSlash($comment_content) . "'," . "visible='1'");
                    }
                }
            }
        }
        return $title;
    }
    return $title . ' already imported';
}
Ejemplo n.º 7
0
 /**
  * Apply Textile to the main article fields.
  *
  * This is duplicated from txp_article.php.
  *
  * @param  array $incoming    The incoming fields
  * @param  bool  $use_textile Use Textile or not
  * @return array The $incoming array formatted
  * @access private
  */
 public function textile_main_fields($incoming, $use_textile = 1)
 {
     global $txpcfg;
     $textile = new Textpattern_Textile_Parser();
     if (!empty($event) and $event == 'article') {
         $incoming['Title_plain'] = $incoming['Title'];
     }
     if ($incoming['textile_body'] == USE_TEXTILE) {
         $incoming['Title'] = $textile->TextileThis($incoming['Title'], '', 1);
     }
     $incoming['url_title'] = preg_replace('|[\\x00-\\x1f#%+/?\\x7f]|', '', $incoming['url_title']);
     $incoming['Body_html'] = TXP_Wrapper::format_field($incoming['Body'], $incoming['textile_body'], $textile);
     $incoming['Excerpt_html'] = TXP_Wrapper::format_field($incoming['Excerpt'], $incoming['textile_excerpt'], $textile);
     return $incoming;
 }
Ejemplo n.º 8
0
 /**
  * Processes help files.
  *
  * @return string
  */
 protected function help()
 {
     $out = array();
     if (isset($this->manifest->help->file)) {
         foreach ((array) $this->manifest->help->file as $file) {
             $out[] = file_get_contents($this->path($file));
         }
     } else {
         if (isset($this->manifest->help)) {
             $out[] = $this->manifest->help;
         }
     }
     if ($out) {
         $textile = new Textpattern_Textile_Parser();
         return $textile->TextileRestricted(implode(n, $out), 0, 0);
     }
     return '';
 }