Exemplo n.º 1
0
	public function indexAction() {
		$this->getView()
			->setValues(array(
				'title' => 'User'
			))
			->addCss('/js/ext-4.0.2a/resources/css/ext-all.css')
			->addJs('/js/ext-4.0.2a/ext-all.js')
			->addJs('/js/redokes/redokes.js');
		
		if (User_Model_User::isLoggedIn()) {
			echo 'is logged in';
		}
		else {
			$this->setView('login');
			echo 'is not logged in';
		}
	}
Exemplo n.º 2
0
 public function indexAction()
 {
     $envConf = Zend_Registry::get('environmentSettings');
     $req = $this->getRequest();
     $id = $req->getParam('id');
     $title = $req->getParam('title');
     $this->view->news = false;
     $this->view->paginator = false;
     $this->view->writeForm = new News_Form_Comment('#');
     if ($id) {
         $this->view->news = News_Model_News::getNewsById($id);
     } else {
         if ($title) {
             $this->view->news = News_Model_News::getNewsBySlug(urldecode($title));
         }
     }
     if ($this->view->news) {
         $paginator = $this->view->news->getCommentPaginator(false, true);
         $page = $req->getParam('page');
         $paginator->setItemCountPerPage($this->conf->news->comments->numpage);
         $paginator->setCurrentPageNumber($page);
         $this->view->paginator = $paginator;
     }
     if ($req->isPost() && $this->view->news) {
         if ($this->view->writeForm->isValid($_POST)) {
             $values = $this->view->writeForm->getValues();
             $nc = new News_Model_Comment();
             $nc->ip = getenv('REMOTE_ADDR');
             $nc->email = User_Model_User::isLoggedIn() ? Zend_Auth::getInstance()->getIdentity()->email : $values['email'];
             $nc->news_id = $this->view->news->id;
             $nc->visible = 'yes';
             // there is no moderation yet
             $nc->author = User_Model_User::isLoggedIn() ? Zend_Auth::getInstance()->getIdentity()->name : $values['author'];
             $nc->url = $values['url'];
             $nc->comment = $values['comment'];
             $nc->checkSpam();
             $nc->save();
             $this->view->writeForm = new News_Form_Comment('#');
             // clear form because comment is submitted
         }
     }
 }
Exemplo n.º 3
0
 public function __construct($action, $options = null)
 {
     parent::__construct($options);
     $this->setName('postcomment')->setAction($action)->setMethod('post')->setAttrib('id', 'postcomment');
     # author
     $authorValidatorDB = new FansubCMS_Validator_NoRecordExists('User_Model_User', 'name');
     $authorValidatorDB->setMessages(array(FansubCMS_Validator_NoRecordExists::RECORD_EXISTS => 'news_comment_form_error_author_user_exists'));
     $author = $this->createElement('text', 'author');
     $author->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty', true, array('messages' => array(Zend_Validate_NotEmpty::IS_EMPTY => 'default_form_error_empty_value')))->addValidator('stringLength', true, array('min' => 3, 'max' => 32, 'messages' => array(Zend_Validate_StringLength::TOO_LONG => 'news_comment_form_error_author_length', Zend_Validate_StringLength::TOO_SHORT => 'news_comment_form_error_author_length')))->addValidator($authorValidatorDB)->setRequired(true)->setLabel('news_comment_field_author');
     # email
     $email = $this->createElement('text', 'email');
     $email->addValidator('NotEmpty', true, array('messages' => array(Zend_Validate_NotEmpty::IS_EMPTY => 'default_form_error_empty_value')))->addFilter('StripTags')->addFilter('StringTrim')->addValidator('EmailAddress', false, array('allow' => Zend_Validate_Hostname::ALLOW_DNS, 'domain' => true, 'messages' => array(Zend_Validate_EmailAddress::DOT_ATOM => 'default_form_error_email', Zend_Validate_EmailAddress::INVALID_FORMAT => 'default_form_error_email', Zend_Validate_EmailAddress::INVALID_HOSTNAME => 'default_form_error_email', Zend_Validate_EmailAddress::INVALID_LOCAL_PART => 'default_form_error_email', Zend_Validate_EmailAddress::INVALID_MX_RECORD => 'default_form_error_email', Zend_Validate_EmailAddress::INVALID_SEGMENT => 'default_form_error_email', Zend_Validate_EmailAddress::LENGTH_EXCEEDED => 'default_form_error_email', Zend_Validate_EmailAddress::QUOTED_STRING => 'default_form_error_email')))->setRequired(true)->setLabel('news_comment_field_email');
     # url
     $url = $this->createElement('text', 'url');
     $url->setRequired(false)->addFilter('StripTags')->addFilter('StringTrim')->setLabel('news_comment_field_website');
     # comment
     $comment = $this->createElement('Textarea', 'comment');
     $comment->setRequired(true)->addFilter('StringTrim')->addValidator('NotEmpty', true, array('messages' => array(Zend_Validate_NotEmpty::IS_EMPTY => 'default_form_error_empty_value')))->setAttrib('rows', 15)->setAttrib('cols', 40)->setLabel('news_comment_field_text');
     #captcha
     if (!User_Model_User::isLoggedIn()) {
         $imgUrl = substr($_SERVER['PHP_SELF'], 0, -9) . '/media/common/images/tmp';
         // little hack to have the correct baseurl
         $imgUrl = str_replace('//', '/', $imgUrl);
         $captcha = new Zend_Form_Element_Captcha('captcha', array('label' => 'captcha', 'captcha' => array('captcha' => 'Image', 'wordLen' => 6, 'timeout' => 300, 'height' => 80, 'width' => 150, 'startImage' => null, 'font' => realpath(APPLICATION_PATH . '/data/ttf') . '/captcha.ttf', 'imgurl' => $imgUrl, 'imgDir' => HTTP_PATH . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tmp'), 'errorMessages' => array('default_form_error_captcha_wrong')));
         $captcha->setRequired(true);
     }
     # add elements to the form
     if (!User_Model_User::isLoggedIn()) {
         $this->addElement($author)->addElement($email);
     }
     $this->addElement($url)->addElement($comment);
     if (!User_Model_User::isLoggedIn()) {
         $this->addElement($captcha);
     }
     # commit button
     $this->addElement('submit', 'submit', array('label' => 'news_comment_field_submit', 'class' => 'button'));
 }