File: /var/www/vhosts/creativefellows.nl/test.creativefellows.nl/e-pact/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));
}
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 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 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 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)
{
return $load_inline_svg == false ? '<img src="'. $this->client["logo"] .'" alt="'. $this->getCompanyName() .'">' : $this->getLogoSVG();
}
public function getEmailLogo()
{
return '<img src="'. $this->getWebsiteUrl() . $this->settings["email_logo"] .'" alt="'. $this->getCompanyName() .'">';
}
private function getWebsiteUrl()
{
return $this->settings["site_url"];
}
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 version="1.1" id="Laag_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="M10.6,5.8c1.3,0,2.5,0.5,3.4,1.4c0.9,0.9,1.4,2.1,1.4,3.4c0,1.3-0.5,2.5-1.4,3.4c-0.9,0.9-2.1,1.4-3.4,1.4
c-1.3,0-2.5-0.5-3.4-1.4c-0.9-0.9-1.4-2.1-1.4-3.4c0-1.3,0.5-2.5,1.4-3.4C8.1,6.2,9.3,5.8,10.6,5.8 M5.2,16c0.7,0.7,1.5,1.2,2.4,1.6
c0.9,0.4,1.9,0.6,3,0.6c1.6,0,3-0.4,4.3-1.3l3.7,3.7c0.3,0.3,0.6,0.4,1,0.4c0.4,0,0.7-0.1,1-0.4c0.3-0.3,0.4-0.6,0.4-1
c0-0.4-0.1-0.7-0.4-1l-3.7-3.7c0.9-1.3,1.3-2.7,1.3-4.3c0-1-0.2-2-0.6-3c-0.4-0.9-0.9-1.8-1.6-2.4S14.5,4,13.6,3.6
c-0.9-0.4-1.9-0.6-3-0.6c-1,0-2,0.2-3,0.6C6.7,4,5.9,4.5,5.2,5.2S4,6.7,3.6,7.7C3.2,8.6,3,9.6,3,10.6c0,1,0.2,2,0.6,3
C4,14.5,4.5,15.3,5.2,16"/>
</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->group_wrapper;
}
public function getCookieNote()
{
$html = "";
if(!isset($_COOKIE["allow_cookies"]))
{
$html .= '<div class="grid-x grid-padding-x align-middle">';
$html .= '<div class="auto cell">';
$html .= '<p>'. $this->getCookieText() .'</p>';
$html .= '</div>';
$html .= '<div class="shrink cell">';
$html .= '<p class="large-text-right"><a id="moreCookie" href="'. $this->getCookieLink() .'" class="button transparent small">Meer informatie</a> <a id="acceptCookie" href="#" class="button small">Accepteren</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;
}
public function getFormResponseMessage(){
return '<div class="text-center form-response">'. $this->formResponseMessage .'</div>';
}
}
?>