Example #1
0
 public function indexAction()
 {
     $this->tag->setTitle('Quản lý bài viết');
     $news = News::find(array('order' => 'id DESC'));
     $currentPage = $this->request->getQuery("page", "int") > 0 ? $this->request->getQuery("page", "int") : 1;
     // Create a Model paginator, show 10 rows by page starting from $currentPage
     $paginator = new PaginatorModel(array("data" => $news, "limit" => 10, "page" => $currentPage));
     // Get the paginated results
     $page = $paginator->getPaginate();
     $this->view->setVar('page', $page);
     // Change active
     $params = $this->request->getPost();
     $id = isset($params['id']) ? $params['id'] : '';
     $active = isset($params['active']) ? $params['active'] : '';
     if ($active == 1) {
         $active = 2;
     } else {
         if ($active == 2) {
             $active = 1;
         }
     }
     if ($id != null) {
         $news = News::findFirst($id);
         $news->active = $active;
         $news->save();
     }
 }
 public function indexAction($id)
 {
     if ($id) {
         $detail = News::findFirst("id =" . $id);
         $this->view->setVar("detail", $detail);
     } else {
     }
 }
Example #3
0
 public function showAction()
 {
     $title = $this->_getSanizitedTitleId();
     $new = News::findFirst("short_title='{$title}'");
     if ($new == false) {
         return $this->_forward('index/index');
     }
     $activeYear = $this->filter->sanitize($this->_getParam('year'), "int");
     Phalcon_Tag::setTitle($new->title);
     $this->view->setVar("new", $new);
     $this->view->setVar("activeYear", $activeYear);
     $this->view->setVar("years", News::count(array('group' => 'year')));
 }
Example #4
0
 public function showAction()
 {
     $title = $this->_getSanizitedTitleId();
     $language = $this->session->get("language");
     $exists = $this->view->getCache()->exists($language . $title);
     if (!$exists) {
         $new = News::findFirst("short_title='{$title}'");
         if ($new == false) {
             $this->flash->error('The post cannot be found');
             return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
         }
         $activeYear = $this->dispatcher->getParam('year', "int");
         Phalcon\Tag::setTitle($new->title);
         $this->view->setVar("new", $new);
         $this->view->setVar("activeYear", $activeYear);
         $this->view->setVar("years", News::count(array('group' => 'year')));
     }
     $this->view->cache(array("lifetime" => 86400, "key" => $language . $title));
 }
Example #5
0
    $dataEntry["content"] = str_replace('default:', '', $domContent->saveHTML());
    $dataEntry["categories"] = array();
    $categories = $entry->getElementsByTagName("category");
    foreach ($categories as $category) {
        $dataEntry["categories"][$category->getAttribute("term")] = $category->getAttribute("label");
    }
    $entries[] = $dataEntry;
}
$modelManager = new Phalcon_Model_Manager();
$modelManager->setModelsDir(__DIR__ . '/' . $config->phalcon->modelsDir);
Phalcon_Db_Pool::setDefaultDescriptor($config->database);
foreach ($entries as $entry) {
    $shortTitle = preg_replace('/[ ]+/', '-', $entry['title']);
    $shortTitle = strtolower(preg_replace('/[^a-zA-Z0-9\\-]/', '', $shortTitle));
    $shortTitle = preg_replace('/[\\-]+/', '-', $shortTitle);
    $news = News::findFirst("short_title='{$shortTitle}'");
    if ($news == false) {
        $news = new News($modelManager);
        $news->language = 'en';
        $news->short_title = $shortTitle;
        $news->title = $entry['title'];
        $published = date_parse($entry['published']);
        $news->published = mktime($published['hour'], $published['minute'], $published['second'], $published['month'], $published['day'], $published['year']);
        $news->year = $published['year'];
        $updated = date_parse($entry['updated']);
        $news->updated = mktime($updated['hour'], $updated['minute'], $updated['second'], $updated['month'], $updated['day'], $updated['year']);
        $news->content = addslashes($entry['content']);
        if ($news->save() == false) {
            foreach ($news->getMessages() as $message) {
                echo 'Error while inserting News: ', $message->getMessage(), PHP_EOL;
                return;
 public function addAction()
 {
     $request = $this->request;
     if (!$request->isPost()) {
     }
     $this->view->disable();
     //判断是编辑还是添加
     if ($request->getPost("newsid") != '') {
         $news = News::findFirst("id =" . $request->getPost("newsid"));
         if ($this->request->hasFiles('fileDataFileName') == true) {
             $fileName = date('Ymd');
             if (!file_exists(APP_PATH . '/public/files/' . $fileName)) {
                 mkdir(APP_PATH . '/public/files/' . $fileName);
             }
             foreach ($this->request->getUploadedFiles() as $file) {
                 $getType = explode('.', $file->getName());
                 $imageName = date('YmdHis') . "." . $getType[count($getType) - 1];
                 if ($getType[count($getType) - 1] != '') {
                     $file->moveTo(APP_PATH . '/public/files/' . $fileName . '/' . $imageName);
                     $news->thumb = '/files/' . $fileName . '/' . $imageName;
                 }
             }
         }
         $news->typeid = $request->getPost("typeid");
         $news->title = $request->getPost("title");
         $news->description = $request->getPost("description");
         $news->content = $request->getPost("content");
         if ($news->save()) {
             $this->flash->notice("保存成功!");
         } else {
             foreach ($news->getMessages() as $message) {
                 $this->flash->error((string) $message);
             }
         }
     } else {
         $news = new News();
         if ($this->request->hasFiles('fileDataFileName') == true) {
             $fileName = date('Ymd');
             if (!file_exists(APP_PATH . '/public/files/' . $fileName)) {
                 mkdir(APP_PATH . '/public/files/' . $fileName);
             }
             foreach ($this->request->getUploadedFiles() as $file) {
                 $getType = explode('.', $file->getName());
                 $imageName = date('YmdHis') . "." . $getType[count($getType) - 1];
                 if ($getType[count($getType) - 1] != '') {
                     $file->moveTo(APP_PATH . '/public/files/' . $fileName . '/' . $imageName);
                     $news->thumb = '/files/' . $fileName . '/' . $imageName;
                 } else {
                     $news->thumb = '/img/test.jpg';
                 }
             }
         }
         $news->typeid = $request->getPost("typeid");
         $news->title = $request->getPost("title");
         $news->description = $request->getPost("description");
         $news->content = $request->getPost("content");
         $news->username = '******';
         $news->inputtime = time();
         $news->updatetime = time();
         $news->status = 0;
         if ($news->save()) {
             $this->flash->notice("保存成功!");
         } else {
             foreach ($news->getMessages() as $message) {
                 $this->flash->error((string) $message);
             }
         }
     }
 }