Esempio n. 1
0
 public function testSetId()
 {
     $p = new ae_PostModel();
     $p->setId(4);
     $this->assertTrue($p->getId() === 4);
     $this->setExpectedException('Exception');
     $p->setId(-1);
 }
Esempio n. 2
0
/**
 * Create the post.
 * @return {int} ID of the new post.
 */
function createPost()
{
    if (!isset($_POST['post-title'], $_POST['post-permalink'], $_POST['post-content'], $_POST['post-tags'], $_POST['post-publish-month'], $_POST['post-publish-day'], $_POST['post-publish-year'], $_POST['post-publish-hour'], $_POST['post-publish-minute'], $_POST['submit'])) {
        header('Location: ../admin.php?error=missing_data_for_post');
        exit;
    }
    $datetime = sprintf('%04d-%02d-%02d %02d:%02d:00', $_POST['post-publish-year'], $_POST['post-publish-month'], $_POST['post-publish-day'], $_POST['post-publish-hour'], $_POST['post-publish-minute']);
    $permalink = trim($_POST['post-permalink']);
    $status = $_POST['submit'] == 'draft' ? ae_PostModel::STATUS_DRAFT : ae_PostModel::STATUS_PUBLISHED;
    $post = new ae_PostModel();
    if (isset($_POST['edit-id'])) {
        $post->setId($_POST['edit-id']);
    }
    $post->setTitle($_POST['post-title']);
    if ($permalink != '') {
        $post->setPermalink($permalink);
    }
    $post->setContent($_POST['post-content']);
    $post->setDatetime(isset($_POST['post-schedule']) ? $datetime : date('Y-m-d H:i:s'));
    $post->setCommentsStatus($_POST['post-comments-status']);
    $post->setStatus($status);
    $post->setTags($_POST['post-tags']);
    $post->setUserId(ae_Security::getCurrentUserId());
    $post->save();
    return $post->getId();
}