Plog 1.0.1 > Class / Action / Addcommentaction.class.php

Questions? Need Help? Want to share? » PHP Forum
Script Name:
Plog 1.0.1

Download:
plog-1.0.1.zip

Category:
Blog

Archive Content:

Plog 1.0.1

Plog 1.0.1 > Class

Plog 1.0.1 > Class > Action

Plog 1.0.1 > Class > Action > Admin

Plog 1.0.1 > Class > Action

Plog 1.0.1 > Class > Bayesian

Plog 1.0.1 > Class > Config

Plog 1.0.1 > Class > Controller

Plog 1.0.1 > Class > Dao

Plog 1.0.1 > Class > Dao > Customfields

Plog 1.0.1 > Class > Dao

Plog 1.0.1 > Class > Dao > Status

Plog 1.0.1 > Class > Dao

Plog 1.0.1 > Class > Data

Plog 1.0.1 > Class > Data > Date

Plog 1.0.1 > Class > Data

Plog 1.0.1 > Class > Data > Forms

Plog 1.0.1 > Class > Data

Plog 1.0.1 > Class > Data > Pager

Plog 1.0.1 > Class > Data

Plog 1.0.1 > Class > Data > Validator

Plog 1.0.1 > Class > Data > Validator > Rules

Plog 1.0.1 > Class > Data > Validator

Plog 1.0.1 > Class > Database

Plog 1.0.1 > Class > Database > Adodb

Plog 1.0.1 > Class > Database > Adodb > Datadict

Plog 1.0.1 > Class > Database > Adodb > Docs

Plog 1.0.1 > Class > Database > Adodb > Drivers

Plog 1.0.1 > Class > Database > Adodb > Lang

Plog 1.0.1 > Class > Database > Adodb

Plog 1.0.1 > Class > Database > Adodb > Perf

Plog 1.0.1 > Class > Database > Adodb

Plog 1.0.1 > Class > Database

Plog 1.0.1 > Class

Plog 1.0.1 > Class > File

Plog 1.0.1 > Class > File > Finder

Plog 1.0.1 > Class > File > Unpacker

Plog 1.0.1 > Class > Gallery

Plog 1.0.1 > Class > Gallery > Dao

Plog 1.0.1 > Class > Gallery > Data

Plog 1.0.1 > Class > Gallery

Plog 1.0.1 > Class > Gallery > Getid3

Plog 1.0.1 > Class > Gallery > Helperapps

Plog 1.0.1 > Class > Gallery > Resizers

Plog 1.0.1 > Class > Gallery > Template

Plog 1.0.1 > Class > Locale

Plog 1.0.1 > Class > Logger

Plog 1.0.1 > Class > Logger > Appender

Plog 1.0.1 > Class > Logger > Config

Plog 1.0.1 > Class > Logger > Layout

Plog 1.0.1 > Class > Logger > Logger

Plog 1.0.1 > Class > Logger

Plog 1.0.1 > Class > Mail

Plog 1.0.1 > Class > Mail > Phpmailer

Plog 1.0.1 > Class > Mail > Phpmailer > Language

Plog 1.0.1 > Class > Mail > Phpmailer

Plog 1.0.1 > Class > Misc

Plog 1.0.1 > Class > Net

Plog 1.0.1 > Class > Net > Http

Plog 1.0.1 > Class > Net > Http > Phpsniff

Plog 1.0.1 > Class > Net > Http > Session

Plog 1.0.1 > Class > Net > Http

Plog 1.0.1 > Class > Net

Plog 1.0.1 > Class > Net > Xmlrpc

Plog 1.0.1 > Class > Net

Plog 1.0.1 > Class > Object

Plog 1.0.1 > Class > Plugin

Plog 1.0.1 > Class > Security

Plog 1.0.1 > Class > Summary

Plog 1.0.1 > Class > Summary > Action

Plog 1.0.1 > Class > Summary > Dao

Plog 1.0.1 > Class > Summary > Data

Plog 1.0.1 > Class > Summary > Data > Validator

Plog 1.0.1 > Class > Summary > Mail

Plog 1.0.1 > Class > Summary > View

Plog 1.0.1 > Class > Template

Plog 1.0.1 > Class > Template > Menu

Plog 1.0.1 > Class > Template > Smarty

Plog 1.0.1 > Class > Template > Smarty > Core

Plog 1.0.1 > Class > Template > Smarty

Plog 1.0.1 > Class > Template > Smarty > Plugins

Plog 1.0.1 > Class > Template > Smarty

Plog 1.0.1 > Class > Template

Plog 1.0.1 > Class > Template > Templatesets

Plog 1.0.1 > Class > Template

Plog 1.0.1 > Class > View

Plog 1.0.1 > Class > View > Admin

Plog 1.0.1 > Class > View

Plog 1.0.1 > Class > Xml

Plog 1.0.1 > Class > Xml > Parser

Plog 1.0.1 > Class > Xml

Plog 1.0.1 > Class > Xml > Rssparser

Plog 1.0.1 > Class > Xml > Rssparser > Magpierss

Plog 1.0.1 > Class > Xml > Rssparser > Magpierss > Extlib

Plog 1.0.1 > Class > Xml > Rssparser > Magpierss

Plog 1.0.1 > Class > Xml > Rssparser

Plog 1.0.1 > Class > Xml > Tree

Plog 1.0.1 > Class > Xml

Plog 1.0.1

Plog 1.0.1 > Config

Plog 1.0.1

Plog 1.0.1 > Gallery

Plog 1.0.1

Plog 1.0.1 > Imgs

Plog 1.0.1 > Imgs > .xvpics

Plog 1.0.1 > Imgs > Admin

Plog 1.0.1 > Imgs

Plog 1.0.1

Plog 1.0.1 > Install

Plog 1.0.1 > Js

Plog 1.0.1 > Js > Calendar

Plog 1.0.1 > Js > Editor

Plog 1.0.1 > Js > Htmlarea

Plog 1.0.1 > Js > Htmlarea > Docs

Plog 1.0.1 > Js > Htmlarea

Plog 1.0.1 > Js > Htmlarea > Images

Plog 1.0.1 > Js > Htmlarea > Lang

Plog 1.0.1 > Js > Htmlarea > Plugins

Plog 1.0.1 > Js > Htmlarea > Plugins > CharacterMap

Plog 1.0.1 > Js > Htmlarea > Plugins > CharacterMap > Img

Plog 1.0.1 > Js > Htmlarea > Plugins > CharacterMap > Lang

Plog 1.0.1 > Js > Htmlarea > Plugins > CharacterMap > Popups

Plog 1.0.1 > Js > Htmlarea > Plugins > ContextMenu

Plog 1.0.1 > Js > Htmlarea > Plugins > ContextMenu > Lang

Plog 1.0.1 > Js > Htmlarea > Plugins > ContextMenu

Plog 1.0.1 > Js > Htmlarea > Plugins > CSS

Plog 1.0.1 > Js > Htmlarea > Plugins > CSS > Lang

Plog 1.0.1 > Js > Htmlarea > Plugins > DynamicCSS

Plog 1.0.1 > Js > Htmlarea > Plugins > DynamicCSS > Lang

Plog 1.0.1 > Js > Htmlarea > Plugins > EnterParagraphs

Plog 1.0.1 > Js > Htmlarea > Plugins > EnterParagraphs > Lang

Plog 1.0.1 > Js > Htmlarea > Plugins > FullPage

Plog 1.0.1 > Js > Htmlarea > Plugins > FullPage > Img

Plog 1.0.1 > Js > Htmlarea > Plugins > FullPage > Lang

Plog 1.0.1 > Js > Htmlarea > Plugins > FullPage > Popups

Plog 1.0.1 > Js > Htmlarea > Plugins > FullPage

Plog 1.0.1 > Js > Htmlarea > Plugins > InsertSmiley

Plog 1.0.1 > Js > Htmlarea > Plugins > InsertSmiley > Emoticons

Plog 1.0.1 > Js > Htmlarea > Plugins > InsertSmiley > Img

Plog 1.0.1 > Js > Htmlarea > Plugins > InsertSmiley

Plog 1.0.1 > Js > Htmlarea > Plugins > InsertSmiley > Lang

Plog 1.0.1 > Js > Htmlarea > Plugins > InsertSmiley > Popups

Plog 1.0.1 > Js > Htmlarea > Plugins > ListType

Plog 1.0.1 > Js > Htmlarea > Plugins > ListType > Lang

Plog 1.0.1 > Js > Htmlarea > Plugins > ListType

Plog 1.0.1 > Js > Htmlarea > Plugins

Plog 1.0.1 > Js > Htmlarea > Plugins > TableOperations

Plog 1.0.1 > Js > Htmlarea > Plugins > TableOperations > Img

Plog 1.0.1 > Js > Htmlarea > Plugins > TableOperations > Lang

Plog 1.0.1 > Js > Htmlarea > Plugins > TableOperations

Plog 1.0.1 > Js > Htmlarea

Plog 1.0.1 > Js > Htmlarea > Popups

Plog 1.0.1 > Js > Htmlarea

Plog 1.0.1 > Js > Ie7

Plog 1.0.1 > Js > Ie7 > Src

Plog 1.0.1 > Js

Plog 1.0.1 > Js > Ui

Plog 1.0.1

Plog 1.0.1 > Locale

Plog 1.0.1 > Locale > Unsupport

Plog 1.0.1 > Plugins

Plog 1.0.1

Plog 1.0.1 > Styles

Plog 1.0.1

Plog 1.0.1 > Templates

Plog 1.0.1 > Templates > Admin

Plog 1.0.1 > Templates > Admin > Xml

Plog 1.0.1 > Templates > Blueish

Plog 1.0.1 > Templates > Grey

Plog 1.0.1 > Templates > Misc

Plog 1.0.1 > Templates > Rss

Plog 1.0.1 > Templates > Standard

Plog 1.0.1 > Templates > Standard > Imgs

Plog 1.0.1 > Templates > Standard

Plog 1.0.1 > Templates > Summary

Plog 1.0.1 > Templates > Summary > Rss

Plog 1.0.1 > Templates > Summary

Plog 1.0.1 > Templates > Wizard

Plog 1.0.1 > Tmp

Plog 1.0.1

Addcommentaction.class.php:


<?php

    
include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/dao/users.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/dao/articles.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/data/validator/emailvalidator.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/net/client.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/data/textfilter.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/view/errorview.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );

    
/**
     * \ingroup Action
     * @private
     *
     * Takes care of validating the form to add new comments to an article
     */
    
class AddCommentAction extends BlogAction 
    
{

        var 
$_articleId;
        var 
$_blogId;
        var 
$_opId;
        var 
$_userName;
        var 
$_userEmail;
        var 
$_userUrl;
        var 
$_commentText;
        var 
$_commentTopic;
        var 
$_parentId;


        
/**
         * Constructor
         */
        
function AddCommentAction$blogInfo,  $request )
        {
            
$this->BlogAction$blogInfo,  $request );
            
            
// change the validation mode of the form
            
$this->registerFieldValidator"articleId",  new IntegerValidator());
            
$this->_form->setFieldErrorMessage"articleId",  $this->_locale->tr("error_incorrect_article_id" ));
            
$this->registerFieldValidator"blogId",  new IntegerValidator());
            
$this->_form->setFieldErrorMessage"blogId",  $this->_locale->tr("error_incorrect_blog_id" ));
            
$this->registerFieldValidator"parentId",  new IntegerValidator(),  true );
            
$this->_form->setFieldErrorMessage"parentId",  $this->_locale->tr("error_incorrect_article_id" ));
            
$this->registerFieldValidator"userEmail",  new EmailValidator(),  true );
            
$this->_form->setFieldErrorMessage"userEmail",  $this->_locale->tr("error_incorrect_email_address" ));
            
$this->registerFieldValidator"userName",  new StringValidator());
            
$this->_form->setFieldErrorMessage"userName",  $this->_locale->tr("error_comment_without_name" ));
            
$this->registerFieldValidator"commentText",  new StringValidator());
            
$this->_form->setFieldErrorMessage"commentText",  $this->_locale->tr("error_comment_without_text" ));
            
$view = new ErrorView$this->_blogInfo );
            
$view->setErrorMessage"There has been an error validating the data!" );
            
$this->setValidationErrorView$view );

            
$this->_fetchFields();
        }

        function 
_fetchFields()
        {
            
$this->_articleId $this->_request->getValue"articleId" );
            
$this->_blogId    $this->_request->getValue"blogId" );
            
$this->_opId      $this->_request->getValue"op" );
            
$this->_parentId  $this->_request->getValue"parentId" );
            if( 
$this->_parentId == null || $this->_parentId == "" )
                
$this->_parentId 0;
            
$this->_userEmail trim($this->_request->getValue"userEmail" ));
            
$this->_userUrl   trim($this->_request->getValue"userUrl" ));
            if( (
strlen($this->_userUrl) != 0) &&
                  (
substr($this->_userUrl,  0,  ) != "http://" )){
                
$this->_userUrl "http://".$this->_userUrl;
            }
            
$this->_userName  trim($this->_request->getValue"userName" ));
            
$this->_commentText trim($this->_request->getValue"commentText" ));
            
$this->_commentTopic trim($this->_request->getValue"commentTopic" ));
            
// remove all straneous stuff from the text and topic
            
$tf = new TextFilter();
            
$this->_commentTopic $tf->xhtmlize($tf->filterHTML$this->_commentTopic ));
            
// and also from the text
            
$this->_commentText $tf->xhtmlize($tf->filterHTML$this->_commentText ));
            
// now,  if the option is set,  we 'beautify' the text typed by users
            
if( $this->_config->getValue"beautify_comments_text" )) {
                
$this->_commentText $tf->autop($this->_commentText);
            }
        }

        
/**
         * Since this function contains this method,  the controller will automatically
         * call it before calling perform()
         *
         * @return True if all fields ok or false otherwise.
         */
        
function validate()
        {
            
// check if comments are enabled
            
$blogSettings $this->_blogInfo->getSettings();
            if( !
$blogSettings->getValue"comments_enabled" )) {
                
$this->_view = new ErrorView$this->_blogInfo,  "error_comments_not_enabled" );
                
$this->setCommonData();

                return 
false;
            }
            
            return( 
parent::validate());
        }
        
        
/**
         * prepare a nicer error message. This method is only going to be executed whenver a validation
         * error happens (see Action::validate())
         *
         * @see Action::validate()
         */
        
function validationErrorProcessing()
        {
            
// collect all the errors from all the fields and for those that failed validation,
            // put them in a nicer string.
            
$results $this->_form->getFormValidationResults();
            foreach( 
$results as $field => $result ) {
                if( !
$result ) {
                    
$errorMessage .= $this->_form->getFieldErrorMessage$field )."<br/><br/>";
                }
            }
            
            
$this->_view->setErrorMessage$errorMessage );
            
            return 
true;
        }

        
/**
         * Carries out the action
         */
        
function perform()
        {
            
// need to check the ip of the client
            
$clientIp Client::getIp();

            
// fetch the same article again so that we can have all the comments from
            // the database,  plus this last one
            
$articles = new Articles();
            
$article  $articles->getBlogArticle$this->_articleId,  $this->_blogInfo->getId());

            
// check if the user wanted to receive comments for this article
            // or not...
            
if( $article->getCommentsEnabled() == false ) {
                 
$this->_view = new ErrorView$this->_blogInfo );
                 
$this->_view->setValue"message",  "Comments have been disabled for this article." );
                 
$this->setCommonData();
                 return 
false;
            }
            
            
$this->notifyEventEVENT_POST_LOADED,  Array( "article" => &$article ));

            
// we have already checked all the data,  so we are sure that everything's in place
            
$comments = new ArticleComments();
            
            
$comment = new UserComment$this->_articleId,  $this->_parentId,  $this->_commentTopic,  $this->_commentText,
                                        
null,  $this->_userName,  $this->_userEmail,  $this->_userUrl,
                                        
$clientIp );            

            
// check if there is already a comment with the same text,  topic and made from the same
            // IP already in the database because if so,  then we will not add the comment that
            // the user is trying to add (a reload button mistake,  perhaps?)
            
if( !$comments->getIdenticalComment$this->_commentTopic,  $this->_commentText,
                                                 
$this->_articleId,  $this->_parentId,
                                                 
$this->_userName,  $this->_userEmail,
                                                 
$this->_userUrl,  $clientIp )) {
                                                 
                
// fire an event
                
$this->notifyEventEVENT_PRE_COMMENT_ADD,  Array( "comment" => &$comment ));
                                                 
                if( !
$comments->addComment$comment )) {
                    
// show an error message if problems
                    
$this->_view = new ErrorView$this->_blogInfo );
                    
$this->_view->setValue"message",  "error_adding_comment" );
                    
$this->setCommonData();
                    return 
false;
                }
            }
            
            
// finally,  check if there was any user who wanted to be notified of new comments
            // to this post...
            
$notifier = new ArticleNotifications();
            
$notifier->notifyUsers$article->getId(),  $this->_blogInfo);
            
            
// fire the post event...
            
$this->notifyEventEVENT_POST_COMMENT_ADD,  Array( "comment" => &$comment ));

            
//
            // clear caches. This should be done in a more granular way,  because right now
            // we're either removing *all* of them or none. I guess we should only remove the 
            // cache whose identifier corresponds with the blog and article that we just removed,  
            // but let's leave it as it is for the time being...
            //
            
CacheControl::resetBlogCache$this->_blogInfo->getId());
            
            
// clean up the request,  there's a parameter called 'userName' also used by
            // ViewArticleAction but that doesn't have the same meaning so we better remove it
            // before it's too late! We also need to add a new request commentUserName to replace
            // original userName,  in case developer need it in filter or event plugin.
            
$request HttpVars::getRequest();
            
$request["commentUserName"] = $request["userName"];
            
$request["userName"] = "";
            
HttpVars::setRequest$request );                     
                        
            
// forward the action to ViewArticleAction
            
return BlogController::setForwardAction"ViewArticle" );
        }
    }
?>



Other Blog Scripts:

WebMaster Resources Home

©RingsWorld.com