b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: admin ] [ index: admin ] [ all elements ]

Source for file edit_actions.php

Documentation is available at edit_actions.php

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

Documentation generated on Tue, 20 May 2008 01:51:37 +0200 by phpDocumentor 1.4.2