Пример #1
0
 /**
  * Filter.
  *
  * @param string $thing
  * @param array  $options
  */
 public function filter($thing, $options)
 {
     parent::filter($thing, $options);
     if ($this->options['restricted']) {
         return $this->textile->textileRestricted($thing, $this->options['lite'], $this->options['noimage'], $this->options['rel']);
     } else {
         return $this->textile->textileThis($thing, $this->options['lite'], '', $this->options['noimage'], '', $this->options['rel']);
     }
 }
Пример #2
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';
}
Пример #3
0
 /**
  * beforeSave callback
  * 
  * Used to process the text in textile format.
  * 
  * @access public
  * @return Always true so it doesnt avoid saving
  */
 function beforeSave()
 {
     App::import('Vendor', 'Textile');
     $Textile = new Textile();
     $this->data[$this->alias]['processed_text'] = $Textile->textileThis($this->data[$this->alias]['text']);
     return true;
 }
Пример #4
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(dumbDown($title));
    $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(dumbDown($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';
}
 public function parse_string($template, $data = array(), $return = FALSE, $options = array())
 {
     if (!is_array($options)) {
         $options = array();
     }
     $options = array_merge($this->config, $options);
     $ci = $this->ci;
     $is_mx = false;
     if (!$return) {
         list($ci, $is_mx) = $this->detect_mx();
     }
     $parser = new Textile($options['doctype']);
     if ($options['restricted_mode']) {
         $template = $parser->textileRestricted($template);
     } else {
         $template = $parser->textileThis($template);
     }
     return $this->output($template, $return, $ci, $is_mx);
 }
Пример #6
0
function doImportMTDB($mt_dblogin, $mt_db, $mt_dbpass, $mt_dbhost, $blog_id, $insert_into_section, $insert_with_status, $default_comment_invite)
{
    global $txpcfg;
    //Keep some response on some part
    $results = array();
    //Avoid left joins
    $authors_map = array();
    $categories_map = array();
    // let's go - Dean says ;-).
    $mtlink = mysql_connect($mt_dbhost, $mt_dblogin, $mt_dbpass, true);
    if (!$mtlink) {
        return 'mt database values don&#8217;t work. Please replace them and try again';
    }
    mysql_select_db($mt_db, $mtlink);
    $results[] = 'connected to mt database. Importing Data';
    sleep(2);
    $a = mysql_query("\n\t\t\tselect\n\t\t\tauthor_id as user_id,\n\t\t\tauthor_nickname as name,\n\t\t\tauthor_name as RealName,\n\t\t\tauthor_email as email,\n\t\t\tauthor_password as pass\n\t\t\tfrom mt_author\n\t\t", $mtlink);
    while ($b = mysql_fetch_assoc($a)) {
        $authors[] = $b;
    }
    $a = mysql_query("\n\t\t\tselect\n\t\t\tmt_entry.entry_id as ID,\n\t\t\tmt_entry.entry_text as Body,\n\t\t\tmt_entry.entry_text_more as Body2,\n\t\t\tmt_entry.entry_title as Title,\n\t\t\tmt_entry.entry_excerpt as Excerpt,\n\t\t\tmt_entry.entry_keywords as Keywords,\n\t\t\tmt_entry.entry_created_on as Posted,\n\t\t\tmt_entry.entry_modified_on as LastMod,\n\t\t\tmt_entry.entry_author_id as AuthorID\n\t\t\tfrom mt_entry\n\t\t\twhere entry_blog_id = '{$blog_id}'\n\t\t", $mtlink);
    $results[] = mysql_error();
    while ($b = mysql_fetch_assoc($a)) {
        $cat = mysql_query("select placement_category_id as category_id from mt_placement where placement_entry_id='{$b['ID']}'");
        while ($cat_id = mysql_fetch_row($cat)) {
            $categories[] = $cat_id[0];
        }
        if (!empty($categories[0])) {
            $b['Category1'] = $categories[0];
        }
        if (!empty($categories[1])) {
            $b['Category2'] = $categories[1];
        }
        unset($categories);
        //Trap comments for each article
        $comments = array();
        $q = "\n\t\t\t\tselect\n\t\t\t\tmt_comment.comment_id as discussid,\n\t\t\t\tmt_comment.comment_ip as ip,\n\t\t\t\tmt_comment.comment_author as name,\n\t\t\t\tmt_comment.comment_email as email,\n\t\t\t\tmt_comment.comment_url as web,\n\t\t\t\tmt_comment.comment_text as message,\n\t\t\t\tmt_comment.comment_created_on as posted\n\t\t\t\tfrom mt_comment where comment_blog_id = '{$blog_id}' AND comment_entry_id='{$b['ID']}'\n\t\t\t";
        $c = mysql_query($q, $mtlink);
        while ($d = mysql_fetch_assoc($c)) {
            $comments[] = $d;
        }
        //Attach comments to article
        $b['comments'] = $comments;
        unset($comments);
        //Article finished
        $articles[] = $b;
    }
    $a = mysql_query("\n\t\t\tselect category_id,category_label from mt_category where category_blog_id='{$blog_id}'\n\t\t", $mtlink);
    while ($b = mysql_fetch_assoc($a)) {
        $categories_map[$b['category_id']] = $b['category_label'];
    }
    mysql_close($mtlink);
    //Yes, we have to make a new connection
    //otherwise doArray complains
    $DB = new DB();
    include txpath . '/lib/classTextile.php';
    $textile = new Textile();
    if (!empty($authors)) {
        foreach ($authors as $author) {
            extract($author);
            $name = empty($name) ? $RealName : $name;
            $authors_map[$user_id] = $name;
            $authorid = safe_field('user_id', 'txp_users', "name = '" . doSlash($name) . "'");
            if (!$authorid) {
                //Add new authors
                $q = safe_insert("txp_users", "\n\t\t\t\t\t\tname     = '" . doSlash($RealName) . "',\n\t\t\t\t\t\temail    = '" . doSlash($email) . "',\n\t\t\t\t\t\tpass     = '******',\n\t\t\t\t\t\tRealName = '" . doSlash($RealName) . "',\n\t\t\t\t\t\tprivs='1'");
                if ($q) {
                    $results[] = 'inserted ' . $RealName . ' into txp_users';
                } else {
                    $results[] = mysql_error();
                }
            }
        }
    }
    if (!empty($categories_map)) {
        foreach ($categories_map as $category) {
            $category = doSlash($category);
            $rs = safe_row('id', 'txp_category', "name='{$category}' and type='article'");
            if (!$rs) {
                $q = safe_insert("txp_category", "name='{$category}',type='article',parent='root'");
                if ($q) {
                    $results[] = 'inserted ' . stripslashes($category) . ' into txp_category';
                } else {
                    $results[] = mysql_error();
                }
            }
        }
    }
    if (!empty($articles)) {
        foreach ($articles as $article) {
            extract($article);
            $Body .= trim($Body2) ? "\n\n" . $Body2 : '';
            $Body_html = $textile->textileThis($Body);
            $Excerpt_html = $textile->textileThis($Excerpt);
            $Title = $textile->textileThis($Title, 1);
            $Category1 = !empty($Category1) ? doSlash($Category1) : '';
            $AuthorID = !empty($authors_map[$AuthorID]) ? doSlash($authors_map[$AuthorID]) : '';
            $insertID = safe_insert("textpattern", "\n\t\t\t\t\tID        \t   = '{$ID}',\n\t\t\t\t\tPosted         = '{$Posted}',\n\t\t\t\t\tLastMod        = '{$LastMod}',\n\t\t\t\t\tTitle          = '" . doSlash($Title) . "',\n\t\t\t\t\tBody           = '" . doSlash($Body) . "',\n\t\t\t\t\tExcerpt\t\t   = '" . doSlash($Excerpt) . "',\n\t\t\t\t\tExcerpt_html   = '" . doSlash($Excerpt_html) . "',\n\t\t\t\t\tKeywords\t   = '" . doSlash($Keywords) . "',\n\t\t\t\t\tBody_html      = '" . doSlash($Body_html) . "',\n\t\t\t\t\tAuthorID       = '{$AuthorID}',\n\t\t\t\t\tCategory1      = '{$Category1}',\n\t\t\t\t\tAnnotateInvite = '" . doSlash($default_comment_invite) . "',\n\t\t\t\t\tSection        = '" . doSlash($insert_into_section) . "',\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");
            if ($insertID) {
                $results[] = 'inserted MT entry ' . strong($Title) . ' into Textpattern as article ' . strong($insertID) . '';
                //Do coment for article
                if (!empty($comments) && is_array($comments)) {
                    foreach ($comments as $comment) {
                        extract($comment);
                        $message = nl2br($message);
                        $commentID = safe_insert("txp_discuss", "\n\t\t\t\t\t\t\t\tdiscussid = {$discussid},\n\t\t\t\t\t\t\t\tparentid  = {$insertID},\n\t\t\t\t\t\t\t\tname      = '" . doSlash($name) . "',\n\t\t\t\t\t\t\t\temail     = '" . doSlash($email) . "',\n\t\t\t\t\t\t\t\tweb       = '" . doSlash($web) . "',\n\t\t\t\t\t\t\t\tmessage   = '" . doSlash($message) . "',\n\t\t\t\t\t\t\t\tip        = '{$ip}',\n\t\t\t\t\t\t\t\tposted    = '{$posted}',\n\t\t\t\t\t\t\t\tvisible   = 1");
                        if ($commentID) {
                            $results[] = 'inserted MT comment ' . $commentID . ' for article ' . $insertID . ' into txp_discuss';
                        } else {
                            $results[] = mysql_error();
                        }
                    }
                }
            } else {
                $results[] = mysql_error();
            }
        }
    }
    return join('<br />', $results);
}
Пример #7
0
function article_edit($message = "")
{
    global $txpcfg, $txp_user, $vars;
    extract(get_prefs());
    extract(gpsa(array('view', 'from_view', 'step')));
    if (!empty($GLOBALS['ID'])) {
        // newly-saved article
        $ID = intval($GLOBALS['ID']);
        $step = 'edit';
    } else {
        $ID = gps('ID');
    }
    include_once $txpcfg['txpath'] . '/lib/classTextile.php';
    $textile = new Textile();
    if (!$view) {
        $view = "text";
    }
    if (!$step) {
        $step = "create";
    }
    if ($step == "edit" && $view == "text" && !empty($ID) && $from_view != "preview" && $from_view != 'html') {
        $pull = true;
        //-- it's an existing article - off we go to the db
        $rs = safe_row("*, unix_timestamp(Posted) as sPosted,\n\t\t\t\tunix_timestamp(LastMod) as sLastMod", "textpattern", "ID={$ID}");
        extract($rs);
        if ($AnnotateInvite != $comments_default_invite) {
            $AnnotateInvite = $AnnotateInvite;
        } else {
            $AnnotateInvite = $comments_default_invite;
        }
    } else {
        $pull = false;
        //-- assume they came from post
        if (!$from_view or $from_view == 'text') {
            extract(gpsa($vars));
        } elseif ($from_view == 'preview' or $from_view == 'html') {
            // coming from either html or preview
            if (isset($_POST['store'])) {
                $store = unserialize(base64_decode($_POST['store']));
                extract($store);
            }
        }
        foreach ($vars as $var) {
            if (isset(${$var})) {
                $store_out[$var] = ${$var};
            }
        }
    }
    $GLOBALS['step'] = $step;
    if ($step == 'create') {
        $textile_body = 1;
        $textile_excerpt = 1;
    }
    if ($step != 'create') {
        // Previous record?
        $prev_id = checkIfNeighbour('prev', $sPosted);
        // Next record?
        $next_id = checkIfNeighbour('next', $sPosted);
    }
    pagetop($Title, $message);
    echo '<form action="index.php" method="post" name="article">';
    if (!empty($store_out)) {
        echo hInput('store', base64_encode(serialize($store_out)));
    }
    echo hInput('ID', $ID), eInput('article'), sInput($step);
    echo '<input type="hidden" name="view" />', startTable('edit');
    echo '<tr><td>&nbsp;</td><td colspan="3">', $view == 'preview' ? hed(ucfirst(gTxt('preview')), 2) . graf($Title) : '', $view == 'html' ? hed('XHTML', 2) . graf($Title) : '', $view == 'text' ? br . '<input type="text" name="Title" value="' . cleanfInput($Title) . '" class="edit" size="40" tabindex="1" />' : '', '</td></tr>';
    //-- article input --------------
    echo '<tr>
  		<td valign="top">', $view == 'text' && $use_textile == 2 ? '<p><a href="#" onclick="toggleDisplay(\'textile_help\');">' . gTxt('textile_help') . '</a></p>
		<div id="textile_help" style="display:none;">' . sidehelp() . '</div>' : sp;
    if ($view == 'text') {
        echo '<p><a href="#" onclick="toggleDisplay(\'advanced\');">' . gTxt('advanced_options') . '</a></p>', '<div id="advanced" style="display:none;">', graf(gTxt('use_textile') . br . tag(checkbox2('textile_body', $textile_body) . gTxt('article'), 'label') . br . tag(checkbox2('textile_excerpt', $textile_excerpt) . gTxt('excerpt'), 'label')), $allow_form_override ? graf(gTxt('override_default_form') . br . form_pop($override_form) . popHelp('override_form')) : '', $custom_1_set ? custField(1, $custom_1_set, $custom_1) : '', $custom_2_set ? custField(2, $custom_2_set, $custom_2) : '', $custom_3_set ? custField(3, $custom_3_set, $custom_3) : '', $custom_4_set ? custField(4, $custom_4_set, $custom_4) : '', $custom_5_set ? custField(5, $custom_5_set, $custom_5) : '', $custom_6_set ? custField(6, $custom_6_set, $custom_6) : '', $custom_7_set ? custField(7, $custom_7_set, $custom_7) : '', $custom_8_set ? custField(8, $custom_8_set, $custom_8) : '', $custom_9_set ? custField(9, $custom_9_set, $custom_9) : '', $custom_10_set ? custField(10, $custom_10_set, $custom_10) : '', graf(gTxt('keywords') . popHelp('keywords') . br . '<textarea name="Keywords" style="width:100px;height:80px" rows="1" cols="1">' . $Keywords . '</textarea>'), graf(gTxt('article_image') . popHelp('article_image') . br . fInput('text', 'Image', $Image, 'edit')), graf(gTxt('url_title') . popHelp('url_title') . br . fInput('text', 'url_title', $url_title, 'edit')) . '</div>
			
			<p><a href="#" onclick="toggleDisplay(\'recent\');">' . gTxt('recent_articles') . '</a>' . '</p>' . '<div id="recent" style="display:none;">';
        $recents = safe_rows_start("Title, ID", 'textpattern', "1 order by LastMod desc limit 10");
        if ($recents) {
            echo '<p>';
            while ($recent = nextRow($recents)) {
                extract($recent);
                if (!$Title) {
                    $Title = gTxt('untitled') . sp . $ID;
                }
                echo '<a href="?event=article' . a . 'step=edit' . a . 'ID=' . $ID . '">' . $Title . '</a>' . br . n;
            }
            echo '</p>';
        }
        echo '</div>';
    } else {
        echo sp;
    }
    echo '</td>
    	<td valign="top" style="width:400px">';
    if ($view == "preview") {
        if ($use_textile == 2) {
            echo $textile->TextileThis($Body);
        } else {
            if ($use_textile == 1) {
                echo nl2br($Body);
            } else {
                if ($use_textile == 0) {
                    echo $Body;
                }
            }
        }
    } elseif ($view == "html") {
        if ($use_textile == 2) {
            $bod = $textile->TextileThis($Body);
        } else {
            if ($use_textile == 1) {
                $bod = nl2br($Body);
            } else {
                if ($use_textile == 0) {
                    $bod = $Body;
                }
            }
        }
        echo tag(str_replace(array(n, t), array(br, sp . sp . sp . sp), htmlspecialchars($bod)), 'code');
    } else {
        echo '<textarea style="width:400px;height:420px" rows="1" cols="1" name="Body" tabindex="2">', htmlspecialchars($Body), '</textarea>';
    }
    //-- excerpt --------------------
    if ($articles_use_excerpts) {
        if ($view == 'text') {
            $Excerpt = str_replace("&amp;", "&", htmlspecialchars($Excerpt));
            echo graf(gTxt('excerpt') . popHelp('excerpt') . br . '<textarea style="width:400px;height:50px" rows="1" cols="1" name="Excerpt" tabindex="3">' . $Excerpt . '</textarea>');
        } else {
            echo '<hr width="50%" />';
            echo $textile_excerpt ? $view == 'preview' ? graf($textile->textileThis($Excerpt), 1) : tag(str_replace(array(n, t), array(br, sp . sp . sp . sp), htmlspecialchars($textile->TextileThis($Excerpt), 1)), 'code') : graf($Excerpt);
        }
    }
    //-- author --------------
    if ($view == "text" && $step != "create") {
        echo "<p><small>" . gTxt('posted_by') . " {$AuthorID}: ", date("H:i, d M y", $sPosted + tz_offset());
        if ($sPosted != $sLastMod) {
            echo br . gTxt('modified_by') . " {$LastModID}: ", date("H:i, d M y", $sLastMod + tz_offset());
        }
        echo '</small></p>';
    }
    echo hInput('from_view', $view), '</td>';
    echo '<td valign="top" align="left" width="20">';
    //-- layer tabs -------------------
    echo $use_textile == 2 ? tab('text', $view) . tab('html', $view) . tab('preview', $view) : '&#160;';
    echo '</td>';
    ?>
	
<td width="200" valign="top" style="padding-left:10px" align="left" id="articleside">
<?php 
    //-- prev/next article links --
    if ($view == 'text') {
        if ($step != 'create' and ($prev_id or $next_id)) {
            echo '<p>', $prev_id ? prevnext_link('&#8249;' . gTxt('prev'), 'article', 'edit', $prev_id, gTxt('prev')) : '', $next_id ? prevnext_link(gTxt('next') . '&#8250;', 'article', 'edit', $next_id, gTxt('next')) : '', '</p>';
        }
    }
    //-- status radios --------------
    echo $view == 'text' ? n . graf(status_radio($Status)) . n : '';
    //-- category selects -----------
    echo $view == 'text' ? graf(gTxt('categorize') . ' [' . eLink('category', '', '', '', gTxt('edit')) . ']' . br . category_popup('Category1', $Category1) . category_popup('Category2', $Category2)) : '';
    //-- section select --------------
    if (!$from_view && !$pull) {
        $Section = getDefaultSection();
    }
    echo $view == 'text' ? graf(gTxt('section') . ' [' . eLink('section', '', '', '', gTxt('edit')) . ']' . br . section_popup($Section)) : '';
    //-- comments stuff --------------
    if ($step == "create") {
        //Avoiding invite disappear when previewing
        $AnnotateInvite = !empty($store_out['AnnotateInvite']) ? $store_out['AnnotateInvite'] : $comments_default_invite;
        if ($comments_on_default == 1) {
            $Annotate = 1;
        }
    }
    echo $use_comments == 1 && $view == 'text' ? graf(gTxt('comments') . onoffRadio("Annotate", $Annotate) . '<br />' . gTxt('comment_invitation') . '<br />' . fInput('text', 'AnnotateInvite', $AnnotateInvite, 'edit')) : '';
    //-- timestamp -------------------
    if ($step == "create" and empty($GLOBALS['ID'])) {
        if ($view == 'text') {
            //Avoiding modified date to disappear
            $persist_timestamp = !empty($store_out['year']) ? mktime($store_out['hour'], $store_out['minute'], '00', $store_out['month'], $store_out['day'], $store_out['year']) : time();
            echo graf(tag(checkbox('publish_now', '1') . gTxt('set_to_now'), 'label')), '<p>', gTxt('or_publish_at'), popHelp("timestamp"), br, tsi('year', 'Y', $persist_timestamp), tsi('month', 'm', $persist_timestamp), tsi('day', 'd', $persist_timestamp), sp, tsi('hour', 'H', $persist_timestamp), ':', tsi('minute', 'i', $persist_timestamp), '</p>';
        }
        //-- publish button --------------
        if ($view == 'text') {
            echo has_privs('article.publish') ? fInput('submit', 'publish', gTxt('publish'), "publish") : fInput('submit', 'publish', gTxt('save'), "publish");
        }
    } else {
        if ($view == 'text') {
            echo '<p>', gTxt('published_at'), popHelp("timestamp"), br, tsi('year', 'Y', $sPosted, 5), tsi('month', 'm', $sPosted, 6), tsi('day', 'd', $sPosted, 7), sp, tsi('hour', 'H', $sPosted, 8), ':', tsi('minute', 'i', $sPosted, 9), '</p>', hInput('sPosted', $sPosted), hInput('sLastMod', $sLastMod), hInput('AuthorID', $AuthorID), hInput('LastModID', $LastModID), graf(checkbox('reset_time', '1', 0) . gTxt('reset_time'));
        }
        //-- save button --------------
        if ($view == 'text') {
            if ($Status >= 4 and has_privs('article.edit.published') or $Status >= 4 and $AuthorID == $txp_user and has_privs('article.edit.own.published') or $Status < 4 and has_privs('article.edit') or $Status < 4 and $AuthorID == $txp_user and has_privs('article.edit.own')) {
                echo fInput('submit', 'save', gTxt('save'), "publish");
            }
        }
    }
    echo '</td></tr></table></form>';
}
Пример #8
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';
}
Пример #9
0
function doImportWP($b2dblogin, $b2db, $b2dbpass, $b2dbhost, $wpdbprefix, $insert_into_section, $insert_with_status, $default_comment_invite, $wpdbcharset)
{
    global $txpcfg;
    $b2link = mysql_connect($b2dbhost, $b2dblogin, $b2dbpass, true);
    if (!$b2link) {
        return 'WordPress database values don&#8217;t work. Go back, replace them and try again.';
    }
    mysql_select_db($b2db, $b2link);
    if (!mysql_query('SET NAMES ' . doslash($wpdbcharset), $b2link)) {
        return 'WordPress database does not support the requested character set. Aborting.';
    }
    // Keep some response on some part
    $results = array();
    $errors = array();
    $results[] = hed('Connected to WordPress database. Importing Data&#8230;', 1);
    /*
    export users
    */
    $users = array();
    $user_query = mysql_query("\n\t\t\tselect\n\t\t\t\tID as user_id,\n\t\t\t\tuser_login as name,\n\t\t\t\tuser_email as email,\n\t\t\t\tdisplay_name as RealName\n\t\t\tfrom " . $wpdbprefix . "users\n\t\t", $b2link) or $errors[] = mysql_error();
    while ($user = mysql_fetch_array($user_query)) {
        $user_privs_query = mysql_query("\n\t\t\t\tselect\n\t\t\t\t\tmeta_value\n\t\t\t\tfrom " . $wpdbprefix . "usermeta\n\t\t\t\twhere user_id = " . $user['user_id'] . " and meta_key = '" . $wpdbprefix . "capabilities'\n\t\t\t", $b2link) or $errors[] = mysql_error();
        $privs = unserialize(mysql_result($user_privs_query, 0));
        foreach ($privs as $key => $val) {
            // convert the built-in WordPress roles
            // to their Txp equivalent
            switch ($key) {
                // publisher
                case 'administrator':
                    $user['privs'] = 1;
                    break;
                    // managing editor
                // managing editor
                case 'editor':
                    $user['privs'] = 2;
                    break;
                    // staff writer
                // staff writer
                case 'author':
                    $user['privs'] = 4;
                    break;
                    // freelancer
                // freelancer
                case 'contributor':
                    $user['privs'] = 5;
                    break;
                    // none
                // none
                case 'subscriber':
                default:
                    $user['privs'] = 0;
                    break;
            }
        }
        $users[] = $user;
    }
    /*
    export article and link categories
    */
    $categories = array();
    $category_query = mysql_query("\n\t\t\tselect\n\t\t\t\tt.slug as name,\n\t\t\t\tt.name as title,\n\t\t\t\ttt.taxonomy as type,\n\t\t\t\ttt.parent as parent\n\t\t\tfrom " . $wpdbprefix . "terms as t inner join " . $wpdbprefix . "term_taxonomy as tt\n\t\t\t\ton(t.term_id = tt.term_id)\n\t\t\torder by field(tt.taxonomy, 'category','post_tag','link_category'), tt.parent asc, t.name asc\n\t\t", $b2link) or $errors[] = mysql_error();
    while ($category = mysql_fetch_array($category_query)) {
        if ($category['parent'] != 0) {
            $category_parent_query = mysql_query("\n\t\t\t\t\tselect\n\t\t\t\t\t\tslug as name\n\t\t\t\t\tfrom " . $wpdbprefix . "terms\n\t\t\t\t\twhere term_id = '" . doSlash($category['parent']) . "'\n\t\t\t\t", $b2link) or $errors[] = mysql_error();
            while ($parent = mysql_fetch_array($category_parent_query)) {
                $category['parent'] = $parent['name'];
            }
        } else {
            $category['parent'] = 'root';
        }
        switch ($category['type']) {
            case 'post_tag':
            case 'category':
                $category['type'] = 'article';
                break;
            case 'link_category':
                $category['type'] = 'link';
                break;
        }
        $categories[] = $category;
    }
    /*
    export articles - do not export post revisions from WP 2.6+
    */
    $article_query = mysql_query("\n\t\t\tselect\n\t\t\t\tp.ID as ID,\n\t\t\t\tp.post_status as Status,\n\t\t\t\tp.post_date as Posted,\n\t\t\t\tp.post_modified as LastMod,\n\t\t\t\tp.post_title as Title,\n\t\t\t\tp.post_content as Body,\n\t\t\t\tp.comment_status as Annotate,\n\t\t\t\tp.comment_count as comments_count,\n\t\t\t\tp.post_name as url_title,\n\t\t\t\tu.user_login as AuthorID\n\t\t\tfrom " . $wpdbprefix . "posts as p left join " . $wpdbprefix . "users as u\n\t\t\t\ton u.ID = p.post_author\n\t\t\twhere p.post_type = 'post'\n\t\t\torder by p.ID asc\n\t\t", $b2link) or $errors[] = mysql_error();
    while ($article = mysql_fetch_array($article_query)) {
        // convert WP article status to Txp equivalent
        switch ($article['Status']) {
            case 'draft':
                $article['Status'] = 1;
                break;
                // hidden
            // hidden
            case 'private':
                $article['Status'] = 2;
                break;
            case 'pending':
                $article['Status'] = 3;
                break;
                // live
            // live
            case 'publish':
                $article['Status'] = 4;
                break;
            default:
                $article['Status'] = $insert_with_status;
                break;
        }
        // convert WP comment status to Txp equivalent
        switch ($article['Annotate']) {
            // on
            case 'open':
                $article['Annotate'] = 1;
                break;
                // off
            // off
            case 'closed':
            case 'registered_only':
                $article['Annotate'] = 0;
                break;
        }
        // article commments
        $comments = array();
        $comment_query = mysql_query("\n\t\t\t\tselect\n\t\t\t\t\tcomment_author_IP as ip,\n\t\t\t\t\tcomment_author as name,\n\t\t\t\t\tcomment_author_email as email,\n\t\t\t\t\tcomment_author_url as web,\n\t\t\t\t\tcomment_content as message,\n\t\t\t\t\tcomment_date as posted\n\t\t\t\tfrom " . $wpdbprefix . "comments\n\t\t\t\twhere comment_post_ID = '" . $article['ID'] . "'\n\t\t\t\torder by comment_ID asc\n\t\t\t", $b2link) or $errors[] = mysql_error();
        while ($comment = mysql_fetch_assoc($comment_query)) {
            $comments[] = $comment;
        }
        $article['comments'] = $comments;
        // article categories
        $article_categories = array();
        $article_category_query = mysql_query("\n\t\t\t\tselect\n\t\t\t\t\tt.name as title,\n\t\t\t\t\tt.slug as name\n\t\t\t\tfrom " . $wpdbprefix . "terms as t inner join " . $wpdbprefix . "term_taxonomy as tt\n\t\t\t\t\ton(t.term_id = tt.term_id)\n\t\t\t\tinner join " . $wpdbprefix . "term_relationships as tr\n\t\t\t\t\ton(tt.term_taxonomy_id = tr.term_taxonomy_id)\n\t\t\t\twhere tr.object_id = '" . $article['ID'] . "' and tt.taxonomy in('post_tag', 'category')\n\t\t\t\torder by tr.object_id asc, t.name asc\n\t\t\t\tlimit 2;\n\t\t\t", $b2link) or $errors[] = mysql_error();
        while ($category = mysql_fetch_array($article_category_query)) {
            $article_categories[] = $category;
        }
        $article['Category1'] = !empty($article_categories[0]) ? $article_categories[0]['name'] : '';
        $article['Category2'] = !empty($article_categories[1]) ? $article_categories[1]['name'] : '';
        // article images
        $article_images = array();
        $article_image_query = mysql_query("\n\t\t\tselect\n\t\t\t\tguid\n\t\t\tfrom " . $wpdbprefix . "posts\n\t\t\twhere post_type = 'attachment' and post_mime_type like 'image/%' and post_parent=" . $article['ID'], $b2link) or $errors[] = mysql_error();
        while ($image = mysql_fetch_array($article_image_query)) {
            $article_images[] = $image['guid'];
        }
        // Comma-separated image urls preserve multiple attachments.
        // Attn: If more than one image is attached, <txp:article_image /> will not work out of the box.
        $article['Image'] = join(',', $article_images);
        $articles[] = $article;
    }
    /*
    export links
    */
    $links = array();
    $link_query = mysql_query("\n\t\t\tselect\n\t\t\t\tlink_id as id,\n\t\t\t\tlink_name as linkname,\n\t\t\t\tlink_description as description,\n\t\t\t\tlink_updated as date,\n\t\t\t\tlink_url as url\n\t\t\tfrom " . $wpdbprefix . "links\n\t\t\torder by link_id asc\n\t\t", $b2link) or $errors[] = mysql_error();
    while ($link = mysql_fetch_array($link_query)) {
        // link categories
        $link_categories = array();
        $link_category_query = mysql_query("\n\t\t\t\tselect\n\t\t\t\t\tt.name as title,\n\t\t\t\t\tt.slug as name\n\t\t\t\tfrom " . $wpdbprefix . "terms as t inner join " . $wpdbprefix . "term_taxonomy as tt\n\t\t\t\t\ton(t.term_id = tt.term_id)\n\t\t\t\tinner join " . $wpdbprefix . "term_relationships as tr\n\t\t\t\t\ton(tt.term_taxonomy_id = tr.term_taxonomy_id)\n\t\t\t\twhere tr.object_id = '" . $link['id'] . "' and tt.taxonomy = 'link_category'\n\t\t\t\torder by tr.object_id asc, t.name asc\n\t\t\t", $b2link) or $errors[] = mysql_error();
        while ($category = mysql_fetch_array($link_category_query)) {
            $link['category'] = $category['name'];
        }
        $links[] = $link;
    }
    mysql_close($b2link);
    /*
    begin import
    */
    // keep a handy copy of txpdb values, and do not alter Dean code
    // for now! ;-)
    $txpdb = $txpcfg['db'];
    $txpdblogin = $txpcfg['user'];
    $txpdbpass = $txpcfg['pass'];
    $txpdbhost = $txpcfg['host'];
    // Yes, we have to make a new connection
    // otherwise doArray complains
    $DB = new DB();
    $txplink =& $DB->link;
    mysql_select_db($txpdb, $txplink);
    /*
    import users
    */
    if ($users) {
        include_once txpath . '/lib/txplib_admin.php';
        $results[] = hed('Imported Users:', 2) . n . graf('Because WordPress uses a different password mechanism than Textpattern, you will need to reset each user&#8217;s password from <a href="index.php?event=admin">the Users tab</a>.') . n . '<ul>';
        foreach ($users as $user) {
            extract($user);
            if (!safe_row('user_id', 'txp_users', "name = '" . doSlash($name) . "'")) {
                $pass = doSlash(generate_password(6));
                $nonce = doSlash(md5(uniqid(mt_rand(), TRUE)));
                $rs = mysql_query("\n\t\t\t\t\t\tinsert into " . safe_pfx('txp_users') . " set\n\t\t\t\t\t\t\tname     = '" . doSlash($name) . "',\n\t\t\t\t\t\t\tpass     = '******',\n\t\t\t\t\t\t\temail    = '" . doSlash($email) . "',\n\t\t\t\t\t\t\tRealName = '" . doSlash($RealName) . "',\n\t\t\t\t\t\t\tprivs    = " . $privs . ",\n\t\t\t\t\t\t\tnonce    = '" . doSlash($nonce) . "'\n\t\t\t\t\t", $txplink) or $errors[] = mysql_error();
                if (mysql_insert_id()) {
                    $results[] = '<li>' . $name . ' (' . $RealName . ')</li>';
                }
            }
        }
        $results[] = '</ul>';
    }
    /*
    import categories
    */
    if ($categories) {
        $results[] = hed('Imported Categories:', 2) . n . '<ul>';
        foreach ($categories as $category) {
            extract($category);
            if (!safe_row('id', 'txp_category', "name = '" . doSlash($name) . "' and type = '" . doSlash($type) . "' and parent = '" . doSlash($parent) . "'")) {
                $rs = mysql_query("\n\t\t\t\t\t\tinsert into " . safe_pfx('txp_category') . " set\n\t\t\t\t\t\t\tname   = '" . doSlash($name) . "',\n\t\t\t\t\t\t\ttitle  = '" . doSlash($title) . "',\n\t\t\t\t\t\t\ttype   = '" . doSlash($type) . "',\n\t\t\t\t\t\t\tparent = '" . doSlash($parent) . "'\n\t\t\t\t\t", $txplink) or $errors[] = mysql_error();
                if (mysql_insert_id()) {
                    $results[] = '<li>' . $title . ' (' . $type . ')</li>';
                }
            }
        }
        rebuild_tree_full('article');
        rebuild_tree_full('link');
        $results[] = '</ul>';
    }
    /*
    import articles
    */
    if ($articles) {
        $results[] = hed('Imported Articles and Comments:', 2) . n . '<ul>';
        include txpath . '/lib/classTextile.php';
        $textile = new Textile();
        foreach ($articles as $article) {
            extract($article);
            // Ugly, really ugly way to workaround the slashes WP gotcha
            $Body = str_replace('<!--more-->', '', $Body);
            $Body_html = $textile->textileThis($Body);
            // can not use array slash due to way on which comments are selected
            $rs = mysql_query("\n\t\t\t\t\tinsert into " . safe_pfx('textpattern') . " set\n\t\t\t\t\t\tPosted         = '" . doSlash($Posted) . "',\n\t\t\t\t\t\tLastMod        = '" . doSlash($LastMod) . "',\n\t\t\t\t\t\tTitle          = '" . doSlash($textile->TextileThis($Title, 1)) . "',\n\t\t\t\t\t\turl_title      = '" . doSlash($url_title) . "',\n\t\t\t\t\t\tBody           = '" . doSlash($Body) . "',\n\t\t\t\t\t\tBody_html      = '" . doSlash($Body_html) . "',\n\t\t\t\t\t\tImage          = '" . doSlash($Image) . "',\n\t\t\t\t\t\tAuthorID       = '" . doSlash($AuthorID) . "',\n\t\t\t\t\t\tCategory1      = '" . doSlash($Category1) . "',\n\t\t\t\t\t\tCategory2      = '" . doSlash($Category2) . "',\n\t\t\t\t\t\tSection        = '{$insert_into_section}',\n\t\t\t\t\t\tuid            = '" . md5(uniqid(rand(), true)) . "',\n\t\t\t\t\t\tfeed_time      = '" . substr($Posted, 0, 10) . "',\n\t\t\t\t\t\tAnnotate       = '" . doSlash($Annotate) . "',\n\t\t\t\t\t\tAnnotateInvite = '{$default_comment_invite}',\n\t\t\t\t\t\tStatus         = '" . doSlash($Status) . "'\n\t\t\t\t", $txplink) or $errors[] = mysql_error();
            if ((int) ($insert_id = mysql_insert_id($txplink))) {
                $results[] = '<li>' . $Title . '</li>';
                if (!empty($comments)) {
                    $inserted_comments = 0;
                    foreach ($comments as $comment) {
                        extract(array_slash($comment));
                        // The ugly workaroud again
                        $message = nl2br($message);
                        $rs = mysql_query("\n\t\t\t\t\t\t\t\tinsert into " . safe_pfx('txp_discuss') . " set\n\t\t\t\t\t\t\t\t\tparentid = '{$insert_id}',\n\t\t\t\t\t\t\t\t\tname     = '" . doSlash($name) . "',\n\t\t\t\t\t\t\t\t\temail    = '" . doSlash($email) . "',\n\t\t\t\t\t\t\t\t\tweb      = '" . doSlash($web) . "',\n\t\t\t\t\t\t\t\t\tip       = '" . doSlash($ip) . "',\n\t\t\t\t\t\t\t\t\tposted   = '" . doSlash($posted) . "',\n\t\t\t\t\t\t\t\t\tmessage  = '" . doSlash($message) . "',\n\t\t\t\t\t\t\t\t\tvisible  = 1\n\t\t\t\t\t\t\t", $txplink) or $results[] = mysql_error();
                        if (mysql_insert_id()) {
                            $inserted_comments++;
                        }
                    }
                    $results[] = '<li>- ' . $inserted_comments . ' of ' . $comments_count . ' comment(s)</li>';
                }
            }
        }
        $results[] = '</ul>';
    }
    /*
    import links
    */
    if ($links) {
        $results[] = hed('Imported Links:', 2) . n . '<ul>';
        foreach ($links as $link) {
            extract($link);
            $rs = mysql_query("\n\t\t\t\t\tinsert into " . safe_pfx('txp_link') . " set\n\t\t\t\t\t\tlinkname    = '" . doSlash($linkname) . "',\n\t\t\t\t\t\tlinksort    = '" . doSlash($linkname) . "',\n\t\t\t\t\t\tdescription = '" . doSlash($description) . "',\n\t\t\t\t\t\tcategory    = '" . doSlash($category) . "',\n\t\t\t\t\t\tdate        = '" . doSlash($date) . "',\n\t\t\t\t\t\turl         = '" . doSlash($url) . "'\n\t\t\t\t", $txplink) or $errors[] = mysql_error();
            if (mysql_insert_id()) {
                $results[] = '<li>' . $linkname . '</li>';
            }
        }
        $results[] = '</ul>';
    }
    /*
    show any errors we encountered
    */
    if ($errors) {
        $results[] = hed('Errors Encountered:', 2) . n . '<ul>';
        foreach ($errors as $error) {
            $results[] = '<li>' . $error . '</li>';
        }
        $results[] = '</ul>';
    }
    return join(n, $results);
}
Пример #10
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);
}
Пример #11
0
function saveComment()
{
    global $siteurl, $comments_moderate, $comments_sendmail, $txpcfg, $comments_disallow_images, $txpac;
    include_once $txpcfg['txpath'] . '/lib/classTextile.php';
    $im = !empty($comments_disallow_images) ? 1 : '';
    $textile = new Textile();
    $ref = serverset('HTTP_REFERRER');
    extract(psa(array('parentid', 'name', 'email', 'web', 'message', 'backpage', 'nonce', 'remember')));
    if ($txpac['comments_require_name']) {
        if (!trim($name)) {
            exit(graf(gTxt('comment_name_required')) . graf('<a href="" onClick="history.go(-1)">' . gTxt('back') . '</a>'));
        }
    }
    if ($txpac['comments_require_email']) {
        if (!trim($email)) {
            exit(graf(gTxt('comment_email_required')) . graf('<a href="" onClick="history.go(-1)">' . gTxt('back') . '</a>'));
        }
    }
    if (!trim($message)) {
        exit(graf(gTxt('comment_required')) . graf('<a href="" onClick="history.go(-1)">' . gTxt('back') . '</a>'));
    }
    $ip = @getHostByAddr(serverset('REMOTE_ADDR'));
    $message = strip_tags(trim($message));
    $message2db = addslashes(nl2br($textile->textileThis($message, 1, '', $im)));
    $isdup = safe_row("message,name", "txp_discuss", "name='{$name}' and message='{$message2db}' and ip='{$ip}'");
    if (checkBan($ip)) {
        if (!$isdup) {
            if (checkNonce($nonce)) {
                $visible = $comments_moderate ? 0 : 1;
                $rs = safe_insert("txp_discuss", "parentid  = '{$parentid}',\n\t\t\t\t\t\t name      = '{$name}',\n\t\t\t\t\t\t email     = '{$email}',\n\t\t\t\t\t\t web       = '{$web}',\n\t\t\t\t\t\t ip        = '{$ip}',\n\t\t\t\t\t\t message   = '{$message2db}',\n\t\t\t\t\t\t visible   = {$visible},\n\t\t\t\t\t\t posted    = now()");
                if ($rs) {
                    safe_update("txp_discuss_nonce", "used='1'", "nonce='{$nonce}'");
                    if ($txpac['comment_means_site_updated']) {
                        safe_update("txp_prefs", "val=now()", "name='lastmod'");
                    }
                    if ($comments_sendmail) {
                        mail_comment($message, $name, $email, $web, $parentid);
                    }
                    ob_start();
                    header('location: ' . $backpage);
                }
            }
            // end check nonce
        }
        // end check dup
    } else {
        exit(gTxt('you_have_been_banned'));
    }
}
Пример #12
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);
}
Пример #13
0
function article_edit($message = '', $concurrent = FALSE)
{
    global $vars, $txp_user, $comments_disabled_after, $txpcfg, $prefs, $event;
    extract($prefs);
    extract(gpsa(array('view', 'from_view', 'step')));
    if (!empty($GLOBALS['ID'])) {
        // newly-saved article
        $ID = $GLOBALS['ID'];
        $step = 'edit';
    } else {
        $ID = gps('ID');
    }
    include_once txpath . '/lib/classTextile.php';
    $textile = new Textile();
    // switch to 'text' view upon page load and after article post
    if (!$view || gps('save') || gps('publish')) {
        $view = 'text';
    }
    if (!$step) {
        $step = "create";
    }
    if ($step == "edit" && $view == "text" && !empty($ID) && $from_view != 'preview' && $from_view != 'html' && !$concurrent) {
        $pull = true;
        //-- it's an existing article - off we go to the db
        $ID = assert_int($ID);
        $rs = safe_row("*, unix_timestamp(Posted) as sPosted,\n\t\t\t\tunix_timestamp(Expires) as sExpires,\n\t\t\t\tunix_timestamp(LastMod) as sLastMod", "textpattern", "ID={$ID}");
        extract($rs);
        $reset_time = $publish_now = $Status < 4 && $sPosted <= time();
    } else {
        $pull = false;
        //-- assume they came from post
        if ($from_view == 'preview' or $from_view == 'html') {
            $store_out = array();
            $store = unserialize(base64_decode(ps('store')));
            foreach ($vars as $var) {
                if (isset($store[$var])) {
                    $store_out[$var] = $store[$var];
                }
            }
        } else {
            $store_out = gpsa($vars);
            if ($concurrent) {
                $store_out['sLastMod'] = safe_field('unix_timestamp(LastMod) as sLastMod', 'textpattern', 'ID=' . $ID);
            }
        }
        $rs = $store_out;
        extract($store_out);
    }
    $GLOBALS['step'] = $step;
    if ($step == 'create') {
        $textile_body = $use_textile;
        $textile_excerpt = $use_textile;
    }
    if ($step != 'create' && $sPosted) {
        // Previous record?
        $prev_id = checkIfNeighbour('prev', $sPosted);
        // Next record?
        $next_id = checkIfNeighbour('next', $sPosted);
    } else {
        $prev_id = $next_id = 0;
    }
    $page_title = $Title ? $Title : gTxt('write');
    pagetop($page_title, $message);
    echo n . '<div id="' . $event . '_container" class="txp-container txp-edit">';
    echo n . n . '<form id="article_form" name="article_form" method="post" action="index.php">';
    if (!empty($store_out)) {
        echo hInput('store', base64_encode(serialize($store_out)));
    }
    echo hInput('ID', $ID) . eInput('article') . sInput($step) . '<input type="hidden" name="view" />' . startTable('edit') . '<tr>' . n . '<td id="article-col-1"><div id="configuration_content">';
    if ($view == 'text') {
        //-- markup help --------------
        echo pluggable_ui('article_ui', 'sidehelp', side_help($textile_body, $textile_excerpt), $rs);
        //-- custom menu entries --------------
        echo pluggable_ui('article_ui', 'extend_col_1', '', $rs);
        //-- advanced --------------
        echo '<div id="advanced_group"><h3 class="plain lever' . (get_pref('pane_article_advanced_visible') ? ' expanded' : '') . '"><a href="#advanced">' . gTxt('advanced_options') . '</a></h3>' . '<div id="advanced" class="toggle" style="display:' . (get_pref('pane_article_advanced_visible') ? 'block' : 'none') . '">';
        // markup selection
        echo pluggable_ui('article_ui', 'markup', n . graf('<label for="markup-body">' . gTxt('article_markup') . '</label>' . br . pref_text('textile_body', $textile_body, 'markup-body'), ' class="markup markup-body"') . n . graf('<label for="markup-excerpt">' . gTxt('excerpt_markup') . '</label>' . br . pref_text('textile_excerpt', $textile_excerpt, 'markup-excerpt'), ' class="markup markup-excerpt"'), $rs);
        // form override
        echo $allow_form_override ? pluggable_ui('article_ui', 'override', graf('<label for="override-form">' . gTxt('override_default_form') . '</label>' . sp . popHelp('override_form') . br . form_pop($override_form, 'override-form'), ' class="override-form"'), $rs) : '';
        echo '</div></div>' . n;
        //-- custom fields --------------
        $cf = '';
        $cfs = getCustomFields();
        echo '<div id="custom_field_group"' . ($cfs ? '' : ' class="empty"') . '><h3 class="plain lever' . (get_pref('pane_article_custom_field_visible') ? ' expanded' : '') . '"><a href="#custom_field">' . gTxt('custom') . '</a></h3>' . '<div id="custom_field" class="toggle" style="display:' . (get_pref('pane_article_custom_field_visible') ? 'block' : 'none') . '">';
        foreach ($cfs as $i => $cf_name) {
            $custom_x_set = "custom_{$i}_set";
            $custom_x = "custom_{$i}";
            $cf .= ${$custom_x_set} !== '' ? custField($i, ${$custom_x_set}, ${$custom_x}) : '';
        }
        echo pluggable_ui('article_ui', 'custom_fields', $cf, $rs);
        echo '</div></div>' . n;
        //-- article image --------------
        echo '<div id="image_group"><h3 class="plain lever' . (get_pref('pane_article_image_visible') ? ' expanded' : '') . '"><a href="#image">' . gTxt('article_image') . '</a></h3>' . '<div id="image" class="toggle" style="display:' . (get_pref('pane_article_image_visible') ? 'block' : 'none') . '">';
        echo pluggable_ui('article_ui', 'article_image', n . graf('<label for="article-image">' . gTxt('article_image') . '</label>' . sp . popHelp('article_image') . br . fInput('text', 'Image', $Image, 'edit', '', '', 22, '', 'article-image'), ' class="article-image"'), $rs);
        echo '</div></div>' . n;
        //-- meta info --------------
        echo '<div id="meta_group"><h3 class="plain lever' . (get_pref('pane_article_meta_visible') ? ' expanded' : '') . '"><a href="#meta">' . gTxt('meta') . '</a></h3>' . '<div id="meta" class="toggle" style="display:' . (get_pref('pane_article_meta_visible') ? 'block' : 'none') . '">';
        // keywords
        echo pluggable_ui('article_ui', 'keywords', n . graf('<label for="keywords">' . gTxt('keywords') . '</label>' . sp . popHelp('keywords') . br . n . '<textarea id="keywords" name="Keywords" cols="18" rows="5">' . htmlspecialchars(str_replace(',', ', ', $Keywords)) . '</textarea>', ' class="keywords"'), $rs);
        // url title
        echo pluggable_ui('article_ui', 'url_title', n . graf('<label for="url-title">' . gTxt('url_title') . '</label>' . sp . popHelp('url_title') . br . fInput('text', 'url_title', $url_title, 'edit', '', '', 22, '', 'url-title'), ' class="url-title"'), $rs);
        echo '</div></div>' . n;
        //-- recent articles --------------
        echo '<div id="recent_group"><h3 class="plain lever' . (get_pref('pane_article_recent_visible') ? ' expanded' : '') . '"><a href="#recent">' . gTxt('recent_articles') . '</a>' . '</h3>' . '<div id="recent" class="toggle" style="display:' . (get_pref('pane_article_recent_visible') ? 'block' : 'none') . '">';
        $recents = safe_rows_start("Title, ID", 'textpattern', "1=1 order by LastMod desc limit 10");
        $ra = '';
        if ($recents) {
            $ra = '<ul class="recent plain-list">';
            while ($recent = nextRow($recents)) {
                if (!$recent['Title']) {
                    $recent['Title'] = gTxt('untitled') . sp . $recent['ID'];
                }
                $ra .= n . t . '<li class="recent-article"><a href="?event=article' . a . 'step=edit' . a . 'ID=' . $recent['ID'] . '">' . escape_title($recent['Title']) . '</a></li>';
            }
            $ra .= '</ul>';
        }
        echo pluggable_ui('article_ui', 'recent_articles', $ra, $rs);
        echo '</div></div>';
    } else {
        echo sp;
    }
    echo '</div></td>' . n . '<td id="article-main"><div id="main_content">';
    //-- title input --------------
    if ($view == 'preview') {
        echo '<div class="preview">' . hed(gTxt('preview'), 2) . hed($Title, 1, ' class="title"');
    } elseif ($view == 'html') {
        echo '<div class="xhtml">' . hed('XHTML', 2) . hed($Title, 1, ' class="title"');
    } elseif ($view == 'text') {
        echo '<div class="text">' . pluggable_ui('article_ui', 'title', n . '<p class="title"><label for="title">' . gTxt('title') . '</label>' . sp . popHelp('title') . br . '<input type="text" id="title" name="Title" value="' . escape_title($Title) . '" class="edit" size="40" tabindex="1" />', $rs);
        if ($step != 'create') {
            if ($Status != 4 and $Status != 5) {
                $url = '?txpreview=' . intval($ID) . '.' . time();
                // article ID plus cachebuster
            } else {
                include_once txpath . '/publish/taghandlers.php';
                $url = permlinkurl_id($ID);
            }
            echo sp . sp . '<a href="' . $url . '" class="article-view">' . gTxt('view') . '</a>';
        }
        echo '</p>';
    }
    //-- body --------------------
    if ($view == 'preview') {
        echo '<div class="body">';
        if ($textile_body == USE_TEXTILE) {
            echo $textile->TextileThis($Body);
        } else {
            if ($textile_body == CONVERT_LINEBREAKS) {
                echo nl2br($Body);
            } else {
                if ($textile_body == LEAVE_TEXT_UNTOUCHED) {
                    echo $Body;
                }
            }
        }
        echo '</div>';
    } elseif ($view == 'html') {
        if ($textile_body == USE_TEXTILE) {
            $bod = $textile->TextileThis($Body);
        } else {
            if ($textile_body == CONVERT_LINEBREAKS) {
                $bod = nl2br($Body);
            } else {
                if ($textile_body == LEAVE_TEXT_UNTOUCHED) {
                    $bod = $Body;
                }
            }
        }
        echo tag(str_replace(array(n, t), array(br, sp . sp . sp . sp), htmlspecialchars($bod)), 'code', ' class="body"');
    } else {
        echo pluggable_ui('article_ui', 'body', n . graf('<label for="body">' . gTxt('body') . '</label>' . sp . popHelp('body') . br . '<textarea id="body" name="Body" cols="55" rows="31" tabindex="2">' . htmlspecialchars($Body) . '</textarea>', ' class="body"'), $rs);
    }
    //-- excerpt --------------------
    if ($articles_use_excerpts) {
        if ($view == 'text') {
            echo pluggable_ui('article_ui', 'excerpt', n . graf('<label for="excerpt">' . gTxt('excerpt') . '</label>' . sp . popHelp('excerpt') . br . '<textarea id="excerpt" name="Excerpt" cols="55" rows="5" tabindex="3">' . htmlspecialchars($Excerpt) . '</textarea>', ' class="excerpt"'), $rs);
        } else {
            echo n . '<hr width="50%" />';
            echo '<div class="excerpt">';
            echo $textile_excerpt == USE_TEXTILE ? $view == 'preview' ? graf($textile->textileThis($Excerpt)) : tag(str_replace(array(n, t), array(br, sp . sp . sp . sp), htmlspecialchars($textile->TextileThis($Excerpt))), 'code', ' class="excerpt"') : graf($Excerpt);
            echo '</div>';
        }
    }
    //-- author --------------
    if ($view == "text" && $step != "create") {
        echo '<p class="author small">' . gTxt('posted_by') . ': ' . htmlspecialchars($AuthorID) . ' &#183; ' . safe_strftime('%d %b %Y &#183; %X', $sPosted);
        if ($sPosted != $sLastMod) {
            echo br . gTxt('modified_by') . ': ' . htmlspecialchars($LastModID) . ' &#183; ' . safe_strftime('%d %b %Y &#183; %X', $sLastMod);
        }
        echo '</p>';
    }
    echo hInput('from_view', $view), '</div></div></td>';
    //-- layer tabs -------------------
    echo '<td id="article-tabs"><div id="view_modes">';
    echo pluggable_ui('article_ui', 'view', $use_textile == USE_TEXTILE || $textile_body == USE_TEXTILE ? tag(tab('text', $view) . tab('html', $view) . tab('preview', $view), 'ul') : '&#160;', $rs);
    echo '</div></td>';
    echo '<td id="article-col-2"><div id="supporting_content">';
    if ($view == 'text') {
        if ($step != 'create') {
            echo n . graf(href(gtxt('create_new'), 'index.php?event=article'), ' class="action-create"');
        }
        //-- prev/next article links --
        if ($step != 'create' and ($prev_id or $next_id)) {
            echo '<p class="article-nav">', $prev_id ? prevnext_link('&#8249;' . gTxt('prev'), 'article', 'edit', $prev_id, gTxt('prev')) : '', $next_id ? prevnext_link(gTxt('next') . '&#8250;', 'article', 'edit', $next_id, gTxt('next')) : '', '</p>';
        }
        //-- status radios --------------
        echo pluggable_ui('article_ui', 'status', n . n . '<fieldset id="write-status">' . n . '<legend>' . gTxt('status') . '</legend>' . n . status_radio($Status) . n . '</fieldset>', $rs);
        //-- category selects -----------
        echo pluggable_ui('article_ui', 'categories', n . n . '<fieldset id="write-sort">' . n . '<legend>' . gTxt('sort_display') . '</legend>' . n . graf('<label for="category-1">' . gTxt('category1') . '</label> ' . '<span class="edit category-edit small">[' . eLink('category', '', '', '', gTxt('edit')) . ']</span>' . br . n . category_popup('Category1', $Category1, 'category-1'), ' class="category category-1"') . n . graf('<label for="category-2">' . gTxt('category2') . '</label>' . br . n . category_popup('Category2', $Category2, 'category-2'), ' class="category category-2"'), $rs);
        //-- section select --------------
        if (!$from_view && !$pull) {
            $Section = getDefaultSection();
        }
        echo pluggable_ui('article_ui', 'section', n . graf('<label for="section">' . gTxt('section') . '</label> ' . '<span class="edit section-edit small">[' . eLink('section', '', '', '', gTxt('edit')) . ']</span>' . br . section_popup($Section, 'section'), ' class="section"') . n . '</fieldset>', $rs);
        //-- "More" section
        echo n . n . '<div id="more_group"><h3 class="plain lever' . (get_pref('pane_article_more_visible') ? ' expanded' : '') . '"><a href="#more">' . gTxt('more') . '</a></h3>', '<div id="more" class="toggle" style="display:' . (get_pref('pane_article_more_visible') ? 'block' : 'none') . '">';
        //-- comments stuff --------------
        if ($step == "create") {
            //Avoiding invite disappear when previewing
            $AnnotateInvite = !empty($store_out['AnnotateInvite']) ? $store_out['AnnotateInvite'] : $comments_default_invite;
            if ($comments_on_default == 1) {
                $Annotate = 1;
            }
        }
        if ($use_comments == 1) {
            $invite[] = n . n . '<fieldset id="write-comments">' . n . '<legend>' . gTxt('comments') . '</legend>';
            $comments_expired = false;
            if ($step != 'create' && $comments_disabled_after) {
                $lifespan = $comments_disabled_after * 86400;
                $time_since = time() - $sPosted;
                if ($time_since > $lifespan) {
                    $comments_expired = true;
                }
            }
            if ($comments_expired) {
                $invite[] = n . n . graf(gTxt('expired'), ' class="comment-annotate"');
            } else {
                $invite[] = n . n . graf(onoffRadio('Annotate', $Annotate), ' class="comment-annotate"') . n . n . graf('<label for="comment-invite">' . gTxt('comment_invitation') . '</label>' . br . fInput('text', 'AnnotateInvite', $AnnotateInvite, 'edit', '', '', '', '', 'comment-invite'), ' class="comment-invite"');
            }
            $invite[] = n . n . '</fieldset>';
            echo pluggable_ui('article_ui', 'annotate_invite', join('', $invite), $rs);
        }
        if ($step == "create" and empty($GLOBALS['ID'])) {
            //-- timestamp -------------------
            //Avoiding modified date to disappear
            $persist_timestamp = !empty($store_out['year']) ? safe_strtotime($store_out['year'] . '-' . $store_out['month'] . '-' . $store_out['day'] . ' ' . $store_out['hour'] . ':' . $store_out['minute'] . ':' . $store_out['second']) : time();
            echo pluggable_ui('article_ui', 'timestamp', n . n . '<fieldset id="write-timestamp">' . n . '<legend>' . gTxt('timestamp') . '</legend>' . n . graf(checkbox('publish_now', '1', $publish_now, '', 'publish_now') . '<label for="publish_now">' . gTxt('set_to_now') . '</label>', ' class="publish-now"') . n . graf(gTxt('or_publish_at') . sp . popHelp('timestamp'), ' class="publish-at"') . n . graf('<span class="label">' . gtxt('date') . '</span>' . sp . tsi('year', '%Y', $persist_timestamp) . ' / ' . tsi('month', '%m', $persist_timestamp) . ' / ' . tsi('day', '%d', $persist_timestamp), ' class="date posted created"') . n . graf('<span class="label">' . gTxt('time') . '</span>' . sp . tsi('hour', '%H', $persist_timestamp) . ' : ' . tsi('minute', '%M', $persist_timestamp) . ' : ' . tsi('second', '%S', $persist_timestamp), ' class="time posted created"') . n . '</fieldset>', array('sPosted' => $persist_timestamp) + $rs);
            //-- expires -------------------
            $persist_timestamp = !empty($store_out['exp_year']) ? safe_strtotime($store_out['exp_year'] . '-' . $store_out['exp_month'] . '-' . $store_out['exp_day'] . ' ' . $store_out['exp_hour'] . ':' . $store_out['exp_minute'] . ':' . $store_out['second']) : NULLDATETIME;
            echo pluggable_ui('article_ui', 'expires', n . n . '<fieldset id="write-expires">' . n . '<legend>' . gTxt('expires') . '</legend>' . n . graf('<span class="label">' . gtxt('date') . '</span>' . sp . tsi('exp_year', '%Y', $persist_timestamp) . ' / ' . tsi('exp_month', '%m', $persist_timestamp) . ' / ' . tsi('exp_day', '%d', $persist_timestamp), ' class="date expires"') . n . graf('<span class="label">' . gTxt('time') . '</span>' . sp . tsi('exp_hour', '%H', $persist_timestamp) . ' : ' . tsi('exp_minute', '%M', $persist_timestamp) . ' : ' . tsi('exp_second', '%S', $persist_timestamp), ' class="time expires"') . n . '</fieldset>', $rs);
            // end "More" section
            echo n . n . '</div></div>';
            //-- publish button --------------
            echo has_privs('article.publish') ? fInput('submit', 'publish', gTxt('publish'), "publish", '', '', '', 4) : fInput('submit', 'publish', gTxt('save'), "publish", '', '', '', 4);
        } else {
            //-- timestamp -------------------
            if (!empty($year)) {
                $sPosted = safe_strtotime($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute . ':' . $second);
            }
            echo pluggable_ui('article_ui', 'timestamp', n . n . '<fieldset id="write-timestamp">' . n . '<legend>' . gTxt('timestamp') . '</legend>' . n . graf(checkbox('reset_time', '1', $reset_time, '', 'reset_time') . '<label for="reset_time">' . gTxt('reset_time') . '</label>', ' class="reset-time"') . n . graf(gTxt('published_at') . sp . popHelp('timestamp'), ' class="publish-at"') . n . graf('<span class="label">' . gtxt('date') . '</span>' . sp . tsi('year', '%Y', $sPosted) . ' / ' . tsi('month', '%m', $sPosted) . ' / ' . tsi('day', '%d', $sPosted), ' class="date posted created"') . n . graf('<span class="label">' . gTxt('time') . '</span>' . sp . tsi('hour', '%H', $sPosted) . ' : ' . tsi('minute', '%M', $sPosted) . ' : ' . tsi('second', '%S', $sPosted), ' class="time posted created"') . n . hInput('sPosted', $sPosted) . n . hInput('sLastMod', $sLastMod) . n . hInput('AuthorID', $AuthorID) . n . hInput('LastModID', $LastModID) . n . '</fieldset>', $rs);
            //-- expires -------------------
            if (!empty($exp_year)) {
                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;
                }
                $sExpires = safe_strtotime($exp_year . '-' . $exp_month . '-' . $exp_day . ' ' . $exp_hour . ':' . $exp_minute . ':' . $exp_second);
            }
            echo pluggable_ui('article_ui', 'expires', n . n . '<fieldset id="write-expires">' . n . '<legend>' . gTxt('expires') . '</legend>' . n . graf('<span class="label">' . gtxt('date') . '</span>' . sp . tsi('exp_year', '%Y', $sExpires) . ' / ' . tsi('exp_month', '%m', $sExpires) . ' / ' . tsi('exp_day', '%d', $sExpires), ' class="date expires"') . n . graf('<span class="label">' . gTxt('time') . '</span>' . sp . tsi('exp_hour', '%H', $sExpires) . ' : ' . tsi('exp_minute', '%M', $sExpires) . ' : ' . tsi('exp_second', '%S', $sExpires), ' class="time expires"') . n . hInput('sExpires', $sExpires) . n . '</fieldset>', $rs);
            // end "More" section
            echo n . n . '</div></div>';
            //-- save button --------------
            if ($Status >= 4 and has_privs('article.edit.published') or $Status >= 4 and $AuthorID == $txp_user and has_privs('article.edit.own.published') or $Status < 4 and has_privs('article.edit') or $Status < 4 and $AuthorID == $txp_user and has_privs('article.edit.own')) {
                echo fInput('submit', 'save', gTxt('save'), "publish", '', '', '', 4);
            }
        }
    }
    echo '</div></td></tr></table></form></div>' . n;
    // Assume users would not change the timestamp if they wanted to "publish now"/"reset time"
    echo script_js(<<<EOS
\t\t\$('#write-timestamp input.edit').change(
\t\t\tfunction() {
\t\t\t\t\$('#publish_now').attr('checked', false);
\t\t\t\t\$('#reset_time').attr('checked', false);
\t\t\t});
EOS
);
}
 function textile($string)
 {
     switch ($this->get_config('textile_version')) {
         case 3:
             if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
                 require_once S9Y_INCLUDE_PATH . 'plugins/serendipity_event_textile/lib3/src/Netcarver/Textile/Parser.php';
                 require_once S9Y_INCLUDE_PATH . 'plugins/serendipity_event_textile/lib3/src/Netcarver/Textile/DataBag.php';
                 require_once S9Y_INCLUDE_PATH . 'plugins/serendipity_event_textile/lib3/src/Netcarver/Textile/Tag.php';
                 include 'textile_namespace.inc.php';
                 // PHP 5.2 compat
                 // todo check for user-supplied output to restrict
                 #    return $textile->textileRestricted($string);
                 if (is_object($textile)) {
                     return $textile->textileThis($string);
                 }
             } else {
                 trigger_error(' Textile lib3 needs at least PHP 5.3.0 running. Update your PHP version or use lib2 instead.', E_USER_WARNING);
             }
             break;
         case 2:
             require_once S9Y_INCLUDE_PATH . 'plugins/serendipity_event_textile/lib2/classTextile.php';
             $textile = new Textile();
             return $textile->textileThis($string);
             break;
         case 1:
             require_once S9Y_INCLUDE_PATH . 'plugins/serendipity_event_textile/lib1/textile.php';
             return textile($string);
             break;
     }
 }
 function textile($string)
 {
     if ($this->get_config('textile_version') == 2) {
         require_once S9Y_INCLUDE_PATH . 'plugins/serendipity_event_textile/classTextile.php';
         $textile = new Textile();
         return $textile->textileThis($string);
     } else {
         require_once S9Y_INCLUDE_PATH . 'plugins/serendipity_event_textile/textile.php';
         return textile($string);
     }
 }
Пример #16
0
/**
*  обработка текста
*  если $var = false, то используется $VAR
*  
*  @param $out входящий текст
*  @param $var опци
*  
*  @return string
*/
function mso_word_processing($out, $var = false)
{
    global $VAR;
    if ($var === false) {
        $var = $VAR;
    }
    if ($a = $var['autotag_my']) {
        // например $VAR['autotag_my'] = 'simple';
        // файл: pages/autotag/simple.php
        // функция должна называться как autotag_ПАРСЕР: autotag_simple($text);
        // или в ENGINE_DIR/autotag/simple.php
        // функция: autotag_simple();
        $fu = 'autotag_' . $a;
        // парсер может быть в каталоге страницы autotag/
        if ($fn = mso_fe(CURRENT_PAGE_DIR . 'autotag/' . $a . '.php')) {
            require_once $fn;
            if (function_exists($fu)) {
                $out = $fu($out);
            }
        } elseif ($fn = mso_fe(ENGINE_DIR . 'autotag/' . $a . '.php')) {
            require_once $fn;
            if (function_exists($fu)) {
                $out = $fu($out);
            }
        }
    }
    if ($var['autoremove']) {
        $out = mso_autoremove($out);
    }
    //  if ($var['autotag']) $out = mso_autotag($out); // -----
    if ($var['autopre']) {
        $out = mso_autopre($out);
    }
    if ($var['bbcode'] and mso_fe(ENGINE_DIR . 'bbcode/index.php')) {
        require_once ENGINE_DIR . 'bbcode/index.php';
        // bb-код
        $out = bbcode_custom($out);
    }
    if ($var['markdown'] and mso_fe(ENGINE_DIR . 'markdown/markdown.php')) {
        require_once ENGINE_DIR . 'markdown/markdown.php';
        // markdown-код
        $out = Markdown($out);
    }
    if ($var['textile'] and mso_fe(ENGINE_DIR . 'textile/textile.php')) {
        require_once ENGINE_DIR . 'textile/textile.php';
        // textile-код
        $parser = new Textile('html5');
        $out = $parser->textileThis($out);
    }
    if ($var['remove_protocol']) {
        $out = mso_remove_protocol($out);
    }
    if ($var['compress_text']) {
        $out = mso_compress_text($out);
    }
    return $out;
}
Пример #17
0
function article_edit($message = '', $concurrent = FALSE)
{
    global $vars, $txp_user, $comments_disabled_after, $txpcfg, $prefs;
    extract($prefs);
    extract(gpsa(array('view', 'from_view', 'step')));
    if (!empty($GLOBALS['ID'])) {
        // newly-saved article
        $ID = $GLOBALS['ID'];
        $step = 'edit';
    } else {
        $ID = gps('ID');
    }
    include_once txpath . '/lib/classTextile.php';
    $textile = new Textile();
    // switch to 'text' view upon page load and after article post
    if (!$view || gps('save') || gps('publish')) {
        $view = 'text';
    }
    if (!$step) {
        $step = "create";
    }
    if ($step == "edit" && $view == "text" && !empty($ID) && $from_view != 'preview' && $from_view != 'html' && !$concurrent) {
        $pull = true;
        //-- it's an existing article - off we go to the db
        $ID = assert_int($ID);
        $rs = safe_row("*, unix_timestamp(Posted) as sPosted,\n\t\t\t\tunix_timestamp(Expires) as sExpires,\n\t\t\t\tunix_timestamp(LastMod) as sLastMod", "textpattern", "ID={$ID}");
        extract($rs);
        $reset_time = $publish_now = $Status < 4;
    } else {
        $pull = false;
        //-- assume they came from post
        if ($from_view == 'preview' or $from_view == 'html') {
            $store_out = array();
            $store = unserialize(base64_decode(ps('store')));
            foreach ($vars as $var) {
                if (isset($store[$var])) {
                    $store_out[$var] = $store[$var];
                }
            }
        } else {
            $store_out = gpsa($vars);
            if ($concurrent) {
                $store_out['sLastMod'] = safe_field('unix_timestamp(LastMod) as sLastMod', 'textpattern', 'ID=' . $ID);
            }
        }
        extract($store_out);
    }
    $GLOBALS['step'] = $step;
    if ($step == 'create') {
        $textile_body = $use_textile;
        $textile_excerpt = $use_textile;
    }
    if ($step != 'create') {
        // Previous record?
        $prev_id = checkIfNeighbour('prev', $sPosted);
        // Next record?
        $next_id = checkIfNeighbour('next', $sPosted);
    }
    $page_title = $Title ? $Title : gTxt('write');
    pagetop($page_title, $message);
    echo n . n . '<form name="article" method="post" action="index.php">';
    if (!empty($store_out)) {
        echo hInput('store', base64_encode(serialize($store_out)));
    }
    echo hInput('ID', $ID) . eInput('article') . sInput($step) . '<input type="hidden" name="view" />' . startTable('edit') . '<tr>' . n . '<td id="article-col-1">';
    if ($view == 'text') {
        //-- markup help --------------
        echo side_help($textile_body, $textile_excerpt) . '<h3 class="plain"><a href="#advanced" onclick="toggleDisplay(\'advanced\'); return false;">' . gTxt('advanced_options') . '</a></h3>', '<div id="advanced" class="toggle" style="display:none">', n . graf('<label for="markup-body">' . gTxt('article_markup') . '</label>' . br . pref_text('textile_body', $textile_body, 'markup-body')), n . graf('<label for="markup-excerpt">' . gTxt('excerpt_markup') . '</label>' . br . pref_text('textile_excerpt', $textile_excerpt, 'markup-excerpt')), $allow_form_override ? graf('<label for="override-form">' . gTxt('override_default_form') . '</label>' . sp . popHelp('override_form') . br . form_pop($override_form, 'override-form')) : '', $custom_1_set ? custField(1, $custom_1_set, $custom_1) : '', $custom_2_set ? custField(2, $custom_2_set, $custom_2) : '', $custom_3_set ? custField(3, $custom_3_set, $custom_3) : '', $custom_4_set ? custField(4, $custom_4_set, $custom_4) : '', $custom_5_set ? custField(5, $custom_5_set, $custom_5) : '', $custom_6_set ? custField(6, $custom_6_set, $custom_6) : '', $custom_7_set ? custField(7, $custom_7_set, $custom_7) : '', $custom_8_set ? custField(8, $custom_8_set, $custom_8) : '', $custom_9_set ? custField(9, $custom_9_set, $custom_9) : '', $custom_10_set ? custField(10, $custom_10_set, $custom_10) : '', n . graf('<label for="keywords">' . gTxt('keywords') . '</label>' . sp . popHelp('keywords') . br . n . '<textarea id="keywords" name="Keywords" cols="18" rows="5">' . htmlspecialchars(str_replace(',', ', ', $Keywords)) . '</textarea>'), n . graf('<label for="article-image">' . gTxt('article_image') . '</label>' . sp . popHelp('article_image') . br . fInput('text', 'Image', $Image, 'edit', '', '', 22, '', 'article-image')), n . graf('<label for="url-title">' . gTxt('url_title') . '</label>' . sp . popHelp('url_title') . br . fInput('text', 'url_title', $url_title, 'edit', '', '', 22, '', 'url-title')), '</div>

			<h3 class="plain"><a href="#recent" onclick="toggleDisplay(\'recent\'); return false;">' . gTxt('recent_articles') . '</a>' . '</h3>' . '<div id="recent" class="toggle" style="display:none">';
        $recents = safe_rows_start("Title, ID", 'textpattern', "1=1 order by LastMod desc limit 10");
        if ($recents) {
            echo '<ul class="plain-list">';
            while ($recent = nextRow($recents)) {
                if (!$recent['Title']) {
                    $recent['Title'] = gTxt('untitled') . sp . $recent['ID'];
                }
                echo n . t . '<li><a href="?event=article' . a . 'step=edit' . a . 'ID=' . $recent['ID'] . '">' . escape_title($recent['Title']) . '</a></li>';
            }
            echo '</ul>';
        }
        echo '</div>';
    } else {
        echo sp;
    }
    echo '</td>' . n . '<td id="article-main">';
    //-- title input --------------
    if ($view == 'preview') {
        echo hed(gTxt('preview'), 2) . hed($Title, 1);
    } elseif ($view == 'html') {
        echo hed('XHTML', 2) . hed($Title, 1);
    } elseif ($view == 'text') {
        echo n . '<p><label for="title">' . gTxt('title') . '</label>' . sp . popHelp('title') . br . '<input type="text" id="title" name="Title" value="' . escape_title($Title) . '" class="edit" size="40" tabindex="1" />';
        if ($step != 'create') {
            include_once txpath . '/publish/taghandlers.php';
            $url = permlinkurl_id($ID);
            if ($Status != 4 and $Status != 5) {
                $url .= (strpos($url, '?') === FALSE ? '?' : '&amp;') . 'txpreview=' . intval($ID) . '.' . time();
            }
            echo sp . sp . '<a href="' . $url . '" class="article-view">' . gTxt('view') . '</a>';
        }
        echo '</p>';
    }
    //-- body --------------------
    if ($view == 'preview') {
        if ($textile_body == USE_TEXTILE) {
            echo $textile->TextileThis($Body);
        } else {
            if ($textile_body == CONVERT_LINEBREAKS) {
                echo nl2br($Body);
            } else {
                if ($textile_body == LEAVE_TEXT_UNTOUCHED) {
                    echo $Body;
                }
            }
        }
    } elseif ($view == 'html') {
        if ($textile_body == USE_TEXTILE) {
            $bod = $textile->TextileThis($Body);
        } else {
            if ($textile_body == CONVERT_LINEBREAKS) {
                $bod = nl2br($Body);
            } else {
                if ($textile_body == LEAVE_TEXT_UNTOUCHED) {
                    $bod = $Body;
                }
            }
        }
        echo tag(str_replace(array(n, t), array(br, sp . sp . sp . sp), htmlspecialchars($bod)), 'code');
    } else {
        echo n . graf('<label for="body">' . gTxt('body') . '</label>' . sp . popHelp('body') . br . '<textarea id="body" name="Body" cols="55" rows="31" tabindex="2">' . htmlspecialchars($Body) . '</textarea>');
    }
    //-- excerpt --------------------
    if ($articles_use_excerpts) {
        if ($view == 'text') {
            echo n . graf('<label for="excerpt">' . gTxt('excerpt') . '</label>' . sp . popHelp('excerpt') . br . '<textarea id="excerpt" name="Excerpt" cols="55" rows="5" tabindex="3">' . htmlspecialchars($Excerpt) . '</textarea>');
        } else {
            echo n . '<hr width="50%" />';
            echo $textile_excerpt == USE_TEXTILE ? $view == 'preview' ? graf($textile->textileThis($Excerpt)) : tag(str_replace(array(n, t), array(br, sp . sp . sp . sp), htmlspecialchars($textile->TextileThis($Excerpt))), 'code') : graf($Excerpt);
        }
    }
    //-- author --------------
    if ($view == "text" && $step != "create") {
        echo '<p class="small">' . gTxt('posted_by') . ': ' . htmlspecialchars($AuthorID) . ' &#183; ' . safe_strftime('%d %b %Y &#183; %X', $sPosted);
        if ($sPosted != $sLastMod) {
            echo br . gTxt('modified_by') . ': ' . htmlspecialchars($LastModID) . ' &#183; ' . safe_strftime('%d %b %Y &#183; %X', $sLastMod);
        }
        echo '</p>';
    }
    echo hInput('from_view', $view), '</td>';
    echo '<td id="article-tabs">';
    //-- layer tabs -------------------
    echo $use_textile == USE_TEXTILE || $textile_body == USE_TEXTILE ? '<ul>' . (tab('text', $view) . tab('html', $view) . tab('preview', $view)) . '</ul>' : '&#160;';
    echo '</td>';
    echo '<td id="article-col-2">';
    if ($view == 'text') {
        if ($step != 'create') {
            echo n . graf(href(gtxt('create_new'), 'index.php?event=article'));
        }
        //-- prev/next article links --
        if ($step != 'create' and ($prev_id or $next_id)) {
            echo '<p>', $prev_id ? prevnext_link('&#8249;' . gTxt('prev'), 'article', 'edit', $prev_id, gTxt('prev')) : '', $next_id ? prevnext_link(gTxt('next') . '&#8250;', 'article', 'edit', $next_id, gTxt('next')) : '', '</p>';
        }
        //-- status radios --------------
        echo n . n . '<fieldset id="write-status">' . n . '<legend>' . gTxt('status') . '</legend>' . n . status_radio($Status) . n . '</fieldset>';
        //-- category selects -----------
        echo n . n . '<fieldset id="write-sort">' . n . '<legend>' . gTxt('sort_display') . '</legend>' . n . graf('<label for="category-1">' . gTxt('category1') . '</label> ' . '<span class="small">[' . eLink('category', '', '', '', gTxt('edit')) . ']</span>' . br . n . category_popup('Category1', $Category1, 'category-1')) . n . graf('<label for="category-2">' . gTxt('category2') . '</label>' . br . n . category_popup('Category2', $Category2, 'category-2'));
        //-- section select --------------
        if (!$from_view && !$pull) {
            $Section = getDefaultSection();
        }
        echo n . graf('<label for="section">' . gTxt('section') . '</label> ' . '<span class="small">[' . eLink('section', '', '', '', gTxt('edit')) . ']</span>' . br . section_popup($Section, 'section')) . n . '</fieldset>' . n . n . '<h3 class="plain"><a href="#more" onclick="toggleDisplay(\'more\'); return false;">' . gTxt('more') . '</a></h3>', '<div id="more" class="toggle" style="display:none">';
        //-- comments stuff --------------
        if ($step == "create") {
            //Avoiding invite disappear when previewing
            $AnnotateInvite = !empty($store_out['AnnotateInvite']) ? $store_out['AnnotateInvite'] : $comments_default_invite;
            if ($comments_on_default == 1) {
                $Annotate = 1;
            }
        }
        if ($use_comments == 1) {
            echo n . n . '<fieldset id="write-comments">' . n . '<legend>' . gTxt('comments') . '</legend>';
            $comments_expired = false;
            if ($step != 'create' && $comments_disabled_after) {
                $lifespan = $comments_disabled_after * 86400;
                $time_since = time() - $sPosted;
                if ($time_since > $lifespan) {
                    $comments_expired = true;
                }
            }
            if ($comments_expired) {
                echo n . n . graf(gTxt('expired'));
            } else {
                echo n . n . graf(onoffRadio('Annotate', $Annotate)) . n . n . graf('<label for="comment-invite">' . gTxt('comment_invitation') . '</label>' . br . fInput('text', 'AnnotateInvite', $AnnotateInvite, 'edit', '', '', '', '', 'comment-invite'));
            }
            echo n . n . '</fieldset>';
        }
        if ($step == "create" and empty($GLOBALS['ID'])) {
            //-- timestamp -------------------
            //Avoiding modified date to disappear
            $persist_timestamp = !empty($store_out['year']) ? safe_strtotime($store_out['year'] . '-' . $store_out['month'] . '-' . $store_out['day'] . ' ' . $store_out['hour'] . ':' . $store_out['minute'] . ':' . $store_out['second']) : time();
            echo n . n . '<fieldset id="write-timestamp">' . n . '<legend>' . gTxt('timestamp') . '</legend>' . n . graf(checkbox('publish_now', '1', $publish_now, '', 'publish_now') . '<label for="publish_now">' . gTxt('set_to_now') . '</label>') . n . graf(gTxt('or_publish_at') . sp . popHelp('timestamp')) . n . graf(gtxt('date') . sp . tsi('year', '%Y', $persist_timestamp) . ' / ' . tsi('month', '%m', $persist_timestamp) . ' / ' . tsi('day', '%d', $persist_timestamp)) . n . graf(gTxt('time') . sp . tsi('hour', '%H', $persist_timestamp) . ' : ' . tsi('minute', '%M', $persist_timestamp) . ' : ' . tsi('second', '%S', $persist_timestamp)) . n . '</fieldset>';
            //-- expires -------------------
            $persist_timestamp = !empty($store_out['exp_year']) ? safe_strtotime($store_out['exp_year'] . '-' . $store_out['exp_month'] . '-' . $store_out['exp_day'] . ' ' . $store_out['exp_hour'] . ':' . $store_out['exp_minute'] . ':' . $store_out['second']) : NULLDATETIME;
            echo n . n . '<fieldset id="write-expires">' . n . '<legend>' . gTxt('expires') . '</legend>' . n . graf(gtxt('date') . sp . tsi('exp_year', '%Y', $persist_timestamp) . ' / ' . tsi('exp_month', '%m', $persist_timestamp) . ' / ' . tsi('exp_day', '%d', $persist_timestamp)) . n . graf(gTxt('time') . sp . tsi('exp_hour', '%H', $persist_timestamp) . ' : ' . tsi('exp_minute', '%M', $persist_timestamp) . ' : ' . tsi('exp_second', '%S', $persist_timestamp)) . n . '</fieldset>' . n . n . '</div>';
            //-- publish button --------------
            echo has_privs('article.publish') ? fInput('submit', 'publish', gTxt('publish'), "publish", '', '', '', 4) : fInput('submit', 'publish', gTxt('save'), "publish", '', '', '', 4);
        } else {
            //-- timestamp -------------------
            if (!empty($year)) {
                $sPosted = safe_strtotime($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute . ':' . $second);
            }
            echo n . n . '<fieldset id="write-timestamp">' . n . '<legend>' . gTxt('timestamp') . '</legend>' . n . graf(checkbox('reset_time', '1', $reset_time, '', 'reset_time') . '<label for="reset_time">' . gTxt('reset_time') . '</label>') . n . graf(gTxt('published_at') . sp . popHelp('timestamp')) . n . graf(gtxt('date') . sp . tsi('year', '%Y', $sPosted) . ' / ' . tsi('month', '%m', $sPosted) . ' / ' . tsi('day', '%d', $sPosted)) . n . graf(gTxt('time') . sp . tsi('hour', '%H', $sPosted) . ' : ' . tsi('minute', '%M', $sPosted) . ' : ' . tsi('second', '%S', $sPosted)) . n . hInput('sPosted', $sPosted), n . hInput('sLastMod', $sLastMod), n . hInput('AuthorID', $AuthorID), n . hInput('LastModID', $LastModID), n . '</fieldset>';
            //-- expires -------------------
            if (!empty($exp_year)) {
                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;
                }
                $sExpires = safe_strtotime($exp_year . '-' . $exp_month . '-' . $exp_day . ' ' . $exp_hour . ':' . $exp_minute . ':' . $exp_second);
            }
            echo n . n . '<fieldset id="write-expires">' . n . '<legend>' . gTxt('expires') . '</legend>' . n . graf(gtxt('date') . sp . tsi('exp_year', '%Y', $sExpires) . ' / ' . tsi('exp_month', '%m', $sExpires) . ' / ' . tsi('exp_day', '%d', $sExpires)) . n . graf(gTxt('time') . sp . tsi('exp_hour', '%H', $sExpires) . ' : ' . tsi('exp_minute', '%M', $sExpires) . ' : ' . tsi('exp_second', '%S', $sExpires)) . n . hInput('sExpires', $sExpires) . n . '</fieldset>' . n . n . '</div>';
            //-- save button --------------
            if ($Status >= 4 and has_privs('article.edit.published') or $Status >= 4 and $AuthorID == $txp_user and has_privs('article.edit.own.published') or $Status < 4 and has_privs('article.edit') or $Status < 4 and $AuthorID == $txp_user and has_privs('article.edit.own')) {
                echo fInput('submit', 'save', gTxt('save'), "publish", '', '', '', 4);
            }
        }
    }
    echo '</td></tr></table></form>';
}
Пример #18
0
function zem_event_save($article_id, $name, $date, $time = NULL, $finish_date = NULL, $finish_time = NULL, $location = NULL, $location_url = NULL, $url = NULL, $email = NULL, $description = NULL, $categories = NULL, $repeat_n = NULL, $repeat_period = NULL, $repeat_to = NULL)
{
    $d = zem_strtotime($date);
    if (!$d) {
        return false;
    }
    $sql_date = zem_sqldate($d);
    if ($time !== NULL) {
        $t = zem_strtotime($time);
        if (!$t) {
            return false;
        }
        $sql_time = zem_sqltime($t);
    }
    if ($finish_date) {
        $d = zem_strtotime($finish_date);
        if (!$d) {
            return false;
        }
        $sql_fdate = zem_sqldate($d);
    }
    if ($finish_time) {
        $t = zem_strtotime($finish_time);
        if (!$t) {
            return false;
        }
        $sql_ftime = zem_sqltime($t);
    }
    if ($repeat_to) {
        $d = zem_strtotime($repeat_to);
        if (!$d) {
            return false;
        }
        $sql_repeat_to = zem_sqldate($d);
    }
    $description_html = $description;
    if ($description !== NULL) {
        include_once txpath . '/lib/classTextile.php';
        $textile = new Textile();
        $description_html = $textile->textileThis($description);
    }
    if ($id = safe_field('id', 'zem_event_calendar', "article_id='" . doSlash($article_id) . "'")) {
        $old = safe_row('*', 'zem_event_calendar', "id='" . doSlash($id) . "'");
        $result = safe_update('zem_event_calendar', "event_date='" . doSlash($sql_date) . "'," . ($time ? "event_time='" . doSlash($sql_time) . "'," : 'event_time=NULL,') . ($finish_date ? "finish_date='" . doSlash($sql_fdate) . "'," : 'finish_date=NULL,') . ($finish_time ? "finish_time='" . doSlash($sql_ftime) . "'," : 'finish_time=NULL,') . ($location !== NULL ? "location='" . doSlash($location) . "'," : '') . ($location_url !== NULL ? "location_url='" . doSlash($location_url) . "'," : '') . ($url !== NULL ? "url='" . doSlash($url) . "'," : '') . ($email !== NULL ? "email='" . doSlash($email) . "'," : '') . ($description !== NULL ? "description='" . doSlash($description) . "'," : '') . ($description_html !== NULL ? "description_html='" . doSlash($description_html) . "'," : '') . ($repeat_n ? "repeat_n='" . intval($repeat_n) . "'," : 'repeat_n=NULL,') . ($repeat_period ? "repeat_period='" . doSlash($repeat_period) . "'," : 'repeat_period=NULL,') . ($repeat_to ? "repeat_to='" . doSlash($sql_repeat_to) . "'," : 'repeat_to=NULL,') . "name='" . doSlash($name) . "',\n\t\t\tmodified=now()", "id='" . doSlash($id) . "'");
        // reinsert dates if any have changed
        if ($result and array($old['event_date'], $old['event_time'], $old['finish_date'], $old['finish_time'], $old['repeat_n'], $old['repeat_period'], $old['repeat_to']) != array($sql_date, @$sql_time, @$sql_fdate, @$sql_ftime, @$repeat_n, $repeat_period, $repeat_to)) {
            safe_delete('zem_event_date', "event_id='" . doSlash($id) . "'");
            zem_event_insert_date($id, $date, $time, $finish_date, $finish_time);
            if ($repeat_n and $repeat_period and $repeat_to) {
                $first_date = zem_strtotime($date);
                $first_finish = zem_strtotime($finish_date);
                $i = 1;
                $count = 0;
                while (++$count < ZEM_MAX_REPEAT_EVENTS and ($next = zem_strtotime('+' . $i * $repeat_n . ' ' . $repeat_period, $first_date)) <= zem_strtotime($repeat_to)) {
                    zem_event_insert_date($id, zem_sqldate($next), $time, $finish_date ? zem_sqldate(zem_strtotime('+' . $i * $repeat_n . ' ' . $repeat_period, $first_finish)) : NULL, $finish_time);
                    ++$i;
                }
            }
        }
    } else {
        $result = safe_insert('zem_event_calendar', "event_date='" . doSlash($sql_date) . "'," . ($time ? "event_time='" . doSlash($sql_time) . "'," : 'event_time=NULL,') . ($finish_date ? "finish_date='" . doSlash($sql_fdate) . "'," : 'finish_date=NULL,') . ($finish_time ? "finish_time='" . doSlash($sql_ftime) . "'," : 'finish_time=NULL,') . ($location !== NULL ? "location='" . doSlash($location) . "'," : '') . ($location_url !== NULL ? "location_url='" . doSlash($location_url) . "'," : '') . ($url !== NULL ? "url='" . doSlash($url) . "'," : '') . ($email !== NULL ? "email='" . doSlash($email) . "'," : '') . ($description !== NULL ? "description='" . doSlash($description) . "'," : '') . ($description_html !== NULL ? "description_html='" . doSlash($description_html) . "'," : '') . ($repeat_n ? "repeat_n='" . intval($repeat_n) . "'," : 'repeat_n=NULL,') . ($repeat_period ? "repeat_period='" . doSlash($repeat_period) . "'," : 'repeat_period=NULL,') . ($repeat_to ? "repeat_to='" . doSlash($sql_repeat_to) . "'," : 'repeat_to=NULL,') . "name='" . doSlash($name) . "',\n\t\t\tarticle_id='" . doSlash($article_id) . "',\n\t\t\tmodified=now(),\n\t\t\tcreated=now()");
        if ($result) {
            $id = $result;
        }
        if ($id) {
            zem_event_insert_date($id, $date, $time, $finish_date, $finish_time);
            if ($repeat_n and $repeat_period and $repeat_to) {
                $first_date = zem_strtotime($date);
                $first_finish = zem_strtotime($finish_date);
                $i = 1;
                $count = 0;
                while (++$count < ZEM_MAX_REPEAT_EVENTS and ($next = zem_strtotime('+' . $i * $repeat_n . ' ' . $repeat_period, $first_date)) <= zem_strtotime($repeat_to)) {
                    zem_event_insert_date($id, zem_sqldate($next), $time, $finish_date ? zem_sqldate(zem_strtotime('+' . $i * $repeat_n . ' ' . $repeat_period, $first_finish)) : NULL, $finish_time);
                    ++$i;
                }
            }
        }
    }
    if ($result and $categories !== NULL) {
        if (empty($categories)) {
            $categories = array();
        }
        if (m2m_update_links('zem_event_category', $id, $categories)) {
            return $id;
        }
        return false;
    }
    if ($result) {
        return $id;
    }
    return false;
}