| 81 | | if (arg(0) == 'jsdoc' && arg(3) == 'resource') { |
| 82 | | // jsdoc/namespace/'HEAD'/'resource'/resource |
| 83 | | |
| 84 | | $node = jsdoc_resource_node_load(arg(1), arg(2), str_replace('__', '/', arg(4))); |
| 85 | | $items[] = array('path' => 'jsdoc/'. arg(1) . '/' . arg(2) . '/resource/' . arg(4), |
| 86 | | 'title' => t('View'), |
| 87 | | 'callback' => 'jsdoc_resource_node_view', |
| 88 | | 'callback arguments' => array($node), |
| 89 | | 'access' => node_access('view', $node), |
| 90 | | 'type' => MENU_CALLBACK, |
| 91 | | ); |
| 92 | | $items[] = array('path' => 'jsdoc/'. arg(1) . '/' . arg(2) . '/resource/' . arg(4) . '/view', |
| 93 | | 'title' => t('View'), |
| 94 | | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 95 | | 'weight' => -10 |
| 96 | | ); |
| 97 | | $items[] = array('path' => 'jsdoc/'. arg(1) . '/' . arg(2) . '/resource/' . arg(4) . '/private', |
| 98 | | 'title' => t('View w/ Private'), |
| 99 | | 'callback' => 'jsdoc_resource_node_view', |
| 100 | | 'callback arguments' => array($node), |
| 101 | | 'access' => node_access('view', $node), |
| 102 | | 'weight' => -9, |
| 103 | | 'type' => MENU_LOCAL_TASK |
| 104 | | ); |
| 105 | | $items[] = array('path' => 'jsdoc/'. arg(1) . '/' . arg(2) . '/resource/' . arg(4) . '/edit', |
| 106 | | 'title' => t('Edit'), |
| 107 | | 'callback' => 'jsdoc_resource_edit_redirect', |
| 108 | | 'callback arguments' => array($node), |
| 109 | | 'access' => node_access('update', $node), |
| 110 | | 'weight' => 1, |
| 111 | | 'type' => MENU_LOCAL_TASK |
| 112 | | ); |
| 113 | | } |
| 114 | | |
| 115 | | if (arg(0) == 'jsdoc' && arg(3) == 'object' && arg(4)) { |
| 116 | | // jsdoc/namespace/'HEAD'/'object'/resource/object |
| 117 | | if (arg(5) && arg(5) != 'view' && arg(5) != 'edit' && arg(5) != 'private') { |
| 118 | | $item = arg(4) . '/' . arg(5); |
| 119 | | $object = $node = jsdoc_object_node_load(arg(1), arg(2), arg(5), str_replace('__', '/', arg(4))); |
| 120 | | } |
| 121 | | // jsdoc/namespace/'HEAD'/'object'/object |
| | 88 | if (arg(0) == 'jsdoc') { |
| | 89 | $project = false; |
| | 90 | $version = false; |
| | 91 | $resource = false; |
| | 92 | $name = ''; |
| | 93 | $path = ''; |
| | 94 | if (arg(4)) { |
| | 95 | // If we have 4 arguments, assume that we've been passed a resource |
| | 96 | $project = arg(1); |
| | 97 | $version = arg(2); |
| | 98 | $resource = str_replace('__', '/', arg(3)); |
| | 99 | $name = arg(4); |
| | 100 | $path = "jsdoc/$project/$version/" . arg(3) . "/$name"; |
| | 101 | } |
| | 102 | elseif (arg(3)) { |
| | 103 | // If we have 3 arguments, assume that we don't have a resource |
| | 104 | $project = arg(1); |
| | 105 | $version = arg(2); |
| | 106 | $name = arg(3); |
| | 107 | $path = "jsdoc/$project/$version/$name"; |
| | 108 | } |
| | 109 | elseif (arg(2)) { |
| | 110 | // If we have 2 arguments, assume that we don't have a resource or project |
| | 111 | // So basically, we assume that version is more important than project |
| | 112 | $version = arg(1); |
| | 113 | $name = arg(2); |
| | 114 | $path = "jsdoc/$version/$name"; |
| | 115 | } |
| | 116 | elseif (arg(1)) { |
| | 117 | // Allow the user to only pass the name |
| | 118 | $name = arg(1); |
| | 119 | $path = "jsdoc/$name"; |
| | 120 | } |
| | 121 | |
| | 122 | if ($node = jsdoc_object_node_load($name, $project, $version, $resource)) { |
| | 123 | $item = array( |
| | 124 | 'path' => $path, |
| | 125 | 'title' => t('View'), |
| | 126 | 'access' => node_access('view', $node), |
| | 127 | 'type' => MENU_CALLBACK |
| | 128 | ); |
| | 129 | if (is_array($node)) { |
| | 130 | $item['callback'] = 'jsdoc_variables_node_view'; |
| | 131 | $item['callback arguments'] = array($node); |
| | 132 | } |
| | 133 | else { |
| | 134 | if ($node->type == 'jsdoc_object') { |
| | 135 | $item['callback'] = 'jsdoc_object_node_view'; |
| | 136 | $item['callback arguments'] = array($node); |
| | 137 | } |
| | 138 | else { |
| | 139 | $item['callback'] = 'jsdoc_variable_node_view'; |
| | 140 | $item['callback arguments'] = array($node); |
| | 141 | } |
| | 142 | } |
| | 143 | $items[] = $item; |
| | 144 | } |
| | 145 | } |
| | 146 | |
| | 147 | /* |
| | 148 | if (arg(0) == 'jsdoc' && arg(3)) { |
| | 149 | // jsdoc/namespace/'HEAD'/resource/object |
| | 150 | if (arg(4) && arg(4) != 'view' && arg(4) != 'edit' && arg(4) != 'private') { |
| | 151 | $item = arg(3) . '/' . arg(4); |
| | 152 | $object = $node = jsdoc_object_node_load(arg(4), arg(1), arg(2), str_replace('__', '/', arg(3))); |
| | 153 | } |
| | 154 | // jsdoc/namespace/'HEAD'/object |
| 1448 | | if (is_numeric($node->jsdoc_provide)) { |
| 1449 | | $node->jsdoc_provide = _jsdoc_node_load($node->jsdoc_provide, $node->jsdoc_provide_vid); |
| 1450 | | } |
| 1451 | | return $node->jsdoc_provide; |
| 1452 | | } |
| 1453 | | |
| 1454 | | function jsdoc_load_children(&$node, $with_private=false) { |
| 1455 | | if (isset($node->jsdoc_variables)) return; |
| | 1497 | $object = $node; |
| | 1498 | if ($node->type == 'jsdoc_variable') { |
| | 1499 | $object = jsdoc_get_variable_object($node); |
| | 1500 | } |
| | 1501 | if (is_numeric($object->jsdoc_provide)) { |
| | 1502 | $object->jsdoc_provide = _jsdoc_node_load($object->jsdoc_provide, $object->jsdoc_provide_vid); |
| | 1503 | } |
| | 1504 | return $object->jsdoc_provide; |
| | 1505 | } |
| | 1506 | |
| | 1507 | function jsdoc_get_child_instances(&$node, $with_private=false) { |
| | 1508 | return jsdoc_get_children($node, $with_private)->instances; |
| | 1509 | } |
| | 1510 | |
| | 1511 | function jsdoc_get_child_prototypes(&$node, $with_private=false) { |
| | 1512 | return jsdoc_get_children($node, $with_private)->prototypes; |
| | 1513 | } |
| | 1514 | |
| | 1515 | function jsdoc_get_child_variables(&$node, $with_private=false) { |
| | 1516 | return jsdoc_get_children($node, $with_private)->variables; |
| | 1517 | } |
| | 1518 | |
| | 1519 | function jsdoc_get_child_chains(&$node, $with_private=false) { |
| | 1520 | return jsdoc_get_children($node, $with_private)->chains; |
| | 1521 | } |
| | 1522 | |
| | 1523 | function jsdoc_get_child_mixins(&$node, $with_private=false) { |
| | 1524 | return jsdoc_get_children($node, $with_private)->mixins; |
| | 1525 | } |
| | 1526 | |
| | 1527 | function jsdoc_get_children(&$node, $with_private=false) { |
| | 1528 | if (isset($node->jsdoc_variables)) { |
| | 1529 | return (object)array( |
| | 1530 | 'instances' => $node->jsdoc_instances, |
| | 1531 | 'prototypes' => $node->jsdoc_prototypes, |
| | 1532 | 'variables' => $node->jsdoc_variables, |
| | 1533 | 'chains' => $node->jsdoc_chains, |
| | 1534 | 'mixins' => $node->jsdoc_mixins |
| | 1535 | ); |
| | 1536 | } |
| 1552 | | $node = node_prepare($node, $teaser); |
| 1553 | | |
| 1554 | | $ending = ''; |
| 1555 | | if (strpos($node->title, '.js') !== false) { |
| 1556 | | $separator = '/'; |
| 1557 | | $ending = '.js'; |
| 1558 | | } |
| 1559 | | elseif (strpos($node->title, '/') !== false) { |
| 1560 | | $separator = '/'; |
| 1561 | | } |
| 1562 | | else { |
| 1563 | | $separator = '.'; |
| 1564 | | } |
| 1565 | | $parts = explode($separator, $node->title); |
| 1566 | | $title_text = ""; |
| 1567 | | $end = array_pop($parts); |
| 1568 | | $title = ''; |
| 1569 | | $last_part = ''; |
| 1570 | | foreach ($parts as $part) { |
| 1571 | | if (!empty($title_text)) { |
| 1572 | | $title_text .= $separator; |
| 1573 | | } |
| 1574 | | $title_text .= $part; |
| 1575 | | $obj = jsdoc_resource_node_load(jsdoc_get_project($node)->nid, jsdoc_get_version($node), $title_text . $ending); |
| 1576 | | if (!empty($title)) { |
| 1577 | | $title .= $separator; |
| 1578 | | } |
| 1579 | | if ($obj) { |
| 1580 | | $title .= l($part, $obj->jsdoc_url); |
| 1581 | | } |
| 1582 | | else { |
| 1583 | | $title .= $part; |
| 1584 | | } |
| 1585 | | } |
| 1586 | | if (!empty($title)) { |
| 1587 | | $title .= $separator; |
| 1588 | | } |
| 1589 | | drupal_set_title($title . $end); |
| 1590 | | |
| 1591 | | jsdoc_get_resources($node, array(3, 4)); |
| 1592 | | |
| 1593 | | $resources = array(); |
| 1594 | | $expanded = _jsdoc_resource_expand($node->jsdoc_resources, $node->vid, 0, $resources); |
| 1595 | | |
| 1596 | | $depth = 1; |
| 1597 | | while ($depth < 20) { |
| 1598 | | $found = false; |
| 1599 | | |
| 1600 | | for ($i = 0; $i < count($expanded); $i++) { |
| 1601 | | $leaf = $expanded[$i]; |
| 1602 | | if ($leaf->depth == $depth - 1) { |
| 1603 | | $leaf = _jsdoc_resource_expand($node->jsdoc_resources, $leaf->vid, $depth, $resources); |
| 1604 | | if (!empty($leaf)) { |
| 1605 | | $found = true; |
| 1606 | | array_splice($expanded, $i + 1, 0, $leaf); |
| 1607 | | $i += count($leaf); |
| 1608 | | } |
| 1609 | | } |
| 1610 | | } |
| 1611 | | ++$depth; |
| 1612 | | if (!$found) break; |
| 1613 | | } |
| 1614 | | |
| 1615 | | $resources = ''; |
| 1616 | | foreach ($expanded as $leaf) { |
| 1617 | | if ($leaf->depth == 0) { |
| 1618 | | $resources .= '<span style="color: red;">'; |
| 1619 | | } |
| 1620 | | $resources .= str_pad('', $leaf->depth, '-') . ' ' . $leaf->name . '<br>'; |
| 1621 | | if ($leaf->depth == 0) { |
| 1622 | | $resources .= '</span>'; |
| 1623 | | } |
| 1624 | | } |
| 1625 | | |
| 1626 | | if (count($expanded)) { |
| 1627 | | $node->content['resources'] = array( |
| 1628 | | '#type' => 'fieldset', |
| 1629 | | '#collapsible' => true, |
| 1630 | | '#collapsed' => true, |
| 1631 | | '#title' => t('Uses') . ' ' . count($expanded) . ' ' . t('resources') . '<br>', |
| 1632 | | '#weight' => 5 |
| 1633 | | ); |
| 1634 | | $node->content['resources']['resources'] = array( |
| 1635 | | '#type' => 'item', |
| 1636 | | '#value' => $resources |
| 1637 | | ); |
| 1638 | | } |
| 1639 | | |
| 1640 | | if ($node->teaser) { |
| 1641 | | $node->content['teaser'] = array( |
| 1642 | | '#type' => 'item', |
| 1643 | | '#title' => t('Summary'), |
| 1644 | | '#value' => '<p>' . $node->teaser . '</p>', |
| 1645 | | '#weight' => -24 |
| 1646 | | ); |
| 1647 | | } |
| 1648 | | |
| 1649 | | $children = jsdoc_resource_object_list($node); |
| 1650 | | if (count($children)) { |
| 1651 | | $node->content['jsdoc_children'] = array( |
| 1652 | | '#type' => 'fieldset', |
| 1653 | | '#collapsible' => true, |
| 1654 | | '#collapsed' => true, |
| 1655 | | '#title' => t('Objects in this resource'), |
| 1656 | | '#weight' => 10 |
| 1657 | | ); |
| 1658 | | } |
| 1659 | | uksort($children, "strnatcmp"); |
| 1660 | | |
| 1661 | | $i = 0; |
| 1662 | | $last = ""; |
| 1663 | | foreach ($children as $child) { |
| 1664 | | $child = _jsdoc_node_load($child->nid, $child->vid); |
| 1665 | | if($last && strpos($child->title, $last) === 0 && strpos($child->title, $node->title . '.') === 0){ |
| 1666 | | continue; |
| 1667 | | } |
| 1668 | | $node->content['jsdoc_children']['children'][] = array( |
| 1669 | | '#type' => 'item', |
| 1670 | | '#weight' => $i++, |
| 1671 | | '#value' => $child->jsdoc_formatted['type'] . $child->jsdoc_formatted['separator'] . l($child->title, $child->jsdoc_url, array(), null, null, null, true) |
| 1672 | | ); |
| 1673 | | if (strpos($child->title, $node->title . '.') === 0) { |
| 1674 | | $last = $child->title . '.'; |
| 1675 | | } |
| 1676 | | } |
| 1677 | | |
| 1678 | | if ($node->content['jsdoc_children']) { |
| 1679 | | $node->content['jsdoc_children']['#title'] = ($i == 1) ? t('1 object in this resource') : t($i . ' objects in this resource'); |
| 1680 | | } |
| 1681 | | |
| 1682 | | if (!$node->content['jsdoc_children']['children']) { |
| 1683 | | unset($node->children['jsdoc_children']); |
| 1684 | | } |
| 1685 | | |
| 1686 | | return $node; |
| | 1633 | $node->title = ''; |
| | 1634 | $node->teaser = ''; |
| | 1635 | $node->body = ''; |
| 2436 | | if (is_array($resource) && !empty($resource) && ($node = db_fetch_object(db_query("SELECT n.nid, n.vid FROM {node_revisions} n JOIN {jsdoc_objects} j ON (j.vid = n.vid) WHERE j.used != -1 AND j.new = 0 AND n.title = '%s' AND BINARY n.title = '%s' AND j.provide_vid IN (%s)", $name, $name, implode(',', $resource))))) { |
| 2437 | | return _jsdoc_node_load($node->nid, $node->vid); |
| 2438 | | } |
| 2439 | | elseif ($resource && is_string($resource) && ($resource = db_fetch_object(db_query("SELECT n.nid, n.vid FROM {node_revisions} n JOIN {jsdoc_resources} j ON (j.vid = n.vid) AND n.title = '%s' AND BINARY n.title = '%s' AND j.version = %d", $resource, $resource, $version_nid)))) { |
| 2440 | | if ($node = db_fetch_object(db_query("SELECT n.nid, n.vid FROM {node_revisions} n JOIN {jsdoc_objects} j ON (j.vid = n.vid) WHERE j.used != -1 AND j.new = 0 AND n.title = '%s' AND BINARY n.title = '%s' AND j.resource_vid = %d", $name, $name, $resource->vid))) { |
| 2441 | | $node = _jsdoc_node_load($node->nid, $node->vid); |
| 2442 | | if ($node->jsdoc_used != -1) { |
| | 2387 | // We have a few situations: |
| | 2388 | // name |
| | 2389 | // project, name |
| | 2390 | // project, version, name |
| | 2391 | // project, version, resource, name |
| | 2392 | |
| | 2393 | // If we're missing the version, assume the latest release |
| | 2394 | // If we're missing the project, look up stuff by name |
| | 2395 | |
| | 2396 | if (!$project_nid) { |
| | 2397 | // We can't look up the proper version without knowing the project |
| | 2398 | $query = db_query("SELECT nr.nid, MAX(nr.vid) AS vid FROM {node_revisions} nr JOIN {node} n ON (n.vid = nr.vid) WHERE nr.title = '%s' AND BINARY nr.title = '%s' AND n.type = 'jsdoc_variable' GROUP BY nr.nid", $name, $name); |
| | 2399 | if (db_num_rows($query) == 1) { |
| | 2400 | $result = db_fetch_object($query); |
| | 2401 | $node = _jsdoc_node_load($result->nid, $result->vid); |
| | 2402 | if ($object = jsdoc_get_variable_object($node)) { |
| | 2403 | if (!$version) { |
| | 2404 | // In the future, figure out the latest non-HEAD |
| | 2405 | $version = 'HEAD'; |
| | 2406 | } |
| | 2407 | $version = jsdoc_version_node_load($version, jsdoc_get_project($object)); |
| | 2408 | $versioned_query = db_query("SELECT vid FROM {jsdoc_objects} WHERE nid = %d AND version = %d", $object->nid, $version->nid); |
| | 2409 | if ($result = db_fetch_object($versioned_query)) { |
| | 2410 | return _jsdoc_node_load($object->nid, $result->vid); |
| | 2411 | } |
| | 2412 | else { |
| | 2413 | return $node; |
| | 2414 | } |
| | 2415 | } |
| | 2416 | else { |
| 2446 | | } |
| 2447 | | if ($node = db_fetch_object(db_query("SELECT n.nid, n.vid FROM {node_revisions} n JOIN {jsdoc_variables} j ON (j.vid = n.vid) WHERE n.title = '%s' AND BINARY n.title = '%s' AND j.version = %d", $name, $name, $version_nid))) { |
| 2448 | | return _jsdoc_node_load($node->nid, $node->vid); |
| 2449 | | } |
| 2450 | | } |
| 2451 | | |
| 2452 | | /** |
| 2453 | | * Path: jsdoc/VERSION/object/NAME |
| | 2420 | else { |
| | 2421 | $nodes = array(); |
| | 2422 | while ($result = db_fetch_object($query)) { |
| | 2423 | $nodes[] = _jsdoc_node_load($result->nid, $result->vid); |
| | 2424 | } |
| | 2425 | return $nodes; |
| | 2426 | } |
| | 2427 | } |
| | 2428 | else { |
| | 2429 | if ($resource) { |
| | 2430 | if (is_object($resource)) { |
| | 2431 | $resources = array($resource->nid); |
| | 2432 | } |
| | 2433 | elseif (is_numeric($resource)) { |
| | 2434 | $resources = array($resource); |
| | 2435 | } |
| | 2436 | elseif (is_array($resource)) { |
| | 2437 | $resources = $resource; |
| | 2438 | } |
| | 2439 | else { |
| | 2440 | $resources = array(jsdoc_resource_node_load($project_nid, $version_nid, $resource)->nid); |
| | 2441 | } |
| | 2442 | $query = db_query("SELECT nr.nid, MAX(nr.vid) AS vid FROM {node_revisions} nr INNER JOIN {jsdoc_objects} j ON (j.vid = nr.vid) WHERE nr.title = '%s' AND BINARY nr.title = '%s' AND j.version = %d AND (j.resource_nid IN (%s) OR j.provide_nid IN (%s)) GROUP BY nr.nid", $name, $name, $version_nid, implode(',', $resources), implode(',', $resources)); |
| | 2443 | } |
| | 2444 | else { |