当前位置: 首页>>代码示例>>PHP>>正文


PHP GeSHi::set_language方法代码示例

本文整理汇总了PHP中GeSHi::set_language方法的典型用法代码示例。如果您正苦于以下问题:PHP GeSHi::set_language方法的具体用法?PHP GeSHi::set_language怎么用?PHP GeSHi::set_language使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GeSHi的用法示例。


在下文中一共展示了GeSHi::set_language方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onExtra

 function onExtra($name)
 {
     $output = NULL;
     if ($name == "header") {
         if (!$this->yellow->config->get("highlightStylesheetDefault")) {
             $locationStylesheet = $this->yellow->config->get("serverBase") . $this->yellow->config->get("pluginLocation") . "highlight.css";
             $fileNameStylesheet = $this->yellow->config->get("pluginDir") . "highlight.css";
             if (is_file($fileNameStylesheet)) {
                 $output = "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"{$locationStylesheet}\" />\n";
             }
         } else {
             $geshi = new GeSHi();
             $geshi->set_language_path($this->yellow->config->get("pluginDir") . "/highlight/");
             foreach ($geshi->get_supported_languages() as $language) {
                 if ($language == "geshi") {
                     continue;
                 }
                 $geshi->set_language($language);
                 $output .= $geshi->get_stylesheet(false);
             }
             $output = "<style type=\"text/css\">\n{$output}</style>";
         }
     }
     return $output;
 }
开发者ID:nogginfuel,项目名称:yellow-extensions,代码行数:25,代码来源:highlight.php

示例2: setLanguage

 /**
  * Язык для подсветки
  *
  * @return Code
  */
 protected function setLanguage()
 {
     switch ($this->getTagName()) {
         case 'code':
             $language = $this->attributes['code'];
             break;
         case 'pre':
             $language = $this->attributes['pre'];
             break;
         default:
             $language = $this->getTagName();
             break;
     }
     if (!$language) {
         $language = 'text';
     }
     if (isset($this->langSynonym[$language])) {
         $language = $this->langSynonym[$language];
     }
     $this->geshi->set_language($language);
     return $this;
 }
开发者ID:thunder-spb,项目名称:xBBCode,代码行数:27,代码来源:Code.php

示例3: getPostedValue

$selectedValue = getPostedValue('selectedValue');
// Create a GeSHi instance.
$geshi = new GeSHi();
// Build a list of all the language php files located in the language
// directory
$languages = array();
if ($handle = opendir($geshi->language_path)) {
    while (($file = readdir($handle)) !== false) {
        $pos = strpos($file, '.');
        if ($pos > 0 && substr($file, $pos) == '.php') {
            $languages[] = substr($file, 0, $pos);
        }
    }
    closedir($handle);
}
// Sort the languages alphabetically
sort($languages);
// Output the start of the select block
echo '<select name="codeType" id="codeType">' . "\n";
// Output an option for each language and set the selected
// attribute if we were provided with a selectedValue
foreach ($languages as $lang) {
    $geshi->set_language($lang);
    $selected = ' ';
    if ($selectedValue == $lang) {
        $selected = ' selected="selected"';
    }
    echo '<option value="' . $lang . '"' . $selected . '>' . $geshi->get_language_name() . '</option>' . "\n";
}
// Output the end of the select block
echo '</select>' . "\n";
开发者ID:shaunfreeman,项目名称:Uthando-CMS,代码行数:31,代码来源:rj_get_lang_select.php

示例4: jx_show_file

/**
 * Allows to view sourcecode (formatted by GeSHi or unformatted) and images
 *
 */
function jx_show_file($dir, $item)
{
    // show file contents
    show_header($GLOBALS["messages"]["actview"] . ": " . $item);
    $index2_edit_link = str_replace('/index3.php', '/index2.php', make_link('edit', $dir, $item));
    echo '<a name="top" class="componentheading" href="javascript:window.close();">[ ' . _PROMPT_CLOSE . ' ]</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    $abs_item = get_abs_item($dir, $item);
    if (get_is_editable($abs_item) && $GLOBALS['jx_File']->is_writable($abs_item)) {
        // Edit the file in the PopUp
        echo '<a class="componentheading" href="' . make_link('edit', $dir, $item) . '&amp;return_to=' . urlencode($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']) . '">[ ' . $GLOBALS["messages"]["editlink"] . ' ]</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
        // Edit the file in the parent window
        //echo '<a class="componentheading" href="javascript:opener.location=\''.$index2_edit_link.'\'; window.close();">[ '.$GLOBALS["messages"]["editlink"].' ]</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    }
    echo '<a class="componentheading" href="#bottom">[ ' . _CMN_BOTTOM . ' ]</a>';
    echo '<br /><br />';
    if (@eregi($GLOBALS["images_ext"], $item)) {
        echo '<img src="' . $GLOBALS['home_url'] . '/' . $dir . '/' . $item . '" alt="' . $GLOBALS["messages"]["actview"] . ": " . $item . '" /><br /><br />';
    } else {
        if (file_exists($GLOBALS['mosConfig_absolute_path'] . '/includes/domit/xml_saxy_shared.php')) {
            require_once $GLOBALS['mosConfig_absolute_path'] . '/includes/domit/xml_saxy_shared.php';
        } elseif (file_exists($GLOBALS['mosConfig_absolute_path'] . '/libraries/domit/xml_saxy_shared.php')) {
            require_once $GLOBALS['mosConfig_absolute_path'] . '/libraries/domit/xml_saxy_shared.php';
        } else {
            return;
        }
        if (file_exists($GLOBALS['mosConfig_absolute_path'] . '/mambots/content/geshi/geshi.php')) {
            $geshiFile = $GLOBALS['mosConfig_absolute_path'] . '/mambots/content/geshi/geshi.php';
        } elseif (file_exists($GLOBALS['mosConfig_absolute_path'] . '/libraries/geshi/geshi.php')) {
            $geshiFile = $GLOBALS['mosConfig_absolute_path'] . '/libraries/geshi/geshi.php';
        }
        if (file_exists($geshiFile)) {
            @ini_set('memory_limit', '32M');
            // GeSHi 1.0.7 is very memory-intensive
            include_once $geshiFile;
            // Create the GeSHi object that renders our source beautiful
            $geshi = new GeSHi('', '', dirname($geshiFile) . '/geshi');
            $file = get_abs_item($dir, $item);
            $pathinfo = pathinfo($file);
            if (jx_isFTPMode()) {
                $file = jx_ftp_make_local_copy($file);
            }
            if (is_callable(array($geshi, 'load_from_file'))) {
                $geshi->load_from_file($file);
            } else {
                $geshi->set_source(file_get_contents($file));
            }
            if (is_callable(array($geshi, 'getlanguagesuage_name_from_extension'))) {
                $lang = $geshi->getlanguage_name_from_extension($pathinfo['extension']);
            } else {
                $pathinfo = pathinfo($item);
                $lang = $pathinfo['extension'];
            }
            $geshi->set_language($lang);
            $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
            $text = $geshi->parse_code();
            if (jx_isFTPMode()) {
                unlink($file);
            }
            echo '<div style="text-align:left;">' . $text . '</div>';
            echo '<div style="line-height:25px;vertical-align:middle;text-align:center;" class="small">Rendering Time: <strong>' . $geshi->get_time() . ' Sec.</strong></div>';
        } else {
            // When GeSHi is not available, just display the plain file contents
            echo '<div class="quote" style="text-align:left;">' . nl2br(htmlentities($GLOBALS['jx_File']->file_get_contents(get_abs_item($dir, $item)))) . '</div>';
        }
    }
    echo '<a href="#top" name="bottom" class="componentheading">[ ' . _CMN_TOP . ' ]</a><br /><br />';
}
开发者ID:RangerWalt,项目名称:ecci,代码行数:71,代码来源:fun_view.php

示例5: execAction

    function execAction($dir, $item)
    {
        // show file contents
        global $action;
        if (@eregi($GLOBALS["images_ext"], $item)) {
            $html = '<img src="' . make_link('get_image', $dir, rawurlencode($item)) . '" alt="' . $GLOBALS["messages"]["actview"] . ": " . $item . '" /><br /><br />';
        } elseif (@eregi($GLOBALS["editable_ext"], $item)) {
            $geshiFile = _EXT_PATH . '/libraries/geshi/geshi.php';
            ext_RaiseMemoryLimit('32M');
            // GeSHi 1.0.7 is very memory-intensive
            include_once $geshiFile;
            // Create the GeSHi object that renders our source beautiful
            $geshi = new GeSHi('', '', dirname($geshiFile) . '/geshi');
            $file = get_abs_item($dir, $item);
            $pathinfo = pathinfo($file);
            if (ext_isFTPMode()) {
                $file = ext_ftp_make_local_copy($file);
            }
            if (is_callable(array($geshi, 'load_from_file'))) {
                $geshi->load_from_file($file);
            } else {
                $geshi->set_source(file_get_contents($file));
            }
            if (is_callable(array($geshi, 'get_language_name_from_extension'))) {
                $lang = $geshi->get_language_name_from_extension($pathinfo['extension']);
            } else {
                $pathinfo = pathinfo($item);
                $lang = $pathinfo['extension'];
            }
            $geshi->set_language($lang);
            $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
            $langs = $GLOBALS["language"];
            if ($langs == "japanese") {
                $enc_list = array("ASCII", "ISO-2022-JP", "UTF-8", "EUCJP-WIN", "SJIS-WIN");
                $_e0 = strtoupper(mb_detect_encoding($geshi->source, $enc_list, true));
                if ($_e0 == "SJIS-WIN") {
                    $_encoding = "Shift_JIS";
                } elseif ($_e0 == "EUCJP-WIN") {
                    $_e0 = "EUC-JP";
                } elseif ($_e0 == "ASCII") {
                    $_e0 = "UTF-8";
                } else {
                    $_encoding = $_e0;
                }
                $geshi->set_encoding($_encoding);
            }
            $html = $geshi->parse_code();
            if ($langs == "japanese") {
                if (empty($lang) || strtoupper(mb_detect_encoding($html, $enc_list)) != "UTF-8") {
                    $html = mb_convert_encoding($html, "UTF-8", $_e0);
                }
            }
            if (ext_isFTPMode()) {
                unlink($file);
            }
            $html .= '<hr /><div style="line-height:25px;vertical-align:middle;text-align:center;" class="small">Rendering Time: <strong>' . $geshi->get_time() . ' Sec.</strong></div>';
        } else {
            $html = '
			<iframe src="' . make_link('download', $dir, $item, null, null, null, '&action2=view') . '" id="iframe1" width="100%" height="100%" frameborder="0"></iframe>';
        }
        $html = str_replace(array("\r", "\n"), array('\\r', '\\n'), addslashes($html));
        ?>
		{

	"dialogtitle": "<?php 
        echo $GLOBALS['messages']['actview'] . ": " . $item;
        ?>
",
	"height": 500,
	"autoScroll": true,
	"html": "<?php 
        echo $html;
        ?>
"

}
		<?php 
    }
开发者ID:elevenfox,项目名称:VTree,代码行数:78,代码来源:view.php

示例6: strlen

require_once "geshi.php";
// Get path info
$path = SOURCE_ROOT . $_SERVER['PATH_INFO'];
// Check for dickheads trying to use '../' to get to sensitive areas
$base_path_len = strlen(SOURCE_ROOT);
$real_path = realpath($path);
if (strncmp($real_path, SOURCE_ROOT, $base_path_len)) {
    exit("Access outside acceptable path.");
}
// Check file exists
if (!file_exists($path)) {
    exit("File not found ({$path}).");
}
// Prepare GeSHi instance
$geshi = new GeSHi();
$geshi->set_language('text');
$geshi->load_from_file($path);
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->enable_classes();
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 10);
$geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
$geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
$geshi->set_code_style('color: #000020;', 'color: #000020;');
$geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
$geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
$geshi->set_header_content('Source code viewer - ' . $path . ' - ' . $geshi->get_language_name());
$geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
$geshi->set_footer_content('Parsed in <TIME> seconds,  using GeSHi <VERSION>');
$geshi->set_footer_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
开发者ID:LanceSandino,项目名称:Stikked,代码行数:31,代码来源:aliased.php

示例7: LoadData

 /**
  * Loads data for this template
  */
 protected function LoadData()
 {
     $head = $this->GetProject()->GetHeadCommit();
     $this->tpl->assign('head', $head);
     $commit = $this->GetProject()->GetCommit($this->params['hashbase']);
     $this->tpl->assign('commit', $commit);
     if (!isset($this->params['hash']) && isset($this->params['file'])) {
         $this->params['hash'] = $commit->GetTree()->PathToHash($this->params['file']);
         if (empty($this->params['hash'])) {
             throw new GitPHP_FileNotFoundException($this->params['file']);
         }
     }
     $blob = $this->GetProject()->GetObjectManager()->GetBlob($this->params['hash']);
     if ($this->params['file']) {
         $blob->SetPath($this->params['file']);
     }
     $blob->SetCommit($commit);
     $this->tpl->assign('blob', $blob);
     $blame = new GitPHP_FileBlame($this->GetProject(), $commit, $this->params['file'], $this->exe);
     $this->tpl->assign('blame', $blame->GetBlame());
     if (isset($this->params['output']) && $this->params['output'] == 'js') {
         return;
     }
     $this->tpl->assign('tree', $commit->GetTree());
     if ($this->config->GetValue('geshi')) {
         include_once GITPHP_GESHIDIR . "geshi.php";
         if (class_exists('GeSHi')) {
             $geshi = new GeSHi("", 'php');
             if ($geshi) {
                 $lang = GitPHP_Util::GeshiFilenameToLanguage($blob->GetName());
                 if (empty($lang)) {
                     $lang = $geshi->get_language_name_from_extension(substr(strrchr($blob->GetName(), '.'), 1));
                 }
                 if (!empty($lang)) {
                     $geshi->enable_classes();
                     $geshi->enable_strict_mode(GESHI_MAYBE);
                     $geshi->set_source($blob->GetData());
                     $geshi->set_language($lang);
                     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
                     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                     $output = $geshi->parse_code();
                     $bodystart = strpos($output, '<td');
                     $bodyend = strrpos($output, '</tr>');
                     if ($bodystart !== false && $bodyend !== false) {
                         $geshihead = substr($output, 0, $bodystart);
                         $geshifoot = substr($output, $bodyend);
                         $geshibody = substr($output, $bodystart, $bodyend - $bodystart);
                         $this->tpl->assign('geshihead', $geshihead);
                         $this->tpl->assign('geshibody', $geshibody);
                         $this->tpl->assign('geshifoot', $geshifoot);
                         $this->tpl->assign('geshicss', $geshi->get_stylesheet());
                         $this->tpl->assign('geshi', true);
                     }
                 }
             }
         }
     }
 }
开发者ID:hmcclungiii,项目名称:gitphp,代码行数:61,代码来源:Controller_Blame.class.php

示例8: LoadData

 /**
  * Loads data for this template
  */
 protected function LoadData()
 {
     $commit = $this->GetProject()->GetCommit($this->params['hashbase']);
     $this->tpl->assign('commit', $commit);
     $tree = $commit->GetTree();
     $this->tpl->assign('tree', $commit->GetTree());
     if (!isset($this->params['hash']) && isset($this->params['file'])) {
         $this->params['hash'] = $tree->PathToHash($this->params['file']);
         if (empty($this->params['hash'])) {
             throw new GitPHP_FileNotFoundException($this->params['file']);
         }
     }
     $blob = $this->GetProject()->GetObjectManager()->GetBlob($this->params['hash']);
     if (!empty($this->params['file'])) {
         $blob->SetPath($this->params['file']);
     }
     $blob->SetCommit($commit);
     $this->tpl->assign('blob', $blob);
     if ($this->Plain()) {
         return;
     }
     $head = $this->GetProject()->GetHeadCommit();
     $this->tpl->assign('head', $head);
     if ($this->config->GetValue('filemimetype')) {
         $mimeReader = new GitPHP_FileMimeTypeReader($blob, $this->GetMimeStrategy());
         $mimetype = $mimeReader->GetMimeType(true);
         if ($mimetype == 'image') {
             $this->tpl->assign('datatag', true);
             $this->tpl->assign('mime', $mimeReader->GetMimeType());
             $this->tpl->assign('data', base64_encode($blob->GetData()));
             return;
         }
     }
     if ($this->config->GetValue('geshi')) {
         include_once GITPHP_GESHIDIR . "geshi.php";
         if (class_exists('GeSHi')) {
             $geshi = new GeSHi("", 'php');
             if ($geshi) {
                 $lang = GitPHP_Util::GeshiFilenameToLanguage($blob->GetName());
                 if (empty($lang)) {
                     $lang = $geshi->get_language_name_from_extension(substr(strrchr($blob->GetName(), '.'), 1));
                 }
                 if (!empty($lang)) {
                     $geshi->enable_classes();
                     $geshi->enable_strict_mode(GESHI_MAYBE);
                     $geshi->set_source($blob->GetData());
                     $geshi->set_language($lang);
                     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
                     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                     $geshi->set_overall_id('blobData');
                     $this->tpl->assign('geshiout', $geshi->parse_code());
                     $this->tpl->assign('geshicss', $geshi->get_stylesheet());
                     $this->tpl->assign('geshi', true);
                     return;
                 }
             }
         }
     }
     $this->tpl->assign('bloblines', $blob->GetData(true));
 }
开发者ID:hmcclungiii,项目名称:gitphp,代码行数:63,代码来源:Controller_Blob.class.php

示例9: git_blob

function git_blob($projectroot, $project, $hash, $file, $hashbase)
{
    global $gitphp_conf, $tpl;
    $cachekey = sha1($project) . "|" . $hashbase . "|" . $hash . "|" . sha1($file);
    $git = new Git($projectroot . $project);
    if (isset($hash)) {
        $hash = $git->revParse($hash);
    }
    if (isset($hashbase)) {
        $hashbase = $git->revParse($hashbase);
    }
    if (!$tpl->is_cached('blob.tpl', $cachekey)) {
        $head = git_read_head($git);
        if (!isset($hashbase)) {
            $hashbase = $head;
        }
        if (!isset($hash) && isset($file)) {
            $hash = git_get_hash_by_path($git, $git->getObject($hashbase), $file, "blob");
        }
        $catout = $git->getObject($hash)->data;
        $tpl->assign("hash", sha1_hex($hash));
        $tpl->assign("hashbase", sha1_hex($hashbase));
        $tpl->assign("head", sha1_hex($head));
        if ($co = git_read_commit($git, $hashbase)) {
            $tpl->assign("fullnav", TRUE);
            $refs = read_info_ref($git);
            $tpl->assign("tree", $co['tree']);
            $tpl->assign("title", $co['title']);
            if (isset($file)) {
                $tpl->assign("file", $file);
            }
            if (isset($refs[$hashbase])) {
                $tpl->assign("hashbaseref", $refs[$hashbase]);
            }
        }
        $paths = git_path_trees($git, $git->getObject($hashbase), $file);
        $tpl->assign("paths", $paths);
        if ($gitphp_conf['filemimetype']) {
            $mime = file_mime($catout, $file);
            if ($mime) {
                $mimetype = strtok($mime, "/");
            }
        }
        if ($mimetype == "image") {
            $tpl->assign("mime", $mime);
            $tpl->assign("data", base64_encode($catout));
        } else {
            $usedgeshi = $gitphp_conf['geshi'];
            if ($usedgeshi) {
                $usedgeshi = FALSE;
                include_once $gitphp_conf['geshiroot'] . "geshi.php";
                if (class_exists("GeSHi")) {
                    $geshi = new GeSHi("", 'php');
                    if ($geshi) {
                        $lang = "";
                        if (isset($file)) {
                            $lang = $geshi->get_language_name_from_extension(substr(strrchr($file, '.'), 1));
                        }
                        if (isset($lang) && strlen($lang) > 0) {
                            $geshi->set_source($catout);
                            $geshi->set_language($lang);
                            $geshi->set_header_type(GESHI_HEADER_DIV);
                            $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
                            $tpl->assign("geshiout", $geshi->parse_code());
                            $usedgeshi = TRUE;
                        }
                    }
                }
            }
            if (!$usedgeshi) {
                $lines = explode("\n", $catout);
                $tpl->assign("lines", $lines);
            }
        }
    }
    $tpl->display('blob.tpl', $cachekey);
}
开发者ID:akumpf,项目名称:gitphp-glip,代码行数:77,代码来源:display.git_blob.php

示例10: getGeSHI

 /**
  * Get a geshi object for this source. This function is for internal use.
  * @return GeSHI! The geshi object associated with the source.
  */
 protected function getGeSHI()
 {
     if (!isset($this->geshi)) {
         // truncante long lines and limit the number of lines
         $text = "";
         $linesTruncated = array();
         $lines = explode("\n", $this->plainSourceCode);
         $nbOfLines = count($lines);
         $n = 0;
         while ($n < $nbOfLines && $n < MAX_NB_OF_LINES) {
             $line = $lines[$n];
             if (strlen($line) > MAX_LINE_LENGTH) {
                 $msg = "line #" . ($n + 1) . " has been truncated to " . MAX_LINE_LENGTH . " characters (out of " . strlen($line) . " characters)\n";
                 $lines[$n] = substr($lines[$n], 0, MAX_LINE_LENGTH) . "... TRUNCATED";
                 trigger_error($msg);
             }
             $text .= $line . "\n";
             $n++;
         }
         if (count($linesTruncated)) {
             $text = "WARNING: Some long lines have been truncated." . "The file might not display correcly\n" . $text;
         }
         $text = implode("\n", $lines);
         if ($nbOfLines > MAX_NB_OF_LINES) {
             $msg = "\nFILE truncated to " . MAX_NB_OF_LINES . " lines (out of " . $nbOfLines . " lines)\n";
             $text .= $msg;
             trigger_error($msg);
         }
         $geshi = new GeSHi();
         $geshi->set_source($text);
         $geshi->set_language($this->geshiLanguage);
         $geshi->set_overall_id($this->sourceId);
         $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
         $geshi->enable_classes();
         $geshi->enable_ids(true);
         $this->geshi = $geshi;
     }
     return $this->geshi;
 }
开发者ID:GitHubTianPeng,项目名称:101worker,代码行数:43,代码来源:megalib_leftover.php

示例11: geshi_format_code

function geshi_format_code($text, $ext)
{
    $str = '';
    $geshi = new GeSHi($text, '');
    $lang = $ext == 'diff' ? $ext : $geshi->get_language_name_from_extension($ext);
    $geshi->set_language($lang);
    if ($geshi->error() == GESHI_ERROR_NO_SUCH_LANG) {
        return null;
    }
    $geshi->set_encoding('UTF-8');
    //$geshi->enable_classes();
    //$geshi->set_overall_class( "source-$lang" );
    //$geshi->enable_keyword_links( false );
    $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
    $geshi->set_header_type(GESHI_HEADER_DIV);
    $str .= $geshi->parse_code($text, 1);
    if ($geshi->error()) {
        $str .= $geshi->error();
    }
    return $str;
}
开发者ID:eclecticdave,项目名称:gitbrowser,代码行数:21,代码来源:GitBrowser.php

示例12: LoadData

 /**
  * LoadData
  *
  * Loads data for this template
  *
  * @access protected
  */
 protected function LoadData()
 {
     $commit = $this->project->GetCommit($this->params['hashbase']);
     $this->tpl->assign('commit', $commit);
     if (!isset($this->params['hash']) && isset($this->params['file'])) {
         $this->params['hash'] = $commit->PathToHash($this->params['file']);
     }
     $blob = $this->project->GetBlob($this->params['hash']);
     if (!empty($this->params['file'])) {
         $blob->SetPath($this->params['file']);
     }
     $blob->SetCommit($commit);
     $this->tpl->assign('blob', $blob);
     if (isset($this->params['plain']) && $this->params['plain']) {
         return;
     }
     $head = $this->project->GetHeadCommit();
     $this->tpl->assign('head', $head);
     $this->tpl->assign('tree', $commit->GetTree());
     if (GitPHP_Config::GetInstance()->GetValue('filemimetype', true)) {
         $mime = $blob->FileMime();
         if ($mime) {
             $mimetype = strtok($mime, '/');
             if ($mimetype == 'image') {
                 $this->tpl->assign('datatag', true);
                 $this->tpl->assign('mime', $mime);
                 $this->tpl->assign('data', base64_encode($blob->GetData()));
                 return;
             }
         }
     }
     if (GitPHP_Config::GetInstance()->GetValue('geshi', true)) {
         include_once GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('geshiroot', 'lib/geshi/')) . "geshi.php";
         if (class_exists('GeSHi')) {
             $geshi = new GeSHi("", 'php');
             if ($geshi) {
                 $lang = $geshi->get_language_name_from_extension(substr(strrchr($blob->GetName(), '.'), 1));
                 if (!empty($lang)) {
                     $geshi->enable_classes();
                     $geshi->enable_strict_mode(GESHI_MAYBE);
                     $geshi->set_source($blob->GetData());
                     $geshi->set_language($lang);
                     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
                     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                     $geshi->set_overall_id('blobData');
                     $this->tpl->assign('geshiout', $geshi->parse_code());
                     $this->tpl->assign('geshicss', $geshi->get_stylesheet());
                     $this->tpl->assign('geshi', true);
                     return;
                 }
             }
         }
     }
     $this->tpl->assign('bloblines', $blob->GetData(true));
 }
开发者ID:sandassha,项目名称:gitstack,代码行数:62,代码来源:Controller_Blob.class.php


注:本文中的GeSHi::set_language方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。