protected function loadOne($file)
 {
     $xml = new SimpleXMLElement($file, 0, true);
     if ((string) $xml->head->title == null) {
         return null;
     }
     $article = new Article();
     foreach ($xml->head->meta as $meta) {
         $name = (string) $meta['name'];
         $content = (string) $meta['content'];
         switch ($name) {
             case 'date':
                 $article->setPublicationDate(new DateTime($content));
                 break;
             case 'author':
                 $article->setAuthor($content);
                 break;
         }
     }
     $article->setTitle((string) $xml->head->title);
     $article->setHash($this->getHash($article->getTitle()));
     $content = "";
     foreach ($xml->body->children() as $child) {
         $content .= $child->asXml();
     }
     $article->setContent($content);
     return $article;
 }
Example #2
0
 public function create($title, $content, User $user)
 {
     $article = new Article();
     $valide = $article->setContent($content);
     if ($valide === true) {
         $valide = $article->setUser($user);
         if ($valide === true) {
             $content = mysqli_real_escape_string($this->db, $article->getContent());
             $id_user = $article->getId_user();
             $query = "INSERT INTO article (title, content, id_user) VALUES('" . $title . "', '" . $content . "', '" . $id_user . "')";
             $res = mysqli_query($this->db, $query);
             if ($res) {
                 $id = mysqli_insert_id($this->db);
                 if ($id) {
                     return $this->findById($id);
                 } else {
                     return "Internal server error";
                 }
             } else {
                 echo 'test14';
                 exit;
                 return mysqli_error($this->db);
             }
         } else {
             return $valide;
         }
     } else {
         return $valide;
     }
 }
Example #3
0
 public function getArticleDetail($id)
 {
     $sqlHelper = new SqlHelper();
     $article = new Article();
     $sql = "select * from lavender_article where id={$id}";
     $res = $sqlHelper->dql_arr($sql);
     $article->setId($res[0]['id']);
     $article->setPraise($res[0]['praise']);
     $article->setContent($res[0]['content']);
     $article->setDate($res[0]['date']);
     $article->setReadTime($res[0]['read_time']);
     $article->setImg($res[0]['img']);
     $article->setNoPraise($res[0]['no_praise']);
     $article->setTitle($res[0]['title']);
     return $article;
 }
Example #4
0
 function executeRandomArticle()
 {
     $post = new Article();
     $arr = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
     for ($i = 0; $i < 6; $i = $i + 1) {
         $index = rand(0, Count($arr));
         $title = $title . $arr[$index];
     }
     $post->setTitle($title);
     for ($i = 0; $i < 30; $i = $i + 1) {
         $index = rand(0, Count($arr));
         $content = $content . $arr[$index];
     }
     $post->setContent($content);
     $post->save();
     $this->redirect('adminblog/index');
 }
Example #5
0
 public function testAction()
 {
     $article = new Article();
     $article->setTitle("L'histoire d'un bon weekend !");
     $article->setContent("Le weekend était vraiment trop bien !");
     $article->setCreatedAt(new \DateTime('now', new \DateTimeZone('Europe/Paris')));
     $article->setEnabled(true);
     $em = $this->getDoctrine()->getManager();
     $user = $this->getUser();
     if ($user) {
         $article->setUser($user);
     }
     $em->persist($article);
     $em->flush();
     $url = $this->generateUrl('suplol_user_homepage');
     return $this->redirect($url);
 }
Example #6
0
    public function create($title, $content, $image, $idAuthor)
    {
        $article = new Article($this->db);
        try {
            $article->setTitle($title);
            $article->setContent($content);
            $article->setImage($image);
            $article->setIdAuthor($idAuthor);
        } catch (Exception $e) {
            $errors = $e->getMessage();
            echo $errors;
        }
        if (!isset($err)) {
            $title = $this->db->quote($article->getTitle());
            $content = $this->db->quote($article->getContent());
            $idAuthor = $article->getIdAuthor();
            if ($image == "") {
                $query = 'INSERT INTO article(title, content, idAuthor)
						VALUE (' . $title . ',' . $content . ',' . $idAuthor . ')';
            } else {
                $image = $this->db->quote($article->getImage());
                $query = 'INSERT INTO article(title, content, image, idAuthor)
						VALUE (' . $title . ',' . $content . ',' . $image . ',' . $idAuthor . ')';
            }
        }
        $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 #7
0
<?php

include_once 'data/CategoryDAO.php';
include_once 'control/ArticleControls.php';
include_once 'business/Article.php';
$categoryDao = new CategoryDao();
$articleController = new ArticleControls();
$article = new Article();
$article->setName($_POST['title']);
$article->setId(intval($_POST['id']));
$article->setContent($_POST['editor']);
$article->setSumup($_POST['sumup_editor']);
$article->setTags($_POST['tags']);
$ret = $articleController->alterArticle($article);
if ($ret) {
    header("location:../news.php?art_id=" . $_POST['id']);
} else {
    echo "Unexpected exception";
}
Example #8
0
<?php

include_once 'business/Article.php';
include 'control/ArticleControls.php';
include_once 'business/Comment.php';
$article = new Article();
$control = new ArticleControls();
$article->setTitle($_POST['title']);
$article->setContent($_POST['category']);
// $article->setUser_name($_POST['name']);
// $article->setNews_id($_POST['id']);
// $article->setIp($_POST['ip']);
if ($control->addMail($article)) {
    header("location:../news.php?art_id=" . $_POST['id']);
} else {
    echo "La requête n'a pu être exécutée";
}
 public function __invoke($args)
 {
     if (count($args) < 2) {
         throw new OrongoScriptParseException("Arguments missing for Articles.SetContent()");
     }
     $article = new Article($args[0]);
     $article->setContent($args[1]);
 }
Example #10
0
     try {
         $article = new Article($id);
     } catch (Exception $e) {
         if ($e->getCode() == ARTICLE_NOT_EXIST) {
             header("Location: " . orongoURL("orongo-admin/manage.php?msg=0&obj=articles"));
             exit;
         } else {
             header("Location: " . orongoURL("orongo-admin/index.php?msg=2"));
             exit;
         }
     }
     if (!empty($_POST['title'])) {
         $article->setTitle($_POST['title']);
     }
     if (!empty($_POST['content'])) {
         $article->setContent($_POST['content']);
     }
     if (!empty($_POST['tags'])) {
         $tags = explode(",", trim($_POST['tags']));
         foreach ($tags as &$tag) {
             trim($tag);
         }
         $article->setTags($tags);
     }
     header("Location: " . orongoURL("orongo-admin/view.php?msg=1&obj=article&id=" . $article->getID()));
     exit;
     break;
 case "page":
     if (getUser()->getRank() < RANK_WRITER) {
         header("Location: " . orongoURL("orongo-admin/index.php?msg=0"));
         exit;
 /**
  * Run method with main page logic
  * 
  * Populate template and display form for creating a new article entry. For POST requests,
  * validate form data and save information to database. Available to admins only
  * @access public
  */
 public function run()
 {
     $session = Session::getInstance();
     $user = $session->getUser();
     if (!$user || !$user->isAdmin()) {
         $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
         header("Location: " . BASE_URL);
         return;
     }
     $form_errors = array();
     $form_values = array("title" => "", "content" => "", "postDate" => "", "published" => "", "tags" => "");
     $articleDAO = ArticleDAO::getInstance();
     $tagDAO = ArticleTagDAO::getInstance();
     if (!empty($_POST)) {
         $form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : "";
         $form_values["content"] = isset($_POST["content"]) ? trim($_POST["content"]) : "";
         $form_values["postDate"] = isset($_POST["postDate"]) ? trim($_POST["postDate"]) : "";
         $form_values["published"] = isset($_POST["published"]) ? trim($_POST["published"]) : "";
         $form_values["tags"] = isset($_POST["tags"]) ? trim($_POST["tags"]) : "";
         if (empty($form_values["title"])) {
             $form_errors["title"] = "No title specified";
         }
         if (empty($form_values["content"])) {
             $form_errors["content"] = "No content specified";
         }
         if (empty($form_values["postDate"])) {
             $form_errors["postDate"] = "No post date specified";
         } else {
             if (strtotime($_POST["postDate"]) == 0) {
                 $form_errors["postDate"] = "An invalid post date was specified";
                 $form_values["postDate"] = "";
             }
         }
         if ($form_values["published"] != "true" && $form_values["published"] != "false") {
             $form_errors["published"] = "Invalid published choice";
         }
         if (empty($form_errors)) {
             $article = new Article();
             $article->setTitle($form_values["title"]);
             $article->setContent($form_values["content"]);
             $article->setPostDate(strtotime($form_values["postDate"]));
             $article->setUpdateDate(0);
             $published = $form_values["published"] == "true" ? 1 : 0;
             $article->setPublished($published);
             $article->setUserId($user->id);
             //$article->setTags ($form_values["tags"]);
             $sorted_tag_array = ArticleTag::tagsFromString($form_values["tags"]);
             $sorted_tags = implode(" ", $sorted_tag_array);
             $article->setTags($sorted_tags);
             if ($articleDAO->insert($article)) {
                 $tagDAO->updateTags($article);
                 $session->setMessage("Article details saved");
                 header("Location: edit_article.php?id={$article->id}");
                 return;
             } else {
                 $session->setMessage("Article details could not be saved", Session::MESSAGE_ERROR);
             }
         }
     }
     $this->template->render(array("title" => "Create Article", "extra_header" => joinPath("headers", "jscal_header_tpl.php"), "main_page" => "create_article_tpl.php", "session" => $session, "form_errors" => $form_errors, "form_values" => $form_values));
 }
Example #12
0
<?php

require '../class/class_article.php';
if (isset($_POST) && !empty($_POST)) {
    $article = new Article();
    $article->setTitle($_POST['title']);
    $article->setContent($_POST["content"]);
    $article->setIdAuthor($_POST["idAuthor"]);
    $article->setIdDisaster($_POST["idDisaster"]);
    $disaster->setDateCreation(date("Y-m-d H:i:s"));
    $article->create();
    var_dump($article);
    exit;
}
Example #13
0
 private function formatContent(Article $article)
 {
     $var = $article->getContent();
     $var = str_replace("\n", "<br/>", $var);
     $article->setContent($var);
 }
 public function update($id)
 {
     try {
         $article = new Article($id);
         if (!UserHelper::isEditor()) {
             throw new fValidationException('not allowed');
         }
         $article->setType(fRequest::get('type'));
         $article->setTitle(fRequest::get('title'));
         $article->setContent(fRequest::get('content'));
         $article->setPriority(fRequest::get('priority', 'integer'));
         $article->setVisible(fRequest::get('visible', 'boolean'));
         $article->store();
         $this->ajaxReturn(array('result' => 'success', 'article_id' => $article->getId()));
     } catch (fException $e) {
         $this->ajaxReturn(array('result' => 'failure', 'message' => $e->getMessage()));
     }
 }
$t->is($human->getHumanRelatedByFatherId()->getName(), 'John', 'with() with self-referenced foreign keys hydrates the related objects');
$t->is(Propel::getConnection()->getLastExecutedQuery(), $sql, 'with() with self-referenced foreign keys avoids subsequent queries');

/******************************/
/* sfPropelFinder::withI18n() */
/******************************/

$t->diag('sfPropelFinder::withI18n()');

CommentPeer::doDeleteAll();
ArticlePeer::doDeleteAll();
ArticleI18nPeer::doDeleteAll();
$article1 = new Article();
$article1->setTitle('aaa');
$article1->setCulture('en');
$article1->setContent('english content');
$article1->setCulture('fr');
$article1->setContent('contenu français');
$article1->save();

$baseSQL = 'SELECT article.ID, article.TITLE, article.CATEGORY_ID, article_i18n.CONTENT, article_i18n.ID, article_i18n.CULTURE FROM article INNER JOIN article_i18n ON (article.ID=article_i18n.ID) ';
sfContext::getInstance()->getUser()->setCulture('en');
$finder = sfPropelFinder::from('Article')->
  withI18n();
$article = $finder->findOne();
$query = $baseSQL . 'WHERE article_i18n.CULTURE=\'en\' LIMIT 1';
$t->is($finder->getLatestQuery(), $query, 'withI18n() hydrates the related I18n object with a culture taken from the user object');
$t->is($article->getContent(), 'english content', 'withI18n() considers the current user culture for hydration');
$t->is(Propel::getConnection()->getLastExecutedQuery(), $query, 'withI18n() hydrates the i18n object so that no further query is necessary');

sfContext::getInstance()->getUser()->setCulture('fr');
$article = $finder->findPk(76543787654);
$t->is($article, null, 'findPk() returns null if the primary key is not found');
$finder = new sfPropelFinder('Article');
$articles = $finder->findPk(array($article2->getId(), $article1->getId()));
$t->ok(is_array($articles), 'findPk() returns an array of objects when passed an array of primary keys');
$t->is(count($articles), 2, 'findPk() returns the objects with the primary keys matching the arguments');

$article = $finder->with('Category')->findPk($article2->getId());
$t->cmp_ok(strpos($finder->getLatestQuery(), 'SELECT article.ID, article.TITLE, article.CATEGORY_ID, category.ID, category.NAME FROM article INNER JOIN category'), '===', 0, 'findPk() is compatible with with()');

ArticlePeer::doDeleteAll();

$article1 = new Article();
$article1->setTitle('foo');
$article1->setCulture('fr');
$article1->setContent('Bar');
$article1->save();
$articlei18n1 = $article1->getCurrentArticleI18n();
try
{
  $articleI18n = sfPropelFinder::from('ArticleI18n')->findPk($articlei18n1->getId());
  $t->fail('findPk() expects an array of values for objects with composite primary keys');
}
catch(Exception $e)
{
  $t->pass('findPk() expects an array of values for objects with composite primary keys');
}
$articleI18n = sfPropelFinder::from('ArticleI18n')->findPk(array($articlei18n1->getId(), $articlei18n1->getCulture()));
$t->ok($articleI18n->equals($articlei18n1), 'findPk() retrieves objects with composite primary keys based on an array of Pks');

$t->diag('Instanciation possibilities');