Пример #1
0
 public function viewAction()
 {
     $id = $this->_request->getParam('id');
     $captchaCode = $this->_request->getParam('captcha_code');
     $modelBlog = new Page();
     $blog = $modelBlog->getPage($id);
     if ($blog) {
         $this->view->blog = $blog;
         // tags
         $modelTags = new Tags();
         $where = array('blog_id' => $id);
         $tags = $modelTags->getTags($where);
         if ($tags) {
             $this->view->tags = $tags;
         }
         // 评论
         $modelComment = new Comment();
         $comments = $modelComment->getComments($id);
         $this->view->comments = $comments;
         $dataComment = $this->_request->getPost();
         // 获取表单提交值
         if ($dataComment) {
             if ($dataComment['captcha'] == $captchaCode) {
                 // 定义过滤规则
                 $filters = array('name' => array('StringTrim'), 'comment' => 'StripTags');
                 // 定义验证规则
                 $validators = array('name' => array(array('StringLength', 3, 16), 'NotEmpty', Zend_Filter_Input::MESSAGES => array(array(Zend_Validate_StringLength::INVALID => "请输入一个合法的字符串", Zend_Validate_StringLength::TOO_SHORT => "请输入字符长度为3-16", Zend_Validate_StringLength::TOO_LONG => "请输入字符长度为3-16"))), 'email' => array('EmailAddress', Zend_Filter_Input::MESSAGES => array(array(Zend_Validate_EmailAddress::INVALID_FORMAT => "邮件格式不正确,请重新输入。"))), 'comment' => array());
                 // 实例化过滤器并进行过滤验证
                 $data = $_POST;
                 $filterPost = new Zend_Filter_Input($filters, $validators, $data);
                 if ($filterPost->hasInvalid() || $filterPost->hasMissing()) {
                     $messages = $filterPost->getMessages();
                     foreach ($messages as $message) {
                         foreach ($message as $value) {
                             echo $value . "<br />";
                         }
                     }
                 }
                 // 将经过验证的数据写入数据库
                 $modelComment = new Comment();
                 $newComment = $modelComment->createComment($pid = $id, $filterPost->name, $filterPost->email, $filterPost->comment);
                 if ($newComment) {
                     $this->_redirect('/blog/view/id/' . $id);
                 } else {
                     echo "评论提交出错!";
                 }
             } else {
                 echo "验证码错误,请刷新后重新输入。";
             }
         }
         // 生成验证码
         $this->captcha_session = new Zend_Session_Namespace('captcha');
         //在默认构造函数里实例化
         $captcha = new Zend_Captcha_Image(array('font' => 'images/SIMYOU.TTF', 'session' => $this->captcha_session, 'fontsize' => 15, 'imgdir' => 'images/code/', 'width' => 120, 'height' => 30, 'gcFreq' => 3, 'dotNoiseLevel' => 5, 'lineNoiseLevel' => 1, 'wordlen' => 4));
         $captcha->generate();
         // 生成图片
         // 界面方式
         $this->view->img_dir = $captcha->getImgDir();
         $this->view->captcha_id = $captcha->getId();
         //图片文件名,md5编码
         $this->view->captcha_code = $captcha->getWord();
         $this->view->id = $id;
     } else {
         echo "该博客文章不存在!";
     }
 }
Пример #2
0
	private function getForm($type='blog', $edit=false, $item=false) {
		$source		= StuffpressModel::forUser($this->_application->user->id);
		$item_id   = $item ? $item->getID() : 0;
		$source_id = $item ? $item->getSource() : $source->getID();
		$date      = $item ? $item->getTimestamp() : false;
		
		// Crappy code !! TODO
		$lat  	  	= $item ? $item->getLatitude() : false;
		$lon  	  	= $item ? $item->getLongitude() : false;
		
		// get the tags if any
		if ($item && $item->getTagCount()>0) {
			$tags_table = new Tags();
			$tags 		= $tags_table->getTags($source_id, $item_id);
			$strings 	= array();
			foreach($tags as $tag) {
				$strings[] = $tag['tag']; 
			}
			$tags = implode(', ', $strings);
		} else {
			$tags = false;
		}
		
		if ($type == SourceItem::STATUS_TYPE) {
			$status = $item ? $item->getStatus() : '';
			$form = $this->getFormStatus($source_id,$item_id, $status, $date, $edit, $tags, $lat, $lon);
		} elseif ($type == SourceItem::BLOG_TYPE) {
			$title = $item ? $item->getTitle() : '';
			$text  = $item ? $item->getContent() : '';
			$form = $this->getFormText($source_id,$item_id, $title, $text, $date, $edit, $tags, $lat, $lon);
		} elseif ($type == SourceItem::LINK_TYPE) {
			$title = $item ? $item->getTitle() : '';
			$link  = $item ? $item->getLink() : '';
			$desc  = $item ? $item->getDescription() : '';
			$form  = $this->getFormLink($source_id, $item_id, $link, $title, $desc, $date, $edit, $tags, $lat, $lon);
		} elseif ($type == SourceItem::IMAGE_TYPE) {
			$title = $item ? $item->getTitle() : '';
			$desc  = $item ? $item->getDescription() : '';
			$form = $this->getFormImage($source_id, $item_id, $title, $desc, $date, $edit, $tags, $lat, $lon);
		} elseif ($type == SourceItem::AUDIO_TYPE) {
			$title = $item ? $item->getTitle() : '';
			$desc  = $item ? $item->getDescription() : '';
			$form  = $this->getFormAudio($source_id, $item_id, $title, $desc, $date, $edit, $tags, $lat, $lon);
		} elseif ($type == SourceItem::VIDEO_TYPE) {
			$title = $item ? $item->getTitle() : '';
			$desc  = $item ? $item->getDescription() : '';
			$embed = $item ? $item->getEmbedCode() : '';			
			$form = $this->getFormVideo($source_id, $item_id, $title, $desc, $embed, $date, $edit, $tags, $lat, $lon);
		}
		
		return $form;
	}
Пример #3
0
 public function updateAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $this->identity = $auth->getIdentity();
     }
     if (!$this->identity->id) {
         $this->_redirect('/user/login');
     }
     $id = $this->_request->getParam('id');
     $modelBlog = new Page();
     $formBlog = new Form_Source();
     if ($this->getRequest()->isPost()) {
         if ($formBlog->isValid($_POST)) {
             $blogData = $formBlog->getValues();
             $blogData['uid'] = $this->identity->id;
             $blogData['type'] = 'source';
             $blogData['createtime'] = time();
             $tags = str_replace(",", ",", $blogData['tags']);
             unset($blogData['tags']);
             unset($blogData['提交']);
             $updateBlog = $modelBlog->updatePage($id, $blogData);
             if ($updateBlog) {
                 $this->_redirect('source/view/id/' . $updateBlog);
             }
         }
     } else {
         $blog = $modelBlog->getPage($id);
         if ($this->identity->id != $blog->uid) {
             echo "你不是本博客的作者,不能对本博客进行编辑操作。";
             exit;
         }
         $arrBlog = $blog->toArray();
         // 该blog的tags
         $modelTags = new Tags();
         $where = array('blog_id' => $id);
         $tags = $modelTags->getTags($where);
         if (count($tags) > 0) {
             $strTags = '';
             foreach ($tags as $tag) {
                 $strTags .= $tag->tag . ",";
             }
             $strTags = rtrim($strTags, ",");
         }
         $arrBlog['tags'] = $strTags;
         $formBlog->populate($arrBlog);
     }
     $this->view->formBlog = $formBlog;
     //  $this->_helper->cache(array('index', 'view'), array('gook'));
 }
Пример #4
0
 public function getTags()
 {
     if ($this->getTagCount() == 0) {
         return false;
     }
     if (!$this->_tags) {
         $tags = new Tags();
         $this->_tags = $tags->getTags($this->getSource(), $this->getID());
     }
     return $this->_tags;
 }
Пример #5
0
 public function actionExportList($id)
 {
     $list = CActiveRecord::model('X2List')->findByPk($id);
     if (isset($list)) {
         if (!$this->checkPermissions($list, 'view')) {
             // check permissions
             throw new CHttpException(403, Yii::t('app', 'You do not have permission to modify this list.'));
         }
     } else {
         throw new CHttpException(404, Yii::t('app', 'The requested list does not exist.'));
     }
     $dataProvider = CActiveRecord::model('Contacts')->searchList($id);
     // get the list
     $totalItemCount = $dataProvider->getTotalItemCount();
     $dataProvider->pagination->itemCount = $totalItemCount;
     $dataProvider->pagination->pageSize = 1000;
     // process list in blocks of 1000
     $allFields = CActiveRecord::model('Contacts')->getFields(true);
     // get associative array of fields
     $gvSettings = ProfileChild::getGridviewSettings('contacts_list' . $id);
     $selectedColumns = array();
     $columns = array();
     if ($gvSettings === null) {
         $selectedColumns = array('firstName', 'lastName', 'phone', 'email', 'leadSource', 'createDate', 'lastUpdated');
     } else {
         $selectedColumns = array_keys($gvSettings);
     }
     foreach ($selectedColumns as &$colName) {
         if ($colName == 'tags') {
             $columns[$colName]['label'] = Yii::t('app', 'Tags');
             $columns[$colName]['type'] = 'tags';
         } elseif ($colName == 'name') {
             $columns[$colName]['label'] = Yii::t('contacts', 'Name');
             $columns[$colName]['type'] = 'name';
         } else {
             if (array_key_exists($colName, $allFields)) {
                 $columns[$colName]['label'] = $allFields[$colName]['attributeLabel'];
                 if (in_array($colName, array('annualRevenue', 'quoteAmount'))) {
                     $columns[$colName]['type'] = 'currency';
                 } else {
                     $columns[$colName]['type'] = $allFields[$colName]['type'];
                 }
                 $columns[$colName]['linkType'] = $allFields[$colName]['linkType'];
             }
         }
     }
     unset($colName);
     $fileName = 'list' . $id . '.csv';
     $fp = fopen($fileName, 'w+');
     // output column labels for the first line
     $columnLabels = array();
     foreach ($columns as $colName => &$field) {
         $columnLabels[] = $field['label'];
     }
     unset($field);
     fputcsv($fp, $columnLabels);
     for ($i = 0; $i < $dataProvider->pagination->pageCount; ++$i) {
         $dataProvider->pagination->currentPage = $i;
         $dataSet = $dataProvider->getData(true);
         foreach ($dataSet as &$model) {
             $row = array();
             foreach ($columns as $fieldName => &$field) {
                 if ($field['type'] == 'tags') {
                     $row[] = Tags::getTags('Contacts', $model->id, 10);
                 } elseif ($field['type'] == 'date') {
                     $row[] = date('Y-m-d H:i:s', $model->{$fieldName});
                 } elseif ($field['type'] == 'visibility') {
                     switch ($model->{$fieldName}) {
                         case '1':
                             $row[] = Yii::t('app', 'Public');
                             break;
                         case '0':
                             $row[] = Yii::t('app', 'Private');
                             break;
                         case '2':
                             $row[] = Yii::t('app', 'User\'s Groups');
                             break;
                     }
                 } elseif ($field['type'] == 'link') {
                     if (is_numeric($model->{$fieldName})) {
                         $className = ucfirst($field['linkType']);
                         if (class_exists($className)) {
                             $lookupModel = CActiveRecord::model($className)->findByPk($model->{$fieldName});
                             if (isset($lookupModel)) {
                                 $row[] = $lookupModel->name;
                             }
                         }
                     } else {
                         $row[] = $model->{$fieldName};
                     }
                 } elseif ($field['type'] == 'currency') {
                     if ($model instanceof Product) {
                         // products have their own currency
                         $row[] = Yii::app()->locale->numberFormatter->formatCurrency($model->{$fieldName}, $model->currency);
                     } elseif (!empty($model->{$fieldName})) {
                         $row[] = Yii::app()->locale->numberFormatter->formatCurrency($model->{$fieldName}, Yii::app()->params['currency']);
                     } else {
                         $row[] = '';
                     }
                 } elseif ($field['type'] == 'dropdown') {
                     $row[] = Yii::t(strtolower(Yii::app()->controller->id), $model->{$fieldName});
                 } else {
                     $row[] = $model->{$fieldName};
                 }
             }
             fputcsv($fp, $row);
         }
         unset($model);
     }
     fclose($fp);
     $file = Yii::app()->file->set($fileName);
     $file->download();
 }