| 1 |
<?php |
<?php |
| 2 |
// $Id: pblog.module,v 1.5.2.5 2008/05/18 15:29:31 baldy Exp $ |
// $Id: pblog.module,v 1.5.2.7 2008/11/30 20:08:27 baldy Exp $ |
| 3 |
/** |
/** |
| 4 |
* Work in progress Photo/Picture blog or pblog |
* Work in progress Photo/Picture blog or pblog |
| 5 |
* laurence.baldwin@gmail.com |
* laurence.baldwin@gmail.com |
| 8 |
* @drupal_package pblog |
* @drupal_package pblog |
| 9 |
* |
* |
| 10 |
*/ |
*/ |
|
/* |
|
|
$items['pblog/rebuild/%'] = array( |
|
|
'title' => 'Rebuild', |
|
|
'page callback' => 'pblog_rebuild', |
|
|
'page arguments' => array(1,2), |
|
|
'access arguments' => array('access pblog'), |
|
|
'type' => MENU_LOCAL_TASK, |
|
|
'weight' => 2, |
|
|
); */ |
|
| 11 |
|
|
| 12 |
function pblog_menu() { |
function pblog_menu() { |
| 13 |
|
|
| 40 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 41 |
); |
); |
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
return $items; |
return $items; |
| 44 |
|
|
| 45 |
} |
} |
| 80 |
$file_dir = file_directory_path(); |
$file_dir = file_directory_path(); |
| 81 |
$img_array = array(); |
$img_array = array(); |
| 82 |
$imgmed_array = array(); |
$imgmed_array = array(); |
| 83 |
|
|
| 84 |
if (is_dir($file_dir .'/pblog/'. $node->nid)) { |
if (is_dir($file_dir .'/pblog/'. $node->nid)) { |
| 85 |
if ($dh = opendir($file_dir .'/pblog/'. $node->nid)) { |
if ($dh = opendir($file_dir .'/pblog/'. $node->nid)) { |
| 86 |
while (($file = readdir($dh)) !== false) { |
while (($file = readdir($dh)) !== false) { |
| 87 |
if (preg_match("/-mini.jpg$/", $file) && !preg_match("/bw-mini.jpg$/", $file) ) { |
if (preg_match("/-mini.jpg$/", $file) && !preg_match("/bw-mini.jpg$/", $file) ) { |
| 91 |
closedir($dh); |
closedir($dh); |
| 92 |
} |
} |
| 93 |
} |
} |
| 94 |
|
|
| 95 |
srand((float) microtime() * 10000000); |
|
| 96 |
$j = array_rand($img_array); |
|
| 97 |
$imgurl = $file_dir .'/pblog/'. $node->nid . $img_array[$j]; |
$imgurl = pblog_get_random_image($node); |
| 98 |
|
$teaser_images = variable_get(pblog_teaser_images,'1'); |
| 99 |
$header = array(array(null, null)); |
if ($teaser_images == 1) { |
| 100 |
$rows = array( |
$rows = array( |
| 101 |
array( |
array( |
| 102 |
l(theme_image($imgurl), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)), |
l(theme_image(pblog_get_random_image($node)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)), |
| 103 |
$node->teaser |
$node->teaser) |
| 104 |
) |
); |
| 105 |
); |
$node->teaser = theme_table(NULL, $rows); |
| 106 |
$node->teaser = theme_table($header, $rows); |
} else { |
| 107 |
|
// make 2x2 table |
| 108 |
|
$cube_rows = array( |
| 109 |
|
array( l(theme_image(pblog_get_random_image($node, strip)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)), |
| 110 |
|
l(theme_image(pblog_get_random_image($node, strip)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE))), |
| 111 |
|
|
| 112 |
|
array( l(theme_image(pblog_get_random_image($node, strip)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)), |
| 113 |
|
l(theme_image(pblog_get_random_image($node, strip)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE))) |
| 114 |
|
); |
| 115 |
|
|
| 116 |
|
$rows = array( |
| 117 |
|
array( |
| 118 |
|
theme_table(NULL, $cube_rows), |
| 119 |
|
$node->teaser) |
| 120 |
|
); |
| 121 |
|
$node->teaser = theme_table(NULL, $rows); |
| 122 |
|
}; |
| 123 |
|
|
| 124 |
$node->body = $node->body .'<p>'; |
$node->body = $node->body .'<p>'; |
| 125 |
$row_count = 0; |
$row_count = 0; |
| 564 |
'#required' => TRUE, |
'#required' => TRUE, |
| 565 |
); |
); |
| 566 |
|
|
| 567 |
|
$form['pblog_teaser_images'] = array( |
| 568 |
|
'#type' => 'textfield', |
| 569 |
|
'#title' => t('Teaser Images'), |
| 570 |
|
'#default_value' => variable_get('pblog_teaser_images', 1), |
| 571 |
|
'#size' => 5, |
| 572 |
|
'#maxlength' => 5, |
| 573 |
|
'#description' => t("The number of images to show in the node teaser, currently only 1 or 4."), |
| 574 |
|
'#required' => TRUE, |
| 575 |
|
); |
| 576 |
|
|
| 577 |
|
|
| 578 |
return system_settings_form($form); |
return system_settings_form($form); |
| 579 |
} |
} |
| 619 |
drupal_set_message('Unable to creating medium image '. $s_root, 'error'); |
drupal_set_message('Unable to creating medium image '. $s_root, 'error'); |
| 620 |
} |
} |
| 621 |
} |
} |
| 622 |
|
|
| 623 |
} |
} |
| 624 |
} else drupal_set_message("Cannot open the directory $image_dir to create thumbnails".'error'); |
} else drupal_set_message("Cannot open the directory $image_dir to create thumbnails".'error'); |
| 625 |
} |
} |
| 626 |
|
|
| 627 |
|
function pblog_get_random_image($node, $size = "mini"){ |
| 628 |
|
$file_dir = file_directory_path(); |
| 629 |
|
$img_array = array(); |
| 630 |
|
$imgmed_array = array(); |
| 631 |
|
|
| 632 |
|
if (is_dir($file_dir .'/pblog/'. $node->nid)) { |
| 633 |
|
if ($dh = opendir($file_dir .'/pblog/'. $node->nid)) { |
| 634 |
|
while (($file = readdir($dh)) !== false) { |
| 635 |
|
if (preg_match("/-mini.jpg$/", $file) && !preg_match("/bw-mini.jpg$/", $file) ) { |
| 636 |
|
array_push($img_array, "$dir_array[$i]"."/$file"); |
| 637 |
|
} |
| 638 |
|
} |
| 639 |
|
closedir($dh); |
| 640 |
|
} |
| 641 |
|
} |
| 642 |
|
|
| 643 |
|
srand((float) microtime() * 10000000); |
| 644 |
|
$j = array_rand($img_array); |
| 645 |
|
|
| 646 |
|
if ($size == "strip"){ |
| 647 |
|
return strtr($file_dir .'/pblog/'. $node->nid . $img_array[$j],array("mini.jpg" => "strip.jpg")); |
| 648 |
|
} else { return($file_dir .'/pblog/'. $node->nid . $img_array[$j]); } |
| 649 |
|
} |
| 650 |
|
|