| 1 |
<?php
|
| 2 |
// $Id: webcomic.module,v 1.10 2006/04/20 07:23:48 chx Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Provides content types and tools for managing a webcomic.
|
| 7 |
*/
|
| 8 |
|
| 9 |
include_once(drupal_get_path('module', 'webcomic') .'/webcomic_theme.inc');
|
| 10 |
if (module_exists('views')) {
|
| 11 |
include_once(drupal_get_path('module', 'webcomic') .'/webcomic_views.inc');
|
| 12 |
}
|
| 13 |
|
| 14 |
/**
|
| 15 |
* Implementation of hook_help().
|
| 16 |
*/
|
| 17 |
function webcomic_help($section) {
|
| 18 |
switch ($section) {
|
| 19 |
case 'admin/help#webcomic':
|
| 20 |
return '<p>'. t('Provides content types and tools for managing a webcomic.') .'</p>';
|
| 21 |
}
|
| 22 |
}
|
| 23 |
|
| 24 |
/**
|
| 25 |
* Implementation of hook_node_info().
|
| 26 |
*/
|
| 27 |
function webcomic_node_info() {
|
| 28 |
return array(
|
| 29 |
'webcomic_strip' => array(
|
| 30 |
'name' => t('Strip'),
|
| 31 |
'module' => 'webcomic',
|
| 32 |
'description' => t('A single comic strip image.'),
|
| 33 |
),
|
| 34 |
'webcomic_character' => array(
|
| 35 |
'name' => t('Character bio'),
|
| 36 |
'module' => 'webcomic',
|
| 37 |
'description' => t('A biography for a comic character.'),
|
| 38 |
),
|
| 39 |
'webcomic_episode' => array(
|
| 40 |
'name' => t('Episode'),
|
| 41 |
'module' => 'webcomic',
|
| 42 |
'description' => t('A comic episode containing multiple strips (for example, an issue of a graphic novel).'),
|
| 43 |
),
|
| 44 |
'webcomic_storyline' => array(
|
| 45 |
'name' => t('Storyline'),
|
| 46 |
'module' => 'webcomic',
|
| 47 |
'description' => t('A comic storyline containing one or more episodes.'),
|
| 48 |
),
|
| 49 |
);
|
| 50 |
}
|
| 51 |
|
| 52 |
/**
|
| 53 |
* Implementation of hook_perm().
|
| 54 |
*/
|
| 55 |
function webcomic_perm() {
|
| 56 |
return array('administer webcomic');
|
| 57 |
}
|
| 58 |
|
| 59 |
/**
|
| 60 |
* Implementation of hook_access().
|
| 61 |
*/
|
| 62 |
function webcomic_access($op, $node) {
|
| 63 |
global $user;
|
| 64 |
if (user_access('administer webcomic')) {
|
| 65 |
return TRUE;
|
| 66 |
}
|
| 67 |
}
|
| 68 |
|
| 69 |
/**
|
| 70 |
* Implementation of hook_menu().
|
| 71 |
*/
|
| 72 |
function webcomic_menu($may_cache) {
|
| 73 |
$items = array();
|
| 74 |
if ($may_cache) {
|
| 75 |
$items[] = array(
|
| 76 |
'path' => 'admin/settings/webcomic',
|
| 77 |
'title' => t('Webcomic'),
|
| 78 |
'description' => t('Webcomic settings.'),
|
| 79 |
'callback' => 'drupal_get_form',
|
| 80 |
'callback arguments' => array('webcomic_admin_settings'),
|
| 81 |
'access' => user_access('administer site configuration') || user_access('administer webcomic'),
|
| 82 |
'type' => MENU_NORMAL_ITEM,
|
| 83 |
);
|
| 84 |
}
|
| 85 |
|
| 86 |
return $items;
|
| 87 |
}
|
| 88 |
|
| 89 |
/**
|
| 90 |
* Menu callback; Webcomic administration page
|
| 91 |
*/
|
| 92 |
function webcomic_admin_settings() {
|
| 93 |
$form['webcomic_discussions'] = array(
|
| 94 |
'#type' => 'radios',
|
| 95 |
'#title' => t('Discussions'),
|
| 96 |
'#default_value' => variable_get('webcomic_discussions', 'normal'),
|
| 97 |
'#options' => array(
|
| 98 |
'normal' => t('Default commenting on each strip, episode, and storyline'),
|
| 99 |
'storyline' => t('Provide a forum for each storyline'),
|
| 100 |
'episode' => t('Provide a forum for each episode'),
|
| 101 |
'strip' => t('Provide a forum for each strip'),
|
| 102 |
),
|
| 103 |
'#description' => t('Allows you to direct users to your site\'s discussion forums rather than commenting on each strip or episode. Requires forum.module.'),
|
| 104 |
);
|
| 105 |
|
| 106 |
$form['browsing'] = array(
|
| 107 |
'#type' => 'fieldset',
|
| 108 |
'#title' => t('Browsing settings')
|
| 109 |
);
|
| 110 |
$form['browsing']['webcomic_browsing_style'] = array(
|
| 111 |
'#type' => 'radios',
|
| 112 |
'#title' => t('Browsing style'),
|
| 113 |
'#default_value' => variable_get('webcomic_browsing_style', 'all_images'),
|
| 114 |
'#options' => array(
|
| 115 |
'like_kinds' => t('Next/Prev links show only the current type'),
|
| 116 |
'all_images' => t('Next/Prev links show storylines, episode, and comic strips'),
|
| 117 |
'episode_index' => t('Next/Prev links return to the index after each episode'),
|
| 118 |
'story_index' => t('Next/Prev links return to the index after each storyline'),
|
| 119 |
),
|
| 120 |
'#description' => t('Allows to change what content is shown when browsing webcomics.'),
|
| 121 |
);
|
| 122 |
$form['browsing']['webcomic_browsing_order'] = array(
|
| 123 |
'#type' => 'radios',
|
| 124 |
'#title' => t('Sort order'),
|
| 125 |
'#default_value' => variable_get('webcomic_browsing_order', 'publish_timestamp'),
|
| 126 |
'#options' => array(
|
| 127 |
'publish_timestamp' => t('Order by publish date'),
|
| 128 |
'storyline_timestampe' => t('Order by storyline date'),
|
| 129 |
'weight' => t('Order by sequence number'),
|
| 130 |
),
|
| 131 |
'#description' => t('Allows to change the order in which webcomic content is browsed and displayed.'),
|
| 132 |
);
|
| 133 |
|
| 134 |
$form['archive'] = array(
|
| 135 |
'#type' => 'fieldset',
|
| 136 |
'#title' => t('Archive settings')
|
| 137 |
);
|
| 138 |
$form['archive']['webcomic_archive_mode'] = array(
|
| 139 |
'#type' => 'radios',
|
| 140 |
'#title' => t('Archive organization'),
|
| 141 |
'#default_value' => variable_get('webcomic_archive_mode', 'strips_month'),
|
| 142 |
'#options' => array(
|
| 143 |
'strips' => t('A list of strips'),
|
| 144 |
'strips_month' => t('A list of strips, grouped by month'),
|
| 145 |
'strips_year' => t('A list of strips, grouped by year'),
|
| 146 |
'strips_episode' => t('A list of strips, grouped by episode'),
|
| 147 |
'episodes' => t('A list of episodes'),
|
| 148 |
'episodes_year' => t('A list of episodes, grouped by year'),
|
| 149 |
'episodes_storyline' => t('A list of episodes, grouped by storyline'),
|
| 150 |
'storylines' => t('A list of storylines'),
|
| 151 |
),
|
| 152 |
'#description' => t('How should your webcomic\'s archive be organized?'),
|
| 153 |
);
|
| 154 |
$form['archive']['webcomic_archive_view'] = array(
|
| 155 |
'#type' => 'radios',
|
| 156 |
'#title' => t('Archive presentation'),
|
| 157 |
'#default_value' => variable_get('webcomic_archive_view', 'list'),
|
| 158 |
'#options' => array(
|
| 159 |
'list' => t('List view (titles for each listed item)'),
|
| 160 |
'summary' => t('Summary view (teasers for each listed item)'),
|
| 161 |
'gallery' => t('Gallery view (a grid of thumbnails with titles)'),
|
| 162 |
),
|
| 163 |
'#description' => t('How should each item in your archive be displayed?'),
|
| 164 |
);
|
| 165 |
|
| 166 |
return system_settings_form($form);
|
| 167 |
}
|
| 168 |
|
| 169 |
function _webcomic_character_form($node) {
|
| 170 |
$form['title'] = array(
|
| 171 |
'#type' => 'textfield',
|
| 172 |
'#title' => t('Name'),
|
| 173 |
'#required' => TRUE,
|
| 174 |
'#default_value' => $node->title,
|
| 175 |
'#weight' => -5,
|
| 176 |
);
|
| 177 |
|
| 178 |
$form['body_filter']['body'] = array(
|
| 179 |
'#type' => 'textarea',
|
| 180 |
'#title' => t('Character bio'),
|
| 181 |
'#default_value' => $node->body,
|
| 182 |
'#rows' => 10,
|
| 183 |
'#required' => TRUE,
|
| 184 |
);
|
| 185 |
|
| 186 |
$form['body_filter']['format'] = filter_form($node->format);
|
| 187 |
|
| 188 |
return $form;
|
| 189 |
}
|
| 190 |
|
| 191 |
function _webcomic_content_form($node) {
|
| 192 |
$form['title'] = array(
|
| 193 |
'#type' => 'textfield',
|
| 194 |
'#title' => t('Title'),
|
| 195 |
'#required' => TRUE,
|
| 196 |
'#default_value' => $node->title,
|
| 197 |
'#weight' => -5,
|
| 198 |
);
|
| 199 |
|
| 200 |
$form['#attributes'] = array("enctype" => "multipart/form-data");
|
| 201 |
$form['images']['#tree'] = TRUE;
|
| 202 |
$form['images']['_original'] = array(
|
| 203 |
'#type' => 'hidden',
|
| 204 |
'#value' => $form['images']['_original']
|
| 205 |
);
|
| 206 |
$sizes = _image_get_sizes();
|
| 207 |
foreach ($sizes as $size) {
|
| 208 |
if ($node->new_file) {
|
| 209 |
$form['images'][$size['label']] = array(
|
| 210 |
'#type' => 'hidden',
|
| 211 |
'#value' => $node->images[$size['label']]
|
| 212 |
);
|
| 213 |
}
|
| 214 |
else {
|
| 215 |
$form['images'][$size['label']] = array(
|
| 216 |
'#type' => 'hidden',
|
| 217 |
'#default_value' => $node->images[$size['label']]
|
| 218 |
);
|
| 219 |
}
|
| 220 |
}
|
| 221 |
$form['thumbnail']['#after_build'][] = array('webcomic_form_add_thumbnail');
|
| 222 |
$form['image'] = array(
|
| 223 |
'#type' => 'file',
|
| 224 |
'#title' => t('Image'),
|
| 225 |
'#description' => t('Click "Browse..." to select an image to upload.'),
|
| 226 |
'#weight' => 1,
|
| 227 |
);
|
| 228 |
|
| 229 |
// For strips and episodes, include a parent-selector.
|
| 230 |
if ($node->type == 'webcomic_strip' || $node->type == 'webcomic_episode') {
|
| 231 |
switch ($node->type) {
|
| 232 |
case 'webcomic_strip':
|
| 233 |
$parent_list = _webcomic_list_type('webcomic_episode');
|
| 234 |
$parent_title = t('Episode');
|
| 235 |
break;
|
| 236 |
case 'webcomic_episode':
|
| 237 |
$parent_list = _webcomic_list_type('webcomic_storyline');
|
| 238 |
$parent_title = t('Storyline');
|
| 239 |
break;
|
| 240 |
}
|
| 241 |
if (count($parent_list) > 1) {
|
| 242 |
$form['parent_nid'] = array(
|
| 243 |
'#type' => 'select',
|
| 244 |
'#title' => $parent_title,
|
| 245 |
'#default_value' => $node->parent_nid,
|
| 246 |
'#options' => $parent_list,
|
| 247 |
'#weight' => 2,
|
| 248 |
);
|
| 249 |
}
|
| 250 |
}
|
| 251 |
|
| 252 |
$form['publish_date'] = array(
|
| 253 |
'#type' => 'textfield',
|
| 254 |
'#title' => t('Publish date'),
|
| 255 |
'#maxlength' => 25,
|
| 256 |
'#weight' => 6,
|
| 257 |
'#default_value' => $node->publish_date,
|
| 258 |
'#description' => t('Used to delay publishing of content. Leave blank for normal behavior. Format: !time. ', array('!time' => $node->date)),
|
| 259 |
);
|
| 260 |
|
| 261 |
$form['storyline_date'] = array(
|
| 262 |
'#type' => 'textfield',
|
| 263 |
'#title' => t('Plot date'),
|
| 264 |
'#maxlength' => 25,
|
| 265 |
'#weight' => 7,
|
| 266 |
'#default_value' => $node->storyline_date,
|
| 267 |
'#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)),
|
| 268 |
);
|
| 269 |
|
| 270 |
switch ($node->type) {
|
| 271 |
case 'webcomic_storyline':
|
| 272 |
$weight_title = t('Storyline number');
|
| 273 |
break;
|
| 274 |
case 'webcomic_episode':
|
| 275 |
$weight_title = t('Episode number');
|
| 276 |
break;
|
| 277 |
case 'webcomic_strip':
|
| 278 |
$weight_title = t('Strip number');
|
| 279 |
break;
|
| 280 |
}
|
| 281 |
|
| 282 |
$form['weight'] = array(
|
| 283 |
'#type' => 'textfield',
|
| 284 |
'#title' => $weight_title,
|
| 285 |
'#maxlength' => 25,
|
| 286 |
'#weight' => 8,
|
| 287 |
'#default_value' => $node->weight,
|
| 288 |
'#description' => t('This number doesn\'t have to be unique, but it probably should be. It\'s used to sort strips, episodes, and storylines.'),
|
| 289 |
);
|
| 290 |
|
| 291 |
if ($node->type == 'webcomic_strip') {
|
| 292 |
$chars = _webcomic_list_characters();
|
| 293 |
if (count($chars) > 0) {
|
| 294 |
$form['characters'] = array(
|
| 295 |
'#type' => 'select',
|
| 296 |
'#title' => t('Characters'),
|
| 297 |
'#default_value' => $node->characters,
|
| 298 |
'#options' => $chars,
|
| 299 |
'#multiple' => TRUE,
|
| 300 |
'#description' => t('Links to all characters that appear in this particular strip.'),
|
| 301 |
'#weight' => 9,
|
| 302 |
);
|
| 303 |
}
|
| 304 |
}
|
| 305 |
|
| 306 |
$form['body_filter']['body'] = array(
|
| 307 |
'#type' => 'textarea',
|
| 308 |
'#title' => t('Description'),
|
| 309 |
'#default_value' => $node->body,
|
| 310 |
'#rows' => 10,
|
| 311 |
'#required' => FALSE,
|
| 312 |
);
|
| 313 |
|
| 314 |
$form['body_filter']['format'] = filter_form($node->format);
|
| 315 |
|
| 316 |
return $form;
|
| 317 |
}
|
| 318 |
|
| 319 |
/**
|
| 320 |
* Implementation of hook_form().
|
| 321 |
*/
|
| 322 |
function webcomic_form($node) {
|
| 323 |
if ($node->type == 'webcomic_character') {
|
| 324 |
return _webcomic_character_form($node);
|
| 325 |
}
|
| 326 |
|
| 327 |
return _webcomic_content_form($node);
|
| 328 |
}
|
| 329 |
|
| 330 |
/**
|
| 331 |
* Moved this over directly from image so I could change the weight.
|
| 332 |
*/
|
| 333 |
//function webcomic_form_add_thumbnail($form_id, $edit) {
|
| 334 |
// if ($edit['images']['thumbnail']) {
|
| 335 |
// $node = (object)($edit);
|
| 336 |
// $form = array(
|
| 337 |
// '#type' => 'item',
|
| 338 |
// '#title' => t('Thumbnail'),
|
| 339 |
// '#value' => image_display($node, 'thumbnail'),
|
| 340 |
// '#weight' => 2,
|
| 341 |
// );
|
| 342 |
// }
|
| 343 |
//
|
| 344 |
// return $form;
|
| 345 |
//}
|
| 346 |
|
| 347 |
/**
|
| 348 |
* Implementation of hook_load().
|
| 349 |
*/
|
| 350 |
function webcomic_load(&$node) {
|
| 351 |
if ($node->type == 'webcomic_storyline' || $node->type == 'webcomic_episode' || $node->type == 'webcomic_strip') {
|
| 352 |
// basic webcomic data
|
| 353 |
$content = db_fetch_object(db_query('SELECT * FROM {webcomic_content} WHERE nid = %d', $node->nid));
|
| 354 |
if ($content->publish_timestamp != 0) {
|
| 355 |
$content->publish_date = format_date($content->publish_timestamp, 'custom', 'Y-m-d H:i:s O');
|
| 356 |
}
|
| 357 |
if ($content->storyline_timestamp != 0) {
|
| 358 |
$content->storyline_date = format_date($content->storyline_timestamp, 'custom', 'Y-m-d H:i:s O');
|
| 359 |
}
|
| 360 |
|
| 361 |
// image loading
|
| 362 |
image_load($node);
|
| 363 |
|
| 364 |
// parent relationships
|
| 365 |
$parent = db_fetch_object(db_query('SELECT * FROM {webcomic_parent} WHERE child_nid = %d', $node->nid));
|
| 366 |
$content->parent_nid = $parent->parent_nid;
|
| 367 |
|
| 368 |
// character associations
|
| 369 |
if ($node->type == 'webcomic_strip') {
|
| 370 |
$result = db_query('SELECT * FROM {webcomic_strip_character} WHERE strip_nid = %d', $node->nid);
|
| 371 |
while ($strip_char = db_fetch_object($result)) {
|
| 372 |
$content->characters[] = $strip_char->character_nid;
|
| 373 |
}
|
| 374 |
}
|
| 375 |
}
|
| 376 |
|
| 377 |
return $content;
|
| 378 |
}
|
| 379 |
|
| 380 |
/**
|
| 381 |
* Implementation of hook_insert().
|
| 382 |
*/
|
| 383 |
function webcomic_insert($node) {
|
| 384 |
if ($node->type == 'webcomic_storyline' || $node->type == 'webcomic_episode' || $node->type == 'webcomic_strip') {
|
| 385 |
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);
|
| 386 |
if (isset($node->parent_nid)) {
|
| 387 |
db_query("INSERT INTO {webcomic_parent} (child_nid, parent_nid) VALUES (%d, %d)", $node->nid, $node->parent_nid);
|
| 388 |
}
|
| 389 |
if (function_exists('image_prepare') && function_exists('image_insert')) {
|
| 390 |
image_prepare($node, 'image');
|
| 391 |
if($node->images['_original'] != '') {
|
| 392 |
image_insert($node);
|
| 393 |
}
|
| 394 |
}
|
| 395 |
if ($node->type == 'webcomic_strip' && is_array($node->characters)) {
|
| 396 |
foreach($node->characters as $char_nid) {
|
| 397 |
db_query("INSERT INTO {webcomic_strip_character} (strip_nid, character_nid) VALUES (%d, %d)", $node->nid, $char_nid);
|
| 398 |
}
|
| 399 |
}
|
| 400 |
}
|
| 401 |
}
|
| 402 |
|
| 403 |
/**
|
| 404 |
* Implementation of hook_update().
|
| 405 |
*/
|
| 406 |
function webcomic_update($node) {
|
| 407 |
if ($node->type == 'webcomic_storyline' || $node->type == 'webcomic_episode' || $node->type == 'webcomic_strip') {
|
| 408 |
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);
|
| 409 |
db_query("DELETE FROM {webcomic_parent} WHERE child_nid = %d", $node->nid);
|
| 410 |
db_query("DELETE FROM {webcomic_strip_character} WHERE strip_nid = %d", $node->nid);
|
| 411 |
|
| 412 |
if (isset($node->parent_nid)) {
|
| 413 |
db_query("INSERT INTO {webcomic_parent} (child_nid, parent_nid) VALUES (%d, %d)", $node->nid, $node->parent_nid);
|
| 414 |
}
|
| 415 |
|
| 416 |
if ($node->type == 'webcomic_strip' && is_array($node->characters)) {
|
| 417 |
foreach($node->characters as $char_nid) {
|
| 418 |
db_query("INSERT INTO {webcomic_strip_character} (strip_nid, character_nid) VALUES (%d, %d)", $node->nid, $char_nid);
|
| 419 |
}
|
| 420 |
}
|
| 421 |
|
| 422 |
if (function_exists('image_prepare') && function_exists('image_update')) {
|
| 423 |
image_prepare($node, 'image');
|
| 424 |
//print_r($node, FALSE);
|
| 425 |
if($node->images[_original] != '') {
|
| 426 |
image_update($node);
|
| 427 |
}
|
| 428 |
}
|
| 429 |
}
|
| 430 |
}
|
| 431 |
|
| 432 |
/**
|
| 433 |
* Implementation of hook_delete().
|
| 434 |
*/
|
| 435 |
function webcomic_delete(&$node) {
|
| 436 |
if ($node->type == 'webcomic_character') {
|
| 437 |
db_query('DELETE FROM {webcomic_strip_character} WHERE character_nid = %d', $node->nid);
|
| 438 |
} else {
|
| 439 |
db_query('DELETE FROM {webcomic_content} WHERE nid = %d', $node->nid);
|
| 440 |
db_query('DELETE FROM {webcomic_parent} WHERE child_nid = %d OR parent_nid = %d', $node->nid, $node->nid);
|
| 441 |
db_query('DELETE FROM {webcomic_strip_character} WHERE strip_nid = %d', $node->nid);
|
| 442 |
|
| 443 |
foreach ($node->images as $label => $image) {
|
| 444 |
file_delete(file_create_path($image));
|
| 445 |
db_query("DELETE FROM {files} WHERE filename='%s' AND nid=%d", $label, $node->nid);
|
| 446 |
}
|
| 447 |
}
|
| 448 |
}
|
| 449 |
|
| 450 |
/**
|
| 451 |
* Implementation of hook_submit().
|
| 452 |
*/
|
| 453 |
function webcomic_submit(&$node) {
|
| 454 |
if ($node->type == 'webcomic_storyline' || $node->type == 'webcomic_episode' || $node->type == 'webcomic_strip') {
|
| 455 |
// If a publish date has been set, and is in the future, override the publish flag
|
| 456 |
// otherwise, set the publish date to the created date
|
| 457 |
if ($node->publish_date != '') {
|
| 458 |
$node->publish_timestamp = strtotime($node->publish_date);
|
| 459 |
if ($node->publish_timestamp > time()) {
|
| 460 |
// Unpublish the node. It shouldn't be visible!
|
| 461 |
$node->status = 0;
|
| 462 |
}
|
| 463 |
}
|
| 464 |
else {
|
| 465 |
$node->publish_timestamp = $node->created;
|
| 466 |
}
|
| 467 |
|
| 468 |
if ($node->storyline_date != '') {
|
| 469 |
$node->storyline_timestamp = strtotime($node->storyline_timestamp);
|
| 470 |
}
|
| 471 |
|
| 472 |
$node->sequence = _webcomic_generate_sequence($node);
|
| 473 |
}
|
| 474 |
}
|
| 475 |
|
| 476 |
function _webcomic_list_type($type = NULL) {
|
| 477 |
$items = array();
|
| 478 |
$items[0] = '-- No parent --';
|
| 479 |
|
| 480 |
$sql = "SELECT n.nid, n.title, n.created, n.status, n.type, wcc.publish_timestamp, wcc.storyline_timestamp, wcc.weight ";
|
| 481 |
$sql .= "FROM {node} n INNER JOIN {webcomic_content} wcc ON n.nid = wcc.nid WHERE n.type = '%s'";
|
| 482 |
$sql .= ' ORDER BY wcc.sequence ASC';
|
| 483 |
|
| 484 |
$result = db_query($sql, $type);
|
| 485 |
while ($item = db_fetch_object($result)) {
|
| 486 |
$key = $item->nid;
|
| 487 |
$value = $item->title;
|
| 488 |
if (!$item->status) {
|
| 489 |
$value .= ' (not published)';
|
| 490 |
}
|
| 491 |
$items[$key] = $value;
|
| 492 |
}
|
| 493 |
|
| 494 |
return $items;
|
| 495 |
}
|
| 496 |
|
| 497 |
function _webcomic_list_characters() {
|
| 498 |
$chars = array();
|
| 499 |
$sql = "SELECT n.nid, n.title, n.status FROM {node} n WHERE n.type = 'webcomic_character' ORDER BY n.title ASC, n.status DESC";
|
| 500 |
|
| 501 |
$result = db_query($sql);
|
| 502 |
while ($char = db_fetch_object($result)) {
|
| 503 |
$key = $char->nid;
|
| 504 |
$value = $char->title;
|
| 505 |
if (!$char->status) {
|
| 506 |
$value .= ' (not published)';
|
| 507 |
}
|
| 508 |
$chars[$key] = $value;
|
| 509 |
}
|
| 510 |
|
| 511 |
return $chars;
|
| 512 |
}
|
| 513 |
|
| 514 |
function _webcomic_generate_sequence($node) {
|
| 515 |
$seq = _webcomic_get_sequence($node);
|
| 516 |
|
| 517 |
switch ($node->type) {
|
| 518 |
case 'webcomic_strip':
|
| 519 |
$seq = str_pad($seq, 33, '0', STR_PAD_LEFT);
|
| 520 |
break;
|
| 521 |
case 'webcomic_episode':
|
| 522 |
$seq = str_pad($seq, 22, '0', STR_PAD_LEFT);
|
| 523 |
$seq = str_pad($seq, 33, '0', STR_PAD_RIGHT);
|
| 524 |
break;
|
| 525 |
case 'webcomic_storyline':
|
| 526 |
$seq = str_pad($seq, 33, '0', STR_PAD_RIGHT);
|
| 527 |
break;
|
| 528 |
}
|
| 529 |
|
| 530 |
return $seq;
|
| 531 |
}
|
| 532 |
|
| 533 |
function _webcomic_get_sequence($node) {
|
| 534 |
$seq = _webcomic_get_sequence_chunk($node);
|
| 535 |
if ($node->parent_nid) {
|
| 536 |
$seq = _webcomic_get_sequence(node_load($node->parent_nid)) . $seq;
|
| 537 |
}
|
| 538 |
|
| 539 |
return $seq;
|
| 540 |
}
|
| 541 |
|
| 542 |
function _webcomic_get_sequence_chunk($node) {
|
| 543 |
switch (variable_get('webcomic_browsing_order', 'publish_timestamp')) {
|
| 544 |
case 'publish_timestamp':
|
| 545 |
$tmp = $node->publish_timestamp;
|
| 546 |
break;
|
| 547 |
case 'storyline_timestamp':
|
| 548 |
$tmp = $node->storyline_timestamp;
|
| 549 |
break;
|
| 550 |
case 'weight':
|
| 551 |
$tmp = $node->weight;
|
| 552 |
break;
|
| 553 |
}
|
| 554 |
|
| 555 |
return str_pad($tmp, 11, '0', STR_PAD_LEFT);
|
| 556 |
}
|
| 557 |
|
| 558 |
/**
|
| 559 |
* Implementation of hook_cron().
|
| 560 |
*
|
| 561 |
* Auto-publishes content.
|
| 562 |
*/
|
| 563 |
function webcomic_cron() {
|
| 564 |
$result = db_query('SELECT wcc.nid FROM {webcomic_content} wcc INNER JOIN {node} n ON wcc.nid = n.nid WHERE n.status = 0 AND wcc.publish_timestamp <= %d', time());
|
| 565 |
while ($tmp = db_fetch_object($result)) {
|
| 566 |
$node = node_load($tmp->nid);
|
| 567 |
$node->status = 1;
|
| 568 |
node_save($node);
|
| 569 |
|
| 570 |
watchdog('webcomic', $node->title .' published.');
|
| 571 |
}
|
| 572 |
}
|
| 573 |
|
| 574 |
/**
|
| 575 |
* Implementation of hook_view().
|
| 576 |
*/
|
| 577 |
function webcomic_view(&$node, $teaser = FALSE, $page = FALSE) {
|
| 578 |
drupal_add_css(drupal_get_path('module', 'webcomic') .'/webcomic.css');
|
| 579 |
if ($page && $node->parent_nid) {
|
| 580 |
$episode = node_load($node->parent_nid);
|
| 581 |
$breadcrumb = array();
|
| 582 |
$breadcrumb[] = array('path' => 'node/'. $episode->nid, 'title' => $episode->title);
|
| 583 |
if ($episode->parent_nid) {
|
| 584 |
$storyline = node_load($episode->parent_nid);
|
| 585 |
$breadcrumb[] = array('path' => 'node/'. $storyline->nid, 'title' => $storyline->title);
|
| 586 |
}
|
| 587 |
|
| 588 |
menu_set_location($breadcrumb);
|
| 589 |
}
|
| 590 |
|
| 591 |
$node = node_prepare($node, $teaser);
|
| 592 |
|
| 593 |
$nav = theme('webcomic_navigation', $node);
|
| 594 |
|
| 595 |
$node->content['teaser']['#value'] = theme('webcomic_teaser', $node);
|
| 596 |
$node->content['body']['#value'] = $nav;
|
| 597 |
$node->content['body']['#value'] .= theme('webcomic_body', $node, 'preview');
|
| 598 |
$node->content['body']['#value'] .= $nav;
|
| 599 |
|
| 600 |
return $node;
|
| 601 |
}
|
| 602 |
|
| 603 |
function webcomic_update_sequences() {
|
| 604 |
$result = db_query('SELECT nid FROM {webcomic_content}');
|
| 605 |
while ($nid = db_fetch_object($result)) {
|
| 606 |
$node = node_load($nid->nid);
|
| 607 |
$node->sequence = _webcomic_generate_sequence($node);
|
| 608 |
|
| 609 |
node_save($node);
|
| 610 |
}
|
| 611 |
}
|
| 612 |
|
| 613 |
function webcomic_first($node) {
|
| 614 |
switch (variable_get('webcomic_browsing_style', 'all_images')) {
|
| 615 |
case 'like_kinds':
|
| 616 |
$where = " AND n.type = '". $node->type ."'";
|
| 617 |
break;
|
| 618 |
case 'all_images':
|
| 619 |
break;
|
| 620 |
case 'episode_index':
|
| 621 |
$where = " AND n.type = '". $node->type ."'";
|
| 622 |
break;
|
| 623 |
case 'story_index':
|
| 624 |
$where = " AND n.type = '". $node->type ."'";
|
| 625 |
break;
|
| 626 |
}
|
| 627 |
|
| 628 |
$sql = "SELECT n.nid, n.title, wcc.sequence FROM {node} n";
|
| 629 |
$sql .= " INNER JOIN {webcomic_content} wcc ON n.nid = wcc.nid";
|
| 630 |
$sql .= " WHERE n.status = 1 AND n.moderate = 0 ". $where;
|
| 631 |
$sql .= " ORDER BY wcc.sequence ASC, n.title ASC LIMIT 1";
|
| 632 |
|
| 633 |
$result = db_query($sql, $node->nid);
|
| 634 |
$first = db_fetch_object($result);
|
| 635 |
|
| 636 |
if ($first->nid != $node->nid) {
|
| 637 |
return $first;
|
| 638 |
}
|
| 639 |
}
|
| 640 |
|
| 641 |
function webcomic_prev($node) {
|
| 642 |
switch (variable_get('webcomic_browsing_style', 'all_images')) {
|
| 643 |
case 'like_kinds':
|
| 644 |
$where = " AND n.type = '". $node->type ."'";
|
| 645 |
break;
|
| 646 |
case 'all_images':
|
| 647 |
break;
|
| 648 |
case 'episode_index':
|
| 649 |
$where = " AND n.type = '". $node->type ."'";
|
| 650 |
break;
|
| 651 |
case 'story_index':
|
| 652 |
$where = " AND n.type = '". $node->type ."'";
|
| 653 |
break;
|
| 654 |
}
|
| 655 |
|
| 656 |
$sql = "SELECT n.nid, n.title, wcc.sequence FROM {node} n";
|
| 657 |
$sql .= " INNER JOIN {webcomic_content} wcc ON n.nid = wcc.nid";
|
| 658 |
$sql .= " WHERE n.status = 1 AND n.moderate = 0 ". $where;
|
| 659 |
$sql .= " AND (wcc.sequence < '%s' OR (wcc.sequence = '%s' AND n.title < '%s')) ";
|
| 660 |
$sql .= " ORDER BY wcc.sequence DESC, n.title DESC LIMIT 1";
|
| 661 |
|
| 662 |
$result = db_query($sql, $node->sequence, $node->sequence, $node->title);
|
| 663 |
$prev = db_fetch_object($result);
|
| 664 |
|
| 665 |
return $prev;
|
| 666 |
}
|
| 667 |
|
| 668 |
function webcomic_next($node) {
|
| 669 |
switch (variable_get('webcomic_browsing_style', 'all_images')) {
|
| 670 |
case 'like_kinds':
|
| 671 |
$where = " AND n.type = '". $node->type ."'";
|
| 672 |
break;
|
| 673 |
case 'all_images':
|
| 674 |
break;
|
| 675 |
case 'episode_index':
|
| 676 |
$where = " AND n.type = '". $node->type ."'";
|
| 677 |
break;
|
| 678 |
case 'story_index':
|
| 679 |
$where = " AND n.type = '". $node->type ."'";
|
| 680 |
break;
|
| 681 |
}
|
| 682 |
|
| 683 |
$sql = "SELECT n.nid, n.title, wcc.sequence FROM {node} n";
|
| 684 |
$sql .= " INNER JOIN {webcomic_content} wcc ON n.nid = wcc.nid";
|
| 685 |
$sql .= " WHERE n.status = 1 AND n.moderate = 0 ". $where;
|
| 686 |
$sql .= " AND (wcc.sequence > '%s' OR (wcc.sequence = '%s' AND n.title > '%s'))";
|
| 687 |
$sql .= " ORDER BY wcc.sequence ASC, n.title ASC LIMIT 1";
|
| 688 |
|
| 689 |
$result = db_query($sql, $node->sequence, $node->sequence, $node->title);
|
| 690 |
$next = db_fetch_object($result);
|
| 691 |
|
| 692 |
return $next;
|
| 693 |
}
|
| 694 |
|
| 695 |
function webcomic_last($node) {
|
| 696 |
switch (variable_get('webcomic_browsing_style', 'all_images')) {
|
| 697 |
case 'like_kinds':
|
| 698 |
$where = " AND n.type = '". $node->type ."'";
|
| 699 |
break;
|
| 700 |
case 'all_images':
|
| 701 |
break;
|
| 702 |
case 'episode_index':
|
| 703 |
$where = " AND n.type = '". $node->type ."'";
|
| 704 |
break;
|
| 705 |
case 'story_index':
|
| 706 |
$where = " AND n.type = '". $node->type ."'";
|
| 707 |
break;
|
| 708 |
}
|
| 709 |
|
| 710 |
$sql = "SELECT n.nid, n.title, wcc.sequence FROM {node} n";
|
| 711 |
$sql .= " INNER JOIN {webcomic_content} wcc ON n.nid = wcc.nid";
|
| 712 |
$sql .= " WHERE n.status = 1 AND n.moderate = 0 ". $where;
|
| 713 |
$sql .= " ORDER BY wcc.sequence DESC, n.title DESC LIMIT 1";
|
| 714 |
|
| 715 |
$result = db_query($sql, $node->nid);
|
| 716 |
$last = db_fetch_object($result);
|
| 717 |
|
| 718 |
if ($last->nid != $node->nid) {
|
| 719 |
return $last;
|
| 720 |
}
|
| 721 |
}
|
| 722 |
|
| 723 |
// This should be modified to return the proper URL for the current
|
| 724 |
function webcomic_index() {
|
| 725 |
switch (variable_get('webcomic_archive_mode', 'strips_month')) {
|
| 726 |
case 'strips':
|
| 727 |
case 'strips_month':
|
| 728 |
case 'strips_year':
|
| 729 |
case 'strips_episode':
|
| 730 |
return 'strips';
|
| 731 |
break;
|
| 732 |
|
| 733 |
case 'episodes':
|
| 734 |
case 'episodes_year':
|
| 735 |
case 'episodes_storyline':
|
| 736 |
return 'episodes';
|
| 737 |
break;
|
| 738 |
|
| 739 |
case 'storylines':
|
| 740 |
return 'storylines';
|
| 741 |
break;
|
| 742 |
}
|
| 743 |
}
|