Generate a file item and return it as HTML string
@param string
@return string
966368
protected function generateFileItem($strPath)
    {
        if (!is_file(TL_ROOT . '/' . $strPath)) {
            return '';
        }

        $imageSize = $this->getImageSize();
        $objFile = new \File($strPath, true);
        $strInfo = $strPath . ' <span class="tl_gray">(' . \System::getReadableSize($objFile->size) . ($objFile->isGdImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';
        $allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
        $strReturn = '';

        // Show files and folders
        if (!$this->blnIsGallery && !$this->blnIsDownloads) {
            if ($objFile->isGdImage) {
                $strReturn = \Image::getHtml(\Image::get($strPath, $imageSize[0], $imageSize[1], $imageSize[2]), '', 'class="gimage" title="' . specialchars($strInfo) . '"');
            } else {
                $strReturn = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
            }
        }

        // Show a sortable list of files only
        else {
            if ($this->blnIsGallery) {
                // Only show images
                if ($objFile->isGdImage) {
                    $strReturn = \Image::getHtml(\Image::get($strPath, $imageSize[0], $imageSize[1], $imageSize[2]), '', 'class="gimage" title="' . specialchars($strInfo) . '"');
                }
            } else {
                // Only show allowed download types
                if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\.txt$/', $objFile->basename)) {
                    $strReturn = \Image::getHtml($objFile->icon) . ' ' . $strPath;
                }
            }
        }

        return $strReturn;
    }
1145875
static function getOutputEncodingHtml()
    {

        $txt = '';
        $tmp1 = '<meta http-equiv="Content-Type" content="text/html; charset=';
        $tmp2 = '" />';
        switch (ReporticoApp::getConfig("output_encoding")) {
            case "None":$txt = '';
                break;
            case "UTF8":$txt = $tmp1 . "utf-8" . $tmp2;'<meta charset="utf-8">';
                break;
            default:$txt = $tmp1 . ReporticoApp::getConfig("output_encoding") . $tmp2;
                break;
        }

        return $txt;
    }
1299727
public function toString()
    {
        $items = $this->data;

        $attachedBaseLib = false;
        $return = array('file' => '', 'script' => '');
        foreach ($items as $item) {
            if ($item['mode'] == 'file' && isset($item['attributes']['src'])) {
                // looking for duplicated base library
                if ($item['attributes']['src'] == $this->getBaseLibrary() && !$attachedBaseLib) {
                    $attachedBaseLib = true;
                } elseif ($item['attributes']['src'] == $this->getBaseLibrary()) {
                    // we have attached base library before
                    continue;
                }
            }

            $return[$item['mode']] .= PHP_EOL.
                $this->startElement().$this->writeAttributes($item['attributes']).$this->endElement().
                (($item['mode'] == 'script') ? $this->overrideScript($item['content']) : '').
                $this->startElement(true).$this->endElement()
            ;
        }

        $return = $return['file'].PHP_EOL.
            $return['script'].PHP_EOL;

        return $return;
    }
856769
private static function string()
    {
        $files = ['Strings'];
        $folder = static::$root.'Strings'.'/';

        self::call($files, $folder);

        $files = ['StringOutIndexException'];
        $folder = static::$root.'Strings/Exceptions'.'/';

        self::call($files, $folder);
    }
1096073
public function generateExtension($file = null)
    {
        if (is_string($file)) {
            if (in_array($file, $this->acceptedMimetypes())) {
                $mime = $file;
            } else {
                $mime = $this->mimetypeFor($file);
            }
        } else {
            $mime = $this->mimetype();
        }

        switch ($mime) {
            case 'image/gif':
                return 'gif';

            case 'image/jpg':
            case 'image/jpeg':
            case 'image/pjpeg':
                return 'jpg';

            case 'image/png':
                return 'png';

            case 'image/svg+xml':
                return 'svg';

            case 'image/webp':
                return 'webp';
        }
    }
589241
protected static function mPDFWrapper($html)
    {
        $pdf = new \Mpdf\Mpdf();
        $pdf->WriteHTML($html);

        return $pdf->Output('','S');    // returns the PDF as a string
    }
17033
function toHtml() {
        global $CFG, $PAGE, $OUTPUT;
        require_once($CFG->dirroot.'/repository/lib.php');

        if ($this->_flagFrozen) {
            return $this->getFrozenHtml();
        }

        $ctx = $this->_options['context'];

        $id           = $this->_attributes['id'];
        $elname       = $this->_attributes['name'];

        $subdirs      = $this->_options['subdirs'];
        $maxbytes     = $this->_options['maxbytes'];
        $areamaxbytes = $this->_options['areamaxbytes'];
        $maxfiles     = $this->_options['maxfiles'];
        $changeformat = $this->_options['changeformat']; // TO DO: implement as ajax calls

        $text         = $this->_values['text'];
        $format       = $this->_values['format'];
        $draftitemid  = $this->_values['itemid'];

        // security - never ever allow guest/not logged in user to upload anything
        if (isguestuser() or !isloggedin()) {
            $maxfiles = 0;
        }

        $str = $this->_getTabs();
        $str .= '<div>';

        $editor = editors_get_preferred_editor($format);
        $strformats = format_text_menu();
        $formats =  $editor->get_supported_formats();
        foreach ($formats as $fid) {
            $formats[$fid] = $strformats[$fid];
        }

        // get filepicker info
        //
        $fpoptions = array();
        if ($maxfiles != 0 ) {
            if (empty($draftitemid)) {
                // no existing area info provided - let's use fresh new draft area
                require_once("$CFG->libdir/filelib.php");
                $this->setValue(array('itemid'=>file_get_unused_draft_itemid()));
                $draftitemid = $this->_values['itemid'];
            }

            $args = new stdClass();
            // need these three to filter repositories list
            $args->accepted_types = array('web_image');
            $args->return_types = $this->_options['return_types'];
            $args->context = $ctx;
            $args->env = 'filepicker';
            // advimage plugin
            $image_options = initialise_filepicker($args);
            $image_options->context = $ctx;
            $image_options->client_id = uniqid();
            $image_options->maxbytes = $this->_options['maxbytes'];
            $image_options->areamaxbytes = $this->_options['areamaxbytes'];
            $image_options->env = 'editor';
            $image_options->itemid = $draftitemid;

            // moodlemedia plugin
            $args->accepted_types = array('video', 'audio');
            $media_options = initialise_filepicker($args);
            $media_options->context = $ctx;
            $media_options->client_id = uniqid();
            $media_options->maxbytes  = $this->_options['maxbytes'];
            $media_options->areamaxbytes  = $this->_options['areamaxbytes'];
            $media_options->env = 'editor';
            $media_options->itemid = $draftitemid;

            // advlink plugin
            $args->accepted_types = '*';
            $link_options = initialise_filepicker($args);
            $link_options->context = $ctx;
            $link_options->client_id = uniqid();
            $link_options->maxbytes  = $this->_options['maxbytes'];
            $link_options->areamaxbytes  = $this->_options['areamaxbytes'];
            $link_options->env = 'editor';
            $link_options->itemid = $draftitemid;

            $args->accepted_types = array('.vtt');
            $subtitle_options = initialise_filepicker($args);
            $subtitle_options->context = $ctx;
            $subtitle_options->client_id = uniqid();
            $subtitle_options->maxbytes  = $this->_options['maxbytes'];
            $subtitle_options->areamaxbytes  = $this->_options['areamaxbytes'];
            $subtitle_options->env = 'editor';
            $subtitle_options->itemid = $draftitemid;

            $fpoptions['image'] = $image_options;
            $fpoptions['media'] = $media_options;
            $fpoptions['link'] = $link_options;
            $fpoptions['subtitle'] = $subtitle_options;
        }

        //If editor is required and tinymce, then set required_tinymce option to initalize tinymce validation.
        if (($editor instanceof tinymce_texteditor)  && !is_null($this->getAttribute('onchange'))) {
            $this->_options['required'] = true;
        }

        // print text area - TODO: add on-the-fly switching, size configuration, etc.
        $editor->set_text($text);
        $editor->use_editor($id, $this->_options, $fpoptions);

        $rows = empty($this->_attributes['rows']) ? 15 : $this->_attributes['rows'];
        $cols = empty($this->_attributes['cols']) ? 80 : $this->_attributes['cols'];

        //Apply editor validation if required field
        $context = [];
        $context['rows'] = $rows;
        $context['cols'] = $cols;
        $context['frozen'] = $this->_flagFrozen;
        foreach ($this->getAttributes() as $name => $value) {
            $context[$name] = $value;
        }
        $context['hasformats'] = count($formats) > 1;
        $context['formats'] = [];
        if (($format === '' || $format === null) && count($formats)) {
            $format = key($formats);
        }
        foreach ($formats as $formatvalue => $formattext) {
            $context['formats'][] = ['value' => $formatvalue, 'text' => $formattext, 'selected' => ($formatvalue == $format)];
        }
        $context['id'] = $id;
        $context['value'] = $text;
        $context['format'] = $format;

        if (!is_null($this->getAttribute('onblur')) && !is_null($this->getAttribute('onchange'))) {
            $context['changelistener'] = true;
        }

        $str .= $OUTPUT->render_from_template('core_form/editor_textarea', $context);

        // during moodle installation, user area doesn't exist
        // so we need to disable filepicker here.
        if (!during_initial_install() && empty($CFG->adminsetuppending)) {
            // 0 means no files, -1 unlimited
            if ($maxfiles != 0 ) {
                $str .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $elname.'[itemid]',
                        'value' => $draftitemid));

                // used by non js editor only
                $editorurl = new moodle_url("$CFG->wwwroot/repository/draftfiles_manager.php", array(
                    'action'=>'browse',
                    'env'=>'editor',
                    'itemid'=>$draftitemid,
                    'subdirs'=>$subdirs,
                    'maxbytes'=>$maxbytes,
                    'areamaxbytes' => $areamaxbytes,
                    'maxfiles'=>$maxfiles,
                    'ctx_id'=>$ctx->id,
                    'course'=>$PAGE->course->id,
                    'sesskey'=>sesskey(),
                    ));
                $str .= '<noscript>';
                $str .= "<div><object type='text/html' data='$editorurl' height='160' width='600' style='border:1px solid #000'></object></div>";
                $str .= '</noscript>';
            }
        }


        $str .= '</div>';

        return $str;
    }
407767
public function generateHTML() {
        //create blocktrail pub key QR codes if not already done
        if (!$this->blocktrailPubKeyQRs) {
            $this->processBlocktrailPubKeys();
        }
        $pubKeysHtml = "";
        foreach ($this->blocktrailPubKeyQRs as $pubKey) {
            $pubKeysHtml .= "<img src='{$pubKey['qr']}' />";
        }
        $totalPubKeys = count($this->blocktrailPubKeyQRs);

        $backupInfo = $this->prepareBackupInfo();
        $extraInfo = $this->prepareExtraInfo();

        $passwordEncryptedSecret = null;
        if (isset($this->backupInfo['encrypted_secret'])) {
            $passwordEncryptedSecret = $this->backupInfo['encrypted_secret'];
        }

        $html = self::renderTemplate(__DIR__ . "/../resources/templates/recovery_sheet.html.php", [
            'identifier' => $this->identifier,
            'totalPubKeys' => $totalPubKeys,
            'pubKeysHtml' => $pubKeysHtml,
            'backupInfo' => $backupInfo,
            'extraInfo' => $extraInfo,
            'passwordEncryptedSecret' => $passwordEncryptedSecret,
            'options' => $this->options,
        ]);

        return $html;
    }
9605
function generateDemoHtml(done) {
			if (!o.htmlDemo) {
				done();
				return;
			}

			var context = prepareHtmlTemplateContext();

			// Generate HTML
			var demoTemplate = readTemplate(o.htmlDemoTemplate, 'demo', '.html');
			var demo = renderTemplate(demoTemplate, context);

			mkdirp(getDemoPath(), function(err) {
				if (err) {
					logger.log(err);
					return;
				}
				// Save file
				fs.writeFileSync(getDemoFilePath(), demo);
				done();
			});

		}
801721
private function createRawDomDocument($html)
    {
        $domDocument = new \DOMDocument();
        $domDocument->strictErrorChecking = false;
        $domDocument->formatOutput = true;
        $libXmlState = \libxml_use_internal_errors(true);
        $domDocument->loadHTML($this->prepareHtmlForDomConversion($html));
        \libxml_clear_errors();
        \libxml_use_internal_errors($libXmlState);

        $this->domDocument = $domDocument;
    }
1300289
public static function generate($file)
    {
        $filePointer = fopen($file, 'rb');

        $names = '';
        $extensions = '';

        $header = true;
        while (($row = fgetcsv($filePointer))) {
            if ($header) {
                $header = false;
                continue;
            }

            $mime = trim($row[0]);
            $name = trim(addslashes($row[1]));
            $extension = trim($row[2]);

            $extensions .= "\t\t'$mime' => '$extension',\n";
            $names .= "\t\t'$mime' => '$name',\n";
        }

        $class = '';
        $class .= self::getHeader();
        $class .= self::getFunctions();
        $class .= self::getPropertyMimesHeader();
        $class .= $extensions;
        $class .= self::getPropertyMimesFooter();
        $class .= self::getPropertyNamesHeader();
        $class .= $names;
        $class .= self::getPropertyNamesFooter();
        $class .= self::getFooter();

        file_put_contents(__DIR__ . '/FileMimes.php', $class);
    }
13780
static function buildFromString($str, $lowercase=true, $forceTagsClosed=true, $target_charset = self::DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=self::DEFAULT_BR_TEXT, $defaultSpanText=self::DEFAULT_SPAN_TEXT)
    {
        $dom = new Tree(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);
        if (empty($str) or strlen($str) > self::MAX_FILE_SIZE)
        {
            $dom->clear();
            return false;
        }
        $dom->load($str, $lowercase, $stripRN);
        return $dom;
    }
603856
function toString( $objectAttribute )
    {
        $binaryFile = $objectAttribute->content();

        if ( is_object( $binaryFile ) )
        {
            return implode( '|', array( $binaryFile->attribute( 'filepath' ), $binaryFile->attribute( 'original_filename' ) ) );
        }
        else
            return '';
    }
185269
public function toString(): string
    {
        $content = $this->content;
        $contentType = $this->contentType;

        if ($this->isString()) {
            return $content;
        } elseif ($this->isImage()) {
            switch ($contentType) {
                case self::CONTENT_TYPE_IMAGE_JPEG:
                    imagejpeg($content)
                        && imagedestroy($content);
                    break;
                case self::CONTENT_TYPE_IMAGE_PNG:
                    imagepng($content)
                        && imagedestroy($content);
                    break;
                case self::CONTENT_TYPE_IMAGE_GIF:
                    imagegif($content)
                        && imagedestroy($content);
                    break;
                default:
                    throw new HttpException("Unimplemented content type '{$contentType}'");
            }
            return '';
        }
    }
826972
public function generateListing()
    {
        if (!$content = $this->getListingContent()) {
            return '';
        }

        $path = app_path('Listings/'.implode('/', $this->sectionSegmentsStudly).'Listing.php');

        if (is_file($path)) {
            return '';
        }

        $this->createMissingDirs($path);

        return file_put_contents($path, $content) !== false ? $path : '';
    }
438417
public function dumpAsHtml()
	{
		$arguments = func_get_args();
		$total = count($arguments);

		$backtrace = debug_backtrace();

		// locate the first file entry that isn't this class itself
		foreach ($backtrace as $stack => $trace)
		{
			if (isset($trace['file']))
			{
				// If being called from within, or using call_user_func(), get the next entry
				if (strpos($trace['function'], 'call_user_func') === 0 or (isset($trace['class']) and $trace['class'] == get_class($this)))
				{
					continue;
				}

				$callee = $trace;
				$label = $this->inflector->humanize($backtrace[$stack+1]['function']);

				// get info about what was dumped
				$callee['code'] = '';
				for ($i = $callee['line']; $i > 0; $i--)
				{
					$line = $this->fileLines($callee['file'], $i, false, 0);
					$callee['code'] = reset($line).' '.trim($callee['code']);
					$tokens = token_get_all('<?php '.trim($callee['code']));
					if (is_array($tokens[1]) and isset($tokens[1][0]) and $tokens[1][0] != 377)
					{
						break;
					}
				}

				$results = array();
				$r = false;
				$c = 0;

				foreach($tokens as $token)
				{
					// skip everything before our function call
					if ($r === false)
					{
						if (isset($token[1]) and $token[1] == $callee['function'])
						{
							$r = 0;
						}
						continue;
					}

					// and quit if we find an end-of-statement
					if ($token == ';')
					{
						break;
					}

					// check for a start-of-expresssion
					elseif ($token == '(')
					{
						$c++;
						if ($c === 1)
						{
							continue;
						}
					}

					// check for an end-of-expresssion
					elseif ($token == ')')
					{
						$c--;
						if ($c === 0)
						{
							$r++;
							continue;
						}
					}

					// new expression in the same dump
					elseif ($token == ',' and $c === 1)
					{
						$r++;
						continue;
					}

					// make sure we have an array entry to add to, and add the token
					if ( ! isset($results[$r]))
					{
						$results[$r] = '';
					}
					$results[$r] .= is_array($token) ? $token[1] : $token;
				}

				// make sure we've parsed the same number of expressions as we have arguments
				if (count($results) == $total)
				{
					$callee['code'] = $results;
				}
				else
				{
					// parsing failed, try it the old fashioned way
					if (preg_match('/(.*'.$callee['function'].'\()(.*?)\);(.*)/', $callee['code'], $matches))
					{
						$callee['code'] = 'Variable'.($total==1?'':'s').' dumped: '.$matches[2];
					}
				}

				$callee['file'] = cleanpath($callee['file']);

				break;
			}
		}

		if ( ! $this->jsDisplayed)
		{
			echo <<<JS
<script type="text/javascript">function fuel_debug_toggle(a){if(document.getElementById){if(document.getElementById(a).style.display=="none"){document.getElementById(a).style.display="block"}else{document.getElementById(a).style.display="none"}}else{if(document.layers){if(document.id.display=="none"){document.id.display="block"}else{document.id.display="none"}}else{if(document.all.id.style.display=="none"){document.all.id.style.display="block"}else{document.all.id.style.display="none"}}}};</script>
JS;
			$this->jsDisplayed = true;
		}

		echo '<div class="fuelphp-dump" style="font-size: 13px;background: #EEE !important; border:1px solid #666; color: #000 !important; padding:10px;">';
		echo '<h1 style="padding: 0 0 5px 0; margin: 0; font: bold 110% sans-serif;">File: '.$callee['file'].' @ line: '.$callee['line'].'</h1>';
		if (is_string($callee['code']))
		{
			echo '<h5 style="border-bottom: 1px solid #CCC;padding: 0 0 5px 0; margin: 0 0 5px 0; font: bold 85% sans-serif;">'.$callee['code'].'</h5>'.PHP_EOL;
		}
		echo '<pre style="overflow:auto;font-size:100%;">';

		$i = 0;
		foreach ($arguments as $argument)
		{
			if (is_string($callee['code']))
			{
				echo '<strong>Variable #'.(++$i).' of '.$total.':</strong>'.PHP_EOL;
			}
			elseif (substr(trim($callee['code'][$i]),0,1) == '$')
			{
				echo '<strong>Variable: '.trim($callee['code'][$i++]).'</strong>'.PHP_EOL;
			}
			else
			{
				echo '<strong>Expression: '.trim($callee['code'][$i++]).'</strong>'.PHP_EOL;
			}
			echo $this->format('', $argument);
			if ($i < $total)
			{
				echo PHP_EOL;
			}
		}

		echo "</pre>";
		echo "</div>";
	}
1021387
protected function build($m)
    {
        $string = $m[1];

        if (substr($string, 0, 1) != '<') {
            // We matched a lone ">" character.
            return '&gt;';
        } elseif (strlen($string) == 1) {
            // We matched a lone "<" character.
            return '&lt;';
        }

        if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9\-]+)([^>]*)>?|(<!--.*?-->)$%', $string, $matches)) {
            // Seriously malformed.
            return '';
        }

        $slash = trim($matches[1]);
        $elem = &$matches[2];
        $attrlist = &$matches[3];
        $comment = &$matches[4];

        if ($comment) {
            $elem = '!--';
        }

        if (!in_array(strtolower($elem), $this->tags, true)) {
            return ''; // Disallowed HTML element.
        }

        if ($comment) {
            return $comment;
        }

        if ($slash != '') {
            return "</$elem>";
        }

        // Is there a closing XHTML slash at the end of the attributes?
        $attrlist = preg_replace('%(\s?)/\s*$%', '\1', $attrlist, -1, $count);
        $xhtml_slash = $count ? ' /' : '';

        // Clean up attributes.
        $attr2 = implode(' ', $this->explodeAttributes($attrlist));
        $attr2 = preg_replace('/[<>]/', '', $attr2);
        $attr2 = strlen($attr2) ? ' ' . $attr2 : '';

        return "<$elem$attr2$xhtml_slash>";
    }