Example #1
0
    public function create($content, $idAuthor, Topic $Topic, SCategory $SCategory)
    {
        $post = new Post($this->db);
        try {
            $post->setContent($content);
            $post->setIdAuthor($idAuthor);
            $post->setTopic($Topic);
            $post->setSCategory($SCategory);
        } catch (Exception $e) {
            $errors = $e->getMessage();
            echo $errors;
        }
        if (!isset($err)) {
            $content = $this->db->quote($post->getContent());
            $idAuthor = $post->getIdAuthor();
            $idTopic = $post->getIdTopic();
            $idSCategory = $post->getIdSCategory();
            $query = 'INSERT INTO post(content, id_author, id_topic, id_sCategory)
						VALUE (' . $content . ',' . $idAuthor . ', ' . $idTopic . ', ' . $idSCategory . ')';
        }
        $res = $this->db->exec($query);
        if ($res) {
            $id = $this->db->lastInsertId();
            if ($id) {
                return $this->findById($id);
            } else {
                throw new Exception('Database error');
            }
        } else {
            throw new Exception($errors);
        }
    }
Example #2
0
 /**
  */
 public function testGetContent()
 {
     $expected = "It's that time in the week when 'A foreign affair' goes to the quiz-night at the Grands. We usually ends up at the bottom half in the results. This might be the result of the lack of knowledge we have in things not categorized in either technology, movies or music.\n\nSometimes we've been lucky enough to hit the second to last place, that given us a whopping \$20 bar tab. Split that money on 4-5 people and we can almost get half a beer each.\n\nUsually it's three europeans and one kiwi, but tonight we're getting some help from the french nation.";
     $this->assertEquals($expected, $this->object->getContent());
     $this->object->setContent('This is the new content');
     $this->assertEquals('This is the new content', $this->object->getContent());
 }
Example #3
0
 public function insert(Post $post)
 {
     $this->conn->beginTransaction();
     try {
         $stmt = $this->conn->prepare('INSERT INTO posts (title, content) VALUES (:title, :content)');
         $stmt->bindValue(':title', $post->getTitle());
         $stmt->bindValue(':content', $post->getContent());
         $stmt->execute();
         $this->conn->commit();
     } catch (Exception $e) {
         $this->conn->rollback();
     }
 }
Example #4
0
function view_post($post)
{
    require_once ROOT . '/application/models/Post.php';
    $app = \Slim\Slim::getInstance();
    // get the posts directory, and post filename
    $dir = POST::POST_PATH;
    $post = new Post($path, $dir);
    $post->createPostFromFile();
    $post_metadata = $post->getMetadata();
    // parse the markdown portion into HTML
    $post_html = $app->config('md')->text($post->getContent());
    // build the final post object
    $post_result = array('title' => $post_metadata['title'], 'date' => $post_metadata['date'], 'desc' => $post_metadata['desc'], 'html' => $post_html);
    // render the post view
    $app->render('blog_post.php', array('post' => $post_result));
}
Example #5
0
 public static function getLastPosts()
 {
     $session_id = '1000004';
     $connexion = new PDO(PDO_DSN, USER, PASSWD);
     $connexion->exec("set names utf8");
     $query = "SELECT p.post_id, p.post_user, m.mbr_name, m.mbr_birthdate, m.mbr_inscription, p.post_content, p.post_date, p.post_picture FROM post AS p JOIN member m ON p.post_user = m.mbr_id WHERE p.post_user IN ( SELECT frs_a FROM friendship WHERE frs_b = ? UNION SELECT frs_b FROM friendship WHERE frs_a = ? ) ORDER BY post_date DESC";
     $stmt = $connexion->prepare($query);
     $stmt->bindParam(1, $session_id, PDO::PARAM_INT);
     $stmt->bindParam(2, $session_id, PDO::PARAM_INT);
     $stmt->execute();
     if ($stmt->rowCount()) {
         while ($ligne = $stmt->fetch(PDO::FETCH_OBJ)) {
             $member = new User($ligne->post_user, $ligne->mbr_name, $ligne->mbr_birthdate, $ligne->mbr_inscription);
             $post = new Post($ligne->post_id, $member, $ligne->post_content, $ligne->post_date, $ligne->post_picture);
             echo $member->getName() . ":" . $post->getContent() . "<br>";
             // SHOW POSTS HERE
         }
     } else {
         echo 404;
     }
 }
Example #6
0
/*$client = new IXR_Client('http://localhost/exercises/php_exercises/chapter4/server.php');

if (!$client->query('time.getGMTTime')) {
	die("Something went wrong - " . $client->getErrorCode() . $client->getErrorMessage());
}
echo($client->getResponse());*/
/*----------  Design Patterns: Decorator Pattern  ----------*/
print "<br/><br/>";
$bbcode_enabled = 0;
$emoticon_enabled = 1;
$post = new Post();
$comment = new Comment();
$post->filter("Test Title: A Test", "Lorem Ipsum Amet");
$comment->filter("Dolot avenus persina olatus");
if ($bbcode_enabled == false && $emoticon_enabled == false) {
    $postcontent = $post->getContent();
    $commentcontent = $comment->getContent();
} elseif ($bbcode_enabled == true && $emoticon_enabled == false) {
    $bb = new BBCodeParser($post);
    // Passing the Post() object to BBCodeParser()
    $postcontent = $bb->getContent();
    $bb = new BBCodeParser($comment);
    $commentcontent = $bb->getContent();
} elseif ($bbcode_enabled == false && $emoticon_enabled == true) {
    $em = new EmoticonParser($post);
    $postcontent = $em->getContent();
    $em = new EmoticonParser($comment);
    $commentcontent = $em->getContent();
}
/*----------  Design Patterns: Facade Pattern  ----------*/
$F = new Facade();
Example #7
0
 public function create($idTopic, $content)
 {
     $post = new Post();
     $set = $post->setContent($content);
     if ($set === true) {
         $manager = new TopicManager($this->db);
         $topic = $manager->findById($idTopic);
         $set = $post->setIdTopic($topic);
         if ($set === true) {
             if (isset($_SESSION['id'])) {
                 $manager = new UserManager($this->db);
                 $user = $manager->getCurrent();
                 $set = $post->setIdAuthor($user);
                 if ($set === true) {
                     $idAuthor = intval($user->getId());
                     $idTopic = intval($post->getIdTopic());
                     $content = mysqli_real_escape_string($this->db, $post->getContent());
                     $query = "INSERT INTO post (id_author, id_topic, content) VALUES (" . $idAuthor . ", " . $idTopic . ", '" . $content . "')";
                     $result = mysqli_query($this->db, $query);
                     if ($result) {
                         $id = mysqli_insert_id($this->db);
                         if ($id) {
                             return $this->findById($id);
                         } else {
                             return "Erreur serveur.";
                         }
                     } else {
                         return mysqli_error();
                     }
                 } else {
                     return $set;
                 }
             } else {
                 return "Utilisateur déconnecté.";
             }
         } else {
             return $set;
         }
     } else {
         return $set;
     }
 }
Example #8
0
 /**
  * Updates a Post in the database
  * 
  * @param Post $post The post to be updated
  * @throws PDOException if a database error occurs
  * @return void
  */
 public function update(Post $post)
 {
     $stmt = $this->db->prepare("UPDATE posts set title=?, content=? where id=?");
     $stmt->execute(array($post->getTitle(), $post->getContent(), $post->getId()));
 }
Example #9
0
    private static function showEditVideoReportageForm($post, $error, $new = false)
    {
        $name = "Edit";
        $caption = "Modifica";
        if ($new) {
            $post = new Post($post);
            $name = "New";
            $caption = "Nuovo";
        }
        ?>
		<div class="title"><?php 
        echo $caption;
        ?>
 Videoreportage</div>
		<?php 
        if (is_array($error)) {
            ?>
		<div class="error"><?php 
            foreach ($error as $err) {
                ?>
			<p><?php 
                echo $err;
                ?>
</p>
			<?php 
            }
            ?>
</div>
		<?php 
        }
        if (!isset($_GET["phase"]) || count($error) != 0) {
            ?>
		<form name="<?php 
            echo $name;
            ?>
Post" action="?type=videoreportage" method="post">
			<!--<p class="post_headline"><label>Occhiello:</label><br />
				<input class="post_headline" name="headline" value="<?php 
            echo Filter::decodeFilteredText($post->getHeadline());
            ?>
"/></p>-->
			<p class="title"><label>Titolo:</label><br/>
				<input class="post_title" name="title" value="<?php 
            echo Filter::decodeFilteredText($post->getTitle());
            ?>
"/></p>
			<p class="post_subtitle"><label>Sottotilolo:</label><br />
				<input class="post_subtitle" name="subtitle" value="<?php 
            echo Filter::decodeFilteredText($post->getSubtitle());
            ?>
"/></p>
			<p class="content"><?php 
            if ($post->getContent() != "") {
                echo youtubeManager::getVideoPlayer($post->getContent());
            }
            ?>
 <fieldset><legend>Video:</legend>
						<label>Inserisci l'URL del video: </label><input type="text" name="userUrl" value="<?php 
            echo youtubeManager::getUrl($post->getContent());
            ?>
">
				</fieldset>
			</p>
			<p class="tags"><label>Tags:</label> 
				<input class="tags" id="post_tags_input" name="tags" value="<?php 
            echo Filter::decodeFilteredText($post->getTags());
            ?>
"/></p>
			<p class="categories"><label>Categorie:</label><br/><?php 
            $cat = array();
            if (trim($post->getCategories()) != "") {
                $cat = explode(", ", Filter::decodeFilteredText($post->getCategories()));
            }
            self::showCategoryTree($cat);
            ?>
			</p>
			<p class="<?php 
            echo trim($post->getPlace()) == "" ? "hidden" : "";
            ?>
"><label id="place_label">Posizione: <?php 
            echo $post->getPlace();
            ?>
</label></p>
			<input type="hidden" name="phase" value="<?php 
            if (isset($_POST["phase"]) == 2) {
                echo '2';
            } else {
                echo '1';
            }
            ?>
">
			<input id="post_place" name="place" type="hidden" value="<?php 
            echo $post->getPlace();
            ?>
" />
			<input name="visible" type="hidden" value="true" />
			<input name="type" type="hidden" value="videoreportage" />
			<p class="submit"><input type="submit" value="Pubblica" /> 
				<input type="button" onclick="javascript:save();" value="Salva come bozza"/></p>
			<script type="text/javascript">
				function save() {
					document.<?php 
            echo $name;
            ?>
Post.visible.value = false;
					document.<?php 
            echo $name;
            ?>
Post.submit();
				}
			</script>
			<?php 
            require_once 'manager/MapManager.php';
            MapManager::setCenterToMap($post->getPlace(), "map_canvas");
            ?>
		</form>
		<?php 
        }
    }
Example #10
0
/**
 * Get post
 *
 * This function retrieves an existing post from the server.
 *
 * @param  array  $args (in appkey string, in blogid string, in postid string,
 *                       in username string, in password string)
 * @return string Upon success this will return the content of the post. Upon
 *                failure, the fault will be returned.
 * @link   http://docs.openlinksw.com/virtuoso/fn_blogger.getPost.html
 */
function getPost($args)
{
    global $server, $site;
    $postid = $args[1] + 0;
    $password = $args[3];
    if ($password === $site->ad_pass) {
        $post = new Post($site);
        $post->fetch_from_db($postid);
        // error occured?
        if ($post->postid <= 0) {
            $server->error(8003, 'No post found.');
        }
        $content = '<title>' . $post->getTitle() . '</title>' . $post->getContent();
        $content .= '<template>' . $post->getAttribute('template') . '</template>';
        $content .= '<allow_comments>' . $post->getAttribute('allow_comments') . '</allow_comments>';
        $content .= '<comment_alert>' . $post->getAttribute('comment_alert') . '</comment_alert>';
        $return = array('dateCreated' => $post->time, 'userid' => 1, 'blogid' => 1, 'content' => $content);
        return $return;
    } else {
        $server->error(8000, 'Wrong password given.');
    }
}
Example #11
0
    private static function showEditNewsForm($post, $error, $new = false)
    {
        $name = "Edit";
        $caption = "Modifica";
        if ($new) {
            $post = new Post($post);
            $name = "New";
            $caption = "Nuova";
        }
        ?>
		<div class="title"><?php 
        echo $caption;
        ?>
 Notizia</div>
		<?php 
        if (is_array($error)) {
            ?>
		<div class="error"><?php 
            foreach ($error as $err) {
                ?>
			<p><?php 
                echo $err;
                ?>
</p>
			<?php 
            }
            ?>
</div>
		<?php 
        }
        ?>
		<form name="<?php 
        echo $name;
        ?>
Post" action="?type=News" method="post">
			<p class="post_headline"><label>Occhiello:</label><br />
				<input class="post_headline" name="headline" value="<?php 
        echo $post->getHeadline();
        ?>
"/></p>
			<p class="title"><label>Titolo:</label><br/>
				<input class="post_title" name="title" value="<?php 
        echo $post->getTitle();
        ?>
"/></p>
			<p class="post_subtitle"><label>Sottotilolo:</label><br />
				<input class="post_subtitle" name="subtitle" value="<?php 
        echo $post->getSubtitle();
        ?>
"/></p>
			<p class="content"><label>Contenuto:</label><br/>
			<textarea name="content" id="post_content"><?php 
        echo $post->getContent();
        ?>
</textarea>
				<!-- sostituisco textarea standard con ckeditor -->
				<script type="text/javascript">
					CKEDITOR.replace( 'post_content', { toolbar : 'edited'});
				</script>
			</p>
			<p class="tags"><label>Tags:</label> 
				<input class="tags" id="post_tags_input" name="tags" value="<?php 
        echo $post->getTags();
        ?>
"/></p>
			<p class="categories"><label>Categorie:</label><br/><?php 
        $cat = array();
        if (trim($post->getCategories()) != "") {
            $cat = explode(", ", Filter::decodeFilteredText($post->getCategories()));
        }
        self::showCategoryTree($cat);
        ?>
			</p>
            <p class="<?php 
        echo trim($post->getPlace()) == "" ? "hidden" : "";
        ?>
"><label id="place_label">Posizione: <?php 
        echo $post->getPlace();
        ?>
</label></p>
            	<input id="post_place" name="place" type="hidden" value="<?php 
        echo $post->getPlace();
        ?>
" />
            <input name="visible" type="hidden" value="true" />
            <input name="type" type="hidden" value="news" />
           	<p class="submit"><input type="submit" value="Pubblica" /> 
            	<input type="button" onclick="javascript:save();" value="Salva come bozza"/></p>
             <script type="text/javascript">
            	function save() {
					document.<?php 
        echo $name;
        ?>
Post.visible.value = false;
					document.<?php 
        echo $name;
        ?>
Post.submit();
            	}
            </script>
		<?php 
        require_once 'maps/geolocate.php';
        MapManager::setCenterToMap($post->getPlace(), "map_canvas");
        ?>
        </form>
        <?php 
    }
Example #12
0
 public function testPost()
 {
     $date = new \DateTime();
     $post = new Post(123, 1, 'A post', 'Some content', 2, $date, 1, 0);
     $this->assertEquals(123, $post->getID());
     $this->assertEquals('A post', $post->getTitle());
     $this->assertEquals('Some content', $post->getContent());
     $this->assertEquals(2, $post->getVisibility());
     $this->assertEquals($date, $post->getDate());
 }