The best way to learn how to use the WebCore is by example. See the documentation for more information.

The requested URL is always shown first; if a page uses one or more WebCore templates, those are shown afterwards.

Source for: https://www.earthli.com/shared/show_source.php

Uses WebCore template(s):

00 <?php
01   require_once ('webcore/init.php');
02   require_once ($Page->page_template_for ('webcore/pages/show_source.php'));
03 ?>

Source for template: webcore/pages/show_source.php

00 <?php
01
02 /****************************************************************************
03  
04 Copyright (c) 2002-2014 Marco Von Ballmoos
05  
06 This file is part of earthli WebCore.
07  
08 earthli WebCore is free software; you can redistribute it and/or modify
09 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12  
13 earthli WebCore is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17  
18 You should have received a copy of the GNU General Public License
19 along with earthli WebCore; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  
22 For more information about the earthli WebCore, visit:
23  
24 http://www.earthli.com/software/webcore
25  
26 ****************************************************************************/
27  
28   $page_name = read_array_index ($_GET, 'page_name');
29   $file_name = url_to_file_name ($page_name);
30  
31   define ('Start_of_template', 'webcore/pages');
32   define ('End_of_template', '.php');
33  
34   function draw_source ($source_text)
35   {
36     echo "<div class=\"log-box\">$source_text</div>\n";
37   }
38  
39  
40   $Page->title->subject = 'View source';
41   $Page->template_options->title = 'Source';
42   $Page->template_options->icon = '{icons}buttons/source';
43  
44   $Page->location->add_root_link ();
45   $Page->location->append ('View source');
46   $Page->add_style_sheet ($Env->logger_style_sheet);
47   $Page->start_display ();
48 ?>
49 <div class="main-box">
50   <div class="text-flow">
51     <p>The best way to learn how to use the <a href="http://earthli.com/software/webcore/">WebCore</a>
52       is by example. See the <a href="http://earthli.com/software/webcore/documentation.php">documentation</a> for
53       more information.</p>
54     <p>The requested URL is always shown first; if a page uses one or more WebCore templates, those are shown afterwards.</p>
55     <?php
56       if (is_file ($file_name))
57       {
58         $class_name = $Page->final_class_name ('HIGHLIGHTER', 'webcore/util/highlighter.php');
59  
60         /** @var HIGHLIGHTER $highlighter */
61         $highlighter = new $class_name ($Page);
62  
63         $page_text = $highlighter->file_as_html ($file_name);
64         $template_texts = array ();
65  
66         $text_to_search = $page_text;
67         $template_start = strpos ($text_to_search, Start_of_template);
68         while ($template_start !== false)
69         {
70           $template_end = strpos ($text_to_search, End_of_template, $template_start);
71           $template_name = substr ($text_to_search, $template_start, $template_end - $template_start + strlen (End_of_template));
72           $template_file_name = join_paths ($Env->library_path, $template_name);
73  
74           if (@is_file ($template_file_name))
75           {
76             $text_to_search = $highlighter->file_as_html ($template_file_name);
77             $template_texts [$template_name] = $text_to_search;
78           }
79           $template_start = strpos ($text_to_search, Start_of_template, $template_end);
80         }
81  
82         if (safe_sizeof ($template_texts))
83         {
84     ?>
85       <p>Source for: <span class="field"><?php echo $page_name; ?></span></p>
86       <p>Uses WebCore template(s):</p>
87       <ul>
88     <?php
89           $idx = 1;
90           foreach ($template_texts as $tname => $ttext)
91           {
92     ?>
93         <li><a href="#template_source_<?php echo $idx; ?>"><?php echo $tname; ?></a></li>
94     <?php
95             $idx += 1;
96           }
97     ?>
98       </ul>
99     <?php
100           draw_source ($page_text);
101  
102           $idx = 1;
103           foreach ($template_texts as $tname => $ttext)
104           {
105     ?>
106     <a id="template_source_<?php echo $idx; ?>"></a>
107     <p>Source for template: <span class="field"><?php echo $tname; ?></span></p>
108     <?php
109             draw_source ($ttext);
110             $idx += 1;
111           }
112         }
113         else
114         {
115           draw_source ($page_text);
116         }
117       }
118       else
119       {
120         $page_name = htmlentities($page_name);
121         echo "<div class=\"error\">[$page_name] is not a file.</div>";
122       }
123     ?>
124   </div>
125 </div>
126 <?php $Page->finish_display (); ?>
127