Skip to content
Permalink
Browse files

Adding if_preview and some (potentially experimental) stuff to custom…

…ize previews. More details to follow...

git-svn-id: http://textpattern.googlecode.com/svn/development/4.0@1041 2fea6a4d-a838-0410-917b-93a53c48e9d2
  • Loading branch information...
Sencer Yurdagül
Sencer Yurdagül committed Oct 17, 2005
1 parent ebad81b commit 879e760ce923a4b85c6b2ad0ba46097606422519
Showing with 68 additions and 10 deletions.
  1. +4 −2 textpattern/publish.php
  2. +8 −6 textpattern/publish/comment.php
  3. +56 −2 textpattern/publish/taghandlers.php
@@ -419,6 +419,8 @@ function textpattern()
set_error_handler("tagErrorHandler");
$html = parse($html);
$GLOBALS['pretext']['secondpass'] = true;
$GLOBALS['txptrace'][] = " secondpass \r\n";
$html = parse($html); // the function so nice, he ran it twice
restore_error_handler();
$html = (!$segment) ? $html : segmentPage($html);
@@ -683,7 +685,7 @@ function doArticle($atts)
$article = fetch_form(($override_form) ? $override_form : $form);
if ($preview && $parentid) {
$article = '<a id="cpreview"></a>'.discuss($parentid).$article;
$article = '<txp:preview bc="1" id="'.$parentid.'" />'.$article;
}
$article = parse($article);
@@ -876,7 +878,7 @@ function processTags($matches)
elseif (isset($pretext[$tag])) $out = $pretext[$tag];
else trigger_error(gTxt('unknown_tag'), E_USER_WARNING);
} else {
if (function_exists($tag)) $out = $tag($atts);
if (function_exists($tag)) $out = $tag($atts,null,$matches[0]);
elseif (isset($pretext[$tag])) $out = $pretext[$tag];
else trigger_error(gTxt('unknown_tag'), E_USER_WARNING);
}
@@ -16,7 +16,7 @@ function fetchComments($id)
{
$rs = safe_rows(
"*, unix_timestamp(posted) as time",
"txp_discuss", "parentid='$id' and visible='1' order by posted asc"
"txp_discuss", "parentid='".doSlash($id)."' and visible='1' order by posted asc"
);
if ($rs) return $rs;
@@ -255,7 +255,7 @@ function saveComment()
$visible = ($comments_moderate) ? 0 : 1;
$rs = safe_insert(
"txp_discuss",
"parentid = '$parentid',
"parentid = '".doSlash($parentid)."',
name = '$name',
email = '$email',
web = '$web',
@@ -266,7 +266,7 @@ function saveComment()
);
if ($rs) {
safe_update("txp_discuss_nonce", "used='1'", "nonce='$nonce'");
safe_update("txp_discuss_nonce", "used='1'", "nonce='".doslash($nonce)."'");
if ($prefs['comment_means_site_updated']) {
safe_update("txp_prefs", "val=now()", "name='lastmod'");
}
@@ -276,7 +276,6 @@ function saveComment()
$updated = update_comments_count($parentid);
ob_start();
$backpage = substr($backpage, 0, $prefs['max_url_len']);
$backpage = preg_replace("/[\x0a\x0d#].*$/s",'',$backpage);
$backpage .= ((strstr($backpage,'?')) ? '&' : '?') . 'commented=1';
@@ -296,11 +295,12 @@ function saveComment()
// -------------------------------------------------------------
function checkNonce($nonce)
{
if (!$nonce) return false;
if (!$nonce && !preg_match('#^[a-zA-Z0-9]*$#',$nonce))
return false;
// delete expired nonces
safe_delete("txp_discuss_nonce", "issue_time < date_sub(now(),interval 10 minute)");
// check for nonce
return (safe_row("*", "txp_discuss_nonce", "nonce='$nonce' and used='0'")) ? true : false;
return (safe_row("*", "txp_discuss_nonce", "nonce='".doslash($nonce)."' and used='0'")) ? true : false;
}
// -------------------------------------------------------------
@@ -314,6 +314,8 @@ function checkCommentsAllowed($id)
{
global $use_comments, $comments_disabled_after, $thisarticle;
$id = intval($id);
if (!$use_comments || !$id)
return false;
@@ -720,7 +720,7 @@ function comments_invite($atts)
'showalways' => false //FIXME in crockery. This is only for BC.
), $atts));
if (($annotate or $comments_count) && ($displayalways or $is_article_list) ) {
if (($annotate or $comments_count) && ($showalways or $is_article_list) ) {
$ccount = ($comments_count && $showcount) ? ' ['.$comments_count.']' : '';
@@ -744,13 +744,14 @@ function comments_form($atts)
extract(lAtts(array(
'id' => @$pretext['id'],
'class' => __FUNCTION__,
'preview' => false,
'form' => 'comment_form',
'wraptag' => ''
),$atts));
# don't display the comment form at the bottom, since it's
# already shown at the top
if (ps('preview') and empty($comment_preview))
if (ps('preview') and empty($comment_preview) and !$preview)
return '';
if (is_array($thisarticle)) extract($thisarticle);
@@ -859,6 +860,59 @@ function comments($atts)
return $out;
}
// -------------------------------------------------------------
function preview($atts, $thing='', $me='')
{
global $thisarticle;
if (!ps('preview'))
return;
extract(lAtts(array(
'id' => @$pretext['id'],
'form' => 'comments',
'bc' => false, // backwards-compatibility; only internally for old preview behaviour
'wraptag' => '',
'class' => __FUNCTION__,
),$atts));
//FIXME for crockery. This emulates the old hardcoded preview behaviour.
if ($bc)
{
if (@$GLOBALS['pretext']['secondpass'] == false)
return $me;
if (@$GLOBALS['pretext']['preview_shown'])
return '';
else
return '<a id="cpreview"></a>'.discuss($id);
}
$GLOBALS['pretext']['preview_shown'] = true;
if (is_array($thisarticle)) extract($thisarticle);
if (@$thisid) $id = $thisid;
$Form = fetch_form($form);
$preview = psas(array('name','email','web','message','parentid','remember'));
$preview['time'] = time();
$preview['discussid'] = 0;
$preview['message'] = markup_comment($preview['message']);
$GLOBALS['thiscomment'] = $preview;
$comments = parse($Form).n;
unset($GLOBALS['thiscomment']);
$out = doTag($comments,$wraptag,$class);
return $out;
}
// -------------------------------------------------------------
function if_preview($atts, $thing)
{
return parse(EvalElse($thing, ps('preview') && checkCommentsAllowed(gps('parentid')) ));
}
// -------------------------------------------------------------
function comment_permlink($atts,$thing)
{

0 comments on commit 879e760

Please sign in to comment.
You can’t perform that action at this time.