Example #1
0
 public function index($parameter = null)
 {
     $this->model('Article');
     /*
      * If no parameter is received then will be the index page.	
      */
     if (!$parameter) {
         $article = new Article();
         $data['bits'] = objectToArray($article->articleList('Bits', 'SECURL', 0, 10));
         $data['article'] = objectToArray($article->articleList(1, 'FEATURED', 0, 10));
         if (sizeof($data['article']) < 8) {
             $data['article'] = array_merge(objectToArray(objectToArray($article->articleList(0, 'TYPE', 0, 10))));
         }
         $data['username'] = "******";
         $data['TITLE'] = "Tech Stream";
         $data['DESCRIPTION'] = "Tech stream is a Web Design and Development blog dedicated to provide inspiring and innovative contents.";
         $this->view('home/index.html', $data);
     } else {
         /*
          *	In case of parameter the following checking has to be done : 
          *		1. If parameter is an article
          *		2. If parameter is a Page
          * 		1. If the parameter is name of section.
          */
         $article = new Article($parameter);
         /*
          *	If the Parameter represents Public URL of an entry then its a valid request
          */
         if ($article->count()) {
             $data = objectToArray($article->data());
             $data['CONTENT'] = str_replace('[IMAGE]', MEDIAPATH, $data['CONTENT']);
             $data['DESCRIPTION'] = $data['DES'];
             $data['CANONICAL'] = PUBLICPATH . $data['LINK'];
             $data['TITLE '] = $data['TITLE'] . "| Tech Stream";
             $data['sidebar']['article'] = objectToArray($article->articleList(0, 'TYPE', 0, 5));
             switch ($article->data()->TEMPLATE) {
                 case 0:
                     $this->view('home/article.html', $data);
                     break;
                 case 1:
                     $this->view('home/bits.html', $data);
                     break;
                 default:
                     $this->view('home/bits.html', $data);
                     break;
             }
         } else {
             $parameter = explode('/', $parameter);
             if ($parameter[0] == 'All') {
                 $targetParameter = 0;
                 $targetEntry = 'TEMPLATE';
             } else {
                 $targetParameter = $parameter[0];
                 $targetEntry = 'SECURL';
             }
             $section = $article->articleList($targetParameter, $targetEntry);
             $total = $article->count();
             if ($section) {
                 $data['start'] = 0;
                 $data['page'] = 1;
                 $data['limit'] = 10;
                 // Number of articles on a page
                 $data['sectionUrl'] = PUBLICPATH . $parameter[0];
                 $total = $article->count();
                 $data['totalArticle'] = $total;
                 if (!isset($parameter[1]) || $parameter[1] < 1) {
                     $parameter[1] = 1;
                 }
                 if (is_numeric($parameter[1])) {
                     $data['page'] = $parameter[1];
                     $data['start'] = $data['limit'] * ($parameter[1] - 1);
                     if ($data['start'] >= $total) {
                         // Redirect to 404
                         echo "no found";
                         die;
                     }
                 }
                 $data['sidebar']['article'] = objectToArray($article->articleList(0, 'TYPE', 0, 5));
                 $data['items'] = objectToArray($article->articleList($targetParameter, $targetEntry, $data['start'], $data['limit']));
                 if ($targetParameter) {
                     $data['TITLE'] = removeHyphen($data['items'][0]['SECURL']) . "| Tech Stream";
                 } else {
                     $data['TITLE'] = "All Articles" . "| Tech Stream";
                 }
                 $data['TOTAL'] = $total;
                 $data['DESCRIPTION'] = "Find out the list of articles and posts in : " . $data['TITLE'];
                 if ($data['items'][0]['TYPE'] == 1) {
                     $this->view('home/list.bits.html', $data);
                 } else {
                     $this->view('home/list.article.html', $data);
                 }
             } else {
                 $article = new Article('NotFound');
                 $data = objectToArray($article->data());
                 $data['CONTENT'] = str_replace('[IMAGE]', MEDIAPATH, $data['CONTENT']);
                 $data['sidebar']['article'] = objectToArray($article->articleList(0, 'TYPE', 0, 5));
                 $data['DESCRIPTION'] = $data['DES'];
                 $this->view('home/bits.html', $data);
             }
         }
     }
 }
Example #2
0
 public function post($post_id)
 {
     $this->model('User');
     $this->model('Article');
     $user = new User();
     $article = new Article();
     $this->loginRequired($user);
     // If new post is to be created
     if (empty($post_id) || $post_id == 'new') {
         if (Input::exists()) {
             $validate = new Validate();
             // Validation for Inputs
             $validation = $validate->check($_POST, array('title' => array('name' => 'Post title', 'required' => true, 'min' => 5), 'description' => array('name' => 'description', 'required' => true, 'min' => 50), 'featuredimage' => array('name' => 'Featured Image', 'required' => true), 'link' => array('name' => 'Article Link', 'required' => true, 'unique' => ARTICLE_TABLE)));
             if (empty(Input::get('type'))) {
                 $type = 0;
             } else {
                 $type = 1;
             }
             if ($validate->passed()) {
                 $template = Strings::get('catagory');
                 try {
                     $article->create(array('TITLE' => Input::get('title'), 'SECURL' => Input::get('catagory'), 'SUBSEC' => Input::get('subsec'), 'CREATED_DATE' => date("Y-m-d  H:i:s", time()), 'IMG' => Input::get('featuredimage'), 'DES' => Input::get('description'), 'LINK' => Input::get('link'), 'TYPE' => $type, 'TEMPLATE' => Input::get('template')));
                     // Get the created article details from LINK to redirect the user to edit it.
                     $newarticle = new Article(Input::get('link'));
                     Redirect::to(ADMINPATH . 'post/' . $newarticle->data()->SL_NO);
                 } catch (Exception $e) {
                     die($e->getMessage());
                 }
                 if (isset($data)) {
                     $submissionData = Input::values($_POST);
                     $data = array_merge($data, $submissionData);
                 } else {
                     $data = Input::values($_POST);
                 }
             } else {
                 $data = $validate->errors();
             }
         }
         if (isset($data)) {
             $submissionData = Input::values($_POST);
             $data = array_merge($data, $submissionData);
         } else {
             $data = Input::values($_POST);
         }
         $data['CATAGORY'] = Strings::get('catagory');
         $data['SUBCATAGORY'] = Strings::get('subcatagory');
         $data['TEMPLATES'] = Strings::get('templates');
         $data['token'] = Token::generate();
         $data['TITLE'] = "Create New Post";
         $this->view('admin/post.new.html', $data);
     } else {
         /** 
          * Edit Post section
          * 
          * The edit and after creation events happen here
          */
         $article = new Article($post_id);
         if (Input::exists()) {
             $validate = new Validate();
             // Validation for Inputs
             $validation = $validate->check($_POST, array('title' => array('name' => 'Post title', 'required' => true, 'min' => 5), 'description' => array('name' => 'description', 'required' => true, 'min' => 50), 'featuredimage' => array('name' => 'Featured Image', 'required' => true)));
             // If Article URL is changed check if it already exist
             if ($validate->passed() && $article->data()->LINK != Input::get('link')) {
                 $validation = $validate->check($_POST, array('link' => array('name' => 'Article Link', 'required' => true, 'unique' => ARTICLE_TABLE)));
             }
             if (empty(Input::get('type'))) {
                 $type = 0;
             } else {
                 $type = 1;
             }
             if (empty(Input::get('featured'))) {
                 $featured = 0;
             } else {
                 $featured = 1;
             }
             if (Input::get('publish') == 1) {
                 $publish = $article->data()->STATUS ? 0 : 1;
             } else {
                 $publish = $article->data()->STATUS;
             }
             if ($validation) {
                 $template = Strings::get('catagory');
                 try {
                     $article->update(array('TITLE' => Input::get('title'), 'SECURL' => Input::get('catagory'), 'SUBSEC' => Input::get('subsec'), 'CONTENT' => Input::get('content'), 'DATE' => Input::get('date'), 'IMG' => Input::get('featuredimage'), 'DES' => Input::get('description'), 'LINK' => Input::get('link'), 'TYPE' => $type, 'TEMPLATE' => Input::get('template'), 'FEATURED' => $featured, 'STATUS' => $publish), $post_id);
                     Redirect::to(ADMINPATH . 'post/' . $post_id);
                 } catch (Exception $e) {
                     die($e->getMessage());
                 }
                 if (isset($data)) {
                     $submissionData = Input::values($_POST);
                     $data = array_merge($data, $submissionData);
                 } else {
                     $data = Input::values($_POST);
                 }
             } else {
                 $data = $validate->errors();
             }
         }
         if ($article->count()) {
             if (isset($data)) {
                 $data = array_merge($data, objectToArray($article->data()));
             } else {
                 $data = objectToArray($article->data());
             }
             $data['CATAGORY'] = Strings::get('catagory');
             $data['SUBCATAGORY'] = Strings::get('subcatagory');
             $data['TEMPLATES'] = Strings::get('templates');
             $data['CONTENT_RAW'] = $data['CONTENT'];
             $data['CONTENT'] = str_replace('[IMAGE]', MEDIAPATH, $data['CONTENT']);
             $data['CONTENT'] = $data['CONTENT'];
             $data['token'] = Token::generate();
             $this->view('admin/post.html', $data);
         }
     }
 }