Ejemplo n.º 1
0
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\t\t\tselect\n\t\t\t\tID as user_id,\n\t\t\t\tuser_login as name,\n\t\t\t\tuser_email as email,\n\t\t\t\tdisplay_name as RealName\n\t\t\tfrom " . $wpdbprefix . "users\n\t\t", $b2link) or $errors[] = mysql_error();
    while ($user = mysql_fetch_array($user_query)) {
        $user_privs_query = mysql_query("\n\t\t\t\tselect\n\t\t\t\t\tmeta_value\n\t\t\t\tfrom " . $wpdbprefix . "usermeta\n\t\t\t\twhere user_id = " . $user['user_id'] . " and meta_key = '" . $wpdbprefix . "capabilities'\n\t\t\t", $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 Txp 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\t\t\tselect\n\t\t\t\tt.slug as name,\n\t\t\t\tt.name as title,\n\t\t\t\ttt.taxonomy as type,\n\t\t\t\ttt.parent as parent\n\t\t\tfrom " . $wpdbprefix . "terms as t inner join " . $wpdbprefix . "term_taxonomy as tt\n\t\t\t\ton(t.term_id = tt.term_id)\n\t\t\torder by field(tt.taxonomy, 'category','post_tag','link_category'), tt.parent asc, t.name asc\n\t\t", $b2link) or $errors[] = mysql_error();
    while ($category = mysql_fetch_array($category_query)) {
        if ($category['parent'] != 0) {
            $category_parent_query = mysql_query("\n\t\t\t\t\tselect\n\t\t\t\t\t\tslug as name\n\t\t\t\t\tfrom " . $wpdbprefix . "terms\n\t\t\t\t\twhere term_id = '" . doSlash($category['parent']) . "'\n\t\t\t\t", $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 WP 2.6+
    */
    $article_query = mysql_query("\n\t\t\tselect\n\t\t\t\tp.ID as ID,\n\t\t\t\tp.post_status as Status,\n\t\t\t\tp.post_date as Posted,\n\t\t\t\tp.post_modified as LastMod,\n\t\t\t\tp.post_title as Title,\n\t\t\t\tp.post_content as Body,\n\t\t\t\tp.comment_status as Annotate,\n\t\t\t\tp.comment_count as comments_count,\n\t\t\t\tp.post_name as url_title,\n\t\t\t\tu.user_login as AuthorID\n\t\t\tfrom " . $wpdbprefix . "posts as p left join " . $wpdbprefix . "users as u\n\t\t\t\ton u.ID = p.post_author\n\t\t\twhere p.post_type = 'post'\n\t\t\torder by p.ID asc\n\t\t", $b2link) or $errors[] = mysql_error();
    while ($article = mysql_fetch_array($article_query)) {
        // convert WP article status to Txp 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 WP comment status to Txp 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\t\t\t\tselect\n\t\t\t\t\tcomment_author_IP as ip,\n\t\t\t\t\tcomment_author as name,\n\t\t\t\t\tcomment_author_email as email,\n\t\t\t\t\tcomment_author_url as web,\n\t\t\t\t\tcomment_content as message,\n\t\t\t\t\tcomment_date as posted\n\t\t\t\tfrom " . $wpdbprefix . "comments\n\t\t\t\twhere comment_post_ID = '" . $article['ID'] . "'\n\t\t\t\torder by comment_ID asc\n\t\t\t", $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\t\t\t\tselect\n\t\t\t\t\tt.name as title,\n\t\t\t\t\tt.slug as name\n\t\t\t\tfrom " . $wpdbprefix . "terms as t inner join " . $wpdbprefix . "term_taxonomy as tt\n\t\t\t\t\ton(t.term_id = tt.term_id)\n\t\t\t\tinner join " . $wpdbprefix . "term_relationships as tr\n\t\t\t\t\ton(tt.term_taxonomy_id = tr.term_taxonomy_id)\n\t\t\t\twhere tr.object_id = '" . $article['ID'] . "' and tt.taxonomy in('post_tag', 'category')\n\t\t\t\torder by tr.object_id asc, t.name asc\n\t\t\t\tlimit 2;\n\t\t\t", $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\t\t\tselect\n\t\t\t\tguid\n\t\t\tfrom " . $wpdbprefix . "posts\n\t\t\twhere 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.
        // Attn: 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\t\t\tselect\n\t\t\t\tlink_id as id,\n\t\t\t\tlink_name as linkname,\n\t\t\t\tlink_description as description,\n\t\t\t\tlink_updated as date,\n\t\t\t\tlink_url as url\n\t\t\tfrom " . $wpdbprefix . "links\n\t\t\torder by link_id asc\n\t\t", $b2link) or $errors[] = mysql_error();
    while ($link = mysql_fetch_array($link_query)) {
        // link categories
        $link_categories = array();
        $link_category_query = mysql_query("\n\t\t\t\tselect\n\t\t\t\t\tt.name as title,\n\t\t\t\t\tt.slug as name\n\t\t\t\tfrom " . $wpdbprefix . "terms as t inner join " . $wpdbprefix . "term_taxonomy as tt\n\t\t\t\t\ton(t.term_id = tt.term_id)\n\t\t\t\tinner join " . $wpdbprefix . "term_relationships as tr\n\t\t\t\t\ton(tt.term_taxonomy_id = tr.term_taxonomy_id)\n\t\t\t\twhere tr.object_id = '" . $link['id'] . "' and tt.taxonomy = 'link_category'\n\t\t\t\torder by tr.object_id asc, t.name asc\n\t\t\t", $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, and do not alter Dean code
    // for now! ;-)
    $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) . n . 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\t\t\t\t\t\tinsert into " . safe_pfx('txp_users') . " set\n\t\t\t\t\t\t\tname     = '" . doSlash($name) . "',\n\t\t\t\t\t\t\tpass     = '******',\n\t\t\t\t\t\t\temail    = '" . doSlash($email) . "',\n\t\t\t\t\t\t\tRealName = '" . doSlash($RealName) . "',\n\t\t\t\t\t\t\tprivs    = " . $privs . ",\n\t\t\t\t\t\t\tnonce    = '" . doSlash($nonce) . "'\n\t\t\t\t\t", $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\t\t\t\t\t\tinsert into " . safe_pfx('txp_category') . " set\n\t\t\t\t\t\t\tname   = '" . doSlash($name) . "',\n\t\t\t\t\t\t\ttitle  = '" . doSlash($title) . "',\n\t\t\t\t\t\t\ttype   = '" . doSlash($type) . "',\n\t\t\t\t\t\t\tparent = '" . doSlash($parent) . "'\n\t\t\t\t\t", $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>';
        include txpath . '/lib/classTextile.php';
        $textile = new Textile();
        foreach ($articles as $article) {
            extract($article);
            // Ugly, really ugly way to workaround the slashes WP 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\t\t\t\t\tinsert into " . safe_pfx('textpattern') . " set\n\t\t\t\t\t\tPosted         = '" . doSlash($Posted) . "',\n\t\t\t\t\t\tLastMod        = '" . doSlash($LastMod) . "',\n\t\t\t\t\t\tTitle          = '" . doSlash($textile->TextileThis($Title, 1)) . "',\n\t\t\t\t\t\turl_title      = '" . doSlash($url_title) . "',\n\t\t\t\t\t\tBody           = '" . doSlash($Body) . "',\n\t\t\t\t\t\tBody_html      = '" . doSlash($Body_html) . "',\n\t\t\t\t\t\tImage          = '" . doSlash($Image) . "',\n\t\t\t\t\t\tAuthorID       = '" . doSlash($AuthorID) . "',\n\t\t\t\t\t\tCategory1      = '" . doSlash($Category1) . "',\n\t\t\t\t\t\tCategory2      = '" . doSlash($Category2) . "',\n\t\t\t\t\t\tSection        = '{$insert_into_section}',\n\t\t\t\t\t\tuid            = '" . md5(uniqid(rand(), true)) . "',\n\t\t\t\t\t\tfeed_time      = '" . substr($Posted, 0, 10) . "',\n\t\t\t\t\t\tAnnotate       = '" . doSlash($Annotate) . "',\n\t\t\t\t\t\tAnnotateInvite = '{$default_comment_invite}',\n\t\t\t\t\t\tStatus         = '" . doSlash($Status) . "'\n\t\t\t\t", $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 workaroud again
                        $message = nl2br($message);
                        $rs = mysql_query("\n\t\t\t\t\t\t\t\tinsert into " . safe_pfx('txp_discuss') . " set\n\t\t\t\t\t\t\t\t\tparentid = '{$insert_id}',\n\t\t\t\t\t\t\t\t\tname     = '" . doSlash($name) . "',\n\t\t\t\t\t\t\t\t\temail    = '" . doSlash($email) . "',\n\t\t\t\t\t\t\t\t\tweb      = '" . doSlash($web) . "',\n\t\t\t\t\t\t\t\t\tip       = '" . doSlash($ip) . "',\n\t\t\t\t\t\t\t\t\tposted   = '" . doSlash($posted) . "',\n\t\t\t\t\t\t\t\t\tmessage  = '" . doSlash($message) . "',\n\t\t\t\t\t\t\t\t\tvisible  = 1\n\t\t\t\t\t\t\t", $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\t\t\t\t\tinsert into " . safe_pfx('txp_link') . " set\n\t\t\t\t\t\tlinkname    = '" . doSlash($linkname) . "',\n\t\t\t\t\t\tlinksort    = '" . doSlash($linkname) . "',\n\t\t\t\t\t\tdescription = '" . doSlash($description) . "',\n\t\t\t\t\t\tcategory    = '" . doSlash($category) . "',\n\t\t\t\t\t\tdate        = '" . doSlash($date) . "',\n\t\t\t\t\t\turl         = '" . doSlash($url) . "'\n\t\t\t\t", $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.º 2
0
function doArticles($atts, $iscustom)
{
    global $pretext, $prefs, $txpcfg;
    extract($pretext);
    extract($prefs);
    //getting attributes
    $theAtts = lAtts(array('form' => 'default', 'limit' => 10, 'pageby' => '', 'category' => '', 'section' => '', 'excerpted' => '', 'author' => '', 'sortby' => '', 'sortdir' => 'desc', 'month' => '', 'keywords' => '', 'frontpage' => '', 'id' => '', 'time' => 'past', 'status' => '4', 'pgonly' => 0, 'searchall' => 1, 'allowoverride' => !$q and !$iscustom, 'offset' => 0), $atts);
    // if an article ID is specified, treat it as a custom list
    $iscustom = !empty($theAtts['id']) ? true : $iscustom;
    //for the txp:article tag, some attributes are taken from globals;
    //override them before extract
    if (!$iscustom) {
        $theAtts['category'] = $c ? $c : '';
        $theAtts['section'] = $s && $s != 'default' ? $s : '';
        $theAtts['author'] = !empty($author) ? $author : '';
        $theAtts['month'] = !empty($month) ? $month : '';
        $theAtts['frontpage'] = $s && $s == 'default' ? true : false;
        $theAtts['excerpted'] = '';
    }
    extract($theAtts);
    $pageby = empty($pageby) ? $limit : $pageby;
    // treat sticky articles differently wrt search filtering, etc
    if (!is_numeric($status)) {
        $status = getStatusNum($status);
    }
    $issticky = $status == 5;
    //give control to search, if necesary
    if ($q && !$iscustom && !$issticky) {
        include_once txpath . '/publish/search.php';
        $s_filter = $searchall ? filterSearch() : '';
        $q = doSlash($q);
        $match = ", match (Title,Body) against ('{$q}') as score";
        $search = " and (Title rlike '{$q}' or Body rlike '{$q}') {$s_filter}";
        // searchall=0 can be used to show search results for the current section only
        if ($searchall) {
            $section = '';
        }
        if (!$sortby) {
            $sortby = 'score';
        }
    } else {
        $match = $search = '';
        if (!$sortby) {
            $sortby = 'Posted';
        }
    }
    //Building query parts
    $frontpage = ($frontpage and !$q) ? filterFrontPage() : '';
    $category = !$category ? '' : " and ((Category1='" . doslash($category) . "') or (Category2='" . doSlash($category) . "')) ";
    $section = !$section ? '' : " and Section = '" . doslash($section) . "'";
    $excerpted = $excerpted == 'y' ? " and Excerpt !=''" : '';
    $author = !$author ? '' : " and AuthorID = '" . doslash($author) . "'";
    $month = !$month ? '' : " and Posted like '" . doSlash($month) . "%'";
    $id = !$id ? '' : " and ID = '" . intval($id) . "'";
    switch ($time) {
        case 'any':
            $time = "";
            break;
        case 'future':
            $time = " and Posted > now()";
            break;
        default:
            $time = " and Posted < now()";
    }
    if (!is_numeric($status)) {
        $status = getStatusNum($status);
    }
    $custom = '';
    // trying custom fields here
    $customFields = getCustomFields();
    if ($customFields) {
        foreach ($customFields as $cField) {
            if (isset($atts[$cField])) {
                $customPairs[$cField] = $atts[$cField];
            }
        }
        if (!empty($customPairs)) {
            $custom = buildCustomSql($customFields, $customPairs);
        } else {
            $custom = '';
        }
    }
    //Allow keywords for no-custom articles. That tagging mode, you know
    if ($keywords) {
        $keys = split(',', $keywords);
        foreach ($keys as $key) {
            $keyparts[] = " Keywords like '%" . doSlash(trim($key)) . "%'";
        }
        $keywords = " and (" . join(' or ', $keyparts) . ")";
    }
    $where = "1" . ($id ? " and Status >= '4'" : " and Status='" . doSlash($status) . "'") . $time . $search . $id . $category . $section . $excerpted . $month . $author . $keywords . $custom . $frontpage;
    //do not paginate if we are on a custom list
    if (!$iscustom and !$issticky) {
        $total = safe_count('textpattern', $where) - $offset;
        $numPages = ceil($total / $pageby);
        $pg = !$pg ? 1 : $pg;
        $pgoffset = $offset + ($pg - 1) * $pageby . ', ';
        // send paging info to txp:newer and txp:older
        $pageout['pg'] = $pg;
        $pageout['numPages'] = $numPages;
        $pageout['s'] = $s;
        $pageout['c'] = $c;
        $pageout['total'] = $total;
        $GLOBALS['thispage'] = $pageout;
        if ($pgonly) {
            return;
        }
    } else {
        $pgoffset = $offset . ', ';
    }
    $rs = safe_rows_start("*, unix_timestamp(Posted) as uPosted" . $match, 'textpattern', $where . ' order by ' . doslash($sortby) . ' ' . doSlash($sortdir) . ' limit ' . doSlash($pgoffset . $limit));
    // alternative form override for search or list
    if ($q and !$iscustom and !$issticky) {
        $form = gAtt($atts, 'searchform', 'search_results');
    } else {
        $form = gAtt($atts, 'listform', $form);
    }
    // might be a form preview, otherwise grab it from the db
    $form = isset($_POST['Form']) ? gps('Form') : fetch_form($form);
    if ($rs) {
        $count = 0;
        $articles = array();
        while ($a = nextRow($rs)) {
            ++$count;
            populateArticleData($a);
            $GLOBALS['thisarticle']['is_first'] = $count == 1;
            $GLOBALS['thisarticle']['is_last'] = $count == numRows($rs);
            // define the article form
            $article = ($allowoverride and $a['override_form']) ? fetch_form($a['override_form']) : $form;
            $articles[] = parse($article);
            // sending these to paging_link(); Required?
            $GLOBALS['uPosted'] = $a['uPosted'];
            $GLOBALS['limit'] = $limit;
            unset($GLOBALS['thisarticle']);
            unset($GLOBALS['theseatts']);
            //Required?
        }
        return join('', $articles);
    }
}
Ejemplo n.º 3
0
function doTxpValidate()
{
    global $logout, $txpcfg, $txp_user;
    $p_userid = ps('p_userid');
    $p_password = ps('p_password');
    $logout = gps('logout');
    $stay = ps('stay');
    if ($logout) {
        setcookie('txp_login', '', time() - 3600);
    }
    if (!empty($_COOKIE['txp_login']) and !$logout) {
        // cookie exists
        @(list($c_userid, $cookie_hash) = split(',', cs('txp_login')));
        $nonce = safe_field('nonce', 'txp_users', "name='" . doslash($c_userid) . "'");
        if (md5($c_userid . $nonce) === $cookie_hash && $nonce) {
            // check nonce
            $txp_user = $c_userid;
            // cookie is good, create $txp_user
            return '';
        } else {
            // something's gone wrong
            $txp_user = '';
            setcookie('txp_login', '', time() - 3600);
            return gTxt('bad_cookie');
        }
    } elseif ($p_userid and $p_password) {
        // no cookie, but incoming login vars
        sleep(3);
        // should grind dictionary attacks to a halt
        if (txp_validate($p_userid, $p_password)) {
            $nonce = safe_field('nonce', 'txp_users', "name='" . doSlash($p_userid) . "'");
            if (!$nonce) {
                define('TXP_UPDATE', 1);
                include_once txpath . '/update/_update.php';
                exit(graf('Please reload'));
            }
            if ($stay) {
                // persistent cookie required
                setcookie('txp_login', $p_userid . ',' . md5($p_userid . $nonce), time() + 3600 * 24 * 365);
                // expires in 1 year
                if (cs('txp_nostay')) {
                    setcookie('txp_nostay', '', time() - 3600);
                }
            } else {
                // session-only cookie required
                setcookie('txp_login', $p_userid . ',' . md5($p_userid . $nonce));
                setcookie('txp_nostay', '1', time() + 3600 * 24 * 365);
                // remember nostay for 1 year
            }
            $txp_user = $p_userid;
            // login is good, create $txp_user
            return '';
        } else {
            $txp_user = '';
            return gTxt('could_not_log_in');
        }
    } else {
        $txp_user = '';
        return gTxt('login_to_textpattern');
    }
}
Ejemplo n.º 4
0
function doArticles($atts, $iscustom)
{
    global $pretext, $prefs, $txpcfg, $DB;
    extract($pretext);
    extract($prefs);
    $customFields = getCustomFields();
    $customlAtts = array_null(array_flip($customFields));
    //getting attributes
    $theAtts = lAtts(array('form' => 'default', 'listform' => '', 'searchform' => '', 'limit' => 10, 'pageby' => '', 'category' => '', 'section' => '', 'excerpted' => 0, 'author' => '', 'sort' => '', 'month' => '', 'keywords' => '', 'frontpage' => '', 'id' => '', 'time' => 'past', 'status' => '4', 'pgonly' => 0, 'searchall' => 1, 'searchsticky' => 0, 'allowoverride' => !$q and !$iscustom, 'offset' => 0) + $customlAtts, $atts);
    // if an article ID is specified, treat it as a custom list
    $iscustom = !empty($theAtts['id']) ? true : $iscustom;
    //for the txp:article tag, some attributes are taken from globals;
    //override them before extract
    if (!$iscustom) {
        $theAtts['category'] = $c ? $c : '';
        $theAtts['section'] = $s && $s != 'default' ? $s : '';
        $theAtts['author'] = !empty($author) ? $author : '';
        $theAtts['month'] = !empty($month) ? $month : '';
        $theAtts['frontpage'] = $s && $s == 'default' ? true : false;
        $theAtts['excerpted'] = 0;
    }
    extract($theAtts);
    $pageby = empty($pageby) ? $limit : $pageby;
    // treat sticky articles differently wrt search filtering, etc
    if (!is_numeric($status)) {
        $status = getStatusNum($status);
    }
    $issticky = $status == 5;
    //give control to search, if necesary
    if ($q && !$iscustom && !$issticky) {
        include_once txpath . '/publish/search.php';
        $s_filter = $searchall ? filterSearch() : '';
        $match = ", " . $DB->match('Title,Body', doSlash($q));
        $words = preg_split('/\\s+/', $q);
        foreach ($words as $w) {
            $rlike[] = "(Title " . $DB->rlike() . " '" . doSlash(preg_quote($w)) . "' or Body " . $DB->rlike() . " '" . doSlash(preg_quote($w)) . "')";
        }
        $search = " and " . join(' and ', $rlike) . " {$s_filter}";
        // searchall=0 can be used to show search results for the current section only
        if ($searchall) {
            $section = '';
        }
        if (!$sort) {
            $sort = 'score desc';
        }
    } else {
        $match = $search = '';
        if (!$sort) {
            $sort = 'Posted desc';
        }
    }
    //Building query parts
    $frontpage = ($frontpage and (!$q or $issticky)) ? filterFrontPage() : '';
    $category = join("','", doSlash(do_list($category)));
    $category = !$category ? '' : " and (Category1 IN ('" . $category . "') or Category2 IN ('" . $category . "'))";
    $section = !$section ? '' : " and Section IN ('" . join("','", doSlash(do_list($section))) . "')";
    $excerpted = !$excerpted ? '' : " and Excerpt !=''";
    $author = !$author ? '' : " and AuthorID IN ('" . join("','", doSlash(do_list($author))) . "')";
    $month = !$month ? '' : " and Posted like '" . doSlash($month) . "%'";
    $id = !$id ? '' : " and ID = '" . intval($id) . "'";
    switch ($time) {
        case 'any':
            $time = "";
            break;
        case 'future':
            $time = " and Posted > now()";
            break;
        default:
            $time = " and Posted <= now()";
    }
    if (!$publish_expired_articles) {
        $time .= " and (now() <= Expires or Expires = " . NULLDATETIME . ")";
    }
    $custom = '';
    if ($customFields) {
        foreach ($customFields as $cField) {
            if (isset($atts[$cField])) {
                $customPairs[$cField] = $atts[$cField];
            }
        }
        if (!empty($customPairs)) {
            $custom = buildCustomSql($customFields, $customPairs);
        }
    }
    //Allow keywords for no-custom articles. That tagging mode, you know
    if ($keywords) {
        $keys = doSlash(do_list($keywords));
        foreach ($keys as $key) {
            $keyparts[] = "FIND_IN_SET('" . $key . "',Keywords)";
        }
        $keywords = " and (" . join(' or ', $keyparts) . ")";
    }
    if ($q and $searchsticky) {
        $statusq = ' and Status >= 4';
    } elseif ($id) {
        $statusq = ' and Status >= 4';
    } else {
        $statusq = ' and Status = ' . intval($status);
    }
    $where = "1=1" . $statusq . $time . $search . $id . $category . $section . $excerpted . $month . $author . $keywords . $custom . $frontpage;
    //do not paginate if we are on a custom list
    if (!$iscustom and !$issticky) {
        $grand_total = safe_count('textpattern', $where);
        $total = $grand_total - $offset;
        $numPages = ceil($total / $pageby);
        $pg = !$pg ? 1 : $pg;
        $pgoffset = $offset + ($pg - 1) * $pageby;
        // send paging info to txp:newer and txp:older
        $pageout['pg'] = $pg;
        $pageout['numPages'] = $numPages;
        $pageout['s'] = $s;
        $pageout['c'] = $c;
        $pageout['grand_total'] = $grand_total;
        $pageout['total'] = $total;
        global $thispage;
        if (empty($thispage)) {
            $thispage = $pageout;
        }
        if ($pgonly) {
            return;
        }
    } else {
        $pgoffset = $offset;
    }
    $rs = safe_rows_start("*, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires" . $match, 'textpattern', $where . ' order by ' . doslash($sort) . ' ' . $DB->limit(intval($limit), intval($pgoffset)));
    // alternative form override for search or list
    if ($q and !$iscustom and !$issticky) {
        $fname = $searchform ? $searchform : 'search_results';
    } else {
        $fname = $listform ? $listform : $form;
    }
    if ($rs) {
        $count = 0;
        $articles = array();
        while ($a = nextRow($rs)) {
            ++$count;
            populateArticleData($a);
            global $thisarticle, $uPosted, $limit;
            $thisarticle['is_first'] = $count == 1;
            $thisarticle['is_last'] = $count == numRows($rs);
            if (@constant('txpinterface') === 'admin' and gps('Form')) {
                $articles[] = parse(gps('Form'));
            } elseif ($allowoverride and $a['override_form']) {
                $articles[] = parse_form($a['override_form']);
            } else {
                $articles[] = parse_form($fname);
            }
            // sending these to paging_link(); Required?
            $uPosted = $a['uPosted'];
            unset($GLOBALS['thisarticle']);
        }
        return join('', $articles);
    }
}
Ejemplo n.º 5
0
function checkNonce($nonce)
{
    if (!$nonce && !preg_match('#^[a-zA-Z0-9]*$#', $nonce)) {
        return false;
    }
    // delete expired nonces
    safe_delete("txp_discuss_nonce", "issue_time < date_sub(now(),interval 10 minute)");
    // check for nonce
    return safe_row("*", "txp_discuss_nonce", "nonce='" . doslash($nonce) . "' and used='0'") ? true : false;
}
function bot_admin_tooltips_tab($event, $step)
{
    global $bot_admin_tooltips_main_array, $plugins;
    if (isset($_POST['bot_item'])) {
        // if there are preferences
        $prefs = bot_get_tips();
        // array of values from the db table
    }
    $r = safe_rows_start('name, val', 'txp_prefs', 'event = "custom" AND val != ""');
    // creates an array of all cfs for selectInput in bot_admin_tooltips_tab
    if ($r) {
        global $arr_custom_fields;
        while ($a = nextRow($r)) {
            $name = 'tab_write|' . str_replace('_set', '', $a['name']);
            $val = $a['val'];
            $arr_custom_fields[$name] = $val;
        }
    }
    pagetop('bot_admin_tooltips ' . gTxt('preferences'), $step == 'update' ? gTxt('preferences_saved') : '');
    echo hed('bot | admin tooltips', '2', ' style="text-align: center; margin:20px auto;   padding-bottom:10px;"');
    if ($step == 'install') {
        // Install the preferences table.
        bot_admin_tooltips_install();
    }
    if ($step == 'uninstall') {
        //remove table
        safe_query("DROP TABLE " . PFX . "bot_admin_tooltips");
        safe_delete('txp_prefs', 'event = "bot_tips_"');
    }
    if ($step == 'update') {
        // set function variables
        $new_item = doslash(ps('bot_new_item'));
        $new_tip = doslash(ps('bot_new_tip'));
        $item = doslash(ps('bot_item'));
        $tip = doslash(ps('bot_saved_tip'));
        $tip_id = ps('bot_id');
        $delete_id = ps('bot_delete_id');
        $hide_pophelp = ps('bot_admin_tooltips_hide_pophelp');
        $js_event = ps('bot_admin_tooltips_js_event');
        $tips_bg = doslash(ps('bot_admin_tooltips_bg'));
        $tips_color = doslash(ps('bot_admin_tooltips_color'));
        $tips_border_color = doslash(ps('bot_admin_tooltips_border_color'));
        $js_path = doslash(ps('bot_admin_tooltips_path'));
        if ($delete_id) {
            // checks if there is something to delete
            foreach ($delete_id as $id) {
                safe_delete('bot_admin_tooltips', 'id ="' . $id . '"');
            }
        }
        safe_update('txp_prefs', 'val= "' . $hide_pophelp . '"', 'name = "bot_admin_tooltips_hide_pophelp"');
        // updates pophelp prefs
        safe_update('txp_prefs', 'val= "' . $js_event . '"', 'name = "bot_admin_tooltips_js_event"');
        // updates click/hover prefs
        safe_update('txp_prefs', 'val= "' . $tips_bg . '"', 'name = "bot_admin_tooltips_bg"');
        // updates bg prefs
        safe_update('txp_prefs', 'val= "' . $tips_color . '"', 'name = "bot_admin_tooltips_color"');
        // updates color prefs
        safe_update('txp_prefs', 'val= "' . $tips_border_color . '"', 'name = "bot_admin_tooltips_border_color"');
        // updates border color prefs
        safe_update('txp_prefs', 'val= "' . $js_path . '"', 'name = "bot_admin_tooltips_path"');
        // updates path prefs
        if ($item != '' && $tip != '') {
            // when tips are set
            for ($i = 0; $i < count($item); $i++) {
                // creates the "posted_variables" array containing item, tip, tip_id
                $posted_variables[$item[$i]]['item'] = $item[$i];
                $posted_variables[$item[$i]]['tip'] = $tip[$i];
                $posted_variables[$item[$i]]['id'] = $tip_id[$i];
            }
            foreach ($posted_variables as $item => $values) {
                // for each posted variable (item, tip, tip_id) updates the db
                $tip = $values['tip'];
                $id = $values['id'];
                if ($item != '' && $tip != '') {
                    // if there is item AND tip
                    safe_update('bot_admin_tooltips', 'item = "' . $item . '", tip = "' . $tip . '"', 'id = "' . $id . '"');
                } elseif ($tip == '') {
                    // if there is no tip, tip is deleted from db
                    safe_delete('bot_admin_tooltips', 'item ="' . $item . '"');
                }
            }
            if ($new_item != '' && $new_tip != '') {
                // if there is a new tip is inserted in db
                safe_insert('bot_admin_tooltips', 'item = "' . $new_item . '", tip = "' . $new_tip . '"');
            }
        } elseif ($new_item != '' && $new_tip != '') {
            // if no tips are set yet deals only with new tip
            safe_insert('bot_admin_tooltips', 'item = "' . $new_item . '", tip = "' . $new_tip . '"');
        }
    }
    if (bot_admin_tooltips_check_install()) {
        extract(bot_admin_tooltips_get_prefs());
        // beginning of the form
        echo form('<div style="text-align:center; background:#f2f2f2; margin:20px auto 40px; padding:10px; border-bottom:solid #ccc 1px; border-top:solid #ccc 1px; ">' . n . '<label for="bot_admin_tooltips_bg">Background color </label>' . finput('text', 'bot_admin_tooltips_bg', $bot_admin_tooltips_bg) . n . '&nbsp; &nbsp;' . n . '<label for="bot_admin_tooltips_color">Text color </label>' . finput('text', 'bot_admin_tooltips_color', $bot_admin_tooltips_color) . n . '&nbsp; &nbsp;' . n . '<label for="bot_admin_tooltips_border_color">Border color </label>' . finput('text', 'bot_admin_tooltips_border_color', $bot_admin_tooltips_border_color) . n . '&nbsp; &nbsp;' . n . '<label for="bot_admin_tooltips_js_event">Show tip on hover </label>' . checkbox2('bot_admin_tooltips_js_event', $bot_admin_tooltips_js_event) . n . '&nbsp; &nbsp;' . n . '<label for="bot_admin_tooltips_hide_pophelp">Hide txp pophelps </label>' . checkbox2('bot_admin_tooltips_hide_pophelp', $bot_admin_tooltips_hide_pophelp) . n . '&nbsp; &nbsp;' . n . '<label for="bot_admin_tooltips_path">Path to js </label>' . finput('text', 'bot_admin_tooltips_path', $bot_admin_tooltips_path) . n . '</div>' . '<div style="margin: 0 auto 20px; width:580px; padding:0 10px;">' . n . eInput('bot_admin_tooltips_tab') . n . sInput('update') . n . fInput('submit', 'update', 'Update', 'publish') . '</div>' . n . startTable('list') . n . tr(td(strong('Item')) . td(strong('Tip'))) . n . bot_admin_tooltips_output_rows() . n . endTable() . '<div style="margin: 20px auto; width:580px; padding:0 10px;">' . n . eInput('bot_admin_tooltips_tab') . n . sInput('update') . n . fInput('submit', 'update', 'Update', 'publish') . '</div>');
        // uninstall button
        echo n . t . '<div style="margin: 20px auto 0; width:580px; border-top:dashed #ccc 1px; margin-top:40px; padding:10px 10px 0;">' . n . t . t . graf(bot_admin_tooltips_gTxt('uninstall_message')) . n . hed(bot_admin_tooltips_gTxt('uninstall'), '1') . n . n . form(n . eInput('bot_admin_tooltips_tab') . n . sInput('uninstall') . n . n . fInput('submit', 'uninstall', 'Uninstall ', 'smallerbox'), "", "confirm('" . bot_admin_tooltips_gTxt('uninstall_confirm') . "')") . '</div>';
    } else {
        // install message
        echo n . t . '<div style="margin: auto; width:40%;">' . n . t . t . hed('bot_admin_tooltips ' . gTxt('Preferences'), '1') . n . graf(bot_admin_tooltips_gTxt('install_message')) . n . n . form(n . eInput('bot_admin_tooltips_tab') . n . sInput('install') . n . n . fInput('submit', 'install', 'Install ', 'publish')) . '</div>';
    }
}