<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/

class Inspira_Plugin_Core extends Zend_Controller_Plugin_Abstract {

	public function onRenderLayoutDefault(){

    $request = Zend_Controller_Front::getInstance()->getRequest();
    $module = $request->getModuleName();
    $controller = $request->getControllerName();
    $action = $request->getActionName();
    $settings = Engine_Api::_()->getApi('settings', 'core');
    $changelanding = $settings->getSetting('inspira.changelanding', 0);
    $view = Zend_Registry::isRegistered('Zend_View') ? Zend_Registry::get('Zend_View') : null;
    if(!empty($changelanding) && $module == 'core' && $controller == 'index' && $action == 'index') {
      $script = '
        en4.core.runonce.add(function() {
          scriptJquery ("body").addClass("inspira_landingpage_'.$changelanding.'");
        });';
      $view->headScript()->appendScript($script);
		}
		
    //Theme mode active
    $script = "var isThemeModeActive = true;";
    $view->headScript()->appendScript($script);

    //Google Font Work
    $usegoogleFont = $settings->getSetting('inspira.googlefonts', 0);
    if(!empty($usegoogleFont)) {
      $string = 'https://fonts.googleapis.com/css?family=';

      $bodyFontFamily = $settings->getSetting('inspira.googlebody.fontfamily'); 
      $string .= str_replace('"', '', $bodyFontFamily);
      $string .= ':'.$settings->getSetting('inspira.googlebody.fontfamilyvariants');

      $headingFontFamily = $settings->getSetting('inspira.googleheading.fontfamily');
      $string .= '|'.str_replace('"', '', $headingFontFamily);
      $string .= ':'.$settings->getSetting('inspira.googleheading.fontfamilyvariants');
      
      $mainmenuFontFamily = $settings->getSetting('inspira.googlemainmenu.fontfamily');
      $string .= '|'.str_replace('"', '', $mainmenuFontFamily);
      $string .= ':'.$settings->getSetting('inspira.googlemainmenu.fontfamilyvariants');

      $tabFontFamily = $settings->getSetting('inspira.googletab.fontfamily');
      $string .= '|'.str_replace('"', '', $tabFontFamily);
      $string .= ':'.$settings->getSetting('inspira.googletab.fontfamilyvariants');

      $view->headLink()->appendStylesheet($string);
    }

    $script = '
     en4.core.runonce.add(function() {
        var height = scriptJquery(".layout_page_header").height();
        if(document.getElementById("global_wrapper")) {
           scriptJquery("#global_wrapper").css("margin-top", height+"px");
        }
     });';
    $view->headScript()->appendScript($script);
	}
  
  public function onRenderLayoutDefaultSimple($event){
    return $this->onRenderLayoutDefault($event, 'simple');
  }
}
