Enables users to organize the contents of their site into publications with multiple editions, like a magazine or newspaper.

'); break; case 'admin/settings/epublish': $output = t('

Settings for periodically-issued publications.

'); break; case 'admin/node/configure/defaults': $output = t('

If you want users to be able to enter brief abstracts of postings for displays on headlines and publication pages, check the has abstract box.

'); break; case 'admin/help#epublish': $output = t("

This module helps organize a publication or group of publications, each with multiple editions.

". "

Configuration

To use this module, you have to take a few steps:

". "", array('!modules' => l(t("administer » modules"), "admin/modules", array(), NULL, NULL, FALSE, TRUE), '!taxonomy' => l(t("administer » topics » add vocabulary"), "admin/taxonomy/add/vocabulary", array(), NULL, NULL, FALSE, TRUE), '!taxcreate' => l(t("administer » topics"), "admin/taxonomy", array(), NULL, NULL, FALSE, TRUE), '!access' => l(t("administer » access"), "admin/access", array(), NULL, NULL, FALSE, TRUE))) . t("

Creating and administering publications

". "

The epublish module deals with three objects, which can be created or edited using !admin:

". "\n". "

You can add or organize headlines to a specific edition of a publication by using !admin to specify the edition that you want to edit. You can also use weighting to control the order in which headlines appear.

\n". "

Viewing publications

". "

A list of publications can be viewed at path !epublish. Each publication has a numeric publication ID (pid). An individual publication can be viewed using the path \"epublish/{pid}\" where ". "{pid} is the publication's ID number, or \"epublish\{name}\" where {name} is the publication name. An individual edition can be viewed using the path \"epublish/{pid}/{eid}\" or \"epublish/{name}/{eid}\" ". "where {eid} is the edition ID number. As an alternative to {eid}, the path can also specify editions by their volume and number using the syntax \"v{volume}n{number}\". For example, the path ". "\"epublish/Monthly%20News/v3n14\" would show volume 3, number 14 of the publication named \"Monthly News.\" Or, the path \"epublish/4/v3\" would show all editions of volume 3 of the publication ". "with {pid} 4. The path \"epublish/{pid}/current\" specifies a publication's current edition.

\n", array('!admin' => l(t("administer » epublish"), "admin/epublish", array(), NULL, NULL, FALSE, TRUE), '!epublish' => l(t('epublish'), "epublish"), '!nodes' => l(t("administer » epublish » edition contents"), "admin/epublish/", array(), NULL, NULL, FALSE, TRUE))) . t("

URL Aliases for publication edition

". "

The Publication edition can have custom URL aliases. To enable the URL aliases, one must enable the 'path' module from the !modules.

", array('!modules' => l(t("module list"), "admin/build/modules", array(), NULL, NULL, FALSE, TRUE))) . t("

Viewing latest headlines

". "

In addition to displaying postings that have been collected into specific editions of a publication, you can also view a list of the most recent postings in each topic section ". "at \"epublish/headlines/{sid}\" where {sid} is a numeric section ID. \"Topics\" use taxonomy terms to organize content according to the following rules:

\n". "
  • When editing the topics in each section, you can set an \"automatically-included headlines limit\" specifying the maximum number of headlines that should be included for that topic and also set a time frame that limits the search. For example, a time ". "frame of \"30 days\" means that postings older than that will be ignored. You can also specify which node types are eligible for inclusion.
  • \n". "
  • Most topics refer to a taxonomy term and all of its descendants. For example, a taxonomy might include the term \"music,\" with child terms \"rock,\" \"classical,\" \"jazz.\" Only nodes that have been tagged with one or more of these terms would be included in the topic \"music.\"
  • \n". "
  • In addition, there are three special topics, named \"top stories\" \"advertisement\" and \"miscellaneous,\" which do not filter for taxonomy terms at all. \"Top stories\" are taken from stories that have been marked as \"sticky at top of lists\. ". "The \"miscellaneous\" topic appears at the bottom of each section. (If, however, you set its \"automatically-included headlines limit\" to zero, no miscellanous headlines will be displayed.)
  • \n"). t("

    Publications and headlines blocks

    ". "

    The epublish module creates a sidebar block for each section, as well as an \"epublish\" block that lists all publications. To make blocks visible on your pages, use !blocks.

    ", array('!blocks' => l(t("administer » blocks"), "admin/block", array(), NULL, NULL, FALSE, TRUE))) . t("

    Customizing layouts

    \n". "

    The epublish module comes with several standard \"layouts\" that make it possible to customize the layout of publication pages. The \"node views,\" \"one- and two-column\" and \"regular\" layouts are different ". "page layouts for displaying nodes from a single edition. The \"simple list of headlines only\" layout is used on pages that list multiple editions of a publication.

    \n". "

    You can use !settings to select a headlines layout and section that apply to all publications and their editions. If you check the \"custom layouts\" or \"custom sections\" boxes, ". "individual publications and editions can also be assigned their own separate layouts and sections that override the global settings, according to the following order of precedence:

    \n". "

    Section selection

    ". "\n". "

    Layout selection

    ". "\n". "

    The ability to customize layouts and sections provides considerable flexibility for design purposes, but it can can also make administration of publications more complicated. Most users will probably ". "want to leave the \"custom layouts\" option turned off.

    \n" . "

    Layouts are also themeable, and additional layouts can be can be added as needed. For an explanation of how to do this, see the README.txt file that comes included with this module.

    ", array('!settings' => l(t("epublish settings"), "admin/settings/epublish"))); break; } return $output; } /** * hook_perm: Define user permissions for module epublish */ function epublish_perm() { return array('administer publications', 'edit abstract'); } /** * Implementation of hook_menu: Define menu links. * * - epublish -> publications page * @note See hook_menu for a description of parameters and return values. */ function epublish_menu($may_cache) { $items = array(); if ($may_cache) { // publications $items[] = array('path' => 'epublish', 'title' => t('Publications'), 'access' => user_access('access content'), 'callback' => 'epublish_pub_page', 'type' => MENU_SUGGESTED_ITEM); // publications $items[] = array('path' => 'og/epublish', 'title' => t('Publications'), 'access' => user_access('access content'), 'callback' => 'epublish_pub_page', 'callback arguments' => array('og'), 'type' => MENU_SUGGESTED_ITEM); // headlines $items[] = array('path' => 'headlines', 'title' => t('Headlines'), 'access' => user_access('access content'), 'callback' => 'epublish_headlines_page', 'type' => MENU_CALLBACK); // admin/epublish $items[] = array('path' => 'admin/epublish', 'title' => t('Epublish'), 'callback' => 'epublish_pub_list', 'access' => user_access('administer publications') ); $items[] = array('path' => 'admin/epublish/list', 'title' => t('List publications'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); $items[] = array('path' => 'admin/epublish/add/publication', 'title' => t('Add publication'), 'callback' => 'epublish_admin_publication_edit', 'access' => user_access('administer publications'), 'type' => MENU_LOCAL_TASK); $items[] = array('path' => 'admin/epublish/edit/publication', 'title' => t('Edit publication'), 'callback' => 'epublish_admin_publication_edit', 'access' => user_access('administer publications'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/epublish/add/edition', 'title' => t('Add edition'), 'callback' => 'epublish_admin_edition_add', 'access' => user_access('administer publications'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/epublish/edit/edition', 'title' => t('Edit edition'), 'callback' => 'epublish_admin_edition_edit', 'access' => user_access('administer publications'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/epublish/sections', 'title' => t('Sections and Topics'), 'callback' => 'epublish_sections_table', 'access' => user_access('administer publications'), 'type' => MENU_LOCAL_TASK); $items[] = array('path' => 'admin/epublish/add/section', 'title' => t('Add section'), 'callback' => 'epublish_admin_section_edit', 'access' => user_access('administer publications'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/epublish/edit/section', 'title' => t('Edit section'), 'callback' => 'epublish_admin_section_edit', 'access' => user_access('administer publications'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/epublish/add/topic', 'title' => t('Add topic'), 'callback' => 'epublish_admin_topic_add', 'access' => user_access('administer publications'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/epublish/edit/topic', 'title' => t('Edit topic'), 'callback' => 'epublish_admin_topic_edit', 'access' => user_access('administer publications'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/epublish/headlines', 'title' => t('Add headlines'), 'callback' => 'epublish_admin_node_head', 'access' => user_access('administer publications'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/epublish/edit/volume', 'title' => t('Edit volume name'), 'callback' => 'epublish_admin_volume_edit', 'access' => user_access('administer publications'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/settings/epublish', 'title' => t('Epublish'), 'description' => t('Describes what the settings generally do.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('epublish_admin_settings'), 'access' => user_access('administer site configuration'), 'type' => MENU_NORMAL_ITEM, // optional ); } else { $path = drupal_get_path('module', 'epublish'); if (variable_get('epublish_css', 1)) { drupal_add_css($path . '/epublish.css'); } drupal_add_js($path . '/epublish.js'); } return $items; } /** * Implementation of hook_settings(). */ function epublish_admin_settings() { $form['display'] = array( '#type' => 'fieldset', '#title' => t('Display'), '#collapsible' => true, '#collapsed' => false, ); $order = array('ASC' => 'ascending', 'DESC' => 'descending'); $form['display']['epublish_edition_order'] = array( '#type' => 'select', '#title' => t("Display order for listing editions"), '#default_value' => variable_get('epublish_edition_order', 'DESC'), '#options' => $order, '#description' => t("Descending order means that the most recent editions will appear at the top of the list."), ); $form['display']['epublish_top_stories'] = array( '#type' => 'textfield', '#title' => t('Top stories'), '#default_value' => variable_get('epublish_top_stories', t('top stories')), '#size' => 50, '#maxlength' => 128, '#description' => t('The subtitle used for top stories in a headlines section.'), ); $form['display']['epublish_miscellaneous'] = array( '#type' => 'textfield', '#title' => t('Miscellaneous stories'), '#default_value' => variable_get('epublish_miscellaneous', t('miscellaneous')), '#size' => 50, '#maxlength' => 128, '#description' => t('The subtitle used for miscellaneous stories in a headlines section.'), ); $form['display']['epublish_advertisement'] = array( '#type' => 'textfield', '#title' => t('Advertisement stories'), '#default_value' => variable_get('epublish_advertisement', t('advertisement')), '#size' => 50, '#maxlength' => 128, '#description' => t('The subtitle used for advertisement stories in a headlines section.'), ); $form['display']['epublish_css'] = array( '#type' => 'select', '#title' => t("Include ePublish CSS file"), '#default_value' => variable_get('epublish_css', 1), '#options' => array(1 => t('enabled'), 0 => t('disabled')), '#description' => t("You may want disable the ePublish CSS file and add all necessary styles to your theme."), ); // layouts $layouts = epublish_layouts('page'); $form['layouts'] = array( '#type' => 'fieldset', '#title' => t('Layouts'), '#collapsible' => true, '#collapsed' => false, ); $form['layouts']['epublish_global_layout_page'] = array( '#type' => 'select', '#title' => t("Page layout"), '#default_value' => variable_get('epublish_global_layout_page', 'regular'), '#options' => $layouts, '#description' => t("Select a page layout."), ); $layouts = epublish_layouts('list'); $form['layouts']['epublish_global_layout_list'] = array( '#type' => 'select', '#title' => t("Listing layout"), '#default_value' => variable_get('epublish_global_layout_list', 'list'), '#options' => $layouts, '#description' => t("Select a layout to control the display of headline listings."), ); $form['layouts']['epublish_custom_layouts'] = array( '#type' => 'checkbox', '#title' => t('Custom layouts?'), '#return_value' => 1, '#default_value' => variable_get('epublish_custom_layouts', '0'), '#description' => t('If this option is checked, publications, sections and editions can each have their own own layouts that override the global layouts selected above.'), ); // sections $sids = epublish_sections(); $array_keys = array_keys($sids); $form['sections'] = array( '#type' => 'fieldset', '#title' => t('Sections'), '#collapsible' => true, '#collapsed' => false, ); $form['sections']['epublish_global_sid'] = array( '#type' => 'select', '#title' => t("Headlines section"), '#default_value' => variable_get('epublish_global_sid', array_shift($array_keys)), '#options' => $sids, '#description' => t("Select a section to control which topics are headlined in each publication."), ); $form['sections']['epublish_custom_sections'] = array( '#type' => 'checkbox', '#title' => t('Custom sections?'), '#return_value' => 1, '#default_value' => variable_get('epublish_custom_sections', '0'), '#description' => t('If checked, each publication and edition can have its own section that overrides the global section selected above.'), ); $form['og'] = array( '#type' => 'fieldset', '#title' => t('Organic Groups'), '#collapsible' => true, '#collapsed' => false, ); $form['og']['epublish_og'] = array( '#type' => 'checkbox', '#title' => t('Set group context for editions?'), '#return_value' => 1, '#default_value' => variable_get('epublish_og', 0), '#description' => t('If checked, each edition will set the group context based on the first article in the layout and will modify links from the blocks and lists to use the og-specific links.'), ); return system_settings_form($form); } /** * Implementation of hook_form_alter(). */ function epublish_form_alter($form_id, &$form) { if (isset($form['type']) && $form['type']['#value'] .'_node_settings' == $form_id && user_access('edit abstract')) { $form['submission']['epublish_abstract_'. $form['type']['#value']] = array( '#type' => 'checkbox', '#title' => t('Has abstract'), '#return_value' => 1, '#default_value' => variable_get('epublish_abstract_'. $form['type'] ['#value'], TRUE), '#description' => t('Users can enter a brief abstract summarizing the content of each node.'), ); } else if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && user_access('edit abstract')) { if (variable_get('epublish_abstract_'. $form['type']['#value'], TRUE)) { $node = $form['#node']; $form['epublish_abstract'] = array( '#type' => 'textarea', '#title' => t('Abstract'), '#default_value' => $node->epublish_abstract, '#cols' => 70, '#rows' => 4, '#description' => t('A brief summary of this item.'), ); } } } /** * Implementation of hook_nodeapi(). */ function epublish_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { switch ($op) { case 'insert': if (variable_get('epublish_abstract_'. $node->type, TRUE)) { db_query("INSERT INTO {epublish_abstract} (nid, vid, epublish_abstract) VALUES (%d, %d, '%s')", $node->nid, $node->vid, $node->epublish_abstract); } break; case 'update': if (variable_get('epublish_abstract_'. $node->type, TRUE)) { db_query("DELETE FROM {epublish_abstract} WHERE nid = '%d'", $node->nid); if ($node->epublish_abstract) { db_query("INSERT INTO {epublish_abstract} (nid, epublish_abstract) VALUES (%d, '%s')", $node->nid, $node->vid, $node->epublish_abstract); } } break; case 'delete': db_query("DELETE FROM {epublish_edition_node} WHERE nid = %d AND vid = %d", $node->nid, $node->vid); if (variable_get('epublish_abstract_'. $node->type, TRUE)) { db_query("DELETE FROM {epublish_abstract} WHERE nid = %d AND vid = %d", $node->nid, $node->vid); } break; case 'load': if (variable_get('epublish_abstract_'. $node->type, TRUE)) { $object = db_fetch_object(db_query("SELECT epublish_abstract FROM {epublish_abstract} WHERE nid = %d AND vid = %d", $node->nid, $node->vid)); return array('epublish_abstract' => $object->epublish_abstract); } break; case 'view'://TODO what about having a 'mode' to be in, rather than always showing the controls? // append epublish navigation to all nodes that belong to an edition if ($a4) { $eid = db_result(db_query('SELECT eid FROM {epublish_edition_node} een WHERE vid = %d', $node->vid)); if ($eid) { $node = theme('epublish_navigation', $node, $eid); } } break; } } /** * Implementation of hook_block(). */ function epublish_block($op = 'list', $delta = 0) {//TODO limit view to site-wide/subscribed/public group pub's if ($op == 'list') { $blocks = array(); $blocks[0]['info'] = t('E-Publish'); foreach (epublish_sections() as $sid => $title) { $blocks[$sid]['info'] = t('E-publish section: ') . t($title); } $publications = db_query("SELECT * FROM {epublish_publication}"); while ($publication = db_fetch_object($publications)) { $blocks['pub_' . $publication->pid]['info'] = t($publication->name); $blocks['cur_edition_' . $publication->pid]['info'] = t("Current edition of !pub", array('!pub' => $publication->name)); } return $blocks; } elseif ($op == 'view') { $og = variable_get('epublish_og', 0); // publication blocks if (substr($delta, 0, 12) == 'cur_edition_') { $pid = substr($delta, 12); $publication = epublish_get_pub($pid); $data['subject'] = t($publication->name); $eid = epublish_current_edition($pid); $edition = epublish_get_edition($eid); $sid = epublish_assign_section($edition); $topics = epublish_section_topics($sid, $edition->eid); $items = array(); foreach ($topics as $topic) { foreach ($topic->nodes as $vid) { $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d"; $nid = db_fetch_object(db_query($sql, $vid)); $node = node_load($nid->nid); $sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d"; $count = db_num_rows(db_query($sql_count, $node->nid)); if ($count > 1) { $items[] = l($node->title, "node/$nid->nid/revisions/$vid/view"); } else { $items[] = l($node->title, "node/$nid->nid"); } } } $data['content'] = theme('item_list', $items); return $data; } elseif (substr($delta, 0, 4) == 'pub_') { $pid = substr($delta, 4); $publication = epublish_get_pub($pid); $data['subject'] = t($publication->name); $items = array(); $order = variable_get('epublish_edition_order', 'DESC'); $result = db_query("SELECT * FROM {epublish_edition} WHERE published=1 AND pid='%d' ORDER BY volume $order, number $order, pubdate $order, eid $order LIMIT 10", $publication->pid); while (($edition = db_fetch_object($result)) && $i++ < 10) { if ($og == 1) { $sid = epublish_assign_section($edition); $topics = epublish_section_topics($sid, $edition->eid); $topic = current($topics); $vid = current($topic->nodes); $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d"; $nid = db_fetch_object(db_query($sql, $vid)); $sql2 = "SELECT group_nid FROM {og_ancestry} WHERE nid = %d"; $group = db_fetch_object(db_query($sql2, $nid->nid)); $gid = $group->group_nid; $items[] = l(theme('epublish_edition_reference', $edition), "og/epublish/$gid/$publication->pid/$edition->eid"); } else { $items[] = l(theme('epublish_edition_reference', $edition), "epublish/$publication->pid/$edition->eid"); } } $data['content'] = theme('item_list', $items); if ($i == 10) { $data['content'] .= ''; } return $data; // section blocks } elseif ($delta) { $section = epublish_get_section($delta); $topics = epublish_topic_selection_list($delta); $data['subject'] = l(t($section->title), "headlines/$delta"); $items = array(); foreach ($topics as $tid => $name) { if ($tid > 0) { $items[] = l(t($name), "taxonomy/term/$tid"); } } $data['content'] = theme('item_list', $items); return $data; } else { $data['subject'] = t('Publications'); $result = db_query("SELECT * from {epublish_publication}"); $items = array(); while ($publication = db_fetch_object($result)) { if ($og == 1) { $current_eid = $publication->current_eid; $edition = epublish_get_edition($current_eid); $sid = epublish_assign_section($edition); $topics = epublish_section_topics($sid, $edition->eid); $topic = current($topics); $vid = current($topic->nodes); $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d"; $nid = db_fetch_object(db_query($sql, $vid)); $sql2 = "SELECT group_nid FROM {og_ancestry} WHERE nid = %d"; $group = db_fetch_object(db_query($sql2, $nid->nid)); $gid = $group->group_nid; $items[] = l($publication->name, "og/epublish/$gid/$publication->pid"); } else { $items[] = l($publication->name, "epublish/$publication->pid"); } } $data['content'] .= theme('item_list', $items); return $data; } } } /******************************************* * LISTINGS ******************************************/ /** * epublish_sections: lists all publication sections. * * @param $include_default * A Boolean value indicating whether a "default" option should be included * * @return * An array of sections and their titles, suitable for use as the $options in a form_select call, e.g., * form_select($title, $name, $value, epublish_sections(), $description) */ function epublish_sections($include_default = false) {//TODO allow groups to maintain their own sections $result = db_query("SELECT * FROM {epublish_section}"); $sections = array(); // if no sections exist, create a default section if (!db_num_rows($result)) { $nodetype = array(); foreach (node_get_types() as $type => $name) { $nodetypes[$type] = $name; } $array_keys = array_keys(module_invoke('taxonomy', 'get_vocabularies')); $vid = array_pop($array_keys); epublish_form_section_submit(NULL, array( 'title' => t('default'), 'vid' => $vid, 'node_types' => $nodetypes, 'timeframe' => '', 'layout_list' => '', 'layout_page' => '')); $result = db_query("SELECT * FROM {epublish_section}"); } if ($include_default) { $sections[0] = t(''); } while ($section = db_fetch_object($result)) { $sections[$section->sid] = $section->title; } return $sections; } /** * epublish_layouts: Loads and lists all installed publication layouts. * * Layouts are loaded from files in the epublish directory. Each layout file should have the filename * layout_{name}.inc * Its content should set the variable $description = a short description of the layout (for display in a form_select pulldown menu) * It should also include a function with the filename and parameters * theme_epublish_layout_{name}($section, $params=NULL) * * @param $context_selection * A text string indicating the context in which the layout should appear. Possible contexts include: * --> 'list' => a listing (for example, a list of headlines within an edition) * --> 'page' => the entire contents of a page * --> 'email' => the text of an email (currently not used) * --> 'rss' => an RSS feed (currently not used) * * @return * An array of layouts and their descriptions, suitable for use as the $options in a form_select call, e.g., * form_select($title, $name, $value, epublish_layouts(), $description) */ function epublish_layouts($context_selection=NULL, $include_default=FALSE) { static $layouts, $contexts; if (!isset($layouts)) { $layouts = array(); $files = file_scan_directory(drupal_get_path('module', 'epublish'), '^layout_.*\.inc$'); foreach ($files as $filename => $file) { include_once($filename); $layouts[drupal_substr($file->name, 7)] = $description; if ($context) { $contexts[$context][drupal_substr($file->name, 7)] = $description; } } } if ($context_selection) { if ($include_default) { return array_merge(array(0 => t('')), $contexts[$context_selection]); } else { return $contexts[$context_selection]; } } else { if ($include_default) { return array_merge(array(0 => t('')), $layouts); } else { return $layouts; } } } // Load all layouts. epublish_layouts(); /******************************************* * DISPLAY FUNCTIONS ******************************************/ /** * theme_epublish_abstract: A themeable function to display the abstract for an article. */ function theme_epublish_abstract($abstract) { return '
    ' . $abstract . '
    '; } /** * theme_epublish_topics: A themeable function to display the headlines from an array of topics. * * @param $topics * An array of topics * @param $sid * A headlines section ID number * @param $eid * An edition ID number * @param $context * The context in which the headlines will appear. Possibilities include: * --> 'list' => a list of items (i.e., "
  • item1
  • item2
  • ..." * --> 'page' => the result will be the main content of a page * * @return * An HTML-formatted list of headlines. */ function theme_epublish_topics(&$topics, $sid, &$edition, $context='page') { $params = array(); if ($edition->description) { $params['description'] = $edition->description; } $layout = epublish_assign_layout($sid, $edition, $context); $function = "theme_epublish_layout_$layout"; if (function_exists($function)) { return theme("epublish_layout_$layout", $topics, $params); } } /** * theme_epublish_volume_reference: Themeable function that returns the reference string for an edition of a publication. * * @param $pid * A publication ID. * @param $volume * A volume number * * @return * A text string describing the volume. */ function theme_epublish_volume_reference($pid, $volume) { $dateline = db_result(db_query("SELECT dateline FROM {epublish_volume} WHERE pid='%d' AND volume='%d'", $pid, $volume)); if ($dateline) { return $dateline; } if ($volume) { return t('Volume') . " $volume"; } return t(''); } /** * theme_epublish_edition_reference: Themeable function that returns the reference string for an edition of a publication. * * @param $edition * An edition object. * * @return * A text string describing the edition. */ function theme_epublish_edition_reference(&$edition) { $reference = array(); if ($edition->dateline) { $reference[] = t($edition->dateline); } if ($edition->volume) { $reference[] = t('Volume') . " $edition->volume"; } if ($edition->number) { $reference[] = t('No.') . " $edition->number"; } return implode(', ', $reference); } /** * epublish_pub_page: Display the publication(s). */ function epublish_pub_page($og = NULL) { if ($og == 'og') { $pub = arg(3); $ed = arg(4); //og_set_group_context(arg(2)); } else { $pub = arg(1); $ed = arg(2); //) ? arg(2) : 'current'; } if (is_numeric($pub)) { $publication = epublish_get_pub($pub); } elseif ($pub) { $publication = epublish_get_pub_by_name($pub); } if ($publication) { if ($ed == t('current')) { $ed = epublish_current_edition($publication->pid); } } else { return theme('epublish_format_pub'); } if (is_numeric($ed)) { $edition = epublish_get_edition($ed); $sid = epublish_assign_section($edition); $topics = epublish_section_topics($sid, $edition->eid); $output = theme('epublish_topics', $topics, $sid, $edition, 'page'); } else { $order = variable_get('epublish_edition_order', 'DESC'); preg_match('/(v([0-9]+))?(n([0-9]+))?/i', $ed, $match); $volume = $match[2] ? (" AND volume=" . $match[2]) : ''; $number = $match[4] ? (" AND number=" . $match[4]) : ''; $editions = db_query("SELECT * FROM {epublish_edition} WHERE published=1 AND pid='%d'$volume$number ORDER BY volume $order, number $order, pubdate $order, eid $order", $publication->pid); if (db_num_rows($editions) == 1) { $edition = db_fetch_object($editions); $sid = epublish_assign_section($edition); $topics = epublish_section_topics($sid, $edition->eid); $output = theme('epublish_topics', $topics, $sid, $edition, 'page'); } else { $edition = NULL; if (!$ed) { $output .= '
    ' . $publication->description . '
    '; } while ($ed = db_fetch_object($editions)) { if ($previous_volume && ($ed->volume != $previous_volume)) { $output .= theme('epublish_format_volume', $previous_volume, $publication->pid, $edition_blocks); $edition_blocks = array(); } $edition_blocks[] = theme('epublish_format_edition', $ed); $previous_volume = $ed->volume; } if ($edition_blocks) { $output .= theme('epublish_format_volume', $previous_volume, $publication->pid, $edition_blocks); } $output = '
    ' . $output . '
    '; } } return theme('epublish_pub_page', $output, $publication, $edition, $match[2]); } /** * theme_epublish_pub_page: Display the page. * * @param $output * A publication ID. * @param $publication * A publication object * @param $edition * An edition object * @param $volume * A volume number (used only if a single edition is not specified) */ function theme_epublish_pub_page(&$output, &$publication, &$edition, $volume=NULL) { $og = variable_get('epublish_og', 0); if ($og == 1) { $sid = epublish_assign_section($edition); $topics = epublish_section_topics($sid, $edition->eid); $topic = current($topics); $vid = current($topic->nodes); $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d"; $nid = db_fetch_object(db_query($sql, $vid)); $sql2 = "SELECT group_nid FROM {og_ancestry} WHERE nid = %d"; $group = db_fetch_object(db_query($sql2, $nid->nid)); $gid = $group->group_nid; } if ($publication) { if ($og == 1) { $breadcrumb[] = array('path' => "og/epublish/$gid/$publication->pid", 'title' => $publication->name); } else { $breadcrumb[] = array('path' => "epublish/$publication->pid", 'title' => $publication->name); } $title = $publication->name; } if ($edition->volume) { if ($og == 1) { $breadcrumb[] = array('path' => "og/epublish/$gid/$edition->pid/v$edition->volume", 'title' => theme('epublish_volume_reference', $edition->pid, $edition->volume)); } else { $breadcrumb[] = array('path' => "epublish/$edition->pid/v$edition->volume", 'title' => theme('epublish_volume_reference', $edition->pid, $edition->volume)); } $title = "$publication->name, " . theme('epublish_volume_reference', $edition->pid, $edition->volume); } elseif ($volume) { if ($og == 1) { $breadcrumb[] = array('path' => "og/epublish/$gid/$publication->pid/v$volume", 'title' => theme('epublish_volume_reference', $publication->pid, $volume)); } else { $breadcrumb[] = array('path' => "epublish/$publication->pid/v$volume", 'title' => theme('epublish_volume_reference', $publication->pid, $volume)); } $title = "$publication->name, " . theme('epublish_volume_reference', $publication->pid, $volume); } if ($edition) { if ($og == 1) { $breadcrumb[] = array('path' => "og/epublish/$gid/$edition->pid/$edition->eid", 'title' => "$publication->name, " . theme('epublish_edition_reference', $edition)); } else { $breadcrumb[] = array('path' => "epublish/$edition->pid/$edition->eid", 'title' => "$publication->name, " . theme('epublish_edition_reference', $edition)); } $title = "$publication->name, " . theme('epublish_edition_reference', $edition); } if ($output) { menu_set_location($breadcrumb); } drupal_set_title($title); return $output; } /** * epublish_headlines_page: Display the headlines. */ function epublish_headlines_page() { $sid = arg(1); $sids = epublish_sections(); if (!$sid) { $array_keys = array_keys($sids); $sid = variable_get('epublish_global_sid', array_shift($array_keys)); } $section = epublish_get_section($sid); if ($section->timeframe) { $timeframe = " AND (n.created >= '" . strtotime('-' . $section->timeframe) . "' OR n.sticky=1)"; } $result = db_query("SELECT et.tid, et.count, et.node_types, td.name FROM {epublish_topic} et LEFT JOIN {term_data} td USING (tid) WHERE et.sid='%d' ORDER BY et.weight", $sid); $all_nodes = array(); $topics = array(); while ($topic = db_fetch_object($result)) { $included_node_types = _epublish_build_node_inclusions(array_unique(array_merge(explode(',', $section->node_types), explode(',', $topic->node_types)))); $exclusions = _epublish_build_node_exclusions($all_nodes); // Condition to handle another default section if ($topic->tid == -2) { $topic->name = variable_get('epublish_advertisement', t('advertisement')); $result2 = db_query("SELECT DISTINCT(v.vid), n.nid FROM {node_revisions} INNER JOIN {node} n ON n.nid = v.nid WHERE ($exclusions) AND ($included_node_types) AND n.promote = 1 AND n.status = 1$timeframe AND n.sticky = 1 ORDER by n.created DESC LIMIT $topic->count"); } else if ($topic->tid == -1) { $topic->name = variable_get('epublish_top_stories', t('top stories')); $result2 = db_query("SELECT DISTINCT(v.vid), n.nid FROM {node_revisions} INNER JOIN {node} n ON n.nid = v.nid WHERE ($exclusions) AND ($included_node_types) AND n.promote = 1 AND n.status = 1$timeframe AND n.sticky = 1 ORDER by n.created DESC LIMIT $topic->count"); } else if ($topic->tid == 0) { $topic->name = variable_get('epublish_miscellaneous', t('miscellaneous')); $result2 = db_query("SELECT DISTINCT(v.vid), n.nid FROM {node_revisions} INNER JOIN {node} n ON n.nid = v.nid WHERE ($exclusions) AND ($included_node_types) AND n.promote = 1 AND n.status = 1$timeframe ORDER by n.sticky DESC, v.timestamp DESC LIMIT $topic->count"); } else { $included_terms = _epublish_topic_term_inclusions($topic->tid, $sid); $result2 = db_query("SELECT DISTINCT(v.vid), n.nid FROM {node_revisions} INNER JOIN {node} n ON n.nid = v.nid INNER JOIN {term_node} tn ON n.nid=tn.nid WHERE ($exclusions) AND ($included_node_types) AND ($included_terms) AND n.promote = 1 AND n.status = 1$timeframe ORDER by n.sticky DESC, v.timestamp DESC LIMIT $topic->count"); } $topic->nodes = array(); while ($node = db_fetch_object($result2)) { $topic->nodes[] = $node->vid; $all_nodes[] = $node->vid; } if (count($topic->nodes)) { $topics[] = $topic; } } $breadcrumb[] = array('path' => "epublish/headlines/$section->sid", 'title' => $section->title); menu_set_location($breadcrumb); $edition = NULL; return theme('epublish_topics', $topics, $sid, $edition, 'page'); } /** * theme_epublish_format_volume: A themeable function that lists the issues * of a single volume of a publication. * * @param $volume * A volume number. * @param $pid * A publication ID number * @param $edition_blocks * A list of blocks of HTML text, one for each edition of a volume. * * @return * An HTML-formatted display showing the reference name of the volume and a list of its editions. */ function theme_epublish_format_volume($volume, $pid, $edition_blocks = array()) { $og = variable_get('epublish_og', 0); if ($volume) { if ($og) { $publication = db_fetch_object(db_query("SELECT * FROM {epublish_publication} WHERE pid = %d", $pid)); $current_eid = $publication->current_eid; $edition = epublish_get_edition($current_eid); $sid = epublish_assign_section($edition); $topics = epublish_section_topics($sid, $edition->eid); $topic = current($topics); $vid = current($topic->nodes); $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d"; $nid = db_fetch_object(db_query($sql, $vid)); $sql2 = "SELECT group_nid FROM {og_ancestry} WHERE nid = %d"; $group = db_fetch_object(db_query($sql2, $nid->nid)); $gid = $group->group_nid; $output = '

    ' . l(theme('epublish_volume_reference', $pid, $volume), "og/epublish/$gid/$pid/v$volume") . "

    \n"; } else { $output = '

    ' . l(theme('epublish_volume_reference', $pid, $volume), "epublish/$pid/v$volume") . "

    \n"; } } $output .= '
      ' . implode('', $edition_blocks) . "
    \n"; return '
    ' . "$output
    \n"; } /** * theme_epublish_format_edition: A themeable layout that lists the nodes in a single edition of a publication. * * @param $edition * An edition object. * * @return * An HTML-formatted display showing the reference name of the edition and a list of its headlines. */ function theme_epublish_format_edition(&$edition) { $og = variable_get('epublish_og', 0); $sid = epublish_assign_section($edition); $topics = epublish_section_topics($sid, $edition->eid); if ($og == 1) { $topic = current($topics); $vid = current($topic->nodes); $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d"; $nid = db_fetch_object(db_query($sql, $vid)); $sql2 = "SELECT group_nid FROM {og_ancestry} WHERE nid = %d"; $group = db_fetch_object(db_query($sql2, $nid->nid)); $gid = $group->group_nid; } if (is_numeric($edition->volume) && is_numeric($edition->number) && $edition->volume > 0 && $edition->number > 0) { if ($og == 1) { $output = "
  • ". l(theme('epublish_edition_reference', $edition), "og/epublish/$gid/$edition->pid/v$edition->volume" . "n$edition->number") . "
  • \n"; } else { $output = "
  • ". l(theme('epublish_edition_reference', $edition), "epublish/$edition->pid/v$edition->volume" . "n$edition->number") . "
  • \n"; } } else { if ($og == 1) { $output = "
  • ". l(theme('epublish_edition_reference', $edition), "og/epublish/$gid/$edition->pid/$edition->eid") . "
  • \n"; } else { $output = "
  • ". l(theme('epublish_edition_reference', $edition), "epublish/$edition->pid/$edition->eid") . "
  • \n"; } } $output .= theme('epublish_topics', $topics, $sid, $edition, 'list'); return '
    ' . "$output
    \n"; } /** * theme_epublish_format_pub: A themeable function that lists all of the publications on the site. * * @return * An HTML-formatted display showing the name of each publication and its description. */ function theme_epublish_format_pub() { $result = db_query("SELECT * from {epublish_publication}"); $output = '
    '; $og = variable_get('epublish_og', 0); while ($publication = db_fetch_object($result)) { if ($og == 1) { $current_eid = $publication->current_eid; $edition = epublish_get_edition($current_eid); $sid = epublish_assign_section($edition); $topics = epublish_section_topics($sid, $edition->eid); $topic = current($topics); $vid = current($topic->nodes); $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d"; $nid = db_fetch_object(db_query($sql, $vid)); $sql2 = "SELECT group_nid FROM {og_ancestry} WHERE nid = %d"; $group = db_fetch_object(db_query($sql2, $nid->nid)); $gid = $group->group_nid; $output .= '
    ' . l($publication->name, "og/epublish/$gid/$publication->pid") . "
    \n"; } else { $output .= '
    ' . l($publication->name, "epublish/$publication->pid") . "
    \n"; } if ($publication->description) { $output .= "
    $publication->description
    \n"; } } $output .= "
    \n"; drupal_set_title(t('Publications')); return "
    $output
    "; } /******************************************* * SELECTORS ******************************************/ /** * epublish_assign_layout: chooses the right layout to use in displaying an array of topics. * If the "custom layouts" option is turned on, this function looks for a layout in the following * order and chooses the first one it finds: * --> section * --> edition * --> publication * --> global settings * * @param $sid * A headlines section ID number * @param $eid * An edition ID number * @param $context * The context in which the layout is designed to appear. Possibilities include: * --> 'list' => a list of items (i.e., "
  • item1
  • item2
  • ..." * --> 'page' => the result will be the main content of a page * * @return * the name of the layout to use */ function epublish_assign_layout($sid, &$edition, $context) { $layout = "layout_$context"; if (variable_get('epublish_custom_layouts', '0')) { $section = epublish_get_section($sid); if ($section->$layout) { return $section->$layout; } if ($edition->$layout) { return $edition->$layout; } $publication = epublish_get_pub($edition->pid); if ($publication->$layout) { return $publication->$layout; } } if ($context == 'page') { return variable_get('epublish_global_layout_page', 'regular'); } else { return variable_get('epublish_global_layout_list', 'list'); } } /** * epublish_assign_section: chooses the right headlines section to use for organizing * topics and their headlines. If the "custom sections" option is turned on, this * function looks for a layout in the following order and chooses the first one it finds: * --> edition * --> publication * --> global settings * * @param $edition * An edition object * * @return * the headlines section ID number */ function epublish_assign_section(&$edition) { $sids = epublish_sections(); if (variable_get('epublish_custom_sections', false)) { if ($sids[$edition->sid]) { return $edition->sid; } $publication = epublish_get_pub($edition->pid); if ($sids[$publication->sid]) { return $publication->sid; } } $array_keys = array_keys($sids); $auto_sid = array_shift($array_keys); $sid = variable_get('epublish_global_sid', $auto_sid); if ($sids[$sid]) { return $sid; } else { return $auto_sid; } } /** * epublish_topic_selection_list: returns the topics associated with a specific section ID * * @param $sid * A section ID. * * @return * An associative array of topic IDs and their reference names, for use as the $options parameter in form_select function calls */ function epublish_topic_selection_list($sid) { $result = db_query("SELECT et.tid, td.name FROM {epublish_topic} et LEFT JOIN {term_data} td USING (tid) WHERE et.sid='%d' ORDER BY et.weight", $sid); $topics = array(); while ($topic = db_fetch_object($result)) { // condition added to handle additional default topic if ($topic->tid == -2) { $topic->name = variable_get('epublish_advertisement', t('advertisement')); } else if ($topic->tid == -1) { $topic->name = variable_get('epublish_top_stories', t('top stories')); } else if ($topic->tid == 0) { $topic->name = variable_get('epublish_miscellaneous', t('miscellaneous')); } $topics[$topic->tid] = $topic->name; } return $topics; } /******************************************* * SECTIONS ******************************************/ /** * epublish_get_section: get an epublish_section record from the database * * @param $sid * A publication section ID * * @return * An object containing all of the values for a single record in the * {epublish_section} table. */ function epublish_get_section($sid) { return db_fetch_object(db_query("SELECT * FROM {epublish_section} WHERE sid='%d'", $sid)); } /** * epublish_get_section_by_title: get an epublish_section record from the database, based on its title * * @param $title * The title of a publication section * * @return * An object containing all of the values for a single epublish_section record in the * {epublish_section} table. */ function epublish_get_section_by_title($title) { return db_fetch_object(db_query("SELECT * FROM {epublish_section} WHERE title='%s'", $title)); } /** * epublish_sections_table: list the sections and topics for admin/epublish/sections * * @return * An HTML-formatted table listing each section and its topics */ function epublish_sections_table() {//TODO will need to create a similar interface at the group level; leave this to the site-wide pub's $sections = epublish_sections(); $result = db_query("SELECT * FROM {epublish_section}"); $header = array(t('sections/topics'), array("data" => t("operations"), "colspan" => 2)); while ($section = db_fetch_object($result)) { $topics = epublish_topic_selection_list($section->sid); $rows[] = array(l('' . t($section->title) . '', "headlines/$section->sid", array(), NULL, NULL, FALSE, TRUE), l(t("edit"), "admin/epublish/edit/section/$section->sid"), l(t("add topic"), "admin/epublish/add/topic/$section->sid"), ); $lines = array(); foreach ($topics as $tid => $name) { $lines[] = "-$name (" . l(t('edit topic'), "admin/epublish/edit/topic/$section->sid/$tid") . ')'; } $rows[] = array(implode('
    ', $lines), array('data' => '', 'colspan' => 2)); } $output = theme("table", $header, $rows); $output .= epublish_sections_button(); // Appends Add Section button / return $output; } /** * epublish_sections_button_form(), to define a Add Section button to be appended to admin/epublish/sections page * * @return * An array */ function epublish_sections_button_form() {//TODO this seems like a waste; see above and below $form[] = array( '#type' => 'submit', '#value' => t("Add Section"), ); return $form; } /** * Renders a form returned by epublish_sections_button_form() */ function epublish_sections_button() {//TODO this seems like a waste; see above $output = drupal_get_form('epublish_sections_button_form'); return $output; } /** * Implementation of hook_submit() */ function epublish_sections_button_form_submit($form_id, $form_values) { drupal_goto('admin/epublish/add/section'); } //function section_form() {//TODO this isn't used? the function below calls epublish_form_section too //$output = drupal_get_form('epublish_form_section'); // return $output; //} /** * Page to add or edit a section */ function epublish_admin_section_edit($sid = NULL) { if ($_POST['op'] == t('Delete') || $_POST['edit']['confirm']) { return epublish_del_section($sid); } elseif ($sid) { $section = epublish_get_section($sid); } $output = drupal_get_form('epublish_form_section', $section); return $output; } /** * epublish_form_section: return a form for editing a headlines section * * @param $edit * an array of values handled by the form * * @return * An HTML-formatted form */ function epublish_form_section($edit = NULL) { // $edit = (object) $edit; $form['title'] = array( '#type' => 'textfield', '#title' => t('Section title'), '#default_value' => $edit->title, '#size' => 50, '#maxlength' => 128, '#description' => t('The title for this section.'), '#attributes' => NULL, '#required' => TRUE, ); $vocs = array(); foreach (module_invoke('taxonomy', 'get_vocabularies') as $vid => $voc) { $vocs[$vid] = $voc->name; } if (!$edit) { $array_keys = array_keys($vocs); $edit->vid = array_pop($array_keys); } $form["vid"] = array( '#type' => 'select', '#title' => t("Vocabulary"), '#default_value' => $edit->vid, '#options' => $vocs, '#description' => t("The vocabulary containing the topics covered in this section."), ); if ($edit->sid) { $form['weight'] = array( '#type' => 'fieldset', '#title' => t('Section'), '#value' => $edit->sid, '#tree' => TRUE, ); $result2 = db_query("SELECT et.*, td.name FROM {epublish_topic} et LEFT JOIN {term_data} td USING (tid) WHERE et.sid='%d' ORDER BY et.weight", $edit->sid); while ($topic = db_fetch_object($result2)) { // condition added to handle additional default field if ($topic->tid == -2) { $form['weight'][$topic->tid] = array( '#title' => variable_get('epublish_advertisement', t('advertisement')), '#type' => 'hidden', '#value' => -98, ); } elseif ($topic->tid == -1) { $form['weight'][$topic->tid] = array( '#title' => variable_get('epublish_top_stories', t('top stories')), '#type' => 'hidden', '#value' => -99, ); } elseif ($topic->tid == 0) { $form['weight'][$topic->tid] = array( '#title' => variable_get('epublish_miscellaneous', t('miscellaneous')), '#type' => 'hidden', '#value' => 99, ); } else { $form['weight'][$topic->tid] = array( '#type' => 'weight', '#title' => $topic->name, '#default_value' => $topic->weight, '#delta' => 10, ); } } } if (variable_get('epublish_custom_layouts', '0')) { $layouts = epublish_layouts('page', TRUE); $form["layout_page"] = array( '#type' => 'select', '#title' => t("Page layout"), '#default_value' => $edit->layout_page, '#options' => $layouts, '#description' => t("Select a page layout for this section. If none is selected, the default !settings will be used.", array('!settings' => l(t('layout settings'), 'admin/settings/epublish'))), ); $layouts = epublish_layouts('list', TRUE); $form["layout_list"] = array( '#type' => 'select', '#title' => t("Listing layout"), '#default_value' => $edit->layout_list, '#options' => $layouts, '#description' => t("Select a layout to control the display of headline listings for this section. If none is selected, the default settings will be used."), ); } else { // Even if custom layouts are turned off, pass through the layout values as hidden inputs. if (!$edit->layout_page) { $edit->layout_page = ''; } if (!$edit->layout_list) { $edit->layout_list = ''; } $form['layout_page'] = array( '#type' => 'hidden', '#value' => $edit->layout_page, ); $form['layout_list'] = array( '#type' => 'hidden', '#value' => $edit->layout_list, ); } $form[] = array('#value' => "
    "); $form['rules'] = array( '#type' => 'fieldset', '#title' => t('Automatic selection rules'), ); $form['rules'][] = array('#value' => t('The automatic selection rules determine which postings will be selected to display in the !heads (where no publication or edition is specified).', array('!heads' => l(t('headlines listing'), 'headlines/' . $edit->sid)))); $nodetypes = array(); foreach (node_get_types() as $type => $name_obj) { if (!$node_already_included[$name_obj->name]) { $nodetypes[$name_obj->name] = $name_obj->name; } } $form['rules']['node_types'] = array( '#type' => 'checkboxes', '#title' => t('Content types'), '#default_value' => explode(',', $edit->node_types), '#options' => $nodetypes, '#description' => t('A list of node types you want to include in headlines listings. If none are selected, all node types will be included.'), '#attributes' => NULL, ); $form['rules']['timeframe'] = array( '#type' => 'textfield', '#title' => t('Time frame'), '#default_value' => $edit->timeframe, '#size' => 20, '#maxlength' => 16, '#description' => t('The time frame covered by the headlines listing. For example, "30 days" means that headlines will be selected from items that have been posted within the last 30 days. Other possibilities could be "2 years" or "3 months" or "1 week." If left blank, there is no time limit.'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save') ); if ($edit->sid) { $form["sid"] = array( '#type' => 'hidden', '#value' => $edit->sid, ); $form['delete'] = array( '#type' => 'submit', '#value' => t('Delete'), ); } return $form; } function epublish_sec() {//TODO again, an unused function??? $output = drupal_get_form('epublish_form_section'); return $output; } function theme_epublish_form_section($form) { $output = ''; $output .= drupal_render($form['title']); $output .= drupal_render($form['vid']); if ($form['weight']) { $sid = $form['weight']['#value']; $header = array(t('topics'), t('weight'), l(t("add topic"), "admin/epublish/add/topic/" . $sid)); $rows = array(); foreach ($form['weight'] as $tid => $item) { if (is_array($item) && $item['#title']) { $form['weight'][$tid]['#title'] = NULL; $rows[] = array($item['#title'], drupal_render($form['weight'][$tid]), l(t('options'), "admin/epublish/edit/topic/$sid/$tid")); } } drupal_render($form['weight']); $output .= theme("table", $header, $rows); } $output .= drupal_render($form); return $output; } /** * epublish_form_section_submit: save changes to a headlines section * * @param $edit * an array of values to be saved * * @return * the same array, with modifications if a new record is created */ function epublish_form_section_submit($form_id, $form_values) { if (!$form_values['node_types']) { $form_values['node_types'] = array(); } if ($form_values['sid'] && $form_values['action'] != 'delete') { db_query("UPDATE {epublish_section} SET title = '%s', vid = '%d', node_types = '%s', timeframe='%s', layout_list='%s', layout_page='%s' WHERE sid = '%d'", $form_values['title'], $form_values['vid'], implode(',', $form_values['node_types']), $form_values['timeframe'], $form_values['layout_list'], $form_values['layout_page'], $form_values['sid']); // Handle operations: if (isset($form_values['weight'])) { foreach ($form_values['weight'] as $tid => $value) { db_query("UPDATE {epublish_topic} SET weight = '%d' WHERE sid = '%d' AND tid = '%d'", $value, $form_values['sid'], $tid); } drupal_set_message(t('The "!title" section has been updated.', array('!title' => $form_values['title']))); } } else if ($form_values['action'] == 'delete') { epublish_del_section($form_values['sid']); } else { $form_values['sid'] = db_next_id('{epublish_section}_sid'); db_query("INSERT INTO {epublish_section} (sid, title, vid, node_types, timeframe, layout_list, layout_page) VALUES ('%d', '%s', '%d', '%s', '%s', '%s', '%s')", $form_values['sid'], $form_values['title'], $form_values['vid'], implode(',', $form_values['node_types']), $form_values['timeframe'], $form_values['layout_list'], $form_values['layout_page']); // Every section has a "miscellaneous" topic that can't be deleted, with a weight of 99 (so it always appears at the bottom of the section) $misc_topic = array('sid' => $form_values['sid'], 'tid' => 0, 'count' => 0, 'weight' => 99, 'node_types' => array()); epublish_form_topic_submit(NULL, $misc_topic); if ($form_id) { drupal_set_message(t('The "!title" section has been added.', array('!title' => $form_values['title']))); } } return 'admin/epublish/sections'; } /** * epublish_del_section: delete a headlines section * * @param $sid * the topic section ID to be deleted * * @return * A message stating that the section has been deleted */ function epublish_del_section($sid) { $section = epublish_get_section($sid); if (($_POST['op'] == t('Delete')) && ($_POST ['form_id'] == 'confirm_form' )){ $result = db_query("SELECT * FROM {epublish_edition}"); while ($edition = db_fetch_object($result)) { if (epublish_assign_section($edition) == $sid) { db_query("UPDATE {epublish_edition_node} SET tid=0 WHERE eid = '%d'", $edition->eid); } } db_query("DELETE FROM {epublish_section} WHERE sid = '%d'", $sid); db_query("DELETE FROM {epublish_topic} WHERE sid = '%d'", $sid); db_query("UPDATE {epublish_edition} SET sid=0 WHERE sid = '%d'", $sid); db_query("UPDATE {epublish_publication} SET sid=0 WHERE sid = '%d'", $sid); if ($sid == variable_get('epublish_global_sid', 0)) { variable_del('epublish_global_sid'); } $result = db_query("SELECT * FROM {epublish_section}"); $sections = array(); // if no sections exist, create a default section if (!db_num_rows($result)) { epublish_sections(); drupal_set_message(t('deleted section "!title" and created new default section.', array('!title' => $section->title))); } else { drupal_set_message(t('deleted section "!title".', array('!title' => $section->title))); } drupal_goto("admin/epublish/sections"); } else if ($section->sid) { return drupal_get_form('confirm_form', array('sid' => array( '#type' => hidden, '#value' => $section->sid )), t('Are you sure you want to delete the section "!title"?', array('!title' => $section->title)), 'admin/epublish/sections', t('This action cannot be undone.'), t('Delete'), t('Cancel'),'',''); } else { drupal_set_message(t('The section no longer exists.')); return 'admin/epublish/sections'; } } /******************************************* * TOPICS ******************************************/ /** * epublish_get_topic: get an epublish_topic record from the database * * @param $sid * A section ID * @param $tid * A term ID (a taxonomy term, or else 0 for "top stories" or -1 for "miscellaneous" or -2 for "advertisement") * * @return * An object containing all of the values for a single record in the * {epublish_topic} table. */ function epublish_get_topic($sid, $tid) { return db_fetch_object(db_query("SELECT * FROM {epublish_topic} WHERE sid='%d' AND tid='%d'", $sid, $tid)); } /** * Page to add or edit a publication */ function epublish_admin_topic_edit($sid=NULL, $tid=NULL) { if ($_POST['op'] == t('Delete') || $_POST['edit']['confirm']) { return epublish_del_topic($sid, $tid); } elseif ($sid) { $topic = epublish_get_topic($sid, $tid); } $output = drupal_get_form('epublish_form_topic', $topic); return $output; } function epublish_admin_topic_add($sid = NULL) { $output = drupal_get_form('epublish_form_topic', NULL,$sid); return $output; } /** * epublish_form_topic: return a form for editing a section topic * * @param $edit * an array of values handled by the form * * @return * An HTML-formatted form */ function epublish_form_topic($edit = NULL, $sid = NULL) { if ($edit->sid) { $sid = $edit->sid; } $section = epublish_get_section($sid); $form['sid'] = array( '#type' => 'hidden', '#value' => $sid, ); if ($edit) { // If the topic already exists, display its name as a subhead $term = epublish_get_term($edit->tid, $edit->sid); $form[] = array('#value' => "

    Topic \"$term->name\" in section \"" . l($section->title, "admin/epublish/edit/section/" . $sid) . "\"

    \n"); $form["tid"] = array( '#type' => 'hidden', '#value' => $edit->tid, ); $topic_exists = true; } else { // If creating a new topic, display a pulldown menu to select it $form[] = array('#value' => "

    Add topic to section \"$section->title\"

    \n"); $terms = array(); $terms[-2] = variable_get('epublish_advertisement', t('advertisement')); $terms[-1] = variable_get('epublish_top_stories', t('top stories')); $tree = module_invoke('taxonomy', 'get_tree', $section->vid); $edit->tid = 0; if ($tree) { foreach ($tree as $term) { //$terms[$term->tid] = _taxonomy_depth($term->depth, '-') .' '. $term->name; // the number of hyphens shows depth within the tree structure $terms[$term->tid] = str_repeat('-', $term->depth) .' '. $term->name; // the number of hyphens shows depth within the tree structure } } $form["tid"] = array( '#type' => 'select', '#title' => t("Topic"), '#default_value' => $edit->tid, '#options' => $terms, '#description' => t("The topic for this group of headlines."), ); $topic_exists = false; } // Each topic can be associated with node types in addition to the node types selected for the entire section $node_already_included = array(); foreach (explode(',', $section->node_types) as $node_type) { $node_already_included[$node_type] = TRUE; } $nodetypes = array(); foreach (node_get_types() as $type => $name_obj) { if (!$node_already_included[$name_obj->name]) { $nodetypes[$name_obj->name] = $name_obj->name; } } // HACK because I can't figure out how to make Drupal 4.7 checkboxes work with default values. // (there's an error if submitting with NO boxes checked) if ($_POST['op']) { $types_array = array(); } else { $types_array = explode(',', $edit->node_types); } $form['node_types'] = array( '#type' => 'checkboxes', '#title' => t('Additional Types'), '#default_value' => $types_array, // $types_array, '#options' => $nodetypes, '#description' => t('A list of node types you want to associate with this topic. Node types checked here will be included in addition to node types selected for this section.'), ); $edit->count = $edit->count ? $edit->count : 0; $range = drupal_map_assoc(range(0, 20)); $form["count"] = array( '#type' => 'select', '#title' => t("Automatically-included headlines limit"), '#default_value' => $edit->count, '#options' => $range, '#description' => t("The maximum number of headlines to select for this topic."), ); $range = drupal_map_assoc(range(-10, 10)); if ($topic_exists && $edit->tid == 0) { $form['weight'] = array( '#type' => 'hidden', '#value' => 99, ); $form[] = array( '#type' => 'submit', '#value' => t("Delete"), ); } elseif ($topic_exists && $edit->tid == -2) { $form['weight'] = array( '#type' => 'hidden', '#value' => -98. ); $form[] = array( '#type' => 'submit', '#value' => t("Delete"), ); } elseif ($topic_exists && $edit->tid == -1) { $form['weight'] = array( '#type' => 'hidden', '#value' => -99, ); $form[] = array( '#type' => 'submit', '#value' => t("Delete"), ); } else { $form["weight"] = array( '#type' => 'select', '#title' => t("Topic weight"), '#default_value' => $edit->weight, '#options' => $range, '#description' => t("The weight sorts headline topics. Lighter (smaller weight value) topics \"float up\" towards the top of the page."), ); if(arg(2)!='add') { $form[] = array( '#type' => 'submit', '#value' => t("Delete"), ); } } $form[] = array( '#type' => 'submit', '#value' => t("Submit"), ); return $form; } function epublish_topic() { $output = drupal_get_form('epublish_form_topic'); return $output; } /** * epublish_save_topic: save changes to a section topic * * @param $edit * an array of values to be saved * * @return * the same array, with modifications if a new record is created */ function epublish_form_topic_submit($form_id, $edit) { if (!$edit['tid']) { $edit['tid'] = 0; } if (!$edit['node_types']) { $edit['node_types'] = array(); } if ($edit['sid'] && $edit['action'] != 'delete') { $result = db_query("SELECT * FROM {epublish_topic} WHERE sid = '%d' AND tid = '%d'", $edit['sid'], $edit['tid']); db_query("DELETE FROM {epublish_topic} WHERE sid = '%d' AND tid = '%d'", $edit['sid'], $edit['tid']); db_query("INSERT INTO {epublish_topic} (sid, tid, count, weight, node_types) VALUES (%d, %d, %d, %d, '%s')", $edit['sid'], $edit['tid'], $edit['count'], $edit['weight'], implode(',', $edit['node_types'])); $term = epublish_get_term($edit['tid'], $edit['sid']); if ($form_id) { if (db_num_rows($result)) { drupal_set_message(t('The topic "!title" has been updated.', array('!title' => $term->name))); } else { drupal_set_message(t('The topic "!title" has been added.', array('!title' => $term->name))); } } } else if ($edit['action'] == 'delete') { return epublish_del_topic($edit['sid'], $edit['tid']); } return 'admin/epublish/sections'; } /** * epublish_del_topic: delete a section topic * * @param $sid * the topic's section ID * @param $tid * the topic's term ID (usually a taxonomy term; 0 and -1 signify "top stories" and "miscellaneous") * * @return * A message stating that the section has been deleted */ function epublish_del_topic($sid, $tid) { $term = epublish_get_term($tid, $sid); $section = epublish_get_section($sid); if (($_POST['op'] == t('Delete')) && ($_POST ['form_id'] == 'confirm_form' )){ db_query("DELETE FROM {epublish_topic} WHERE sid = '%d' AND tid = '%d'", $sid, $tid); $result = db_query("SELECT eid FROM {epublish_edition} WHERE sid = '%d'", $sid); while ($edition = db_fetch_object($result)) { db_query("UPDATE {epublish_edition_node} SET tid=0 WHERE tid='%d' AND eid = '%d'", $tid, $edition->eid); } drupal_set_message(t('deleted topic "!term" from section "!section."', array('!term' => $term->name, '!section' => $section->title))); drupal_goto('admin/epublish/sections'); } else if ($term->tid) { return drupal_get_form('confirm_form', array( 'sid' => array( '#type' => hidden, '#value' => $section->sid), 'tid' => array( '#type' => hidden, '#value' => $term->tid), ), t('Are you sure you want to delete the term "!term" from section "!section"?', array('!term' => $term->name,'!section' => $section->title)), 'admin/epublish/sections', t('This action cannot be undone.'), t('Delete'), t('Cancel'),'',''); } else { drupal_set_message(t('The term no longer exists.')); return 'admin/epublish'; } } /** * epublish_section_topics: build an array of topics for a single section of a single edition of a publication. * * @param $sid * A headlines section ID * @param $eid * A publication edition ID. This value is only used if epublish.module is enabled. * * @return * An array of topics. Each topic is an object that contains the following values: * --> tid: the topic ID. The values 0 and -1 correspond to "miscellaneous" and "top stories," respectively. * All other values correspond to a taxonomy term with the same numeric term ID. * --> name: the topic name (either a taxonomy term or the special topic names "miscellaneous" or "top stories") * --> nodes: an array of node IDs for each article associated with the topic */ function epublish_section_topics($sid, $eid) { $section = epublish_get_section($sid); $result = db_query("SELECT DISTINCT(v.vid), v.nid, een.tid, et.weight FROM {node_revisions} v LEFT JOIN {epublish_edition_node} een ON een.vid = v.vid LEFT JOIN {epublish_topic} et ON et.tid=een.tid WHERE eid='$eid' AND et.sid='$sid' ORDER BY et.weight, een.weight, v.timestamp DESC"); $last_tid = NULL; $topics = array(); $topic = NULL; while ($node = db_fetch_object($result)) { if ($last_tid != $node->tid) { if ($topic) { $topics[] = $topic; } $topic = db_fetch_object(db_query("SELECT et.tid, td.name, et.weight FROM {epublish_topic} et LEFT JOIN {term_data} td USING (tid) WHERE et.sid='%d' AND et.tid='%d'", $sid, $node->tid)); if ($topic->tid == -2) { $topic->name = variable_get('epublish_advertisement', t('advertisement')); } else if ($topic->tid == -1) { $topic->name = variable_get('epublish_top_stories', t('top stories')); } else if ($topic->tid == 0) { $topic->name = variable_get('epublish_miscellaneous', t('miscellaneous')); } $last_tid = $node->tid; } $topic->nodes[] = $node->vid; } if ($topic) { $topics[] = $topic; } return $topics; } /******************************************* * PUBLICATIONS ******************************************/ /** * epublish_get_pub: get a publication record from the database * * @param $pid * A publication ID number * * @return * An object containing all of the values for a single record in the * {epublish_publication} table. */ function epublish_get_pub($pid) { return db_fetch_object(db_query("SELECT * FROM {epublish_publication} WHERE pid='%d'", $pid)); } /** * epublish_get_pub_by_name: get a publication record from the database, based on its name * * @param $name * A publication name * * @return * An object containing all of the values for a single record in the * {epublish_publication} table. */ function epublish_get_pub_by_name($name) { $name = preg_replace('/_/', ' ', $name); return db_fetch_object(db_query("SELECT * FROM {epublish_publication} WHERE LOWER('%s') LIKE LOWER(name)", trim($name))); } /** * epublish_pub_list: list the publications for admin/epublish * * @return * An HTML-formatted table listing each publication and its editions */ function epublish_pub_list() {//TODO show only those that the user should see based on subscribed og's, or move the directory elsewhere $order = variable_get('epublish_edition_order', 'DESC'); $publications = db_query("SELECT * FROM {epublish_publication}"); $header = array(t('publication/editions'), array("data" => t("operations"), "colspan" => 2)); while ($publication = db_fetch_object($publications)) { $rows[] = array(l('' . t($publication->name) . '', "epublish/$publication->pid", array(), NULL, NULL, FALSE, TRUE), l(t("edit publication"), "admin/epublish/edit/publication/$publication->pid"), l(t("add edition"), "admin/epublish/add/edition/$publication->pid") ); $result = db_query("SELECT * FROM {epublish_edition} WHERE pid='%d' ORDER BY volume $order, number $order, pubdate $order, eid $order", $publication->pid); $previous_volume = -1; $editions = array(); while ($edition = db_fetch_object($result)) { if ($edition->volume != $previous_volume) { if ($previous_volume != -1) { $rows[] = array(implode('
    ', $editions), array('data' => t('volume name: ') . l(theme('epublish_volume_reference', $publication->pid, $previous_volume), "admin/epublish/edit/volume/$publication->pid/$previous_volume"), 'colspan' => 2)); $editions = array(); } } $editions[] = '-' . theme('epublish_edition_reference', $edition) . ' (' . l(t('edit edition'), "admin/epublish/edit/edition/$edition->eid") . ')'; $previous_volume = $edition->volume; } if ($editions) { $rows[] = array(implode('
    ', $editions), array('data' => t('volume name: ') . l(theme('epublish_volume_reference', $publication->pid, $previous_volume), "admin/epublish/edit/volume/$publication->pid/$previous_volume"), 'colspan' => 2)); } } $output = theme("table", $header, $rows); return $output; } /** * Page to add or edit a publication */ function epublish_admin_publication_edit($pid = NULL) { if ($_POST['op'] == t('Delete') || $_POST['edit']['confirm']) { return epublish_del_pub($pid); } elseif ($pid) { $publication = epublish_get_pub($pid); } $output = drupal_get_form('epublish_form_pub', $publication); return $output; } /** * epublish_form_pub: return a form for editing a publication * * @param $edit * an array of values handled by the form * * @return * An HTML-formatted form */ function epublish_form_pub($edit = NULL) { $edit = (object) $edit; if (!$edit) { $edit->pid = 0; } $order = variable_get('epublish_edition_order', 'DESC'); $form['name'] = array( '#type' => 'textfield', '#title' => t('Publication name'), '#default_value' => $edit->name, '#size' => 50, '#maxlength' => 128, '#description' => t('The name for this publication.'), '#attributes' => NULL, '#required' => TRUE, ); $form['description'] = array( '#type' => 'textarea', '#title' => t('Description'), '#default_value' => $edit->description, '#cols' => 70, '#rows' => 4, '#description' => t('A description of this publication.'), ); // The schedule field doesn't currently do anything but may be used in some future version of this module. --Sheldon $form['schedule'] = array( '#type' => 'hidden', '#value' => '', ); $editions[0] = ''; if ($edit->pid) { $result = db_query("SELECT * FROM {epublish_edition} WHERE pid='%d' ORDER BY volume $order, number $order, pubdate $order, eid $order", $edit->pid); while ($edition = db_fetch_object($result)) { $editions[$edition->eid] = theme('epublish_edition_reference', $edition); } } if (!$edit->current_eid) { $edit->current_eid = 0; } $form['current_eid'] = array( '#type' => 'select', '#title' => t("Current edition"), '#default_value' => $edit->current_eid, '#options' => $editions, '#description' => t("The default edition to display from this publication. If none is specified, the latest edition will be selected."), ); // Select a layout if (variable_get('epublish_custom_layouts', '0')) { $layouts = epublish_layouts('page', TRUE); $form["layout_page"] = array( '#type' => 'select', '#title' => t("Page layout"), '#default_value' => $edit->layout_page, '#options' => $layouts, '#description' => t("Select a page layout for this publication. If none is selected, the default !settings will be used.", array('!settings' => l(t('layout settings'), 'admin/settings/epublish'))), ); $layouts = epublish_layouts('list', TRUE); $form["layout_list"] = array( '#type' => 'select', '#title' => t("Listing layout"), '#default_value' => $edit->layout_list, '#options' => $layouts, '#description' => t("Select a layout to control the display of headline listings for this publication. If none is selected, the default settings will be used."), ); } else { // Even if custom layouts are turned off, pass through the value as a hidden input. //That way the settings are still there if custom layouts gets turned on again later. $form['layout_page'] = array( '#type' => 'hidden', '#value' => $edit->layout_page, ); $form['layout_list'] = array( '#type' => 'hidden', '#value' => $edit->layout_list, ); } // Select sections if (variable_get('epublish_custom_sections', '0')) { $sids = epublish_sections(true); $form["sid"] = array( '#type' => 'select', '#title' => t("Section"), '#default_value' => $edit->sid, '#options' => $sids, '#description' => t("Select a section to control which topics are headlined for each edition of this publication. If none is selected, the default section from !settings will be used.", array('!settings' => l(t('publication settings'), 'admin/settings/epublish'))), ); } else { $form['sid'] = array( '#type' => 'hidden', '#value' => $edit->sid, ); } $form[] = array( '#type' => 'submit', '#value' => t("Submit"), ); if ($edit->pid) { $form["pid"] = array( '#type' => 'hidden', '#value' => $edit->pid, ); $form[] = array( '#type' => 'submit', '#value' => t("Delete"), ); } return $form; } function epublish_pub() { $output = drupal_get_form('epublish_form_pub'); return $output; } /** * epublish_form_pub_submit: save changes to a publication * * @param $edit * an array of values to be saved * * @return * the same array, with modifications if a new record is created */ function epublish_form_pub_submit($form_id, $edit) { if ($edit['pid'] && $edit['action'] != 'delete') { db_query("UPDATE {epublish_publication} SET name = '%s', description = '%s', schedule = '%s', current_eid = '%d', layout_list = '%s', layout_page = '%s', sid = '%s' WHERE pid = '%d'", $edit['name'], $edit['description'], $edit['schedule'], $edit['current_eid'], $edit['layout_list'], $edit['layout_page'], $edit['sid'], $edit['pid']); drupal_set_message(t('The publication "!title" has been updated.', array('!title' => $edit['name']))); } else if ($edit['action'] == 'delete') { epublish_del_pub($edit['pid']); } else { $edit['pid'] = db_next_id('{epublish_publication}_pid'); db_query("INSERT INTO {epublish_publication} (pid, name, description, schedule, current_eid, layout_list, layout_page, sid) VALUES ('%d', '%s', '%s', '%s', '%d', '%s', '%s', '%s')", $edit['pid'], $edit['name'], $edit['description'], $edit['schedule'], $edit['current_eid'], $edit['layout_list'], $edit['layout_page'], $edit['sid']); drupal_set_message(t('The publication "!title" has been added.', array('!title' => $edit['name']))); } return 'admin/epublish'; } /** * epublish_del_pub: delete a publication * * @param $pid * the publication ID to be deleted * * @return * A message stating that the publication has been deleted */ function epublish_del_pub($pid) { $publication = epublish_get_pub($pid); if (($_POST['op'] == t('Delete')) && ($_POST ['form_id'] == 'confirm_form' )){ db_query("DELETE FROM {epublish_publication} WHERE pid = '%d'", $pid); $result = db_query("SELECT eid from {epublish_edition} WHERE pid = '%d'", $pid); while ($edition = db_fetch_object($result)) { db_query("DELETE FROM {epublish_edition_node} WHERE eid = '%d'", $edition->eid); } db_query("DELETE FROM {epublish_edition} WHERE pid = '%d'", $pid); db_query("DELETE FROM {epublish_volume} WHERE pid = '%d'", $pid); drupal_set_message(t('deleted publication "!name".', array('!name' => $publication->name))); drupal_goto("admin/epublish"); } else if ($publication->pid) { return drupal_get_form('confirm_form',array('pid' => array( '#type' => hidden,'#value' => $publication->pid)), t('Are you sure you want to delete the publication "!title"?', array('!title' => $publication->name)), 'admin/epublish', t('This action cannot be undone.'), t('Delete'), t('Cancel'),'confirm'); } else { drupal_set_message(t('The section no longer exists.')); return 'admin/epublish'; } } /******************************************* * EDITIONS ******************************************/ /** * epublish_get_edition: get an epublish_edition record from the database * * @param $eid * An edition ID number * * @return * An object containing all of the values for a single record in the * {epublish_edition} table. */ function epublish_get_edition($eid) { return db_fetch_object(db_query("SELECT * FROM {epublish_edition} WHERE eid='%d'", $eid)); } /** * epublish_current_edition: return the current edition ID number for a publication. * If no edition is specified, returns the edition with the latest publication date. * * @param $pid * A publication ID number * * @return * An edition ID number */ function epublish_current_edition($pid=0) { $publication = epublish_get_pub($pid); if ($publication->current_eid) { return $publication->current_eid; } $eid = db_result(db_query("SELECT eid FROM {epublish_edition} WHERE pid='%d' ORDER BY volume DESC, number DESC, pubdate DESC, eid DESC LIMIT 1", $pid)); if ($eid) { return $eid; } $eid = db_result(db_query("SELECT eid FROM {epublish_edition} ORDER BY pubdate DESC, volume DESC, number DESC, eid DESC LIMIT 1")); return $eid; } /** * Page to add or edit an edition */ function epublish_admin_edition_edit($eid = NULL) { if ($_POST['op'] == t('Delete') || $_POST['edit']['confirm']) { return epublish_del_edition($eid); } elseif ($_POST['op'] == t('Add more headlines')) { drupal_goto( "admin/epublish/headlines/$eid" ); } elseif ($eid) { $edition = epublish_get_edition($eid); } $output = drupal_get_form('epublish_form_edition',$edition); return $output; } function epublish_admin_edition_add($pid = NULL) { $output = drupal_get_form('epublish_form_edition',NULL,$pid); return $output; } /** * epublish_form_edition: return a form for editing a publication edition * * @param $edit * an array of values handled by the form * * @return * An HTML-formatted form */ function epublish_form_edition($edit = NULL, $pid=NULL) {//TODO makes sure a given user only sees nodes for the group the pub belongs to or public posts to add to pub $urlquery = 'epublish/'.$edit->pid.'/'.$edit->eid; $urlres= db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '".$urlquery."'")); $edit = (object) $edit; if ($pid) { $edit->pid = $pid; } $publication = epublish_get_pub($edit->pid); $form[] = array('#value' => '

    ' . t('Edition of publication ') . l($publication->name, "admin/epublish/edit/publication/$publication->pid") . "

    \n"); $form['pid'] = array( '#type' => 'hidden', '#value' => $edit->pid, ); $form['dateline'] = array( '#type' => 'textfield', '#title' => t('Dateline'), '#default_value' => $edit->dateline, '#size' => 50, '#maxlength' => 128, '#description' => t('A textual representation of the publication date, e.g., "March 2003" or "April 11-17, 2004."'), ); $form[] = array('#value' => '
    '); $form['volume'] = array( '#type' => 'textfield', '#title' => '', '#default_value' => $edit->volume, '#size' => 6, '#maxlength' => 6, '#prefix' => '' . t('Volume') . ': ', ); $form['number'] = array( '#type' => 'textfield', '#title' => '', '#default_value' => $edit->number, '#size' => 6, '#maxlength' => 6, '#prefix' => '' . t('Number') . ': ', ); $form[] = array('#value' => '
    '); $form['description'] = array( '#type' => 'textarea', '#title' => t('Description'), '#default_value' => $edit->description, '#cols' => 70, '#rows' => 8, ); if (module_exists('path')) { $path = $form['#node']->path; $form['path'] = array( '#type' => 'fieldset', '#title' => t('URL path settings'), '#collapsible' => TRUE, '#collapsed' => empty($path), '#weight' => 1, ); $form['path']['path'] = array( '#type' => 'textfield', '#default_value' => $urlres, '#maxlength' => 250, '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => t('Optionally specify an alternative URL by which this node can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'), ); $form['path']['pthid'] = array( '#type' => 'hidden', '#value' => db_result(db_query("SELECT pid FROM {url_alias} WHERE dst ='".$urlres."'")) ); } // publication date if (!$edit->year && !$edit->pubdate) { $edit->year = date('Y', time()); $edit->month = date('m', time()); $edit->day = date('d', time()); } else if (!$edit->year) { $edit->year = substr($edit->pubdate, 0, 4); $edit->month = substr($edit->pubdate, 4, 2); $edit->day = substr($edit->pubdate, 6, 2); } $years = drupal_map_assoc(range(date("Y", time())-15, date("Y", time())+1)); $months = array('01' => t("January"), '02' => t("February"), '03' => t("March"), '04' => t("April"), '05' => t("May"), '06' => t("June"), '07' => t("July"), '08' => t("August"), '09' => t("September"), '10' => t("October"), '11' => t("November"), '12' => t("December")); $days = array('01' => '1', '02' => '2', '03' => '3', '04' => '4', '05' => '5', '06' => '6', '07' => '7', '08' => '8', '09' => '9', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27', '28' => '28', '29' => '29', '30' => '30', '31' => '31'); $form[] = array('#value' => '
    '); $form["month"] = array( '#type' => 'select', '#title' => "Publication date", '#default_value' => $edit->month, '#options' => $months ); $form['day'] = array( '#type' => 'select', '#title' => "", '#default_value' => $edit->day, '#options' => $days, ); $form['year'] = array( '#type' => 'select', '#title' => "", '#default_value' => $edit->year, '#options' => $years, ); $form[] = array('#value' => '
    '); // Select a layout if (variable_get('epublish_custom_layouts', '0')) { $layouts = epublish_layouts('page', TRUE); $form["layout_page"] = array( '#type' => 'select', '#title' => t("Page layout"), '#default_value' => $edit->layout_page, '#options' => $layouts, '#description' => t("Select a page layout for this edition. If none is selected, the default !settings will be used.", array('!settings' => l(t('layout for this publication'), 'admin/epublish/edit/publication/' . $edit->pid))), ); $layouts = epublish_layouts('list', TRUE); $form["layout_list"] = array( '#type' => 'select', '#title' => t("Listing layout"), '#default_value' => $edit->layout_list, '#options' => $layouts, '#description' => t("Select a layout to control the display of headline listings for this edition. If none is selected, the default for this publication will be used."), ); } else { // Even if custom layouts are turned off, pass through the value as a hidden input. //That way the settings are still there if custom layouts gets turned on again later. $form['layout_page'] = array( '#type' => 'hidden', '#value' => $edit->layout_page, ); $form['layout_list'] = array( '#type' => 'hidden', '#value' => $edit->layout_list, ); } // Select section(s) if (variable_get('epublish_custom_sections', '0')) { $sids = epublish_sections(true); $form["sid"] = array( '#type' => 'select', '#title' => t("Section"), '#default_value' => $edit->sid, '#options' => $sids, '#description' => t("Select a section to control which topics are headlined in this edition. If none is selected, the default section for this publication will be used."), ); } else { // Even if custom sections are turned off, pass through the value as a hidden input. //That way the settings are still there if custom sections gets turned on again later. $form['sid'] = array( '#type' => 'hidden', '#value' => $edit->sid, ); } if ($edit->eid) { $form['published'] = array( '#type' => 'checkbox', '#title' => t('Published?'), '#return_value' => 1, '#default_value' => $edit->published, ); $form['make_current'] = array( '#type' => 'checkbox', '#title' => t('Make current?'), '#return_value' => 1, '#default_value' => ($edit->eid == $publication->current_eid), '#description' => t('Check this box if you want this to be the !current of this publication', array('!current' => l(t('current edition'), "epublish/" . $publication->pid . "/current"))), ); $form["eid"] = array( '#type' => 'hidden', '#value' => $edit->eid, ); $form[] = array( '#type' => 'submit', '#weight' => 2, '#value' => t("Submit"), ); $form[] = array( '#type' => 'submit', '#weight' => 2, '#value' => t("Delete"), ); // headlines $form[] = array('#value'=>'
    ', '#weight' => 2,) ; $form['headlines'] = array( '#type' => 'fieldset', '#title' => t('Manage headlines'), ); $edition = epublish_get_edition($edit->eid); $sid = epublish_assign_section($edition); $operations = array('add' => t('Update the selected posts'), 'del' => t('Remove the selected posts')); $form['headlines'][] = array('#value'=>'
    '); $form['headlines']['operation'] = array( '#type' => 'select', '#default_value' => 'add', '#options' => $operations, ); $form['headlines']['submit'] = array('#type' => 'submit', '#value' => t('Update')); $form['headlines'][] = array('#type' => 'submit', '#value' => t("Add more headlines")); $form['headlines'][] = array('#value'=>'
    '); $header = array(NULL, t('Stories'), t('Topic'), t('Type'), t('Status'), t('Weight')); $topics = epublish_topic_selection_list($sid); $result = db_query(db_rewrite_sql("SELECT v.vid, v.nid, v.title, v.timestamp, n.status, n.type, een.weight, een.tid FROM {node_revisions} v LEFT JOIN {epublish_edition_node} een ON v.vid = een.vid INNER JOIN {node} n ON n.nid = v.nid LEFT JOIN {epublish_topic} et ON et.tid=een.tid WHERE eid='" . $edit->eid . "' AND et.sid='" . $sid . "' ORDER BY et.weight, een.weight, v.timestamp DESC")); while ($node = db_fetch_object($result)) { $nodes[$node->vid] = ''; $sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d"; $count = db_num_rows(db_query($sql_count, $node->nid)); if ($count > 1) { $form['title'][$node->vid] = array('#value' => l($node->title, 'node/'. $node->nid .'/revisions/'. $node->vid .'/view') .' '. theme('mark', node_mark($node->nid, $node->changed))); } else { $form['title'][$node->vid] = array('#value' => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed))); } $form['name'][$node->vid] = array('#value' => node_get_types('name', $node)); $form['tid']['tid_' . $node->vid] = array('#type' => 'select', '#default_value' => $node->tid, '#options' => $topics, '#attributes' => array('onchange'=>'onChangeTID(' . $node->vid . ')')); $form['status'][$node->vid] = array('#value' => ($node->status ? t('published') : t('not published'))); $form['weight']['weight_' . $node->vid] = array('#type' => 'weight', '#default_value' => $node->weight, '#delta' => 30, '#attributes' => array('onchange'=>'onChangeWeight(' . $node->vid . ')')); } $form['nodes'] = array('#type' => 'checkboxes', '#options' => $nodes); drupal_set_title(t('edit ') . "$publication->name, " . theme('epublish_edition_reference', $edition)); } else { $form['published'] = array( '#type' => 'checkbox', '#title' => t('Published?'), '#return_value' => 1, '#default_value' => 1, ); $form['make_current'] = array( '#type' => 'checkbox', '#title' => t('Make current?'), '#return_value' => 1, '#default_value' => 0, ); $form[] = array( '#type' => 'submit', '#value' => t("Submit"), ); } return $form; } function epublish_edition() {//TODO another unused function? $output = drupal_get_form('epublish_form_edition'); return $output; } function theme_epublish_form_edition($form) { // create the headlines table if (isset($form['title']) && is_array($form['title'])) { $rows = array(); foreach (element_children($form['title']) as $key) { $row = array(); $row[] = drupal_render($form['nodes'][$key]); $row[] = drupal_render($form['title'][$key]); $row[] = drupal_render($form['name'][$key]); $row[] = drupal_render($form['tid']['tid_' . $key]); $row[] = drupal_render($form['status'][$key]); $row[] = drupal_render($form['weight']['weight_' . $key]); $rows[] = $row; } } else { $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '6')); } $header = array(NULL, t('Title'), t('Type'), t('Topic'), t('Status'), t('Weight')); $table_content = theme('table', $header, $rows); // put the table content inside the headlines fieldset $output = drupal_render($form['headlines']); $output = str_replace('', $table_content . "\n\n", $output); // put the headlines fieldset and table below the rest of the form content $output = drupal_render($form) . $output; return $output; } /** * epublish_save_edition: save changes to a publication edition * * @param $edit * an array of values to be saved * @make_current $edit * a Boolean value that indicates whether or not this edition should become the current edition of the publication * * @return * the same array, with modifications if a new record is created */ // ($edit, $make_current = false) function epublish_form_edition_submit($form_id, $edit) { if ($edit['eid'] && $edit['action'] != 'delete') { if(module_exists('path')) { $ppid = $edit['pid']; $peid = $edit['eid']; $pnid = $edit['path']; $pthid = $edit['pthid']; if ($edit['path']) { if($pthid) { path_set_alias("epublish/$ppid/$peid",$pnid,$pthid); } else { path_set_alias("epublish/$ppid/$peid",$pnid); } } } db_query("UPDATE {epublish_edition} SET pid='%d', dateline='%s', description='%s', volume='%d', number='%d', pubdate='%d', layout_list='%s', layout_page='%s', sid='%d', published='%d' WHERE eid = '%d'", $edit['pid'], $edit['dateline'], $edit['description'], $edit['volume'], $edit['number'], $edit['year'].$edit['month'].$edit['day'], $edit['layout_list'], $edit['layout_page'], $edit['sid'], $edit['published'], $edit['eid']); // Handle operations: if (isset($edit['operation']) && isset($edit['nodes'])) { foreach ($edit['nodes'] as $vid => $value) { if ($value) { $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d"; $nid = db_fetch_object(db_query($sql, $vid)); switch ($edit['operation']) { case 'add': epublish_add_node($edit['eid'], $nid->nid, $vid, $edit['weight_' . $vid], $edit['tid_' . $vid]); break; case 'del': epublish_del_node($edit['eid'], $nid->nid, $vid); break; } } } drupal_set_message(t('The "!title" edition has been updated.', array('!title' => $edit['dateline']))); } } elseif ($edit['action'] == 'delete') { epublish_del_edition($edit); } else { $edit['eid'] = db_next_id('{epublish_edition}_eid'); db_query("INSERT INTO {epublish_edition} (eid, pid, dateline, description, volume, number, pubdate, layout_list, layout_page, sid, published) VALUES ('%d', '%d', '%s', '%s', '%d', '%d', '%d', '%s', '%s', '%d', '%d')", $edit['eid'], $edit['pid'], $edit['dateline'], $edit['description'], $edit['volume'], $edit['number'], $edit['year'].$edit['month'].$edit['day'], $edit['layout_list'], $edit['layout_page'], $edit['sid'], $edit['published']); drupal_set_message(t('The "!title" edition has been added.', array('!title' => $edit['dateline']))); } if ($edit['make_current']) { db_query("UPDATE {epublish_publication} SET current_eid = '%d' WHERE pid = '%d'", $edit['eid'], $edit['pid']); } return 'admin/epublish'; } /** * epublish_del_edition: delete a publication edition * * @param $edit * an array for the edition to be deleted * * @return * A message stating that the edition has been deleted */ function epublish_del_edition($eid) { $edition = epublish_get_edition($eid); if (($_POST['op'] == t('Delete')) && ($_POST ['form_id'] == 'confirm_form' )){ $publication = epublish_get_pub($edition->pid); db_query("DELETE FROM {epublish_edition} WHERE eid = '%d'", $edition->eid); db_query("DELETE FROM {epublish_edition_node} WHERE eid = '%d'", $edition->eid); drupal_set_message(t('Deleted "!edition" edition from publication "!publication."', array('!edition' => $edition->dateline, '!publication' => $publication->name))); drupal_goto("admin/epublish"); } else if ($edition->eid) { $publication = epublish_get_pub($edition->pid); return drupal_get_form('confirm_form', array('eid' => array('#type' => hidden, '#value' => $edition->eid)), t('Are you sure you want to delete the "!edition" edition from publication "!publication"?', array('!edition' => $edition->dateline, '!publication' => $publication->name)), 'admin/epublish', t('This action cannot be undone.'), t('Delete'), t('Cancel'),'',''); } else { drupal_set_message(t('The edition no longer exists.')); return 'admin/epublish'; } } /******************************************* * VOLUMES ******************************************/ /** * epublish_get_volume: get an epublish_volume record from the database * * @param $pid * A publication ID number * @param $volume * A volume number * * @return * An object containing all of the values for a single record in the * {epublish_volume} table. */ function epublish_get_volume($pid, $volume) { $vol = db_fetch_object(db_query("SELECT * FROM {epublish_volume} WHERE pid='%d' AND volume='%d'", $pid, $volume)); if (!$vol) { db_query("INSERT INTO {epublish_volume} (pid, volume) VALUES ('%d', '%d')", $pid, $volume); $vol = db_fetch_object(db_query("SELECT * FROM {epublish_volume} WHERE pid='%d' AND volume='%d'", $pid, $volume)); } return $vol; } /** * Page to add or edit an edition */ function epublish_admin_volume_edit($pid = NULL, $volume = NULL) { if ($_POST['op'] == t('Delete') || $_POST['edit']['confirm']) { return epublish_del_volume($pid, $volume); } elseif ($pid) { $volume = epublish_get_volume($pid, $volume); } //return epublish_form_volume($volume); $output = drupal_get_form('epublish_form_volume',$volume); return $output; } /** * epublish_form_volume: return a form for editing a publication volume * * @param $edit * an array of values handled by the form * * @return * An HTML-formatted form */ function epublish_form_volume($edit = NULL) { $edit = (object) $edit; $publication = epublish_get_pub($edit->pid); $form[] = array('#value' => '

    ' . t('Volume !vol of publication "!pub"', array('!vol' => $edit->volume, '!pub' => l($publication->name, "admin/epublish/edit/publication/$publication->pid"))) . "

    \n"); $form["pid"] = array( '#type' => 'hidden', '#value' => $edit->pid, ); $form["volume"] = array( '#type' => 'hidden', '#value' => $edit->volume, ); $form['dateline'] = array( '#type' => 'textfield', '#title' => t('Name'), '#default_value' => $edit->dateline, '#size' => 50, '#maxlength' => 128, '#description' => t('A name for this volume. Since many publications begin a new volume annually, the name might simply be the name of that year, e.g., "2004."'), ); $form[] = array( '#type' => 'submit', '#value' => t("Submit"), ); $form[] = array( '#type' => 'submit', '#value' => t("Delete"), ); return $form; } function epublish_volume() { $output = drupal_get_form('epublish_form_volume'); return $output; } /** * epublish_save_volume: save changes to a publication volume * * @param $edit * an array of values to be saved * * @return * the same array */ function epublish_form_volume_submit($form_id, $edit) { if ($edit['action'] == 'delete') { epublish_del_volume($edit['pid'], $edit['volume']); } else { db_query("DELETE FROM {epublish_volume} WHERE pid = '%d' AND volume = '%d'", $edit['pid'], $edit['volume']); db_query("INSERT INTO {epublish_volume} (pid, volume, dateline) VALUES ('%d', '%d', '%s')", $edit['pid'], $edit['volume'], $edit['dateline']); drupal_set_message(t('The volume name "!title" has been updated.', array('!title' => $edit['dateline']))); } return 'admin/epublish'; } /** * epublish_del_volume: delete a publication volume name * * @param $edit * an array with the values specifying the volume to be deleted * * @return * A message stating that the volume has been deleted */ function epublish_del_volume($pid, $volume) { $publication = epublish_get_pub($pid); $vol = epublish_get_volume($pid, $volume); if (($_POST['op'] == t('Delete')) && ($_POST ['form_id'] == 'confirm_form' )) { db_query("DELETE FROM {epublish_volume} WHERE pid = '%d' AND volume = '%d'", $pid, $volume); drupal_set_message(t('Removed volume name "!volume" from publication "!publication."', array('!volume' => $vol->dateline, '!publication' => $publication->name))); drupal_goto("admin/epublish"); } else { return drupal_get_form('confirm_form', array('pid' => array( '#type' => hidden,'#value' => $pid), 'volume' => array( '#type' => hidden, '#value' => $volume)), t('Are you sure you want to remove volume name !volume from publication !publication?', array('!volume' => $vol->dateline, '!publication' => $publication->name)), 'admin/epublish', t('This action cannot be undone.'), t('Delete'), t('Cancel'),'',''); } } /******************************************* * NODES ******************************************/ /** * epublish_get_edition_nodes: get a list of nodes from an edition * * @param $eid * An edition ID * * @return * An array containing all of the node IDs from that edition */ function epublish_get_edition_nodes($eid) { $result = db_query(db_rewrite_sql("SELECT v.vid, v.nid FROM {node_revisions} v LEFT JOIN {epublish_edition_node} een ON v.vid = een.vid LEFT JOIN {node} n ON v.nid = n.nid WHERE een.eid='%d' AND n.status='1' ORDER BY n.sticky DESC, n.created DESC"), $eid); while ($node = db_fetch_object($result)) { $nodes[] = $node->vid; } return $nodes; } /** * epublish_add_node: add a node to an edition * * @param $eid * An edition ID * @param $nid * A node ID */ function epublish_add_node($eid, $nid, $vid, $weight=0, $tid=0) { epublish_del_node($eid, $nid, $vid); db_query("INSERT INTO {epublish_edition_node} (eid, nid, weight, tid, vid) VALUES ('%d', '%d', '%d', '%d', '%d')", $eid, $nid, $weight, $tid, $vid); } /** * epublish_del_node: delete a node from an edition * * @param $eid * An edition ID * @param $nid * A node ID */ function epublish_del_node($eid, $nid, $vid) { db_query("DELETE FROM {epublish_edition_node} WHERE eid = '%d' AND nid = '%d' AND vid = '%d'", $eid, $nid, $vid); } /** * epublish_admin_node: generate the form for adding nodes to editions * * @param $edit * an array of values to be saved */ function epublish_admin_node_head() { $output = drupal_get_form('epublish_admin_node'); return $output; } function epublish_admin_node() { $eid = arg(3); $filter = arg(4) ? arg(4) : 0; $edition = epublish_get_edition($eid); $sid = epublish_assign_section($edition); $form['eid'] = array( '#type' => 'hidden', '#value' => $eid, ); $publication = epublish_get_pub($edition->pid); $exclusions = _epublish_build_node_exclusions(epublish_get_edition_nodes($eid)); $filters[] = array(t('View posts that are new or updated'), "WHERE $exclusions ORDER BY n.changed DESC"); $filters[] = array(t('View posts that need approval'), "WHERE ($exclusions) AND (n.status = 0 OR n.moderate = 1) ORDER BY n.changed DESC"); $filters[] = array(t('View posts that are promoted'), "WHERE ($exclusions) AND (n.status = 1 AND n.promote = 1) ORDER BY n.changed DESC"); $filters[] = array(t('View posts that are not promoted'), "WHERE ($exclusions) AND (n.status = 1 AND n.promote = 0) ORDER BY n.changed DESC"); $filters[] = array(t('View posts that are sticky'), "WHERE ($exclusions) AND (n.status = 1 AND n.sticky = 1) ORDER BY n.changed DESC"); $filters[] = array(t('View posts that are unpublished'), "WHERE ($exclusions) AND (n.status = 0 AND n.moderate = 0) ORDER BY n.changed DESC"); // Render filter form: $options = array(); foreach ($filters as $key => $value) { $options[] = $value[0]; } $form[] = array('#value' => "
    \n"); $form['filter'] = array( '#type' => 'select', '#title' => t('Filter options'), '#default_value' => $filter, '#options' => $options, ); $form[] = array( '#type' => 'submit', '#value' => t('Filter'), ); $form[] = array('#value' => '
    '); $result = pager_query("SELECT DISTINCT (v.vid), v.nid, v.title, n.changed, n.type, n.status FROM {node_revisions} v LEFT JOIN {node} n ON v.nid = n.nid ". $filters[$filter][1], 50); // Make sure the update controls are disabled if we don't have any rows to select from. $disabled = !db_num_rows($result); $form['op'] = array( '#type' => 'submit', '#value' => t('Add checked items to this edition'), '#attributes' => ($disabled ? array('disabled' => 'disabled') : array()), ); while ($node = db_fetch_object($result)) { $nodes[$node->vid] = ''; $node->tid = 0; $node->weight = 0; $topics = epublish_topic_selection_list($sid); $sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d"; $count = db_num_rows(db_query($sql_count, $node->nid)); if ($count > 1) { $form['title'][$node->vid] = array('#value' => l($node->title, 'node/'. $node->nid .'/revisions/'. $node->vid .'/view') .' '. theme('mark', node_mark($node->nid, $node->changed))); } else { $form['title'][$node->vid] = array('#value' => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed))); } $form['name'][$node->vid] = array('#value' => node_get_types('name', $node)); $form['tid']['tid_' . $node->vid] = array('#type' => 'select', '#default_value' => $node->tid, '#options' => $topics, '#attributes' => array('onchange'=>'onChangeTID(' . $node->vid . ')')); $form['status'][$node->vid] = array('#value' => ($node->status ? t('published') : t('not published'))); $form['weight']['weight_' . $node->vid] = array('#type' => 'weight', '#default_value' => $node->weight, '#delta' => 30, '#attributes' => array('onchange'=>'onChangeWeight(' . $node->vid . ')')); } $form['nodes'] = array('#type' => 'checkboxes', '#options' => $nodes); $form['pager'] = array('#value' => theme('pager', NULL, 50, 0)); $form[] = array('#value' => '

    ' . $filters[$filter][0] . '

    '); drupal_set_title(t('Add Posts to !pub', array('!pub' => "$publication->name, " . theme('epublish_edition_reference', $edition)))); return $form; } function epublish_headlines() {//TODO another mystery function??? $output = drupal_get_form('epublish_admin_node'); return $output; } function theme_epublish_admin_node($form) { // create the headlines table if (isset($form['title']) && is_array($form['title'])) { $rows = array(); foreach (element_children($form['title']) as $key) { $row = array(); $row[] = drupal_render($form['nodes'][$key]); $row[] = drupal_render($form['title'][$key]); $row[] = drupal_render($form['name'][$key]); $row[] = drupal_render($form['tid']['tid_' . $key]); $row[] = drupal_render($form['status'][$key]); $row[] = drupal_render($form['weight']['weight_' . $key]); $rows[] = $row; } } else { $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '6')); } // Overview table: $header = array(NULL, t('Title'), t('Topic'), t('Type'), t('Status'), t('Weight')); $output = theme('table', $header, $rows); if ($form['pager']['#value']) { $output .= drupal_render($form['pager']); } // put the headlines table below the rest of the form content $output = drupal_render($form) . $output; return $output; } function epublish_admin_node_submit($form_id, $edit) { $op = $_POST['op']; if ($op == t('Add checked items to this edition') && isset($edit['nodes'])) { $nodes_added = 0; foreach ($edit['nodes'] as $vid => $checked) { if ($checked) { $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d"; $nid = db_fetch_object(db_query($sql, $vid)); epublish_add_node($edit['eid'], $nid->nid, $vid, $edit['weight_' . $vid], $edit['tid_' . $vid]); $nodes_added++; } } if ($nodes_added) { drupal_set_message(format_plural($nodes_added, 'One headline was added to this edition.', '@count headlines were added to this edition.')); } else { drupal_set_message(t('The update has been performed.')); } return 'admin/epublish/edit/edition/' . $edit['eid']; } return 'admin/epublish/headlines/' . $edit['eid'] . '/' . $edit['filter']; } /** * epublish_get_term: get a taxonomy term or a pseudo-term for "miscellaneous" or "top stories" * * @param $tid * a topic ID * @param $vid * a vocabulary ID * * @return * A term object */ function epublish_get_term($tid, $sid) { if ($tid > 0) { return module_invoke('taxonomy', 'get_term', $tid); } $section = epublish_get_section($sid); $vid = $section->vid; if ($tid == -2) { $term = db_fetch_object(db_query("SELECT vid FROM {vocabulary} WHERE vid = '%d'", $vid)); $term->name = variable_get('epublish_advertisement', t('advertisement')); } else if ($tid == -1) { $term = db_fetch_object(db_query("SELECT vid FROM {vocabulary} WHERE vid = '%d'", $vid)); $term->name = variable_get('epublish_top_stories', t('top stories')); } else { $term = db_fetch_object(db_query("SELECT vid FROM {vocabulary} WHERE vid = '%d'", $vid)); $term->name = variable_get('epublish_miscellaneous', t('miscellaneous')); } $term->tid = $tid; return $term; } /** * _epublish_build_node_inclusions: internal function that builds a set of SQL conditions for * specifying which node types should be included in a query. * * @param $node_types * An array of node types to include * * @return * The SQL conditions that should appear in the WHERE clause of a SELECT statement. */ function _epublish_build_node_inclusions($node_types = array()) { if (count($node_types)) { return " n.type='" . implode("' OR n.type='", $node_types) . "'"; } else { return " n.type=n.type"; } } /** * _epublish_build_node_exclusions: internal function that builds a set of SQL conditions for * specifying which nodes should be excluded in a query. * * @param $nodes * An array of nodes to include * * @return * The SQL conditions that should appear in the WHERE clause of a SELECT statement. */ function _epublish_build_node_exclusions($nodes = array()) { if (count($nodes)) { return 'v.vid!=' . implode(' AND v.vid!=', $nodes); } else { return 'v.vid!=0'; } } /** * epublish_topic_terms: get a list of taxonomy terms encompassed by a topic * * @param $tid * A term ID number * @param $sid * A section ID number * * @return * An associative array of the term IDs and their names. */ function _epublish_topic_term_inclusions($tid, $sid) { $terms = array(); if ($tid > 0) { $terms[] = $tid; $section = epublish_get_section($sid); $tree = module_invoke('taxonomy', 'get_tree', $section->vid, $tid); if ($tree) { foreach ($tree as $term) { $terms[] = $term->tid; } } } return 'tn.tid=' . implode(' OR tn.tid =', $terms); } function _epublish_topics_node_count(&$topics) { $count = 0; foreach ($topics as $topic) { $count += count($topic->nodes); } return $count; } /** * Prepares both the custom breadcrumb trail and the forward/backward * navigation for a node presented as part of an epublish edition. * * @ingroup themeable */ function theme_epublish_navigation($node, $eid) { if ($node->nid) { $og = variable_get('epublish_og', 0); $output .= '
    '; $edition = epublish_get_edition($eid); $publication = epublish_get_pub($edition->pid); $sid = epublish_assign_section($edition); $topics = epublish_section_topics($sid, $edition->eid); $topic = current($topics); $vid = current($topic->nodes); $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d"; $nid = db_fetch_object(db_query($sql, $vid)); $sql2 = "SELECT group_nid FROM {og_ancestry} WHERE nid = %d"; $group = db_fetch_object(db_query($sql2, $nid->nid)); $gid = $group->group_nid; // Construct the breadcrumb: $node->breadcrumb = array(); if ($og == 1) { $node->breadcrumb[] = array('path' => "og/epublish/$gid/$publication->pid", 'title' => $publication->name); $node->breadcrumb[] = array('path' => "og/epublish/$gid/$edition->pid/$edition->eid", 'title' => theme('epublish_edition_reference', $edition)); } else { $node->breadcrumb[] = array('path' => "epublish/$publication->pid", 'title' => $publication->name); $node->breadcrumb[] = array('path' => "epublish/$edition->pid/$edition->eid", 'title' => theme('epublish_edition_reference', $edition)); } $sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d"; $count = db_num_rows(db_query($sql_count, $node->nid)); if ($count > 1) { $node->breadcrumb[] = array('path' => "node/$node->nid/revisions/$node->vid/view", 'title' => $node->title); } else { $node->breadcrumb[] = array('path' => "node/$node->nid", 'title' => $node->title); } menu_set_location($node->breadcrumb); if ($prev = epublish_prev($node, $topics)) { $sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d"; $count = db_num_rows(db_query($sql_count, $prev->nid)); if ($count > 1) { $links[] = "Previous story: " . l($prev->title, 'node/'. $prev->nid .'/revisions/'. $prev->vid .'/view'); } else { $links[] = "Previous story: " . l($prev->title, 'node/'. $prev->nid); } } if ($next = epublish_next($node, $topics)) { $sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d"; $count = db_num_rows(db_query($sql_count, $next->nid)); if ($count > 1) { $links[] = "Next story: " . l($next->title, 'node/'. $next->nid .'/revisions/'. $next->vid .'/view'); } else { $links[] = "Next story: " . l($next->title, 'node/'. $next->nid); } } if ($og == 1) { $output .= "

    Published in " . l("$publication->name", "og/epublish/$gid/$publication->pid") .", ". l(theme('epublish_edition_reference', $edition), "og/epublish/$gid/$publication->pid/$edition->eid") ."


    \n"; } else { $output .= "

    Published in " . l("$publication->name", "epublish/$publication->pid") .", ". l(theme('epublish_edition_reference', $edition), "epublish/$publication->pid/$edition->eid") ."


    \n"; } $output .= theme('item_list', $links); $output .= '
    '; } $node->content['body']['#value'] = $node->body.$output; return $node; } function epublish_prev($node, $topics) { $prev_vid = NULL; foreach ($topics as $topic) { foreach ($topic->nodes as $vid) { if ($vid == $node->vid) { $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d"; $nid = db_fetch_object(db_query($sql, $prev_vid)); return $prev_vid ? node_load($nid, $prev_vid) : $prev_vid; } $prev_vid = $vid; } } } function epublish_next($node, $topics) { $next_vid = false; foreach ($topics as $topic) { foreach ($topic->nodes as $vid) { if ($next_vid) { $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d"; $nid = db_fetch_object(db_query($sql, $vid)); return node_load($nid, $vid); } if ($vid == $node->vid) { $next_vid = true; } } } return NULL; } ?>