File: /var/www/vhosts/creativefellows.nl/test.creativefellows.nl/nomor/classes/BaseController.php
<?php
class BaseController{
function __construct($settings,$client_settings)
{
$this->client = $client_settings;
foreach($settings as $el =>$val){
$this->$el = $val;
}
}
/*
* validate link
*/
function vl($url){
$replace_chars = array('Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y',
"?" => " ","!" => " ","(" => " ",")" => " "
);
$valid = strtr( $url, $replace_chars );
return preg_replace("/[-]+/","-",preg_replace("/[^0-9a-zA-Z-#\/]/",'-', trim($valid)));
}
/*
* decode post url
*/
function dp($post)
{
return preg_replace("/-/"," ",strtolower($post));
}
/*
* decode post url
*/
function replaceSpace($string)
{
return preg_replace("/ /","_",strtolower($string));
}
function validDBpar($str)
{
return preg_replace("/( |-)/","%", $str);
}
public function getQueryLimit($view_page=null)
{
$start = ($view_page == null) ? 0 : ($view_page-1) * $this->settings["items_per_page"];
$limit_query = ( $this->settings["items_per_page"] != null ) ? " LIMIT $start,". $this->settings["items_per_page"] : "";// : ($limit == null ? null: " LIMIT 0,$limit");
return $limit_query;
}
public function setPaginationLimit($limit=20)
{
$this->settings["items_per_page"] = $limit;
}
public function makeIntro($text,$length=null,$addParagraphtags=null,$sign=null){
$text = preg_replace('/<(h1|h2|h3|h4)[^>]*>([\s\S]*?)<\/(h1|h2|h3|h4)[^>]*>/', '', $text);
$sign = ($sign == null) ? " …" : $sign;
$textlen = strlen(strip_tags($text));
if($textlen < $length && $length!=null) $return = strip_tags($text);
else{
$cropAfter = ($length != null) ? $length : 115;
$intro = substr(strip_tags($text), 0, $cropAfter);
$ls = strrpos($intro, " ");
$return = substr($intro, 0, $ls).$sign;
}
$return = ($addParagraphtags == null) ? $return : "<p>".$return."</p>";
return $return;
}
public function getBaseUrl()
{
return $this->base_url;
}
public function getSiteUrl()
{
return $this->site_url;
}
public function getLocale()
{
return $this->language["locale"];
}
public function getLinkBase()
{
return $this->language["language_base"];
}
public function getRegion()
{
return $this->language["region"];
}
public function getPhoneCountryCode()
{
return $this->phone_countrycode;
}
public function getFooterCopy()
{
return sprintf($this->footer_copy,$this->client["bedrijfsnaam"]);
}
public function getFooterSocial()
{
$links = array();
if($this->client["linkedin_url"]) $links[] = '<a href="'. $this->client["linkedin_url"] .'" class="social linkedin" target="_blank">LinkedIn</a>';
if($this->client["facebook_url"]) $links[] = '<a href="'. $this->client["facebook_url"] .'" class="social facebook" target="_blank">Facebook</a>';
if($this->client["twitter_url"]) $links[] = '<a href="'. $this->client["twitter_url"] .'" class="social twitter" target="_blank">Twitter</a>';
if($this->client["googleplus_url"]) $links[] = '<a href="'. $this->client["googleplus_url"] .'" class="social googleplus" target="_blank">Google PLus</a>';
if($this->client["youtube_url"]) $links[] = '<a href="'. $this->client["youtube_url"] .'" class="social youtube" target="_blank">Youtube</a>';
return implode("",$links);
}
public function getSearchPlaceholder()
{
return $this->search_placeholder;
}
public function getNoResultsheader($search)
{
return sprintf($this->search_no_result, $search);
}
public function getSearchHeader()
{
return $this->search_header;
}
public function getTypekitFont()
{
return $this->client["typekit"];
}
public function getGoogleAnalitcs()
{
return $this->client["google_analitics"];
}
public function getLogoSVG(){
return $this->logo_svg_data;
}
public function get404label()
{
return $this->error_404_header;
}
public function get404Text()
{
return $this->error_404_desc;
}
public function get404Image($style=null)
{
return sprintf($this->error_404_img,$style);
}
public function getCompanyName()
{
return $this->client["bedrijfsnaam"];
}
public function getCompanyLogo($load_inline_svg=false, $absolute_image_path="",$additional_style="")
{
return $load_inline_svg == false ? '<img src="'.$absolute_image_path . $this->client["logo"] .'" alt="'. $this->getCompanyName() .'" style="'. $additional_style .'">' : $this->getLogoSVG();
}
public function getPrimaryLogo($include_logo_tag = false,$load_inline_svg=false)
{
return '<a href="'. $this->getBaseUrl() . $this->getLinkBase() .'" class="logo-primary">'. ($include_logo_tag == false ? $this->getCompanyName() : $this->getCompanyLogo($load_inline_svg) ) .'</a>';
}
public function getNavigationToggler(){
return $this->navigationToggler;
}
public function outputSafe($string){
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
}
public function is_odd($number)
{
return $number & 1;
}
public function is_last($array,$i)
{
$array_keys = array_keys($array);
$last_key = end($array_keys);
return $last_key == $i ? true : false;
}
/*
* get inline svg
*/
public function getSVG($type){
switch($type){
case "phone":
return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 0H7C6 0 5.2.8 5.2 1.7v20.5c0 1 .8 1.8 1.8 1.8h10c1 0 1.7-.8 1.7-1.7V1.7C18.8.8 18 0 17 0zM9.5 1.1h5c.1 0 .2.2.2.4s-.1.4-.2.4h-5c-.1 0-.2-.2-.2-.4 0-.3.1-.4.2-.4zM12 22.3c-.6 0-1.1-.5-1.1-1.1 0-.6.5-1.1 1.1-1.1.6 0 1.1.5 1.1 1.1 0 .6-.5 1.1-1.1 1.1zm5.5-3.8h-11V2.9h11v15.6z" /></svg>';
break;
case "email":
return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 4v16h24V4H0zm12 9.9L2.2 5.2h19.7L12 13.9zM8.1 12l-6.9 6.1V5.9L8.1 12zm.9.8l3 2.7 3-2.7 6.8 6H2.2l6.8-6zm6.9-.8l6.9-6.1V18l-6.9-6z"/></svg>';
break;
case "close":
return '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;" xml:space="preserve">
<path d="M14.1,12l6.4-6.4c0.6-0.6,0.6-1.5,0-2.1c-0.6-0.6-1.5-0.6-2.1,0L12,9.9L5.6,3.4C5,2.9,4,2.9,3.4,3.4
C2.9,4,2.9,5,3.4,5.6L9.9,12l-6.4,6.4c-0.6,0.6-0.6,1.5,0,2.1c0.6,0.6,1.5,0.6,2.1,0l6.4-6.4l6.4,6.4c0.6,0.6,1.5,0.6,2.1,0
c0.6-0.6,0.6-1.5,0-2.1L14.1,12z M14.1,12"/>
</svg>';
break;
case "search":
return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M6.5 11.5a4.86 4.86 0 0 0 2.5-.67A5 5 0 0 0 10.83 9a4.86 4.86 0 0 0 .67-2.5 4.86 4.86 0 0 0-.67-2.5A5 5 0 0 0 9 2.17a4.86 4.86 0 0 0-2.5-.67 4.86 4.86 0 0 0-2.5.67A5 5 0 0 0 2.17 4a4.86 4.86 0 0 0-.67 2.5A4.86 4.86 0 0 0 2.17 9 5 5 0 0 0 4 10.83a4.86 4.86 0 0 0 2.5.67m9.41 3.16a.33.33 0 0 1 .09.25.49.49 0 0 1-.09.28l-.72.68a.38.38 0 0 1-.28.13.28.28 0 0 1-.25-.13l-3.82-3.78a.4.4 0 0 1-.09-.25v-.43a6.63 6.63 0 0 1-2 1.17A6.31 6.31 0 0 1 6.5 13a6.35 6.35 0 0 1-3.27-.87A6.64 6.64 0 0 1 .88 9.77 6.26 6.26 0 0 1 0 6.5a6.26 6.26 0 0 1 .88-3.27A6.56 6.56 0 0 1 3.23.87 6.35 6.35 0 0 1 6.5 0a6.35 6.35 0 0 1 3.27.87 6.56 6.56 0 0 1 2.35 2.36A6.26 6.26 0 0 1 13 6.5a6.31 6.31 0 0 1-.42 2.28 6.63 6.63 0 0 1-1.17 2h.43a.33.33 0 0 1 .25.09z" /></svg>';
break;
}
}
public function wrapAsSection($html,$id=null,$class=null,$style=null,$data_attributes=null)
{
return preg_replace(array("/{section_htmlwrapper}/","/{element-id}/","/{style}/","/{element-class}/","/{data-attributes}/"),array($html,$id,$style,$class,$data_attributes), $this->getGroupWrapper() );
}
private function getGroupWrapper()
{
return $this->default_wrapper;
}
public function getSetting($setting)
{
return $this->$setting;
}
public function getCookieNote()
{
$html = "";
if(!isset($_COOKIE["allow_cookies"]))
{
$html .= '<div class="grid-x grid-padding-x">';
$html .= '<div class="small-12 cell text-center">';
$html .= '<p>'. $this->getCookieText();
$html .= '<a id="acceptCookie" href="#" class="button primary small">Accepteren</a><a id="moreCookie" href="'. $this->getCookieLink() .'" class="button secondary small">Meer informatie</a> </p>';
$html .= '</div>';
$html .= '</div>';
return $this->wrapAsSection($html,"cookies");
}else return null;
}
public function getCookieText()
{
return $this->cookie_text;
}
public function getCookieLink()
{
return $this->cookie_link;
}
public function accceptCookies($request, $response, $args)
{
$cookieLifetime = 60*60*24*365;
setcookie("allow_cookies","yes",time()+60*60*24*365,"/");
}
public function getReveal($type)
{
if( isset($_COOKIE["reveal-status-".$type]) ) return;
switch($type){
case "subscribe":
$html .= '<div class="reveal text-center show-on-scroll" id="exampleModal1" data-reveal data-type="subscribe" data-animation-in="fade-in" data-animation-out="fade-out">
<h1>Blijf op de hoogte!</h1>
<p><img src="images/subscribe.png" style="width:128px;"></p>
<p class="lead">Maandelijks een nieuwsbrief gevuld met interessante blogs en artikelen in je mailbox?</p>
<a href="https://confirmsubscription.com/h/d/517EF84A57079EAB" class="button primary" target="_blank">Inschrijven nieuwsbrief</a>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>';
break;
}
return $html;
}
public function setRevealStatus($request, $response, $args)
{
$postData = $request->getParsedBody();
setcookie("reveal-status-". $postData["type"],0,time()+60*60*24*365,"/");
}
public function getFormHash($hash_prefix='')
{
return hash('sha256', $hash_prefix.$this->settings["hash_key"]);
}
public function hasValidResponse($post_hash,$form_id)
{
return $post_hash == $this->getFormHash($form_id) ? true : false;
}
}
?>