/* After PHP 5.6
const RESOURCE_ICONS = array(
'video' => 'fa-video-camera',
'slides' => 'fa-file-powerpoint-o',
'assignment' => 'fa-lock',
'solution' => 'fa-unlock',
'reference' => 'fa-external-link'
);
976413
public static function getUrlResources($module) {
        $resources = array();
        if ( isset($module->videos) ) {
            foreach($module->videos as $video ) {
                $resources[] = self::makeUrlResource('video',$video->title,
                    'https://www.youtube.com/watch?v='.urlencode($video->youtube));
            }
        }
        if ( isset($module->slides) ) {
            $resources[] = self::makeUrlResource('slides','Slides: '.$module->title, $module->slides);
        }
        if ( isset($module->assignment) ) {
            $resources[] = self::makeUrlResource('assignment','Assignment Specification', $module->assignment);
        }
        if ( isset($module->solution) ) {
            $resources[] = self::makeUrlResource('solution','Assignment Solution', $module->solution);
        }
        if ( isset($module->references) ) {
            foreach($module->references as $reference ) {
                $resources[] = self::makeUrlResource('reference',$reference->title, $reference->href);
            }
        }
        return $resources;
    }
1306586
function templ_rights($attrib)
    {
        // Get supported rights
        $supported = $this->rights_supported();

        // give plugins the opportunity to adjust this list
        $data = $this->rc->plugins->exec_hook('acl_rights_supported',
            array('rights' => $supported, 'folder' => $this->mbox, 'labels' => array()));
        $supported = $data['rights'];

        // depending on server capability either use 'te' or 'd' for deleting msgs
        $deleteright = implode(array_intersect(str_split('ted'), $supported));

        $out = '';
        $ul  = '';
        $input = new html_checkbox();

        // Advanced rights
        $attrib['id'] = 'advancedrights';
        foreach ($supported as $key => $val) {
            $id = "acl$val";
            $ul .= html::tag('li', null,
                $input->show('', array(
                    'name' => "acl[$val]", 'value' => $val, 'id' => $id))
                . html::label(array('for' => $id, 'title' => $this->gettext('longacl'.$val)),
                    $this->gettext('acl'.$val)));
        }

        $out = html::tag('ul', $attrib, $ul, html::$common_attrib);

        // Simple rights
        $ul = '';
        $attrib['id'] = 'simplerights';
        $items = array(
            'read' => 'lrs',
            'write' => 'wi',
            'delete' => $deleteright,
            'other' => preg_replace('/[lrswi'.$deleteright.']/', '', implode($supported)),
        );

        // give plugins the opportunity to adjust this list
        $data = $this->rc->plugins->exec_hook('acl_rights_simple',
            array('rights' => $items, 'folder' => $this->mbox, 'labels' => array(), 'titles' => array()));

        foreach ($data['rights'] as $key => $val) {
            $id = "acl$key";
            $ul .= html::tag('li', null,
                $input->show('', array(
                    'name' => "acl[$val]", 'value' => $val, 'id' => $id))
                . html::label(array('for' => $id, 'title' => $data['titles'][$key] ?: $this->gettext('longacl'.$key)),
                    $data['labels'][$key] ?: $this->gettext('acl'.$key)));
        }

        $out .= "\n" . html::tag('ul', $attrib, $ul, html::$common_attrib);

        $this->rc->output->set_env('acl_items', $data['rights']);

        return $out;
    }
151949
function () {
            var res = this.__resources;
            if (!res) {
                var src = this.$resources;
                if (src) {
                    this.__resources = res = {};
                    for (var itm in src) {
                        if (src.hasOwnProperty(itm)) {
                            res[itm] = this[itm];
                        }
                    }
                }
            }
            return res;
        }
1186031
function () {
            var messageTypes = this.data.messageTypes;
            var res = this.DEFAULT_ICON;
            var icons = this.ICONS;
            for (var i = 0, l = icons.length; i < l; i++) {
                var curIcon = icons[i];
                if (messageTypes[curIcon.type] > 0) {
                    res = curIcon.icon;
                    break;
                }
            }
            return res;
        }
139205
public function getMenuIcon()
    {
        // Look for these files by default
        // If your plugin directory contains an [post-type].png file, that will by default be the icon
        // Ex: hot-sauce.png
        $reflector = new \ReflectionClass(get_called_class());
        $dir = basename(dirname($reflector->getFileName()));
        $post_type = $this->getPostType();
        $fnames = array(
            $post_type.'.png',
            $post_type.'.gif',
            $post_type.'.jpg'
        );
        foreach ($fnames as $fname) {
            $fpath = sprintf('%s/%s/%s', WP_PLUGIN_DIR, $dir, $fname);
            if (!file_exists($fpath)) {
                continue;
            }

            return sprintf('%s/%s/%s', WP_PLUGIN_URL, $dir, $fname);
        }
        return '';
    }
81903
function () {

			var images = {};
			var blobs = {};

			if ( 'Video' in fbxTree.Objects ) {

				var videoNodes = fbxTree.Objects.Video;

				for ( var nodeID in videoNodes ) {

					var videoNode = videoNodes[ nodeID ];

					var id = parseInt( nodeID );

					images[ id ] = videoNode.RelativeFilename || videoNode.Filename;

					// raw image data is in videoNode.Content
					if ( 'Content' in videoNode ) {

						var arrayBufferContent = ( videoNode.Content instanceof ArrayBuffer ) && ( videoNode.Content.byteLength > 0 );
						var base64Content = ( typeof videoNode.Content === 'string' ) && ( videoNode.Content !== '' );

						if ( arrayBufferContent || base64Content ) {

							var image = this.parseImage( videoNodes[ nodeID ] );

							blobs[ videoNode.RelativeFilename || videoNode.Filename ] = image;

						}

					}

				}

			}

			for ( var id in images ) {

				var filename = images[ id ];

				if ( blobs[ filename ] !== undefined ) images[ id ] = blobs[ filename ];
				else images[ id ] = images[ id ].split( '\\' ).pop();

			}

			return images;

		}
1208720
private static function taskbarArrayTemplate():array
    {
        $options = array();
        try {
            $um =  new MasterCore();
            $options['css'] =  FEnv::get("host.web.components.libs.framework")."assets/css/iumioTaskBar.css";
            $options['css_icon'] =
                FEnv::get("host.web.components.libs.framework")."iumio-manager/css/pe-icon-7-stroke.css";
            $options['js'] = FEnv::get("host.web.components.libs.framework")."assets/js/iumioTaskBar.js";
            $options['logo'] =  FEnv::get("host.web.components.libs.framework")."img/logo_white_small.png";
            $options['ve']  =  \iumioFramework\Core\Requirement\FrameworkCore::
                getInfo('EDITION_VERSION')." ".\iumioFramework\Core\Requirement\FrameworkCore::
                getInfo('EDITION_SHORTNAME');
            $options['env'] = FEnv::get("framework.env");
            $options['call_app'] = ((!FEnv::isset("app.call"))? "No apps called" : FEnv::get("app.call"));
            $options['manager'] =  $um->generateRoute(
                "iumio_manager_index",
                null,
                "ManagerApp",
                true
            );
            $options['cache_clear_all']     =  $um->generateRoute(
                "iumio_manager_cache_manager_remove_all",
                null,
                "ManagerApp",
                true
            );
            $options['cache_clear_dev']     =  $um->generateRoute(
                "iumio_manager_cache_manager_remove",
                array("env" => "dev"),
                "ManagerApp",
                true
            );
            $options['cache_clear_prod']    =  $um->generateRoute(
                "iumio_manager_cache_manager_remove",
                array("env" => "prod"),
                "ManagerApp",
                true
            );
            $options['publish_assets_all']  =  $um->generateRoute(
                "iumio_manager_assets_manager_publish",
                array("env" => "all", "appname" => "_all"),
                "ManagerApp",
                true
            );
            $options['publish_assets_dev']  =  $um->generateRoute(
                "iumio_manager_assets_manager_publish",
                array("env" => "dev", "appname" => "_all"),
                "ManagerApp",
                true
            );
            $options['publish_assets_prod'] =  $um->generateRoute(
                "iumio_manager_assets_manager_publish",
                array("env" => "prod", "appname" => "_all"),
                "ManagerApp",
                true
            );
            $options['clear_assets_all']    =  $um->generateRoute(
                "iumio_manager_assets_manager_clear",
                array("env" => "all", "appname" => "_all"),
                "ManagerApp",
                true
            );
            $options['clear_assets_dev']    =  $um->generateRoute(
                "iumio_manager_assets_manager_clear",
                array("env" => "dev", "appname" => "_all"),
                "ManagerApp",
                true
            );
            $options['clear_assets_prod']   =  $um->generateRoute(
                "iumio_manager_assets_manager_clear",
                array("env" => "prod", "appname" => "_all"),
                "ManagerApp",
                true
            );
            $options['all_simple_apps']     =  $um->generateRoute(
                "iumio_manager_app_manager_get_simple_apps",
                null,
                "ManagerApp",
                true
            );
            $options['get_logs']            =  $um->generateRoute(
                "iumio_manager_logs_get",
                null,
                "ManagerApp",
                true
            );
        } catch (\Exception $e) {
            echo $e->getMessage();
        }
        return ($options);
    }
13385
static function processNodeTransformationNodes( $tpl, &$node, &$nodes, &$privateData )
    {
        $useComments = $privateData['use-comments'];
        $php =& $privateData['php-creator'];
        $resourceData =& $privateData['resource-data'];
        return eZTemplateCompiler::processNodeTransformationChildren( $useComments, $php, $tpl, $node, $nodes, $resourceData );
    }
552474
function options(o, k, a, i) {
  if(k==='--help') o.help = true;
  else if(k==='--version') o.version = true;
  else if(k==='-l' || k==='--log') o.log = true;
  else if(k==='-i' || k==='--id') o.id = a[++i];
  else if(k==='-v' || k==='--video') o.video = a[++i];
  else if(k==='-t' || k==='--thumbnail') o.thumbnail = a[++i];
  else if(k==='-c' || k==='--caption') o.caption = a[++i];
  else if(k==='-m' || k==='--meta') o.meta = a[++i];
  else if(k==='-d' || k==='--descriptionpath') o.descriptionpath = a[++i];
  else if(k==='-ci' || k==='--client_id') o.client_id = a[++i];
  else if(k==='-ct' || k==='--client_token') o.client_token = a[++i];
  else if(k==='-ot' || k==='--title') o.title = a[++i];
  else if(k==='-od' || k==='--description') o.description = a[++i];
  else if(k==='-ok' || k==='--tags') o.tags = a[++i];
  else if(k==='-ol' || k==='--language') o.language = a[++i];
  else if(k==='-oc' || k==='--category') o.category = a[++i];
  else if(k==='-op' || k==='--privacystatus') o.privacystatus = a[++i];
  else if(k==='-oe' || k==='--embeddable') o.embeddable = true;
  else if(k==='-ol' || k==='--license') o.license = a[++i];
  else if(k==='-os' || k==='--publicstatsviewable') o.publicstatsviewable = true;
  else if(k==='-opa' || k==='--publishat') o.publishat = a[++i];
  else if(k==='-ord' || k==='--recordingdate') o.recordingdate = a[++i];
  else if(k==='-opi' || k==='--playlistids') o.playlistids = a[++i];
  else if(k==='-opt' || k==='--playlisttitles') o.playlisttitles = a[++i];
  else if(k==='-ola' || k==='--location_latitude') o.location_latitude = a[++i];
  else if(k==='-olo' || k==='--location_longitude') o.location_longitude = a[++i];
  else if(k==='-old' || k==='--locationdescription') o.locationdescription = a[++i];
  else if(k==='-uc' || k==='--upload_chunk') o.upload_chunk = a[++i];
  else if(k==='-ur' || k==='--upload_rate') o.upload_rate = a[++i];
  else if(k==='-ut' || k==='--upload_time') o.upload_time = a[++i];
  else if(k==='-ap' || k==='--auth_port') o.auth_port = a[++i];
  else if(k==='-ah' || k==='--auth_headless') o.auth_headless = true;
  else o.input = a[i];
  return i+1;
}
359948
function _replaceMediaSources( xmlDoc, mediaMap ) {
    if ( !mediaMap ) {
        return xmlDoc;
    }

    // iterate through each element with a src attribute
    xmlDoc.find( '//*[@src] | //a[@href]' ).forEach( mediaEl => {
        const attribute = ( mediaEl.name().toLowerCase() === 'a' ) ? 'href' : 'src';
        const src = mediaEl.attr( attribute ).value();
        const matches = src ? src.match( /jr:\/\/[\w-]+\/(.+)/ ) : null;
        const filename = matches && matches.length ? matches[ 1 ] : null;
        const replacement = filename ? mediaMap[ filename ] : null;
        if ( replacement ) {
            mediaEl.attr( attribute, replacement );
        }
    } );

    // add form logo <img> element if applicable
    const formLogo = mediaMap[ 'form_logo.png' ];
    const formLogoEl = xmlDoc.get( '//*[@class="form-logo"]' );
    if ( formLogo && formLogoEl ) {
        formLogoEl
            .node( 'img' )
            .attr( 'src', formLogo )
            .attr( 'alt', 'form logo' );
    }

    return xmlDoc;
}
347379
public function getIcon(AbstractResource $resource, Workspace $workspace = null)
    {
        $node = $resource->getResourceNode();
        $mimeElements = explode('/', $node->getMimeType());
        $ds = DIRECTORY_SEPARATOR;
        // if video or img => generate the thumbnail, otherwise find an existing one.
        if (('video' === $mimeElements[0] || 'image' === $mimeElements[0])) {
            $this->om->startFlushSuite();
            $publicFile = $this->createFromFile(
                $this->fileDir.$ds.$resource->getHashName(),
                $mimeElements[0],
                $workspace
            );

            if ($publicFile) {
                $thumbnailPath = $this->webdir.$ds.$publicFile->getUrl();
                $relativeUrl = ltrim(str_replace($this->webdir, '', $thumbnailPath), "{$ds}");
                $icon = new ResourceIcon();
                $icon->setMimeType('custom');
                $icon->setRelativeUrl($relativeUrl);
                $icon->setShortcut(false);
                $icon->setUuid(uniqid('', true));
                $this->om->persist($icon);
                $this->om->endFlushSuite();

                $this->fu->createFileUse(
                  $publicFile,
                  get_class($icon),
                  $icon->getUuid(),
                  'resource-thumbnail'
                );

                return $icon;
            }
            $this->om->endFlushSuite();
        }

        //default & fallback
        return $this->searchIcon($node->getMimeType());
    }
1105417
static function generatePHPCode( $useComments, $php, $tpl, &$node, &$resourceData )
    {
        $parameters = array();
        $currentParameters = array( 'spacing' => 0 );
        $nodeType = $node[0];
        if ( $nodeType == eZTemplate::NODE_ROOT )
        {
            $children = $node[1];
            if ( $children )
            {
                eZTemplateCompiler::generatePHPCodeChildren( $useComments, $php, $tpl, $children, $resourceData, $parameters, $currentParameters );
            }
        }
        else
            $tpl->error( 'generatePHPCode', "Unknown root type $nodeType, should be " . eZTemplate::NODE_ROOT );
        $php->addSpace();
    }
974173
public function compile()
    {
        // Path prefix
        $prefix = $this->getNewPrefix();
        // List of images
        $data = $this->getList();

        // sizes
        $sizes = [];
        foreach ($this->providers as $provider) {
            if ($provider instanceof SizeProviderInterface) {
                $sizes = array_merge($sizes, $provider->getSizes());
            }
        }

        $num = 0;
        $scss = [];
        foreach ($data as $name => $list) {
            // Sprite size
            $size = !isset($sizes[$name]) ? null : $sizes[$name];
            $size = $this->getSize($name, $size);
            if (is_array($size)) {
                $border = $size[1];
                $sizeH = isset($size[2]) ? $size[2] : $size[0];
                $sizeW = $size[0];
            } else {
                $border = static::BORDER_WIDTH;
                $sizeH = $sizeW = $size;
            }
            $scss[] = $this->compileFile($prefix, $name, $list, [$sizeW, $sizeH], $border);
            $num += count($list);
        }

        // Populating template
        $template = file_get_contents($this->template);
        $scss = str_replace(
            static::TEMPLATE_NEEDLE, join("\n", $scss), $template
        );

        // Creating global classes
        if (static::CREATE_CLASSES) {
            foreach ($data as $name => $list) {
                $scss .= '.#{$' . static::NAMESPACE_NAME . '}';
                $scss .= ', .#{$' . static::NAMESPACE_NAME . '}-' . $name . ' {' . "\n";
                $scss .= '@include ' . static::PREFIX_SPRITE . $name . ';' . "\n";
                $scss .= '};' . "\n";
            }
        }

        // Writing the file
        file_put_contents($this->stylePath, $scss);

        return $num;
    }
744673
function () {
        var self = this, id = self._id, prefix = self.classPrefix;
        var icon = self.state.get('icon'), image, text = self.state.get('text'), textHtml = '';

        image = self.settings.image;
        if (image) {
          icon = 'none';

          // Support for [high dpi, low dpi] image sources
          if (typeof image != "string") {
            image = window.getSelection ? image[0] : image[1];
          }

          image = ' style="background-image: url(\'' + image + '\')"';
        } else {
          image = '';
        }

        if (text) {
          self.classes.add('btn-has-text');
          textHtml = '<span class="' + prefix + 'txt">' + self.encode(text) + '</span>';
        }

        icon = icon ? prefix + 'ico ' + prefix + 'i-' + icon : '';

        return (
          '<div id="' + id + '" class="' + self.classes + '" tabindex="-1" aria-labelledby="' + id + '">' +
          '<button role="presentation" type="button" tabindex="-1">' +
          (icon ? '<i class="' + icon + '"' + image + '></i>' : '') +
          textHtml +
          '</button>' +
          '</div>'
        );
      }
1229932
private function createCoreImages()
    {
        Helper::createFolderIfNoExist(PATH_HOME . "assetsPublic/img");
        $config = json_decode(file_get_contents(PATH_HOME . "_config/config.json"), true);
        copy(PATH_HOME . VENDOR . "config/public/assets/dino.png", PATH_HOME . "assetsPublic/img/dino.png");
        copy(PATH_HOME . VENDOR . "config/public/assets/file.png", PATH_HOME . "assetsPublic/img/file.png");
        copy(PATH_HOME . VENDOR . "config/public/assets/save.gif", PATH_HOME . "assetsPublic/img/save.gif");
        copy(PATH_HOME . VENDOR . "config/public/assets/file_type.svg", PATH_HOME . "assetsPublic/img/file_type.svg");
        copy(PATH_HOME . VENDOR . "config/public/assets/image-not-found.png", PATH_HOME . "assetsPublic/img/img.png");

        if(file_exists(PATH_HOME . (!empty($config['favicon']) ? "uploads/site/favicon.png" : VENDOR . "config/public/assets/favicon.png")))
        copy(PATH_HOME . (!empty($config['favicon']) ? "uploads/site/favicon.png" : VENDOR . "config/public/assets/favicon.png"), PATH_HOME . "assetsPublic/img/favicon.png");

        if(!empty($config['logo']) && file_exists(PATH_HOME . "uploads/site/logo.png"))
            copy(PATH_HOME . "uploads/site/logo.png", PATH_HOME . "assetsPublic/img/logo.png");

        elseif(file_exists(PATH_HOME . "assetsPublic/img/logo.png"))
            unlink(PATH_HOME . "assetsPublic/img/logo.png");
    }
100082
static function processNodeTransformationRoot( $useComments, $php, $tpl, &$node, &$resourceData )
    {
        $nodeType = $node[0];
        if ( $nodeType == eZTemplate::NODE_ROOT )
        {
            $children = $node[1];
            $newNode = array( $nodeType,
                              false );
            if ( $children )
            {
                $newChildren = array();
                foreach ( $children as $childNode )
                {
                    $newChildNode = eZTemplateCompiler::processNodeTransformationChild( $useComments, $php, $tpl, $childNode, $resourceData );
                    if ( !$newChildNode )
                        $newChildren[] = $childNode;
                    else
                        $newChildren = array_merge( $newChildren, $newChildNode );
                }
                if ( count( $newChildren ) > 0 )
                    $newNode[1] = $newChildren;
            }
            return $newNode;
        }
        else
            $tpl->error( 'processNodeTransformation', "Unknown root type $nodeType, should be " . eZTemplate::NODE_ROOT );
        return false;
    }
244237
static function compileTemplate( $tpl, $key, &$resourceData )
    {
        if ( !eZTemplateCompiler::isCompilationEnabled() )
            return false;

        $resourceData['use-comments'] = eZTemplateCompiler::isCommentsEnabled();

        $cacheFileName = eZTemplateCompiler::compilationFilename( $key, $resourceData );
        $resourceData['uniqid'] = md5( $resourceData['template-filename']. uniqid( "ezp". getmypid(), true ) );

        // Time limit #1:
        // We reset the time limit to 30 seconds to ensure that templates
        // have enough time to compile
        // However if time limit is unlimited (0) we leave it be
        // Time limit will also be reset after subtemplates are compiled
        $maxExecutionTime = ini_get( 'max_execution_time' );
        if ( $maxExecutionTime != 0 && $maxExecutionTime < 30 )
        {
            @set_time_limit( 30 );
        }

        $rootNode =& $resourceData['root-node'];
        if ( !$rootNode )
            return false;

        $GLOBALS['eZTemplateCompilerResourceCache'][$resourceData['template-filename']] =& $resourceData;

        $useComments = eZTemplateCompiler::isCommentsEnabled();

        if ( !$resourceData['test-compile'] )
        {
            eZTemplateCompiler::createCommonCompileTemplate();
        }

        /* Check if we need to disable the generation of spacing for the compiled templates */
        $ini = eZINI::instance();
        $spacing = 'disabled';
        if ( $ini->variable( 'TemplateSettings', 'UseFormatting' ) == 'enabled' )
        {
            $spacing = 'enabled';
        }

        $php = new eZPHPCreator( eZTemplateCompiler::compilationDirectory(), $cacheFileName,
                                 eZTemplateCompiler::TemplatePrefix(), array( 'spacing' => $spacing ) );
        $php->addComment( 'URI:       ' . $resourceData['uri'] );
        $php->addComment( 'Filename:  ' . $resourceData['template-filename'] );
        $php->addComment( 'Timestamp: ' . $resourceData['time-stamp'] . ' (' . date( 'D M j G:i:s T Y', $resourceData['time-stamp'] ) . ')' );

        $php->addCodePiece("\$oldSetArray_{$resourceData['uniqid']} = isset( \$setArray ) ? \$setArray : array();\n".
                           "\$setArray = array();\n");
// Code to decrement include level of the templates
        $php->addCodePiece( "\$tpl->Level++;\n" );
        $php->addCodePiece( "if ( \$tpl->Level > $tpl->MaxLevel )\n".
                            "{\n".
                            "\$text = \$tpl->MaxLevelWarning;".
                            "\$tpl->Level--;\n".
                            "return;\n".
                            "}\n" );
        if ( $resourceData['locales'] && count( $resourceData['locales'] ) )
        {
            $php->addComment( 'Locales:   ' . join( ', ', $resourceData['locales'] ) );

            $php->addCodePiece(
                '$locales = array( "'. join( '", "', $resourceData['locales'] ) . "\" );\n".
                '$oldLocale_'. $resourceData['uniqid']. ' = setlocale( LC_CTYPE, null );'. "\n".
                '$currentLocale_'. $resourceData['uniqid']. ' = setlocale( LC_CTYPE, $locales );'. "\n"
            );
        }
//         $php->addCodePiece( "print( \"" . $resourceData['template-filename'] . " ($cacheFileName)<br/>\n\" );" );
        if ( $useComments )
        {
            $templateFilename = $resourceData['template-filename'];
            if ( file_exists( $templateFilename ) )
            {
                $fd = fopen( $templateFilename, 'rb' );
                if ( $fd )
                {
                    $templateText = fread( $fd, filesize( $templateFilename ) );
                    $php->addComment( "Original code:\n" . $templateText );
                    fclose( $fd );
                }
            }
        }
        $php->addVariable( 'eZTemplateCompilerCodeDate', eZTemplateCompiler::CODE_DATE );
        $php->addCodePiece( "if ( !defined( 'EZ_TEMPLATE_COMPILER_COMMON_CODE' ) )\n" );
        $php->addInclude( eZTemplateCompiler::compilationDirectory() . '/common.php', eZPHPCreator::INCLUDE_ONCE_STATEMENT, array( 'spacing' => 4 ) );
        $php->addSpace();

        if ( eZTemplateCompiler::isAccumulatorsEnabled() )
        {
            $php->addCodePiece( "eZDebug::accumulatorStart( 'template_compiled_execution', 'template_total', 'Template compiled execution', true );\n" );
        }
        if ( eZTemplateCompiler::isTimingPointsEnabled() )
        {
            $php->addCodePiece( "eZDebug::addTimingPoint( 'Script start $cacheFileName' );\n" );
        }

//         $php->addCodePiece( "if ( !isset( \$vars ) )\n    \$vars =& \$tpl->Variables;\n" );
//         $php->addSpace();

        $parameters = array();
        $textName = eZTemplateCompiler::currentTextName( $parameters );

//         $php->addCodePiece( "if ( !isset( \$$textName ) )\n    \$$textName = '';\n" );
//         $php->addSpace();

        $transformedTree = array();
        eZTemplateCompiler::processNodeTransformation( $useComments, $php, $tpl, $rootNode, $resourceData, $transformedTree );

        if ( $ini->variable( 'TemplateSettings', 'TemplateOptimization' ) == 'enabled' )
        {
            /* Retrieve class information for the attribute lookup table */
            if ( isset( $resourceData['handler']->Keys ) and isset( $resourceData['handler']->Keys['class'] ) ) {
                $resourceData['class-info'] = eZTemplateOptimizer::fetchClassDeclaration( $resourceData['handler']->Keys['class'] );
            }
            /* Run the optimizations */
            eZTemplateOptimizer::optimize( $useComments, $php, $tpl, $transformedTree, $resourceData );
        }

        $staticTree = array();
        eZTemplateCompiler::processStaticOptimizations( $useComments, $php, $tpl, $transformedTree, $resourceData, $staticTree );

        $combinedTree = array();
        eZTemplateCompiler::processNodeCombining( $useComments, $php, $tpl, $staticTree, $resourceData, $combinedTree );

        $finalTree = $combinedTree;
        if ( !eZTemplateCompiler::isNodePlacementEnabled() )
            eZTemplateCompiler::processRemoveNodePlacement( $finalTree );

        eZTemplateCompiler::generatePHPCode( $useComments, $php, $tpl, $finalTree, $resourceData );

        if ( eZTemplateCompiler::isTreeEnabled( 'final' ) )
            $php->addVariable( 'finalTree', $finalTree, eZPHPCreator::VARIABLE_ASSIGNMENT, array( 'full-tree' => true ) );
        if ( eZTemplateCompiler::isTreeEnabled( 'combined' ) )
            $php->addVariable( 'combinedTree', $combinedTree, eZPHPCreator::VARIABLE_ASSIGNMENT, array( 'full-tree' => true ) );
        if ( eZTemplateCompiler::isTreeEnabled( 'static' ) )
            $php->addVariable( 'staticTree', $staticTree, eZPHPCreator::VARIABLE_ASSIGNMENT, array( 'full-tree' => true ) );
        if ( eZTemplateCompiler::isTreeEnabled( 'transformed' ) )
            $php->addVariable( 'transformedTree', $transformedTree, eZPHPCreator::VARIABLE_ASSIGNMENT, array( 'full-tree' => true ) );
        if ( eZTemplateCompiler::isTreeEnabled( 'original' ) )
            $php->addVariable( 'originalTree', $rootNode, eZPHPCreator::VARIABLE_ASSIGNMENT, array( 'full-tree' => true ) );

        if ( eZTemplateCompiler::isTimingPointsEnabled() )
            $php->addCodePiece( "eZDebug::addTimingPoint( 'Script end $cacheFileName' );\n" );
        if ( eZTemplateCompiler::isAccumulatorsEnabled() )
            $php->addCodePiece( "eZDebug::accumulatorStop( 'template_compiled_execution', true );\n" );

        if ( $resourceData['locales'] && count( $resourceData['locales'] ) )
        {
            $php->addCodePiece(
                'setlocale( LC_CTYPE, $oldLocale_'. $resourceData['uniqid']. ' );'. "\n"
            );
        }
        $php->addCodePiece('$setArray = $oldSetArray_'. $resourceData['uniqid']. ";\n");

// Code to decrement include level of the templates
        $php->addCodePiece("\$tpl->Level--;\n" );

        /*
        // dump names of all defined PHP variables
        $php->addCodePiece( "echo \"defined vars in $resourceData[uri]:<br/><pre>\\n\";\n" );
        $php->addCodePiece( 'foreach ( array_keys( get_defined_vars() ) as $var_name  ) echo "- $var_name\n";' );
        // dump tpl vars
        $php->addCodePiece( 'echo "\n-----------------------------------------------------------\nvars: ";' );
        $php->addCodePiece( 'var_dump( $vars );' );
        $php->addCodePiece( 'echo "</pre><hr/>\n";' );
        */

        if ( !$resourceData['test-compile'] )
        {
            $php->store( true );
        }

        return true;
    }