Example #1
0
 public function init()
 {
     parent::init();
     $this->setTitle('Edit Blog Entry')->setDescription('Edit your entry below, then click "Post Entry" to publish the entry on your blog.');
     $this->submit->setLabel('Save Changes');
 }
Example #2
0
 public function createAction()
 {
     if (!$this->_helper->requireUser()->isValid()) {
         return;
     }
     if (!$this->_helper->requireAuth()->setAuthParams('blog', null, 'create')->isValid()) {
         return;
     }
     // Render
     $this->_helper->content->setEnabled();
     // set up data needed to check quota
     $viewer = Engine_Api::_()->user()->getViewer();
     $values['user_id'] = $viewer->getIdentity();
     $paginator = Engine_Api::_()->getItemTable('blog')->getBlogsPaginator($values);
     $this->view->quota = $quota = Engine_Api::_()->authorization()->getPermission($viewer->level_id, 'blog', 'max');
     $this->view->current_count = $paginator->getTotalItemCount();
     // Prepare form
     $this->view->form = $form = new Blog_Form_Create();
     // If not post or form not valid, return
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $table = Engine_Api::_()->getItemTable('blog');
     $db = $table->getAdapter();
     $db->beginTransaction();
     try {
         // Create blog
         $viewer = Engine_Api::_()->user()->getViewer();
         $values = array_merge($form->getValues(), array('owner_type' => $viewer->getType(), 'owner_id' => $viewer->getIdentity()));
         $blog = $table->createRow();
         $blog->setFromArray($values);
         $blog->save();
         // Auth
         $auth = Engine_Api::_()->authorization()->context;
         $roles = array('owner', 'owner_member', 'owner_member_member', 'owner_network', 'registered', 'everyone');
         if (empty($values['auth_view'])) {
             $values['auth_view'] = 'everyone';
         }
         if (empty($values['auth_comment'])) {
             $values['auth_comment'] = 'everyone';
         }
         $viewMax = array_search($values['auth_view'], $roles);
         $commentMax = array_search($values['auth_comment'], $roles);
         foreach ($roles as $i => $role) {
             $auth->setAllowed($blog, $role, 'view', $i <= $viewMax);
             $auth->setAllowed($blog, $role, 'comment', $i <= $commentMax);
         }
         // Add tags
         $tags = preg_split('/[,]+/', $values['tags']);
         $blog->tags()->addTagMaps($viewer, $tags);
         // Add activity only if blog is published
         if ($values['draft'] == 0) {
             $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($viewer, $blog, 'blog_new');
             // make sure action exists before attaching the blog to the activity
             if ($action) {
                 Engine_Api::_()->getDbtable('actions', 'activity')->attachActivity($action, $blog);
             }
         }
         // Send notifications for subscribers
         Engine_Api::_()->getDbtable('subscriptions', 'blog')->sendNotifications($blog);
         // Commit
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     return $this->_helper->redirector->gotoRoute(array('action' => 'manage'));
 }