1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
|
<?php
/**
* Editing actions
*
* Performs one of the following:
* - Insert new post
* - Update existing post
* - Publish existing post
* - Delete existing post
* - Update existing comment
* - Delete existing comment
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
*
* @package admin
*/
/**
* Includes:
*/
require_once( dirname(__FILE__) . '/_header.php' );
$admin_tab = 'edit';
param( 'action', 'string', '' );
param( 'mode', 'string', '' );
param( 'edit_date', 'integer', 0 );
param( 'aa', 'integer', 2000 );
param( 'mm', 'integer', 1 );
param( 'jj', 'integer', 1 );
param( 'hh', 'integer', 20 );
param( 'mn', 'integer', 30 );
param( 'ss', 'integer', 0 );
$jj = ($jj > 31) ? 31 : $jj;
$hh = ($hh > 23) ? $hh - 24 : $hh;
$mn = ($mn > 59) ? $mn - 60 : $mn;
$ss = ($ss > 59) ? $ss - 60 : $ss;
// All statuses are allowed for acting on:
$show_statuses = array( 'published', 'protected', 'private', 'draft', 'deprecated' );
switch($action)
{
case 'post':
/*
* --------------------------------------------------------------------
* INSERT POST & more
*/
param( 'post_category', 'integer', true );
$blog = get_catblog( $post_category );
$blogparams = get_blogparams_by_ID( $blog );
param( 'mode', 'string', '' );
switch($mode)
{
case 'sidebar':
$location="b2sidebar.php?blog=$blog";
break;
default:
$location="b2browse.php?blog=$blog";
break;
}
$admin_pagetitle = T_('Adding new post...');
require( dirname(__FILE__) . '/_menutop.php' );
require( dirname(__FILE__) . '/_menutop_end.php' );
param( 'post_status', 'string', 'published' );
param( 'post_extracats', 'array', array() );
// make sure main cat is in extracat list and there are no duplicates
$post_extracats[] = $post_category;
$post_extracats = array_unique( $post_extracats );
// Check permission on statuses:
$current_User->check_perm( 'cats_post_statuses', $post_status, true, $post_extracats );
param( 'post_autobr', 'integer', 0 );
param( 'post_pingback', 'integer', 0 );
param( 'trackback_url', 'string' );
$post_trackbacks = & $trackback_url;
param( 'content', 'html' );
param( 'post_title', 'html' );
param( 'post_urltitle', 'string' );
param( 'post_url', 'string' );
param( 'post_comments', 'string', 'open' ); // 'open' or 'closed' or ...
param( 'post_locale', 'string', $default_locale );
param( 'renderers', 'array', array() );
if( $edit_date && $current_User->check_perm( 'edit_timestamp' ))
{ // We use user date
$post_date = date('Y-m-d H:i:s', mktime( $hh, $mn, $ss, $mm, $jj, $aa ) );
}
else
{ // We use current time
$post_date = date('Y-m-d H:i:s', $localtimenow);
}
// CHECK and FORMAT content
$post_renderers = $Renderer->validate_list( $renderers );
$post_title = format_to_post($post_title,0,0);
if( $error = validate_url( $post_url, $allowed_uri_scheme ) )
{
errors_add( T_('Supplied URL is invalid: ').$error );
}
$content = format_to_post($content,$post_autobr,0);
if( !empty($comment) && antispam_check( strip_tags($comment) ) )
{
errors_add( T_('Supplied content is invalid') );
}
if( errors() )
{
echo '<div class="panelinfo">';
errors_display( T_('Cannot post, please correct these errors:'),
'[<a href="javascript:history.go(-1)">' . T_('Back to post editing') . '</a>]' );
echo '</div>';
break;
}
echo '<div class="panelinfo">'."\n";
echo '<h3>', T_('Recording post...'), "</h3>\n";
// Are we going to do the pings or not?
$pingsdone = ( $post_status == 'published' ) ? true : false;
// INSERT NEW POST INTO DB:
$post_ID = bpost_create( $user_ID, $post_title, $content, $post_date, $post_category,
$post_extracats, $post_status, $post_locale, '', $post_autobr,
$pingsdone, $post_urltitle, $post_url, $post_comments,
$post_renderers );
if (isset($sleep_after_edit) && $sleep_after_edit > 0)
{
echo '<p>', T_('Sleeping...'), "</p>\n";
flush();
sleep($sleep_after_edit);
}
echo '<p>'.T_('Done.').'</p>';
echo "</div>\n";
if( $post_status != 'published' )
{
echo "<div class=\"panelinfo\">\n";
echo '<p>', T_('Post not publicly published: skipping trackback, pingback and blog pings...'), "</p>\n";
echo "</div>\n";
}
else
{ // We do all the pinging now!
$blogparams = get_blogparams_by_ID( $blog );
// trackback
trackbacks( $post_trackbacks, $content, $post_title, $post_ID);
// pingback
pingback( $post_pingback, $content, $post_title, $post_url, $post_ID, $blogparams);
pingb2evonet($blogparams, $post_ID, $post_title);
pingWeblogs($blogparams);
pingBlogs($blogparams);
pingTechnorati($blogparams);
}
echo '<div class="panelinfo"><p>', T_('Posting Done...'), "</p></div>\n";
break;
case 'editpost':
/*
* --------------------------------------------------------------------
* UPDATE POST
*/
param( 'post_category', 'integer', true );
$blog = get_catblog($post_category);
$blogparams = get_blogparams_by_ID( $blog );
$location = 'b2browse.php?blog='. $blog;
$admin_pagetitle = T_('Updating post...');
require( dirname(__FILE__) . '/_menutop.php' );
require( dirname(__FILE__) . '/_menutop_end.php' );
param( 'post_status', 'string', 'published' );
param( 'post_extracats', 'array', array() );
// make sure main cat is in extracat list and there are no duplicates
$post_extracats[] = $post_category;
$post_extracats = array_unique( $post_extracats );
// Check permission on statuses:
$current_User->check_perm( 'cats_post_statuses', $post_status, true, $post_extracats );
param( 'post_ID', 'integer', true );
param( "post_autobr", 'integer', 0 );
param( "post_pingback", 'integer', 0 );
param( 'trackback_url', 'string' );
$post_trackbacks = $trackback_url;
param( 'content', 'html' );
param( 'post_title', 'html' );
param( 'post_urltitle', 'string' );
param( 'post_url', 'string' );
param( 'post_comments', 'string', 'open' ); // 'open' or 'closed' or ...
param( 'post_locale', 'string', $default_locale );
param( 'renderers', 'array', array() );
$post_renderers = $Renderer->validate_list( $renderers );
$postdata = get_postdata($post_ID) or die(T_('Oops, no post with this ID.'));
if( $edit_date && $current_User->check_perm( 'edit_timestamp' ))
{ // We use user date
$post_date = date('Y-m-d H:i:s', mktime( $hh, $mn, $ss, $mm, $jj, $aa ) );
}
else
{ // We use current time
$post_date = $postdata['Date'];
}
// CHECK and FORMAT content
$post_title = format_to_post( $post_title, 0, 0 );
if( $error = validate_url( $post_url, $allowed_uri_scheme ) )
{
errors_add( T_('Supplied URL is invalid: ').$error );
}
$content = format_to_post($content,$post_autobr,0);
if( !empty($comment) && antispam_check( strip_tags($comment) ) )
{
errors_add( T_('Supplied content is invalid') );
}
if( errors() )
{
echo '<div class="panelinfo">';
errors_display( T_('Cannot update, please correct these errors:'),
'[<a href="javascript:history.go(-1)">' . T_('Back to post editing') . '</a>]' );
echo '</div>';
break;
}
echo "<div class=\"panelinfo\">\n";
echo '<h3>'.T_('Updating post...')."</h3>\n";
// We need to check the previous flags...
$post_flags = $postdata['Flags'];
if( in_array( 'pingsdone', $post_flags ) )
{ // pings have been done before
$pingsdone = true;
}
elseif( $post_status != 'published' )
{ // still not publishing
$pingsdone = false;
}
else
{ // We'll be pinging now
$pingsdone = true;
}
// UPDATE POST IN DB:
bpost_update( $post_ID, $post_title, $content, $post_date, $post_category, $post_extracats,
$post_status, $post_locale, '', $post_autobr, $pingsdone, $post_urltitle,
$post_url, $post_comments, $post_renderers );
if (isset($sleep_after_edit) && $sleep_after_edit > 0)
{
echo '<p>'.T_('Sleeping...')."</p>\n";
flush();
sleep($sleep_after_edit);
}
echo '<p>'.T_('Done.').'</p></div>';
if( $post_status != 'published' )
{
echo "<div class=\"panelinfo\">\n";
echo '<p>', T_('Post not publicly published: skipping trackback, pingback and blog pings...'), "</p>\n";
echo "</div>\n";
}
else
{ // We may do some pinging now!
$blogparams = get_blogparams_by_ID( $blog );
// trackback
trackbacks( $post_trackbacks, $content, $post_title, $post_ID );
// pingback
pingback( $post_pingback, $content, $post_title, $post_url, $post_ID, $blogparams);
// ping ?
if( in_array( 'pingsdone', $post_flags ) )
{ // pings have been done before
echo "<div class=\"panelinfo\">\n";
echo '<p>', T_('Post had already pinged: skipping blog pings...'), "</p>\n";
echo "</div>\n";
}
else
{ // We'll ping now
pingb2evonet( $blogparams, $post_ID, $post_title );
pingWeblogs( $blogparams );
pingBlogs( $blogparams );
pingTechnorati( $blogparams );
}
}
echo '<div class="panelinfo"><p>', T_('Updating done...'), "</p></div>\n";
break;
case 'publish':
/*
* --------------------------------------------------------------------
* PUBLISH POST NOW
*/
param( 'post_ID', 'integer', true );
$postdata = get_postdata($post_ID) or die(T_('Oops, no post with this ID.'));
$post_cat =$postdata['Category'];
$blog = get_catblog($post_cat);
$blogparams = get_blogparams_by_ID( $blog );
$location = 'b2browse.php?blog=' . $blog;
$admin_pagetitle = T_('Updating post status...');
require(dirname(__FILE__).'/_menutop.php');
require(dirname(__FILE__).'/_menutop_end.php');
$post_status = 'published';
// Check permissions:
/* TODO: Check extra categories!!! */
$current_User->check_perm( 'blog_post_statuses', $post_status, true, $blog );
$current_User->check_perm( 'edit_timestamp', 'any', true ) ;
$post_date = date('Y-m-d H:i:s', $localtimenow);
$post_title = $postdata['Title'];
$post_url = $postdata['Url'];
echo "<div class=\"panelinfo\">\n";
echo '<h3>'.T_('Updating post status...')."</h3>\n";
// We need to check the previous flags...
$post_flags = $postdata['Flags'];
if( in_array( 'pingsdone', $post_flags ) )
{ // pings have been done before
$pingsdone = true;
}
elseif( $post_status != 'published' )
{ // still not publishing
$pingsdone = false;
}
else
{ // We'll be pinging now
$pingsdone = true;
}
// UPDATE POST IN DB:
bpost_update_status( $post_ID, $post_status, $pingsdone, $post_date );
if (isset($sleep_after_edit) && $sleep_after_edit > 0)
{
echo "<p>Sleeping...</p>\n";
flush();
sleep($sleep_after_edit);
}
echo '<p>', T_('Done.'), "</p>\n";
echo "</div>\n";
if( $post_status != 'published' )
{
echo "<div class=\"panelinfo\">\n";
echo '<p>', T_('Post not publicly published: skipping trackback, pingback and blog pings...'), "</p>\n";
echo "</div>\n";
}
else
{ // We may do some pinging now!
$blogparams = get_blogparams_by_ID( $blog );
// ping ?
if( in_array( 'pingsdone', $post_flags ) )
{ // pings have been done before
echo "<div class=\"panelinfo\">\n";
echo '<p>', T_('Post had already pinged: skipping blog pings...'), "</p>\n";
echo "</div>\n";
}
else
{ // We'll ping now
pingb2evonet( $blogparams, $post_ID, $post_title);
pingWeblogs($blogparams);
pingBlogs($blogparams);
pingTechnorati($blogparams);
}
}
echo '<div class="panelinfo"><p>'.T_('Updating done...').'</p></div>';
break;
case 'delete':
/*
* --------------------------------------------------------------------
* DELETE a post from db
*/
$admin_pagetitle = T_('Deleting post...');
require( dirname(__FILE__) . '/_menutop.php' );
require( dirname(__FILE__) . '/_menutop_end.php' );
param( 'post', 'integer' );
// echo $post;
if( ! ($postdata = get_postdata( $post )) )
{
echo '<div class="panelinfo"><p class="error">'.( T_('Oops, no post with this ID!') ).'</p></div>';
break;
}
$blog = get_catblog( $postdata['Category'] );
$blogparams = get_blogparams_by_ID( $blog );
$location = 'b2browse.php?blog='.$blog;
// Check permission:
$current_User->check_perm( 'blog_del_post', '', true, $blog );
echo "<div class=\"panelinfo\">\n";
echo '<h3>', T_('Deleting post...'), "</h3>\n";
// DELETE POST FROM DB:
if( bpost_delete( $post ) )
{
if( isset($sleep_after_edit) && $sleep_after_edit > 0 )
{
echo '<p>', T_('Sleeping...'), "</p>\n";
flush();
sleep( $sleep_after_edit );
}
echo '<p>'.T_('Deleting Done...')."</p>\n";
}
else
{
echo '<p>'.T_('Error')."!</p>\n";
}
echo '</div>';
break;
case 'editedcomment':
/*
* --------------------------------------------------------------------
* UPDATE comment in db:
*/
param( 'comment_ID', 'integer', true );
// echo $comment_ID;
$edited_Comment = Comment_get_by_ID( $comment_ID );
$blog = $edited_Comment->Item->get( 'blog_ID' );
// Check permission:
$current_User->check_perm( 'blog_comments', '', true, $blog );
if( $edited_Comment->author_User === NULL )
{ // If this is not a member comment
param( 'newcomment_author', 'string', true );
param( 'newcomment_author_email', 'string' );
param( 'newcomment_author_url', 'string' );
}
param( 'content', 'html' );
param( "post_autobr", 'integer', ($comments_use_autobr == 'always')?1:0 );
// CHECK and FORMAT content
if( $error = validate_url( $newcomment_author_url, $allowed_uri_scheme ) )
{
errors_add( T_('Supplied URL is invalid: ').$error );
}
$content = format_to_post($content,$post_autobr,0); // We are faking this NOT to be a comment
if( errors_display( T_('Cannot update comment, please correct these errors:'),
'[<a href="javascript:history.go(-1)">' . T_('Back to post editing') . '</a>]' ) )
{
break;
}
$edited_Comment->set( 'content', $content );
if( $edited_Comment->author_User === NULL )
{ // If this is not a member comment
$edited_Comment->set( 'author', $newcomment_author );
$edited_Comment->set( 'author_email', $newcomment_author_email );
$edited_Comment->set( 'author_url', $newcomment_author_url );
}
if( $edit_date && $current_User->check_perm( 'edit_timestamp' ))
{ // We use user date
$edited_Comment->set( 'date', date('Y-m-d H:i:s', mktime( $hh, $mn, $ss, $mm, $jj, $aa ) ) );
}
$edited_Comment->dbupdate(); // Commit update to the DB
$comment_post_ID = $edited_Comment->Item->ID;
header ("Location: b2browse.php?blog=$blog&p=$comment_post_ID&c=1#comments"); //?a=ec");
exit();
case 'deletecomment':
/*
* --------------------------------------------------------------------
* DELETE comment from db:
*/
param( 'comment_ID', 'integer', true );
// echo $comment_ID;
$edited_Comment = Comment_get_by_ID( $comment_ID );
$comment_post_ID = $edited_Comment->Item->ID;
$blog = $edited_Comment->Item->get( 'blog_ID' );
// Check permission:
$current_User->check_perm( 'blog_comments', '', true, $blog );
// Delete from Db:
$edited_Comment->dbdelete();
header ("Location: b2browse.php?blog=$blog&p=$comment_post_ID&c=1#comments");
exit();
default:
// This can happen if we were displaying an action result, then the user logs out
// and logs in again: he comes back here with no action parameter set.
// Residrect to browse
header( 'Location: b2browse.php?blog=0' );
exit();
}
echo '<div class="panelinfo">';
if( empty( $mode ) )
{ // Normal mode:
if( isset($location) )
{
echo '<p><strong>[<a href="' . $location . '">' . T_('Back to posts!') . '</a>]</strong></p>';
}
echo '<p>' . T_('You may also want to generate static pages or view your blogs...') . '</p>';
echo '</div>';
// List the blogs:
require( dirname(__FILE__) . '/_blogs_list.php' );
}
else
{ // Special mode:
?>
<p><strong>[<a href="b2edit.php?blog=<?php echo $blog ?>&mode=<?php echo $mode ?>"><?php echo T_('New post') ?></a>]</strong></p>
<?php
}
echo '</div>';
require( dirname(__FILE__) . '/_footer.php' );
?>
|