Example #1
0
 public function init()
 {
     parent::init();
     $this->setTitle('Edit Talk')->setDescription('Edit your entry below, then click "Post Entry" to publish the entry on your talk.');
     $this->submit->setLabel('Save Changes');
     $captcha = Engine_Api::_()->getApi('settings', 'core')->getSetting('ynblog.captcha', 0);
     if ($captcha) {
         $this->removeElement('captcha');
     }
 }
Example #2
0
 public function createAction()
 {
     // Check authoraiztion permisstion
     if (!$this->_helper->requireUser()->isValid()) {
         return;
     }
     if (!$this->_helper->requireAuth()->setAuthParams('blog', null, 'create')->isValid()) {
         return;
     }
     // Render
     $this->_helper->content->setEnabled();
     $viewer = Engine_Api::_()->user()->getViewer();
     // Checking maximum blog allowed
     $this->view->maximum_blogs = $maximum_blogs = Engine_Api::_()->getItemTable('blog')->checkMaxBlogs();
     $blog_number = Engine_Api::_()->getItemTable('blog')->getCountBlog($viewer);
     if ($maximum_blogs == 0 || $blog_number < $maximum_blogs) {
         $this->view->maximum_reach = false;
     } else {
         $this->view->maximum_reach = true;
     }
     // Get navigation
     $this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')->getNavigation('ynblog_main');
     // Prepare form
     $this->view->form = $form = new Ynblog_Form_Create();
     // Post request checking
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $table = Engine_Api::_()->getDbTable('blogs', 'ynblog');
     $db = $table->getAdapter();
     $db->beginTransaction();
     try {
         // Create blog
         $values = array_merge($form->getValues(), array('owner_type' => $viewer->getType(), 'owner_id' => $viewer->getIdentity()));
         // Moderation mode
         $blog_moderation = Engine_Api::_()->getApi('settings', 'core')->getSetting('ynblog.moderation', 0);
         if ($blog_moderation) {
             $values['is_approved'] = 0;
         } else {
             $values['is_approved'] = 1;
         }
         $blog = $table->createRow();
         $blog->setFromArray($values);
         $blog->save();
         // Set photo
         if (!empty($values['photo'])) {
             $blog->setPhoto($form->photo);
         }
         // Authorization set up
         $auth = Engine_Api::_()->authorization()->context;
         $roles = array('owner', 'owner_member', 'owner_member_member', 'owner_network', '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 && $values['is_approved'] == 1) {
             $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($viewer, $blog, 'ynblog_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', 'ynblog')->sendNotifications($blog);
             $blog->add_activity = 1;
             $blog->save();
         }
         // Commit
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     return $this->_helper->redirector->gotoRoute(array('action' => 'manage'));
 }