--- webcomic.module 2006-04-20 10:23:48.000000000 +0300 +++ webcomic-5.x-0.x-dev.module 2007-12-03 00:54:33.000000000 +0200 @@ -2,25 +2,17 @@ // $Id: webcomic.module,v 1.10 2006/04/20 07:23:48 chx Exp $ include_once(drupal_get_path('module', 'webcomic') . '/webcomic_theme.inc'); -if (module_exist('views')) { - include_once(drupal_get_path('module', 'webcomic') . '/webcomic_views.inc'); -} +// if (module_exists('views')) { +// include_once(drupal_get_path('module', 'webcomic') . '/webcomic_views.inc'); +// } /** * Implementation of hook_help */ function webcomic_help($section) { switch ($section) { - case 'admin/modules#description': + case 'admin/help#webcomic': return t('Provides content types and tools for managing a webcomic'); - case 'node/add#webcomic_strip': - return t('A single comic strip image.'); - case 'node/add#webcomic_character': - return t('A biography for a comic character.'); - case 'node/add#webcomic_episode': - return t('A comic episode containing multiple strips (for example, an issue of a graphic novel).'); - case 'node/add#webcomic_storyline': - return t('A comic storyline containing one or more episodes.'); } } @@ -29,10 +21,26 @@ function webcomic_help($section) { */ function webcomic_node_info() { return array( - 'webcomic_strip' => array('name' => t('strip'), 'base' => 'webcomic_content'), - 'webcomic_character' => array('name' => t('character bio'), 'base' => 'webcomic_character'), - 'webcomic_episode' => array('name' => t('episode'), 'base' => 'webcomic_content'), - 'webcomic_storyline' => array('name' => t('storyline'), 'base' => 'webcomic_content'), + 'webcomic_strip' => array( + 'name' => t('Strip'), + 'module' => 'webcomic', + 'description' => t('A single comic strip image.'), + ), + 'webcomic_character' => array( + 'name' => t('Character bio'), + 'module' => 'webcomic', + 'description' => t('A biography for a comic character.'), + ), + 'webcomic_episode' => array( + 'name' => t('Episode'), + 'module' => 'webcomic', + 'description' => t('A comic episode containing multiple strips (for example, an issue of a graphic novel).'), + ), + 'webcomic_storyline' => array( + 'name' => t('Storyline'), + 'module' => 'webcomic', + 'description' => t('A comic storyline containing one or more episodes.'), + ), ); } @@ -41,26 +49,16 @@ function webcomic_node_info() { */ function webcomic_perm() { return array( - 'administer webcomic system', + 'administer webcomic', ); } /** * Implementation of hook_access */ -function webcomic_content_access($op, $node) { +function webcomic_access($op, $node) { global $user; - if (user_access('administer comic system')) { - return TRUE; - } -} - -/** - * Implementation of hook_access - */ -function webcomic_character_access($op, $node) { - global $user; - if (user_access('administer comic system')) { + if (user_access('administer webcomic')) { return TRUE; } } @@ -70,29 +68,24 @@ function webcomic_character_access($op, */ function webcomic_menu($may_cache) { $items = array(); - if ($may_cache) { - $items[] = array( - 'path' => 'node/add/webcomic_strip', 'title' => t('strip'), - 'type' => MENU_NORMAL_ITEM); - $items[] = array( - 'path' => 'node/add/webcomic_episode', 'title' => t('episode'), - 'type' => MENU_NORMAL_ITEM); - $items[] = array( - 'path' => 'node/add/webcomic_storyline', 'title' => t('storyline'), - 'type' => MENU_NORMAL_ITEM); - $items[] = array( - 'path' => 'node/add/webcomic_character', 'title' => t('character'), - 'type' => MENU_NORMAL_ITEM); + $items[] = array( + 'path' => 'admin/settings/webcomic', + 'title' => t('Webcomic'), + 'description' => t('Webcomic settings.'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('webcomic_admin_settings'), + 'access' => user_access('administer site configuration'), + 'type' => MENU_NORMAL_ITEM, + ); } return $items; } - /** * Implementation of hook_settings */ -function webcomic_settings() { +function webcomic_admin_settings() { $form['webcomic_discussions'] = array( '#type' => 'radios', '#title' => t('Discussions'), @@ -167,50 +160,63 @@ function webcomic_settings() { ), '#description' => t('How should each item in your archive be displayed?'), ); - return $form; + return system_settings_form($form); } -function webcomic_character_form($node) { - $form['title'] = array('#type' => 'textfield', - '#title' => t('Name'), - '#required' => TRUE, - '#default_value' => $node->title, - '#weight' => -5, - ); - - $form['body_filter']['body'] = array('#type' => 'textarea', - '#title' => t('Character bio'), - '#default_value' => $node->body, - '#rows' => 10, - '#required' => TRUE, - ); - $form['body_filter']['format'] = filter_form($node->format); +function webcomic_form($node) { + if ($node->type == 'webcomic_character') { + $form['title'] = array( + '#type' => 'textfield', + '#title' => t('Name'), + '#required' => TRUE, + '#default_value' => $node->title, + '#weight' => -5, + ); - return $form; -} + $form['body_filter']['body'] = array( + '#type' => 'textarea', + '#title' => t('Character bio'), + '#default_value' => $node->body, + '#rows' => 10, + '#required' => TRUE, + ); + $form['body_filter']['format'] = filter_form($node->format); -function webcomic_content_form($node) { - $form['title'] = array('#type' => 'textfield', + return $form; + } + + $form['title'] = array( + '#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5, ); - + /* $form['#attributes'] = array("enctype" => "multipart/form-data"); - $sizes = _image_get_sizes(); $form['images']['#tree'] = TRUE; - $form['images']['_original'] = array('#type' => 'hidden', '#value' => $form['images']['_original']); + $form['images']['_original'] = array( + '#type' => 'hidden', + '#value' => $form['images']['_original'] + ); + $sizes = _image_get_sizes(); foreach ($sizes as $size) { if ($node->new_file) { - $form['images'][$size['label']] = array('#type' => 'hidden', '#value' => $node->images[$size['label']]); + $form['images'][$size['label']] = array( + '#type' => 'hidden', + '#value' => $node->images[$size['label']] + ); } else { - $form['images'][$size['label']] = array('#type' => 'hidden', '#default_value' => $node->images[$size['label']]); + $form['images'][$size['label']] = array( + '#type' => 'hidden', + '#default_value' => $node->images[$size['label']] + ); } - } + }*/ - $form['thumbnail']['#after_build'] = array('webcomic_form_add_thumbnail'); + // $form['thumbnail']['#after_build'][] = array('webcomic_form_add_thumbnail'); + $form['#attributes'] = array("enctype" => "multipart/form-data"); $form['image'] = array( '#type' => 'file', '#title' => t('Image'), @@ -231,7 +237,8 @@ function webcomic_content_form($node) { break; } if (count($parent_list) > 1) { - $form['parent_nid'] = array('#type' => 'select', + $form['parent_nid'] = array( + '#type' => 'select', '#title' => $parent_title, '#default_value' => $node->parent_nid, '#options' => $parent_list, @@ -246,7 +253,7 @@ function webcomic_content_form($node) { '#maxlength' => 25, '#weight' => 6, '#default_value' => $node->publish_date, - '#description' => t('Used to delay publishing of content. Leave blank for normal behavior. Format: %time. ', array('%time' => $node->date)), + '#description' => t('Used to delay publishing of content. Leave blank for normal behavior. Format: !time. ', array('!time' => $node->date)), ); $form['storyline_date'] = array( @@ -255,7 +262,7 @@ function webcomic_content_form($node) { '#maxlength' => 25, '#weight' => 7, '#default_value' => $node->storyline_date, - '#description' => t('Used to organize webcomic content that follows a custom timeline, or when strips are posted out of order. Format: %time. ', array('%time' => $node->date)), + '#description' => t('Used to organize webcomic content that follows a custom timeline, or when strips are posted out of order. Format: !time. ', array('!time' => $node->date)), ); switch ($node->type) { @@ -294,7 +301,8 @@ function webcomic_content_form($node) { } } - $form['body_filter']['body'] = array('#type' => 'textarea', + $form['body_filter']['body'] = array( + '#type' => 'textarea', '#title' => t('Description'), '#default_value' => $node->body, '#rows' => 10, @@ -324,28 +332,30 @@ function webcomic_form_add_thumbnail($fo /** * Implementation of hook_load(). */ -function webcomic_content_load(&$node) { - // basic webcomic data - $content = db_fetch_object(db_query('SELECT * FROM {webcomic_content} WHERE nid = %d', $node->nid)); - if ($content->publish_timestamp != 0) { - $content->publish_date = format_date($content->publish_timestamp, 'custom', 'Y-m-d H:i:s O'); - } - if ($content->storyline_timestamp != 0) { - $content->storyline_date = format_date($content->storyline_timestamp, 'custom', 'Y-m-d H:i:s O'); - } - - // image loading - image_load($node); - - // parent relationships - $parent = db_fetch_object(db_query('SELECT * FROM {webcomic_parent} WHERE child_nid = %d', $node->nid)); - $content->parent_nid = $parent->parent_nid; - - // character associations - if ($node->type == 'webcomic_strip') { - $result = db_query('SELECT * FROM {webcomic_strip_character} WHERE strip_nid = %d', $nid); - while ($strip_char = db_fetch_object($result)) { - $content->characters[] = $strip_char->character_nid; +function webcomic_load(&$node) { + if ($node->type == 'webcomic_storyline' || $node->type == 'webcomic_episode' || $node->type == 'webcomic_strip') { + // basic webcomic data + $content = db_fetch_object(db_query('SELECT * FROM {webcomic_content} WHERE nid = %d', $node->nid)); + if ($content->publish_timestamp != 0) { + $content->publish_date = format_date($content->publish_timestamp, 'custom', 'Y-m-d H:i:s O'); + } + if ($content->storyline_timestamp != 0) { + $content->storyline_date = format_date($content->storyline_timestamp, 'custom', 'Y-m-d H:i:s O'); + } + + // image loading + image_load($node); + + // parent relationships + $parent = db_fetch_object(db_query('SELECT * FROM {webcomic_parent} WHERE child_nid = %d', $node->nid)); + $content->parent_nid = $parent->parent_nid; + + // character associations + if ($node->type == 'webcomic_strip') { + $result = db_query('SELECT * FROM {webcomic_strip_character} WHERE strip_nid = %d', $node->nid); + while ($strip_char = db_fetch_object($result)) { + $content->characters[] = $strip_char->character_nid; + } } } @@ -355,20 +365,22 @@ function webcomic_content_load(&$node) { /** * Implementation of hook_insert(). */ -function webcomic_content_insert($node) { - db_query("INSERT INTO {webcomic_content} (nid, publish_timestamp, storyline_timestamp, weight, sequence) VALUES (%d, %d, %d, %d, '%s')", $node->nid, $node->publish_timestamp, $node->storyline_timestamp, $node->weight, $node->sequence); - if (isset($node->parent_nid)) { - db_query("INSERT INTO {webcomic_parent} (child_nid, parent_nid) VALUES (%d, %d)", $node->nid, $node->parent_nid); - } - if (function_exists('image_prepare') && function_exists('image_insert')) { - image_prepare($node, 'image'); - if($node->images['_original'] != '') { - image_insert($node); - } - } - if ($node->type == 'webcomic_strip' && is_array($node->characters)) { - foreach($node->characters as $char_nid) { - db_query("INSERT INTO {webcomic_strip_character} (strip_nid, character_nid) VALUES (%d, %d)", $node->nid, $char_nid); +function webcomic_insert($node) { + if ($node->type == 'webcomic_storyline' || $node->type == 'webcomic_episode' || $node->type == 'webcomic_strip') { + db_query("INSERT INTO {webcomic_content} (nid, publish_timestamp, storyline_timestamp, weight, sequence) VALUES (%d, %d, %d, %d, '%s')", $node->nid, $node->publish_timestamp, $node->storyline_timestamp, $node->weight, $node->sequence); + if (isset($node->parent_nid)) { + db_query("INSERT INTO {webcomic_parent} (child_nid, parent_nid) VALUES (%d, %d)", $node->nid, $node->parent_nid); + } + if (function_exists('image_prepare') && function_exists('image_insert')) { + image_prepare($node, 'image'); + if($node->images['_original'] != '') { + image_insert($node); + } + } + if ($node->type == 'webcomic_strip' && is_array($node->characters)) { + foreach($node->characters as $char_nid) { + db_query("INSERT INTO {webcomic_strip_character} (strip_nid, character_nid) VALUES (%d, %d)", $node->nid, $char_nid); + } } } } @@ -376,25 +388,27 @@ function webcomic_content_insert($node) /** * Implementation of hook_update(). */ -function webcomic_content_update($node) { - db_query("UPDATE {webcomic_content} SET publish_timestamp = %d, storyline_timestamp = %d, weight = %d, sequence = '%s' WHERE nid = %d", $node->publish_timestamp, $node->storyline_timestamp, $node->weight, $node->sequence, $node->nid); - db_query("DELETE FROM {webcomic_parent} WHERE child_nid = %d", $node->nid); - db_query("DELETE FROM {webcomic_strip_character} WHERE strip_nid = %d", $node->nid); - - if (isset($node->parent_nid)) { - db_query("INSERT INTO {webcomic_parent} (child_nid, parent_nid) VALUES (%d, %d)", $node->nid, $node->parent_nid); - } - if ($node->type == 'webcomic_strip' && is_array($node->characters)) { - foreach($node->characters as $char_nid) { - db_query("INSERT INTO {webcomic_strip_character} (strip_nid, character_nid) VALUES (%d, %d)", $node->nid, $char_nid); - } - } - - if (function_exists('image_prepare') && function_exists('image_update')) { - image_prepare($node, 'image'); - //print_r($node, FALSE); - if($node->images[_original] != '') { - image_update($node); +function webcomic_update($node) { + if ($node->type == 'webcomic_storyline' || $node->type == 'webcomic_episode' || $node->type == 'webcomic_strip') { + db_query("UPDATE {webcomic_content} SET publish_timestamp = %d, storyline_timestamp = %d, weight = %d, sequence = '%s' WHERE nid = %d", $node->publish_timestamp, $node->storyline_timestamp, $node->weight, $node->sequence, $node->nid); + db_query("DELETE FROM {webcomic_parent} WHERE child_nid = %d", $node->nid); + db_query("DELETE FROM {webcomic_strip_character} WHERE strip_nid = %d", $node->nid); + + if (isset($node->parent_nid)) { + db_query("INSERT INTO {webcomic_parent} (child_nid, parent_nid) VALUES (%d, %d)", $node->nid, $node->parent_nid); + } + if ($node->type == 'webcomic_strip' && is_array($node->characters)) { + foreach($node->characters as $char_nid) { + db_query("INSERT INTO {webcomic_strip_character} (strip_nid, character_nid) VALUES (%d, %d)", $node->nid, $char_nid); + } + } + + if (function_exists('image_prepare') && function_exists('image_update')) { + image_prepare($node, 'image'); + //print_r($node, FALSE); + if($node->images[_original] != '') { + image_update($node); + } } } } @@ -402,42 +416,44 @@ function webcomic_content_update($node) /** * Implementation of hook_delete(). */ -function webcomic_content_delete(&$node) { - db_query('DELETE FROM {webcomic_content} WHERE nid = %d', $node->nid); - db_query('DELETE FROM {webcomic_parent} WHERE child_nid = %d OR parent_nid = %d', $node->nid, $node->nid); - db_query('DELETE FROM {webcomic_strip_character} WHERE strip_nid = %d', $node->nid); - - foreach ($node->images as $label => $image) { - file_delete(file_create_path($image)); - db_query("DELETE FROM {files} WHERE filename='%s' AND nid=%d", $label, $node->nid); +function webcomic_delete(&$node) { + if ($node->type == 'webcomic_character') { + db_query('DELETE FROM {webcomic_strip_character} WHERE character_nid = %d', $node->nid); + } else { + db_query('DELETE FROM {webcomic_content} WHERE nid = %d', $node->nid); + db_query('DELETE FROM {webcomic_parent} WHERE child_nid = %d OR parent_nid = %d', $node->nid, $node->nid); + db_query('DELETE FROM {webcomic_strip_character} WHERE strip_nid = %d', $node->nid); + + foreach ($node->images as $label => $image) { + file_delete(file_create_path($image)); + db_query("DELETE FROM {files} WHERE filename='%s' AND nid=%d", $label, $node->nid); + } } } -function webcomic_character_delete(&$node) { - db_query('DELETE FROM {webcomic_strip_character} WHERE character_nid = %d', $node->nid); -} - /** * Implementation of hook_submit(). */ -function webcomic_content_submit(&$node) { - // If a publish date has been set, and is in the future, override the publish flag - // otherwise, set the publish date to the created date - if ($node->publish_date != '') { - $node->publish_timestamp = strtotime($node->publish_date); - if ($node->publish_timestamp > time()) { - // unpublish the node. It shouldn't be visible! - $node->status = 0; +function webcomic_submit(&$node) { + if ($node->type == 'webcomic_storyline' || $node->type == 'webcomic_episode' || $node->type == 'webcomic_strip') { + // If a publish date has been set, and is in the future, override the publish flag + // otherwise, set the publish date to the created date + if ($node->publish_date != '') { + $node->publish_timestamp = strtotime($node->publish_date); + if ($node->publish_timestamp > time()) { + // unpublish the node. It shouldn't be visible! + $node->status = 0; + } + } + else { + $node->publish_timestamp = $node->created; + } + if ($node->storyline_date != '') { + $node->storyline_timestamp = strtotime($node->storyline_timestamp); } - } - else { - $node->publish_timestamp = $node->created; - } - if ($node->storyline_date != '') { - $node->storyline_timestamp = strtotime($node->storyline_timestamp); - } - $node->sequence = _webcomic_generate_sequence($node); + $node->sequence = _webcomic_generate_sequence($node); + } } function _webcomic_list_type($type = NULL) { @@ -535,7 +551,7 @@ function webcomic_cron() { /** * Implementation of hook_view */ -function webcomic_content_view(&$node, $teaser = 0, $page = 0) { +function webcomic_view(&$node, $teaser = 0, $page = 0) { if ($page && $node->parent_nid) { $episode = node_load($node->parent_nid); $breadcrumb = array(); @@ -548,14 +564,17 @@ function webcomic_content_view(&$node, $ } $node = node_prepare($node, $teaser); - $node->teaser = theme('webcomic_teaser', $node); + $nav = theme('webcomic_navigation', $node); - $node->body = $nav . theme('webcomic_body', $node, 'preview') . $nav; + + $node->content['teaser']['#value'] = theme('webcomic_teaser', $node); + $node->content['body']['#value'] = $nav; + $node->content['body']['#value'] .= theme('webcomic_body', $node, 'preview'); + $node->content['body']['#value'] .= $nav; + + return $node; } - - - function webcomic_update_sequences() { $result = db_query('SELECT nid FROM {webcomic_content}'); while ($nid = db_fetch_object($result)) { @@ -589,7 +608,8 @@ function webcomic_first($node) { $first = db_fetch_object($result); if ($first->nid != $node->nid) { return $first; - }} + } +} function webcomic_prev($node) { switch (variable_get('webcomic_browsing_style', 'all_images')) {