Ejemplo n.º 1
0
 /**
  * Create an entry
  *
  * @apiMethod POST
  * @apiUri    /blog
  * @apiParameter {
  * 		"name":        "scope",
  * 		"description": "Scope type (group, member, etc.)",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "scope_id",
  * 		"description": "Scope object ID",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "title",
  * 		"description": "Entry title",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "alias",
  * 		"description": "Entry alias",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "content",
  * 		"description": "Entry content",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "created",
  * 		"description": "Created timestamp (YYYY-MM-DD HH:mm:ss)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "now"
  * }
  * @apiParameter {
  * 		"name":        "crated_by",
  * 		"description": "User ID of entry creator",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "state",
  * 		"description": "Published state (0 = unpublished, 1 = published)",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "access",
  * 		"description": "Access level (0 = public, 1 = registered users, 4 = private)",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "allow_comments",
  * 		"description": "Allow comments on the entry?",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     1
  * }
  * @apiParameter {
  * 		"name":        "publish_up",
  * 		"description": "Publish start timestamp (YYYY-MM-DD HH:mm:ss)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "now"
  * }
  * @apiParameter {
  * 		"name":        "publish_down",
  * 		"description": "Publish end timestamp (YYYY-MM-DD HH:mm:ss)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "tags",
  * 		"description": "Comma-separated list of tags",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @return    void
  */
 public function createTask()
 {
     $this->requiresAuthentication();
     $fields = array('scope' => Request::getVar('scope', '', 'post'), 'scope_id' => Request::getInt('scope_id', 0, 'post'), 'title' => Request::getVar('title', null, 'post', 'none', 2), 'alias' => Request::getVar('alias', 0, 'post'), 'content' => Request::getVar('content', null, 'post', 'none', 2), 'created' => Request::getVar('created', new Date('now'), 'post'), 'created_by' => Request::getInt('created_by', 0, 'post'), 'state' => Request::getInt('state', 0, 'post'), 'access' => Request::getInt('access', 0, 'post'), 'allow_comments' => Request::getInt('allow_comments', 0, 'post'), 'publish_up' => Request::getVar('publish_up', new Date('now'), 'post'), 'publish_down' => Request::getVar('publish_down', null, 'post'), 'hits' => Request::getInt('hits', 0, 'post'), 'tags' => Request::getVar('tags', null, 'post'));
     $row = new Entry();
     if (!$row->set($fields)) {
         throw new Exception(Lang::txt('COM_BLOG_ERROR_BINDING_DATA'), 500);
     }
     $row->set('email', isset($fields['email']) ? 1 : 0);
     $row->set('anonymous', isset($fields['anonymous']) ? 1 : 0);
     if (!$row->save()) {
         throw new Exception(Lang::txt('COM_BLOG_ERROR_SAVING_DATA'), 500);
     }
     if (isset($fields['tags'])) {
         if (!$row->tag($fields['tags'], User::get('id'))) {
             throw new Exception(Lang::txt('COM_BLOG_ERROR_SAVING_TAGS'), 500);
         }
     }
     $row->set('created', with(new Date($row->get('created')))->format('Y-m-d\\TH:i:s\\Z'));
     $row->set('publish_up', with(new Date($row->get('publish_up')))->format('Y-m-d\\TH:i:s\\Z'));
     if ($row->get('publish_down') && $row->get('publish_down') != '0000-00-00 00:00:00') {
         $row->set('publish_down', with(new Date($row->get('publish_down')))->format('Y-m-d\\TH:i:s\\Z'));
     }
     // Log activity
     $base = rtrim(Request::base(), '/');
     $url = str_replace('/api', '', $base . '/' . ltrim(Route::url($row->link()), '/'));
     Event::trigger('system.logActivity', ['activity' => ['action' => 'created', 'scope' => 'blog.entry', 'scope_id' => $row->get('id'), 'description' => Lang::txt('COM_BLOG_ACTIVITY_ENTRY_CREATED', '<a href="' . $url . '">' . $row->get('title') . '</a>'), 'details' => array('title' => $row->get('title'), 'url' => $url)], 'recipients' => [$row->get('created_by')]]);
     $this->send($row->toObject());
 }