home
/
zktecojo
/
public_html
/
app
/
controllers
➕ New
📤 Upload
✎ Editing:
BaseController.php
← Back
<?php include('htmlpurifier/library/HTMLPurifier.auto.php'); //include('library/SimpleImage.php'); class BaseController extends Controller { /** * Setup the layout used by the controller. * * @return void */ protected $data; protected $parentID; protected $parentMenuAlias=false; protected $parentMenuLevel; protected $HTMLPurifier; protected $staticSlugs; protected $breadCrumbs = array(); protected $baseLanguage ='en'; protected $loggedUserType ; public function __construct(){ // $this->under_maintenace();exit; // echo 'DD';exit(); $this->admin_settings(); $this->get_menus(); $this->ismobile(); $this->get_product_menus(); $this->get_download_menus(); $this->get_footer_menu(); $this->get_footer_aboutus(); $this->get_footer_products(); $this->staticSlugs=array('products','news','events','training','contact-us','online-support','download','faq','enquiry','newsletter','privacy-policy','terms-condition'); $this->get_footer_download(); $this->get_footer_press(); $this->set_multi_language(); $this->get_website_settings(); $this->data['pageTitle'] = ''; //$this->data['websiteSettings']->sitename.'::'; $this->data['current_menu']=''; $this->parentMenuLevel=0; $HTMLPurifierConfig = HTMLPurifier_Config::createDefault(); $this->HTMLPurifier = new HTMLPurifier($HTMLPurifierConfig); // dd($this->HTMLPurifier); $this->data['HTMLPurifier'] = $this->HTMLPurifier; $this->data['breadCrumbs'] = ''; $this->data['isNewsletterSubscribed'] = false; $temp = Cookie::get('fngSubscribe'); // echo $temp; // exit() if(!empty($temp)){ $this->data['isNewsletterSubscribed'] = true; } if( Auth::user() ){ $this->loggedUserType = ( Auth::user()->is_super_admin == "1" ? 'SUPERADMIN':'' ); } $this->data['userFormData'] = Session::get('downloadFormData'); // $this->parent // echo "<pre>"; // print_r($this->data); // exit(); // echo Purifier::clean('<a href="#">Test');exit(); // Artisan::call('composer require ezyang/htmlpurifier'); // exit(); $this->get_admin_page_list(); } protected function setupLayout() { if ( ! is_null($this->layout)) { $this->layout = View::make($this->layout); } } private function get_website_settings(){ $this->data['websiteSettings'] = DB::table('setting')->first(); } protected function custom_message($message,$type){ if($type=='success'){ $message = '<div class="alert alert-success alert-dismissable"><i class="fa fa-check"></i> <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button><b>'.$message.'</b></div>'; }elseif($type=='error'){ $message = '<div class="alert alert-danger alert-dismissable"><i class="fa fa-ban"></i> <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button><b>'.$message.'</b></div>'; } return $message; } protected function is_admin_login(){ $this->beforeFilter(function(){ if(!Auth::user() ){ return Redirect::to('/admin'); } // $credentials = array("email"=>Auth::user()->email,"is_admin"=>1); // if (!Auth::validate($credentials)){return Redirect::to('/admin'); } }); } protected function starts_with($haystack, $needle) { // search backwards starting from haystack length characters from the end return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE; } protected function ends_with($haystack, $needle) { // search forward starting from end minus needle length characters return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE); } protected function get_admin_page_list(){ $mainMenus = DB::table('pages') // ->where('page_status','=',1) ->where('page_parent_id','=',0) ->where('page_type','=',1) ->orderBy('page_priority','asc') ->get(); $this->data['pageTreeAdmin'] = $this->get_all_child_menus_for_admin($mainMenus); } protected function get_all_child_menus_for_admin(&$menus){ foreach($menus as &$main){ $main->childrens = DB::table('pages') // ->where('page_status','=',1) ->where('page_parent_id','=',$main->page_id) ->orderBy('page_priority','asc') ->get(); $this->get_all_child_menus_for_admin($main->childrens); } return $menus; } protected function get_menus(){ $mainMenus = DB::table('pages') ->where('page_status','=',1) ->where('page_parent_id','=',0) ->where('page_type','=',1) ->where('not_include_in_menu','=',0) ->orderBy('page_priority','asc') ->get(); $this->data['menuTree'] = $this->get_all_child_menus($mainMenus); } protected function get_product_menus(){ $mainMenus = DB::table('pages') ->where('page_status','=',1) ->where('page_parent_id','=',1) ->where('page_type','=',1) ->orderBy('page_priority','asc') ->get(); $this->data['menuProductTree'] = $this->get_all_child_menus($mainMenus); } protected function get_download_menus(){ $mainMenus = DB::table('pages') ->where('page_status','=',1) ->where('page_parent_id','=',22) ->where('page_type','=',1) ->orderBy('page_priority','asc') ->get(); $this->data['menuDownloadTree'] = $this->get_all_child_menus($mainMenus); } protected function get_validator_messages($validator){ $messages = $validator->messages(); $str ='<ul class="validation_errors">'; foreach ($messages->all('<li>:message</li>') as $message){ $str .= $message; } $str .='</ul>'; $this->data['messages'] =$this->custom_message($str,'error'); } protected function get_top_parent($alias){ $parent = DB::table('pages') ->where('page_status','=',1) ->where('page_slug','=',$alias) ->first(); if(empty($parent)) return $this->parentMenuAlias; $this->breadCrumbs[] = array( 'pageName'=> (($this->data['lang']=='ar')?$parent->page_name_arabic:$parent->page_name), 'pageAlias'=> $parent->page_slug, ); $this->parentID = $parent->page_parent_id; if($this->parentMenuLevel==0 && $this->parentID==0){ return $parent->page_slug; } $this->parentMenuLevel++; if( $this->parentID > 0 ){ $parent = DB::table('pages') ->where('page_status','=',1) ->where('page_id','=',$parent->page_parent_id) ->first(); // $this->parentID = $parent->page_parent_id; $this->parentMenuAlias = $parent->page_slug; $this->get_top_parent($this->parentMenuAlias); } return $this->parentMenuAlias; } protected function get_top_parent_sidebar($alias){ $parent = DB::table('pages') ->where('page_status','=',1) ->where('page_slug','=',$alias) ->first(); if(empty($parent)) return $this->parentMenuAlias; $this->parentID = $parent->page_parent_id; if($this->parentMenuLevel==0 && $this->parentID==0){ return $parent->page_slug; } $this->parentMenuLevel++; if( $this->parentID > 0 ){ $parent = DB::table('pages') ->where('page_status','=',1) ->where('page_id','=',$parent->page_parent_id) ->first(); $this->parentMenu = (($this->data['lang']=='ar')?$parent->page_name_arabic:$parent->page_name); $this->parentMenuAlias = $parent->page_slug; $this->get_top_parent_sidebar($this->parentMenuAlias); } return $this->parentMenu; } protected function get_nearest_parent($alias){ $temp = DB::table('pages') ->where('page_status','=',1) ->where('page_slug','=',$alias) ->orderBy('page_priority','asc') ->first(); if(empty($temp)) return false; $parnt = DB::table('pages') ->where('page_status','=',1) ->where('page_id','=',$temp->page_parent_id) ->orderBy('page_priority','asc') ->first(); if(empty($parnt)) return false; return $parnt->page_slug; } protected function get_sub_menu($alias){ $mainMenus = DB::table('pages') ->where('page_status','=',1) ->where('page_slug','=',$alias) ->orderBy('page_priority','asc') ->get(); $this->data['subMenuParent'] = $alias; $this->data['subMenus'] = $this->get_all_child_menus($mainMenus); if(!empty($this->data['subMenus'][0])){ $this->data['subMenuParent'] = $this->data['subMenus'][0]->page_slug; $this->data['subMenus'] = $this->data['subMenus'][0]->childrens; } return $this->data['subMenus']; } protected function get_all_child_menus(&$menus){ foreach($menus as &$main){ $main->childrens = DB::table('pages') ->where('page_status','=',1) ->where('page_parent_id','=',$main->page_id) ->orderBy('page_priority','asc') ->get(); $this->get_all_child_menus($main->childrens); } return $menus; } protected function get_footer_menu(){ $mainMenus = DB::table('pages') ->where('page_status','=',1) ->where('is_footer_link','=',2) ->orderBy('page_priority','asc') ->get(); $this->data['footerMenu'] = $mainMenus; } protected function get_footer_aboutus(){ $mainMenus = DB::table('pages') ->where('page_status','=',1) ->where('page_parent_id','=',19) ->orderBy('page_priority','asc') ->get(); $this->data['footerAbout'] = $mainMenus; } protected function get_footer_products(){ $mainMenus = DB::table('pages') ->where('page_status','=',1) ->where('page_parent_id','=',1) ->orderBy('page_priority','asc') ->get(); $this->data['footerProduct'] = $mainMenus; } protected function get_footer_download(){ $mainMenus = DB::table('pages') ->where('page_status','=',1) ->where('page_parent_id','=',22) ->orderBy('page_priority','asc') ->get(); $this->data['footerdownload'] = $mainMenus; } protected function get_footer_press(){ $mainMenus = DB::table('pages') ->where('page_status','=',1) ->where('page_parent_id','=',15) ->orderBy('page_priority','asc') ->get(); $this->data['footerpress'] = $mainMenus; } protected function admin_settings(){ $this->data['admin_settings'] = DB::table('setting')->first(); $this->data['pageTitle'] = ''; } public function set_multi_language(){ $lang = Session::get('lang'); if(empty($lang)){ $lang='en';} Session::put('lang', $lang); App::setLocale($lang); $this->data['lang'] = $lang; // echo $lang; } /* protected function remapProjectCategoryArray($arr,$insertID){ $returnArr = array(); if(!empty($arr)){ foreach($arr as $dom){ $returnArr[] = array( 'pid_image_id'=>$insertID, 'pid_cat_id'=>$dom, ); } } return $returnArr; } */ protected function send_mail($settings,$data,$attachment=null,$template='email_template.email_message_contact'){ // dd($data); Mail::send($template, $data, function($message) use ($settings){ $message->from($settings['from']); if ($settings['cc']) { $message->to($settings['to'])->subject($settings['subject'])->cc($settings['cc']); } else { $message->to($settings['to'])->subject($settings['subject']); } if(!empty($settings['attachment'])){ $message->attach($settings['attachment']); } }); } protected function send_career_mail($settings,$data,$attachment=null,$template='email_template.email_message'){ // dd($data); Mail::send($template, $data, function($message) use ($settings){ $message->from($settings['from']); $message->to($settings['to'])->subject($settings['subject']);//->cc('bar@example.com'); if(!empty($settings['attachment'])){ $message->attach($settings['attachment']); } }); } protected function resize_and_crop_image($controlName,$destinationPath,$dimensions=array(),$oldFileName=''){ // if(empty($dimensions)) return false; if(empty($destinationPath)) return false; if(empty($controlName)) return false; if (!Request::hasFile($controlName)) return false; // check whether file is uploaded if(!Request::file($controlName)->isValid()) return false; // chek whether file is valid` $file = Input::file($controlName); $extension = $file->getClientOriginalExtension(); $filename = md5(date('Y-m-d-H:i:s')."-".$file->getClientOriginalName()).'.'.$extension; $imageUpload = Input::file($controlName) ->move($destinationPath, $filename); $sourceImage = $destinationPath.DIRECTORY_SEPARATOR.$filename; if(!empty($dimensions)){ foreach($dimensions as $dim){ if (!File::isDirectory($destinationPath.'/'.$dim['folder']."/")){ // echo $destinationPath.'/'.$dim['folder']."/";exit(); File::makeDirectory($destinationPath.'/'.$dim['folder']); } /* $img = new SimpleImage($sourceImage); $img->resize($dim['width'],$dim['height'])->save($destinationPath.'/'.$dim['folder'].'/'.$filename); */ Image::make($sourceImage) ->fit($dim['width'],$dim['height']) ->save($destinationPath.'/'.$dim['folder'].'/'.$filename) ->destroy(); } } if(!empty($oldFileName) && File::exists($destinationPath.'/'.$oldFileName) ){ // echo "DDD";exit(); File::delete($destinationPath.'/'.$oldFileName); foreach($dimensions as $dim){ File::delete($destinationPath.'/'.$dim['folder'].'/'.$oldFileName); } } // echo $destinationPath.'/'.$oldFileName."DD";exit(); return $filename; } protected function create_breadcrumbs(){ if(empty($this->breadCrumbs)) return; $temp = array_reverse($this->breadCrumbs); // dd($temp); $this->data['breadCrumbs'] .= '<ul class="breadcrumbs">'; $this->data['breadCrumbs'] .= '<li><a href="'.asset('/').'" class="homebrc">'.(($this->data['lang']=='ar')?'الصفحة الرئيسية':'Home').'</a> <span class="brc-expand"></span></li>'; $count = count($temp); $counter =0; foreach($temp as $breadC){ if($counter< ($count-1)){ $this->data['breadCrumbs'] .= '<li><a href="'.asset($breadC['pageAlias']).'">'.$breadC['pageName'].'</a><span class="brc-expand"></span></li>'; }else{ $this->data['breadCrumbs'] .= '<li class="current">'.$breadC['pageName'].'</li>'; } $counter++; } $this->data['breadCrumbs'] .= '</ul>'; } protected function mutiple_image_upload($file,$destinationPath,$dimensions=array(),$oldFileName=''){ // if(empty($dimensions)) return false; if(empty($destinationPath)) return false; if(empty($file)) return false; $extension = $file->getClientOriginalExtension(); $filename = md5(date('Y-m-d-H:i:s')."-".$file->getClientOriginalName()).'.'.$extension; $imageUpload = $file->move($destinationPath, $filename); $sourceImage = $destinationPath.DIRECTORY_SEPARATOR.$filename; if(!empty($dimensions)){ foreach($dimensions as $dim){ if (!File::isDirectory($destinationPath.'/'.$dim['folder']."/")){ // echo $destinationPath.'/'.$dim['folder']."/";exit(); File::makeDirectory($destinationPath.'/'.$dim['folder']); } Image::make($sourceImage) ->fit($dim['width'],$dim['height']) ->save($destinationPath.'/'.$dim['folder'].'/'.$filename) ->destroy(); /* $img = new SimpleImage($sourceImage); $img->resize($dim['width'],$dim['height'])->save($destinationPath.'/'.$dim['folder'].'/'.$filename); */ } } if(!empty($oldFileName) && File::exists($destinationPath.'/'.$oldFileName) ){ // echo "DDD";exit(); File::delete($destinationPath.'/'.$oldFileName); foreach($dimensions as $dim){ File::delete($destinationPath.'/'.$dim['folder'].'/'.$oldFileName); } } // echo $destinationPath.'/'.$oldFileName."DD";exit(); return $filename; } protected function pdf_upload($file,$destinationPath,$oldFileName=''){ if(!empty($file)){ //$filename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $filename = md5(date('Y-m-d-H:i:s')."-".$file->getClientOriginalName()).'.'.$extension; if(!empty($filename)){ $upload_success = $file->move($destinationPath, $filename); } return $filename; } } protected function ismobile(){ if(Agent::isMobile()){ $this->data['mobileView']=1; }else{ $this->data['mobileView']=0; } return $this->data['mobileView']; } protected function get_unique_slug($pageSlug){ if(in_array($pageSlug,$this->staticSlugs)){ return $pageSlug; } $this->pageSlug = $pageSlug; //echo "31".$this->pageSlug."<br/>"; $tempRes = DB::Table('pages') ->where(DB::Raw('TRIM(page_slug)'),'=',trim($this->pageSlug)); if(!empty($id)){ $tempRes = $tempRes->where('page_id','!=',$id); } $tempRes = $tempRes->first(); if(!empty($tempRes)){ $ttt = explode('-',$tempRes->page_slug); $newSlugCount = (int)end($ttt)+1; if($newSlugCount<2){ $ttt[count($ttt)] = $newSlugCount; }else{ $ttt[count($ttt)-1] = $newSlugCount; } $this->pageSlug = implode("-",$ttt); //echo "39". $this->pageSlug."<br/>";; $this->get_unique_slug($this->pageSlug); } //return "Return ".$this->pageSlug."<br/>";; return $this->pageSlug; } protected function get_unique_product_slug($pageSlug){ $this->pageSlug = $pageSlug; // echo "31".$this->pageSlug."<br/>"; $tempRes = DB::Table('products') ->where(DB::Raw('TRIM(product_alias)'),'=',trim($this->pageSlug)); $tempRes = $tempRes->first(); if(!empty($tempRes)){ $ttt = explode('-',$tempRes->product_alias); $newSlugCount = (int)end($ttt)+1; if($newSlugCount<2){ $ttt[count($ttt)] = $newSlugCount; }else{ $ttt[count($ttt)-1] = $newSlugCount; } $this->pageSlug = implode("-",$ttt); //echo "39". $this->pageSlug."<br/>";; $this->get_unique_slug($this->pageSlug); } // echo "Return ".$this->pageSlug."<br/>";exit; return $this->pageSlug; } public function under_maintenace(){ // echo $alias;exit(); //$this->data['pageTitle'] .= '404-Page Not Found'; return View::make('errors.maintenance',$this->data); } }
💾 Save Changes
Cancel
📤 Upload File
×
Select File
Upload
Cancel
➕ Create New
×
Type
📄 File
📁 Folder
Name
Create
Cancel
✎ Rename Item
×
Current Name
New Name
Rename
Cancel
🔐 Change Permissions
×
Target File
Permission (e.g., 0755, 0644)
0755
0644
0777
Apply
Cancel