Subversion Repositories PHPX

Rev

Rev 14 | Rev 17 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 PointedEar 1
<?php
2
 
3
require_once 'global.inc';
4
 
13 PointedEar 5
define('FEATURES_ENCODING',
6
  mb_detect_encoding(file_get_contents($_SERVER['SCRIPT_FILENAME'])));
7
 
2 PointedEar 8
/**
9
 * A list of language features with URNs definitions
10
 * for reference links.
11
 */
12
class FeatureList
13
{
14
  public $versions = array();
15
 
16
  /**
17
   * Versions of implementations that are considered safe.
18
   * A feature is considered safe if it does not require
19
   * an implementation version above these versions.
20
   *
21
   * @var Array[string=>string]
22
   */
23
  public $safeVersions = array();
24
 
25
  /**
26
   * URNs that can be used for reference links.
27
   *
28
   * @var Array[string=>string]
29
   */
30
  protected $urns = array();
31
 
32
  /**
33
   * The list of language features
34
   *
35
   * @var array[Features]
36
   */
37
  protected $items = array();
38
 
39
  /**
40
   * Determines the number of printed items the table headings should be repeated
41
   *
42
   * @var int
43
   */
44
  protected $headerRepeat = 25;
45
 
46
  /**
47
   * Initializes the FeatureList object
48
   *
49
   * @param array|Object $a
50
   * @return FeatureList
51
   */
52
  public function __construct($a)
53
  {
9 PointedEar 54
    $aVars = get_class_vars(get_class($this));
55
 
2 PointedEar 56
    while ((list($key, $value) = each($aVars)))
57
    {
58
      if (isset($a[$key]))
59
      {
60
        $this->$key = $a[$key];
61
      }
62
    }
63
 
64
    /* Inform items of ourself so that URNs can be used for links */
65
    if (is_array($this->items))
66
    {
67
      foreach ($this->items as &$item)
68
      {
4 PointedEar 69
        $item->setList($this);
2 PointedEar 70
      }
71
    }
72
 
73
    /* resolve URN references that are URNs */
74
    if (is_array($this->urns))
75
    {
76
      foreach ($this->urns as &$urn)
77
      {
78
        if (($url = $this->resolveURN($urn)))
79
        {
80
          $urn = $url;
81
        }
82
      }
83
    }
84
  }
85
 
86
  public function printHeaders()
87
  {
88
    foreach ($this->versions as $ver)
89
    {
90
?>
91
          <th><?php echo $ver; ?></th>
92
<?php
93
    }
94
  }
95
 
96
  /**
97
   * Prints the list of features.
98
   *
99
   * @see Feature::printMe()
100
   */
101
  public function printItems()
102
  {
103
    $counter = 0;
104
    $headerRepeat = $this->headerRepeat;
105
    $repeatHeaders = ($headerRepeat > 1);
106
 
107
    foreach ($this->items as $feature)
108
    {
109
      if ($feature instanceof Feature)
110
      {
16 PointedEar 111
        /*
112
         * TODO: Disabled header repetition until footnote ref. name/ID
113
         * problem has been solved
114
         */
115
//        if ($repeatHeaders
116
//            && $counter > 1
117
//            && $counter % $headerRepeat === 0)
118
//        {
119
//          echo <<<HTML
120
//        <tr class="header">
121
//          <th>Feature</th>
122
//          {$this->printHeaders()}
123
//        </tr>
124
//HTML;
125
//        }
2 PointedEar 126
 
127
        $feature->printMe();
128
 
129
        $counter++;
130
      }
131
    }
132
  }
133
 
134
  /**
135
   * Resolves a URN according to the value of the
136
   * object's <code>$urn</code> property.
137
   *
138
   * @param string $urn
139
   *   URN to be resolved
140
   * @return string|boolean
141
   *   The resolved URN if successful,
142
   *   <code>false</code> otherwise.
143
   */
144
  public function resolveURN($urn)
145
  {
146
    if (is_array($this->urns))
147
    {
148
      $reURN = '|^(.+?):(?!//)|';
149
 
150
      if (preg_match($reURN, $urn, $m) && isset($this->urns[$m[1]]))
151
      {
152
        return preg_replace($reURN, $this->urns[$m[1]], $urn);
153
      }
154
    }
155
 
156
    return $urn;
157
  }
158
}
159
 
160
/**
161
 * A language feature.
162
 */
163
class Feature
164
{
165
  /**
166
   * Fragment identifiers to be defined for quickly accessing
167
   * the feature description.
168
   *
169
   * @var Array[String]
170
   */
171
  protected $anchors = array();
172
 
173
  /**
174
   * Value of the explanatory <code>title</code> attribute for the feature.
175
   *
176
   * @var string
177
   */
178
  protected $title = '';
179
 
180
  /**
181
   * Name or example code of the feature
182
   *
183
   * @var string
184
   */
185
  protected $content = '';
186
 
187
  /**
188
   * Description of the feature.  Displayed directly if code is missing,
189
   * otherwise used as `title' attribute value.
190
   *
191
   * @var string
192
   */
193
  protected $descr = '';
194
 
195
  /**
196
   * Versions that support this feature
197
   *
198
   * @var Array
199
   */
200
  protected $versions = array();
201
 
202
  /**
203
   * Reference to the FeatureList that this feature belongs to
204
   *
205
   * @var FeatureList
206
   */
207
  protected $list = null;
208
 
4 PointedEar 209
  public function setList(&$oList)
2 PointedEar 210
  {
211
    $this->list =& $oList;
212
  }
213
 
214
  /**
215
   * Creates a new Feature object, using values from the passed parameters
216
   * array.
217
   *
218
   * @param array|Object $params
219
   * @return Feature
220
   */
221
  public function __construct($params = array())
222
  {
14 PointedEar 223
    $aVars = get_class_vars(__CLASS__);
9 PointedEar 224
 
225
    while ((list($key, $value) = each($aVars)))
2 PointedEar 226
    {
9 PointedEar 227
      if (isset($params[$key]))
228
      {
229
        $this->$key = $params[$key];
230
      }
2 PointedEar 231
    }
232
  }
233
 
234
  /**
235
   * Returns <code>' class="safe"'</code> if the feature
236
   * can be considered safe.  The required information
237
   * is stored in the <code>safeVersions</code> property
238
   * of the associated <code>FeatureList</code> object.
239
   *
240
   * @return string
241
   * @see FeatureList::defaultSafeVersions
242
   */
243
  protected function getSafeStr()
244
  {
245
    if (!is_null($this->list))
246
    {
247
      foreach ($this->list->safeVersions as $impl => &$safeVer)
248
      {
249
        $thisImplVer =& $this->versions[$impl];
250
        if (is_array($thisImplVer))
251
        {
252
          if (isset($thisImplVer['tested']) && !is_bool($thisImplVer['tested']))
253
          {
254
            $thisImplVer =& $thisImplVer['tested'];
255
          }
256
          else
257
        {
258
            $thisImplVer =& $thisImplVer[0];
259
          }
260
        }
261
 
262
        /* DEBUG */
263
        // echo " $impl=$thisImplVer ";
264
 
3 PointedEar 265
        if (preg_match('/^-?$/', $thisImplVer) || $thisImplVer > $safeVer)
2 PointedEar 266
        {
267
          return '';
268
        }
269
      }
270
 
271
      return ' class="safe"';
272
    }
273
    else
274
    {
275
      return '';
276
    }
277
  }
278
 
279
  protected function getTitleStr()
280
  {
281
    if (!empty($this->title))
282
    {
283
      return " title=\"{$this->title}\"";
284
    }
285
    else
286
    {
287
      return '';
288
    }
289
  }
290
 
291
  protected function getAnchors()
292
  {
293
    $result = array();
294
 
295
    foreach ($this->anchors as $anchor)
296
    {
297
      $result[] = "<a name=\"{$anchor}\"";
298
 
299
      if (preg_match('/^[a-z][a-z0-9_:.-]*/i', $anchor))
300
      {
301
        $result[] = " id=\"{$anchor}\"";
302
      }
303
 
304
      $result[] = '></a>';
305
    }
306
 
307
    return join('', $result);
308
  }
309
 
310
  protected function getAssumed($v)
311
  {
312
    if (is_array($v) && isset($v['assumed']) && $v['assumed'])
313
    {
314
      return ' class="assumed"';
315
    }
316
 
317
    return '';
318
  }
319
 
320
  protected function getTested($v)
321
  {
322
    if (is_array($v) && isset($v['tested']) && $v['tested'])
323
    {
324
      return ' class="tested"';
325
    }
326
 
327
    return '';
328
  }
329
 
330
  /**
331
   * Returns the version of a feature.
332
   *
333
   * @param string|VersionInfo $vInfo
334
   * @return mixed
335
   */
336
  protected function getVer($vInfo)
337
  {
338
    if (is_array($vInfo))
339
    {
340
      /* TODO: Return all versions: documented, assumed, and tested */
341
      $vNumber = (isset($vInfo['tested'])
342
                  && gettype($vInfo['tested']) !== 'boolean')
343
                     ? $vInfo['tested']
344
                     : $vInfo[0];
345
      $section = isset($vInfo['section'])
346
                   ? ' <span class="section" title="Specification section">['
347
                      . $vInfo['section'] . ']</span>'
348
                   : '';
349
 
350
      if (isset($vInfo['urn']))
351
      {
352
        if ($this->list instanceof FeatureList)
353
        {
354
          $url = $this->list->resolveURN($vInfo['urn']);
355
          $vNumber = '<a href="' . $url . '">' . $vNumber
6 PointedEar 356
            . ($section ? $section : '') . '</a>';
2 PointedEar 357
        }
358
      }
359
      else if ($section)
360
      {
361
        $vNumber .= $section;
362
      }
363
 
6 PointedEar 364
      $vInfo = $vNumber;
2 PointedEar 365
    }
6 PointedEar 366
 
367
    return ($vInfo === '-')
368
      ? '<span title="Not supported">&#8722;</span>'
369
      : $vInfo;
2 PointedEar 370
  }
371
 
372
  protected static function shl($s)
373
  {
374
    /* stub */
375
  }
376
 
377
  public function printMe()
378
  {
379
    ?>
380
<tr<?php echo $this->getSafeStr(); ?>>
381
          <th<?php echo $this->getTitleStr(); ?>><?php
382
            echo $this->getAnchors();
383
            echo /*preg_replace_callback(
384
              '#(<code>)(.+?)(</code>)#',
385
              array('self', 'shl'),*/
386
              preg_replace('/&hellip;/', '&#8230;', $this->content)/*)*/;
387
            ?></th>
388
<?php
389
    $versions = $this->versions;
390
    if (!is_null($this->list))
391
    {
392
      $versions =& $this->list->versions;
393
    }
394
 
395
    static $row = 0;
396
    $row++;
397
 
398
    $column = 0;
399
 
400
    foreach ($versions as $key => $value)
401
    {
402
      $column++;
403
      $id = "td$row-$column";
404
      $ver = $this->versions[$key];
405
?>
406
          <td id="<?php echo $id; ?>"<?php
407
            echo $this->getAssumed($ver) . $this->getTested($ver);
408
            if (!$key)
409
            {
410
              if (!empty($ver))
411
              {
13 PointedEar 412
                echo ' title="Test code: '
413
                  . htmlspecialchars(
414
                      stripslashes($ver),
415
                      ENT_COMPAT,
416
                      FEATURES_ENCODING)
417
                  . '"';
2 PointedEar 418
              }
419
              else
420
              {
421
                echo ' title="Not applicable: No automated test case'
422
                  . ' is available for this feature.  Please click'
423
                  . ' the feature code in the first column to run'
424
                  . ' a manual test."';
425
              }
426
            }
427
            ?>><?php
428
            if ($key)
429
            {
430
              echo $this->getVer($ver);
431
            }
432
            else
433
            {
434
              if (!empty($ver))
435
              {
436
                ?><script type="text/javascript">
437
  // <![CDATA[
5 PointedEar 438
  var s = test(<?php echo $ver; ?>, '<span title="Supported">+</span>',
439
    '<span title="Not supported">&#8722;</span>');
2 PointedEar 440
  tryThis("document.write(s);",
441
          "document.getElementById('<?php echo $id; ?>').appendChild("
442
          + "document.createTextNode(s));");
443
  // ]]>
444
</script><?php
445
              }
446
              else
447
              {
448
                echo '<abbr>N/A</abbr>';
449
              }
450
            }
451
            ?></td>
452
<?php
453
    }
454
?>
455
        </tr>
456
<?php
457
  }
458
}
459
 
460
?>