<commit_before><?php
/**
 * NGS predefined templater class
 * handle smarty and json responses
 *
 * @author <NAME> <<EMAIL>>
 * @site http://naghashyan.com
 * @package ngs.framework.templater
 * @version 2.5.0
 * @year 2010-2016
 *
 * This file is part of the NGS package.
 *
 * @copyright Naghashyan Solutions LLC
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace ngs\templater {

  use Smarty;

  class NgsSmartyTemplater extends Smarty {

    private $isHtml = true;
    private $customJsHeader = "";
    /**
     * constructor
     * reading Smarty config and setting up smarty environment accordingly
     */
    private $params = array();

    public function __construct($isHtml = true) {
      parent::__construct();
      $this->isHtml = $isHtml;
      //register NGS plugins
      $this->registerPlugin("function", "nest", array($this, 'nest'));
      $this->registerPlugin("function", "ngs", array($this, 'NGS'));

      $this->setTemplateDir(NGS()->getTemplateDir());
      $this->setCompileDir($this->getSmartyCompileDir());
      $this->setConfigDir($this->getSmartyConfigDir());
      $this->setCacheDir($this->getSmartyCacheDir());
      $this->compile_check = true;
      if ($isHtml){
        // register the outputfilter
        $this->registerFilter("output", array($this, "addScripts"));
      }
    }

    /**
     * Smarty {nest} function plugin
     *
     * Type:     function<br>
     * Name:     nest<br>
     * Purpose:  handle math computations in template
     * <br>
     * @param array $params parameters
     * @param object $template template object
     * @return string html
     */
    public function nest($params, $template) {
      if (!isset($params['ns'])){
        trigger_error("nest: missing 'ns' parameter");
        return;
      }

      if (!$template->tpl_vars["ns"]){
        $template->tpl_vars["ns"] = $template->tpl_vars["ns"];
      }

      $nsValue = $template->tpl_vars["ns"]->value;
      $namespace = $nsValue["inc"][$params["ns"]]["namespace"];

      $include_file = $nsValue["inc"][$params["ns"]]["filename"];
      if (!file_exists($include_file)){
        trigger_error("nest: missing 'file' " . $include_file);
        return;
      }
      $_tpl = $template->createTemplate($include_file, null, null, $nsValue["inc"][$params["ns"]]["params"]);
      foreach ($template->tpl_vars as $key => $tplVars){
        $_tpl->assign($key, $tplVars);
      }
      $_tpl->assign("ns", $nsValue["inc"][$params["ns"]]["params"]);
      if ($_tpl->mustCompile()){
        $_tpl->compileTemplateSource();
      }
      //$_tpl->renderTemplate();
      $_output = $_tpl->display();
      if (NGS()->isJsFrameworkEnable() && !NGS()->getHttpUtils()->isAjaxRequest()){
        $jsonParams = $nsValue["inc"][$params["ns"]]["jsonParam"];
        $parentLoad = $nsValue["inc"][$params["ns"]]["parent"];
        $jsString = '<script type="text/javascript">';
        $jsString .= 'NGS.setNestedLoad("' . $parentLoad . '", "' . $namespace . '", ' . json_encode($jsonParams) . ')';
        $jsString .= '</script>';
        $_output = $jsString . $_output;
      }

      return $_output;
    }


    /**
     * Smarty plugin
     *
     * This plugin is only for Smarty3
     * @package Smarty
     * @subpackage PluginsFunction
     */

    /**
     * Smarty {NGS} function plugin
     *
     * Type:     function<br>
     * Name:     NGS<br>
     * Purpose:  helper function gor access global NGS Object
     * <br>
     *
     * @param array $params parameters
     * @param object $template template object
     * @return  string url
     */
    public function NGS($params, $template) {
      if (!isset($params['cmd'])){
        trigger_error("NGS: missing 'cmd' parameter");
        return;
      }
      $ns = "";
      if (isset($params['ns'])){
        $ns = $params['ns'];
      }
      switch ($params['cmd']){
        case 'get_js_out_dir' :
          $protocol = false;
          if (isset($params['protocol']) && $params['protocol'] == true){
            $protocol = true;
          }
          return NGS()->getPublicOutputHost($ns, $protocol) . "/js";
          break;
        case 'get_css_out_dir' :
          $protocol = false;
          if (isset($params['protocol']) && $params['protocol'] == true){
            $protocol = true;
          }
          return NGS()->getPublicOutputHost($ns, $protocol) . "/css";
          break;
        case 'get_less_out_dir' :
          $protocol = false;
          if (isset($params['protocol']) && $params['protocol'] == true){
            $protocol = true;
          }
          return NGS()->getPublicOutputHost($ns, $protocol) . "/less";
          break;
        case 'get_template_dir' :
          return NGS()->getTemplateDir($ns);
          break;
        case 'get_http_host' :
          $protocol = false;
          if (isset($params['protocol']) && $params['protocol'] == true){
            $protocol = true;
          }
          return NGS()->getHttpUtils()->getHttpHostByNs($ns, $protocol);
          break;
        case 'get_host' :
          $protocol = false;
          if (isset($params['protocol']) && $params['protocol'] == true){
            $protocol = true;
          }
          return NGS()->getHttpUtils()->getHost();
          break;
        case 'get_static_path' :
          if (isset(NGS()->getConfig()->static_path)){
            return "//" . NGS()->getConfig()->static_path;
          }
          $protocol = false;
          if (isset($params['protocol']) && $params['protocol'] == true){
            $protocol = true;
          }
          return NGS()->getHttpUtils()->getNgsStaticPath($ns, $protocol);
          break;<commit_msg>update static path http protocol<commit_after><?php
/**
 * NGS predefined templater class
 * handle smarty and json responses
 *
 * @author <NAME> <<EMAIL>>
 * @site http://naghashyan.com
 * @package ngs.framework.templater
 * @version 2.5.0
 * @year 2010-2016
 *
 * This file is part of the NGS package.
 *
 * @copyright Naghashyan Solutions LLC
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace ngs\templater {

  use Smarty;

  class NgsSmartyTemplater extends Smarty {

    private $isHtml = true;
    private $customJsHeader = "";
    /**
     * constructor
     * reading Smarty config and setting up smarty environment accordingly
     */
    private $params = array();

    public function __construct($isHtml = true) {
      parent::__construct();
      $this->isHtml = $isHtml;
      //register NGS plugins
      $this->registerPlugin("function", "nest", array($this, 'nest'));
      $this->registerPlugin("function", "ngs", array($this, 'NGS'));

      $this->setTemplateDir(NGS()->getTemplateDir());
      $this->setCompileDir($this->getSmartyCompileDir());
      $this->setConfigDir($this->getSmartyConfigDir());
      $this->setCacheDir($this->getSmartyCacheDir());
      $this->compile_check = true;
      if ($isHtml){
        // register the outputfilter
        $this->registerFilter("output", array($this, "addScripts"));
      }
    }

    /**
     * Smarty {nest} function plugin
     *
     * Type:     function<br>
     * Name:     nest<br>
     * Purpose:  handle math computations in template
     * <br>
     * @param array $params parameters
     * @param object $template template object
     * @return string html
     */
    public function nest($params, $template) {
      if (!isset($params['ns'])){
        trigger_error("nest: missing 'ns' parameter");
        return;
      }

      if (!$template->tpl_vars["ns"]){
        $template->tpl_vars["ns"] = $template->tpl_vars["ns"];
      }

      $nsValue = $template->tpl_vars["ns"]->value;
      $namespace = $nsValue["inc"][$params["ns"]]["namespace"];

      $include_file = $nsValue["inc"][$params["ns"]]["filename"];
      if (!file_exists($include_file)){
        trigger_error("nest: missing 'file' " . $include_file);
        return;
      }
      $_tpl = $template->createTemplate($include_file, null, null, $nsValue["inc"][$params["ns"]]["params"]);
      foreach ($template->tpl_vars as $key => $tplVars){
        $_tpl->assign($key, $tplVars);
      }
      $_tpl->assign("ns", $nsValue["inc"][$params["ns"]]["params"]);
      if ($_tpl->mustCompile()){
        $_tpl->compileTemplateSource();
      }
      //$_tpl->renderTemplate();
      $_output = $_tpl->display();
      if (NGS()->isJsFrameworkEnable() && !NGS()->getHttpUtils()->isAjaxRequest()){
        $jsonParams = $nsValue["inc"][$params["ns"]]["jsonParam"];
        $parentLoad = $nsValue["inc"][$params["ns"]]["parent"];
        $jsString = '<script type="text/javascript">';
        $jsString .= 'NGS.setNestedLoad("' . $parentLoad . '", "' . $namespace . '", ' . json_encode($jsonParams) . ')';
        $jsString .= '</script>';
        $_output = $jsString . $_output;
      }

      return $_output;
    }


    /**
     * Smarty plugin
     *
     * This plugin is only for Smarty3
     * @package Smarty
     * @subpackage PluginsFunction
     */

    /**
     * Smarty {NGS} function plugin
     *
     * Type:     function<br>
     * Name:     NGS<br>
     * Purpose:  helper function gor access global NGS Object
     * <br>
     *
     * @param array $params parameters
     * @param object $template template object
     * @return  string url
     */
    public function NGS($params, $template) {
      if (!isset($params['cmd'])){
        trigger_error("NGS: missing 'cmd' parameter");
        return;
      }
      $ns = "";
      if (isset($params['ns'])){
        $ns = $params['ns'];
      }
      switch ($params['cmd']){
        case 'get_js_out_dir' :
          $protocol = false;
          if (isset($params['protocol']) && $params['protocol'] == true){
            $protocol = true;
          }
          return NGS()->getPublicOutputHost($ns, $protocol) . "/js";
          break;
        case 'get_css_out_dir' :
          $protocol = false;
          if (isset($params['protocol']) && $params['protocol'] == true){
            $protocol = true;
          }
          return NGS()->getPublicOutputHost($ns, $protocol) . "/css";
          break;
        case 'get_less_out_dir' :
          $protocol = false;
          if (isset($params['protocol']) && $params['protocol'] == true){
            $protocol = true;
          }
          return NGS()->getPublicOutputHost($ns, $protocol) . "/less";
          break;
        case 'get_template_dir' :
          return NGS()->getTemplateDir($ns);
          break;
        case 'get_http_host' :
          $protocol = false;
          if (isset($params['protocol']) && $params['protocol'] == true){
            $protocol = true;
          }
          return NGS()->getHttpUtils()->getHttpHostByNs($ns, $protocol);
          break;
        case 'get_host' :
          $protocol = false;
          if (isset($params['protocol']) && $params['protocol'] == true){
            $protocol = true;
          }
          return NGS()->getHttpUtils()->getHost();
          break;
        case 'get_static_path' :
          if (isset(NGS()->getConfig()->static_path)){
            if(strpos(NGS()->getConfig()->static_path, "http") == 0){
              return NGS()->getConfig()->static_path;
            }
            $httpProtocol  = "//";
            if (isset($params['protocol']) && $params['protocol'] == true){
              $httpProtocol = NGS()->getHttpUtils()->getRequestProtocol().$httpProtocol;
            }
            return $httpProtocol . NGS()->getConfig()->static_path;
          }
          $protocol = false;
          if (isset($params['protocol']) && $params['protocol'] == true){
            $protocol = true;
          }
          return NGS()->getHttpUtils()->getNgsStaticPath($ns, $protocol);
          break;
{'fraction_non_alphanumeric': 0.1707542415588779, 'fraction_numerical': 0.002099781622711238, 'mean_word_length': 2.375956903884321, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 119, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4875376', 'n_tokens_mistral': 3520, 'n_tokens_neox': 3491, 'n_words': 738}