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; }
function _addPost($data, $_debug) { if ($data["title"] == NULL) { $data["title"] = "No Title Entered."; } if ($data["text"] == NULL) { $data["text"] = "No Body Entered."; } if ($data["category"] == NULL) { $data["category"] = 1; } if ($data["user_id"] == NULL) { $data["user_id"] = 1; } if ($data["blog_id"] == NULL) { $data["blog_id"] = 1; } if ($data["status"] == NULL) { $data["status"] = POST_STATUS_PUBLISHED; } if ($data["comments"] == NULL) { $data["comments"] = true; } $articles = new Articles(); // verify that article does not exist in database $artss = $articles->getBlogArticles($data["blog_id"]); $exists = 0; foreach ($artss as $art) { if ($art->getTopic() == $data["title"]) { $exists = $art->getId(); break; } } /* $exists = $articles->getBlogArticleByTitle( TextFilter::urlize($data["title"]) , $data["blog_id"], true, -1 -1 -1, POST_STATUS_PUBLISHED ); if (!$exists) { $exists = $articles->getBlogArticleByTitle( TextFilter::urlize($data["title"]) , $data["blog_id"], true, -1 -1 -1, POST_STATUS_DRAFT ); } */ if (!$exists) { // verify that desired post id does not exist. Otherwise, create new id. if (!$articles->getUserArticle($data["id"])) { $post_id = $data["id"]; } if ($_debug) { print "--- --- adding post " . $data["title"] . " to db.<br />\n\r"; } $cat[0] = $data["category"]; $article = new Article($data["title"], $data["text"], $cat, $data["user_id"], $data["blog_id"], $data["status"], 0); if ($data["date"]) { $article->setDate($data["date"]); } if ($post_id) { $article->setId($post_id); } $article->setCommentsEnabled($data["comments"]); $artId = $articles->addArticle($article); $this->_stats["posts"]["write"]++; // remap comments to $artId if ($this->_container["comments"]) { foreach ($this->_t_container["comments"] as $comment => $val) { if ($this->container["comments"][$comment]["article_id"] == $data["id"] || $val["article_id"] == NULL) { $this->_container["comments"][$comment]["article_id"] = $artId; if ($_debug) { print "--- --- remapping comment entry #" . $comment . " to proper article id<br />\n\r"; } } } } } else { $artId = $exists; if ($_debug) { print "--- --- post already exists, aborting operation.<br />\n\r"; } } return $artId; }
function metaWeblogNewPost($args) { global $users, $articles, $category, $blogsG; $blogid = $args[0]; $username = $args[1]; $password = $args[2]; $content = $args[3]; $publish = $args[4]; // true post&publish | false post only /* int postid */ // -mhe todo security $erg = $users->getUserInfo($username, $password); if ($erg != false) { if ($publish) { $status = POST_STATUS_PUBLISHED; } else { $status = POST_STATUS_DRAFT; } // Get the default category //$cats = $category->getBlogCategories($blogid); //foreach($cats as $cat) //{ // $idCategory = $cat->_id; // // Stop here, we have a category // break; //} $title = $content["title"]; $body = $content["description"]; $catList = $content["categories"]; $categoryName = NULL; // // :KLUDGE: // not exactly the smartest and fastest bit of code ever but it seems to work :-) // $categories = array(); $cats = $category->getBlogCategories($blogid); if ($catList != NULL) { foreach ($catList as $categoryName) { foreach ($cats as $blogCategory) { if (strcmp($categoryName, $blogCategory->getName()) == 0) { $categories[] = $blogCategory->getId(); } } } } else { // if no category, let's pick a random one $blogCategory = array_pop($cats); $categories[] = $blogCategory->getId(); } $article = new Article($title, $body, $categories, $erg->_id, $blogid, $status, 0, array("comments_enabled" => true)); $dateCreated = $content['dateCreated']; // there must be a bug in the xmlrpc library, we're getting an object in $dateCreated // that does not have a type or anyhting, but it still is an object... kinda weird. Anyway, // clients like ecto do not allow to change the time an article is posted so this is not // too annoying, *yet* if (!empty($dateCreated)) { // Convert the UTC time to local time, since articleDate is in local time $ar = localtime($dateCreated->getTimestamp()); $ar[5] += 1900; $ar[4]++; $localTimeStamp = gmmktime($ar[2], $ar[1], $ar[0], $ar[4], $ar[3], $ar[5], $ar[8]); $articleDate = date("YmdHis", $localTimeStamp); } else { $articleDate = date("YmdHis"); } $article->setDate($articleDate); // Get the plugin manager $plugMgr =& PluginManager::getPluginManager(); $plugMgr->setBlogInfo($blogsG->getBlogInfo($blogid)); $plugMgr->setUserInfo($erg); $plugMgr->loadPlugins(); // Send the PRE_POST_POST_ADD message $plugMgr->notifyEvent(EVENT_PRE_POST_ADD, array("article" => &$article)); $postid = $articles->addArticle($article); if ($postid != 0) { // The post was successful // Send the EVENT_POST_POST_ADD messages to the plugins $plugMgr->notifyEvent(EVENT_POST_POST_ADD, array("article" => &$article)); CacheControl::resetBlogCache($blogid); return sprintf("%d", $postid); } else { return new IXR_Error(-1, 'Internal error occured creating your post!'); } } else { return new IXR_Error(-1, 'You did not provide the correct password'); } }
public function setDate($date) { $this->__load(); return parent::setDate($date); }
/** * @private */ function _fillArticleHeaderInformation($query_result, $includeHiddenFields = true) { $id = $query_result['id']; if (isset($this->cache[$id])) { return $this->cache[$id]; } // this is a little dirty trick or otherwise the old // that don't have the 'properties' field will not work // as they will appear to have comments disabled if ($query_result['properties'] == "") { $tmpArray = array('comments_enabled' => true); $query_result['properties'] = serialize($tmpArray); } // --- // this, i do not like... but I couldn't find a more // "elegant" way to arrange it! This makes this method // totally dependant on the blog configuration so it basically // means an additional query every time we fetch an article // (just in case we didn't have enough!) // --- // // if there's a time difference applied to all dates, then we'd better // calculate it here!! // if ($this->_blogInfo == null) { $blogId = $query_result['blog_id']; $this->_blogInfo = $this->blogs->getBlogInfo($blogId); $this->_blogSettings = $this->_blogInfo->getSettings(); $this->_timeDiff = $this->_blogSettings->getValue('time_offset'); } // we can use this auxiliary function to help us... $date = Timestamp::getDateWithOffset($query_result['date'], $this->_timeDiff); // postText does not exist here.. maybe a copy/paste problem? // anyway.. it works without postText, so i'll just set this to // null. oscar, pls double check.. original code: // $article = new Article( $postText['topic'], // $postText['text'], // NULL, $article = new Article(NULL, NULL, NULL, $query_result['user_id'], $query_result['blog_id'], $query_result['status'], $query_result['num_reads'], unserialize($query_result['properties']), $query_result['slug'], $query_result['id']); // and fill in all the fields with the information we just got from the db $article->setDate($date); $article->setTimeOffset($this->_timeDiff); $article->setBlogInfo($this->_blogInfo); $article->setUserInfo($this->users->getUserInfoFromId($query_result['user_id'])); return $article; }
function index() { $this->load->helper('text'); $this->load->helper('security'); //appel formulaire $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); //Regle de validation //appel de l'object if (isset($_POST['idArticle']) && !empty($_POST['idArticle'])) { $id = $_POST['idArticle']; //echo "id : ".$id."<br>"; $this->form_validation->set_rules('idArticle', 'Id de l\'article', 'trim'); $object = $this->doctrine->em->find('article', $id); } else { $object = new Article(); } if (isset($_POST['idUser']) && !empty($_POST['idUser'])) { //echo "idUser : "******"<br>"; $idUser = $_POST['idUser']; $this->form_validation->set_rules('idUser', 'Id de l\'utilisateur', 'trim'); $queryUser = $this->doctrine->em->createQuery("SELECT u\n\t\t\t\t\t\tFROM user u\n\t\t\t\t\t\tWHERE u.iduser="******"Recup : ".$_POST['langue']."<br>"; $postLangue = $_POST['langue']; $this->form_validation->set_rules('langue', 'Id de la langue', 'trim'); //Recuperation de l'objet dans la base; $langue = $this->doctrine->em->createQuery("SELECT l FROM langue l")->getResult(); foreach ($langue as $dataLg) { $test = utf8_encode($dataLg->getLangue()); //echo "Test : ".$test." = ".$postLangue."<br>"; if ($test == $postLangue) { //echo "-> this : ".$test." = OK <br>"; $object->setIdlangue($dataLg); } } } if (isset($_POST['date']) && !empty($_POST['date'])) { //echo "date : ".$_POST['date']."<br>"; $this->form_validation->set_rules('date', 'Date', 'trim'); $date = new DateTime($_POST['date']); $object->setDate($date); } if (isset($_POST['titre']) && !empty($_POST['titre'])) { //echo "titre : ".$_POST['titre']."<br>"; $this->form_validation->set_rules('titre', 'Titre', 'trim|min_length[5]|xss_clean'); $object->setTitre(utf8_decode($_POST['titre'])); } if (isset($_POST['texte']) && !empty($_POST['texte'])) { //echo "texte : ".$_POST['texte']."<br>"; $this->form_validation->set_rules('texte', 'texte', 'trim|min_length[5]|max_length[301]|xss_clean'); $object->setTexte(utf8_decode($_POST['texte'])); } if (isset($_POST['page']) && !empty($_POST['page']) && $_POST['page'] != "NULL") { //echo "page : ".$_POST['page']."<br>"; $idPage = $_POST['page']; $this->form_validation->set_rules('page', 'Id de la page', 'trim'); //Recuperation de l'objet dans la base; $page = $this->doctrine->em->find('page', $idPage); $object->setIdpage($page->getIdpage()); } if (isset($_POST['page']) && !empty($_POST['page']) && $_POST['page'] == "NULL") { $this->form_validation->set_rules('page', 'Id de la page', 'trim'); $object->setIdpage(NULL); } if ($this->form_validation->run() == FALSE) { //echo 'test false'; $titre = "Article"; $this->layout->set_titre($titre); $this->layout->th_default(); if (isset($id)) { $object = $this->doctrine->em->find('article', $id); $langues = $this->doctrine->em->createQuery("SELECT l FROM langue l")->getResult(); $this->load->view('article/vEdit', array('article' => $object, 'langues' => $langues)); } else { $langues = $this->doctrine->em->createQuery("SELECT l FROM langue l")->getResult(); $this->load->view('article/vAdd', array('article' => $object, 'langues' => $langues)); } } else { //echo 'test true'; $this->doctrine->em->persist($object); $this->doctrine->em->flush(); redirect('cArticle', 'refresh'); } }