phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Source for file _comments.ctrl.php

Documentation is available at _comments.ctrl.php

  1. <?php
  2. /**
  3.  * This file implements the UI controller for managing comments.
  4.  *
  5.  * Quam Plures - {@link http://quamplures.net/}
  6.  * Released under GNU GPL License - {@link http://quamplures.net/license.html}
  7.  * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
  8.  * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
  9.  *
  10.  *  {@internal Open Source relicensing agreement:
  11.  *  }}}
  12.  *
  13.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  14.  * @author fplanque: Francois PLANQUE.
  15.  *
  16.  * @package pond
  17.  */
  18. if!defined('QP_MAIN_INIT') ) die'Please, do not access this page directly.' );
  19.  
  20. /**
  21.  * @var AdminUI 
  22.  */
  23. global $AdminUI;
  24.  
  25. /**
  26.  * @var UserSettings 
  27.  */
  28. global $UserSettings;
  29.  
  30. param'action''string''list' );
  31.  
  32. /*
  33.  * Init the objects we want to work on.
  34.  */
  35. switch$action )
  36. {
  37.     case 'edit':
  38.     case 'update':
  39.     case 'publish':
  40.     case 'deprecate':
  41.     case 'delete':
  42.         param'comment_ID''integer'true );
  43.         $edited_Comment Comment_get_by_ID$comment_ID );
  44.  
  45.         $edited_Comment_Item $edited_Comment->get_Item();
  46.         set_working_blog$edited_Comment_Item->get_blog_ID() );
  47.         $BlogCache get_Cache'BlogCache' );
  48.         $Blog $BlogCache->get_by_ID$blog );
  49.  
  50.         // Check permission:
  51.         $current_User->check_perm'blog_comments''edit'true$blog );
  52.  
  53.         // Where are we going to redirect to?
  54.         param'redirect_to''string'url_add_param$admin_url'ctrl=items&blog='.$blog.'&p='.$edited_Comment->item_ID'&' ) );
  55.         break;
  56.  
  57.     case 'list':
  58.       // Check permission:
  59.       $selected autoselect_blog'blog_comments''edit' );
  60.         if$selected )
  61.         // No blog could be selected
  62.             $Messages->addT_('You have no permission to edit comments.' )'error' );
  63.             $action 'nil';
  64.         }
  65.         elseifset_working_blog$selected ) )    // set $blog & memorize in user prefs
  66.         {    // Selected a new blog:
  67.             $BlogCache get_Cache'BlogCache' );
  68.             $Blog $BlogCache->get_by_ID$blog );
  69.         }
  70.         break;
  71.  
  72.     default:
  73.         debug_die'unhandled action 1' );
  74. }
  75.  
  76.  
  77. $AdminUI->set_path'items' );    // Sublevel may be attached below
  78.  
  79. /**
  80.  * Perform action:
  81.  */
  82. switch$action )
  83. {
  84.      case 'nil':
  85.         // Do nothing
  86.         break;
  87.  
  88.  
  89.     case 'edit':
  90.         $AdminUI->title $AdminUI->title_titlearea T_('Editing comment').' #'.$edited_Comment->ID;
  91.         break;
  92.  
  93.  
  94.     case 'update':
  95.         // fp> TODO: $edited_Comment->load_from_Request( true );
  96.  
  97.         if$edited_Comment->get_author_User() )
  98.         // If this is not a member comment
  99.             param'newcomment_author''string'true );
  100.             param'newcomment_author_email''string' );
  101.             param'newcomment_author_url''string' );
  102.             param_check_not_empty'newcomment_author'T_('Please enter and author name.')'' );
  103.             $edited_Comment->set'author'$newcomment_author );
  104.             param_check_email'newcomment_author_email'false );
  105.             $edited_Comment->set'author_email'$newcomment_author_email );
  106.             param_check_url'newcomment_author_url''posting''' )// Give posting permissions here
  107.             $edited_Comment->set'author_url'$newcomment_author_url );
  108.         }
  109.  
  110.         // Content:
  111.         param'content''html' );
  112.         param'post_autobr''integer'($comments_use_autobr == 'always');
  113.  
  114.         param_check_html'content'T_('Invalid comment text.')'#'$post_autobr );    // Check this is backoffice content (NOT with comment rules)
  115.         $edited_Comment->set'content'get_param'content' ) );
  116.  
  117.         if$current_User->check_perm'edit_timestamp' ))
  118.         // We use user date
  119.             param_date'comment_issue_date'T_('Please enter a valid comment date.')true );
  120.             ifstrlen(get_param('comment_issue_date')) )
  121.             // only set it, if a date was given:
  122.                 param_time'comment_issue_time' );
  123.                 $edited_Comment->set'date'form_dateget_param'comment_issue_date' )get_param'comment_issue_time' ) ) )// TODO: cleanup...
  124.             }
  125.         }
  126.  
  127.         param'comment_rating''integer'NULL );
  128.         $edited_Comment->set_from_Request'rating' );
  129.  
  130.         param'comment_status''string''published' );
  131.         $edited_Comment->set_from_Request'status' );
  132.  
  133.         param'comment_nofollow''integer');
  134.         $edited_Comment->set_from_Request'nofollow' );
  135.  
  136.         if$Messages->count('error') )
  137.         {    // There have been some validation errors:
  138.             break;
  139.         }
  140.  
  141.         // UPDATE DB:
  142.         $edited_Comment->dbupdate();    // Commit update to the DB
  143.  
  144.         $Messages->addT_('Comment has been updated.')'success' );
  145.  
  146.         header_redirect$redirect_to );
  147.         /* exited */
  148.         break;
  149.  
  150.  
  151.     case 'publish':
  152.         $edited_Comment->set('status''published' );
  153.  
  154.         $edited_Comment->dbupdate();    // Commit update to the DB
  155.  
  156.         $Messages->addT_('Comment has been published.')'success' );
  157.  
  158.         header_redirect$redirect_to );
  159.         /* exited */
  160.         break;
  161.  
  162.  
  163.     case 'deprecate':
  164.         $edited_Comment->set('status''deprecated' );
  165.  
  166.         $edited_Comment->dbupdate();    // Commit update to the DB
  167.  
  168.         $Messages->addT_('Comment has been deprecated.')'success' );
  169.  
  170.         header_redirect$redirect_to );
  171.         /* exited */
  172.         break;
  173.  
  174.  
  175.     case 'delete':
  176.         // fp> TODO: non JS confirm
  177.  
  178.         // Delete from DB:
  179.         $edited_Comment->dbdelete();
  180.  
  181.         $Messages->addT_('Comment has been deleted.')'success' );
  182.  
  183.         header_redirect$redirect_to );
  184.         break;
  185.  
  186.  
  187.     case 'list':
  188.         /*
  189.          * Latest comments:
  190.          */
  191.         $AdminUI->title $AdminUI->title_titlearea T_('Latest comments');
  192.  
  193.         param'show_statuses''array'array()true );    // Array of cats to restrict to
  194.  
  195.         // Generate available blogs list:
  196.         $AdminUI->set_coll_list_params'blog_comments''edit',
  197.                         array'ctrl' => 'comments' )NULL'' );
  198.  
  199.         /*
  200.          * Add sub menu entries:
  201.          * We do this here instead of _header because we need to include all filter params into regenerate_url()
  202.          */
  203.         attach_browse_tabs();
  204.  
  205.         $AdminUI->append_path_level'comments' );
  206.  
  207.         /*
  208.          * List of comments to display:
  209.          */
  210.         $CommentList new CommentList$Blog"'comment','trackback'"$show_statuses'',    '',    'DESC',    '',    20 );
  211.         break;
  212.  
  213.  
  214.     default:
  215.         debug_die'unhandled action 2' );
  216. }
  217.  
  218.  
  219. /*
  220.  * Page navigation:
  221.  */
  222.  
  223. $AdminUI->set_path'items''comments' );
  224.  
  225. // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
  226. $AdminUI->disp_html_head();
  227.  
  228. // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
  229. $AdminUI->disp_body_top();
  230.  
  231. /**
  232.  * Display payload:
  233.  */
  234. switch$action )
  235. {
  236.     case 'nil':
  237.         // Do nothing
  238.         break;
  239.  
  240.  
  241.     case 'edit':
  242.     case 'update':    // on error
  243.         // Begin payload block:
  244.         $AdminUI->disp_payload_begin();
  245.  
  246.         // Display VIEW:
  247.         $AdminUI->disp_view'comments/views/_comment.form.php' );
  248.  
  249.  
  250.         // End payload block:
  251.         $AdminUI->disp_payload_end();
  252.         break;
  253.  
  254.  
  255.     case 'list':
  256.     default:
  257.         // Begin payload block:
  258.         $AdminUI->disp_payload_begin();
  259.  
  260.         // Display VIEW:
  261.         $AdminUI->disp_view'comments/views/_browse_comments.view.php' );
  262.  
  263.         // End payload block:
  264.         $AdminUI->disp_payload_end();
  265.         break;
  266. }
  267.  
  268. // Display body bottom, debug info and close </html>:
  269. $AdminUI->disp_global_footer();
  270.  
  271.  
  272. ?>