NewsNewsFeaturesDownloadsDevelopmentSupportForumDocumentsAbout Us

adminaddlinkaction.class.php

查看本檔案說明文件.
00001 <?php
00002 
00003     include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
00004     include_once( PLOG_CLASS_PATH."class/dao/mylinks.class.php" );
00005     include_once( PLOG_CLASS_PATH."class/dao/mylink.class.php" );
00006     include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00007     include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00008     include_once( PLOG_CLASS_PATH."class/data/validator/httpurlvalidator.class.php" );
00009     include_once( PLOG_CLASS_PATH."class/data/validator/emptyvalidator.class.php" );    
00010     include_once( PLOG_CLASS_PATH."class/view/admin/adminnewlinkview.class.php" );
00011     include_once( PLOG_CLASS_PATH."class/view/admin/adminlinkslistview.class.php" );
00012 
00019     class AdminAddLinkAction extends AdminAction 
00020     {
00021 
00022         var $_linkName;
00023         var $_linkUrl;
00024         var $_linkDescription;
00025         var $_linkCategoryId;
00026         var $_properties;
00027 
00032         function AdminAddLinkAction( $actionInfo, $request )
00033         {
00034             $this->AdminAction( $actionInfo, $request );
00035             
00036             // data validation
00037             $this->registerFieldValidator( "linkName", new StringValidator());
00038             $this->registerFieldValidator( "linkUrl", new HttpUrlValidator());
00039             // linkRssFeed will only be validated if it is available in the form
00040             $this->registerFieldValidator( "linkRssFeed", new HttpUrlValidator(), true );
00041             $this->registerFieldValidator( "linkCategoryId", new IntegerValidator());
00042             $this->registerFieldValidator( "linkDescription", new EmptyValidator());
00043             $view = new AdminNewLinkView( $this->_blogInfo );
00044             $view->setErrorMessage( $this->_locale->tr("error_adding_link" ));
00045             $this->setValidationErrorView( $view );
00046         }
00047 
00051         function perform()
00052         {
00053             // fetch the data
00054             $this->_linkName = Textfilter::filterAllHTML($this->_request->getValue( "linkName" ));
00055             $this->_linkUrl  = Textfilter::filterAllHTML($this->_request->getValue( "linkUrl" ));
00056             $this->_linkCategoryId = $this->_request->getValue( "linkCategoryId" );
00057             $this->_linkDescription = Textfilter::filterAllHTML($this->_request->getValue( "linkDescription" ));
00058             $this->_linkRss = Textfilter::filterAllHTML($this->_request->getValue( "linkRssFeed" ));
00059             $this->_properties = Array();
00060             
00061             // adds the new link to the database
00062             $myLinks = new MyLinks();
00063             $myLink  = new MyLink( $this->_linkName, $this->_linkDescription, $this->_linkUrl, 
00064                                    $this->_blogInfo->getId(), $this->_linkCategoryId, 
00065                                    0, $this->_linkRss, $this->_properties );
00066             $this->notifyEvent( EVENT_PRE_LINK_ADD, Array( "link" => &$link ));
00067             if( !$myLinks->addMyLink( $myLink, $this->_blogInfo->getId())) {
00068                 $this->_view = new AdminNewLinkView( $this->_blogInfo );
00069                 $this->_view->setErrorMessage( $this->_locale->tr("error_adding_link"));
00070                 $this->setCommonData();
00071 
00072                 return false;
00073             }
00074             $this->notifyEvent( EVENT_POST_LINK_ADD, Array( "link" => &$link ));            
00075 
00076             $this->_view = new AdminLinksListView( $this->_blogInfo );
00077             $this->_view->setSuccessMessage( $this->_locale->pr("link_added_ok", $myLink->getName()));
00078             $this->setCommonData();
00079             
00080             // clear the cache
00081             CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );
00082 
00083             // better to return true if everything fine
00084             return true;
00085         }
00086     }
00087 ?>