public function __construct()
 {
     gateKeeper();
     $guid = getInput("guid");
     $title = getInput("blog_title");
     $description = getInput("description");
     $access_id = getInput("access_id");
     $container_guid = getInput("container_guid");
     $owner_guid = getLoggedInUserGuid();
     if ($guid) {
         $blog = getEntity($guid);
     } else {
         $blog = new Blog();
     }
     $blog->title = $title;
     $blog->description = $description;
     $blog->access_id = $access_id;
     $blog->owner_guid = $owner_guid;
     $blog->status = "published";
     $blog->container_guid = $container_guid;
     $blog->save();
     new Activity(getLoggedInUserGuid(), "blog:add", array(getLoggedInUser()->getURL(), getLoggedInUser()->full_name, $blog->getURL(), $blog->title, truncate($blog->description)), "", $access_id);
     new SystemMessage("Your blog has been published");
     forward("blogs/all_blogs");
 }
 public function addPost()
 {
     // let's setup some rules for our new data
     // I'm sure you can come up with better ones
     $rules = array('title' => 'required|min:3|max:128', 'content' => 'required', 'file' => 'mimes:jpg,gif,png');
     $pictrue = '';
     $title = Input::get('title');
     $content = Input::get('content');
     $description = Input::get('title');
     if (empty($description)) {
         $description = substr($content, 0, 120);
     }
     $author_id = Input::get('author_id');
     $tags = Input::get('tags');
     if (Input::hasFile('file')) {
         $file = Input::file('file');
         $ext = $file->guessClientExtension();
         $filename = $file->getClientOriginalName();
         $file->move(public_path() . '/data', md5(date('YmdHis') . $filename) . '.' . $ext);
         $pictrue = md5(date('YmdHis') . $filename) . '.' . $ext;
     }
     $new_blog = array('title' => $title, 'description' => $description, 'content' => $content, 'author_id' => $author_id, 'views' => 0, 'pictrue' => $pictrue, 'tags' => $tags);
     $v = Validator::make($new_blog, $rules);
     if ($v->fails()) {
         // redirect back to the form with
         // errors, input and our currently
         // logged in user
         return Redirect::to('blog/add')->with('user', Auth::user())->withErrors($v)->withInput();
     }
     // create the new post
     $blog = new Blog($new_blog);
     $blog->save();
     // redirect to viewing our new post
     return Redirect::to('blog/view/' . $blog->id);
 }
 public function __construct($data)
 {
     if (isset($data['session'])) {
         $guid = $data['guid'];
         $title = $data['blog_title'];
         $description = $data['description'];
         $access_id = $data['access_id'];
         $user = getUserFromSession($data['session']);
         if (!$guid) {
             $blog = new Blog();
             $blog->owner_guid = $user->guid;
             $blog->save();
         } else {
             $blog = getEntity($guid);
         }
         if ($blog->owner_guid == $user->guid) {
             $blog->title = $title;
             $blog->description = $description;
             $blog->access_id = $access_id;
             $blog->status = "draft";
             $guid = $blog->save();
             $blog = getEntity($guid);
             echo json_encode(array("guid" => $guid, "timeago" => display("output/friendly_time", array("timestamp" => $blog->last_updated))));
         }
     }
 }
Example #4
0
	/**
	 * @Acl allow blog-writer
	 * @Acl allow blog-admin
	*/
	public function save($title, $text, $tags)
	{
		$blog = new Blog($title, UserSession::get()->username, $text, CoOrg::getLanguage());
		$config = BlogConfig::get();
		$blog->commentsAllowed = $config->enableComments;
		if ($config->enableCommentsFor)
		{
			$blog->commentsCloseDate = time()+60*60*24*$config->enableCommentsFor;
		}
		$blog->tags = $tags;
		
		try
		{
			$blog->save();
		
			$this->notice(t('Your blog item is saved'));
			$year = date('Y', $blog->datePosted);
			$month = date('m', $blog->datePosted);
			$day = date('d', $blog->datePosted);
			$this->redirect('blog/show', $year, $month, $day, $blog->ID);
		}
		catch (ValidationException $e)
		{
			$this->blog = $blog;
			$this->error(t('Your blog item is not saved'));
			$this->render('create');
		}
	}
Example #5
0
 public function action_add()
 {
     $method = Request::method();
     if ($method == 'POST') {
         // let's setup some rules for our new data
         // I'm sure you can come up with better ones
         $rules = array('title' => 'required|min:3|max:128', 'content' => 'required', 'file' => 'mimes:jpg,gif,png');
         //
         //Input::upload('picture', 'path/to/pictures', 'filename.ext');
         //File::cpdir($directory, $destination);
         //File::rmdir($directory);
         //echo File::mime('gif'); // outputs 'image/gif'
         //if (File::is('jpg', 'path/to/file.jpg'))
         //{
         //File::extension('picture.png');File::delete('path/to/file');
         //File::append('path/to/file', 'appended file content');
         //}File::put('path/to/file', 'file contents');$contents = File::get('path/to/file');
         // make the validator
         // let's get the new post from the POST data
         // this is much safer than using mass assignment
         $image = Input::file();
         $pictrue = '';
         $title = Input::get('title');
         $content = Input::get('content');
         $description = Input::get('title');
         if (empty($description)) {
             $description = substr($content, 0, 120);
         }
         $author_id = Input::get('author_id');
         $tags = Input::get('tags');
         if (!empty($image['file']['name'])) {
             $ext = File::extension($image['file']['name']);
             //$image['file']['tmp_name']
             Input::upload('file', path('public') . 'data', md5(date('YmdHis') . $image['file']['name']) . '.' . $ext);
             $pictrue = md5(date('YmdHis') . $image['file']['name']) . '.' . $ext;
         }
         $new_blog = array('title' => $title, 'description' => $description, 'content' => $content, 'author_id' => $author_id, 'views' => 0, 'pictrue' => $pictrue, 'tags' => $tags);
         $v = Validator::make($new_blog, $rules);
         if ($v->fails()) {
             // redirect back to the form with
             // errors, input and our currently
             // logged in user
             return Redirect::to('blog/add')->with('user', Auth::user())->with_errors($v)->with_input();
         }
         // create the new post
         $blog = new Blog($new_blog);
         $blog->save();
         // redirect to viewing our new post
         return Redirect::to('blog/view/' . $blog->id);
     } else {
         // get the current user
         $user = Auth::user();
         // show the create post form, and send
         // the current user to identify the post author
         return View::make('blog.add')->with('user', $user);
     }
 }
Example #6
0
 /**
  * Создает новую модель блога.
  * Если создание прошло успешно - перенаправляет на просмотр.
  *
  * @return nothing
  **/
 public function actionCreate()
 {
     $model = new Blog();
     if (Yii::app()->getRequest()->getIsPostRequest() && Yii::app()->getRequest()->getPost('Blog') !== null) {
         $model->setAttributes(Yii::app()->getRequest()->getPost('Blog'));
         if ($model->save()) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('BlogModule.blog', 'Blog was added!'));
             $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', array('create')));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function register()
 {
     $blog = new Blog(_post('blog'));
     $blog->trim();
     if (!$blog->validate_register()) {
         $this->flash->add('message_error', $blog->errors->get_messages());
         $this->back();
     }
     $blog->user_id = User::get_login_id();
     $blog->save();
     $this->redirect_to('/blog/index');
 }
Example #8
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Blog();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Blog'])) {
         $model->attributes = $_POST['Blog'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #9
0
	public function translate($translator, $title, $text, $language)
	{
		$translation = new Blog($title, $translator, $text, $language, $this->datePosted);
		if (!$this->parentID)
		{
			$translation->parentID  = $this->ID;
			$translation->parentLanguage = $this->language;
		}
		else
		{
			$translation->parentID = $this->parentID;
			$translation->parentLanguage = $this->parentLanguage;
		}
		$translation->save();
		return $translation;
	}
Example #10
0
 public function store()
 {
     $datas = Input::all();
     $blog = new Blog();
     if ($datas['title']) {
         $blog->title = $datas['title'];
     } else {
         $blog->title = "Không tiêu đề";
     }
     $blog->content = $datas['content'];
     $blog->user_id = Session::get('user')['id'];
     $blog->privacy = $datas['privacy'];
     $blog->save();
     FEEntriesHelper::save($blog->id, FEEntriesHelper::getId("Blog"), $blog->user_id, $blog->privacy);
     return Redirect::back();
 }
Example #11
0
 public function executeAdd()
 {
     $this->redirectIf($this->getUser()->isAuthenticated(), 'ucp/index');
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         $blog = new Blog();
         $blog->setMid($this->getRequestParameter('mid'));
         $blog->setEmail($this->getRequestParameter('email'));
         $blog->setName($this->getRequestParameter('name'));
         $blog->setAuthor($this->getRequestParameter('author'));
         $blog->setUrl($this->getRequestParameter('url'));
         $blog->setFeed($this->getRequestParameter('feed'));
         $blog->setFile(substr(md5(rand()), 0, 16));
         $blog->save();
         $this->blog = $blog;
         return 'Done';
     }
     return $this->displayAddForm();
 }
Example #12
0
 /**
  * Register a new user
  *
  * @param Request $request
  * @param string $params
  * @return void
  */
 protected static function post($request, $params)
 {
     try {
         try {
             User::find(array('username' => $request->get('username')));
             static::response(array(), 409, 'User with this username already exists');
         } catch (Exception $e) {
             $user = new User(array('username' => $request->get('username'), 'password' => password_hash($request->get('password'), PASSWORD_BCRYPT), 'isAdmin' => false));
             $user->save();
             $blog = new Blog(array('userID' => $user->id, 'name' => $request->get('blogname')));
             $blog->save();
             $user->blog = $blog;
             static::response($user, 201);
         }
     } catch (Exception $e) {
         static::response(array(), 500, $e->getMessage());
     }
 }
Example #13
0
 /**
  * Stores the object in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      Connection $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave($con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aBlog !== null) {
             if ($this->aBlog->isModified()) {
                 $affectedRows += $this->aBlog->save($con);
             }
             $this->setBlog($this->aBlog);
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = PostPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += PostPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         if ($this->collPostTags !== null) {
             foreach ($this->collPostTags as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 private function edit(Blog $model)
 {
     if (isset($_POST['Blog']) && $_POST['Blog']) {
         $model->attributes = $_POST['Blog'];
         $image = CUploadedFile::getInstanceByName('upload');
         $imageModel = new BlogImage();
         $imageModel->image = $image;
         if ($imageModel->save()) {
             $model->featuredImage = $imageModel->id;
         }
         if ($model->save()) {
             /** @var CWebUser $user */
             $user = Yii::app()->user;
             $user->setFlash('blog-created', $model->isNewRecord ? 'Post succesfully created' : 'Post updated');
             $this->redirect(['blog/update', 'id' => $model->id, 'preview' => isset($_POST['preview'])]);
         }
     }
     $this->render('edit', compact('model'));
 }
 /**
  * Form for POST save the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function doSave()
 {
     $validator = Validator::make(Input::all(), Blog::$rules);
     if ($validator->passes()) {
         $id = Input::get('id');
         if (isset($id) && $id > 0) {
             $blog = Blog::find($id);
         } else {
             $blog = new Blog();
         }
         $blog->title = Input::get('title');
         $blog->description = Input::get('description');
         $blog->tags = Input::get('tags');
         $blog->user_id = Auth::user()->id;
         $blog->save();
         return Redirect::route('blog-list')->with('message', 'Blog was changed successfully.');
     } else {
         return Redirect::route('blog-edit')->with('message', 'The following errors occurred')->withErrors($validator)->withInput();
     }
 }
 /**
  * Store a newly created resource in storage.
  * POST /blogs
  *
  * @return Response
  */
 public function store()
 {
     $validator = Blog::validate(Input::only('topic', 'description'));
     if ($validator->fails()) {
         return Redirect::to('/create')->withErrors($validator)->withInput(Input::all());
     } else {
         $blog = new Blog();
         $blog->topic = Input::get('topic');
         $blog->tag_id = Input::get('tag_id');
         $author = Input::get('author');
         if ($author == "") {
             $author = "Taylor & Preston";
         }
         $blog->author = $author;
         $blog->description = Input::get('description');
         if ($blog->save()) {
             return Redirect::to('/blogs');
         }
     }
 }
Example #17
0
 public function executeNew(sfWebRequest $request)
 {
     // Display the form
     $this->form = new BlogForm();
     if ($this->getRequest()->isMethod('post')) {
         $this->form->bind($request->getParameter('blog'));
         if ($this->form->isValid()) {
             $blog = new Blog();
             $blog->setEmail($this->form->getValue('email'));
             $blog->setUrl($this->form->getValue('url'));
             $blog->setAdmin_hash(md5(time() . $this->form->getValue('url') . $this->form->getValue('email')));
             $blog->setPublic_hash(md5(time() . $this->form->getValue('email') . $this->form->getValue('url')));
             $blog->save();
             // Send mail with secret URL
             try {
                 // Create the mailer and message objects
                 //$mailer = new Swift(new Swift_Connection_NativeMail());
                 //$connection = new Swift_Connection_SMTP('smtp.free.fr');
                 $connection = new Swift_Connection_NativeMail();
                 $mailer = new Swift($connection);
                 $message = new Swift_Message('Welcome!');
                 // Render message parts
                 $mailContext = array('admin_hash' => $blog->getAdmin_hash(), 'blog_url' => $blog->getUrl());
                 $v = $this->getPartial('newBlogMailHtmlBody', $mailContext);
                 $htmlPart = new Swift_Message_Part($v, 'text/html');
                 $message->attach($htmlPart);
                 $message->attach(new Swift_Message_Part($this->getPartial('newBlogMailTextBody', $mailContext), 'text/plain'));
                 $mailTo = $blog->getEmail();
                 $mailFrom = sfConfig::get('app_mail_webmaster');
                 $mailer->send($message, $mailTo, $mailFrom);
                 $mailer->disconnect();
             } catch (Exception $e) {
                 $this->logMessage($e);
             }
             //redirect to the thank you page
             $this->redirect('blog/thankyou');
         }
     }
 }
	public function testIndexWithPager()
	{
		for ($i = 0; $i < 40; $i++)
		{
			$b = new Blog;
			$b->title = 'Some Title ' . $i;
			$b->authorID = 'nathan';
			$b->text = 'Some Random Content (4) <-- Its random';
			$b->language = 'en';
			$b->save();
		}
	
		$this->request('blog/index/3');
		$this->assertVarSet('blogs');
		$blogs = CoOrgSmarty::$vars['blogs'];
		$blogpager = CoOrgSmarty::$vars['blogpager'];
		$this->assertEquals(2, $blogpager->prev());
		$this->assertEquals(4, $blogpager->next());
		$this->assertEquals(2, count($blogpager->pages(2)));
		$this->assertEquals(10, count($blogs));
		$this->assertEquals('en', $blogs[0]->language);
		$this->assertRendered('latest');
	}
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //$proveedores_galeria = new Proveedor_galeria;
     //$proveedores_galeria->id=0;
     //$proveedores_galeria->proveedores_idproveedor=Input::get('idproveedor');
     //$fecha=''
     //$titulo=Input::get('titulo');
     //$idproveedor=Input::get('idproveedor');
     $authuser = Auth::user();
     if (!File::exists('images/blog/')) {
         $result = File::makeDirectory('images/blog/', 0777);
     }
     $rules = array('titulo' => 'required', 'contenido' => 'required', 'imagen' => 'required|mimes:png,gif,jpeg|max:200000000');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('administracion/blog/create')->withErrors($validator)->withInput();
     } else {
         $file = Input::file('imagen');
         $blog = new Blog();
         $id = Str::random(4);
         $date_now = new DateTime();
         $destinationPath = 'images/blog/';
         $filename = $date_now->format('YmdHis') . $id;
         $mime_type = $file->getMimeType();
         $extension = $file->getClientOriginalExtension();
         $upload_success = $file->move($destinationPath, $filename . '.' . $extension);
         $blog->fecha = $date_now;
         $blog->usuario = $authuser->id;
         $blog->titulo = Input::get('titulo');
         $blog->imagen = $filename . '.' . $extension;
         $blog->contenido = Input::get('contenido');
         $blog->save();
     }
     return Redirect::to("administracion/blog")->with(array('usuarioimg' => $authuser->imagen, 'usuarionombre' => $authuser->nombre, 'usuarioid' => $authuser->id));
     //
 }
Example #20
0
 public function postSaveReply($topic_id)
 {
     if (Auth::check()) {
         $cre = ['reply' => Input::get('reply')];
         $rules = ['reply' => 'required'];
         $validator = Validator::make($cre, $rules);
         if ($validator->passes()) {
             $blog = new Blog();
             $blog->user_id = Auth::id();
             $blog->topic_id = $topic_id;
             $blog->reply = Input::get('reply');
             $blog->save();
             return Redirect::Back()->with('success', 'gfhfhfh');
         } else {
             return Redirect::Back()->withErrors($validator)->withInput();
         }
     }
 }
Example #21
0
$user->save();
/* Create one service */
$twt = new Twitter();
$twt->user = $user;
$twt->rss = "http://twitter.com/statuses/user_timeline/crodas.rss";
$twt->save();
/* Create another service */
$blg = new Blog();
$blg->user = $user;
$blg->rss = "http://crodas.org/feed/rss";
$blg->save();
/* Create another service */
$blg1 = new Blog();
$blg1->user = $user;
$blg1->rss = "http://crodas.org/feed/rss";
$blg1->save();
/* Add references to the current user to its services */
$user->add_service($blg);
$user->add_service($blg1);
$user->add_service($twt);
$user->save();
/* Delete current objects */
unset($user, $blg, $blg1, $twt);
/* Output the document that is going to be sent to MongoDB */
$debug = TRUE;
$users = new User();
foreach ($users->where('username', 'crodas') as $user) {
    /* Load all references */
    $user->doDeferencing();
    /* Modify the first service */
    $user->services[0]->title = 'English Blog';
 public function actionWrite()
 {
     $label = new Article();
     $labels = $label->findAll('userid=:uid', array(':uid' => Yii::app()->session['uid']));
     //$labesArray是对应于id,label键值的一维数组
     $labesArray[0] = '--请选择--';
     foreach ($labels as $l) {
         $labesArray[$l->id] = $l->label;
     }
     $blog = Blog::model();
     if (isset($_POST['Blog'])) {
         $post = $_POST['Blog'];
         $post['view'] = 0;
         $post['time'] = time();
         $post['userid'] = Yii::app()->session['uid'];
         $blog->attributes = $post;
         if ($blog->validate()) {
             //$blog = Blog::model();
             if (!empty(Yii::app()->session['blogid'])) {
                 //根据blogid查询后更新数据
                 $blog = $blog->findByPk(Yii::app()->session['blogid']);
             } else {
                 //insert一条记录
                 $blog = new Blog();
                 $blog->userid = Yii::app()->session['uid'];
                 $blog->save(FALSE);
                 Yii::app()->session['blogid'] = $blog->attributes['id'];
             }
             /**
              * 处理图片
              * require_once 'UPimage/UPimage.php';		//图片缩略类
              * $resizeimage = new resizeimage("1.jpg", "320", "240", "1","2.jpg");
              */
             Yii::import('application.vendors.*');
             require_once 'Qiniu/io.php';
             //七牛上传类
             require_once 'Qiniu/rs.php';
             $images = "";
             //拼接图片以@方式
             if (CheckUploadFiles($_FILES['thumb'])) {
                 $file = $_FILES['thumb'];
                 $type = ".jpg";
                 $bucket = Yii::app()->params['bucket'];
                 $accessKey = Yii::app()->params['accessKey'];
                 $secretKey = Yii::app()->params['secretKey'];
                 foreach ($file['name'] as $key => $f) {
                     if (empty($file['name'][$key])) {
                         //为空循环下一次
                         continue;
                     }
                     if (ImageTypeCheck($file['name'][$key], $file['size'][$key])) {
                         $newname = time() . rand(10000, 99999) . $type;
                         Qiniu_SetKeys($accessKey, $secretKey);
                         $putPolicy = new Qiniu_RS_PutPolicy($bucket);
                         $upToken = $putPolicy->Token(null);
                         list($ret, $err) = Qiniu_Put($upToken, $newname, file_get_contents($file['tmp_name'][$key]), null);
                         if ($err === null) {
                             //成功
                             //$images .= "http://".Yii::app()->params['bucket'].".".Yii::app()->params['domain']."/".$newname."@";
                             $images .= $newname . "@";
                         } else {
                             //失败
                         }
                     }
                 }
             }
             $post['image'] = $images;
             $post['content'] = $_POST['content'];
             $blog->attributes = $post;
             if ($blog->save()) {
                 /**
                  * 注销blogid
                  */
                 Yii::app()->session['blogid'] = null;
                 Yii::app()->user->setFlash('sendblogsuccess', '发布文章成功 :)');
                 $this->redirect(array('articles'));
             }
         }
     }
     $data = array('labels' => $labesArray, 'blogModel' => $blog);
     $this->render('addarticle', $data);
 }
	private function postBlogs()
	{
		for ($i = 0; $i < 95; $i++)
		{
			$blog = new Blog;
			$blog->authorID = 'nathan';
			$blog->title = 'Ole Ola ' . $i;
			$blog->text = '...';
			$blog->language = 'en';
			$blog->save();
		}
	}
Example #24
0
 public static function getOrCreateByTag($tag, $user = null)
 {
     $blog = self::getByTag($tag);
     if (!$blog) {
         $blog = new Blog();
         $blog->setTag($tag);
         $blog->setName($tag);
         if ($user) {
             $blog->setUserId($user["id"]);
         } else {
             $blog->setUserId(1);
         }
         $blog->save();
     }
     return $blog;
 }
$t->is($service->getOption('fake_option', 'bar'), 'bar', '->getOption() on a nonexistent option returns the default value.');
$t->info('2 - Test shouldShowEditor()');
$service = new ioEditableContentService($context->getUser(), $dispatcher);
$t->is($service->shouldShowEditor(null, true), false, '->shouldShowEditor() returns false: no credential passed in, but we still require auth.');
$context->getUser()->setAuthenticated(true);
$t->is($service->shouldShowEditor(null, true), true, '->shouldShowEditor() returns true if no credential is passed to require.');
$service->setOption('admin_credential', 'test_edit_credential');
$t->is($service->shouldShowEditor(null, true), false, '->shouldShowEditor() returns false: the user does not have the credential');
$context->getUser()->addCredential('test_edit_credential');
$t->is($service->shouldShowEditor(null, true), true, '->shouldShowEditor() returns true: the user has the proper credential');
$t->info('3 - Test getContent()');
$service = new ioEditableContentService($context->getUser(), $dispatcher);
$blog = new Blog();
$blog->title = 'Unit test blog';
$blog->body = 'Lorem Ipsum';
$blog->save();
$t->info('  3.1 - Test a single-field, no partial rendering');
$result = $service->getContent($blog, array('title'));
$t->is($result, 'Unit test blog', '->getContent() returns the correct value');
$t->info('  3.2 - Test multiple fields, no partial - throws an exception');
try {
    $service->getContent($blog, array('title', 'body'), null, null);
    $t->fail('Exception not thrown');
} catch (sfException $e) {
    $t->pass('Exception thrown');
}
$t->info('  3.2.1 - Test multiple fields, no partial, yes "method" - does not throw exception');
try {
    $service->getContent($blog, array('title', 'body'), null, 'getTestValue');
    $t->pass('Exception not thrown');
} catch (sfException $e) {
Example #26
0
 /**
  * 发布域名,并更新数据库
  * 
  * @param string $domain
  * 
  * @return \stdClass
  * 
  * @throws \Exception\Msg
  */
 public static function domain($domain)
 {
     $user = User::show();
     $repo = Github::showDefaultBlogRepoName($user['metadata']['login']);
     if ($domain) {
         $dns = dns_get_record($domain, DNS_CNAME);
         if (!$dns) {
             throw new \Exception\Msg('指定域名没有设置CNAME记录');
         }
         if (count($dns) > 1) {
             throw new \Exception\Msg('指定域名CNAME记录设置超过一个');
         }
         if ($dns[0]['target'] !== $repo) {
             throw new \Exception\Msg(sprintf('指定域名CNAME错误(错误记录为:%s)', $dns[0]['target']));
         }
         $message = sprintf('Bind domain %s', $domain);
     } else {
         $message = sprintf('Remove domain');
     }
     $path = 'CNAME';
     $result = self::publishUserRespos($path, $domain, $message);
     //上传文件成功,更新数据库
     if (!empty($result->content) && !empty($result->commit)) {
         Blog::save(array('domain' => $domain));
     }
     return $result;
 }
Example #27
0
 public function postBlog()
 {
     $event = $this->calendar->schedule->loadEvent();
     if (!PHPWS_Core::initModClass('blog', 'Blog.php')) {
         return;
     }
     $blog = new Blog();
     $blog->title = $event->summary;
     $tpl = $event->tplFormatTime();
     $summary[] = sprintf('%s %s %s', $tpl['START_TIME'], $tpl['TO'], $tpl['END_TIME']);
     if (!empty($event->location)) {
         $summary[] = $event->getLocation();
     }
     $blog->summary = PHPWS_Text::parseInput('<p class="calendar-post">' . implode('<br />', $summary) . '</p>') . $event->description;
     $blog->approved = 1;
     $days = (int) $_POST['advance_post'];
     $publish = $event->start_time - $days * 86400;
     if ($publish < time()) {
         $blog->publish_date = time();
     } else {
         $blog->publish_date =& $publish;
     }
     return !PHPWS_Error::logIfError($blog->save());
 }
 /**
  * Add post action
  */
 public function actionaddpost()
 {
     // Perms
     if (!Yii::app()->user->checkAccess('op_blog_addposts')) {
         throw new CHttpException(403, Yii::t('error', 'Sorry, You don\'t have the required permissions to enter this section'));
     }
     $model = new Blog();
     if (isset($_POST['Blog'])) {
         $model->attributes = $_POST['Blog'];
         if ($model->save()) {
             Yii::app()->user->setFlash('success', Yii::t('adminblog', 'Post Added.'));
             $this->redirect(array('viewcategory', 'id' => $model->catid));
         }
     }
     // Adding by cat?
     if (Yii::app()->request->getParam('catid')) {
         $model->catid = Yii::app()->request->getParam('catid');
     }
     // cat list
     $parents = array();
     $parentlist = BlogCats::model()->getRootCats();
     if (count($parentlist)) {
         foreach ($parentlist as $row) {
             $parents[$row->id] = $row->title;
         }
     }
     $this->breadcrumbs[Yii::t('adminblog', 'Adding Post')] = '';
     $this->pageTitle[] = Yii::t('adminblog', 'Adding Post');
     // Render
     $this->render('post_form', array('model' => $model, 'parents' => $parents, 'label' => Yii::t('adminblog', 'Adding Post')));
 }
Example #29
0
	public function testSetCommentExpirationDate()
	{
		$blog = new Blog;
		$blog->title = 'My New Blog Title';
		$blog->authorID = 'nathan';
		$blog->text = '...';
		$blog->language = 'en';
		$blog->commentsAllowed = true;
		$blog->commentsOpenFor = 14; // 2 weeks
		$blog->save();
		
		$blog = Blog::getBlog($blog->year, $blog->month, $blog->day, $blog->ID, 'en');
		$this->assertTrue($blog->allowComments());
		$this->assertLessThan(5, abs($blog->commentsCloseDate - 60 * 60 * 24 * 14 - time()));
		
		$blog = new Blog;
		$blog->title = 'My New Blog Title With Unlimited comments';
		$blog->authorID = 'nathan';
		$blog->text = '...';
		$blog->language = 'en';
		$blog->commentsAllowed = true;
		$blog->commentsOpenFor = 0; //Unlimited
		$blog->save();
		$blog = Blog::getBlog($blog->year, $blog->month, $blog->day, $blog->ID, 'en');
		$this->assertTrue($blog->allowComments());
		$this->assertNull($blog->commentsCloseDate);
	}
 /**
  * Are we allowed to add posts?
  */
 public function actionaddpost()
 {
     if (!Yii::app()->user->checkAccess('op_blog_addposts')) {
         throw new CHttpException(403, Yii::t('error', 'Sorry, You are not allowed to perform that action.'));
     }
     $model = new Blog();
     if (isset($_POST['Blog'])) {
         $model->attributes = $_POST['Blog'];
         if (!Yii::app()->user->checkAccess('op_blog_manage')) {
             // Can we auto approve posts for this category?
             $model->status = 0;
             $cat = BlogCats::model()->findByPk($model->catid);
             if ($cat) {
                 if ($cat->autoaddperms) {
                     $perms = explode(',', $cat->autoaddperms);
                     if (count($perms)) {
                         foreach ($perms as $perm) {
                             if (Yii::app()->user->checkAccess($perm)) {
                                 $model->status = 1;
                                 break;
                             }
                         }
                     }
                 }
             }
         }
         if ($model->save()) {
             if ($model->status) {
                 Yii::app()->user->setFlash('success', Yii::t('blog', 'Post Added.'));
                 $this->redirect(array('/blog/view/' . $model->alias, 'lang' => false));
             } else {
                 Yii::app()->user->setFlash('success', Yii::t('blog', 'Post Added. It will be displayed once approved.'));
                 $this->redirect('blog/index');
             }
         }
     }
     // Grab cats that we can add posts to
     $cats = BlogCats::model()->getCatsForMember(null, 'add');
     // Make a category selection
     $categories = array();
     foreach ($cats as $cat) {
         $categories[$cat->id] = $cat->title;
     }
     // Add page breadcrumb and title
     $this->pageTitle[] = Yii::t('blog', 'Adding Post');
     $this->breadcrumbs[Yii::t('blog', 'Adding Post')] = '';
     $this->render('post_form', array('model' => $model, 'label' => Yii::t('blog', 'Adding Post'), 'categories' => $categories));
 }