Fetch inline minified css or js
@param string $what style | script
@param string $data text that needs to be minified inline
@param bool $return should we return or echo the minified data?
@throws Exception
429076
public function inline($what = null, $data = null, $return = false) {
        // not supported?
        if(!in_array($what, ['style', 'script']))
            throw new Exception("{$what} not supported");

        // call private function
        $function = '_inline' . ucfirst($what);
        $data = $this->$function($data);

        // return or output?
        if($return) return $data;
        echo $data;
    }
859876
public function renderTemplate($filename, $data, $return = false)
    {
        $templateOutput = $this->parseTemplate($filename, $data);

        if ($return)
        {
            return $templateOutput;
        }

        echo $templateOutput;
        return $return;
    }
92811
public static function js(StreamInterface $input, StreamInterface $output)
    {
        $output->write(JSMinPlus::minify((string) $input));

        return $output;
    }
1030651
public static function trace(array $trace, $return = false, $html = true, $withArgs = true)
        {
            $out    = '';
            if ($html) {
                $out .= '<pre>';
            }

            foreach ($trace as $i => $data) {
                // skip self
                if ($i == 0) {
                    continue;
                }

                // prepare method argments
                $args = array();
                if (isset($data['args']) && true === $withArgs) {
                    foreach ($data['args'] as $arg) {
                        $args[] = static::_formatCalledArgument($arg);
                    }
                }

                // prepare method's name
                if (isset($data['class']) && isset($data['function'])) {
                    if (isset($data['object']) && get_class($data['object']) != $data['class']) {
                        $className = get_class($data['object']) . '[' . $data['class'] . ']';
                    } else {
                        $className = $data['class'];
                    }
                    if (isset($data['object'])) {
                        $className .= sprintf('#%s#', spl_object_hash($data['object']));
                    }

                    $methodName = sprintf('%s%s%s(%s)',
                        $className,
                        isset($data['type']) ? $data['type'] : '->',
                        $data['function'],
                        join(', ', $args)
                    );
                } else if (isset($data['function'])) {
                    $methodName = sprintf('%s(%s)', $data['function'], join(', ', $args));
                }

                if (isset($data['file'])) {
                    $pos = strpos($data['file'], static::getRootPath());
                    if ($pos !== false) {
                        $data['file'] = substr($data['file'], strlen(static::getRootPath()) + 1);
                    }
                    $fileName = sprintf('%s:%d', $data['file'], $data['line']);
                } else {
                    $fileName = false;
                }

                if ($fileName) {
                    $out .= sprintf('#%d %s called at [%s]', $i, $methodName, $fileName);
                } else {
                    $out .= sprintf('#%d %s', $i, $methodName);
                }

                $out .= "\n";
            }

            if (true === $html) {
                $out .= '</pre>';
            }

            if (true === $return) {
                return $out;
            } else {
                echo $out;
                return true;
            }
        }
430772
public function call($command, $data = NULL, $format = 'xml')
		{
			if ($this->checkStatus()) {
				$request = array(
					'form_params' => [
						'r'             => $this->realm,
						'p'             => $this->password,
						'version'       => $this->version,
						'c'             => $command,
						'output_format' => $format
					]
				);

				if (!empty($data)) {
					$request = array('form_params' => array_merge($request['form_params'], $data));
				}

				$guzzle = new \GuzzleHttp\Client;
				$response = $guzzle->request(
					'POST',
					$this->url,
					$request
				);

				$body = (string)$response->getBody();

				if (empty($body)) {
					throw new Exception("No results");
				}

				if ($body == 'Invalid credentials') {
					throw new Exception('Invalid Credentials');
				}

				if ((int)substr_compare($body, "FAILURE", 0, 7) == 0) {
					$result = explode(":", $body);
					throw new Exception(trim($result[1]));
				}

				if ((int)substr_compare($body, "SUCCESS", 0, 7) == 0) {
					$result = explode(":", $body);

					return $result;
				}

				if ((int)substr_compare($body, "<data>", 0, 6, 1) == 0) return new \SimpleXMLElement($body);
				if ((int)substr_compare($body, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", 0, 38, 1) == 0) return new \SimpleXMLElement($body);

				return $body;
			}

			return FALSE;
		}
303982
private function _renderItemsTogether ($actualGroupName = '', $items = [], $indent = 0, $minify = FALSE) {
		// some configurations is not possible to render together and minimized
		list($itemsToRenderMinimized, $itemsToRenderSeparately) = $this->filterItemsForNotPossibleMinifiedAndPossibleMinifiedItems($items);

		$indentStr = $this->getIndentString($indent);
		$resultItems = [];
		if (self::$fileRendering) $resultItems[] = '<!-- css group begin: ' . $actualGroupName . ' -->';

		// process array with groups, which are not possible to minimize
		foreach ($itemsToRenderSeparately as & $itemsToRender) {
			$resultItems[] = $this->_renderItemsTogetherAsGroup($itemsToRender, $minify);
		}

		// process array with groups to minimize
		foreach ($itemsToRenderMinimized as & $itemsToRender) {
			$resultItems[] = $this->_renderItemsTogetherAsGroup($itemsToRender, $minify);
		}

		if (self::$fileRendering) $resultItems[] = '<!-- css group end: ' . $actualGroupName . ' -->';

		return $indentStr . implode(PHP_EOL . $indentStr, $resultItems);
	}
1263156
static public function css($path, $with_version = true, $return = false, $absolutely = false) {
        $href = $absolutely ? $path : self::path('static/' . $path);

        $query = array();
        \Comm\Misc::isProEnv() || $query['debug'] = 1;
        $with_version && $query['version'] = self::cssVer();
        $query && $href .= '?' . http_build_query($query);

        $result = "<link href=\"{$href}\" type=\"text/css\" rel=\"stylesheet\" />";
        if ($return) {
            return $result;
        } else {
            echo $result;
            return null;
        }
    }
644572
public function toXml(array $data, $isReturn = false)
    {
        $xml = Tools::arr2xml($data);
        if ($isReturn) {
            return $xml;
        }
        echo $xml;
    }
1307958
function fetch( $template = false, $extraParameters = false, $returnResourceData = false )
    {
        $this->resetErrorLog();
        // Reset fetch list when a new fetch is started
        $this->TemplateFetchList = array();

        eZDebug::accumulatorStart( 'template_total' );
        eZDebug::accumulatorStart( 'template_load', 'template_total', 'Template load' );
        $root = null;
        if ( is_string( $template ) )
        {
            $resourceData = $this->loadURIRoot( $template, true, $extraParameters );
            if ( $resourceData and
                 $resourceData['root-node'] !== null )
                $root =& $resourceData['root-node'];
        }
        eZDebug::accumulatorStop( 'template_load' );
        if ( $resourceData['locales'] && !empty( $resourceData['locales'] ) )
        {
            $savedLocale = setlocale( LC_CTYPE, null );
            setlocale( LC_CTYPE, $resourceData['locales'] );
        }

        $text = "";

        if ( $root !== null or
             $resourceData['compiled-template'] )
        {
            if ( $this->ShowDetails )
                eZDebug::addTimingPoint( "Process" );
            eZDebug::accumulatorStart( 'template_processing', 'template_total', 'Template processing' );

            $templateCompilationUsed = false;
            if ( $resourceData['compiled-template'] )
            {
                $textElements = array();
                if ( $this->executeCompiledTemplate( $resourceData, $textElements, "", "", $extraParameters ) )
                {
                    $text = implode( '', $textElements );
                    $templateCompilationUsed = true;
                }
            }
            if ( !$templateCompilationUsed )
            {
                if ( eZTemplate::isDebugEnabled() )
                {
                    $fname = $resourceData['template-filename'];
                    eZDebug::writeDebug( "FETCH START URI: $template, $fname" );
                }
                $this->process( $root, $text, "", "" );
                if ( eZTemplate::isDebugEnabled() )
                    eZDebug::writeDebug( "FETCH END URI: $template, $fname" );
            }

            eZDebug::accumulatorStop( 'template_processing' );
            if ( $this->ShowDetails )
                eZDebug::addTimingPoint( "Process done" );
        }

        eZDebug::accumulatorStop( 'template_total' );

        if ( $resourceData['locales'] && !empty( $resourceData['locales'] ) )
        {
            setlocale( LC_CTYPE, $savedLocale );
        }

        if ( $returnResourceData )
        {
            $resourceData['result_text'] = $text;
            return $resourceData;
        }
        return $text;
    }
1374479
public static function view($url, $view, $data = null)
    {
        $callback = function () use ($view, $data) {
            $view = view($view);

            if (!is_null($data)) {
                foreach ($data as $key => $value) {
                    $view = $view->with($key, $value);
                }
            }

            return $view;
        };

        static::get($url, $callback);
    }
364090
public static function highlight_string($source, $language, $return = false, $opts = 0)
    {
        if (is_int($return)) {
            $opts = $return;
            $return = false;
        }

        $gs = new static($source, $language, $opts);
        $s = $gs->parseCode();

        if ($gs->error()) {
            return false;
        }

        if ($return) {
            return '<code>' . $s . '</code>';
        }
        echo '<code>' . $s . '</code>';

        return true;
    }
270904
static public function js($path, $with_version = true, $return = false, $absolutely = false) {
        $src = $absolutely ? $path : self::path('static/' . $path);

        $query = array();
        \Comm\Misc::isProEnv() || $query['debug'] = 1;
        $with_version && $query['version'] = self::jsVer();
        $query && $src .= '?' . http_build_query($query);

        $result = "<script type=\"text/javascript\" src=\"{$src}\"></script>";

        if ($return) {
            return $result;
        } else {
            echo $result;
            return null;
        }
    }
688747
private static function updateResponseContentType(ResponseInterface $response, Run $whoops): ResponseInterface
    {
        if (1 !== count($whoops->getHandlers())) {
            return $response;
        }

        $handler = current($whoops->getHandlers());

        if ($handler instanceof PrettyPageHandler) {
            return $response->withHeader('Content-Type', 'text/html');
        }

        if ($handler instanceof JsonResponseHandler) {
            return $response->withHeader('Content-Type', 'application/json');
        }

        if ($handler instanceof XmlResponseHandler) {
            return $response->withHeader('Content-Type', 'text/xml');
        }

        if ($handler instanceof PlainTextHandler) {
            return $response->withHeader('Content-Type', 'text/plain');
        }

        return $response;
    }
904364
private function preparedUpdate($data,$where){
        $sqldata = empty($data)?$this->_ar:$data;
        $sql = $this->dealUpdateSQL($this->GetTable(),$sqldata,$where);
        $phl = $this->dbh->prepare($sql);
        $res = $phl->execute($sqldata);
        $this->initialize();
        return $res;
    }
308109
public function execute($data, $value = null) {
        try {
            $config = $this->sanitizeConfig($data);
            if ($value != null)
                $config->value = number_format(floatval($value), 2, '.', '');
            $this->isConciliate($config);
            if (!$this->doRefund($config))
            throw new \Exception('impossible to refund');

            $this->doUpdates($config);
            return true;
        } catch (\Exception $exception) {
            $error = simplexml_load_string($exception->getMessage());
            throw new \Exception((string)$error->error->code);
        }
    }
538127
public function fetch($return = self::RETURN_COLLECTION) {
        /** We replace Post.xx by post.xx */
        foreach ($this->_entities as $entity) {
            $class = $this->_getTableEntity($entity);

            if ($entity != $class->name()) {
                $this->_query = preg_replace('#(.*)' . $entity . '\.(.*)#isU', '$1' . $class->name() . '.$2', $this->_query);
            }
        }

        /** Query execution */
        $sql = new Sql();
        $sql->vars($this->_vars);
        $sql->query('orm-' . $this->_token, $this->_query);

        if ($this->_type == self::QUERY_COUNT) {
            return $sql->fetch('orm-' . $this->_token, Sql::PARAM_FETCHCOLUMN);
        }
        else {
            $sql->fetch('orm-' . $this->_token, Sql::PARAM_FETCH);
        }

        $collection = $sql->data($this->_getEntityName($this->_entity->name()));

        /** We can do SELECT OR SELECT DISTINCT OR SELECT RAW */
        if (in_array($this->_type, [self::QUERY_DISTINCT, self::QUERY_RAW])) {
            $nLines = $collection->count();
            $in = '';

            /** @var $value \Gcs\Framework\Core\Orm\Entity\Entity */
            foreach ($collection as $key => $value) {
                $in .= $value->fields()[$value->primary()]->value;

                if ($key < $nLines - 1) {
                    $in .= ', ';
                }
            }

            $builder = new Builder($this->_entity);
            $collection = $builder->find()->where($this->_entity->name() . '.' . $this->_entity->primary() . ' IN (' . $in . ')')->fetch();
        }

        /** If we have fields with a relation ONE TO MANY OR MANY TO MANY */
        foreach ($this->_entity->fields() as $field) {
            if ($field->foreign != null && in_array($field->foreign->type(), [ForeignKey::ONE_TO_MANY, ForeignKey::MANY_TO_MANY])) {
                /** we loop through the results to add each time */
                switch ($field->foreign->type()) {
                    case ForeignKey::ONE_TO_MANY :
                        $collection = $this->_dataOneToMany($field, $collection);
                        break;

                    case ForeignKey::MANY_TO_MANY :
                        $collection = $this->_dataManyToMany($field, $collection);
                        break;
                }
            }
        }

        if ($return == self::RETURN_ENTITY && $collection->count() <= 1) {
            return $collection->first();
        }
        else {
            return $collection;
        }
    }
798989
public function displayImage($which = 'main') {
		$js = '	if(isCertifColorboxActive == 0) { 
					activatecertifcolorbox();
					isCertifColorboxActive = 1;
				}
		';
		
		$script = '';
		$controller = Globals::getController();
		if($controller && !($controller instanceof IndividualController)){
			$controller->addInlineJavascript('$(document).ready(function() { '.$js.' });');
		} else {
			$script = '<script>' . $js . '</script>';
		}
		
		if ($which == 'icon' || !file_exists($this->getServerFilename())) {
			// Use an icon
			$image =
			'<i dir="auto" class="icon-maj-certificate margin-h-2"' .
			' title="' . strip_tags($this->getFullName()) . '"' .
			'></i>';
		} else {
			$imgsize = getimagesize($this->getServerFilename());
			$image =
			'<img' .
			' class ="'. 'certif_image'					 	. '"' .
			' dir="'   . 'auto'                           	. '"' . // For the tool-tip
			' src="'   . $this->getHtmlUrlDirect() 			. '"' .
			' alt="'   . strip_tags($this->getFullName()) 	. '"' .
			' title="' . strip_tags($this->getFullName()) 	. '"' .
			$imgsize[3] . // height="yyy" width="xxx"
			'>';
		}	
		return
		'<a' .
		' class="'          . 'certgallery'                          . '"' .
		' href="'           . $this->getHtmlUrlDirect()    		 . '"' .
		' type="'           . $this->mimeType()                  . '"' .
		' data-obje-url="'  . $this->getHtmlUrl()                . '"' .
		' data-title="'     . strip_tags($this->getFullName())   . '"' .
		'>' . $image . '</a>'.$script;
	}