Example #1
0
function import_mt_item($item, $section, $status, $invite)
{
    # Untested import code follows
    if (empty($item)) {
        return;
    }
    include_once txpath . '/lib/classTextile.php';
    $textile = new Textile();
    $title = $textile->TextileThis($item['TITLE'], 1);
    //nice non-english permlinks
    $url_title = stripSpace(dumbDown($title));
    $body = $item['BODY'][0]['content'] . (isset($item['EXTENDED_BODY']) ? "\n<!--more-->\n" . $item['EXTENDED_BODY'][0]['content'] : '');
    $body_html = $textile->textileThis($body);
    $excerpt = @$item['EXCERPT'][0]['content'];
    $excerpt_html = $textile->textileThis($excerpt);
    $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;
    }
    $category1 = @$item['PRIMARY CATEGORY'];
    if ($category1 and !safe_field("name", "txp_category", "name = '{$category1}'")) {
        safe_insert('txp_category', "name='" . doSlash($category1) . "', type='article', parent='root'");
    }
    $keywords = @$item['KEYWORDS'][0]['content'];
    $authorid = safe_field('user_id', 'txp_users', "name = '" . 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($item['AUTHOR']) . "'");
    }
    if (!safe_field("ID", "textpattern", "Title = '" . doSlash($title) . "' AND Posted = '" . doSlash($date) . "'")) {
        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) . "'," . "Excerpt='" . doSlash($excerpt) . "'," . "Excerpt_html='" . doSlash($excerpt_html) . "'," . "Category1='" . doSlash($category1) . "'," . "AnnotateInvite='" . doSlash($invite) . "'," . "Status='" . doSlash($post_status) . "'," . "Section='" . doSlash($section) . "'," . "Keywords='" . doSlash($keywords) . "'," . "uid='" . md5(uniqid(rand(), true)) . "'," . "feed_time='" . substr($date, 0, 10) . "'," . "url_title='" . doSlash($url_title) . "'");
        $parentid = mysql_insert_id();
        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);
                if (!safe_field("discussid", "txp_discuss", "posted = '" . doSlash($comment_date) . "' AND message = '" . doSlash($comment_content) . "'")) {
                    safe_insert('txp_discuss', "parentid='" . doSlash($parentid) . "'," . "name='" . doSlash(@$comment['AUTHOR']) . "'," . "email='" . doSlash(@$comment['EMAIL']) . "'," . "web='" . doSlash(@$comment['URL']) . "'," . "ip='" . doSlash(@$comment['IP']) . "'," . "posted='" . doSlash($comment_date) . "'," . "message='" . doSlash($comment_content) . "'," . "visible='1'");
                }
            }
        }
        return $title;
    }
    return $title . ' already imported';
}
Example #2
0
/**
 * Performs searching and returns results.
 *
 * This is now performed by doArticles().
 *
 * @param      string $q
 * @deprecated in 4.0.4
 * @see        doArticles()
 */
function search($q)
{
    global $prefs;
    $url = $prefs['siteurl'];
    extract($prefs);
    $s_filter = filterSearch();
    $form = fetch('form', 'txp_form', 'name', 'search_results');
    // Lose this eventually - only used if search_results form is missing.
    $form = !$form ? legacy_form() : $form;
    $rs = safe_rows("*, ID AS thisid, UNIX_TIMESTAMP(Posted) AS posted, Title AS title,\n        MATCH (Title,Body) AGAINST ('{$q}') AS score", 'textpattern', "(Title RLIKE '{$q}' OR Body RLIKE '{$q}') {$s_filter}\n        AND Status = 4 AND Posted <= " . now('posted') . " ORDER BY score DESC LIMIT 40");
    if ($rs) {
        $result_rows = count($rs);
        $text = $result_rows == 1 ? gTxt('article_found') : gTxt('articles_found');
    } else {
        $result_rows = 0;
        $text = gTxt('articles_found');
    }
    $results[] = graf($result_rows . ' ' . $text);
    if ($result_rows > 0) {
        foreach ($rs as $a) {
            extract($a);
            $result_date = safe_strftime($archive_dateformat, $posted);
            $uTitle = $url_title ? $url_title : stripSpace($Title);
            $hurl = permlinkurl($a);
            $result_url = '<a href="' . $hurl . '">' . $hurl . '</a>';
            $result_title = '<a href="' . $hurl . '">' . $Title . '</a>';
            $result = preg_replace("/>\\s*</", "> <", $Body_html);
            preg_match_all("/\\s.{1,50}" . preg_quote($q) . ".{1,50}\\s/i", $result, $concat);
            $concat = join(" ... ", $concat[0]);
            $concat = strip_tags($concat);
            $concat = preg_replace('/^[^>]+>/U', "", $concat);
            $concat = preg_replace("/({$q})/i", "<strong>\$1</strong>", $concat);
            $result_excerpt = $concat ? "... " . $concat . " ..." : '';
            $glob['search_result_title'] = $result_title;
            $glob['search_result_excerpt'] = $result_excerpt;
            $glob['search_result_url'] = $result_url;
            $glob['search_result_date'] = $result_date;
            $GLOBALS['this_result'] = $glob;
            $thisresult = $form;
            $results[] = parse($thisresult);
        }
    }
    return is_array($results) ? join('', $results) : '';
}
Example #3
0
function search($q)
{
    global $prefs;
    $url = $prefs['siteurl'];
    extract($prefs);
    $s_filter = filterSearch();
    $form = fetch('form', 'txp_form', 'name', 'search_results');
    // lose this eventually - only used if search_results form is missing
    $form = !$form ? legacy_form() : $form;
    $rs = safe_rows("*, ID as thisid, unix_timestamp(Posted) as posted, Title as title,\n\t\t\tmatch (Title,Body) against ('{$q}') as score", "textpattern", "(Title rlike '{$q}' or Body rlike '{$q}') {$s_filter}\n\t\t\tand Status = 4 and Posted <=now() order by score desc limit 40");
    if ($rs) {
        $result_rows = count($rs);
        $text = $result_rows == 1 ? gTxt('article_found') : gTxt('articles_found');
    } else {
        $result_rows = 0;
        $text = gTxt('articles_found');
    }
    $results[] = graf($result_rows . ' ' . $text);
    if ($result_rows > 0) {
        foreach ($rs as $a) {
            extract($a);
            $result_date = safe_strftime($archive_dateformat, $posted);
            $uTitle = $url_title ? $url_title : stripSpace($Title);
            $hurl = permlinkurl($a);
            $result_url = '<a href="' . $hurl . '">' . $hurl . '</a>';
            $result_title = '<a href="' . $hurl . '">' . $Title . '</a>';
            $result = preg_replace("/>\\s*</", "> <", $Body_html);
            preg_match_all("/\\s.{1,50}" . preg_quote($q) . ".{1,50}\\s/i", $result, $concat);
            $concat = join(" ... ", $concat[0]);
            $concat = strip_tags($concat);
            $concat = preg_replace('/^[^>]+>/U', "", $concat);
            $concat = preg_replace("/({$q})/i", "<strong>\$1</strong>", $concat);
            $result_excerpt = $concat ? "... " . $concat . " ..." : '';
            $glob['search_result_title'] = $result_title;
            $glob['search_result_excerpt'] = $result_excerpt;
            $glob['search_result_url'] = $result_url;
            $glob['search_result_date'] = $result_date;
            $GLOBALS['this_result'] = $glob;
            $thisresult = $form;
            $results[] = parse($thisresult);
        }
    }
    return is_array($results) ? join('', $results) : '';
}
Example #4
0
function search($q)
{
    global $prefs;
    $url = $prefs['siteurl'];
    extract($prefs);
    $s_filter = filterSearch();
    $form = fetch('form', 'txp_form', 'name', 'search_results');
    // lose this eventually - only used if search_results form is missing
    $form = !$form ? legacy_form() : $form;
    $rs = safe_rows("ID, Title, Body_html, Section, unix_timestamp(Posted) as uPosted, \n\t\t\tmatch (Title,Body) against ('{$q}') as score", "textpattern", "Title rlike '{$q}' or Body rlike '{$q}' {$s_filter}\n\t\t\tand Status = 4 and Posted <=now() order by score desc limit 40");
    if ($rs) {
        $result_rows = count($rs);
        $text = $result_rows == 1 ? gTxt('article_found') : gTxt('articles_found');
    } else {
        $result_rows = 0;
        $text = gTxt('articles_found');
    }
    $results[] = graf($result_rows . ' ' . $text);
    if ($result_rows > 0) {
        foreach ($rs as $a) {
            extract($a);
            $result_date = date("j M Y", $uPosted);
            $hurl = $url_mode ? $siteurl . $path_from_root . $Section . '/' . $ID . '/' . stripSpace($Title) : $siteurl . $path_from_root . 'index.php?id=' . $ID;
            $result_url = '<a href="http://' . $hurl . '">' . $hurl . '</a>';
            $result_title = '<a href="http://' . $hurl . '">' . $Title . '</a>';
            $result = preg_replace("/>\\s*</", "> <", $Body_html);
            preg_match_all("/\\s.{0,50}" . $q . ".{0,50}\\s/i", $result, $concat);
            $concat = implode(" ... ", $concat[0]);
            $concat = strip_tags($concat);
            $concat = preg_replace('/^[^>]+>/U', "", $concat);
            $concat = preg_replace("/({$q})/i", "<strong>\$1</strong>", $concat);
            $result_excerpt = $concat ? "... " . $concat . " ..." : '';
            $glob['search_result_title'] = $result_title;
            $glob['search_result_excerpt'] = $result_excerpt;
            $glob['search_result_url'] = $result_url;
            $glob['search_result_date'] = $result_date;
            $GLOBALS['this_result'] = $glob;
            $thisresult = $form;
            $results[] = parse($thisresult);
        }
    }
    return is_array($results) ? join('', $results) : '';
}
 function _getMetaWeblogContents($struct, $publish, $txp)
 {
     global $gmtoffset, $is_dst;
     $contents = array('Body' => str_replace('\\n', n, $struct['description']), 'Status' => $publish ? '4' : '1', 'Title' => $struct['title']);
     if (!empty($struct['categories'])) {
         if (!empty($struct['categories'][0])) {
             $c = $txp->getCategoryTitle($struct['categories'][0]);
             $contents['Category1'] = $c['name'];
         }
         if (!empty($struct['categories'][1])) {
             $c = $txp->getCategoryTitle($struct['categories'][1]);
             $contents['Category2'] = $c['name'];
         }
     }
     if (isset($struct['date_created_gmt'])) {
         $struct['dateCreated'] = $struct['date_created_gmt'];
         $struct['dateCreated']->tz = 'Z';
         // force GMT timezone
     }
     if (isset($struct['dateCreated'])) {
         if ($struct['dateCreated']->tz == 'Z') {
             // GMT-based posting time; transform into server time zone
             $posted = $struct['dateCreated']->getTimestamp() - tz_offset() + $gmtoffset + ($is_dst ? 3600 : 0);
         } elseif (!$struct['dateCreated']->tz) {
             // posting in an unspecified time zone: Assume site time.
             $posted = $struct['dateCreated']->getTimestamp() - tz_offset();
         } else {
             // numeric time zone offsets
             if (preg_match('/([+-][0-9]{2})([0-9]{2})/', $struct['dateCreated']->tz, $t)) {
                 $tz = $t[1] * 3600 + $t[2] * 60;
                 $posted = $struct['dateCreated']->getTimestamp() - tz_offset() + $gmtoffset + ($is_dst ? 3600 : 0) - $tz;
             }
         }
     }
     if (isset($posted)) {
         $contents['Posted'] = date('Y-m-d H:i:s', $posted);
     }
     // MovableType Implementation Add ons
     if (isset($struct['mt_allow_comments'])) {
         $contents['Annotate'] = $struct['mt_allow_comments'];
     }
     if (isset($struct['mt_convert_breaks'])) {
         $contents['textile_body'] = $contents['textile_excerpt'] = intval($struct['mt_convert_breaks']);
     }
     if (isset($struct['mt_text_more'])) {
         $contents['Body'] .= n . n . str_replace('\\n', n, $struct['mt_text_more']);
     }
     if (isset($struct['mt_excerpt'])) {
         $contents['Excerpt'] = str_replace('\\n', n, $struct['mt_excerpt']);
     }
     if (isset($struct['mt_keywords'])) {
         $contents['Keywords'] = $struct['mt_keywords'];
     }
     if (isset($struct['mt_basename'])) {
         $contents['url_title'] = stripSpace($struct['mt_basename']);
     } elseif (isset($struct['wp_slug'])) {
         $contents['url_title'] = stripSpace($struct['wp_slug']);
     }
     return $contents;
 }
Example #6
0
function import_blogger_item($item, $section, $status, $invite)
{
    # Untested import code follows
    if (empty($item)) {
        return;
    }
    include_once txpath . '/lib/classTextile.php';
    $textile = new Textile();
    $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;
    }
    //Bogger can use special chars 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) . "'")) {
        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) . "'");
        $parentid = mysql_insert_id();
        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';
}
Example #7
0
function doImportWP($b2dblogin, $b2db, $b2dbpass, $b2dbhost, $wpdbprefix, $insert_into_section, $insert_with_status, $default_comment_invite)
{
    global $txpcfg;
    //Keep some response on some part
    $results = array();
    // let's go - Dean says ;-).
    $b2link = mysql_connect($b2dbhost, $b2dblogin, $b2dbpass, true);
    if (!$b2link) {
        return 'wp database values don&#8217;t work. Go back, replace them and try again';
    }
    mysql_select_db($b2db, $b2link);
    $results[] = 'connected to wp database. Importing Data';
    $a = mysql_query("\n\t\t        select\n\t\t        " . $wpdbprefix . "posts.ID as ID,\n\t\t        " . $wpdbprefix . "posts.post_date as Posted,\n\t\t        " . $wpdbprefix . "posts.post_title as Title,\n\t\t        " . $wpdbprefix . "posts.post_content as Body,\n\t\t        " . $wpdbprefix . "users.user_login as AuthorID\n\t\t        from " . $wpdbprefix . "posts\n\t\t        left join " . $wpdbprefix . "users on\n\t\t            " . $wpdbprefix . "users.ID = " . $wpdbprefix . "posts.post_author\n\t\t    ", $b2link) or $results[] = mysql_error();
    while ($b = mysql_fetch_array($a)) {
        //Clean ugly wp slashes before to continue
        $b = undoSlash(undoSlash($b));
        //Trap comments for each article
        $comments = array();
        $q = "\n\t\t\t        select\n\t\t\t        " . $wpdbprefix . "comments.comment_author_IP as ip,\n\t\t\t        " . $wpdbprefix . "comments.comment_author as name,\n\t\t\t        " . $wpdbprefix . "comments.comment_author_email as email,\n\t\t\t        " . $wpdbprefix . "comments.comment_author_url as web,\n\t\t\t        " . $wpdbprefix . "comments.comment_content as message,\n\t\t\t        " . $wpdbprefix . "comments.comment_date as posted\n\t\t\t        from " . $wpdbprefix . "comments where comment_post_ID='" . $b['ID'] . "'\n\t\t\t    ";
        $c = mysql_query($q, $b2link) or $results[] = mysql_error();
        while ($d = mysql_fetch_assoc($c)) {
            $d = undoSlash(undoSlash($d));
            $comments[] = $d;
        }
        $b['comments'] = $comments;
        unset($comments);
        //Post categories now
        $q = "\n\t\t\t      select\n\t\t\t        " . $wpdbprefix . "post2cat.category_id as catid,\n\t\t\t        " . $wpdbprefix . "categories.cat_name as catname\n\t\t\t        from " . $wpdbprefix . "post2cat\n\t\t\t        left join " . $wpdbprefix . "categories on\n\t\t\t          " . $wpdbprefix . "categories.cat_ID = " . $wpdbprefix . "post2cat.category_id where " . $wpdbprefix . "post2cat.post_id='" . $b['ID'] . "' limit 2        \n\t\t\t        ";
        $e = mysql_query($q, $b2link) or $results[] = mysql_error();
        while ($f = mysql_fetch_array($e)) {
            $categories[] = $f;
        }
        $b['Category1'] = !empty($categories[0]) ? $categories[0]['catname'] : '';
        $b['Category2'] = !empty($categories[1]) ? $categories[1]['catname'] : '';
        unset($categories);
        $articles[] = $b;
    }
    $a = mysql_query("\n\t\t      select\n\t\t        " . $wpdbprefix . "categories.cat_ID as catid,\n\t\t        " . $wpdbprefix . "categories.cat_name as catname,\n\t\t        " . $wpdbprefix . "categories.category_parent as catparent\n\t\t        from " . $wpdbprefix . "categories\n\t\t        ", $b2link) or $results[] = mysql_error();
    while ($b = mysql_fetch_array($a)) {
        $cats[] = $b;
    }
    mysql_close($b2link);
    //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);
    include txpath . '/lib/classTextile.php';
    $textile = new Textile();
    if (!empty($articles)) {
        foreach ($articles as $a) {
            //Ugly, really ugly way to workaround the slashes WP gotcha
            $a['Body'] = str_replace('<!--more-->', '', $a['Body']);
            $a['Body_html'] = $textile->textileThis($a['Body']);
            extract($a);
            //can not use array slash due to way on which comments are selected
            $q = mysql_query("\n\t\t\t                insert into " . PFX . "textpattern set\n\t\t\t                Posted    = '" . addslashes($Posted) . "',\n\t\t\t                Title     = '" . addslashes($textile->TextileThis($Title, 1)) . "',\n\t\t\t                url_title = '" . stripSpace($Title) . "',\n\t\t\t                Body      = '" . addslashes($Body) . "',\n\t\t\t                Body_html = '" . addslashes($Body_html) . "',\n\t\t\t                AuthorID  = '" . addslashes($AuthorID) . "',\n\t\t\t                Category1 = '" . addslashes($Category1) . "',\n\t\t\t                Category2 = '" . addslashes($Category2) . "',\n\t\t\t                Section   = '{$insert_into_section}',\n\t\t\t                uid='" . md5(uniqid(rand(), true)) . "',\n\t\t\t\t\t\t\tfeed_time='" . substr($Posted, 0, 10) . "',\n\t\t\t                AnnotateInvite = '{$default_comment_invite}',\n\t\t\t                Status    = '{$insert_with_status}'\n\t\t\t            ", $txplink) or $results[] = mysql_error();
            if ($insertID = mysql_insert_id()) {
                $results[] = 'inserted wp_ entry ' . $Title . ' into Textpattern as article ' . $insertID . '';
                if (!empty($comments)) {
                    foreach ($comments as $comment) {
                        extract(array_slash($comment));
                        //The ugly workaroud again
                        $message = nl2br($message);
                        $r = mysql_query("insert into " . PFX . "txp_discuss set\t\t\t\t\t\n\t\t\t\t\t\t\t                parentid = '{$insertID}',\n\t\t\t\t\t\t\t                name = '{$name}',\n\t\t\t\t\t\t\t                email = '{$email}',\n\t\t\t\t\t\t\t                web = '{$web}',\n\t\t\t\t\t\t\t                ip = '{$ip}',\n\t\t\t\t\t\t\t                posted = '{$posted}',\n\t\t\t\t\t\t\t                message = '{$message}',\n\t\t\t\t\t\t\t                visible = 1", $txplink) or $results[] = mysql_error();
                        if ($commentID = mysql_insert_id()) {
                            $results[] = 'inserted wp_ comment <strong>' . $commentID . '</strong> into txp_discuss';
                        }
                    }
                }
            }
        }
    }
    if (!empty($cats)) {
        $right = 2;
        $left = 1;
        foreach ($cats as $cat) {
            extract(array_slash($cat));
            //Prevent repeated categories
            $rs = safe_row('id', 'txp_category', "name='{$catname}'");
            if (!$rs) {
                $left++;
                $right++;
                $q = mysql_query("\n\t\t\t\t            insert into " . PFX . "txp_category set\n\t\t\t\t             name = '{$catname}',\n\t\t\t\t             type = 'article',\n\t\t\t\t             parent = 'root',\n\t\t\t\t             lft = '{$left}',\n\t\t\t\t             rgt = '{$right}'", $txplink) or $results[] = mysql_error($q);
                if (mysql_insert_id()) {
                    $results[] = 'inserted wp_ category <strong>' . $catname . '</strong> into txp_category';
                }
            }
        }
    }
    return join('<br />', $results);
}
Example #8
0
    /**
     * Reads a CSV and inserts it into the textpattern table.
     *
     * @param resource $handle File opened with fopen()
     * @param int $status Article status.
     */
    public function import($handle, $status)
    {
        global $prefs, $txp_user;
        $row = 1;
        while (($csv = fgetcsv($handle, 0, ',')) !== FALSE) {
            $fields = count($csv);
            if ($row === 1) {
                for ($i = 0; $i < $fields; $i++) {
                    $header[$i] = $csv[$i];
                }
            } else {
                $insert = '';
                foreach ($header as $key => $value) {
                    // escape all fields
                    $csv[$key] = doSlash($csv[$key]);
                    if ($value === 'Title') {
                        $url_title = stripSpace($csv[$key], 1);
                    }
                    if ($value === 'Body' || $value === 'Excerpt') {
                        $insert .= "{$value}_html='{$csv[$key]}',";
                    }
                    $insert .= "{$value}='{$csv[$key]}',";
                }
                $uid = md5(uniqid(rand(), true));
                $insert .= <<<EOD
AuthorID='{$txp_user}',
LastModID='{$txp_user}',
AnnotateInvite='{$prefs['comments_default_invite']}',
url_title='{$url_title}',
uid='{$uid}',
feed_time=now(),
Posted=now(),
LastMod=now(),
Status={$status},
textile_body=0,
textile_excerpt=0
EOD;
                safe_insert('textpattern', $insert);
            }
            $row++;
        }
    }
 /**
  * _cbe_rndc_pop_art - Admin-side: Generate articles
  *
  * See "Rules for articles" in the helpfile
  *
  * @return  array
  */
 function _cbe_rndc_pop_art(&$message, &$html)
 {
     global $event, $comments_on_default, $comments_default_invite;
     $next_step = NULL;
     include_once txpath . '/lib/classTextile.php';
     $out = array();
     $globerrlevel = '';
     $message = gTxt(CBE_RNDC_LPFX . 'populate_end');
     if (($use_textile = get_pref('use_textile')) == USE_TEXTILE) {
         include_once txpath . '/lib/classTextile.php';
     }
     $authors = safe_column_num('name', 'txp_users', "`privs`<6");
     $posauthor = count($authors) - 1;
     $sections = safe_column_num('name', 'txp_section', "`on_frontpage`=1 AND `name`!='default'");
     $possection = count($sections) - 1;
     $categories = safe_column_num('name', 'txp_category', " `name`!='root' AND `type`='article'");
     $poscategory = count($categories) - 1;
     $stati = array(STATUS_LIVE, STATUS_LIVE, STATUS_DRAFT, STATUS_LIVE, STATUS_LIVE, STATUS_HIDDEN, STATUS_LIVE, STATUS_LIVE, STATUS_PENDING, STATUS_LIVE, STATUS_LIVE);
     $posstatus = count($stati) - 1;
     $rndnb = rand(10, 15);
     $aAids = array();
     $errlevel = "success";
     for ($i = 0; $i < $rndnb; $i++) {
         $seeddate = rand(time() - 300 * 24 * 60 * 60, time() + 60 * 24 * 60 * 60);
         $in = rand(0, 9);
         $status = $stati[rand(0, $posstatus)];
         $published = date("Y-m-d H:i:s", $seeddate);
         $lastmod = date("Y-m-d H:i:s");
         $expires = in_array($in, array(0, 4, 8)) ? '' : date("Y-m-d H:i:s", strtotime("+{$in} months", $seeddate));
         $feeddate = date("Y-m-d", $seeddate);
         $author = $authors[rand(0, $posauthor)];
         $section = $sections[rand(0, $possection)];
         $category1 = $categories[rand(0, $poscategory)];
         if (($category2 = $in == 0 ? '' : $categories[rand(0, $poscategory)]) == $category1) {
             $category2 = '';
         }
         $title = substr(_cbe_rndc_sentence(3, 5, 3, 6), 0, -1);
         $url_title = stripSpace($title, 1);
         $excerpt = _cbe_rndc_text(6, 10, 2, 8);
         $arrbody = array();
         $parag = rand(2, 5);
         for ($j = 0; $j < $parag; $j++) {
             $arrbody[] .= _cbe_rndc_text(6, 8, 5, 10) . n;
         }
         $body = join(n, $arrbody);
         switch ($use_textile) {
             case USE_TEXTILE:
                 $textile = new Textile(get_pref('doctype'));
                 $title = $textile->TextileThis($title, '', 1);
                 $body_html = $textile->TextileThis($body);
                 $excerpt_html = $textile->TextileThis($excerpt);
                 break;
             case LEAVE_TEXT_UNTOUCHED:
                 $body_html = trim($body);
                 $excerpt_html = trim($excerpt);
                 break;
             case CONVERT_LINEBREAKS:
                 $body_html = nl2br(trim($body));
                 $excerpt_html = nl2br(trim($excerpt));
                 break;
             default:
                 break;
         }
         if ($insertd = safe_insert("textpattern", "Title           = '{$title}',\n                                       Body            = '{$body}',\n                                       Body_html       = '{$body_html}',\n                                       Excerpt         = '{$excerpt}',\n                                       Excerpt_html    = '{$excerpt_html}',\n                                       Status          = '{$status}',\n                                       Posted          = '{$published}',\n                                       Expires         = '{$expires}',\n                                       AuthorID        = '{$author}',\n                                       LastMod         = '{$lastmod}',\n                                       LastModID       = '{$author}',\n                                       Section         = '{$section}',\n                                       Category1       = '{$category1}',\n                                       Category2       = '{$category2}',\n                                       textile_body    =  {$use_textile},\n                                       textile_excerpt =  {$use_textile},\n                                       Annotate        =  {$comments_on_default},\n                                       url_title       = '" . doSlash($url_title) . "',\n                                       AnnotateInvite  = '{$comments_default_invite}',\n                                       uid             = '" . md5(uniqid(rand(), true)) . "',\n                                       feed_time       = '{$feeddate}'")) {
             $aAids[] = $insertd;
         } else {
             $errlevel = "warning";
             $globerrlevel = E_ERROR;
         }
     }
     $out[] = graf(tag(gTxt(CBE_RNDC_LPFX . 'populate_end'), 'span', ' class="' . $errlevel . '"') . ': ' . join(", ", $aAids));
     if (!empty($globerrlevel)) {
         $message .= ' ' . gTxt(CBE_RNDC_LPFX . 'with_errors');
     }
     $back = tag(fInput('submit', 'submit', gTxt(CBE_RNDC_LPFX . 'go_back'), 'publish') . n . sInput(CBE_RNDC_SPFX . 'initiate') . n . eInput($event), 'div');
     $html = join(n, $out) . form($back);
     return $next_step;
 }
Example #10
0
function related_articles($atts)
{
    if (is_array($atts)) {
        extract($atts);
    }
    global $pretext, $thisid;
    extract($pretext);
    $label = empty($label) ? "" : $label;
    $limit = empty($limit) ? 10 : $limit;
    $break = empty($break) ? br : $break;
    $wraptag = empty($wraptag) ? "" : $wraptag;
    if ($thisid) {
        $id = $thisid;
    }
    $cats = safe_row("Category1,Category2", "textpattern", "ID='{$id}' limit 1");
    if (!empty($cats[0]) or !empty($cats[1])) {
        $q = array("select * from " . PFX . "textpattern where Status = 4 and ID!='{$id}'", !empty($cats[0]) ? "and ((Category1='{$cats['0']}') or (Category2='{$cats['0']}'))" : '', !empty($cats[1]) ? "or ((Category1='{$cats['1']}') or (Category2='{$cats['1']}'))" : '', "and Status=4 and Posted <= now() order by Posted desc limit 0,{$limit}");
        $rs = getRows(join(' ', $q));
        if ($rs) {
            if ($label) {
                $out[] = $label;
            }
            foreach ($rs as $a) {
                extract($a);
                $conTitle = $url_title ? $url_title : stripSpace($Title);
                $out[] = $url_mode ? tag($Title, 'a', ' href="' . $pfr . $Section . '/' . $ID . '/' . $conTitle . '"') : tag($Title, 'a', ' href="' . $pfr . 'index.php?id=' . $ID . '"');
            }
            if (is_array($out)) {
                if ($break == 'li') {
                    return $wraptag ? tag("<li>" . join("</li>\n<li>", $out) . "</li>", $wraptag) : "<li>" . join("</li>\n<li>", $out) . "</li>";
                }
                return $wraptag ? tag(join($break . n, $out), $wraptag) : join($break . n, $out);
            }
        }
    }
    return '';
    unset($GLOBALS['thisid']);
}
Example #11
0
function formatHref($pfr, $Section, $ID, $Linktext, $Title, $class = "")
{
    global $url_mode;
    $class = $class ? ' class="' . $class . '"' : '';
    return $url_mode == 1 ? '<a href="' . $pfr . $Section . '/' . $ID . '/' . stripSpace($Title) . '"' . $class . '>' . $Linktext . '</a>' : '<a href="' . $pfr . 'index.php?id=' . $ID . '"' . $class . '>' . $Linktext . '</a>';
}
Example #12
0
function atom()
{
    global $thisarticle;
    extract($GLOBALS['prefs']);
    define("t_texthtml", ' type="text/html"');
    define("t_text", ' type="text"');
    define("t_html", ' type="html"');
    define("t_xhtml", ' type="xhtml"');
    define('t_appxhtml', ' type="xhtml"');
    define("r_relalt", ' rel="alternate"');
    define("r_relself", ' rel="self"');
    $area = doSlash(gps('area'));
    extract(doSlash(gpsa(array('category', 'section', 'limit'))));
    $last = fetch('unix_timestamp(val)', 'txp_prefs', 'name', 'lastmod');
    $sitename .= $section ? ' - ' . $section : '';
    $sitename .= $category ? ' - ' . $category : '';
    $pub = safe_row("RealName, email", "txp_users", "privs=1");
    $out[] = tag($sitename, 'title', t_text);
    $out[] = tag($site_slogan, 'subtitle', t_text);
    $out[] = '<link' . r_relself . ' href="' . pagelinkurl(array('atom' => 1)) . '" />';
    $out[] = '<link' . r_relalt . t_texthtml . ' href="' . hu . '" />';
    $articles = array();
    //Atom feeds with mail or domain name
    $dn = explode('/', $siteurl);
    $mail_or_domain = $use_mail_on_feeds_id ? eE($blog_mail_uid) : $dn[0];
    $out[] = tag('tag:' . $mail_or_domain . ',' . $blog_time_uid . ':' . $blog_uid . ($section ? '/' . $section : '') . ($category ? '/' . $category : ''), 'id');
    $out[] = tag('Textpattern', 'generator', ' uri="http://textpattern.com/" version="' . $version . '"');
    $out[] = tag(gmdate("Y-m-d\\TH:i:s\\Z", $last), 'updated');
    $auth[] = tag($pub['RealName'], 'name');
    $auth[] = $include_email_atom ? tag(eE($pub['email']), 'email') : '';
    $auth[] = tag(hu, 'uri');
    $out[] = tag(n . t . t . join(n . t . t, $auth) . n, 'author');
    if (!$area or $area == 'article') {
        $sfilter = $section ? "and Section = '" . $section . "'" : '';
        $cfilter = $category ? "and (Category1='" . $category . "' or Category2='" . $category . "')" : '';
        $limit = $limit ? $limit : $rss_how_many;
        $limit = min($limit, max(100, $rss_how_many));
        $frs = safe_column("name", "txp_section", "in_rss != '1'");
        $query = array();
        foreach ($frs as $f) {
            $query[] = "and Section != '" . doSlash($f) . "'";
        }
        $query[] = $sfilter;
        $query[] = $cfilter;
        $rs = safe_rows_start("*, \n\t\t\t\tID as thisid, \n\t\t\t\tunix_timestamp(Posted) as uPosted,\n\t\t\t\tunix_timestamp(LastMod) as uLastMod", "textpattern", "Status=4 and Posted <= now() " . join(' ', $query) . "order by Posted desc limit {$limit}");
        if ($rs) {
            while ($a = nextRow($rs)) {
                extract($a);
                populateArticleData($a);
                $e = array();
                $a['posted'] = $uPosted;
                if ($show_comment_count_in_feed) {
                    $count = $comments_count > 0 ? ' [' . $comments_count . ']' : '';
                } else {
                    $count = '';
                }
                $thisauthor = get_author_name($AuthorID);
                $e['thisauthor'] = tag(n . t . t . t . tag(htmlspecialchars($thisauthor), 'name') . n . t . t, 'author');
                $e['issued'] = tag(gmdate('Y-m-d\\TH:i:s\\Z', $uPosted), 'published');
                $e['modified'] = tag(gmdate('Y-m-d\\TH:i:s\\Z', $uLastMod), 'updated');
                $escaped_title = escape_title($Title);
                $escaped_title = preg_replace("/&(?![#a-z0-9]+;)/i", '&amp;', $escaped_title);
                $escaped_title = str_replace('<', '&lt;', $escaped_title);
                $escaped_title = str_replace('>', '&gt;', $escaped_title);
                $e['title'] = tag($escaped_title . $count, 'title');
                $uTitle = $url_title ? $url_title : stripSpace($Title);
                $uTitle = htmlspecialchars($uTitle, ENT_NOQUOTES);
                $permlink = permlinkurl($a);
                $e['link'] = '<link' . r_relalt . t_texthtml . ' href="' . $permlink . '" />';
                $e['id'] = tag('tag:' . $mail_or_domain . ',' . $feed_time . ':' . $blog_uid . '/' . $uid, 'id');
                $e['category1'] = trim($Category1) ? '<category term="' . htmlspecialchars($Category1) . '" />' : '';
                $e['category2'] = trim($Category2) ? '<category term="' . htmlspecialchars($Category2) . '" />' : '';
                $Excerpt = fixup_for_feed($thisarticle['excerpt'], permlinkurl($a));
                if ($syndicate_body_or_excerpt == 0) {
                    $Body = fixup_for_feed($thisarticle['body'], permlinkurl($a));
                } else {
                    $Body = '';
                    // If there's no excerpt, use body as content instead of body as summary
                    if (!trim($Excerpt)) {
                        $Body = fixup_for_feed($thisarticle['body'], permlinkurl($a));
                    }
                }
                if (trim($Body)) {
                    $e['content'] = tag(n . $Body . n, 'content', t_html);
                }
                if (trim($Excerpt)) {
                    $e['summary'] = tag(n . $Excerpt . n, 'summary', t_html);
                }
                $articles[$ID] = tag(n . t . t . join(n . t . t, $e) . n, 'entry');
                $etags[$ID] = strtoupper(dechex(crc32($articles[$ID])));
                $dates[$ID] = $uLastMod;
            }
        }
    } elseif ($area == 'link') {
        $cfilter = $category ? "category='" . $category . "'" : '1';
        $limit = $limit ? $limit : $rss_how_many;
        $limit = min($limit, max(100, $rss_how_many));
        $rs = safe_rows_start("*", "txp_link", "{$cfilter} order by date desc limit {$limit}");
        if ($rs) {
            while ($a = nextRow($rs)) {
                extract($a);
                $e['title'] = tag(doSpecial($linkname), 'title');
                $content = utf8_encode(htmlspecialchars($description));
                $e['content'] = tag(n . $description . n, 'content', t_texthtml);
                $url = preg_replace("/^\\/(.*)/", "http://{$siteurl}/\$1", $url);
                $url = preg_replace("/&((?U).*)=/", "&amp;\\1=", $url);
                $e['link'] = '<link' . r_relalt . t_texthtml . ' href="' . $url . '" />';
                $e['issued'] = tag(gmdate('Y-m-d\\TH:i:s\\Z', strtotime($date)), 'published');
                $e['modified'] = tag(gmdate('Y-m-d\\TH:i:s\\Z', strtotime($date)), 'updated');
                $e['id'] = tag('tag:' . $mail_or_domain . ',' . $feed_time . ':' . $id, 'id');
                $articles[$id] = tag(n . t . t . join(n . t . t, $e) . n, 'entry');
                $etags[$id] = strtoupper(dechex(crc32($articles[$id])));
                $dates[$id] = $date;
            }
        }
    }
    if (!empty($articles)) {
        //turn on compression if we aren't using it already
        if (extension_loaded('zlib') && ini_get("zlib.output_compression") == 0 && ini_get('output_handler') != 'ob_gzhandler' && !headers_sent()) {
            @ob_start("ob_gzhandler");
        }
        $expires = gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 3600 * 1);
        header("Expires: {$expires}");
        $hims = serverset('HTTP_IF_MODIFIED_SINCE');
        $imsd = $hims ? strtotime($hims) : 0;
        if ($imsd >= $last) {
            txp_status_header("304 Not Modified");
            exit;
        }
        header("Last-Modified: " . gmdate('D, d M Y H:i:s \\G\\M\\T', $last));
        if (is_callable('apache_request_headers')) {
            $headers = apache_request_headers();
            if (isset($headers["A-IM"])) {
                $canaim = strpos($headers["A-IM"], "feed");
            } else {
                $canaim = false;
            }
        } else {
            $canaim = false;
        }
        $hinm = stripslashes(serverset('HTTP_IF_NONE_MATCH'));
        $cutarticles = false;
        if ($canaim !== false) {
            foreach ($articles as $id => $thing) {
                if (strpos($hinm, $etags[$id])) {
                    unset($articles[$id]);
                    $cutarticles = true;
                    $cut_etag = true;
                }
                if ($dates[$id] < $imsd) {
                    unset($articles[$id]);
                    $cutarticles = true;
                    $cut_time = true;
                }
            }
        }
        if (isset($cut_etag) && isset($cut_time)) {
            header("Vary: If-None-Match, If-Modified-Since");
        } else {
            if (isset($cut_etag)) {
                header("Vary: If-None-Match");
            } else {
                if (isset($cut_time)) {
                    header("Vary: If-Modified-Since");
                }
            }
        }
        $etag = @join("-", $etags);
        if (strstr($hinm, $etag)) {
            header("HTTP/1.1 304 Not Modified");
            exit;
        }
        if ($etag) {
            header('ETag: "' . $etag . '"');
        }
        if ($cutarticles) {
            //header("HTTP/1.1 226 IM Used");
            //This should be used as opposed to 200, but Apache doesn't like it.
            //http://intertwingly.net/blog/2004/09/11/Vary-ETag/ says that the status code should be 200.
            header("Cache-Control: no-store, im");
            header("IM: feed");
        }
        $out = array_merge($out, $articles);
        header('Content-type: application/atom+xml; charset=utf-8');
        return chr(60) . '?xml version="1.0" encoding="UTF-8"?' . chr(62) . n . '<feed xml:lang="' . $language . '" xmlns="http://www.w3.org/2005/Atom">' . join(n, $out) . '</feed>';
    }
}
Example #13
0
 /**
  * Executes the real action for @see udpateArticleId and @see newArticle
  * @param array $incoming containing the desired article fields
  * @param mixed(string|integer) $article_id the ID of the article to update
  * @return mixed integer article id on success, false otherwise
  * @access private
  */
 function _setArticle($incoming, $article_id = null)
 {
     global $txpcfg;
     $prefs = get_prefs();
     extract($prefs);
     if (!empty($incoming['Section']) && !$this->getSection($incoming['Section'])) {
         return false;
     }
     if (!empty($incoming['Category1']) && !$this->getCategory($incoming['Category1'])) {
         return false;
     }
     if (!empty($incoming['Category2']) && !$this->getCategory($incoming['Category2'])) {
         return false;
     }
     if ($article_id !== null) {
         $article_id = assert_int($article_id);
     }
     //All validation rules assumed to be passed before this point.
     //Do content processing here
     $incoming_with_markup = $this->textile_main_fields($incoming, $use_textile);
     $incoming['Title'] = $incoming_with_markup['Title'];
     if (empty($incoming['Body_html']) && !empty($incoming['Body'])) {
         $incoming['Body_html'] = $incoming_with_markup['Body_html'];
     }
     if (empty($incoming['Excerpt_html']) && !empty($incoming['Excerpt'])) {
         $incoming['Excerpt_html'] = $incoming_with_markup['Excerpt_html'];
     }
     unset($incoming_with_markup);
     if (empty($incoming['Posted'])) {
         if ($article_id === null) {
             $when = !$article_id ? 'now()' : '';
             $incoming['Posted'] = $when;
         } else {
             # do not override post time for existing articles unless Posted is present
             unset($incoming['Posted']);
         }
     } else {
         $when = strtotime($incoming['Posted']) - tz_offset();
         $when = "from_unixtime({$when})";
     }
     if ($incoming['Title'] || $incoming['Body'] || $incoming['Excerpt']) {
         //Build SQL then and run query
         //Prevent data erase if not defined on the update action
         //but it was on the DB from a previous creation/edition time
         if ($article_id) {
             $old = safe_row('*', 'textpattern', "ID = {$article_id}");
             //Status should be defined previously. Be sure of that.
             if (!has_privs('article.publish', $this->txp_user) && $incoming['Status'] == 4 && $old['Status'] != 4) {
                 $incoming['Status'] = 3;
             }
             foreach ($old as $key => $val) {
                 if (!isset($incoming[$key])) {
                     $incoming[$key] = $val;
                 }
             }
         } else {
             //Status should be defined previously. Be sure of that.
             if (!has_privs('article.publish', $this->txp_user) && $incoming['Status'] == 4) {
                 $incoming['Status'] = 3;
             }
         }
         if (empty($incoming['Section']) && $article_id) {
             $incoming['Section'] = safe_field('Section', 'textpattern', "ID = {$article_id}");
         }
         $incoming = $this->_check_keys($incoming, array('AuthorID' => $this->txp_user, 'Annotate' => $comments_on_default, 'AnnotateInvite' => $comments_default_invite, 'textile_body' => $use_textile, 'textile_excerpt' => $use_textile, 'url_title' => stripSpace($incoming['Title'])));
         //Build the SQL query
         $sql = array();
         foreach ($incoming as $key => $val) {
             if ($key == 'Posted' && $val == 'now()') {
                 $sql[] = "{$key} = {$val}";
             } elseif ($key != 'ID' && $key != 'uid' && $key != 'feed_time' && $key != 'LastMod' && $key != 'LastModID') {
                 $sql[] = "{$key} = '" . doSlash($val) . "'";
             }
         }
         $sql[] = 'LastMod = now()';
         $sql[] = "LastModID = '" . doSlash($this->txp_user) . "'";
         if (!$article_id) {
             $sql[] = "uid = '" . doSlash(md5(uniqid(rand(), true))) . "'";
         }
         if (!$article_id) {
             if (empty($incoming['Posted'])) {
                 $sql[] = "feed_time = curdate()";
             } else {
                 $when = strtotime($incoming['Posted']) - tz_offset();
                 $when = strftime("%Y-%m-%d", $when);
                 $sql[] = "feed_time ='" . doSlash($when) . "'";
             }
         }
         $sql = join(', ', $sql);
         $rs = $article_id ? safe_update('textpattern', $sql, "ID = {$article_id}") : safe_insert('textpattern', $sql);
         $oldstatus = $article_id ? $old['Status'] : '';
         if (!$article_id && $rs) {
             $article_id = $rs;
         }
         if ($incoming['Status'] >= 4 && !$article_id || $oldstatus != 4 && $article_id) {
             safe_update("txp_prefs", "val = now()", "name = 'lastmod'");
             //@$this->_sendPings();
         }
         return $article_id;
     }
     return false;
 }
function sed_get_comment_class($atts)
{
    global $thiscomment, $thisarticle;
    global $logfile, $logging;
    $logfile = 'textpattern' . DS . 'tmp' . DS . 'sed_comment_pack.log.txt';
    #	print_r( "<br/>===== Start THIS COMMENT =====<br/>\n" );
    #	print_r( $thiscomment );
    #	print_r( "<br/>===== Start THIS ARTICLE =====<br/>\n" );
    #	print_r( $thisarticle );
    #	print_r( "<br/>==============================<br/><br/>\n" );
    extract(lAtts(array('author_class' => 'author', 'hide_odd_even' => '', 'odd_class' => 'odd', 'even_class' => 'even', 'count' => 'up', 'class' => 'comment', 'method' => 'check-email', 'per_name' => '1', 'cmtr_prefix' => 'commentator', 'log' => 'off'), $atts));
    $logging = 'on' === $log;
    $out_result = $class;
    # Every entry gets at least the base 'class'.
    #
    #	Process odd/even classes...
    #
    if (empty($hide_odd_even)) {
        $_comment_num = _sed_cp_get_comment_number($count);
        if (0 == ($_comment_num & 0x1)) {
            $out_result .= ' ' . $even_class;
        } else {
            $out_result .= ' ' . $odd_class;
        }
    }
    #
    #	Process the author_class...
    #
    if (!empty($author_class) and _sed_cp_if_author_comment($method)) {
        $out_result .= " {$author_class}";
    } else {
        #	Append a prefixed, dumbed-down, version of the commentator's name to the class defs.
        #
        if (!empty($per_name)) {
            $basic_name = stripSpace($thiscomment['name']);
            $out_result .= " {$cmtr_prefix}-{$basic_name}";
        }
    }
    #
    #	If there are any sed_class_extra variables (from the sed_comments tag handler) then append them too!
    #
    if (!empty($thiscomment['sed_class_extra'])) {
        $out_result .= $thiscomment['sed_class_extra'];
    }
    return $out_result;
}
Example #15
0
function permlinkurl($article_array)
{
    global $permlink_mode, $prefs;
    if (isset($prefs['custom_url_func']) and is_callable($prefs['custom_url_func'])) {
        return call_user_func($prefs['custom_url_func'], $article_array);
    }
    if (empty($article_array)) {
        return;
    }
    extract($article_array);
    if (!isset($title)) {
        $title = $Title;
    }
    if (empty($url_title)) {
        $url_title = stripSpace($title);
    }
    if (empty($section)) {
        $section = $Section;
    }
    // lame, huh?
    if (empty($posted)) {
        $posted = $Posted;
    }
    if (empty($thisid)) {
        $thisid = $ID;
    }
    $section = urlencode($section);
    $url_title = urlencode($url_title);
    switch ($permlink_mode) {
        case 'section_id_title':
            if ($prefs['attach_titles_to_permalinks']) {
                return hu . "{$section}/{$thisid}/{$url_title}";
            } else {
                return hu . "{$section}/{$thisid}/";
            }
        case 'year_month_day_title':
            list($y, $m, $d) = explode("-", date("Y-m-d", $posted));
            return hu . "{$y}/{$m}/{$d}/{$url_title}";
        case 'id_title':
            if ($prefs['attach_titles_to_permalinks']) {
                return hu . "{$thisid}/{$url_title}";
            } else {
                return hu . "{$thisid}/";
            }
        case 'section_title':
            return hu . "{$section}/{$url_title}";
        case 'title_only':
            return hu . "{$url_title}";
        case 'messy':
            return hu . "index.php?id={$thisid}";
    }
}
function product_post()
{
    global $txp_user, $vars, $txpcfg, $prefs;
    extract($prefs);
    define("IMPATH", $path_to_site . '/' . $img_dir . '/');
    $incoming = psa($vars);
    $import = false;
    $message = '';
    $wrapper = new TXP_Wrapper();
    $incoming = $wrapper->textile_main_fields($incoming, $use_textile);
    extract(doSlash($incoming));
    extract(array_map('assert_int', psa(array('Status', 'textile_body', 'textile_excerpt'))));
    $Annotate = ps('Annotate') ? assert_int(ps('Annotate')) : 0;
    if ($import) {
        $Status = $product['Status'];
    }
    $when = 'now()';
    if ($Title or $Body or $Excerpt) {
        if (!has_privs('article.publish') && $Status >= 4) {
            $Status = 3;
        }
        if (empty($url_title)) {
            $url_title = stripSpace($Title_plain, 1);
        }
        if (!$Annotate) {
            $Annotate = 0;
        }
        if (isset($new_vendor_name) && !empty($new_vendor_name)) {
            $custom_5 = $new_vendor_name;
            cat_vendor_category_create($custom_5);
        } else {
            if (isset($vendor)) {
                $custom_5 = $vendor;
            }
        }
        safe_insert("textpattern", "Title           = '{$Title}',\n\t\t\t\tBody            = '{$Body}',\n\t\t\t\tBody_html       = '{$Body_html}',\n\t\t\t\tExcerpt         = '{$Excerpt}',\n\t\t\t\tExcerpt_html    = '{$Excerpt_html}',\n\t\t\t\tImage           = '{$Image}',\n\t\t\t\tKeywords        = '{$Keywords}',\n\t\t\t\tStatus          =  {$Status},\n\t\t\t\tPosted          =  {$when},\n\t\t\t\tLastMod         =  now(),\n\t\t\t\tAuthorID        = '{$txp_user}',\n\t\t\t\tSection         = '{$Section}',\n\t\t\t\tCategory1       = '{$Category1}',\n\t\t\t\tCategory2       = '{$Category2}',\n\t\t\t\ttextile_body    =  {$textile_body},\n\t\t\t\ttextile_excerpt =  {$textile_excerpt},\n\t\t\t\tAnnotate        =  {$Annotate},\n\t\t\t\toverride_form   = '{$override_form}',\n\t\t\t\turl_title       = '{$url_title}',\n\t\t\t\tAnnotateInvite  = '{$AnnotateInvite}',\n\t\t\t\tcustom_1        = '{$custom_1}',\n\t\t\t\tcustom_2        = '{$custom_2}',\n\t\t\t\tcustom_3        = '{$custom_3}',\n\t\t\t\tcustom_4        = '{$custom_4}',\n\t\t\t\tcustom_5        = '{$custom_5}',\n\t\t\t\tcustom_6        = '{$custom_6}',\n\t\t\t\tcustom_7        = '{$custom_7}',\n\t\t\t\tcustom_8        = '{$custom_8}',\n\t\t\t\tcustom_9        = '{$custom_9}',\n\t\t\t\tcustom_10       = '{$custom_10}',\n\t\t\t\tuid\t\t\t\t= '" . md5(uniqid(rand(), true)) . "',\n\t\t\t\tfeed_time\t\t= now()");
        $GLOBALS['ID'] = mysql_insert_id();
        $ID = $GLOBALS['ID'];
        //print_r($_FILES);
        //CUSTOM FIELDS
        save_custom_fields($_REQUEST['custom_fields'], $ID);
        //IMAGE UPLOAD
        //=======================
        if ($_FILES["uploadFile"]["type"] == "image/gif" || $_FILES["uploadFile"]["type"] == "image/jpeg" || $_FILES["uploadFile"]["type"] == "image/png") {
            // prepare the image for insertion
            $img = $_FILES['uploadFile']['tmp_name'];
            upload_image($img, 1, $ID);
        }
        //END IMAGE UPLOAD
        //=======================
        if ($Status >= 4) {
            if (!function_exists("do_pings")) {
                require_once txpath . '/include/txp_article.php';
                do_pings();
            }
            update_lastmod();
        }
        product_edit("", "", "Product Saved");
    } else {
        product_edit();
    }
}
Example #17
0
function atom()
{
    global $thisarticle;
    extract($GLOBALS['prefs']);
    define("textplain", ' type="text/plain"');
    define("texthtml", ' type="text/html"');
    define("relalt", ' rel="alternate"');
    define('appxhtml', ' type="application/xhtml+xml"');
    define("divxhtml", '<div xmlns="http://www.w3.org/1999/xhtml">');
    $area = doSlash(gps('area'));
    extract(doSlash(gpsa(array('category', 'section', 'limit'))));
    $last = fetch('unix_timestamp(val)', 'txp_prefs', 'name', 'lastmod');
    $sitename .= $section ? ' - ' . $section : '';
    $sitename .= $category ? ' - ' . $category : '';
    $pub = safe_row("RealName, email", "txp_users", "privs=1");
    $out[] = tag($sitename, 'title', textplain);
    $out[] = tag($site_slogan, 'tagline', textplain);
    $out[] = '<link' . relalt . texthtml . ' href="' . hu . '" />';
    $articles = array();
    //Atom feeds with mail or domain name
    $dn = explode('/', $siteurl);
    $mail_or_domain = $use_mail_on_feeds_id ? eE($blog_mail_uid) : $dn[0];
    $out[] = tag('tag:' . $mail_or_domain . ',' . $blog_time_uid . ':' . $blog_uid . ($section ? '/' . $section : '') . ($category ? '/' . $category : ''), 'id');
    $out[] = tag('Textpattern', 'generator', ' url="http://textpattern.com" version="' . $version . '"');
    $out[] = tag(date("Y-m-d\\TH:i:s\\Z", $last), 'modified');
    $auth[] = tag($pub['RealName'], 'name');
    $auth[] = $include_email_atom ? tag(eE($pub['email']), 'email') : '';
    $auth[] = tag(hu, 'url');
    $out[] = tag(n . t . t . join(n . t . t, $auth) . n, 'author');
    if (!$area or $area == 'article') {
        $sfilter = $section ? "and Section = '" . $section . "'" : '';
        $cfilter = $category ? "and (Category1='" . $category . "' or Category2='" . $category . "')" : '';
        $limit = $limit ? $limit : '5';
        $frs = safe_column("name", "txp_section", "in_rss != '1'");
        foreach ($frs as $f) {
            $query[] = "and Section != '" . $f . "'";
        }
        $query[] = $sfilter;
        $query[] = $cfilter;
        $rs = safe_rows_start("*, \n\t\t\t\tID as thisid, \n\t\t\t\tunix_timestamp(Posted) as uPosted,\n\t\t\t\tunix_timestamp(LastMod) as uLastMod", "textpattern", "Status=4 and Posted <= now() " . join(' ', $query) . "order by Posted desc limit {$limit}");
        if ($rs) {
            while ($a = nextRow($rs)) {
                extract($a);
                populateArticleData($a);
                $a['posted'] = $uPosted;
                if ($show_comment_count_in_feed) {
                    $dc = getCount('txp_discuss', "parentid={$ID} and visible=1");
                    $count = $dc > 0 ? ' [' . $dc . ']' : '';
                } else {
                    $count = '';
                }
                $thisauthor = safe_field("RealName", "txp_users", "name='{$AuthorID}'");
                $e['thisauthor'] = tag(n . t . t . t . tag(htmlspecialchars($thisauthor), 'name') . n . t . t, 'author');
                $e['issued'] = tag(gmdate("Y-m-d\\TH:i:s\\Z", $uPosted), 'issued');
                $e['modified'] = tag(gmdate("Y-m-d\\TH:i:s\\Z", $uLastMod), 'modified');
                $escaped_title = safe_hed($Title);
                $escaped_title = preg_replace("/&(?![#a-z0-9]+;)/i", '&amp;', $escaped_title);
                $escaped_title = str_replace('<', '&lt;', $escaped_title);
                $escaped_title = str_replace('>', '&gt;', $escaped_title);
                $e['title'] = tag($escaped_title . $count, 'title');
                $uTitle = $url_title ? $url_title : stripSpace($Title);
                $uTitle = htmlspecialchars($uTitle, ENT_NOQUOTES);
                $permlink = permlinkurl($a);
                $e['link'] = '<link' . relalt . texthtml . ' href="' . $permlink . '" />';
                $e['id'] = tag('tag:' . $mail_or_domain . ',' . $feed_time . ':' . $blog_uid . '/' . $uid, 'id');
                $e['subject'] = tag(htmlspecialchars($Category1), 'dc:subject');
                // pull Body or Excerpt?
                $Body = !$syndicate_body_or_excerpt ? $thisarticle['body'] : $thisarticle['excerpt'];
                // if Excerpt is empty, switch back to Body_html
                $Body = !trim($Body) ? $thisarticle['body'] : $Body;
                // fix relative urls
                $Body = str_replace('href="/', 'href="' . hu, $Body);
                $Body = preg_replace("/href=\\\"#(.*)\"/", "href=\"" . permlinkurl($a) . "#\\1\"", $Body);
                $Body = safe_hed($Body);
                // encode and entify
                $Body = preg_replace(array('/</', '/>/', "/'/", '/"/'), array('&#60;', '&#62;', '&#039;', '&#34;'), $Body);
                // encode bare ampersands
                $Body = preg_replace("/&(?![#0-9]+;|\\w+;)/i", '&amp;', $Body);
                $e['content'] = tag(n . $Body . n, 'content', ' type="text/html" mode="escaped"');
                $articles[$ID] = tag(n . t . t . join(n . t . t, $e) . n, 'entry');
                $etags[$ID] = strtoupper(dechex(crc32($articles[$ID])));
                $dates[$ID] = $uLastMod;
            }
        }
    } elseif ($area == 'link') {
        $cfilter = $category ? "category='{$category}'" : '1';
        $limit = $limit ? $limit : 15;
        $rs = safe_rows_start("*", "txp_link", "{$cfilter} order by date desc limit {$limit}");
        if ($rs) {
            while ($a = nextRow($rs)) {
                extract($a);
                $e['title'] = tag(doSpecial($linkname), 'title');
                $content = utf8_encode(htmlspecialchars($description));
                $e['content'] = tag(n . $description . n, 'content', ' type="text/html" mode="escaped"');
                $url = preg_replace("/^\\/(.*)/", "http://{$siteurl}/\$1", $url);
                $url = preg_replace("/&((?U).*)=/", "&amp;\\1=", $url);
                $e['link'] = '<link' . relalt . texthtml . ' href="' . $url . '" />';
                $e['issued'] = tag(gmdate("Y-m-d\\TH:i:s\\Z", $date), 'issued');
                $e['modified'] = tag(gmdate("Y-m-d\\TH:i:s\\Z", $date), 'modified');
                $e['id'] = tag('tag:' . $mail_or_domain . ',' . $feed_time . ':' . $id, 'id');
                $articles[$id] = tag(n . t . t . join(n . t . t, $e) . n, 'entry');
                $etags[$id] = strtoupper(dechex(crc32($articles[$id])));
                $dates[$id] = $date;
            }
        }
    }
    if (!empty($articles)) {
        //turn on compression if we aren't using it already
        if (extension_loaded('zlib') && ini_get("zlib.output_compression") == 0 && ini_get('output_handler') != 'ob_gzhandler' && !headers_sent()) {
            ob_start("ob_gzhandler");
        }
        $last = fetch('unix_timestamp(val)', 'txp_prefs', 'name', 'lastmod');
        $last = gmdate("D, d M Y H:i:s \\G\\M\\T", $last);
        header("Last-Modified: {$last}");
        $expires = gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 3600 * 1);
        header("Expires: {$expires}");
        $hims = serverset('HTTP_IF_MODIFIED_SINCE');
        if ($hims == $last) {
            header("HTTP/1.1 304 Not Modified");
            exit;
        }
        $imsd = @strtotime($hims);
        if (is_callable('apache_request_headers')) {
            $headers = apache_request_headers();
            if (isset($headers["A-IM"])) {
                $canaim = strpos($headers["A-IM"], "feed");
            } else {
                $canaim = false;
            }
        } else {
            $canaim = false;
        }
        $hinm = stripslashes(serverset('HTTP_IF_NONE_MATCH'));
        $cutarticles = false;
        if ($canaim !== false) {
            foreach ($articles as $id => $thing) {
                if (strpos($hinm, $etags[$id])) {
                    unset($articles[$id]);
                    $cutarticles = true;
                    $cut_etag = true;
                }
                if ($dates[$id] < $imsd) {
                    unset($articles[$id]);
                    $cutarticles = true;
                    $cut_time = true;
                }
            }
        }
        if (isset($cut_etag) && isset($cut_time)) {
            header("Vary: If-None-Match, If-Modified-Since");
        } else {
            if (isset($cut_etag)) {
                header("Vary: If-None-Match");
            } else {
                if (isset($cut_time)) {
                    header("Vary: If-Modified-Since");
                }
            }
        }
        $etag = @join("-", $etags);
        if (strstr($hinm, $etag)) {
            header("HTTP/1.1 304 Not Modified");
            exit;
        }
        if ($etag) {
            header('ETag: "' . $etag . '"');
        }
        if ($cutarticles) {
            //header("HTTP/1.1 226 IM Used");
            //This should be used as opposed to 200, but Apache doesn't like it.
            //http://intertwingly.net/blog/2004/09/11/Vary-ETag/ says that the status code should be 200.
            header("Cache-Control: no-store, im");
            header("IM: feed");
        }
        $out = array_merge($out, $articles);
        ob_start();
        header('Content-type: application/atom+xml; charset=utf-8');
        return chr(60) . '?xml version="1.0" encoding="UTF-8"?' . chr(62) . n . '<feed version="0.3" xml:lang="' . $language . '" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">' . join(n, $out) . '</feed>';
    }
}
 function _permlinkurl($article_array, $type = PERMLINKURL, $pl_index = NULL)
 {
     global $pretext, $prefs, $production_status;
     if ($type == PAGELINKURL) {
         return $this->toggle_custom_url_func('pagelinkurl', $article_array);
     }
     if (empty($article_array)) {
         return;
     }
     if ($pl_index) {
         $pl = $this->get_permlink($pl_index);
     } else {
         // Get the matched pretext replacement array.
         $matched = count($this->matched_permlink) ? $this->matched_permlink : @array_shift(array_slice($this->partial_matches, -1));
         if (!isset($pl) && $matched && array_key_exists('id', $matched)) {
             // The permlink id is stored in the pretext replacement array, so we can find the permlink.
             $pl = $this->get_permlink($matched['permlink_id']);
             foreach ($pl['components'] as $pl_c) {
                 if (in_array($pl_c['type'], array('feed', 'page')) || !$this->check_permlink_conditions($pl, $article_array)) {
                     unset($pl);
                     break;
                 }
             }
         }
         if (!isset($pl)) {
             // We have no permlink id so grab the permlink with the highest precedence.
             $permlinks = $this->get_all_permlinks(1, array('feed', 'page'));
             foreach ($permlinks as $key => $pl) {
                 if (!$this->check_permlink_conditions($pl, $article_array)) {
                     unset($permlinks[$key]);
                 }
             }
             $pl = array_shift($permlinks);
         }
     }
     $uri = '';
     if (is_array($pl) && array_key_exists('components', $pl)) {
         extract($article_array);
         if (!isset($title)) {
             $title = $Title;
         }
         if (empty($url_title)) {
             $url_title = stripSpace($title);
         }
         if (empty($section)) {
             $section = $Section;
         }
         if (empty($posted)) {
             $posted = $Posted;
         }
         if (empty($authorid)) {
             $authorid = @$AuthorID;
         }
         if (empty($category1)) {
             $category1 = @$Category1;
         }
         if (empty($category2)) {
             $category2 = @$Category2;
         }
         if (empty($thisid)) {
             $thisid = $ID;
         }
         $pl_components = $pl['components'];
         // Check to see if there is a title component.
         $title = false;
         foreach ($pl_components as $pl_c) {
             if ($pl_c['type'] == 'title' || $pl_c['type'] == 'id') {
                 $title = true;
             }
         }
         // If there isn't a title component then we need to append one to the end of the URI
         if (!$title && $this->pref('automatically_append_title')) {
             $pl_components[] = array('type' => 'title', 'prefix' => '', 'suffix' => '', 'regex' => '', 'text' => '');
         }
         $uri = rtrim(doStrip(@$pretext['subpath']), '/');
         foreach ($pl_components as $pl_c) {
             $uri .= '/';
             $type = $pl_c['type'];
             switch ($type) {
                 case 'category':
                     if (!@$pl_c['category']) {
                         $pl_c['category'] = 1;
                     }
                     $primary = 'category' . $pl_c['category'];
                     $secondary = 'category' . (3 - (int) $pl_c['category']);
                     $check_context = $this->pref('join_pretext_to_pagelinks') && $this->pref('check_pretext_category_context');
                     if (!$check_context || ${$primary} == $pretext['c']) {
                         $uri_c = ${$primary};
                     } else {
                         if (!$check_context || ${$secondary} == $pretext['c']) {
                             $uri_c = ${$secondary};
                         } else {
                             if ($this->pref('debug') && in_array($production_status, array('debug', 'testing'))) {
                                 $uri_c = '--INVALID_CATEGORY--';
                             } else {
                                 unset($uri);
                                 break 2;
                             }
                         }
                     }
                     break;
                 case 'section':
                     $check_context = $this->pref('join_pretext_to_pagelinks') && $this->pref('check_pretext_section_context');
                     if (!$check_context || $section == $pretext['s']) {
                         $uri_c = $section;
                     } else {
                         unset($uri);
                         break 2;
                     }
                     break;
                 case 'title':
                     $uri_c = $url_title;
                     break;
                 case 'id':
                     $uri_c = $thisid;
                     break;
                 case 'author':
                     $uri_c = safe_field('RealName', 'txp_users', "name like '{$authorid}'");
                     break;
                 case 'login':
                     $uri_c = $authorid;
                     break;
                 case 'date':
                     $uri_c = explode('/', date('Y/m/d', $posted));
                     break;
                 case 'year':
                     $uri_c = date('Y', $posted);
                     break;
                 case 'month':
                     $uri_c = date('m', $posted);
                     break;
                 case 'day':
                     $uri_c = date('d', $posted);
                     break;
                 case 'custom':
                     if ($uri_c = @$article_array[$prefs["custom_{$pl_c['custom']}_set"]]) {
                     } else {
                         if ($uri_c = @$article_array["custom_{$pl_c['custom']}"]) {
                         } else {
                             if ($this->pref('debug') && in_array($production_status, array('debug', 'testing'))) {
                                 $uri_c = '--UNSET_CUSTOM_FIELD--';
                             } else {
                                 unset($uri);
                                 break 2;
                             }
                         }
                     }
                     break;
                 case 'text':
                     $uri_c = $pl_c['text'];
                     break;
                 case 'regex':
                     // Check to see if regex is valid without outputting error messages.
                     ob_start();
                     preg_match($pl_c['regex'], $pl_c['regex'], $regex_matches);
                     $is_valid_regex = !ob_get_clean();
                     if ($is_valid_regex) {
                         $key = "permlink_regex_{$pl_c['name']}";
                         $uri_c = array_key_exists($key, $pretext) ? $pretext[$key] : $regex_matches[0];
                     } else {
                         if ($this->pref('debug')) {
                             $uri_c = '--INVALID_REGEX--';
                         }
                     }
                     break;
             }
             if (empty($uri_c)) {
                 if ($this->pref('debug') && in_array($production_status, array('debug', 'testing'))) {
                     $uri_c = '--PERMLINK_FORMAT_ERROR--';
                 } else {
                     unset($uri);
                     break;
                 }
             }
             if (@$pl_c['prefix']) {
                 $uri .= $this->encode_url($pl_c['prefix']);
             }
             if (is_array($uri_c)) {
                 foreach ($uri_c as $uri_c2) {
                     $uri .= $this->encode_url($uri_c2) . '/';
                 }
                 $uri = rtrim($uri, '/');
             } else {
                 $uri .= $this->encode_url($uri_c);
             }
             if (@$pl_c['suffix']) {
                 $uri .= $this->encode_url($pl_c['suffix']);
             }
             unset($uri_c);
         }
         if (isset($uri)) {
             $uri .= '/';
         }
     }
     if ($uri_empty = empty($uri)) {
         // It is possible the uri is still empty if there is no match or if we're using
         // strict matching if so try the default permlink mode.
         $uri = $this->toggle_permlink_mode('permlinkurl', $article_array);
     }
     if ($this->pref('omit_trailing_slash')) {
         $uri = rtrim($uri, '/');
     }
     if (!$uri_empty && in_array(txpath . '/publish/rss.php', get_included_files()) || in_array(txpath . '/publish/atom.php', get_included_files()) || txpinterface == 'admin') {
         $host = rtrim(str_replace(rtrim(doStrip(@$pretext['subpath']), '/'), '', hu), '/');
         $uri = $host . $uri;
     }
     return $this->pref('force_lowercase_urls') ? strtolower($uri) : $uri;
 }
Example #19
0
/**
 * Processes sent forms and updates existing articles.
 */
function article_save()
{
    global $txp_user, $vars, $prefs;
    extract($prefs);
    $incoming = array_map('assert_string', psa($vars));
    $oldArticle = safe_row("Status, url_title, Title, textile_body, textile_excerpt,\n        UNIX_TIMESTAMP(LastMod) AS sLastMod, LastModID,\n        UNIX_TIMESTAMP(Posted) AS sPosted,\n        UNIX_TIMESTAMP(Expires) AS sExpires", 'textpattern', "ID = " . (int) $incoming['ID']);
    if (!($oldArticle['Status'] >= STATUS_LIVE and has_privs('article.edit.published') or $oldArticle['Status'] >= STATUS_LIVE and $incoming['AuthorID'] === $txp_user and has_privs('article.edit.own.published') or $oldArticle['Status'] < STATUS_LIVE and has_privs('article.edit') or $oldArticle['Status'] < STATUS_LIVE and $incoming['AuthorID'] === $txp_user and has_privs('article.edit.own'))) {
        // Not allowed, you silly rabbit, you shouldn't even be here.
        // Show default editing screen.
        article_edit();
        return;
    }
    if ($oldArticle['sLastMod'] != $incoming['sLastMod']) {
        article_edit(array(gTxt('concurrent_edit_by', array('{author}' => txpspecialchars($oldArticle['LastModID']))), E_ERROR), true, true);
        return;
    }
    if (!has_privs('article.set_markup')) {
        $incoming['textile_body'] = $oldArticle['textile_body'];
        $incoming['textile_excerpt'] = $oldArticle['textile_excerpt'];
    }
    $incoming = textile_main_fields($incoming);
    extract(doSlash($incoming));
    extract(array_map('assert_int', psa(array('ID', 'Status'))));
    // Comments may be on, off, or disabled.
    $Annotate = (int) $Annotate;
    if (!has_privs('article.publish') && $Status >= STATUS_LIVE) {
        $Status = STATUS_PENDING;
    }
    // Set and validate article timestamp.
    if ($reset_time) {
        $whenposted = "Posted = NOW()";
        $when_ts = time();
    } else {
        if (!is_numeric($year) || !is_numeric($month) || !is_numeric($day) || !is_numeric($hour) || !is_numeric($minute) || !is_numeric($second)) {
            $ts = false;
        } else {
            $ts = strtotime($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute . ':' . $second);
        }
        if ($ts === false || $ts < 0) {
            $when = $when_ts = $oldArticle['sPosted'];
            $msg = array(gTxt('invalid_postdate'), E_ERROR);
        } else {
            $when = $when_ts = $ts - tz_offset($ts);
        }
        $whenposted = "Posted = FROM_UNIXTIME({$when})";
    }
    // Set and validate expiry timestamp.
    if (empty($exp_year)) {
        $expires = 0;
    } else {
        if (empty($exp_month)) {
            $exp_month = 1;
        }
        if (empty($exp_day)) {
            $exp_day = 1;
        }
        if (empty($exp_hour)) {
            $exp_hour = 0;
        }
        if (empty($exp_minute)) {
            $exp_minute = 0;
        }
        if (empty($exp_second)) {
            $exp_second = 0;
        }
        $ts = strtotime($exp_year . '-' . $exp_month . '-' . $exp_day . ' ' . $exp_hour . ':' . $exp_minute . ':' . $exp_second);
        if ($ts === false || $ts < 0) {
            $expires = $oldArticle['sExpires'];
            $msg = array(gTxt('invalid_expirydate'), E_ERROR);
        } else {
            $expires = $ts - tz_offset($ts);
        }
    }
    if ($expires && $expires <= $when_ts) {
        $expires = $oldArticle['sExpires'];
        $msg = array(gTxt('article_expires_before_postdate'), E_ERROR);
    }
    if ($expires) {
        $whenexpires = "Expires = FROM_UNIXTIME({$expires})";
    } else {
        $whenexpires = "Expires = " . NULLDATETIME;
    }
    // Auto-update custom-titles according to Title, as long as unpublished and
    // NOT customised.
    if (empty($url_title) || $oldArticle['Status'] < STATUS_LIVE && $oldArticle['url_title'] === $url_title && $oldArticle['url_title'] === stripSpace($oldArticle['Title'], 1) && $oldArticle['Title'] !== $Title) {
        $url_title = stripSpace($Title_plain, 1);
    }
    $Keywords = doSlash(trim(preg_replace('/( ?[\\r\\n\\t,])+ ?/s', ',', preg_replace('/ +/', ' ', ps('Keywords'))), ', '));
    $user = doSlash($txp_user);
    $description = doSlash($description);
    $cfq = array();
    $cfs = getCustomFields();
    foreach ($cfs as $i => $cf_name) {
        $custom_x = "custom_{$i}";
        $cfq[] = "custom_{$i} = '" . ${$custom_x} . "'";
    }
    $cfq = join(', ', $cfq);
    $rs = compact($vars);
    if (article_validate($rs, $msg)) {
        if (safe_update('textpattern', "Title           = '{$Title}',\n            Body            = '{$Body}',\n            Body_html       = '{$Body_html}',\n            Excerpt         = '{$Excerpt}',\n            Excerpt_html    = '{$Excerpt_html}',\n            Keywords        = '{$Keywords}',\n            description     = '{$description}',\n            Image           = '{$Image}',\n            Status          =  {$Status},\n            LastMod         =  NOW(),\n            LastModID       = '{$user}',\n            Section         = '{$Section}',\n            Category1       = '{$Category1}',\n            Category2       = '{$Category2}',\n            Annotate        =  {$Annotate},\n            textile_body    = '{$textile_body}',\n            textile_excerpt = '{$textile_excerpt}',\n            override_form   = '{$override_form}',\n            url_title       = '{$url_title}',\n            AnnotateInvite  = '{$AnnotateInvite}'," . ($cfs ? $cfq . ',' : '') . "{$whenposted},\n            {$whenexpires}", "ID = {$ID}")) {
            if ($Status >= STATUS_LIVE && $oldArticle['Status'] < STATUS_LIVE) {
                do_pings();
            }
            if ($Status >= STATUS_LIVE || $oldArticle['Status'] >= STATUS_LIVE) {
                update_lastmod('article_saved', $rs);
            }
            now('posted', true);
            now('expires', true);
            callback_event('article_saved', '', false, $rs);
            if (empty($msg)) {
                $s = check_url_title($url_title);
                $msg = array(get_status_message($Status) . ' ' . $s, $s ? E_WARNING : 0);
            }
        } else {
            $msg = array(gTxt('article_save_failed'), E_ERROR);
        }
    }
    article_edit($msg, false, true);
}
Example #20
0
function article_save()
{
    global $txp_user, $vars, $txpcfg;
    extract(get_prefs());
    $incoming = psa($vars);
    $oldArticle = safe_row('Status, url_title, Title', 'textpattern', 'ID = ' . (int) $incoming['ID']);
    if (!($oldArticle['Status'] >= 4 and has_privs('article.edit.published') or $oldArticle['Status'] >= 4 and $incoming['AuthorID'] == $txp_user and has_privs('article.edit.own.published') or $oldArticle['Status'] < 4 and has_privs('article.edit') or $oldArticle['Status'] < 4 and $incoming['AuthorID'] == $txp_user and has_privs('article.edit.own'))) {
        // Not allowed, you silly rabbit, you shouldn't even be here.
        // Show default editing screen.
        article_edit();
        return;
    }
    include_once $txpcfg['txpath'] . '/lib/classTextile.php';
    $textile = new Textile();
    $incoming['Title_plain'] = $incoming['Title'];
    if ($use_textile == 0 or !$incoming['textile_body']) {
        $incoming['Body_html'] = trim($incoming['Body']);
    } else {
        if ($use_textile == 1) {
            $incoming['Body_html'] = nl2br(trim($incoming['Body']));
        } else {
            if ($use_textile == 2 && $incoming['textile_body']) {
                $incoming['Body_html'] = $textile->TextileThis($incoming['Body']);
                $incoming['Title'] = $textile->TextileThis($incoming['Title'], '', 1);
            }
        }
    }
    if ($incoming['textile_excerpt']) {
        $incoming['Excerpt_html'] = $textile->TextileThis($incoming['Excerpt']);
    } else {
        $incoming['Excerpt_html'] = $textile->TextileThis($incoming['Excerpt'], 1);
    }
    extract(doSlash($incoming));
    if (!has_privs('article.publish') && $Status >= 4) {
        $Status = 3;
    }
    if ($reset_time) {
        $whenposted = "Posted=now()";
    } else {
        $when = strtotime($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute . ":00") - tz_offset();
        $when = "from_unixtime({$when})";
        $whenposted = "Posted={$when}";
    }
    $textile_body = !$textile_body ? 0 : 1;
    $textile_excerpt = !$textile_excerpt ? 0 : 1;
    if (empty($url_title)) {
        $url_title = stripSpace($Title_plain, 1);
    } elseif ($oldArticle['Status'] < 4 && $oldArticle['url_title'] == stripSpace($oldArticle['Title'], 1)) {
        $url_title = stripSpace($Title_plain, 1);
    }
    safe_update("textpattern", "Title           = '{$Title}',\n\t\t\tBody            = '{$Body}',\n\t\t\tBody_html       = '{$Body_html}',\n\t\t\tExcerpt         = '{$Excerpt}',\n\t\t\tExcerpt_html    = '{$Excerpt_html}',\n\t\t\tKeywords        = '{$Keywords}',\n\t\t\tImage           = '{$Image}',\n\t\t\tStatus          = '{$Status}',\n\t\t\tLastMod         =  now(),\n\t\t\tLastModID       = '{$txp_user}',\n\t\t\tSection         = '{$Section}',\n\t\t\tCategory1       = '{$Category1}',\n\t\t\tCategory2       = '{$Category2}',\n\t\t\tAnnotate        = '{$Annotate}',\n\t\t\ttextile_body    =  {$textile_body},\n\t\t\ttextile_excerpt =  {$textile_excerpt},\n\t\t\toverride_form   = '{$override_form}',\n\t\t\turl_title       = '{$url_title}',\n\t\t\tAnnotateInvite  = '{$AnnotateInvite}',\n\t\t\tcustom_1        = '{$custom_1}',\n\t\t\tcustom_2        = '{$custom_2}',\n\t\t\tcustom_3        = '{$custom_3}',\n\t\t\tcustom_4        = '{$custom_4}',\n\t\t\tcustom_5        = '{$custom_5}',\n\t\t\tcustom_6        = '{$custom_6}',\n\t\t\tcustom_7        = '{$custom_7}',\n\t\t\tcustom_8        = '{$custom_8}',\n\t\t\tcustom_9        = '{$custom_9}',\n\t\t\tcustom_10       = '{$custom_10}',\n\t\t\t{$whenposted}", "ID='{$ID}'");
    if ($Status >= 4) {
        if ($oldArticle['Status'] < 4) {
            include_once $txpcfg['txpath'] . '/lib/IXRClass.php';
            if ($ping_textpattern_com) {
                $tx_client = new IXR_Client('http://textpattern.com/xmlrpc/');
                $tx_client->query('ping.Textpattern', $sitename, $siteurl);
            }
            if ($ping_weblogsdotcom == 1) {
                $wl_client = new IXR_Client('http://rpc.pingomatic.com/');
                $wl_client->query('weblogUpdates.ping', $sitename, hu);
            }
        }
        safe_update("txp_prefs", "val = now()", "`name` = 'lastmod'");
        $message = gTxt("article_saved");
    } else {
        if ($Status == 3) {
            $message = gTxt("article_saved_pending");
        } else {
            if ($Status == 2) {
                $message = gTxt("article_saved_hidden");
            } else {
                if ($Status == 1) {
                    $message = gTxt("article_saved_draft");
                }
            }
        }
    }
    $message .= check_url_title($url_title);
    article_edit($message);
}
Example #21
0
function doArticleHref($ID, $Title, $url_title, $Section)
{
    $conTitle = $url_title ? $url_title : stripSpace($Title);
    return $GLOBALS['url_mode'] ? tag($Title, 'a', ' href="' . hu . $Section . '/' . $ID . '/' . $conTitle . '"') : tag($Title, 'a', ' href="' . hu . 'index.php?id=' . $ID . '"');
}
Example #22
0
/**
 * Generates an article URL from the given data array.
 *
 * @param   array $article_array An array consisting of keys 'thisid', 'section', 'title', 'url_title', 'posted', 'expires'
 * @return  string The URL
 * @package URL
 * @see     permlinkurl_id()
 * @example
 * echo permlinkurl_id(array(
 *     'thisid'    => 12,
 *     'section'   => 'blog',
 *     'url_title' => 'my-title',
 *     'posted'    => 1345414041,
 *     'expires'   => 1345444077
 * ));
 */
function permlinkurl($article_array)
{
    global $permlink_mode, $prefs, $permlinks, $production_status;
    if (!$article_array || !is_array($article_array)) {
        return;
    }
    if (isset($prefs['custom_url_func']) and is_callable($prefs['custom_url_func']) and ($url = call_user_func($prefs['custom_url_func'], $article_array, PERMLINKURL)) !== false) {
        return $url;
    }
    extract(lAtts(array('thisid' => null, 'id' => null, 'title' => null, 'url_title' => null, 'section' => null, 'posted' => null, 'expires' => null), array_change_key_case($article_array, CASE_LOWER), false));
    if (empty($thisid)) {
        $thisid = $id;
    }
    $thisid = (int) $thisid;
    if (isset($permlinks[$thisid])) {
        return $permlinks[$thisid];
    }
    if (empty($prefs['publish_expired_articles']) && !empty($expires) && $expires < time() && $production_status != 'live' && txpinterface == 'public') {
        trigger_error(gTxt('permlink_to_expired_article', array('{id}' => $thisid)), E_USER_NOTICE);
    }
    if (empty($url_title)) {
        $url_title = stripSpace($title);
    }
    $section = urlencode($section);
    $url_title = urlencode($url_title);
    switch ($permlink_mode) {
        case 'section_id_title':
            if ($prefs['attach_titles_to_permalinks']) {
                $out = hu . "{$section}/{$thisid}/{$url_title}";
            } else {
                $out = hu . "{$section}/{$thisid}/";
            }
            break;
        case 'year_month_day_title':
            list($y, $m, $d) = explode("-", date("Y-m-d", $posted));
            $out = hu . "{$y}/{$m}/{$d}/{$url_title}";
            break;
        case 'id_title':
            if ($prefs['attach_titles_to_permalinks']) {
                $out = hu . "{$thisid}/{$url_title}";
            } else {
                $out = hu . "{$thisid}/";
            }
            break;
        case 'section_title':
            $out = hu . "{$section}/{$url_title}";
            break;
        case 'title_only':
            $out = hu . "{$url_title}";
            break;
        case 'messy':
            $out = hu . "index.php?id={$thisid}";
            break;
    }
    return $permlinks[$thisid] = $out;
}
Example #23
0
}
if (!safe_field('val', 'txp_prefs', "name='permlink_mode'")) {
    safe_insert('txp_prefs', "prefs_id=1,name='permlink_mode',val='section_id_title'");
}
if (!safe_field('val', 'txp_prefs', "name='comments_are_ol'")) {
    safe_insert('txp_prefs', "prefs_id=1,name='comments_are_ol',val='1'");
}
if (!safe_field('name', 'txp_prefs', "name='path_to_site'")) {
    safe_insert('txp_prefs', "prefs_id=1,name='path_to_site',val=''");
}
// 1.0: need to get non-manually set url-only titles into the textpattern table,
// so we can start using title as an url search option
$rs = mysql_query("select ID, Title from `" . PFX . "textpattern` where url_title like ''");
while ($a = mysql_fetch_array($rs)) {
    extract($a);
    $url_title = addslashes(stripSpace($Title, 1));
    safe_update("textpattern", "url_title = '{$url_title}'", "ID={$ID}");
}
// 1.0: properly i18n
//Change current language names by language codes
$lang = fetch('val', 'txp_prefs', 'name', 'language');
switch ($lang) {
    case 'czech':
        $rs = safe_update("txp_prefs", "val= 'cs-cs'", "name='language' AND val= 'czech'");
        break;
    case 'danish':
        $rs = safe_update("txp_prefs", "val= 'da-da'", "name='language' AND val= 'danish'");
        break;
    case 'dutch':
        $rs = safe_update("txp_prefs", "val= 'nl-nl'", "name='language' AND val= 'dutch'");
        break;
Example #24
0
function doArticleHref($ID, $Title, $url_title, $Section)
{
    trigger_error(gTxt('deprecated_tag'), E_USER_NOTICE);
    $conTitle = $url_title ? $url_title : stripSpace($Title);
    return $GLOBALS['url_mode'] ? tag($Title, 'a', ' href="' . hu . $Section . '/' . $ID . '/' . $conTitle . '"') : tag($Title, 'a', ' href="' . hu . 'index.php?id=' . $ID . '"');
}
Example #25
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_mt_item($item, $section, $status, $invite)
{
    global $prefs;
    if (empty($item)) {
        return;
    }
    include_once txpath . '/lib/classTextile.php';
    $textile = new Textile();
    $title = $textile->TextileThis($item['TITLE'], 1);
    // Nice non-English permlinks.
    $url_title = stripSpace($title, 1);
    $body = isset($item['BODY'][0]['content']) ? $item['BODY'][0]['content'] : '';
    if (isset($item['EXTENDED BODY'][0]['content'])) {
        $body .= "\n <!-- more -->\n\n" . $item['EXTENDED BODY'][0]['content'];
    }
    $body_html = $textile->textileThis($body);
    $excerpt = isset($item['EXCERPT'][0]['content']) ? $item['EXCERPT'][0]['content'] : '';
    $excerpt_html = $textile->textileThis($excerpt);
    $date = safe_strtotime($item['DATE']);
    $date = strftime('%Y-%m-%d %H:%M:%S', $date);
    if (isset($item['STATUS'])) {
        $post_status = $item['STATUS'] == 'Draft' ? 1 : 4;
    } else {
        $post_status = $status;
    }
    $category1 = @$item['PRIMARY CATEGORY'];
    if ($category1 and !safe_field("name", "txp_category", "name = '{$category1}'")) {
        safe_insert('txp_category', "name='" . doSlash($category1) . "', type='article', parent='root'");
    }
    $category2 = @$item['CATEGORY'];
    if ($category2 == $category1) {
        $category2 = '';
    }
    if ($category2 and !safe_field("name", "txp_category", "name = '{$category2}'")) {
        safe_insert('txp_category', "name='" . doSlash($category2) . "', type='article', parent='root'");
    }
    $keywords = isset($item['KEYWORDS'][0]['content']) ? $item['KEYWORDS'][0]['content'] : '';
    $annotate = !empty($item['ALLOW COMMENTS']);
    if (isset($item['ALLOW COMMENTS'])) {
        $annotate = intval($item['ALLOW COMMENTS']);
    } else {
        $annotate = (!empty($item['COMMENT']) or $prefs['comments_on_default']);
    }
    $authorid = safe_field('user_id', 'txp_users', "name = '" . 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($item['AUTHOR']) . "'");
    }
    if (!safe_field("ID", "textpattern", "Title = '" . doSlash($title) . "' AND Posted = '" . doSlash($date) . "'")) {
        $parentid = 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) . "'," . "Excerpt='" . doSlash($excerpt) . "'," . "Excerpt_html='" . doSlash($excerpt_html) . "'," . "Category1='" . doSlash($category1) . "'," . "Category2='" . doSlash($category2) . "'," . "Annotate='" . doSlash($annotate) . "'," . "AnnotateInvite='" . doSlash($invite) . "'," . "Status='" . doSlash($post_status) . "'," . "Section='" . doSlash($section) . "'," . "Keywords='" . doSlash($keywords) . "'," . "uid='" . md5(uniqid(rand(), true)) . "'," . "feed_time='" . substr($date, 0, 10) . "'," . "url_title='" . doSlash($url_title) . "'");
        if (!empty($item['COMMENT']) and is_array($item['COMMENT'])) {
            foreach ($item['COMMENT'] as $comment) {
                $comment_date = strftime('%Y-%m-%d %H:%M:%S', safe_strtotime(@$comment['DATE']));
                $comment_content = $textile->TextileThis(nl2br(@$comment['content']), 1);
                if (!safe_field("discussid", "txp_discuss", "posted = '" . doSlash($comment_date) . "' AND message = '" . doSlash($comment_content) . "'")) {
                    safe_insert('txp_discuss', "parentid='" . doSlash($parentid) . "'," . "name='" . doSlash(@$comment['AUTHOR']) . "'," . "email='" . doSlash(@$comment['EMAIL']) . "'," . "web='" . doSlash(@$comment['URL']) . "'," . "ip='" . doSlash(@$comment['IP']) . "'," . "posted='" . doSlash($comment_date) . "'," . "message='" . doSlash($comment_content) . "'," . "visible='1'");
                }
            }
            update_comments_count($parentid);
        }
        return $title;
    }
    return $title . ' already imported';
}
Example #26
0
/**
 * Generates an article URL from the given data array.
 *
 * @param   array  $article_array An array consisting of keys 'thisid', 'section', 'title', 'url_title', 'posted'
 * @return  string The URL
 * @package URL
 * @see     permlinkurl_id()
 * @example
 * echo permlinkurl_id(array(
 *     'thisid'    => 12,
 *     'section'   => 'blog',
 *     'url_title' => 'my-title',
 *     'posted'    => 1345414041
 * ));
 */
function permlinkurl($article_array)
{
    global $permlink_mode, $prefs, $permlinks;
    if (!$article_array || !is_array($article_array)) {
        return;
    }
    if (isset($prefs['custom_url_func']) and is_callable($prefs['custom_url_func']) and ($url = call_user_func($prefs['custom_url_func'], $article_array, PERMLINKURL)) !== false) {
        return $url;
    }
    extract(lAtts(array('thisid' => null, 'ID' => null, 'Title' => null, 'title' => null, 'url_title' => null, 'section' => null, 'Section' => null, 'posted' => null, 'Posted' => null), $article_array, false));
    if (empty($thisid)) {
        $thisid = $ID;
    }
    $thisid = (int) $thisid;
    if (isset($permlinks[$thisid])) {
        return $permlinks[$thisid];
    }
    if (!isset($title)) {
        $title = $Title;
    }
    if (empty($url_title)) {
        $url_title = stripSpace($title);
    }
    if (empty($section)) {
        $section = $Section;
    }
    if (!isset($posted)) {
        $posted = $Posted;
    }
    $section = urlencode($section);
    $url_title = urlencode($url_title);
    switch ($permlink_mode) {
        case 'section_id_title':
            if ($prefs['attach_titles_to_permalinks']) {
                $out = hu . "{$section}/{$thisid}/{$url_title}";
            } else {
                $out = hu . "{$section}/{$thisid}/";
            }
            break;
        case 'year_month_day_title':
            list($y, $m, $d) = explode("-", date("Y-m-d", $posted));
            $out = hu . "{$y}/{$m}/{$d}/{$url_title}";
            break;
        case 'id_title':
            if ($prefs['attach_titles_to_permalinks']) {
                $out = hu . "{$thisid}/{$url_title}";
            } else {
                $out = hu . "{$thisid}/";
            }
            break;
        case 'section_title':
            $out = hu . "{$section}/{$url_title}";
            break;
        case 'title_only':
            $out = hu . "{$url_title}";
            break;
        case 'messy':
            $out = hu . "index.php?id={$thisid}";
            break;
    }
    return $permlinks[$thisid] = $out;
}
Example #27
0
function rss()
{
    global $prefs, $thisarticle;
    extract($prefs);
    ob_start();
    extract(doSlash(gpsa(array('category', 'section', 'limit', 'area'))));
    $area = gps('area');
    $sitename .= $section ? ' - ' . $section : '';
    $sitename .= $category ? ' - ' . $category : '';
    $out[] = tag(doSpecial($sitename), 'title');
    $out[] = tag(hu, 'link');
    $out[] = tag(doSpecial($site_slogan), 'description');
    $articles = array();
    if (!$area or $area == 'article') {
        $sfilter = $section ? "and Section = '" . $section . "'" : '';
        $cfilter = $category ? "and (Category1='" . $category . "' or Category2='" . $category . "')" : '';
        $limit = $limit ? $limit : '5';
        $frs = safe_column("name", "txp_section", "in_rss != '1'");
        if ($frs) {
            foreach ($frs as $f) {
                $query[] = "and Section != '" . $f . "'";
            }
        }
        $query[] = $sfilter;
        $query[] = $cfilter;
        $rs = safe_rows_start("*, unix_timestamp(Posted) as uPosted, ID as thisid", "textpattern", "Status = 4 " . join(' ', $query) . "and Posted < now() order by Posted desc limit {$limit}");
        if ($rs) {
            while ($a = nextRow($rs)) {
                extract($a);
                populateArticleData($a);
                $a['posted'] = $uPosted;
                $Body = !$syndicate_body_or_excerpt ? $thisarticle['body'] : $thisarticle['excerpt'];
                $Body = !trim($Body) ? $thisarticle['body'] : $Body;
                $Body = str_replace('href="/', 'href="' . hu, $Body);
                $Body = preg_replace("/href=\\\"#(.*)\"/", "href=\"" . permlinkurl($a) . "#\\1\"", $Body);
                $Body = safe_hed($Body);
                $Body = preg_replace(array('/</', '/>/', "/'/", '/"/'), array('&lt;', '&gt;', '&#039;', '&quot;'), $Body);
                // encode bare ampersands
                $Body = preg_replace("/&(?![#0-9]+;|\\w+;)/i", '&amp;', $Body);
                $uTitle = $url_title ? $url_title : stripSpace($Title);
                $uTitle = htmlspecialchars($uTitle, ENT_NOQUOTES);
                if ($show_comment_count_in_feed) {
                    $dc = getCount('txp_discuss', "parentid={$ID} and visible=1");
                    $count = $dc > 0 ? ' [' . $dc . ']' : '';
                } else {
                    $count = '';
                }
                $Title = doSpecial($Title) . $count;
                $permlink = permlinkurl($a);
                $item = tag(strip_tags($Title), 'title') . n . tag($Body, 'description') . n . tag($permlink, 'link');
                $articles[$ID] = tag($item, 'item');
                $etags[$ID] = strtoupper(dechex(crc32($articles[$ID])));
                $dates[$ID] = $uPosted;
            }
        }
    } elseif ($area == 'link') {
        $cfilter = $category ? "category='{$category}'" : '1';
        $limit = $limit ? $limit : 15;
        $rs = safe_rows_start("*", "txp_link", "{$cfilter} order by date desc limit {$limit}");
        if ($rs) {
            while ($a = nextRow($rs)) {
                extract($a);
                $item = tag(doSpecial($linkname), 'title') . n . tag(doSpecial($description), 'description') . n . tag(doSpecial($url), 'link');
                $articles[$id] = tag($item, 'item');
                $etags[$id] = strtoupper(dechex(crc32($articles[$id])));
                $dates[$id] = $date;
            }
        }
    }
    //turn on compression if we aren't using it already
    if (extension_loaded('zlib') && ini_get("zlib.output_compression") == 0 && ini_get('output_handler') != 'ob_gzhandler' && !headers_sent()) {
        ob_start("ob_gzhandler");
    }
    $last = fetch('unix_timestamp(val)', 'txp_prefs', 'name', 'lastmod');
    $last = gmdate("D, d M Y H:i:s \\G\\M\\T", $last);
    header("Last-Modified: {$last}");
    $expires = gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 3600 * 1);
    header("Expires: {$expires}");
    $hims = serverset('HTTP_IF_MODIFIED_SINCE');
    if ($hims == $last) {
        header("HTTP/1.1 304 Not Modified");
        exit;
    }
    $imsd = @strtotime($hims);
    if (is_callable('apache_request_headers')) {
        $headers = apache_request_headers();
        if (isset($headers["A-IM"])) {
            $canaim = strpos($headers["A-IM"], "feed");
        } else {
            $canaim = false;
        }
    } else {
        $canaim = false;
    }
    $hinm = stripslashes(serverset('HTTP_IF_NONE_MATCH'));
    $cutarticles = false;
    if ($canaim !== false) {
        foreach ($articles as $id => $thing) {
            if (strpos($hinm, $etags[$id]) !== false) {
                unset($articles[$id]);
                $cutarticles = true;
                $cut_etag = true;
            }
            if ($dates[$id] < $imsd) {
                unset($articles[$id]);
                $cutarticles = true;
                $cut_time = true;
            }
        }
    }
    if (isset($cut_etag) && isset($cut_time)) {
        header("Vary: If-None-Match, If-Modified-Since");
    } else {
        if (isset($cut_etag)) {
            header("Vary: If-None-Match");
        } else {
            if (isset($cut_time)) {
                header("Vary: If-Modified-Since");
            }
        }
    }
    $etag = @join("-", $etags);
    if (strstr($hinm, $etag)) {
        header("HTTP/1.1 304 Not Modified");
        exit;
    }
    if ($cutarticles) {
        //header("HTTP/1.1 226 IM Used");
        //This should be used as opposed to 200, but Apache doesn't like it.
        //http://intertwingly.net/blog/2004/09/11/Vary-ETag/ says that the status code should be 200.
        header("Cache-Control: no-store, im");
        header("IM: feed");
    }
    $out = array_merge($out, $articles);
    header("Content-Type: application/rss+xml; charset=utf-8");
    if ($etag) {
        header('ETag: "' . $etag . '"');
    }
    return '<rss version="0.92">' . tag(join(n, $out), 'channel') . '</rss>';
}
Example #28
0
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();
    // let's go - Dean says ;-).
    $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 & Paste your table-definitions from b2config.php
    $tableposts = 'b2posts';
    $tableusers = 'b2users';
    $tablecategories = 'b2categories';
    $tablecomments = 'b2comments';
    $a = mysql_query("\n\t\t\tselect \n\t\t\t" . $tableposts . ".ID as ID,\n\t\t\t" . $tableposts . ".post_date as Posted, \n\t\t\t" . $tableposts . ".post_title as Title, \n\t\t\t" . $tableposts . ".post_content as Body, \n\t\t\t" . $tablecategories . ".cat_name as Category1, \n\t\t\t" . $tableusers . ".user_login as AuthorID \n\t\t\tfrom " . $tableposts . " \n\t\t\tleft join " . $tablecategories . " on \n\t\t\t\t" . $tablecategories . ".cat_ID = " . $tableposts . ".post_category \n\t\t\tleft join " . $tableusers . " on \n\t\t\t\t" . $tableusers . ".ID = " . $tableposts . ".post_author\n            ORDER BY post_date DESC\n\t\t", $b2link) or $results[] = mysql_error();
    while ($b = mysql_fetch_array($a)) {
        $articles[] = $b;
    }
    $a = mysql_query("\n\t\t\tselect\n\t\t\t" . $tablecomments . ".comment_ID as discussid, \n\t\t\t" . $tablecomments . ".comment_post_ID as parentid, \n\t\t\t" . $tablecomments . ".comment_author_IP as ip, \n\t\t\t" . $tablecomments . ".comment_author as name, \n\t\t\t" . $tablecomments . ".comment_author_email as email, \n\t\t\t" . $tablecomments . ".comment_author_url as web, \n\t\t\t" . $tablecomments . ".comment_content as message, \n\t\t\t" . $tablecomments . ".comment_date as posted\n\t\t\tfrom " . $tablecomments . "\n\t\t", $b2link) or $results[] = mysql_error();
    while ($b = mysql_fetch_assoc($a)) {
        $comments[] = $b;
    }
    mysql_close($b2link);
    //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);
    include txpath . '/lib/classTextile.php';
    $textile = new Textile();
    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']);
            $a['Body_html'] = $textile->textileThis($a['Body']);
            extract(array_slash($a));
            $q = mysql_query("\n\t\t\t\t\tinsert into " . PFX . "textpattern set \n\t\t\t\t\tID        = '{$ID}',\n\t\t\t\t\tPosted    = '{$Posted}',\n\t\t\t\t\tTitle     = '{$Title}',\n                    url_title = '{$url_title}',\n\t\t\t\t\tBody      = '{$Body}',\n\t\t\t\t\tBody_html = '{$Body_html}',\n\t\t\t\t\tExcerpt   = '{$Excerpt}',\n\t\t\t\t\tExcerpt_html = '{$Excerpt_html}',\n\t\t\t\t\tCategory1 = '{$Category1}',\n\t\t\t\t\tAuthorID  = '{$AuthorID}',\n\t\t\t\t\tSection   = '{$insert_into_section}',\n\t\t\t\t\tAnnotateInvite = '{$default_comment_invite}',\n\t\t\t\t\tuid='" . md5(uniqid(rand(), true)) . "',\n\t\t\t\t\tfeed_time='" . substr($Posted, 0, 10) . "',\n\t\t\t\t\tStatus    = '{$insert_with_status}'\n\t\t\t\t", $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\t\t\t\t\t({$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 . '</strong> into txp_discuss';
            }
        }
    }
    return join('<br />', $results);
}
Example #29
0
function article_save()
{
    global $txp_user, $vars, $txpcfg, $prefs;
    extract($prefs);
    $incoming = psa($vars);
    $oldArticle = safe_row('Status, url_title, Title, unix_timestamp(LastMod) as sLastMod, LastModID', 'textpattern', 'ID = ' . (int) $incoming['ID']);
    if (!($oldArticle['Status'] >= 4 and has_privs('article.edit.published') or $oldArticle['Status'] >= 4 and $incoming['AuthorID'] == $txp_user and has_privs('article.edit.own.published') or $oldArticle['Status'] < 4 and has_privs('article.edit') or $oldArticle['Status'] < 4 and $incoming['AuthorID'] == $txp_user and has_privs('article.edit.own'))) {
        // Not allowed, you silly rabbit, you shouldn't even be here.
        // Show default editing screen.
        article_edit();
        return;
    }
    if ($oldArticle['sLastMod'] != $incoming['sLastMod']) {
        article_edit(gTxt('concurrent_edit_by', array('{author}' => htmlspecialchars($oldArticle['LastModID']))), TRUE);
        return;
    }
    $incoming = textile_main_fields($incoming, $use_textile);
    extract(doSlash($incoming));
    extract(array_map('assert_int', psa(array('ID', 'Status', 'textile_body', 'textile_excerpt'))));
    $Annotate = (int) $Annotate;
    if (!has_privs('article.publish') && $Status >= 4) {
        $Status = 3;
    }
    if ($reset_time) {
        $whenposted = "Posted=now()";
        $when_ts = time();
    } else {
        $when = $when_ts = strtotime($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute . ':' . $second) - tz_offset();
        $whenposted = "Posted=from_unixtime({$when})";
    }
    if (empty($exp_year)) {
        $expires = 0;
        $whenexpires = "Expires=" . NULLDATETIME;
    } else {
        if (empty($exp_month)) {
            $exp_month = 1;
        }
        if (empty($exp_day)) {
            $exp_day = 1;
        }
        if (empty($exp_hour)) {
            $exp_hour = 0;
        }
        if (empty($exp_minute)) {
            $exp_minute = 0;
        }
        if (empty($exp_second)) {
            $exp_second = 0;
        }
        $expires = strtotime($exp_year . '-' . $exp_month . '-' . $exp_day . ' ' . $exp_hour . ':' . $exp_minute . ':' . $exp_second) - tz_offset();
        $whenexpires = "Expires=from_unixtime({$expires})";
    }
    if ($expires) {
        if ($expires <= $when_ts) {
            article_edit(gTxt('article_expires_before_postdate'));
            return;
        }
    }
    //Auto-Update custom-titles according to Title, as long as unpublished and NOT customized
    if (empty($url_title) || $oldArticle['Status'] < 4 && $oldArticle['url_title'] == $url_title && $oldArticle['url_title'] == stripSpace($oldArticle['Title'], 1) && $oldArticle['Title'] != $Title) {
        $url_title = stripSpace($Title_plain, 1);
    }
    $Keywords = doSlash(trim(preg_replace('/( ?[\\r\\n\\t,])+ ?/s', ',', preg_replace('/ +/', ' ', ps('Keywords'))), ', '));
    safe_update("textpattern", "Title           = '{$Title}',\n\t\t\tBody            = '{$Body}',\n\t\t\tBody_html       = '{$Body_html}',\n\t\t\tExcerpt         = '{$Excerpt}',\n\t\t\tExcerpt_html    = '{$Excerpt_html}',\n\t\t\tKeywords        = '{$Keywords}',\n\t\t\tImage           = '{$Image}',\n\t\t\tStatus          =  {$Status},\n\t\t\tLastMod         =  now(),\n\t\t\tLastModID       = '{$txp_user}',\n\t\t\tSection         = '{$Section}',\n\t\t\tCategory1       = '{$Category1}',\n\t\t\tCategory2       = '{$Category2}',\n\t\t\tAnnotate        =  {$Annotate},\n\t\t\ttextile_body    =  {$textile_body},\n\t\t\ttextile_excerpt =  {$textile_excerpt},\n\t\t\toverride_form   = '{$override_form}',\n\t\t\turl_title       = '{$url_title}',\n\t\t\tAnnotateInvite  = '{$AnnotateInvite}',\n\t\t\tcustom_1        = '{$custom_1}',\n\t\t\tcustom_2        = '{$custom_2}',\n\t\t\tcustom_3        = '{$custom_3}',\n\t\t\tcustom_4        = '{$custom_4}',\n\t\t\tcustom_5        = '{$custom_5}',\n\t\t\tcustom_6        = '{$custom_6}',\n\t\t\tcustom_7        = '{$custom_7}',\n\t\t\tcustom_8        = '{$custom_8}',\n\t\t\tcustom_9        = '{$custom_9}',\n\t\t\tcustom_10       = '{$custom_10}',\n\t\t\t{$whenposted},\n\t\t\t{$whenexpires}", "ID = {$ID}");
    if ($Status >= 4) {
        if ($oldArticle['Status'] < 4) {
            do_pings();
        }
        update_lastmod();
    }
    article_edit(get_status_message($Status) . check_url_title($url_title));
}
Example #30
0
function article_save()
{
    global $txp_user, $vars, $txpcfg, $prefs;
    extract($prefs);
    $incoming = psa($vars);
    $oldArticle = safe_row('Status, url_title, Title', 'textpattern', 'ID = ' . (int) $incoming['ID']);
    if (!($oldArticle['Status'] >= 4 and has_privs('article.edit.published') or $oldArticle['Status'] >= 4 and $incoming['AuthorID'] == $txp_user and has_privs('article.edit.own.published') or $oldArticle['Status'] < 4 and has_privs('article.edit') or $oldArticle['Status'] < 4 and $incoming['AuthorID'] == $txp_user and has_privs('article.edit.own'))) {
        // Not allowed, you silly rabbit, you shouldn't even be here.
        // Show default editing screen.
        article_edit();
        return;
    }
    $incoming = textile_main_fields($incoming, $use_textile);
    extract(doSlash($incoming));
    extract(array_map('assert_int', psa(array('ID', 'Status', 'textile_body', 'textile_excerpt'))));
    $Annotate = ps('Annotate') ? assert_int(ps('Annotate')) : 0;
    if (!has_privs('article.publish') && $Status >= 4) {
        $Status = 3;
    }
    if ($reset_time) {
        $whenposted = "Posted=now()";
    } else {
        $when = strtotime($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute . ':' . $second) - tz_offset();
        $when = "from_unixtime({$when})";
        $whenposted = "Posted={$when}";
    }
    //Auto-Update custom-titles according to Title, as long as unpublished and NOT customized
    if (empty($url_title) || $oldArticle['Status'] < 4 && $oldArticle['url_title'] == $url_title && $oldArticle['url_title'] == stripSpace($oldArticle['Title'], 1) && $oldArticle['Title'] != $Title) {
        $url_title = stripSpace($Title_plain, 1);
    }
    if (!$Annotate) {
        $Annotate = 0;
    }
    safe_update("textpattern", "Title           = '{$Title}',\n\t\t\tBody            = '{$Body}',\n\t\t\tBody_html       = '{$Body_html}',\n\t\t\tExcerpt         = '{$Excerpt}',\n\t\t\tExcerpt_html    = '{$Excerpt_html}',\n\t\t\tKeywords        = '{$Keywords}',\n\t\t\tImage           = '{$Image}',\n\t\t\tStatus          =  {$Status},\n\t\t\tLastMod         =  now(),\n\t\t\tLastModID       = '{$txp_user}',\n\t\t\tSection         = '{$Section}',\n\t\t\tCategory1       = '{$Category1}',\n\t\t\tCategory2       = '{$Category2}',\n\t\t\tAnnotate        =  {$Annotate},\n\t\t\ttextile_body    =  {$textile_body},\n\t\t\ttextile_excerpt =  {$textile_excerpt},\n\t\t\toverride_form   = '{$override_form}',\n\t\t\turl_title       = '{$url_title}',\n\t\t\tAnnotateInvite  = '{$AnnotateInvite}',\n\t\t\tcustom_1        = '{$custom_1}',\n\t\t\tcustom_2        = '{$custom_2}',\n\t\t\tcustom_3        = '{$custom_3}',\n\t\t\tcustom_4        = '{$custom_4}',\n\t\t\tcustom_5        = '{$custom_5}',\n\t\t\tcustom_6        = '{$custom_6}',\n\t\t\tcustom_7        = '{$custom_7}',\n\t\t\tcustom_8        = '{$custom_8}',\n\t\t\tcustom_9        = '{$custom_9}',\n\t\t\tcustom_10       = '{$custom_10}',\n\t\t\t{$whenposted}", "ID = {$ID}");
    if ($Status >= 4) {
        if ($oldArticle['Status'] < 4) {
            do_pings();
        }
        update_lastmod();
    }
    article_edit(get_status_message($Status) . check_url_title($url_title));
}