Index: flexinode/flexinode.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/flexinode/flexinode.module,v retrieving revision 1.77 diff -U65535 -r1.77 flexinode.module --- flexinode/flexinode.module 29 Apr 2006 18:44:11 -0000 1.77 +++ flexinode/flexinode.module 19 Aug 2006 13:44:37 -0000 @@ -1,1150 +1,1146 @@ $file) { include_once($filename); $function = 'flexinode_'. $file->name .'_name'; if(function_exists($function)) { $types[] = substr($file->name, 6); } } } return $types; } // Load all installed field types. flexinode_field_types(); /** * Implementation of hook_help(). */ function flexinode_help($section) { switch ($section) { case 'admin/help#flexinode': $output = '
'. t('The flexinode module allows administrators to create simple new content types. Administrators find it very useful to create new types of content without having to program a new content module.') .'
'; $output .= ''. t('When creating a new flexinode, administrators are presented with a flexinode form to create their new content type. Once administrators have created their flexinode they can accept the format or choose to theme the content type to change it\'s presentation. For users, creating content that is a flexinode is just like adding other content. The flexinode content type will show up alongside all normal content.') .'
'; $output .= t('You can
'. t('For more information please read the configuration and customization handbook Flexinode page.', array('%flexinode' => 'http://www.drupal.org/handbook/modules/flexinode/')) .'
'; return $output; case 'admin/modules#description': return t('Allows administrators to define their own content types.'); case 'admin/node/types': return t('You may manage your own content types here. These will all have a "title" field to start off, and contain additional fields that you specify. Choose the "add content type" tab to add a new type. Make a selection below to edit an existing type or field. To delete a field or entire content type, first open the editing form for that field or type.'); case 'admin/node/type': return t('Once you create a content type here you will be able to add additional fields to it on the "content types" tab.'); } $output = ''; if (strpos($section, 'node/add') === 0) { foreach (flexinode_content_types() as $type => $name) { if ($section == 'node/add#flexinode-' . $type) { $ctype = flexinode_load_content_type($type); $output .= t($ctype->description); } if ($section == 'node/add/flexinode-' . $type) { $ctype = flexinode_load_content_type($type); $output .= t($ctype->help); } } } return $output; } /** * Implementation of hook_perm(). */ function flexinode_perm() { $perms = array('administer content types'); foreach (flexinode_content_types() as $ctype) { $perms[] = 'create '. $ctype->name .' content'; $perms[] = 'edit own '. $ctype->name .' content'; $perms[] = 'edit any '. $ctype->name .' content'; } return $perms; } /** * Implementation of hook_settings(). */ function flexinode_settings() { //$output = implode("\n", flexinode_invoke_all('settings')); $form['flexinode_list_count'] = array( '#type' => 'textfield', '#title' => t('Number of posts in flexinode listings'), '#description' => t('Number of posts to show on flexinode listing pages.'), '#default_value' => variable_get('flexinode_list_count', 10), ); return $form; } /** * Implementation of hook_link(). */ function flexinode_link($type, $node = 0, $teaser = FALSE) { $links = array(); if ($type == 'node' && strpos($node->type, 'flexinode-') === 0) { /* Don't display a redundant edit link if they are node administrators */ if (flexinode_access('update', $node) && !user_access('administer nodes')) { $links[] = l(t('edit this %nodename', array('%nodename' => node_get_name($node))), 'node/'. $node->nid .'/edit'); } } return $links; } /** * Implementation of hook_menu(). */ function flexinode_menu($may_cache) { $items = array(); if ($may_cache) { $admin_access = user_access('administer content types'); foreach (flexinode_content_types() as $ctype) { $items[] = array( 'path' => 'node/add/flexinode-'. $ctype->ctype_id, 'title' => t($ctype->name), 'access' => user_access('create '. $ctype->name .' content') or $admin_access ); } // listing menu items $items[] = array( 'path' => 'flexinode/list', 'title' => t('list view'), 'callback' => 'flexinode_page_list', 'access' => user_access('access content'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'flexinode/table', 'title' => t('tabular view'), 'callback' => 'flexinode_page_table', 'access' => user_access('access content'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'flexinode/feed', 'title' => t('rss feed'), 'callback' => 'flexinode_feed', 'access' => user_access('access content'), 'type' => MENU_CALLBACK, ); // admin menu items $items[] = array( 'path' => 'admin/node/types', 'title' => t('content types'), 'callback' => 'flexinode_page_admin', 'access' => $admin_access, 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/node/type', 'title' => t('add content type'), 'callback' => 'flexinode_content_type_form', 'access' => $admin_access, 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/node/type/delete', 'title' => t('delete content type'), 'callback' => 'flexinode_confirm_delete_content_type', 'access' => $admin_access, 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/node/field', 'title' => t('edit fields'), 'callback' => 'flexinode_admin_field', 'access' => $admin_access, 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'flexinode/update', 'title' => t('update'), 'callback' => 'flexinode_page_admin_update', 'access' => $admin_access, 'type' => MENU_CALLBACK, ); } return $items; } /** * MENU CALLBACKS */ /** * Menu callback; presents a listing of all nodes of one type. */ function flexinode_page_list($ctype_id = 0) { if (!$ctype_id) { drupal_not_found(); } $output = ''; $ctype = flexinode_load_content_type($ctype_id); if ($ctype_id) { $type = 'flexinode-' . db_escape_string($ctype_id); } else { $type = 'flexinode-%'; } $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.status = 1 AND n.type LIKE '%s' ORDER BY n.sticky DESC, n.created DESC"), variable_get('flexinode_list_count', 10), 0, NULL, $type); while ($node = db_fetch_object($result)) { $output .= node_view(node_load($node->nid), 1); } $output .= theme('pager', NULL, variable_get('flexinode_list_count', 10)); drupal_set_title(t($ctype->name)); return $output ? $output : drupal_not_found(); } /** * Menu callback; presents a tabular view of nodes of one type. */ function flexinode_page_table($ctype_id = 0) { if (!$ctype_id) { drupal_not_found(); } $output = ''; $ctype = flexinode_load_content_type($ctype_id); // Build the query. $fields_to_select = array(); $table_joins = array(); $where_clauses = array(); foreach ($ctype->fields as $field) { $fieldname = 'flexinode_'. $field->field_id; $fields_to_select[] = flexinode_invoke('db_select', $field); $table_joins[] = 'LEFT JOIN {flexinode_data} '. $fieldname .' ON n.nid = '. $fieldname .'.nid'; $where_clauses[] = $fieldname .'.field_id = '. $field->field_id; } $type = 'flexinode-' . db_escape_string($ctype_id); $extra_fields = count($fields_to_select) > 0 ? ', ' . implode(', ', $fields_to_select) : ''; $extra_where = count($where_clauses) > 0 ? ' AND ' . implode(' AND ', $where_clauses) : ''; $sql = 'SELECT n.nid, n.title '. $extra_fields .' FROM {node} n '. implode(' ', $table_joins) ." WHERE n.status = 1 AND n.type = '$type'". $extra_where; // Build the columns. $header[] = array('data' => t('title'), 'field' => 'n.title'); foreach ($ctype->fields as $field) { if ($field->show_table) { $fieldname = 'flexinode_'. $field->field_id; $sort_column = flexinode_invoke('db_sort_column', $field); if ($sort_column) { $header[] = array('data' => t($field->label), 'field' => $sort_column); } else { $header[] = array('data' => t($field->label)); } } } $sql .= tablesort_sql($header); // Build the rows. $rows = array(); $nodes = pager_query(db_rewrite_sql($sql), 20); while ($node = db_fetch_object($nodes)) { $row = array(l($node->title, 'node/' . $node->nid)); foreach ($ctype->fields as $field) { if ($field->show_table) { $data = flexinode_invoke('format', $field, $node, TRUE); $row[] = $data ? $data : ''; } } $rows[] = $row; } if ($rows) { $output .= theme('table', $header, $rows); $output .= theme('pager', NULL, 20); } else { $output .= theme('box', t('Your search yielded no results'), search_help('search#noresults')); } drupal_set_title(t('%type search results', array('%type' => t($ctype->name)))); return $output; } /** * Menu callback; handles rss feeds for flexinode types. */ function flexinode_feed($ctype_id = NULL) { global $base_url; if (!$ctype_id) { drupal_not_found(); } $ctype = flexinode_load_content_type($ctype_id); if ($ctype_id) { $type = 'flexinode-' . db_escape_string($ctype_id); } else { $type = 'flexinode-%'; } $nodes = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.status = 1 AND n.type LIKE '%s' ORDER BY n.sticky DESC, n.created DESC"), $type, 0, variable_get('feed_default_items', 10)); $channel= array( 'title' => variable_get('site_name', 'drupal') .' - '. $ctype->name .t(' feed'), 'link' => $base_url .'/flexinode/list/'. $ctype_id ); node_feed($nodes, $channel); } /** * Menu callback; presents an overview of all admin-defined content types. */ function flexinode_page_admin($ctype_id = NULL) { $content_types = flexinode_content_types(); $first = ($ctype_id ? FALSE : TRUE); $output = ''; foreach ($content_types as $ctype) { $ctype = flexinode_load_content_type($ctype->ctype_id); $ctype->links[] = l(t('edit content type'), 'admin/node/type/' . $ctype->ctype_id); $ctype->links[] = l(t('settings'), 'admin/settings/content-types/flexinode-' . $ctype->ctype_id); $ctype->controls = flexinode_field_select($ctype->ctype_id); foreach ($ctype->fields as $field) { $ctype->fieldlist[] = $field->label . ' (' . l(t('edit field'), 'admin/node/field/' . $field->field_id) .')'; } $output .= theme('flexinode_type', $ctype, ($first || ($ctype_id == $ctype->ctype_id))); $first = FALSE; } if (strlen($output) == 0) { $output = ''. t('No flexinode content types have been defined. You can add a new content type.', array('%url' => url('admin/node/type'))) .'
'; } drupal_add_js('misc/collapse.js'); return $output; } /** * Menu callback; presents a form to edit an existing field in a content type. */ function flexinode_admin_field($field_id = NULL) { - global $form_values; $op = $_POST['op']; $crumbs = drupal_get_breadcrumb(); $crumbs[] = l('content types', 'admin/node/types'); drupal_set_breadcrumb($crumbs); switch ($op) { case t('Add field'): - // load the field select form up into $form_values. formapi is teh r0x0rZ. - flexinode_field_select(); - $output = flexinode_field_form($form_values['field_type'], $form_values['ctype_id']); + $output = flexinode_field_form(); break; case t('Confirm'): $field = flexinode_load_field($field_id); flexinode_delete_field($field); drupal_goto('admin/node/types/'. $field->ctype_id); break; case t('Delete'): $field = flexinode_load_field($field_id); $output = flexinode_confirm_delete_field($field); break; case t('More'): default: $output = flexinode_field_form($field_id); break; } return $output; } /** * Perform database updates from older versions. * * This is a temporary solution until the install system becomes part of * the Drupal core. */ function flexinode_page_admin_update($update_num = 0) { switch ($update_num) { case 1: db_query("ALTER TABLE {flexinode_field} MODIFY default_value MEDIUMTEXT NOT NULL"); db_query("ALTER TABLE {flexinode_field} ADD show_teaser INT(1) UNSIGNED DEFAULT '0' NOT NULL"); db_query("ALTER TABLE {flexinode_field} ADD show_table INT(1) UNSIGNED DEFAULT '0' NOT NULL"); foreach (flexinode_content_types() as $type) { $field_id = flexinode_save_field(array('label' => 'Description', 'default_value' => '', 'rows' => 10, 'required' => 0, 'weight' => 0, 'ctype_id' => $type->ctype_id, 'field_type' => 'textarea', 'options' => NULL, 'description' => '')); $result = db_query("SELECT body, nid FROM {node} WHERE type = 'flexinode-%d'", $type->ctype_id); while ($node = db_fetch_object($result)) { db_query("INSERT INTO {flexinode_data} (nid, field_id, textual_data) VALUES (%d, %d, '%s')", $node->nid, $field_id, $node->body); } } $output = 'Update complete.'; break; default: $output = 'Which update do you wish to perform?
'; $output .= '