liberty
[ class tree: liberty ] [ index: liberty ] [ all elements ]

Source for file ajax_comments.php

Documentation is available at ajax_comments.php

  1. <?php
  2. /**
  3.  * @version $Header$
  4.  * @package liberty
  5.  * @subpackage functions
  6.  */
  7.  
  8. /**
  9.  * required setup
  10.  */
  11. require_once( '../kernel/setup_inc.php' );
  12.  
  13. $staticContent = new LibertyContent();
  14. $gContent = LibertyBase::getLibertyObject( $_REQUEST['parent_id'], ( !empty( $_REQUEST['parent_guid'] ) ? $_REQUEST['parent_guid'] : NULL ));
  15. $XMLContent = "";
  16.  
  17. if( !$gContent->hasUserPermission( 'p_liberty_post_comments', TRUE, TRUE)) {
  18.     $statusCode = 401;
  19.     $XMLContent = tra( "You do not have the required permissions to post new comments" );
  20. } elseif( $gContent->isCommentable() ) {
  21.     /**
  22.      * If we are receiving ajax comments request make sure our results also
  23.      * know we are using ajax comments. This is an insurance measure that if
  24.      * the originating content forced on ajax comments (even if off system
  25.      * wide) that the return results continue to use ajax comments. Don't take
  26.      * this out under penalty of death.
  27.      */
  28.     $gBitSystem->setConfig( 'comments_ajax', 'y' );
  29.  
  30.     $commentsParentId = $_REQUEST['parent_id'];
  31.     $comments_return_url = $_REQUEST['comments_return_url'];
  32.     include_once( LIBERTY_PKG_PATH.'comments_inc.php' );
  33.  
  34.     if( isset( $_REQUEST['post_comment_submit'] )) {
  35.         if ($storeComment->loadComment()){
  36.             $statusCode = 200;
  37.             $postComment = $storeComment->mInfo;
  38.             $postComment['parsed_data'] = $storeComment->parseData( $postComment );
  39.         } else {
  40.             //if store is requested but it fails for some reason - like captcha mismatch
  41.             $statusCode = 400;
  42.         }
  43.     } else {
  44.         //we assume preview request which we return as ok - our js callback knows what to do when preview is requested
  45.         $statusCode = 200;
  46.     }
  47.  
  48.     $gBitSmarty->assign( 'comment', $postComment );
  49.     $gBitSmarty->assign( 'commentsParentId', $commentsParentId );
  50.     if( !empty( $formfeedback )){
  51.         $statusCode = 400;
  52.         $gBitSmarty->loadPlugin( 'smarty_modifier_formfeedback' );
  53.         $XMLContent = smarty_function_formfeedback( $formfeedback, $gBitSmarty );
  54.     }
  55.     $XMLContent .= $gBitSmarty->fetch( 'bitpackage:liberty/display_comment.tpl' );
  56. } else {
  57.     $statusCode = 405;
  58.     $XMLContent = tra( "Sorry, you can not post a comment here." );
  59. }
  60.  
  61. // We return XML with a status code
  62. $mRet = "<req><status><code>".$statusCode."</code></status>"
  63.     ."<content><![CDATA[".$XMLContent."]]></content></req>";
  64.  
  65. // Since we are returning xml we must report so in the header
  66. // we also need to tell the browser not to cache the page
  67. // see: http://mapki.com/index.php?title=Dynamic_XML
  68. // Date in the past
  69. header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
  70. // always modified
  71. header( "Last-Modified: ".gmdate( "D, d M Y H:i:s" )." GMT" );
  72. // HTTP/1.1
  73. header( "Cache-Control: no-store, no-cache, must-revalidate" );
  74. header( "Cache-Control: post-check=0, pre-check=0", FALSE );
  75. // HTTP/1.0
  76. header( "Pragma: no-cache" );
  77. //XML Header
  78. header( "content-type:text/xml" );
  79.  
  80. print_r( '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>' );
  81. print_r( $mRet );
  82.  
  83. die;
  84. ?>

Documentation generated on Wed, 29 Jul 2015 13:55:33 +0000 by phpDocumentor 1.5.0-lsces