/**
     * Fetches an application by its url
     * @param string $uri
     * @param string $outputType
     * @return ApplicationDefault
     */
    static public function fetchByUri( $uri, $outputType = 'html' )
    {
        // We keep $currentApplication to avoid loosing it during the process
        $currentApplication = ApplicationDefault::instance();
        $realServerURi      = $_SERVER['REQUEST_URI'];
        $uri                = trim($uri, '/ ');
        $uriparams          = explode('/', $uri);
        $applicationName    = $uriparams[0];

        $functions = array(
            'html'     => 'main_view',
            'json'     => 'json',
            'ajax'     => 'ajax'
        );

        array_unshift($uriparams, 'app_content');

        $_SERVER['REQUEST_URI'] = '/esibuild/'.$functions[$outputType].'/app_content/'.$uri;

        $params = array(
            self::paramBlockKey()               => 'app_content',
            'ModuleName'                        => 'esibuild',
            'FunctionName'                      => $functions[$outputType],
            self::paramCurrentApplicationKey()  => $applicationName,
            'Parameters'                        => $uriparams
        );

        $application            = BlockFactory::factory( $params, $outputType );
        $_SERVER['REQUEST_URI'] = $realServerURi;

        // We set $currentApplication again
        ApplicationDefault::setInstance($currentApplication);

        return $application;
    }
    /**
     * @return bool
     */
    public static function appHasSpeciality()
    {
        /** @var $application ContentListBase */
        $application = ApplicationDefault::instance();
        $facets = $application->facets;

        foreach($facets as $facet)
            if($facet instanceof FacetFieldTagSpeciality)
                return true;

        return false;
    }
    /**
     * @param eZTemplate $tpl
     * @param string $operatorName
     * @param array $operatorParameters
     * @param string $rootNamespace
     * @param string $currentNamespace
     * @param mixed $operatorValue
     * @param array $namedParameters
     */
    function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters)
    {
        switch ($operatorName)
        {
            case 'timestampToDateISO':
                $operatorValue = date('c', $namedParameters['timestamp']);
                break;
            case 'ezstr_replace':
                $operatorValue = str_replace(
                    $namedParameters['search'],
                    $namedParameters['replace'],
                    $namedParameters['text']
                );
                break;
            case 'hash_set':
                $hash                          = $namedParameters['hash'];
                $hash[$namedParameters['key']] = $namedParameters['val'];
                $operatorValue                 = $hash;
                break;
            case 'currentApplication':
                $operatorValue = ApplicationDefault::instance();
                break;
            case 'getApplicationName':
                if ($namedParameters['application'] instanceof ApplicationDefault)
                {
                    $operatorValue = $namedParameters['application']->applicationName();
                }
                break;
            case 'getTableEmbeddedName':
                $pattern = '/<td class="MMTableCellHead" ?.*>(.*)<\/td>/';
                preg_match_all($pattern, $namedParameters['htmlCode'], $matches);

                $operatorValue = $matches[1][0];
                break;
            case 'external_app_cookie_key':
                $operatorValue = ExternalApplication::createExternalApplicationCookieKey(
                    $namedParameters['localized_application']
                );
                break;
            case 'getCurrentCluster':
                $operatorValue = ClusterTool::clusterIdentifier();
                break;
            case 'checkIfSiteMatchesType':
                $contexts = array(
                    ContextTool::APP_MOBILE_DESIGN,
                    ContextTool::FRONT_DESIGN,
                    ContextTool::MOBILE_DESIGN
                );

                $operatorValue = (in_array($namedParameters['site_type'], $contexts)) ? ContextTool::instance(
                )->siteIsTypeOf($namedParameters['site_type']) : false;
                break;
            case 'import_status_xml_mdd':
                $statusXmlMdd = array(
                    1 => 'COMPLETE_SUCCESS',
                    2 => 'SUCCESS_WITH_WARNINGS',
                    3 => 'BLOCKING_ERROR',
                    4 => 'CRITICAL_ERROR',
                    5 => 'FATAL_ERROR'
                );

                $operatorValue = (isset($statusXmlMdd[$namedParameters['status']]) ? $statusXmlMdd[$namedParameters['status']] : $namedParameters['status']);
                break;
            case 'import_status_mdd_ez':
                $statusMddEz = array(
                    '-1' => 'DO_NOT_TREAT',
                    0    => 'INITIAL',
                    1    => 'SYNCHRO',
                    2    => 'ARTICLE_REF',
                    4    => 'CRITICAL_ERROR',
                    8    => 'FATAL_ERROR'
                );

                $operatorValue = (isset($statusMddEz[$namedParameters['status']]) ? $statusMddEz[$namedParameters['status']] : $namedParameters['status']);
                break;
            case 'getUserCustomerType':
                $user          = MMUsers::getCurrentUserObject();
                $operatorValue = ($user) ? $user->attribute('customer_type') : 'User not logged in';
                break;
            case 'isUserDataMissing':
                $instance      = MMUserData::instance();
                $operatorValue = $instance->isUserDataMissing($namedParameters['name']);
                break;
            case 'isMobile':
                $operatorValue = ContextTool::instance()->isMobile();
                break;
            case 'getExternalConfiguration':
                $operatorValue = ApplicationExternalConfiguration::getExternalConfiguration($namedParameters['id']);
                break;
            case 'getLocalizedApplicationByIdentifier':
                $operatorValue = CacheApplicationTool::buildLocalizedApplicationByIdentifier(
                    $namedParameters['identifier']
                );
                break;
            case 'getWebtrendsTimezone':
                $d = new DateTime('now', new DateTimeZone(eZINI::instance()->variable('TimeZoneSettings', 'TimeZone')));

                $operatorValue = ($d->getOffset() / 3600);
                break;
            case 'getChinaProvinceCity':
                $operatorValue = ChinaLocation::fetchProvincesAndCities();
                break;
            case 'isCatchUpAppNameEnabled':
                $operatorValue = MMGlobalSearch::isCatchUpAppNameEnabled();
                break;
            case 'gmdate':
                $operatorValue = gmdate($namedParameters['format'], $namedParameters['duration']);
                break;
            case 'mb_strtoupper':
                $operatorValue = mb_strtoupper($namedParameters['str']);
                break;
            case 'preg_replace':
                $operatorValue = preg_replace(
                    $namedParameters['pattern'],
                    $namedParameters['replacement'],
                    $namedParameters['subject'],
                    $namedParameters['$limit']
                );
                break;
            case 'html_entity_decode':
                $operatorValue = html_entity_decode($namedParameters['string']);
                break;
            case 'urlencode':
                $operatorValue = urlencode($namedParameters['string']);
                break;
            case 'json_encode':
                $operatorValue = json_encode($namedParameters['value']);
                break;
            case 'domain':
                $operatorValue = ContextTool::instance()->domain();
                break;
            case 'getUumpDateFormat':
                $operatorValue = SolrSafeOperatorHelper::clusterIni('EsbDateConvert', 'FormatDate', 'merck.ini' );
                break;
            case 'html_contains_image':
                $operatorValue = SolrSafeOperatorHelper::htmlContainsImage($namedParameters['string']);
                break;
            case 'preg_match':
                $operatorValue = preg_match (
                    $namedParameters['pattern'],
                    $namedParameters['subject']
                );
                break;
        }
    }