public function testLockedFields()
 {
     $post = new Post();
     $post->activateLocker();
     $post->activateLockCheck();
     $post->setTitle('A super book');
     $post->save();
     $this->assertTrue($post->getTitleLock());
     $this->assertEquals('A super book', $post->getTitle());
     $post->setTitle('New Title');
     $this->assertEquals('New Title', $post->getTitle());
     $post->save();
     $this->assertEquals('A super book', $post->getTitle());
 }
Example #2
0
 public function createPost($data)
 {
     $currentUser = parent::authenticateUser();
     $post = new Post();
     if (isset($data->title) && isset($data->content)) {
         $post->setTitle($data->title);
         $post->setContent($data->content);
         $post->setAuthor($currentUser);
     }
     try {
         // validate Post object
         $post->checkIsValidForCreate();
         // if it fails, ValidationException
         // save the Post object into the database
         $postId = $this->postMapper->save($post);
         // response OK. Also send post in content
         header($_SERVER['SERVER_PROTOCOL'] . ' 201 Created');
         header('Location: ' . $_SERVER['REQUEST_URI'] . "/" . $postId);
         header('Content-Type: application/json');
         echo json_encode(array("id" => $postId, "title" => $post->getTitle(), "content" => $post->getContent()));
     } catch (ValidationException $e) {
         header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad request');
         echo json_encode($e->getErrors());
     }
 }
Example #3
0
function parseItem($blog, $item, $ts)
{
    if ($ts != 0 && $item->pubdate <= $ts) {
        logmsg('Zatrzymanie na wpisie: %s', StringUtils::removeAccents($item->title));
        return false;
    }
    logmsg('  - Parsowanie wpisu: %s', StringUtils::removeAccents($item->title));
    $post = new Post();
    $post->setBlog($blog);
    foreach ($item->tags as $name) {
        $tag = TagPeer::retriveByName($name, true);
        if ($post->addTag($tag)) {
            logmsg('    - Znaleziono tag: %s', $name);
        }
    }
    if ($post->hasTags()) {
        $shortened = $post->setFullContent($item->content);
        $post->setLink(htmlspecialchars($item->link));
        $post->setTitle($item->title);
        $post->setCreatedAt($item->pubdate);
        $post->setShortened($shortened);
        $post->save();
    } else {
        logmsg('    - Nie znaleziono tagow');
    }
    return true;
}
 public function controlerJob($maincont)
 {
     if ($maincont->isLoggued()) {
         if (isset($_POST["title"])) {
             $p = new Post();
             $p->setTitle($_POST["title"]);
             $p->setBody($_POST["body"]);
             $p->setHour(date("h:i:s"));
             $p->setDate(date("Y-m-d"));
             // gestion des tags
             $tags = explode(" ", $_POST["tags"]);
             foreach ($tags as $t) {
                 if ($t == "") {
                     continue;
                 }
                 $ta = Tag::getByTag($t);
                 //echo "Tag : $t<br />";
                 if (count($ta) == 0) {
                     $mytag = new Tag();
                     $mytag->setTag($t);
                 } else {
                     $mytag = $ta[0];
                 }
                 // création du posttag liant le tag et le post
                 $pt = new Posttag();
                 $pt->setPostid($p->id);
                 $pt->setTagid($mytag->id);
             }
         }
         $maincont->goModule("post", "admin");
     } else {
         $maincont->goModule("home", "display");
     }
 }
Example #5
0
 private static function getPostFromJSON($id, $json)
 {
     $post = new Post($id);
     $post->setText($json['text']);
     $post->setTitle($json['title']);
     return $post;
 }
Example #6
0
 static function save($id)
 {
     $post = new Post($id);
     $post->setText($_POST['post_text']);
     $post->setTitle($_POST['post_title']);
     $newid = PostStorage::savePost($post);
     redirect_to('/' . $newid);
 }
 /**
  * {@inheritDoc}
  */
 public function findPost($id)
 {
     $postData = $this->data[$id];
     $model = new Post();
     $model->setId($postData['id']);
     $model->setTitle($postData['title']);
     $model->setText($postData['text']);
     return $model;
 }
 /**
  * Returns Post object by specified id
  *
  * @param int $id
  * @return Post|null
  */
 public function getById($id)
 {
     $arrayData = $this->persistence->retrieve($id);
     if (is_null($arrayData)) {
         return null;
     }
     $post = new Post();
     $post->setId($arrayData['id']);
     $post->setAuthor($arrayData['author']);
     $post->setCreated($arrayData['created']);
     $post->setText($arrayData['text']);
     $post->setTitle($arrayData['title']);
     return $post;
 }
Example #9
0
 private function processResults($statement)
 {
     $results = array();
     if ($statement) {
         while ($row = $statement->fetch(PDO::FETCH_OBJ)) {
             $post = new Post();
             $post->setId($row->post_id);
             $post->setTitle($row->title);
             $post->setContent($row->content);
             $results[] = $post;
         }
     }
     return $results;
 }
Example #10
0
 public function user_update_post()
 {
     $db = new PDO("mysql:dbname=xuthulu", 'root', 'password');
     $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $post = new Post($db, $_SESSION['user_id'], $_POST['prod_id']);
     $post->setTitle($_POST['title']);
     $post->setDescription($_POST['description']);
     $post->setCondition($_POST['condition']);
     $post->setPrice($_POST['price']);
     if ($post->update_post()) {
         header('Location: userpage.php');
         exit;
     } else {
         throw new Exception("An error has occured. Please try again.");
     }
 }
Example #11
0
 /**
  * Console-only route to generate fixtures.
  */
 public function fixturesAction()
 {
     $em = $this->getEntityManager();
     for ($i = 0; $i < 100; $i++) {
         $post = new Post();
         $post->setTitle('Post ' . uniqid());
         $post->setIntro(str_repeat('intro ', rand(1, 100)));
         $content = '';
         for ($j = mt_rand(1, 100); $j > 0; $j--) {
             $content .= str_repeat('lorem ipsum ', rand(1, 20));
         }
         $post->setContent($content);
         $em->persist($post);
     }
     $em->flush();
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $p1 = new Post();
     $p1->setTitle("1 Lorem Impsum post");
     $p1->setBody("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.");
     $p1->setAuthor($this->getAuthor($manager, 'Vlad'));
     $p2 = new Post();
     $p2->setTitle("2 Lorem Impsum post");
     $p2->setBody("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.");
     $p2->setAuthor($this->getAuthor($manager, 'Nikolay'));
     $p3 = new Post();
     $p3->setTitle("3 Lorem Impsum post");
     $p3->setBody("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.");
     $p3->setAuthor($this->getAuthor($manager, 'Edgar'));
     $manager->persist($p1);
     $manager->persist($p2);
     $manager->persist($p3);
     $manager->flush();
 }
Example #13
0
 public function controlerJob($maincont)
 {
     if ($maincont->isLoggued()) {
         //print_r($_POST);
         if (isset($_POST["id"])) {
             $p = new Post($_POST["id"]);
             $p->setTitle($_POST["title"]);
             $p->setBody($_POST["body"]);
             //$p->setHour(date("h:i:s"));
             //$p->setDate(date("Y-m-d"));
             // gestion des tags
             // il faut virer tous les posttags de l'article avant de mettre les nouveaux
             $ptall = Posttag::getByPostid($_POST["id"]);
             foreach ($ptall as $trollol) {
                 $trollol->delete();
             }
             $tags = explode(" ", $_POST["tags"]);
             foreach ($tags as $t) {
                 if ($t == "") {
                     continue;
                 }
                 $ta = Tag::getByTag($t);
                 //echo "Tag : $t<br />";
                 if (count($ta) == 0) {
                     $mytag = new Tag();
                     $mytag->setTag($t);
                 } else {
                     $mytag = $ta[0];
                 }
                 // création du posttag liant le tag et le post
                 $pt = new Posttag();
                 $pt->setPostid($_POST["id"]);
                 $pt->setTagid($mytag->id);
             }
         }
         $maincont->goModule("post", "admin");
     } else {
         $maincont->goModule("home", "display");
     }
 }
Example #14
0
 public function process($ctrl)
 {
     OW::getCacheManager()->clean(array(PostDao::CACHE_TAG_POST_COUNT));
     $service = PostService::getInstance();
     /* @var $postDao PostService */
     $data = $this->getValues();
     $data['title'] = UTIL_HtmlTag::stripJs($data['title']);
     $postIsNotPublished = $this->post->getStatus() == 2;
     $text = UTIL_HtmlTag::sanitize($data['post']);
     /* @var $post Post */
     $this->post->setTitle($data['title']);
     $this->post->setPost($text);
     $this->post->setIsDraft($_POST['command'] == 'draft');
     $isCreate = empty($this->post->id);
     if ($isCreate) {
         $this->post->setTimestamp(time());
         //Required to make #698 and #822 work together
         if ($_POST['command'] == 'draft') {
             $this->post->setIsDraft(2);
         }
         BOL_AuthorizationService::getInstance()->trackAction('blogs', 'add_blog');
     } else {
         //If post is not new and saved as draft, remove their item from newsfeed
         if ($_POST['command'] == 'draft') {
             OW::getEventManager()->trigger(new OW_Event('feed.delete_item', array('entityType' => 'blog-post', 'entityId' => $this->post->id)));
         } else {
             if ($postIsNotPublished) {
                 // Update timestamp if post was published for the first time
                 $this->post->setTimestamp(time());
             }
         }
     }
     $service->save($this->post);
     $tags = array();
     if (intval($this->post->getId()) > 0) {
         $tags = $data['tf'];
         foreach ($tags as $id => $tag) {
             $tags[$id] = UTIL_HtmlTag::stripTags($tag);
         }
     }
     $tagService = BOL_TagService::getInstance();
     $tagService->updateEntityTags($this->post->getId(), 'blog-post', $tags);
     if ($this->post->isDraft()) {
         $tagService->setEntityStatus('blog-post', $this->post->getId(), false);
         if ($isCreate) {
             OW::getFeedback()->info(OW::getLanguage()->text('blogs', 'create_draft_success_msg'));
         } else {
             OW::getFeedback()->info(OW::getLanguage()->text('blogs', 'edit_draft_success_msg'));
         }
     } else {
         $tagService->setEntityStatus('blog-post', $this->post->getId(), true);
         //Newsfeed
         $event = new OW_Event('feed.action', array('pluginKey' => 'blogs', 'entityType' => 'blog-post', 'entityId' => $this->post->getId(), 'userId' => $this->post->getAuthorId()));
         OW::getEventManager()->trigger($event);
         if ($isCreate) {
             OW::getFeedback()->info(OW::getLanguage()->text('blogs', 'create_success_msg'));
             OW::getEventManager()->trigger(new OW_Event(PostService::EVENT_AFTER_ADD, array('postId' => $this->post->getId())));
         } else {
             OW::getFeedback()->info(OW::getLanguage()->text('blogs', 'edit_success_msg'));
             OW::getEventManager()->trigger(new OW_Event(PostService::EVENT_AFTER_EDIT, array('postId' => $this->post->getId())));
         }
         $ctrl->redirect(OW::getRouter()->urlForRoute('post', array('id' => $this->post->getId())));
     }
 }
Example #15
0
<?php

include_once 'Registry.php';
include_once 'dao/PostDAO.php';
include_once 'model/Post.php';
// Instanciar uma conexão com PDO
$conn = new PDO('mysql:host=localhost;port=3306;dbname=example-pdo', 'user', 'password');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Armazenar essa instância no Registry
$registry = Registry::getInstance();
$registry->set('Connection', $conn);
// Instanciar um novo Post e setar informações
$primeiroPost = new Post();
$primeiroPost->setTitle('Primeiro post');
$primeiroPost->setContent('Conteudo!');
// Instanciar um novo Post e setar informações
$segundoPost = new Post();
$segundoPost->setTitle('Segundo post');
$segundoPost->setContent('Conteudo!');
// Instanciar o DAO e trabalhar com os métodos
$postDAO = new PostDAO();
$postDAO->insert($primeiroPost);
$postDAO->insert($segundoPost);
// Resgatar todos os registros e iterar
$results = $postDAO->getAll();
foreach ($results as $post) {
    echo $post->getTitle() . '<br />';
    echo $post->getContent() . '<br />';
    echo '<br />';
}
Example #16
0
<?php

require_once 'autoloader.php';
echo "ok";
$query = new Create();
$query->createDatabase();
$user = new Post();
$user->setTitle('Etiam posuere');
$user->setPhotos('pics02.jpg');
$user->setContent('Pellentesque viverra vulputate enim. Aliquam erat volutpat. Pellentesque tristique ante. Sed vel tellus.');
$user->save();
Example #17
0
 public function testSave()
 {
     $post = new Post();
     $post->setDate('2012-01-01 12:12');
     $post->setTitle('New Post');
     $post->setContent('New content');
     $post->save('/tmp/');
     $newPost = new Post('/tmp/2012-01-01-new-post.md');
     $this->assertEquals('New Post', $post->getTitle());
     $newPost->setTitle('change-url');
     $newPost->save('/tmp/');
 }
    redirect("../login.php");
}
$database = new Database();
$user = new User();
$post = new Post();
$media = new Media();
if (isset($_POST['submit'])) {
    //print_r($_FILES['mediaUploads']);
    $title = $database->escapeString($_POST['title']);
    $undertitle = $database->escapeString($_POST['undertitle']);
    $pageId = $database->escapeString($_POST['pageId']);
    $body = $database->escapeString($_POST['body']);
    $d = new DateTime();
    $date = $d->format('Y-m-d H:i');
    $userId = $_SESSION['USID'];
    $post->setTitle($title);
    $post->setUnderTitle($undertitle);
    $post->setPageId($pageId);
    $post->setBody($body);
    $post->setDate($date);
    $post->setUserId($userId);
    if (isset($_POST['postId'])) {
        $postId = $database->escapeString($_POST['postId']);
        $post->setPostId($postId);
        $post->update($database);
        $post->deleteCategories($database);
    } else {
        $postId = $post->create($database);
    }
    if (isset($_POST['categories'])) {
        $categoriesArray = $_POST['categories'];
 public function loadList()
 {
     $posts = array();
     if (file_exists(POSTS_DIRECTORY)) {
         if ($handle = opendir(POSTS_DIRECTORY)) {
             while (false !== ($entry = readdir($handle))) {
                 if ($entry != "." && $entry != "..") {
                     $title = str_ireplace(POSTS_SUFFIX, '', $entry);
                     $post = new Post();
                     $post->setTitle($title);
                     array_push($posts, $post);
                 }
             }
             closedir($handle);
         }
     }
     $this->posts = $posts;
 }
$post->Thread = new Thread();
$post->Thread->title = 'test thread';
$post->save();
Doctrine::getTable('Post')->setSearchHandler($handler);
// @After
$handler->reset();
unset($handler);
unset($post);
// @Test: Check if index is updated when a new object is created
$handler->any('unindex')->once();
$handler->commit()->once();
$handler->any('index')->once();
$handler->commit()->once();
$handler->replay();
$post2 = new Post();
$post2->setTitle('title');
$post2->setBody('body');
$post2->Thread = new Thread();
$post2->Thread->title = 'test thread';
$post2->save();
$handler->verify();
// @Test: Check if index is updated when the object is
$handler->any('unindex')->once();
$handler->commit()->once();
$handler->any('index')->once();
$handler->commit()->once();
$handler->replay();
$post->title = 'changed title';
$post->save();
$handler->verify();
// @Test: Check if index is updated when the object is deleted
Example #21
0
 /**
  * Action to add a new post
  * 
  * When called via GET, it shows the add form
  * When called via POST, it adds the post to the
  * database
  * 
  * The expected HTTP parameters are:
  * <ul>
  * <li>title: Title of the post (via HTTP POST)</li>
  * <li>content: Content of the post (via HTTP POST)</li>      
  * </ul>
  * 
  * The views are:
  * <ul>
  * <li>posts/add: If this action is reached via HTTP GET (via include)</li>   
  * <li>posts/index: If post was successfully added (via redirect)</li>
  * <li>posts/add: If validation fails (via include). Includes these view variables:</li>
  * <ul>
  *  <li>post: The current Post instance, empty or 
  *  being added (but not validated)</li>
  *  <li>errors: Array including per-field validation errors</li>   
  * </ul>
  * </ul>
  * @throws Exception if no user is in session
  * @return void
  */
 public function add()
 {
     if (!isset($this->currentUser)) {
         throw new Exception("Not in session. Adding posts requires login");
     }
     $post = new Post();
     if (isset($_POST["submit"])) {
         // reaching via HTTP Post...
         // populate the Post object with data form the form
         $post->setTitle($_POST["title"]);
         $post->setContent($_POST["content"]);
         // The user of the Post is the currentUser (user in session)
         $post->setAuthor($this->currentUser);
         try {
             // validate Post object
             $post->checkIsValidForCreate();
             // if it fails, ValidationException
             // save the Post object into the database
             $this->postMapper->save($post);
             // POST-REDIRECT-GET
             // Everything OK, we will redirect the user to the list of posts
             // We want to see a message after redirection, so we establish
             // a "flash" message (which is simply a Session variable) to be
             // get in the view after redirection.
             $this->view->setFlash("Post \"" . $post->getTitle() . "\" successfully added.");
             // perform the redirection. More or less:
             // header("Location: index.php?controller=posts&action=index")
             // die();
             $this->view->redirect("posts", "index");
         } catch (ValidationException $ex) {
             // Get the errors array inside the exepction...
             $errors = $ex->getErrors();
             // And put it to the view as "errors" variable
             $this->view->setVariable("errors", $errors);
         }
     }
     // Put the Post object visible to the view
     $this->view->setVariable("post", $post);
     // render the view (/view/posts/add.php)
     $this->view->render("posts", "add");
 }
Example #22
0
echo PHP_EOL;
//PHP 5.4
class Post implements JsonSerializable
{
    private $sTitle, $oDate;
    public function getTitle()
    {
        return $this->sTitle;
    }
    public function setTitle($sTitle)
    {
        $this->sTitle = $sTitle;
    }
    public function getDate()
    {
        return $this->oDate;
    }
    public function setDate($oDate)
    {
        $this->oDate = $oDate;
    }
    public function jsonSerialize()
    {
        return ['title' => $this->getTitle(), 'date' => $this->getDate(), 'somecode' => [1, 2, 3]];
    }
}
$oPost = new Post();
$oPost->setTitle('Hello PHP 5.4');
$oPost->setDate(new DateTime());
echo json_encode($oPost, JSON_PRETTY_PRINT);
echo PHP_EOL;
<?php

/**
 * Doctrine_Template_Solr tests.
 */
include_once dirname(__FILE__) . '/../../../bootstrap/bootstrap.php';
LimeAnnotationSupport::enable();
$t = new lime_test(13);
// @Before
$handler = $t->mock('Search_Handler_Interface');
$post = new Post();
$post->setTitle('title');
$post->setBody('body');
$post->Thread = new Thread();
$post->Thread->title = 'test thread';
$post->save();
Doctrine::getTable('Post')->setSearchHandler($handler);
// @After
$handler->reset();
unset($handler);
unset($post);
// @Test: template availability
$t->ok(is_callable(array(Doctrine::getTable('Post'), 'isSearchAvailable')));
// @Test: getUniqueId() generates a correct id
$identifier = sprintf("Post_%d", $post->getId());
$t->is($post->getUniqueId(), $identifier);
// @Test: getFieldsArray() generates an array with all the required fields
$keys = array_keys($post->getFieldsArray());
$t->is_deeply($keys, array('sf_unique_id', 'sf_meta_class', 'sf_meta_id', 'title_t', 'body_t'));
// @Test: getFieldsArray() generates an array with correct values
$array = $post->getFieldsArray();
Example #24
0
/* Init Databases */
session_start();
require_once 'models/Post.class.php';
require_once 'models/utils.php';
require_once 'config.php';
$db = mysql_connect(WALKER_DB_HOST, WALKER_DB_USERNAME, WALKER_DB_PASSWORD) or die('Could not connect: ' . mysql_error());
mysql_select_db(WALKER_DB_NAME);
mysql_query('SET NAMES utf8');
mysql_query('SET CHARACTER SET utf8');
mysql_query("SET COLLATION_CONNECTION='utf8_general_ci'");
if (isset($_POST['method'])) {
    $post = new Post();
    switch ($_POST['method']) {
        case 'new':
            check_login();
            $post->setTitle($_POST['title']);
            $post->setAuthor($_SESSION['user']);
            $post->setTags($_POST['tags']);
            $post->setReply($_POST['reply']);
            $post->setShow($_POST['show']);
            $post->setContent($_POST['content']);
            $id = $post->newTopic();
            mysql_close($db);
            echo 'ok';
            //header("Location: http://www.n7money.cn/view/$id.html");
            break;
        case 'modify':
            check_login();
            $post->setId(intval($_POST['topic_id']));
            $post->setTitle($_POST['title']);
            $post->setCreated($_POST['created']);