/[drupal]/contributions/modules/api/api.module
ViewVC logotype

Diff of /contributions/modules/api/api.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.49 by drumm, Mon May 19 07:09:38 2008 UTC revision 1.50 by drumm, Mon May 19 07:20:48 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: api.module,v 1.48.2.21 2008/01/26 03:34:44 drumm Exp $  // $Id: api.module,v 1.49 2008/05/19 07:09:38 drumm Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 27  define('API_RE_FILENAME', '([a-zA-Z0-9_- Line 27  define('API_RE_FILENAME', '([a-zA-Z0-9_-
27  /**  /**
28   * Implementation of hook_help()   * Implementation of hook_help()
29   */   */
30  function api_help($section) {  function api_help($path, $arg) {
31    switch ($section) {    switch ($path) {
32      case 'admin/help#api':      case 'admin/help#api':
33        $output = t('        $output = t('
34  <p>  <p>
# Line 72  Indexing of PHP functions is also suppor Line 72  Indexing of PHP functions is also suppor
72  <p>  <p>
73  The module indexes code branches during cron runs, so make sure the site has cron functionality set up properly.  The module indexes code branches during cron runs, so make sure the site has cron functionality set up properly.
74  </p>  </p>
75  ', array('!api_site' => l('http://api.drupal.org', 'http://api.drupal.org', array(), NULL, NULL, TRUE), '!api_settings_page' => l(t('API settings page'), 'admin/settings/api')));  ', array('!api_site' => l('http://api.drupal.org', 'http://api.drupal.org', array('absolute' => TRUE)), '!api_settings_page' => l(t('API settings page'), 'admin/settings/api')));
76        return $output;        return $output;
77    }    }
78  }  }
# Line 94  function api_get_branches() { Line 94  function api_get_branches() {
94  /**  /**
95   * Implementation of hook_menu().   * Implementation of hook_menu().
96   */   */
97  function api_menu($may_cache) {  function api_menu() {
98    $items = array();    $items = array();
99    $access = user_access('access API reference');  
100      $access_callback = 'user_access';
101      $access_arguments = array('access API reference');
102    
103    $branches = api_get_branches();    $branches = api_get_branches();
104    $default_branch = variable_get('api_default_branch', 'HEAD');    $default_branch = variable_get('api_default_branch', 'HEAD');
105    
106    if ($may_cache) {    // Part 1: No object, Default branch
107      $items[] = array(    $items['api'] = array(
108        'path' => 'api',      'title' => 'API reference',
109        'title' => t('API reference'),      'access callback' => $access_callback,
110        'access' => $access,      'access arguments' => $access_arguments,
111        'callback' => 'api_page_branch',      'page callback' => 'api_page_branch',
112        'callback arguments' => array($default_branch),      'page arguments' => array($default_branch),
113      );    );
114      $items[] = array(    $items['api/functions'] = array(
115        'path' => 'api/functions',      'title' => 'Functions',
116        'title' => t('Functions'),      'page callback' => 'api_page_listing',
117        'callback' => 'api_page_listing',      'access callback' => $access_callback,
118        'access' => $access,      'access arguments' => $access_arguments,
119        'callback arguments' => array($default_branch, 'function'),      'page arguments' => array($default_branch, 'function'),
120        'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
121      );    );
122      $items[] = array(    $items['api/constants'] = array(
123        'path' => 'api/constants',      'title' => 'Constants',
124        'title' => t('Constants'),      'page callback' => 'api_page_listing',
125        'callback' => 'api_page_listing',      'access callback' => $access_callback,
126        'access' => $access,      'access arguments' => $access_arguments,
127        'callback arguments' => array($default_branch, 'constant'),      'page arguments' => array($default_branch, 'constant'),
128        'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
129      );    );
130      $items[] = array(    $items['api/globals'] = array(
131        'path' => 'api/globals',      'title' => 'Globals',
132        'title' => t('Globals'),      'page callback' => 'api_page_listing',
133        'callback' => 'api_page_listing',      'access callback' => $access_callback,
134        'access' => $access,      'access arguments' => $access_arguments,
135        'callback arguments' => array($default_branch, 'global'),      'page arguments' => array($default_branch, 'constant'),
136        'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
137      );    );
138      $items[] = array(    $items['api/file'] = array(
139        'path' => 'api/file',      'title' => 'Files',
140        'title' => t('Files'),      'page callback' => 'api_page_listing',
141        'callback' => 'api_page_listing',      'access callback' => $access_callback,
142        'access' => $access,      'access arguments' => $access_arguments,
143        'callback arguments' => array($default_branch, 'file'),      'page arguments' => array($default_branch, 'file'),
144        'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
145      );    );
146      $items[] = array(    $items['api/files'] = array(
147        'path' => 'api/files',      'title' => 'Files',
148        'title' => t('Files'),      'page callback' => 'api_page_listing',
149        'callback' => 'api_page_listing',      'access callback' => $access_callback,
150        'access' => $access,      'access arguments' => $access_arguments,
151        'callback arguments' => array($default_branch, 'file'),      'page arguments' => array($default_branch, 'file'),
152        'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
153      );    );
154      $items[] = array(    $items['api/groups'] = array(
155        'path' => 'api/groups',      'title' => 'Topics',
156        'title' => t('Topics'),      'page callback' => 'api_page_listing',
157        'callback' => 'api_page_listing',      'access callback' => $access_callback,
158        'access' => $access,      'access arguments' => $access_arguments,
159        'callback arguments' => array($default_branch, 'group'),      'page arguments' => array($default_branch, 'group'),
160        'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
161      );    );
   
     foreach ($branches as $branch) {  
       $items[] = array(  
         'path' => 'api/'. $branch->branch_name,  
         'title' => $branch->title,  
         'callback' => 'api_page_branch',  
         'access' => $access,  
         'callback arguments' => array($branch->branch_name),  
         'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,  
       );  
       $items[] = array(  
         'path' => 'api/function_dump/'. $branch->branch_name,  
         'title' => t('Functions'),  
         'callback' => 'api_page_function_dump',  
         'access' => $access,  
         'callback arguments' => array($branch->branch_name),  
         'type' => MENU_CALLBACK,  
       );  
       $items[] = array(  
         'path' => 'api/functions/'. $branch->branch_name,  
         'title' => $branch->title,  
         'callback' => 'api_page_listing',  
         'access' => $access,  
         'callback arguments' => array($branch->branch_name, 'function'),  
         'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,  
       );  
       $items[] = array(  
         'path' => 'api/constants/'. $branch->branch_name,  
         'title' => $branch->title,  
         'callback' => 'api_page_listing',  
         'access' => $access,  
         'callback arguments' => array($branch->branch_name, 'constant'),  
         'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,  
       );  
       $items[] = array(  
         'path' => 'api/globals/'. $branch->branch_name,  
         'title' => $branch->title,  
         'callback' => 'api_page_listing',  
         'access' => $access,  
         'callback arguments' => array($branch->branch_name, 'global'),  
         'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,  
       );  
       $items[] = array(  
         'path' => 'api/files/'. $branch->branch_name,  
         'title' => $branch->title,  
         'callback' => 'api_page_listing',  
         'access' => $access,  
         'callback arguments' => array($branch->branch_name, 'file'),  
         'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,  
       );  
       $items[] = array(  
         'path' => 'api/groups/'. $branch->branch_name,  
         'title' => $branch->title,  
         'callback' => 'api_page_listing',  
         'access' => $access,  
         'callback arguments' => array($branch->branch_name, 'group'),  
         'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,  
       );  
     }  
162    
163      $items[] = array(    $items['apis'] = array(
164        'path' => 'apis',      'title' => 'API search',
165        'title' => t('API search'),      'page callback' => 'api_search_listing',
166        'callback' => 'api_search_listing',      'access callback' => $access_callback,
167        'access' => $access,      'access arguments' => $access_arguments,
168        'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
169      );    );
170      $items[] = array('path' => 'api/autocomplete',    $items['api/autocomplete'] = array(
171          'callback' => 'api_autocomplete', 'access' => $access,      'page callback' => 'api_autocomplete',
172          'type' => MENU_CALLBACK);      'access callback' => $access_callback,
173      $items[] = array('path' => 'admin/settings/api',      'access arguments' => $access_arguments,
174        'title' => t('API reference'),      'type' => MENU_CALLBACK,
175        'description' => t('Configure Drupal branches for documentation.'),    );
176        'access' => user_access('administer API reference'),    $items['admin/settings/api'] = array(
177        'callback' => 'api_page_admin');      'title' => 'API reference',
178    }      'description' => 'Configure Drupal branches for documentation.',
179    else {      'access callback' => 'user_access',
180      if (arg(0) == 'api') {      'access arguments' => array('administer API reference'),
181        if (arg(1) == 'function' && is_string(arg(2))) {      'page callback' => 'api_page_admin',
182          $items[] = array(    );
           'path' => 'api/function/'. arg(2),  
           'title' => t('Function'),  
           'callback' => 'api_page_function',  
           'access' => $access,  
           'callback arguments' => array($default_branch, arg(2)),  
           'type' => MENU_CALLBACK,  
         );  
         foreach ($branches as $branch) {  
           if (db_result(db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_name = '%s' AND object_type = 'function'", arg(2), $branch->branch_name))) {  
             $items[] = array(  
               'path' => 'api/function/'. arg(2) .'/'. $branch->branch_name,  
               'title' => $branch->title,  
               'callback' => 'api_page_function',  
               'access' => $access,  
               'callback arguments' => array($branch->branch_name, arg(2)),  
               'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,  
             );  
           }  
         }  
         $version = is_null(arg(3)) ? $default_branch : arg(3);  
         $items[] = array(  
           'path' => 'api/function/'. arg(2) .'/'. $version .'/documentation',  
           'title' => t('View documentation'),  
           'type' => MENU_DEFAULT_LOCAL_TASK,  
           'weight' => -10  
         );  
         $items[] = array(  
           'path' => 'api/function/'. arg(2) .'/'. $version .'/references',  
           'title' => t('List references'),  
           'callback' => 'api_page_function_references',  
           'access' => $access,  
           'callback arguments' => array(arg(3), arg(2)),  
           'type' => MENU_LOCAL_TASK,  
         );  
       }  
183    
184        if (arg(1) == 'constant' && is_string(arg(2))) {    // Function dumps for IDEs and code editors.
185            $items[] = array(    $items['api/function_dump/%api_branch'] = array(
186              'path' => 'api/constant/'. arg(2),      'page callback' => 'api_page_function_dump',
187              'title' => t('Constant'),      'callback arguments' => array(2),
188              'callback' => 'api_page_constant',      'type' => MENU_CALLBACK,
189              'access' => $access,    );
             'callback arguments' => array($default_branch, arg(2)),  
             'type' => MENU_CALLBACK,  
           );  
         foreach ($branches as $branch) {  
           if (db_result(db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_name = '%s' AND object_type = 'constant'", arg(2), $branch->branch_name))) {  
             $items[] = array(  
               'path' => 'api/constant/'. arg(2) .'/'. $branch->branch_name,  
               'title' => $branch->title,  
               'callback' => 'api_page_constant',  
               'access' => $access,  
               'callback arguments' => array($branch->branch_name, arg(2)),  
               'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,  
             );  
           }  
         }  
       }  
190    
191        if (arg(1) == 'global' && is_string(arg(2))) {    // Part 2: Object provided, default branch.
192            $items[] = array(    $items['api/function/%'] = array(
193              'path' => 'api/global/'. arg(2),      'title' => 'Function',
194              'title' => t('Global'),      'page callback' => 'api_page_function',
195              'callback' => 'api_page_global',      'page arguments' => array($default_branch, 2),
196              'access' => $access,      'type' => MENU_CALLBACK,
197              'callback arguments' => array($default_branch, arg(2)),    );
198              'type' => MENU_CALLBACK,    // Note: We can't support Documentation / References for the "default" branch case.
199            );    // If we tried it, we'd suddenly get extra tabs in the branch list.
200          foreach ($branches as $branch) {    $items['api/constant/%'] = array(
201            if (db_result(db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_name = '%s' AND object_type = 'global'", arg(2), $branch->branch_name))) {      'title' => 'Constant',
202              $items[] = array(      'page callback' => 'api_page_constant',
203                'path' => 'api/global/'. arg(2) .'/'. $branch->branch_name,      'page arguments' => array($default_branch, 2),
204                'title' => $branch->title,      'type' => MENU_CALLBACK,
205                'callback' => 'api_page_global',    );
206                'access' => $access,    $items['api/global/%'] = array(
207                'callback arguments' => array($branch->branch_name, arg(2)),      'title' => 'Global',
208                'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,      'page callback' => 'api_page_global',
209              );      'page arguments' => array($default_branch, 2),
210            }      'type' => MENU_CALLBACK,
211          }    );
212        }    $items['api/file/%api_filename'] = array(
213        'title callback' => 'basename',
214        'title arguments' => array(2),
215        'page callback' => 'api_page_file',
216        'page arguments' => array($default_branch, 2),
217        'type' => MENU_CALLBACK,
218      );
219      $items['api/group/%'] = array(
220        'title' => 'Topic',
221        'page callback' => 'api_page_group',
222        'page arguments' => array($default_branch, 2),
223        'type' => MENU_CALLBACK,
224      );
225    
226        if (arg(1) == 'file' && is_string(arg(2))) {    foreach ($branches as $branch) {
227          // The file path to the file makes determining the correct menu path a      // Part 3: No object, specific branch
228          // bit tricky.  We have to break off the beginning section of the path,      $items['api/'. $branch->branch_name] = array(
229          // then test the last part to see if it's a branch name, then build the        'title' => $branch->title,
230          // filename/branch name from there.        'page callback' => 'api_page_branch',
231          $parts = $parts2 = explode('/', substr($_GET['q'], strlen('api/file/')));        'page arguments' => array($branch->branch_name),
232          $last = array_pop($parts2);        'access callback' => $access_callback, // @@@
233          if ($last == 'source' || $last == 'documentation') {        'access arguments' => $access_arguments, // @@@
234            $last = array_pop($parts2);        'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
235          }      );
236          if (in_array($last, array_keys($branches))) {      $items['api/functions/'. $branch->branch_name] = array(
237            $main_file_name = implode('/', $parts2);        'title' => $branch->title,
238            $branch_name = $last;        'page callback' => 'api_page_listing',
239          }        'page arguments' => array($branch->branch_name, 'function'),
240          else {        'access callback' => 'api_tabchk',
241            $main_file_name = implode('/', $parts);        'access arguments' => array('function', NULL, $branch->branch_name),
242            $branch_name = $default_branch;        'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
243          }      );
244        $items['api/constants/'. $branch->branch_name] = array(
245          'title' => $branch->title,
246          'page callback' => 'api_page_listing',
247          'page arguments' => array($branch->branch_name, 'constant'),
248          'access callback' => 'api_tabchk',
249          'access arguments' => array('constant', NULL, $branch->branch_name),
250          'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
251        );
252        $items['api/globals/'. $branch->branch_name] = array(
253          'title' => $branch->title,
254          'page callback' => 'api_page_listing',
255          'page arguments' => array($branch->branch_name, 'global'),
256          'access callback' => 'api_tabchk',
257          'access arguments' => array('global', NULL, $branch->branch_name),
258          'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
259        );
260        $items['api/files/'. $branch->branch_name] = array(
261          'title' => $branch->title,
262          'page callback' => 'api_page_listing',
263          'page arguments' => array($branch->branch_name, 'file'),
264          'access callback' => 'api_tabchk',
265          'access arguments' => array('file', NULL, $branch->branch_name),
266          'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
267        );
268        $items['api/groups/'. $branch->branch_name] = array(
269          'title' => $branch->title,
270          'page callback' => 'api_page_listing',
271          'page arguments' => array($branch->branch_name, 'group'),
272          'access callback' => 'api_tabchk',
273          'access arguments' => array('group', NULL, 2),
274          'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
275        );
276    
277          foreach ($branches as $branch) {      // Part 4: Object provided, specific branch.
278            if ($branch->branch_name == $branch_name) {      $items['api/function/%/'. $branch->branch_name] = array(
279              $items[] = array(        'title' => $branch->title,
280                'path' => 'api/file/'. $main_file_name,        'page callback' => 'api_page_function',
281                'title' => basename($main_file_name),        'page arguments' => array(3, 2),
282                'callback' => 'api_page_file',        'access callback' => 'api_tabchk',
283                'access' => $access,        'access arguments' => array(1, 2, 3),
284                'callback arguments' => array($branch->branch_name, $main_file_name),        'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
285                'type' => MENU_CALLBACK,      );
286              );      // Documentation / References sub-tabs
287            }      $version = ($branch->branch_name == $default_branch) ? '' : $branch->branch_name .'/';
288            // Check if file path has changed in different branches.      $items['api/function/%/'. $version .'documentation'] = array(
289            if ($file_name = db_result(db_query("SELECT file_name FROM {api_documentation} WHERE title = '%s' AND branch_name = '%s' AND object_type = 'file'", basename($main_file_name), $branch->branch_name))) {        'title' => 'View documentation',
290              $items[] = array(        'type' => MENU_DEFAULT_LOCAL_TASK,
291                'path' => 'api/file/'. $file_name .'/'. $branch->branch_name,        'weight' => -10,
292                'title' => $branch->title,      );
293                'callback' => 'api_page_file',      $items['api/function/%/'. $version .'references'] = array(
294                'access' => $access,        'title' => 'List references',
295                'callback arguments' => array($branch->branch_name, $file_name),        'page callback' => 'api_page_function_references',
296                'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,        'page arguments' => array(3, 2),
297              );        'type' => MENU_LOCAL_TASK,
298            }      );
         }  
         $items[] = array(  
           'path' => 'api/file/'. $main_file_name .'/'. $branch_name .'/documentation',  
           'title' => t('View documentation'),  
           'type' => MENU_DEFAULT_LOCAL_TASK,  
           'weight' => -10,  
         );  
         $items[] = array(  
           'path' => 'api/file/'. $main_file_name .'/'. $branch_name .'/source',  
           'title' => t('View source'),  
           'callback' => 'api_page_file_source',  
           'access' => $access,  
           'callback arguments' => array($branch_name, $main_file_name),  
           'type' => MENU_LOCAL_TASK,  
         );  
       }  
299    
300        if (arg(1) == 'group' && is_string(arg(2))) {      $items['api/constant/%/'. $branch->branch_name] = array(
301          $items[] = array(        'title' => $branch->title,
302            'path' => 'api/group/'. arg(2),        'page callback' => 'api_page_constant',
303            'title' => t('Topic'),        'page arguments' => array(3, 2),
304            'callback' => 'api_page_group',        'access callback' => 'api_tabchk',
305            'access' => $access,        'access arguments' => array(1, 2, 3),
306            'callback arguments' => array($default_branch, arg(2)),        'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
307            'type' => MENU_CALLBACK,      );
308          );      $items['api/global/%/'. $branch->branch_name] = array(
309          foreach ($branches as $branch) {        'title' => $branch->title,
310            if (db_result(db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_name = '%s' AND object_type = 'group'", arg(2), $branch->branch_name))) {        'page callback' => 'api_page_global',
311              $items[] = array(        'page arguments' => array(3, 2),
312                'path' => 'api/group/'. arg(2) .'/'. $branch->branch_name,        'access callback' => 'api_tabchk',
313                'title' => $branch->title,        'access arguments' => array(1, 2, 3),
314                'callback' => 'api_page_group',        'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
315                'access' => $access,      );
316                'callback arguments' => array($branch->branch_name, arg(2)),      // Here's where it gets interesting.
317                'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,      $items['api/file/%api_filename/'. $branch->branch_name] = array(
318              );        'title' => $branch->title,
319            }        'page callback' => 'api_page_file',
320          }        'page arguments' => array(3, 2),
321        }        'access callback' => 'api_tabchk',
322          'access arguments' => array(1, 2, 3),
323        if (arg(1) == 'search' && is_string(arg(3))) {        'tab_parent' => 'api/file/%api_filename',
324          $items[] = array(        'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
325            'path' => 'api/search',      );
326            'title' => t('Search'),      // We are actually collapsing the entire filename into a single argument.
327            'callback' => 'api_search_listing',      $items['api/file/%api_filename/'. $branch->branch_name .'/documentation'] = array(
328            'access' => $access,        'title' => 'View documentation',
329            'type' => MENU_CALLBACK,        'type' => MENU_DEFAULT_LOCAL_TASK,
330          );        'tab_parent' => 'api/file/%api_filename/'. $branch->branch_name,
331          foreach ($branches as $branch) {        'weight' => -10,
332            $items[] = array(      );
333              'path' => 'api/search/'. $branch->branch_name .'/'. arg(3),      // The tabs act as expected, even thought there are a variable number of slashes.
334              'title' => $branch->title,      $items['api/file/%api_filename/'. $branch->branch_name .'/source'] = array(
335              'callback' => 'api_search_listing',        'title' => 'View source',
336              'callback arguments' => array($branch->branch_name, arg(3)),        'page callback' => 'api_page_file_source',
337              'access' => $access,        'page arguments' => array(3, 2),
338              //'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,        'type' => MENU_LOCAL_TASK,
339              'type' => MENU_LOCAL_TASK,        'tab_parent' => 'api/file/%api_filename/'. $branch->branch_name,
340            );      );
341          }      $items['api/group/%/'. $branch->branch_name] = array(
342        }        'title' => $branch->title,
343      }        'page callback' => 'api_page_group',
344          'page arguments' => array(3, 2),
345          'access callback' => 'api_tabchk',
346          'access arguments' => array(1, 2, 3),
347          'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
348        );
349        $items['api/search/'. $branch->branch_name .'/%menu_tail'] = array(
350          'title' => $branch->title,
351          'page callback' => 'api_search_listing',
352          'page arguments' => array($branch->branch_name, 3),
353          'access callback' => $access_callback,
354          'access arguments' => $access_arguments,
355          //'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
356          'type' => MENU_LOCAL_TASK,
357        );
358    }    }
   
359    return $items;    return $items;
360  }  }
361    
362  /**  /**
363     * Determine a filename.
364     */
365    function api_filename_to_arg($arg, $map, $index) {
366      $end = count($map) - 1;
367      // Search for a dot going backwards. When we find one, we know we're in the basename section.
368      while(strpos($map[$end], '.') === FALSE && $end > $index) {
369        $end--;
370      }
371      return implode('/', array_slice($map, $index + 3, $end - $index + 1));
372    }
373    
374    /**
375     * Quote unquote "access" control function which is mainly used to hide inapplicable branch tabs.
376     */
377    function api_tabchk($object_type = NULL, $object_name = NULL, $branch_name = NULL) {
378      // If the user isn't allowed in in the FIRST place, quit early.
379      if (!user_access('access API reference')) {
380        return FALSE;
381      }
382    
383      // NULL means we're using the default branch.
384      if ($branch_name == NULL) {
385        $branch_name = variable_get('api_default_branch', 'HEAD');
386      }
387    
388      // Are we talking about a *group* of objects here?
389      if ($object_name == NULL) {
390        // OK, no object name, let's see if there's ANYTHING in this branch of this type...
391        return (db_result(db_query("SELECT COUNT(*) FROM {api_documentation} WHERE object_type = '%s' AND branch_name = '%s'", $object_type, $branch_name)) >= 1);
392      }
393      else {
394        // We have all three, see if this branch carries this object of this type.
395        return (db_result(db_query("SELECT COUNT(*) FROM {api_documentation} WHERE object_type = '%s' AND object_name = '%s' AND branch_name = '%s'", $object_type, $object_name, $branch_name)) >= 1);
396      }
397    }
398    
399    /**
400   * Implementation of hook_perm().   * Implementation of hook_perm().
401   */   */
402  function api_perm() {  function api_perm() {
# Line 474  function api_block($op, $delta = NULL, $ Line 444  function api_block($op, $delta = NULL, $
444            $links = array();            $links = array();
445            $links[] = l($branches[$branch]->title, 'api'. $suffix);            $links[] = l($branches[$branch]->title, 'api'. $suffix);
446            $links[] = l(t('Constants'), 'api/constants'. $suffix);            $links[] = l(t('Constants'), 'api/constants'. $suffix);
447              $links[] = l(t('Globals'), 'api/globals'. $suffix);
448            $links[] = l(t('Files'), 'api/files'. $suffix);            $links[] = l(t('Files'), 'api/files'. $suffix);
449            $links[] = l(t('Functions'), 'api/functions'. $suffix);            $links[] = l(t('Functions'), 'api/functions'. $suffix);
450            $links[] = l(t('Globals'), 'api/globals'. $suffix);            $links[] = l(t('Globals'), 'api/globals'. $suffix);
# Line 528  function api_get_active_branch() { Line 499  function api_get_active_branch() {
499    return variable_get('api_default_branch', 'HEAD');    return variable_get('api_default_branch', 'HEAD');
500  }  }
501    
502  function api_search_form($branch) {  function api_search_form($form_state, $branch) {
503    $form = array();    $form = array();
504    
505    $form['branch_name'] = array(    $form['branch_name'] = array(
# Line 550  function api_search_form($branch) { Line 521  function api_search_form($branch) {
521    return $form;    return $form;
522  }  }
523    
524  function api_search_form_submit($form_id, $form_values) {  function api_search_form_submit($form, &$form_state) {
525    return 'api/search/'. $form_values['branch_name'] .'/'. $form_values['search'];    $form_state['redirect'] = 'api/search/'. $form_state['values']['branch_name'] .'/'. $form_state['values']['search'];
526  }  }
527    
528  /**  /**
# Line 567  function api_search_listing($branch_name Line 538  function api_search_listing($branch_name
538    
539    // Exact match.    // Exact match.
540    $result = db_query("SELECT * FROM {api_documentation} WHERE branch_name = '%s' AND title = '%s'", $branch_name, $search_text);    $result = db_query("SELECT * FROM {api_documentation} WHERE branch_name = '%s' AND title = '%s'", $branch_name, $search_text);
541    $count = db_num_rows($result);    $count = db_affected_rows($result);
542    if ($count != 1) {    if ($count != 1) {
543      // Wildcard search.      // Wildcard search.
544      $result = db_query("SELECT * FROM {api_documentation} WHERE branch_name = '%s' AND title LIKE '%%%s%%'", $branch_name, $search_text);      $result = db_query("SELECT * FROM {api_documentation} WHERE branch_name = '%s' AND title LIKE '%%%s%%'", $branch_name, $search_text);
545      $count = db_num_rows($result);      $count = db_affected_rows($result);
546    }    }
547    
548    switch ($count) {    switch ($count) {
# Line 594  function api_search_listing($branch_name Line 565  function api_search_listing($branch_name
565   */   */
566  function api_autocomplete($branch_name, $search) {  function api_autocomplete($branch_name, $search) {
567    $matches = array();    $matches = array();
568    $result = db_query("SELECT title FROM {api_documentation} WHERE title LIKE '%%%s%%' AND branch_name = '%s' ORDER BY LENGTH(title) LIMIT 20", $search, $branch_name);    $result = db_query("SELECT title FROM {api_documentation} WHERE title LIKE '%%%s%%' AND branch_name = '%s' ORDER BY LENGTH(title)", 0, 20);
569    while ($r = db_fetch_object($result)) {    while ($r = db_fetch_object($result)) {
570      $matches[$r->title] = check_plain($r->title);      $matches[$r->title] = check_plain($r->title);
571    }    }
# Line 868  function api_page_global($branch_name, $ Line 839  function api_page_global($branch_name, $
839   * Menu callback; displays documentation for a file.   * Menu callback; displays documentation for a file.
840   */   */
841  function api_page_file($branch_name, $object_name) {  function api_page_file($branch_name, $object_name) {
842    // @@@ TODO: Figure out why $object_name is being split like this....
843      $object_name = func_get_args();
844      array_shift($object_name);
845      array_pop($object_name);
846      $object_name = implode('/', $object_name);
847    
848    drupal_add_css(drupal_get_path('module', 'api') .'/api.css');    drupal_add_css(drupal_get_path('module', 'api') .'/api.css');
849    
850    $result = db_query("SELECT d.did, d.title, d.documentation, f.version FROM {api_documentation} d INNER JOIN {api_file} f ON d.did = f.did WHERE object_name = '%s' AND branch_name = '%s' AND object_type = 'file'", $object_name, $branch_name);    $result = db_query("SELECT d.did, d.title, d.documentation, f.version FROM {api_documentation} d INNER JOIN {api_file} f ON d.did = f.did WHERE object_name = '%s' AND branch_name = '%s' AND object_type = 'file'", $object_name, $branch_name);
# Line 1038  function api_page_admin() { Line 1015  function api_page_admin() {
1015    
1016  function api_page_admin_form() {  function api_page_admin_form() {
1017    $form = array();    $form = array();
1018      $radios = array();
1019    
1020    $result = db_query('SELECT branch_name, title, directory FROM {api_branch}');    $result = db_query('SELECT branch_name, title, directory FROM {api_branch}');
1021    $form['branches'] = array(    $form['branches'] = array(
# Line 1086  function api_page_admin_form() { Line 1064  function api_page_admin_form() {
1064    );    );
1065    
1066    global $base_url;    global $base_url;
1067      $first_key = '';
1068    if ($radios) {    if ($radios) {
1069      if (!variable_get('api_default_branch', FALSE)) {      if (!variable_get('api_default_branch', FALSE)) {
1070        list($first_key) = array_keys($radios);  
1071          $first_key = array_keys($radios);
1072          list($first_key) = $first_key;
1073        variable_set('api_default_branch', $first_key);        variable_set('api_default_branch', $first_key);
1074      }      }
1075    
# Line 1126  function api_page_admin_form() { Line 1106  function api_page_admin_form() {
1106    return $form;    return $form;
1107  }  }
1108    
1109  function api_page_admin_form_submit($form_id, $form_values) {  function api_page_admin_form_submit($form, &$form_state) {
1110    foreach ($form_values['branches'] as $branch_name => $branch) {    foreach ($form_state['values']['branches'] as $branch_name => $branch) {
1111      if ($branch_name == 'new') {      if ($branch_name == 'new') {
1112        if ($branch['branch_name'] != '') {        if ($branch['branch_name'] != '') {
1113          db_query("INSERT INTO {api_branch} (branch_name, title, directory) VALUES ('%s', '%s', '%s')", $branch['branch_name'], $branch['title'], $branch['directory']);          db_query("INSERT INTO {api_branch} (branch_name, title, directory) VALUES ('%s', '%s', '%s')", $branch['branch_name'], $branch['title'], $branch['directory']);
# Line 1158  function api_page_admin_form_submit($for Line 1138  function api_page_admin_form_submit($for
1138    }    }
1139    
1140    //save the variable for default branch    //save the variable for default branch
1141    if ($form_values['default_branch']) {    if (!empty($form_state['values']['default_branch'])) {
1142      variable_set('api_default_branch', $form_values['default_branch']);      variable_set('api_default_branch', $form_state['values']['default_branch']);
1143    }    }
1144    
1145    // Save the variable for max files per cron.    // Save the variable for max files per cron.
1146    variable_set('api_files_per_cron', $form_values['api_files_per_cron']);    variable_set('api_files_per_cron', $form_state['values']['api_files_per_cron']);
1147    
1148    // We may have menu changes, so clear the menu cache for all users.    // We may have menu changes, so clear the menu cache for all users.
1149    cache_clear_all('*', 'cache_menu', TRUE);    cache_clear_all('*', 'cache_menu', TRUE);
# Line 1190  function api_php_manual_index_form() { Line 1170  function api_php_manual_index_form() {
1170    return $form;    return $form;
1171  }  }
1172    
1173  function api_php_manual_index_form_submit($form_id, $form_values) {  function api_php_manual_index_form_submit($form, &$form_state) {
1174    include_once(drupal_get_path('module', 'api') .'/parser.inc');    include_once(drupal_get_path('module', 'api') .'/parser.inc');
1175    variable_set('api_php_funcsummary', $form_values['api_php_funcsummary']);    variable_set('api_php_funcsummary', $form_state['values']['api_php_funcsummary']);
1176    variable_set('api_php_funcpath', $form_values['api_php_funcpath']);    variable_set('api_php_funcpath', $form_state['values']['api_php_funcpath']);
1177    db_query("DELETE FROM {api_documentation} WHERE branch_name = 'php'");    db_query("DELETE FROM {api_documentation} WHERE branch_name = 'php'");
1178    api_parse_php_manual($form_values['api_php_funcsummary']);    api_parse_php_manual($form_state['values']['api_php_funcsummary']);
1179    drupal_set_message(t('Manual pages scanned.'));    drupal_set_message(t('Manual pages scanned.'));
1180  }  }
1181    
# Line 1210  function api_reindex_form() { Line 1190  function api_reindex_form() {
1190    return $form;    return $form;
1191  }  }
1192    
1193  function api_reindex_form_submit($form_id, $form_values) {  function api_reindex_form_submit($form, &$form_state) {
1194    db_query("UPDATE {api_file} SET modified = 52");    db_query("UPDATE {api_file} SET modified = 52");
1195    drupal_set_message(t('All files have been tagged for reindexing. The index will be rebuilt during the next few runs of !cron.', array('!cron' => l('cron.php', 'admin/logs/status/run-cron'))));    drupal_set_message(t('All files have been tagged for reindexing. The index will be rebuilt during the next few runs of !cron.', array('!cron' => l('cron.php', 'admin/reports/status/run-cron'))));
1196  }  }
1197    
1198  /**  /**
1199   * Implementation of hook_cron().   * Implementation of hook_cron().
1200   */   */
1201  function api_cron() {  function api_cron() {
1202    include_once(drupal_get_path('module', 'api') .'/parser.inc');    require_once(drupal_get_path('module', 'api') .'/parser.inc');
1203    
1204    $files_scanned = 0;    $files_scanned = 0;
1205    $max_files = variable_get('api_files_per_cron', 10);    $max_files = variable_get('api_files_per_cron', 10);
# Line 1253  function api_cron() { Line 1233  function api_cron() {
1233    if ($files_scanned == 0) {    if ($files_scanned == 0) {
1234      $result = db_query("SELECT ad.file_name, ad.branch_name FROM {api_file} af LEFT JOIN {api_documentation} ad ON ad.did = af.did WHERE af.found = 0");      $result = db_query("SELECT ad.file_name, ad.branch_name FROM {api_file} af LEFT JOIN {api_documentation} ad ON ad.did = af.did WHERE af.found = 0");
1235      while ($file = db_fetch_object($result)) {      while ($file = db_fetch_object($result)) {
1236        watchdog('api', t('Removing %file', array('%file' => $file->file_name)));        watchdog('api', 'Removing %file', array('%file' => $file->file_name));
1237        $doc_result = db_query("SELECT ad.did FROM {api_documentation} ad WHERE ad.file_name = '%s' AND ad.branch_name = '%s'", $file->file_name, $file->branch_name);        $doc_result = db_query("SELECT ad.did FROM {api_documentation} ad WHERE ad.file_name = '%s' AND ad.branch_name = '%s'", $file->file_name, $file->branch_name);
1238        while ($doc = db_fetch_object($doc_result)) {        while ($doc = db_fetch_object($doc_result)) {
1239          db_query("DELETE FROM {api_documentation} WHERE did = %d", $doc->did);          db_query("DELETE FROM {api_documentation} WHERE did = %d", $doc->did);

Legend:
Removed from v.1.49  
changed lines
  Added in v.1.50

  ViewVC Help
Powered by ViewVC 1.1.3