Initial add of defaria.com
[clearscm.git] / defaria.com / php / site-functions.php
1 <?php
2 function menu () {
3   $main_links   = "/web/index.links";
4   $local_links  = "index.links";
5
6   if (is_readable ($local_links)) {
7     $links = @file ($local_links)
8       or die ("Unable to open local links file ($local_links)");
9   } else {
10     $links = @file ($main_links)
11       or die ("Unable to open main links file ($main_links)");
12   } // if
13
14   print "<div id=menu>\n";
15
16   foreach ($links as $link) {
17     $link_desc = explode ("|", chop ($link));
18     print "<a href=\"" . $link_desc[0] . "\">" . $link_desc[1] . "</a><br>\n";
19   } // foreach
20   print "</div>\n";
21 } // menu
22
23 function search_box () {
24   print <<<END
25 <div id="search">
26   <!-- Start: Search my site with Google -->
27   <form method="get" action="https://www.google.com/search" name="search">
28   <div>Search my site
29   <input type="text" name="q" size="15" id="q" maxlength=255 value=""
30     onclick="document.search.q.value='';">
31   <input type="hidden" name="domains" value="defaria.com">
32   <input type="hidden" name="sitesearch" value="defaria.com">
33   </div>
34   </form>
35   <!-- End: Search my site with Google -->
36 </div>
37 <br>
38 END;
39 } // search_box
40
41 function navigation_bar ($validated = "no") {
42   print "<div class=leftbar>\n";
43   search_box ();
44   menu ();
45   print <<<END
46   <script src="/maps/JavaScript/CheckAddress.js" type="text/javascript"></script>
47   <div id="emailsearch">
48   <form "method"=post action="javascript://" name="address" onsubmit="checkaddress(this,'andrew');">
49     <a href="/maps/doc">Can you email me?</a>
50     Type in your email address and hit enter to see.
51     <input type="text" class="searchfield" id="emailsearchfield" name="email"
52      size="18" maxlength="255" value="" onclick="document.address.email.value = '';">
53   </form>
54   </div>
55 </div>
56 END;
57 } // navigation_bar
58
59 function copyright ($start_year = "",
60                     $author     = "Andrew DeFaria",
61                     $email      = "Andrew@DeFaria.com",
62                     $home       = "") {
63   $today        = getdate ();
64   $current_year = $today ["year"];
65
66   $this_file = $_SERVER['PHP_SELF'];
67
68   // Handle user home web pages
69   if (preg_match ("/\/\~/", $this_file)) {
70     $this_file= preg_replace ("/\/\~(\w+)\/(\s*)/", "/home/$1/web$2/", $this_file);
71   } else {
72     $this_file = "/web" . $this_file;
73   } // if
74
75   $mod_time  = date ("F d Y @ g:i a", filemtime ($this_file));
76
77   print <<<END
78 <div class="copyright">
79 Last modified: $mod_time<br>
80 Copyright &copy; 
81 END;
82
83   if ($start_year != "") {
84     print "$start_year-";
85   } // if
86
87 print <<<END
88 $current_year - All rights reserved<br>
89 <a href="$home/"><img src="/Icons/HomeSmall.gif" alt="Home">&nbsp;$author</a> &lt;<a
90 href="mailto:$email">$email</a>&gt;
91 </div>
92 END;
93 } // copyright
94
95 function display_code ($file) {
96   $code = @file ($file) 
97     or die ("Unable to open file ($file)");
98
99   print "<div class=code>\n<table id=listing cellspacing=0 cellpadding=2 border=0>\n";
100
101   $line_number = 1;
102
103   foreach ($code as $line_of_code) {
104     print "<tr>\n  <td align=right id=line-number><a name=line_$line_number></a>" . 
105           $line_number++ . "</td>\n";
106     print "  <td id=code><tt>\n";
107     for ($i = 0; $i < strlen ($line_of_code); $i++) {
108       if ($line_of_code [$i] == " ") {
109         echo "&nbsp;";
110       } else if ($line_of_code [$i] == "\t") {
111         echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
112       } else if ($line_of_code [$i] != "\n") {
113         echo $line_of_code [$i];
114       } // if
115     } // foreach 
116     print "</tt></td>\n</tr>\n";
117   } // foreach
118
119   print "</table>\n</div>";
120 } // display_code
121 ?>