123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593 |
- <?php namespace App\Controllers;
- use CodeIgniter\Controller;
- use \App\Models\BlogModel;
- use \App\Andy\Utility;
- use \App\Andy\ImgPreCheck;
- use CodeIgniter\I18n\Time;
- use \App\Andy\BlogManager;
- class Blog extends BaseController
- {
-
- protected $blogId;
- protected $myDate;
- protected $myTime;
- protected $blogImages="blogImages";
- public function __construct()
- {
- parent::__construct();
- $this->myTime = parent::getTime();
- $this->myDate= date("d/m/Y",$this->myTime);
-
- }
- public function altMethod()
- {
-
- $BlogHandle = new BlogManager(model(BlogModel::class));
-
- $result= $BlogHandle->list();
- var_dump($result);
-
- echo "place holder for trying dependency injection";
-
- }
-
- public function doCount()
- {
- $handle = new BlogModel();
- $mycount= $handle->count();
- }
- public function doPaginate()
- {
-
- $handle = new BlogModel();
- $newresult = $handle->getDesending();
-
- //$result= $handle->getAll();
- $data = [
- 'title'=>'paginate',
- //'blogs' => $handle->paginate(5),
- 'blogs'=>$newresult->paginate(5),
- 'pager' => $handle->pager,
- 'date'=>$this->myDate
- ];
-
-
-
- echo view('listBlogsPaginate',$data);
-
-
-
- }
-
- public function showArticle($theSlug)
-
- {
-
-
-
-
-
- $handle = new BlogModel();
- $result= $handle->getArticle($theSlug);
-
- $data =[
- 'title'=>$theSlug,
- 'blog'=>$result,
- 'date'=>$this->myDate
- ];
-
-
- echo view('blogArticle',$data);
-
-
-
- }
-
-
- public function listBlogs()
-
-
- {
-
- $handle = new BlogModel();
- $result= $handle->getAll();
- $data =[
- 'title'=>'andything',
- 'blogs'=>$result,
- 'date'=>$this->myDate
- ];
-
-
- echo view('listBlogs',$data);
-
-
-
-
- }
-
-
-
-
-
-
-
- public function blogForm()
- {
- // displays form to submit newblog
-
-
-
- $data =[
- 'title'=>'new blog',
- 'info'=>' ',
- 'date'=>$this->myDate
- ];
-
-
- echo view('form4',$data);
-
-
-
- }
-
-
-
-
- public function newBlogArticle()
- {
-
-
-
-
- //accepts post data from form4 and processes form submission of data for new blog
- //what im going to do is filter out bad chars
- $title = $this->request->getVar('title');
- $date= $this->request->getVar('date');
-
-
- $article = $this->request->getVar('article');
-
-
- //now to remove ALL bad chars, can always do an edit
-
- $utilityHandle= new Utility();
-
- $cleanTitle=$utilityHandle->badCharsRemoveAll($title);
- $cleanDate= $utilityHandle->badCharsRemoveAll($date);
-
- $cleanArticle1 = $utilityHandle->removeScript($article);
- $cleanArticle2= $utilityHandle->convertQuotes($cleanArticle1);
- $cleanArticle = $utilityHandle->newRegex($cleanArticle2);
-
-
-
-
-
- $file = $this->request->getFile('userfile');
- $name= $file->getName();
- $tempfile = $file->getTempName();
- $slug= url_title($cleanTitle);
-
-
-
-
-
- //nowsome pre checks
- $handle = new ImgPreCheck();
- //ImgPreCheck is one of my classes
-
-
-
-
- $logic = $handle->allReadyExists($this->blogImages,$name);
- if($logic == "true")
-
- {
- $data =[
- 'title'=>'andything',
- 'info'=>'image with that name already exists',
- 'date'=>$this->myDate
- ];
-
-
- echo view('form4',$data);
-
- exit();
- }
-
-
- $logic2 = $handle->extCheck($name);
-
- if($logic2 == 0)
-
- {
-
- $data =[
- 'title'=>'andything',
- 'info'=>'that is not an image file',
- 'date'=>$this->myDate
- ];
-
- echo view('form4',$data);
-
- exit();
-
- }
-
-
-
- $size= $handle->getFileSize($tempfile);
-
- if($size > 500000)
-
- {
- $data =[
- 'title'=>'andything',
- 'info'=>'thats too large an image file',
- 'date'=>$this->myDate
- ];
-
-
- echo view('form4',$data);
-
- exit();
-
- }
-
-
-
-
-
- try{
-
- $file->move('blogImages',$name);
- $handle = new BlogModel();
- $blogLogic= $handle->insertBlog($cleanTitle,$cleanArticle,$name,$slug,$cleanDate);
-
- }
-
- catch ( \Exception $e)
- {
-
-
-
-
-
-
- $data = [
- 'title' => 'info',
-
- 'info'=>'somwething went wrong with new blog $e->getMessage(); ',
- 'date'=>$this->myDate
- ];
-
- echo view('info', $data);
-
-
-
- die();
- //above try catch works
-
-
-
- }
-
-
-
- if ($blogLogic == true)
-
-
- {
-
-
-
-
- $data =[
- 'title'=>'blog submission',
- 'info'=>'looks like new blog was created ',
- 'date'=>$date
- ];
-
-
- echo view('info',$data);
-
- exit();
-
- }
-
-
-
-
- }//end new blog
-
- public function delBlogForm()
- {
-
- $myTime = new Time('now');
- $date= $myTime->toLocalizedString('MMM d, yyyy');
-
-
-
- helper('form');
- helper('html');
-
- $handle = New BlogModel();
- $result= $handle->getAll();
-
-
-
- $data =[
- 'title'=>'andything',
- 'blogList'=>$result,
- 'info'=> '',
- 'date'=>$this->myDate
-
-
- ];
-
-
- echo view('removeBlogForm',$data);
-
-
- //end of newblog below
-
- }
-
- public function delBlog()
-
- {
- $myTime = new Time('now');
- $date= $myTime->toLocalizedString('MMM d, yyyy');
-
-
- helper('uri');
- helper('html');
- helper('form');
- helper('security');
- $this->blogId = $this->request->getVar('BlogId');
- $handle= new BlogModel();
- $result= $handle->getOneToDel($this->blogId);
-
- if($result==null)
- {
-
-
- $handle= new BlogModel();
- $result= $handle->getAll();
-
-
- $data = [
- 'title' => 'del ',
- 'blogList'=>$result,
- 'info'=>'no such item ',
- 'date'=>$this->myDate
- ];
-
-
- echo view('removeBlogForm',$data);
-
- exit();
-
- }
-
-
-
-
-
-
- $image= $result['image'];
- //first get rid of image
-
- try
- {
- // chmod(ROOTPATH.'public/blogImages/'.$image,0777);
-
-
- unlink(ROOTPATH.'public/blogImages/'.$image);
- //now need to remove entry from databse
- $logic= $handle->deleteOne($this->blogId);
-
- }
-
- catch ( \Exception $e)
- {
- $data = [
- 'title' => 'info',
-
- 'info'=>'somwething went wrong with deleting blog'.$e->getMessage(),
- 'date'=>$date
- ];
-
- echo view('info', $data);
-
-
-
- die();
- //above try catch works
- }
-
-
-
-
- if ($logic == True)
- {
- $data =[
- 'title'=>'del blog',
- 'info'=>'lookes like blog was deleted ',
- 'date'=>$this->myDate
-
- ];
-
-
- echo view('admin',$data);
-
-
- }
-
- }
-
-
- public function editBlogForm()
- {
- //will try utility class to strip bad chars
-
- //here another approach is to first convert all quotes to html entitiy
- //then in a second round remove bad chars
- $handle = new BlogModel();
- $result= $handle->getAll();
- $data =[
- 'title'=>'andything',
- 'blogs'=>$result,
- 'date'=>$this->myDate
- ];
-
-
- echo view('editBlogForm',$data);
-
-
-
- }
-
-
-
-
- public function editBlog($slug)
-
- {
-
-
-
- $handle= new BlogModel();
- $result= $handle->getArticle($slug);
-
-
-
- $data =[
- 'title'=>'andything',
- 'blog'=>$result,
- 'date'=>$this->myDate
- ];
-
-
- echo view('doEditBlog',$data);
-
-
-
- }
-
-
-
- public function processEditBlog()
-
- {
-
-
-
-
-
- $title = $this->request->getVar('title');
- $article = $this->request->getVar('article');
- $blogId= $this->request->getVar('Id');
- $slug= url_title($title);
-
- $utilityHandle= new Utility();
-
- $cleanTitle=$utilityHandle->badCharsRemoveAll($title);
-
- $cleanArticle1 = $utilityHandle->removeScript($article);
- $cleanArticle2= $utilityHandle->convertQuotes($cleanArticle1);
- $cleanArticle3 = $utilityHandle->newRegex($cleanArticle2);
-
-
-
-
-
- try
- {
- $handle= new BlogModel();
-
- $result= $handle->amendBlog($blogId,$cleanTitle,$cleanArticle3,$slug);
- }
-
- catch ( \Exception $e)
- {
- $data = [
- 'title' => 'info',
-
- 'info'=>'somwething went wrong with editing blog ',
- 'date'=>$this->myDate
- ];
-
- echo view('info', $data);
-
-
-
-
- die();
- //above try catch works
- }
-
-
-
-
-
- if ($result == 1)
- {
-
-
- $data =[
- 'title'=>'blog result',
- 'info'=>'lookes like edit of blog was successful',
- 'date'=>$this->myDate
- ];
-
-
- echo view('info',$data);
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
-
-
-
-
- }
|