changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / linking / linkexcerpts.php
1 <?php
2
3 /*
4    Fancyfication of page links with an <a href="..." title="..."> page
5    excerpt. This however slows down rendering a lot (pre-fetching all
6    associated pages is required) - eventually one could write another
7    SQL-only version.
8 */
9
10
11 $ewiki_plugins["handler"][] = "ewiki_handler_fancy_linkexcerpts";
12 $ewiki_plugins["link_final"][] = "ewiki_ahref_fancy_linkexcerpts";
13
14
15 function ewiki_handler_fancy_linkexcerpts($id, &$data, $action) {
16    global $ewiki_fancy_linkexcerpts;
17    if ($action == "view") {
18       $ewiki_fancy_linkexcerpts = array();
19       foreach (explode("\n", trim($data["refs"])) as $link) {
20          $row = ewiki_db::GET($link);
21          if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
22             $text = trim(substr($row["content"], 0, 160));
23             $text = substr($text, 0, strrpos($text, " "));
24             $text = strtr($text, "\t\r\n", "   ");
25             $text = htmlentities($text);
26             $text = wordwrap($text, 40, "&#10;", 0);
27             $ewiki_fancy_linkexcerpts[strtolower($link)] = $text;
28          }
29       }
30
31    }
32 }
33
34
35 function ewiki_ahref_fancy_linkexcerpts(&$str, &$type, &$href, &$title) {
36    global $ewiki_fancy_linkexcerpts; 
37    if ($text = $ewiki_fancy_linkexcerpts[strtolower($href)]) {
38       $str = str_replace('<a ', '<a title="'.$text.'"', $str);
39    }
40 }
41
42
43 ?>