/[drupal]/contributions/modules/api/parser.inc
ViewVC logotype

Diff of /contributions/modules/api/parser.inc

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

revision 1.41.2.29, Thu Oct 15 05:52:59 2009 UTC revision 1.41.2.30, Sun Oct 18 23:07:51 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: parser.inc,v 1.41.2.28 2009/10/08 06:07:46 drumm Exp $  // $Id: parser.inc,v 1.41.2.29 2009/10/15 05:52:59 drumm Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 29  function api_parse_php_manual($location) Line 29  function api_parse_php_manual($location)
29    }    }
30  }  }
31    
32  function api_parse_file($callback, $file_path, $branch_name, $file_name) {  function api_parse_file($callback, $file_path, $branch, $file_name) {
33    $docblock = array(    $docblock = array(
34      'object_name' => $file_name,      'object_name' => $file_name,
35      'branch_name' => $branch_name,      'branch' => $branch,
36      'object_type' => 'file',      'object_type' => 'file',
37      'file_name' => $file_name,      'file_name' => $file_name,
38      'title' => strpos($file_name, '/') ? substr($file_name, strrpos($file_name, '/') + 1) : $file_name,      'title' => strpos($file_name, '/') ? substr($file_name, strrpos($file_name, '/') + 1) : $file_name,
# Line 55  function api_parse_file($callback, $file Line 55  function api_parse_file($callback, $file
55   * documentation.   * documentation.
56   */   */
57  function api_parse_text_file($docblock) {  function api_parse_text_file($docblock) {
58    $docblock['documentation'] = api_format_documentation($docblock['source'], $docblock['branch_name']);    $docblock['documentation'] = api_format_documentation($docblock['source']);
59    $docblock['code'] = api_format_php($docblock['source']);    $docblock['code'] = api_format_php($docblock['source']);
60    
61    api_save_documentation(array($docblock));    api_save_documentation(array($docblock));
# Line 218  function api_parse_function_calls($code) Line 218  function api_parse_function_calls($code)
218  function api_save_documentation($docblocks) {  function api_save_documentation($docblocks) {
219    $old_dids = array();    $old_dids = array();
220    $nested_groups = array();    $nested_groups = array();
221    $result = db_query("SELECT did FROM {api_documentation} WHERE branch_name = '%s' AND file_name = '%s'", $docblocks[0]['branch_name'], $docblocks[0]['file_name']);    $result = db_query("SELECT did FROM {api_documentation} WHERE branch_id = %d AND file_name = '%s'", $docblocks[0]['branch']->branch_id, $docblocks[0]['file_name']);
222    while ($object = db_fetch_object($result)) {    while ($object = db_fetch_object($result)) {
223      $old_dids[] = $object->did;      $old_dids[] = $object->did;
224    }    }
# Line 231  function api_save_documentation($docbloc Line 231  function api_save_documentation($docbloc
231        $docblock['title'] = $mainpage_matches[1];        $docblock['title'] = $mainpage_matches[1];
232        $docblock['content'] = preg_replace('/' . API_RE_TAG_START . 'mainpage.*?\n/', '', $docblock['content']);        $docblock['content'] = preg_replace('/' . API_RE_TAG_START . 'mainpage.*?\n/', '', $docblock['content']);
233        $docblock['object_type'] = 'mainpage';        $docblock['object_type'] = 'mainpage';
234        $docblock['object_name'] = $docblocks[0]['branch_name'];        $docblock['object_name'] = $docblocks[0]['branch']->branch_name;
235      }      }
236      elseif (preg_match('/' . API_RE_TAG_START . 'file/', $docblock['content'])) {      elseif (preg_match('/' . API_RE_TAG_START . 'file/', $docblock['content'])) {
237        $docblocks[0]['content'] = str_replace('@file', '', $docblock['content']);        $docblocks[0]['content'] = str_replace('@file', '', $docblock['content']);
238        $docblocks[0]['documentation'] = api_format_documentation($docblocks[0]['content'], $docblocks[0]['branch_name']);        $docblocks[0]['documentation'] = api_format_documentation($docblocks[0]['content']);
239      }      }
240      elseif (preg_match('/' . API_RE_TAG_START . 'defgroup/', $docblock['content'])) {      elseif (preg_match('/' . API_RE_TAG_START . 'defgroup/', $docblock['content'])) {
241        $group_matches = array();        $group_matches = array();
# Line 264  function api_save_documentation($docbloc Line 264  function api_save_documentation($docbloc
264          $docblock['parameters'] .= "\n\n". $param_match[1][0];          $docblock['parameters'] .= "\n\n". $param_match[1][0];
265          $offset = $param_match[0][1];          $offset = $param_match[0][1];
266        }        }
267        $docblock['parameters'] = api_format_documentation($docblock['parameters'], $docblocks[0]['branch_name']);        $docblock['parameters'] = api_format_documentation($docblock['parameters']);
268    
269        // Find return value definitions.        // Find return value definitions.
270        $return_matches = array();        $return_matches = array();
# Line 274  function api_save_documentation($docbloc Line 274  function api_save_documentation($docbloc
274          $docblock['content'] = str_replace($return_match[0], '', $docblock['content']);          $docblock['content'] = str_replace($return_match[0], '', $docblock['content']);
275          $docblock['return_value'] .= "\n\n". $return_match[1];          $docblock['return_value'] .= "\n\n". $return_match[1];
276        }        }
277        $docblock['return_value'] = api_format_documentation($docblock['return_value'], $docblocks[0]['branch_name']);        $docblock['return_value'] = api_format_documentation($docblock['return_value']);
278    
279        // Determine group membership.        // Determine group membership.
280        $group_matches = array();        $group_matches = array();
# Line 306  function api_save_documentation($docbloc Line 306  function api_save_documentation($docbloc
306          array_pop($nested_groups);          array_pop($nested_groups);
307        }        }
308    
309        $docblock['documentation'] = api_format_documentation($docblock['content'], $docblocks[0]['branch_name']);        $docblock['documentation'] = api_format_documentation($docblock['content']);
310      }      }
311      if (!isset($docblock['summary'])) {      if (!isset($docblock['summary'])) {
312        $docblock['summary'] = api_documentation_summary($docblock['documentation']);        $docblock['summary'] = api_documentation_summary($docblock['documentation']);
# Line 320  function api_save_documentation($docbloc Line 320  function api_save_documentation($docbloc
320          $docblock['code'] = '';          $docblock['code'] = '';
321        }        }
322      }      }
323      $did = db_result(db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_name = '%s' AND object_type = '%s'", $docblock['object_name'], $docblocks[0]['branch_name'], $docblock['object_type'], $docblock['file_name']));      $did = db_result(db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_id = %d AND object_type = '%s'", $docblock['object_name'], $docblocks[0]['branch']->branch_id, $docblock['object_type'], $docblock['file_name']));
324      if ($did > 0) {      if ($did > 0) {
325        db_query("UPDATE {api_documentation} SET title = '%s', file_name = '%s', summary = '%s', documentation = '%s', code = '%s', start_line = %d WHERE did = %d", $docblock['title'], $docblock['file_name'], $docblock['summary'], $docblock['documentation'], $docblock['code'], $docblock['start_line'], $did);        db_query("UPDATE {api_documentation} SET title = '%s', file_name = '%s', summary = '%s', documentation = '%s', code = '%s', start_line = %d WHERE did = %d", $docblock['title'], $docblock['file_name'], $docblock['summary'], $docblock['documentation'], $docblock['code'], $docblock['start_line'], $did);
326      }      }
# Line 333  function api_save_documentation($docbloc Line 333  function api_save_documentation($docbloc
333        }        }
334        node_save($node);        node_save($node);
335        $did = $node->nid;        $did = $node->nid;
336        db_query("INSERT INTO {api_documentation} (did, object_name, branch_name, object_type, title, file_name, summary, documentation, code, start_line) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", $did, $docblock['object_name'], $docblocks[0]['branch_name'], $docblock['object_type'], $docblock['title'], $docblock['file_name'], $docblock['summary'], $docblock['documentation'], $docblock['code'], $docblock['start_line']);        db_query("INSERT INTO {api_documentation} (did, object_name, branch_id, object_type, title, file_name, summary, documentation, code, start_line) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", $did, $docblock['object_name'], $docblocks[0]['branch']->branch_id, $docblock['object_type'], $docblock['title'], $docblock['file_name'], $docblock['summary'], $docblock['documentation'], $docblock['code'], $docblock['start_line']);
337      }      }
338    
339      switch ($docblock['object_type']) {      switch ($docblock['object_type']) {
# Line 342  function api_save_documentation($docbloc Line 342  function api_save_documentation($docbloc
342          db_query("INSERT INTO {api_function} (did, signature, parameters, return_value) VALUES (%d, '%s', '%s', '%s')", $did, $docblock['signature'], $docblock['parameters'], $docblock['return_value']);          db_query("INSERT INTO {api_function} (did, signature, parameters, return_value) VALUES (%d, '%s', '%s', '%s')", $did, $docblock['signature'], $docblock['parameters'], $docblock['return_value']);
343    
344          if (!empty($docblock['code'])) {          if (!empty($docblock['code'])) {
345            db_query("DELETE FROM {api_reference_storage} WHERE branch_name = '%s' AND object_type = 'function' AND from_did = %d", $docblocks[0]['branch_name'], $did);            db_query("DELETE FROM {api_reference_storage} WHERE branch_id = %d AND object_type = 'function' AND from_did = %d", $docblocks[0]['branch']->branch_id, $did);
346            foreach (api_parse_function_calls($docblock['code']) as $function_name) {            foreach (api_parse_function_calls($docblock['code']) as $function_name) {
347              api_reference($docblocks[0]['branch_name'], 'function', $function_name, $did);              api_reference($docblocks[0]['branch'], 'function', $function_name, $did);
348            }            }
349          }          }
350          break;          break;
# Line 356  function api_save_documentation($docbloc Line 356  function api_save_documentation($docbloc
356      }      }
357    
358      if (isset($docblock['groups'])) {      if (isset($docblock['groups'])) {
359        db_query("DELETE FROM {api_reference_storage} WHERE branch_name = '%s' AND object_type = 'group' AND from_did = %d", $docblocks[0]['branch_name'], $did);        db_query("DELETE FROM {api_reference_storage} WHERE branch_id = '%s' AND object_type = 'group' AND from_did = %d", $docblocks[0]['branch']->branch_id, $did);
360        foreach ($docblock['groups'] as $group_name) {        foreach ($docblock['groups'] as $group_name) {
361          api_reference($docblocks[0]['branch_name'], 'group', $group_name, $did);          api_reference($docblocks[0]['branch'], 'group', $group_name, $did);
362        }        }
363      }      }
364    
# Line 380  function api_save_documentation($docbloc Line 380  function api_save_documentation($docbloc
380  /**  /**
381   * Format a documentation block as HTML.   * Format a documentation block as HTML.
382   */   */
383  function api_format_documentation($documentation, $branch_name) {  function api_format_documentation($documentation) {
384    // Don't do processing on empty text (so we don't end up with empty paragraphs).    // Don't do processing on empty text (so we don't end up with empty paragraphs).
385    if (empty($documentation)) {    if (empty($documentation)) {
386      return '';      return '';
# Line 647  function api_format_php($code) { Line 647  function api_format_php($code) {
647   * using a scratch table and save the references to the database table after the   * using a scratch table and save the references to the database table after the
648   * referenced object has been parsed.   * referenced object has been parsed.
649   */   */
650  function api_reference($branch_name, $to_type, $to_name, $from_did) {  function api_reference($branch, $to_type, $to_name, $from_did) {
651    static $is_php_function = array();    static $is_php_function = array();
652    
653    if ($to_type == 'function' && !isset($is_php_function[$to_name])) {    if ($to_type == 'function' && !isset($is_php_function[$to_name])) {
654        //todo
655      $is_php_function[$to_name] = (db_result(db_query("SELECT COUNT(*) FROM {api_documentation} WHERE object_name = '%s' AND branch_name = 'php'", $to_name)) == 1);      $is_php_function[$to_name] = (db_result(db_query("SELECT COUNT(*) FROM {api_documentation} WHERE object_name = '%s' AND branch_name = 'php'", $to_name)) == 1);
656    }    }
657    
658    if ($to_type != 'function' || !$is_php_function[$to_name]) {    if ($to_type != 'function' || !$is_php_function[$to_name]) {
659      db_query("INSERT INTO {api_reference_storage} (object_name, branch_name, object_type, from_did) VALUES ('%s', '%s', '%s', %d)", $to_name, $branch_name, $to_type, $from_did);      db_query("INSERT INTO {api_reference_storage} (object_name, branch_id, object_type, from_did) VALUES ('%s', '%s', '%s', %d)", $to_name, $branch->branch_id, $to_type, $from_did);
660    }    }
661  }  }
662    
# Line 674  function api_schedule_shutdown() { Line 675  function api_schedule_shutdown() {
675   */   */
676  function api_shutdown() {  function api_shutdown() {
677    // Figure out all the dids of the object/branch/types.    // Figure out all the dids of the object/branch/types.
678    db_query('UPDATE {api_reference_storage} r INNER JOIN {api_documentation} d ON r.object_name = d.object_name AND r.branch_name = d.branch_name AND r.object_type = d.object_type SET r.to_did = d.did');    db_query('UPDATE {api_reference_storage} r INNER JOIN {api_documentation} d ON r.object_name = d.object_name AND r.branch_id = d.branch_id AND r.object_type = d.object_type SET r.to_did = d.did');
679    
680    $directory = file_directory_path();    $directory = file_directory_path();
681    if (is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC)) {    if (is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC)) {
# Line 682  function api_shutdown() { Line 683  function api_shutdown() {
683      file_check_directory($path, FILE_CREATE_DIRECTORY);      file_check_directory($path, FILE_CREATE_DIRECTORY);
684      $date = gmdate('U');      $date = gmdate('U');
685      foreach (api_get_branches() as $branch) {      foreach (api_get_branches() as $branch) {
686        $new_json = api_autocomplete($branch->branch_name, FALSE);        $new_json = api_autocomplete($branch, FALSE);
687    
688        $old_file_path = variable_get('api_autocomplete_path_' . $branch->branch_name, FALSE);        $old_file_path = variable_get('api_autocomplete_path_' . $branch->branch_name, FALSE);
689        if ($old_file_path !== FALSE) {        if ($old_file_path !== FALSE) {
# Line 693  function api_shutdown() { Line 694  function api_shutdown() {
694          job_queue_add('file_delete', t('Remove expired API JSON, %path.'), array('%path' => $old_file_path));          job_queue_add('file_delete', t('Remove expired API JSON, %path.'), array('%path' => $old_file_path));
695        }        }
696    
697        $file_name = $path . '/api-' . $branch->branch_name . '-' . $date . '.json';        $file_name = $path . '/api-' . $branch->branch_id . '-' . $date . '.json';
698        file_save_data($new_json, $file_name, FILE_EXISTS_REPLACE);        file_save_data($new_json, $file_name, FILE_EXISTS_REPLACE);
699        variable_set('api_autocomplete_path_' . $branch->branch_name, $file_name);        variable_set('api_autocomplete_path_' . $branch->branch_name, $file_name);
700      }      }
# Line 726  function api_update_branch($branch) { Line 727  function api_update_branch($branch) {
727    
728    // List all documented files for the branch.    // List all documented files for the branch.
729    $files = array();    $files = array();
730    $result = db_query("SELECT f.did, f.modified, d.object_name FROM {api_documentation} d INNER JOIN {api_file} f ON d.did = f.did WHERE d.branch_name = '%s' AND d.object_type = 'file'", $branch->branch_name);    $result = db_query("SELECT f.did, f.modified, d.object_name FROM {api_documentation} d INNER JOIN {api_file} f ON d.did = f.did WHERE d.branch_id = %d AND d.object_type = 'file'", $branch->branch_id);
731    while ($file = db_fetch_object($result)) {    while ($file = db_fetch_object($result)) {
732      $files[$file->object_name] = $file;      $files[$file->object_name] = $file;
733    }    }
# Line 742  function api_update_branch($branch) { Line 743  function api_update_branch($branch) {
743          $parse = TRUE;          $parse = TRUE;
744        }        }
745        if ($parse) {        if ($parse) {
746          job_queue_add('api_parse_file', t('API parse %branch %file'), array($parse_functions[$matches[1]], $path, '%branch' => $branch->branch_name, '%file' => $file_name), drupal_get_path('module', 'api') .'/parser.inc', TRUE);          job_queue_add('api_parse_file', t('API parse %branch %file'), array($parse_functions[$matches[1]], $path, '%branch' => $branch, '%file' => $file_name), drupal_get_path('module', 'api') .'/parser.inc', TRUE);
747        }        }
748      }      }
749    }    }
# Line 750  function api_update_branch($branch) { Line 751  function api_update_branch($branch) {
751    // Remove outdated files.    // Remove outdated files.
752    foreach (array_keys($files) as $file_name) {    foreach (array_keys($files) as $file_name) {
753      watchdog('api', 'Removing %file.', array('%file' => $file_name));      watchdog('api', 'Removing %file.', array('%file' => $file_name));
754      $result = db_query("SELECT ad.did FROM {api_documentation} ad WHERE ad.file_name = '%s' AND ad.branch_name = '%s'", $file_name, $branch->branch_name);      $result = db_query("SELECT ad.did FROM {api_documentation} ad WHERE ad.file_name = '%s' AND ad.branch_id = %d", $file_name, $branch->branch_id);
755      while ($doc = db_fetch_object($result)) {      while ($doc = db_fetch_object($result)) {
756        db_query("DELETE FROM {api_documentation} WHERE did = %d", $doc->did);        db_query("DELETE FROM {api_documentation} WHERE did = %d", $doc->did);
757        db_query("DELETE FROM {api_file} WHERE did = %d", $doc->did);        db_query("DELETE FROM {api_file} WHERE did = %d", $doc->did);

Legend:
Removed from v.1.41.2.29  
changed lines
  Added in v.1.41.2.30

  ViewVC Help
Powered by ViewVC 1.1.2