~ubuntu-branches/ubuntu/wily/acl2/wily

« back to all changes in this revision

Viewing changes to books/xdoc/fancy/index-seo.php

  • Committer: Package Import Robot
  • Author(s): Camm Maguire
  • Date: 2015-01-16 10:35:45 UTC
  • mfrom: (3.3.26 sid)
  • Revision ID: package-import@ubuntu.com-20150116103545-prehe9thgo79o8w8
Tags: 7.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
   // ><html><body><h1> Sorry, no php enabled, this won't work! </h1></body></html><!--
 
3
   // settings:
 
4
   
 
5
   $top = 'ACL2____TOP'; // top topic
 
6
   $notFound = 'DOCNOTFOUND'; // not found topic
 
7
   $index = 'DOCINDEX'; // index page
 
8
   
 
9
   $basedir=pathinfo($_SERVER["SCRIPT_NAME"],PATHINFO_DIRNAME)."/";
 
10
   $scriptdir=$_SERVER["SCRIPT_NAME"].'/';
 
11
   error_reporting(E_ALL);
 
12
   ini_set('display_errors', 1);
 
13
   
 
14
   class MyDB extends SQLite3
 
15
   {
 
16
      function __construct()
 
17
      {
 
18
         $this->open('xdata-seo.db');
 
19
      }
 
20
   }
 
21
   $db = new MyDB();
 
22
   if(!$db){
 
23
      echo $db->lastErrorMsg();
 
24
      exit();
 
25
   }
 
26
   
 
27
   if(isset($_SERVER["PATH_INFO"]) && (strlen($_SERVER["PATH_INFO"])>1))
 
28
        $key = pathinfo($_SERVER["PATH_INFO"],PATHINFO_BASENAME);
 
29
   else $key = $top;
 
30
   $showIndex=false;
 
31
   if($key=="*") {$showIndex=true;$key=$index;unset($_GET['path']);}
 
32
   
 
33
   $ret = $db->query("SELECT * from xdoc_data where XKEY='".sqlite_escape_string($key)."'");
 
34
   $page = $ret->fetchArray(SQLITE3_ASSOC);
 
35
   
 
36
   if(!$page || $page['XKEY']!=$key){
 
37
     header("HTTP/1.0 404 Not Found");
 
38
     $key  = $notFound;
 
39
     $ret  = $db->query("SELECT * from xdoc_data where XKEY='".$key."'");
 
40
     $page = $ret->fetchArray(SQLITE3_ASSOC);
 
41
   }else 
 
42
   if(!$showIndex){
 
43
     $preferedURL=$scriptdir.$page['XKEY'];
 
44
     header("Content-Location: ".$preferedURL);
 
45
   }
 
46
   
 
47
   if(!$page) { // fallback when not even the 404 page was found
 
48
     header("Location: ".$scriptdir);
 
49
     die();
 
50
   }
 
51
   
 
52
   
 
53
   $lookup = array($page['ID']=>$page);
 
54
   $lookupx = array($page['XKEY']=>$page);
 
55
   if(isset($_GET['path'])) $path_idea = explode('/',$_GET['path']); else $path_idea = array();
 
56
   $path_reversed=array();
 
57
   $cur = $page;
 
58
   $parents = explode(',',substr($cur['PARENTIDS'],1,-1));
 
59
   while (count($parents)) {
 
60
     $candidates = array_intersect($path_idea,$parents);
 
61
     if(count($candidates)){ // found something (hopefully one)
 
62
       $path_idea = array_diff($path_idea,$parents);
 
63
       $nextID = array_pop($candidates);
 
64
     }else{
 
65
       $nextID = $parents[0]; // nothing found, pick first parent
 
66
     }
 
67
     if(isset($lookup[$nextID])){ // loop found! Abort
 
68
       $parents = array();
 
69
     }else{
 
70
       $ret = $db->query("SELECT * from xdoc_data where ID='".sqlite_escape_string($nextID)."'");
 
71
       $cur = $ret->fetchArray(SQLITE3_ASSOC);
 
72
       if($cur){
 
73
         $lookup[$cur['ID']] = $cur;
 
74
         $path_reversed[] = $cur['ID'];
 
75
         $parents = explode(',',substr($cur['PARENTIDS'],1,-1));
 
76
       }else $parents = array();
 
77
     }
 
78
   }; // while (count($parents));
 
79
   $path=$page['ID'];
 
80
   foreach($path_reversed as $itm){
 
81
     $path=$itm.'/'.$path;
 
82
   }
 
83
   
 
84
   function lookup_by_id($id){
 
85
     global $lookup, $lookupx, $db;
 
86
     if(!isset($lookup[$id])){
 
87
       $ret = $db->query("SELECT * from xdoc_data where ID='".sqlite_escape_string($id)."'");
 
88
       $cur = $ret->fetchArray(SQLITE3_ASSOC);
 
89
       $lookup[$cur['ID']] = $cur;
 
90
       $lookupx[$cur['XKEY']] = $cur;
 
91
     }
 
92
     return $lookup[$id];
 
93
   }
 
94
   function lookup_by_xkey($xkey){
 
95
     global $lookup, $lookupx, $db;
 
96
     if(!isset($lookupx[$xkey])){
 
97
       $ret = $db->query("SELECT * from xdoc_data where XKEY='".sqlite_escape_string($xkey)."'");
 
98
       $cur = $ret->fetchArray(SQLITE3_ASSOC);
 
99
       $lookup[$cur['ID']] = $cur;
 
100
       $lookupx[$cur['XKEY']] = $cur;
 
101
     }
 
102
     return $lookupx[$xkey];
 
103
   }
 
104
   
 
105
   function disp($str){
 
106
     global $scriptdir;
 
107
     echo str_replace(
 
108
        array('<see topic="'        ,'</see>','<code>'            ,'</code>')
 
109
       ,array('<a href="'.$scriptdir,'</a>'  ,'<pre class="code">','</pre>')
 
110
       ,$str);
 
111
   }
 
112
?><!DOCTYPE html>
 
113
<html>
 
114
<head>
 
115
<?php
 
116
  if(isset($preferedURL)){ echo '<link rel="canonical" href="http://'.$_SERVER['SERVER_NAME'].$preferedURL.'" />'; }
 
117
?>
 
118
<meta charset="UTF-8">
 
119
<!--
 
120
; Original author: Jared Davis <jared@centtech.com>
 
121
; PHP version by Sebastiaan Joosten
 
122
; Content by various authors
 
123
-->
 
124
<title><?php echo($page['PACKAGE'] .' - '. $page['TITLE']); ?></title>
 
125
<link rel="stylesheet" type="text/css" href="<?= $basedir ?>style.css"/>
 
126
<link rel="shortcut icon" href="<?= $basedir ?>favicon.png"/>
 
127
</head>
 
128
<body>
 
129
 
 
130
<div id="top">
 
131
 
 
132
  <table border="0" id="toolbar">
 
133
    <tr>
 
134
      <th>
 
135
        <a href="<?= $scriptdir ?>ACL2____TOP">
 
136
          <img class="toolbutton" src="<?= $basedir ?>xdoc-home.png"
 
137
               data-powertip="<p>Go to the Top topic.</p>">
 
138
        </a>&nbsp; &nbsp;</th><th>
 
139
        <a href="<?= $scriptdir ?>*">
 
140
          <img class="toolbutton" src="<?= $basedir ?>view_flat.png"
 
141
               data-powertip="<p>View sitemap.</p>"/>
 
142
        </a>
 
143
        <a target="DownloadWindow" href="<?= $basedir ?>download/manual.zip">
 
144
          <img class="rtoolbutton" src="<?= $basedir ?>download.png"
 
145
               data-powertip="<p>Download a zipped copy of this manual (for
 
146
               faster or offline browsing).</p>"/>
 
147
          </a>
 
148
      </th>
 
149
      <td><label style="color:white">
 
150
          Search-engine friendly clone of the <a href="http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/" style="color:white;text-decoration:underline">ACL2 documentation</a>.
 
151
          </label>
 
152
      </td>
 
153
    </tr>
 
154
  </table>
 
155
 
 
156
</div>
 
157
 
 
158
<div id="left">
 
159
  <div id="nav"><UL>
 
160
    <?php
 
161
      $cur = lookup_by_xkey($top);
 
162
      $path_reversed[] = $page['ID'];
 
163
      function show_rec($cur,$newpath){
 
164
        global $path_reversed, $scriptdir;
 
165
        echo '<LI style="list-style-type:';
 
166
        if(strlen($cur['CHILDREN'])) echo 'disc'; else echo 'circle';
 
167
        echo '"><nobr><A HREF="'.$scriptdir.$cur['XKEY'].'?path='.$newpath.'" title="'.htmlentities(strip_tags($cur['SHORTDESC'])).'">'.$cur['TITLE'].'</A></nobr>';
 
168
        if(array_search($cur['ID'],$path_reversed)!==FALSE){
 
169
          $children=explode(',',$cur['CHILDREN']);
 
170
          if(count($children)){
 
171
            echo '<UL>';
 
172
            for($i=1;$i<count($children);$i++){
 
173
              $kid=lookup_by_xkey($children[$i]);
 
174
              show_rec($kid,$newpath.'/'.$kid['ID']);
 
175
            }
 
176
            echo '</UL>';
 
177
          }
 
178
        }
 
179
      }
 
180
      show_rec($cur,$cur['ID']);
 
181
    ?></UL>
 
182
  </div>
 
183
</div>
 
184
 
 
185
<div id="right">
 
186
  <?php
 
187
  $ps=explode(',',substr($page['PARENTIDS'],1,-1));
 
188
  function ispos($x){return strlen($x)&&(-$x<1);}
 
189
  $ps = array_filter($ps,"ispos");
 
190
  if(count($ps)){ ?>
 
191
    <div id="parents">
 
192
    <UL> <?php
 
193
      foreach($ps as $id){
 
194
        $cur=lookup_by_id($id);
 
195
        echo '<li><a id="'.$id.'" href="'.$scriptdir.$cur['XKEY'].'?path='.$path.'"';
 
196
        echo ' title="'.htmlentities(strip_tags($cur['SHORTDESC'])).'">'.$cur['TITLE'].'</a></li>';
 
197
      } ?>
 
198
    </UL></div><?php
 
199
  }
 
200
  
 
201
  ?>
 
202
  <div id="data">
 
203
    <H1><?php echo $page['TITLE']; ?></H1>
 
204
    <P align="center"><?php
 
205
     disp($page['SHORTDESC']);
 
206
    ?></P>
 
207
    <?php
 
208
     disp($page['LONGDESC']);
 
209
     if($showIndex){
 
210
        echo '<UL>';
 
211
        $ret = $db->query("SELECT XKEY,TITLE,SHORTDESC,PACKAGE from xdoc_data ORDER BY TITLE");
 
212
        while($cur=$ret->fetchArray(SQLITE3_ASSOC)){
 
213
          if(strlen($cur['PACKAGE'])){
 
214
            echo '<LI><a href="'.$scriptdir.$cur['XKEY'].'" title="'.htmlentities(strip_tags($cur['SHORTDESC'])).'">';
 
215
            echo $cur['TITLE'];
 
216
            echo '</a></li>';
 
217
          }
 
218
        }
 
219
        echo '</UL>';
 
220
     }else
 
221
     if(strlen($page['CHILDREN'])){
 
222
       ?><H3>Subtopics</H3>
 
223
       <DL>
 
224
       <?php
 
225
        $childs = explode(',',$page['CHILDREN']);
 
226
        for($i=1;$i<count($childs);$i++){
 
227
          $cur = lookup_by_xkey($childs[$i]);
 
228
          echo '<DT><a href="'.$scriptdir.$cur['XKEY'].'?path='.$path.'">';
 
229
          echo $cur['TITLE'];
 
230
          echo '</a></dt><dd>';
 
231
          disp($cur['SHORTDESC']);
 
232
          echo'</dd>';
 
233
        }
 
234
     }
 
235
     
 
236
    $db->close();
 
237
    ?>
 
238
  </div>
 
239
</div>
 
240
</body>
 
241
</html>
 
 
b'\\ No newline at end of file'