diff -up ed_classified_dev/ed_classified.module ed_classified/ed_classified.module
--- ed_classified_dev/ed_classified.module 2008-02-23 21:02:58.000000000 -0500
+++ ed_classified/ed_classified.module 2009-01-25 02:53:06.000000000 -0500
@@ -229,10 +229,23 @@ function ed_classified_menu($may_cache)
'type' => MENU_NORMAL_ITEM, // MENU_SUGGESTED_ITEM,
'callback' => 'ed_classified_page');
$items[] = array(
- 'path' => 'node/add/' . EDI_CLASSIFIED_PATH_NAME,
- 'title' => _ed_classified_displayname(),
+ 'path' => EDI_CLASSIFIED_PATH_NAME . '/add',
+ 'title' => t('Submit new Classified Ad'), //_ed_classified_displayname(),
'access' => user_access('create classified ads'),
- );
+ 'type' => MENU_ITEM_GROUPING & MENU_EXPANDED,
+ 'callback' => 'ed_classified_add',
+ );
+ // Create menu items for all ed_classified content types
+ $sql = "SELECT type, name FROM {node_type} WHERE module = '%s'";
+ $result = db_query($sql, EDI_CLASSIFIED_MODULE_NAME);
+ while ($content_type = db_fetch_object($result)) {
+ $items[] = array(
+ 'path' => EDI_CLASSIFIED_PATH_NAME . '/add/'. str_replace('_','-',$content_type->type),
+ 'title' => 'Create new ' . $content_type->name,
+ 'type' => MENU_NORMAL_ITEM,
+ 'access' => user_access('create classified ad'),
+ );
+ }
$items[] = array(
'path' => 'admin/content/node/' . EDI_CLASSIFIED_PATH_NAME,
'title' => _ed_classified_displayname(),
@@ -244,11 +257,36 @@ function ed_classified_menu($may_cache)
'path' => 'admin/settings/'. EDI_CLASSIFIED_PATH_NAME,
'title' => $name,
'description' => t('Configure @name settings', $parms),
- 'callback' => 'drupal_get_form',
- 'callback arguments' => array('ed_classified_admin_settings'),
+ 'callback' => 'ed_classified_admin_page',
'access' => user_access('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM, // optional
);
+ $items[] = array(
+ 'path' => 'admin/settings/' . EDI_CLASSIFIED_PATH_NAME . '/general',
+ 'title' => t('General'),
+ 'description' => t('Allows the user to configure overall default values for @name.', $parms),
+ 'callback' => 'ed_classified_admin_page',
+ 'access' => user_access('administer site configuration'),
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => -10,
+ );
+ $items[] = array(
+ 'path' => 'admin/settings/' . EDI_CLASSIFIED_PATH_NAME . '/term-defaults',
+ 'title' => t('Default Term Durations'),
+ 'description' => t('Allows the user to configure default expiration values for individual terms.'),
+ 'callback' => 'ed_classified_admin_taxonomy_page',
+ 'access' => user_access('administer site configuration'),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => -9,
+ );
+ $items[] = array(
+ 'path' => 'admin/settings/' . EDI_CLASSIFIED_PATH_NAME . '/content-types',
+ 'title' => t('Content Type Settings'),
+ 'description' => t('Allows the user to configure default expiration values for individual terms.'),
+ 'callback' => 'ed_classified_admin_content_page',
+ 'access' => user_access('administer site configuration'),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => -8,
+ );
$items[] = array('path' => 'admin/' . EDI_CLASSIFIED_PATH_NAME . '/purge',
'title' => t('purge'),
'callback' => '_ed_classified_purge',
@@ -366,18 +404,20 @@ function ed_classified_page($type = NULL
// get a list of categories and counts
$cats = taxonomy_get_tree(_ed_classified_get_vid(), $tid, -1, 1);
for ($i=0; $i < count($cats); $i++) {
- $cats[$i]->count = taxonomy_term_count_nodes($cats[$i]->tid, EDI_CLASSIFIED_MODULE_NAME);
+ $cats[$i]->count = taxonomy_term_count_nodes($cats[$i]->tid);
$tree = taxonomy_get_tree(_ed_classified_get_vid(), $cats[$i]->tid, -1);
$descendant_tids = array_merge(array($cats[$i]->tid), array_map('_taxonomy_get_tid_from_term', $tree));
$last = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (%s) AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), implode(',', $descendant_tids), 0, 1));
$cats[$i]->latest = node_load(array('nid' => $last->nid));
}
-
+ $node_types = array_keys(_ed_classified_get_types());
// TODO: order by created date, #views, what?
$ads = array();
// echo "tid=$tid
"; var_dump($tid);
if ($tid) {
- $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='ed_classified' AND t.tid=%d ORDER BY n.sticky DESC, n.created DESC"), _ed_classified_variable_get('ads_per_page', 10), 0, NULL, $tid);
+ // Query assembly removed from rewrite to prevent escaping of comma separated list.
+ $sql = "SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type IN ('" . implode("','",$node_types) . "') AND t.tid=%d ORDER BY n.sticky DESC, n.created DESC";
+ $result = pager_query(db_rewrite_sql($sql), _ed_classified_variable_get('ads_per_page', 10), 0, NULL, $tid);
while ($node = db_fetch_object($result)) {
$ads[] = node_load(array('nid' => $node->nid));
}
@@ -529,11 +569,18 @@ function ed_classified_load($node) {
* Implementation of hook_node_info().
*/
function ed_classified_node_info() {
+ $info = array();
// beware: these must match nodeapi value; name must be same as $node->type for spam module to add spam reporting links
- return array(EDI_CLASSIFIED_MODULE_NAME =>
+/* $sql = "SELECT type, name, description FROM {node_type} WHERE module = '%s'";
+ $result = db_query($sql, EDI_CLASSIFIED_MODULE_NAME);
+ while ($type = db_fetch_object($result)) {
+ $info["$type->type"] = array( 'name' => t($type->name), 'module' => EDI_CLASSIFIED_MODULE_NAME, 'description' => t($type->description));
+ }*/
+ $info[EDI_CLASSIFIED_MODULE_NAME] =
array('name' => t('Classified Ads'), // cannot call node_get_types() since it ends up calling this code.
'module' => EDI_CLASSIFIED_MODULE_NAME,
- 'description' => t('Contains a title, a body, and an administrator-defined expiration date')));
+ 'description' => t('Contains a title, a body, and an administrator-defined expiration date'));
+ return $info;
}
@@ -667,3 +714,57 @@ function ed_classified_node_type($op, $i
}
}
}
+
+/**
+ * Present a classified ad submission form or a set of links to such forms.
+ */
+function ed_classified_add($type = NULL) {
+ global $user;
+
+ $types = _ed_classified_get_types();
+ $type = isset($type) ? str_replace('-', '_', $type) : NULL;
+ // If a node type has been specified, validate its existence.
+ if (isset($types[$type]) && node_access('create', $type)) {
+ // Initialize settings:
+ $node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type);
+
+ drupal_set_title(t('Submit @name', array('@name' => $types[$type]->name)));
+ $output = drupal_get_form($type .'_node_form', $node);
+ }
+ else {
+ // If no (valid) node type has been provided, display a node type overview.
+ foreach ($types as $type) {
+ if (function_exists($type->module .'_form') && node_access('create', $type->type)) {
+ $type_url_str = str_replace('_', '-', $type->type);
+ $module_url_str = str_replace('_', '-', $type->module);
+ $title = t('Add a new @s.', array('@s' => $type->name));
+ $out = '