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

class Twitterclone_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('twitterclone.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("twitterclone_landingpage");
        });';
      $view->headScript()->appendScript($script);
		}

		$changememberhome = $settings->getSetting('twitterclone.changememberhome', 0);
		if(!empty($changememberhome) && $module == 'user' && $controller == 'index' && $action == 'home') {
			$script = 'en4.core.runonce.add(function() {
					scriptJquery ("body").addClass("twitterclone_member_home_page");
			});';
      $view->headScript()->appendScript($script);
		}
		
		$changememberprofile = $settings->getSetting('twitterclone.changememberprofile', 0);
		if(!empty($changememberprofile) && $module == 'user' && $controller == 'profile' && $action == 'index') {
			$script = 'en4.core.runonce.add(function() {
					scriptJquery ("body").addClass("twitterclone_member_profile_page");
			});';
      $view->headScript()->appendScript($script);
		}
		
    //Theme mode active
    $script = "var isThemeModeActive = true;";
    $script .= "var loginSignupPlaceHolderActive = true;";
    $view->headScript()->appendScript($script);

      //Google Font Work
      $usegoogleFont = $settings->getSetting('twitterclone.googlefonts', 0);
      if(!empty($usegoogleFont)) {
        $string = 'https://fonts.googleapis.com/css?family=';
  
        $bodyFontFamily = $settings->getSetting('twitterclone.googlebody.fontfamily'); 
        $string .= str_replace('"', '', $bodyFontFamily);
        $string .= ':'.$settings->getSetting('twitterclone.googlebody.fontfamilyvariants');
  
        $headingFontFamily = $settings->getSetting('twitterclone.googleheading.fontfamily');
        $string .= '|'.str_replace('"', '', $headingFontFamily);
        $string .= ':'.$settings->getSetting('twitterclone.googleheading.fontfamilyvariants');
        
        $mainmenuFontFamily = $settings->getSetting('twitterclone.googlemainmenu.fontfamily');
        $string .= '|'.str_replace('"', '', $mainmenuFontFamily);
        $string .= ':'.$settings->getSetting('twitterclone.googlemainmenu.fontfamilyvariants');
  
        $tabFontFamily = $settings->getSetting('twitterclone.googletab.fontfamily');
        $string .= '|'.str_replace('"', '', $tabFontFamily);
        $string .= ':'.$settings->getSetting('twitterclone.googletab.fontfamilyvariants');
  
        $view->headLink()->appendStylesheet($string);
      }
	}
  public function onRenderLayoutDefaultSimple($event) {
    return $this->onRenderLayoutDefault($event, 'simple');
  }
}
