Pelzini

This is the code documentation for the Pelzini project

source of /viewer/controllers/function.php

Shows information about a specific function
  1. <?php
  2. /*
  3. Copyright 2008 Josh Heidenreich
  4.  
  5. This file is part of Pelzini.
  6.  
  7. Pelzini is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. Pelzini is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Pelzini. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20.  
  21. /**
  22.  * Shows information about a specific function
  23.  *
  24.  * @package Viewer
  25.  * @author Josh Heidenreich
  26.  * @since 0.1
  27.  * @see ParserFunction
  28.  * @tag i18n-done
  29.  **/
  30.  
  31. require_once 'functions.php';
  32.  
  33.  
  34. $sql_name = db_quote($_GET['name']);
  35. $q = new SelectQuery();
  36. $q->addFields('functions.id, functions.name, namespaces.name AS namespace, functions.description,
  37. files.name AS filename, functions.deprecated, functions.linenum, functions.classid,
  38. classes.name AS class, interfaces.name AS interface, functions.static, functions.final, functions.sinceid');
  39. $q->setFrom('functions');
  40. $q->addInnerJoin('files ON functions.fileid = files.id');
  41. $q->addLeftJoin('classes ON functions.classid = classes.id');
  42. $q->addLeftJoin('interfaces ON functions.interfaceid = interfaces.id');
  43. $q->addLeftJoin('namespaces ON functions.namespaceid = namespaces.id');
  44. $q->addWhere("functions.name = {$sql_name}");
  45. $q->addProjectWhere();
  46.  
  47. if (isset($_GET['memberof'])) {
  48. $sql_name = db_quote($_GET['memberof']);
  49. $q->addWhere("(classes.name = {$sql_name} OR interfaces.name = {$sql_name})");
  50. }
  51.  
  52. if (isset($_GET['file'])) {
  53. $sql_name = db_quote($_GET['file']);
  54. $q->addWhere("files.name = {$sql_name}");
  55. }
  56.  
  57. $q = $q->buildQuery();
  58. $res = db_query ($q);
  59.  
  60. if (db_num_rows($res) == 0) {
  61. require_once 'head.php';
  62. echo '<h2>', str(STR_ERROR_TITLE), '</h2>';
  63. echo '<p>', str(STR_FUNC_INVALID), '</p>';
  64. require_once 'foot.php';
  65.  
  66. } else if (db_num_rows($res) > 1) {
  67. require_once 'head.php';
  68. echo '<h2>', str(STR_MULTIPLE_TITLE, 'NUM', db_num_rows($res), 'TYPE', strtolower(str(STR_FUNCTIONS))), '</h2>';
  69.  
  70. echo '<div class="list">';
  71. while ($row = db_fetch_assoc($res)) {
  72. $name_parts = array();
  73. $name_parts[] = str(STR_IN_FILE, 'VAL', $row['filename']);
  74.  
  75. $url = 'function?name=' . htmlspecialchars($_GET['name']) . '&file=' . urlencode($row['filename']);
  76.  
  77. if ($row['class']) {
  78. $url .= '&memberof=' . urlencode($row['class']);
  79. $name_parts[] = str(STR_IN_CLASS, 'VAL', $row['class']);
  80. } else if ($row['interface']) {
  81. $url .= '&memberof=' . urlencode($row['interface']);
  82. $name_parts[] = str(STR_IN_INTERFACE, 'VAL', $row['class']);
  83. }
  84.  
  85. echo '<div class="item">';
  86. echo '<p><strong><a href="', htmlspecialchars($url), '">', htmlspecialchars($row['name']), '</a></strong></p>';
  87. echo '<pre>', ucfirst(implode(', ', $name_parts)), '</pre>';
  88. echo '</div>';
  89. }
  90. echo '</div>';
  91.  
  92. require_once 'foot.php';
  93.  
  94. } else {
  95. $function = db_fetch_assoc($res);
  96. }
  97.  
  98. $skin['page_name'] = str(STR_FUNC_BROWSER_TITLE, 'name', $function['name']);
  99. require_once 'head.php';
  100.  
  101. echo '<h2>', str(STR_FUNC_PAGE_TITLE, 'name', $function['name']), '</h2>';
  102.  
  103. echo '<div class="main-description">';
  104. echo process_inline($function['description']);
  105. echo '</div>';
  106.  
  107.  
  108. echo "<ul>";
  109. $line = $function['linenum'];
  110. $start = '';
  111. if ($line > 5) {
  112. $start = '#src-lines-' . ($line - 5);
  113. }
  114. echo '<li>File: <a href="file?name=', urlencode($function['filename']), '">', htmlspecialchars($function['filename']), '</a>, line <a href="file_source?name=', urlencode($function['filename']), "&amp;highlight={$line}{$start}\">{$line}</a></li>";
  115.  
  116. if ($function['namespace'] != null) {
  117. echo '<li>', str(STR_NAMESPACE, 'name', get_namespace_link($function['namespace'])), '</li>';
  118. }
  119.  
  120. if ($function['classid']) {
  121. echo '<li>', str(STR_FUNC_CLASS, 'name', $function['class']);
  122.  
  123. if ($function['static']) echo ', ', str(STR_METHOD_STATIC);
  124. if ($function['final']) echo ', ', str(STR_METHOD_FINAL);
  125.  
  126. echo '</li>';
  127.  
  128. } else if ($function['static']) {
  129. echo '<li>', str(STR_FUNC_STATIC), '</li>';
  130. }
  131.  
  132. if ($function['sinceid']) {
  133. echo '<li>', str(STR_AVAIL_SINCE, 'version', get_since_version($function['sinceid'])), '</li>';
  134. }
  135. echo "</ul>";
  136.  
  137.  
  138. // Usage
  139. echo '<h3>', str(STR_FUNC_USAGE), '</h3>';
  140.  
  141. if ($function['deprecated'] === null) {
  142. show_function_usage ($function['id']);
  143.  
  144. } else if ($function['deprecated'] === '') {
  145. echo '<p><span class="deprecated">', str(STR_FUNC_DEPRECATED), '</span></p>';
  146. show_function_usage ($function['id']);
  147.  
  148. } else {
  149. echo '<p><span class="deprecated">', str(STR_FUNC_DEPRECATED), '</span>';
  150. echo '<br>', process_inline($function['deprecated']), '</p>';
  151. }
  152.  
  153.  
  154. show_examples($function['id'], LINK_TYPE_FUNCTION);
  155. show_authors ($function['id'], LINK_TYPE_FUNCTION);
  156. show_tables ($function['id'], LINK_TYPE_FUNCTION);
  157.  
  158.  
  159. // Show Arguments
  160. $q = "SELECT id, name, type, byref, defaultvalue, description FROM arguments WHERE functionid = {$function['id']} ORDER BY id";
  161. $res = db_query($q);
  162. if (db_num_rows($res) > 0) {
  163. echo '<h3>', str(STR_FUNC_ARGUMENTS), '</h3>';
  164.  
  165. echo "<ol class=\"spaced-list code-list\">";
  166. while ($row = db_fetch_assoc ($res)) {
  167. $row['name'] = htmlspecialchars($row['name']);
  168. $row['type'] = htmlspecialchars($row['type']);
  169.  
  170. echo '<li><span class="type">', get_object_link ($row['type']), "</span> <strong>{$row['name']}</strong>";
  171. if ($row['defaultvalue'] !== null) {
  172. if ($row['defaultvalue'] == '') $row['defaultvalue'] = "''";
  173. $row['defaultvalue'] = htmlspecialchars($row['defaultvalue']);
  174. echo "<span class=\"default\"> = {$row['defaultvalue']}</span>";
  175. }
  176. if ($row['byref']) echo ' <span class="by-ref">(by reference)</span>';
  177. echo '<br>', process_inline ($row['description']);
  178. echo "</li>";
  179. }
  180. echo "</ol>\n";
  181. }
  182.  
  183.  
  184. // Show throws
  185. $q = "SELECT exception, description FROM throws WHERE functionid = {$function['id']} ORDER BY id";
  186. $res = db_query($q);
  187. if (db_num_rows($res) > 0) {
  188. echo '<h3>', str(STR_FUNC_THROWS), '</h3>';
  189.  
  190. echo "<ul class=\"spaced-list code-list\">";
  191. while ($row = db_fetch_assoc ($res)) {
  192. $row['exception'] = htmlspecialchars($row['exception']);
  193.  
  194. echo '<li>', get_object_link($row['exception']);
  195. echo '<br>', process_inline ($row['description']);
  196. echo "</li>";
  197. }
  198. echo "</ul>\n";
  199. }
  200.  
  201.  
  202. // Show return types
  203. $q = "SELECT type, description FROM returns WHERE functionid = {$function['id']} ORDER BY id";
  204. $res = db_query($q);
  205. if (db_num_rows($res) > 0) {
  206. echo '<h3>', str(STR_FUNC_RETURN_VALUE), '</h3>';
  207.  
  208. echo "<ul class=\"spaced-list code-list\">";
  209. while ($row = db_fetch_assoc ($res)) {
  210. $row['type'] = htmlspecialchars($row['type']);
  211.  
  212. echo '<li>', get_object_link($row['type']);
  213. echo '<br>', process_inline ($row['description']);
  214. echo "</li>";
  215. }
  216. echo "</ul>\n";
  217. }
  218.  
  219.  
  220. show_see_also ($function['id'], LINK_TYPE_FUNCTION);
  221. show_tags ($function['id'], LINK_TYPE_FUNCTION);
  222.  
  223.  
  224. require_once 'foot.php';
  225. ?>
  226.