| 1 |
<?php |
<?php |
| 2 |
// $Id: pblog.module,v 1.5.2.1 2008/02/20 14:10:01 baldy Exp $ |
// $Id: pblog.module,v 1.5.2.5 2008/05/18 15:29:31 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 |
| 97 |
$node->body = $node->body .'<p>'; |
$node->body = $node->body .'<p>'; |
| 98 |
sort($img_array); |
sort($img_array); |
| 99 |
$numberofpics = count($img_array); |
$numberofpics = count($img_array); |
| 100 |
for ( $counter=0; $counter < $numberofpics; $counter++ ) { |
for( $counter=0; $counter < $numberofpics; $counter++ ) { |
| 101 |
$trans = array("mini.jpg" => "med.jpg"); |
$trans = array("mini.jpg" => "med.jpg"); |
| 102 |
$med_image = strtr($img_array[$counter], $trans); |
$med_image = strtr($img_array[$counter], $trans); |
| 103 |
$image_tag = theme_image("$file_dir/pblog/$node->nid$img_array[$counter]"); |
$image_tag = theme_image("$file_dir/pblog/$node->nid$img_array[$counter]"); |
| 170 |
} |
} |
| 171 |
else { |
else { |
| 172 |
$node = node_load($nid); |
$node = node_load($nid); |
| 173 |
|
$strip_size = variable_get(pblog_stripsize,'5'); |
| 174 |
drupal_set_title($title .= t(l($node->title, "node/$node->nid") ." - ". $picture)); |
drupal_set_title($title .= t(l($node->title, "node/$node->nid") ." - ". $picture)); |
| 175 |
|
|
| 176 |
// to work out whats in front and behind we need to create an array of all the images in the directory |
// to work out whats in front and behind we need to create an array of all the images in the directory |
| 177 |
// then find the current one. |
// then find the current one. |
| 178 |
$img_array = array(); |
$img_array = array(); // Array of all the medium size image for this node |
| 179 |
$fullsize_img_array = array(); |
$fullsize_img_array = array(); // Array of all the file size images for this node |
| 180 |
if (is_dir("$file_dir/pblog/$nid")) { |
if (is_dir("$file_dir/pblog/$nid")) { |
| 181 |
if ($dh = opendir("$file_dir/pblog/$nid")) { |
if ($dh = opendir("$file_dir/pblog/$nid")) { |
| 182 |
while (($file = readdir($dh)) !== false) { |
while (($file = readdir($dh)) !== false) { |
| 183 |
if (!preg_match("/bw-mini.jpg$/", $file) && !preg_match("/-mini.jpg$/", $file) |
if (preg_match("/-med.jpg$/", $file)) { |
|
&& preg_match("/-med.jpg$/", $file)) { |
|
| 184 |
array_push($img_array, "$dir_array[$i]"."/$file"); |
array_push($img_array, "$dir_array[$i]"."/$file"); |
| 185 |
} |
} |
| 186 |
else if (!preg_match("/-mini.jpg$/", $file) && !preg_match("/-med.jpg$/", $file) |
else if (!is_dir($file) && !preg_match("/-mini.jpg$/", $file) && !preg_match("/-med.jpg$/", $file) |
| 187 |
&& !preg_match("/-strip.jpg$/", $file) ) { |
&& !preg_match("/-strip.jpg$/", $file) ) { |
| 188 |
array_push($fullsize_img_array, "$dir_array[$i]"."/$file"); |
array_push($fullsize_img_array, "$dir_array[$i]"."/$file"); |
| 189 |
} |
} |
| 191 |
closedir($dh); |
closedir($dh); |
| 192 |
} |
} |
| 193 |
} |
} |
| 194 |
sort($img_array); |
|
| 195 |
|
|
| 196 |
|
sort($img_array); |
| 197 |
$num_images = count($img_array); |
$num_images = count($img_array); |
| 198 |
sort($fullsize_img_array); |
sort($fullsize_img_array); |
| 199 |
|
$num_images2 = count($fullsize_img_array); |
| 200 |
|
|
| 201 |
|
// error check |
| 202 |
|
if ( $num_images != $num_images2 ){ |
| 203 |
|
drupal_set_message("There is a mismatch with number of full size images and scaled images, full size = ".$num_images2." scaled images". $num_images, 'error'); |
| 204 |
|
} |
| 205 |
|
|
| 206 |
// set $current_image to position in array of current image |
// set $current_image to position in array of current image |
| 207 |
$current_image = array_search("/$picture", $img_array); |
$current_image = array_search("/$picture", $img_array); |
| 208 |
$full_image = $fullsize_img_array[$current_image + 2]; |
$full_image = $fullsize_img_array[$current_image]; |
| 209 |
|
|
| 210 |
$image_tag = theme_image("$file_dir/pblog/$nid/$picture", $node->title, $node->title); |
$image_tag = theme_image("$file_dir/pblog/$nid/$picture", $node->title, $node->title); |
| 211 |
$main_image =l($image_tag, "$file_dir/pblog/$nid$full_image", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)); |
$main_image =l($image_tag, file_create_url($file_dir.'/pblog/'.$nid.$full_image), array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)); |
| 212 |
$output = "$main_image"; |
$output = "$main_image"; |
| 213 |
|
|
| 214 |
if ($current_image >= $num_images - 2) { |
// if $strip_size is 0 dont display the strip |
| 215 |
$next_image1 = $img_array[0]; |
if ( $strip_size > 0) { |
| 216 |
} |
if ($strip_size % 2 == 0 ) { |
| 217 |
else $next_image1 = $img_array[$current_image + 2]; |
$j = $strip_size / 2; } else |
| 218 |
|
$j = ($strip_size - 1) / 2; |
| 219 |
if ($current_image >= $num_images - 1) { |
|
| 220 |
$next_image = $img_array[1]; |
$tr_med2strip = array("med" => "strip"); |
| 221 |
} |
$tr_med = array("-med" => ""); |
| 222 |
else $next_image = $img_array[$current_image + 1]; |
|
| 223 |
|
// create array of image indexs |
| 224 |
$cur_image = $img_array[$current_image]; |
if ($current_image == 0) { |
| 225 |
if ($current_image == 1 || $current_image == 0) { |
$previous_array[0] = $num_images - 1; |
| 226 |
$prev_image1 = $img_array[$num_images - 1]; |
} else $previous_array[0] = $current_image - 1; |
| 227 |
} |
|
| 228 |
else $prev_image1 = $img_array[$current_image - 2]; |
for ($i = 1; $i < $j ; $i++){ |
| 229 |
|
if ($previous_array[$i - 1] <= 0) { |
| 230 |
if ($current_image == 0) { |
$previous_array[$i] = $num_images - 1; |
| 231 |
$prev_image = $img_array[$num_images - 2]; |
} else { |
| 232 |
} |
$previous_array[$i] = $previous_array[$i - 1] - 1; |
| 233 |
else $prev_image = $img_array[$current_image - 1]; |
} |
| 234 |
|
} |
| 235 |
|
|
| 236 |
|
|
| 237 |
|
for($i = $j; $i > 0; $i--){ |
| 238 |
|
unset($arrows); |
| 239 |
|
for($k = 0; $k < $i; $k++) { |
| 240 |
|
$arrows .= "<"; |
| 241 |
|
} |
| 242 |
|
|
| 243 |
|
$previous_image = $img_array[$previous_array[$i - 1 ]]; |
| 244 |
|
|
| 245 |
|
$previous_image_url = theme_image("$file_dir/pblog/$nid". strtr($previous_image,$tr_med2strip), 'Next Image', 'Previous Image'); |
| 246 |
|
|
| 247 |
|
$header[] = l("$arrows Previous", "pblog/$nid$previous_image", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)); |
| 248 |
|
$rows[0][] = l($previous_image_url, "pblog/$nid$previous_image", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)); |
| 249 |
|
} |
| 250 |
|
|
| 251 |
|
// Current image |
| 252 |
|
$cur_image = $img_array[$current_image]; |
| 253 |
|
$cur_image_strip = $cur_image; |
| 254 |
|
$cur_image_strip = strtr($cur_image_strip, $tr_med2strip) ; |
| 255 |
|
$full_image_url = theme_image("$file_dir/pblog/$nid$cur_image_strip", 'Current Image', 'Current Image'); |
| 256 |
|
$header[] = l("Full Size", file_create_url($file_dir.'/pblog/'.$nid.$full_image), array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)); |
| 257 |
|
$rows[0][] = l($full_image_url, file_create_url($file_dir.'/pblog/'.$nid.$full_image), array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)); |
| 258 |
|
|
| 259 |
|
$next_image_ref = $current_image; |
| 260 |
|
// Next images |
| 261 |
|
for($i = 1; $i <= $j; $i++){ |
| 262 |
|
unset($arrows); |
| 263 |
|
for($k = 0; $k < $i; $k++) { |
| 264 |
|
$arrows .= ">"; |
| 265 |
|
} |
| 266 |
|
|
| 267 |
|
if ($next_image_ref >= $num_images - 1) { |
| 268 |
|
$next_image_ref = 0 ; |
| 269 |
|
} else $next_image_ref = $next_image_ref + 1; |
| 270 |
|
|
| 271 |
|
$next_image = $img_array[$next_image_ref]; |
| 272 |
|
|
| 273 |
|
$next_image_url = theme_image("$file_dir/pblog/$nid". strtr($next_image,$tr_med2strip), 'Next Image', 'Next Image'); |
| 274 |
|
|
| 275 |
|
$header[] = l("$arrows Next", "pblog/$nid$next_image", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)); |
| 276 |
|
$rows[0][] = l($next_image_url, "pblog/$nid$next_image", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)); |
| 277 |
|
|
| 278 |
|
} |
| 279 |
|
|
| 280 |
|
} |
| 281 |
|
|
| 282 |
|
$output .= theme_table($header, $rows); |
| 283 |
|
|
| 284 |
$trans = array("med" => "strip"); |
return $output; |
|
$trans2 = array("-med" => ""); |
|
|
$next_image_url1 = theme_image("$file_dir/pblog/$nid". strtr($next_image1, $trans), 'Next Image', 'Next Image'); |
|
|
$next_image_url = theme_image("$file_dir/pblog/$nid". strtr($next_image, $trans), 'Next Image', 'Next Image'); |
|
|
$full_image_url = theme_image("$file_dir/pblog/$nid". strtr($cur_image, $trans), 'Current Image', 'Current Image'); |
|
|
$prev_image_url = theme_image("$file_dir/pblog/$nid". strtr($prev_image, $trans), 'Previous Image', 'Previous Image'); |
|
|
$prev_image_url1 = theme_image("$file_dir/pblog/$nid". strtr($prev_image1, $trans), 'Previous Image', 'Previous Image'); |
|
|
$header = array( |
|
|
l("<< Previous", "pblog/$nid$prev_image1", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)), |
|
|
l("< Previous", "pblog/$nid$prev_image", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)), |
|
|
l("Full Size", "pblog/$nid$next_image", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)), |
|
|
l("Next >", "pblog/$nid$next_image", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)), |
|
|
l("Next >>", "pblog/$nid$next_image1", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)) |
|
|
); |
|
|
$rows = array(array( |
|
|
l($prev_image_url1, "pblog/$nid$prev_image1", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)), |
|
|
l($prev_image_url, "pblog/$nid$prev_image", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)), |
|
|
l($full_image_url, "$file_dir/pblog/$nid$full_image", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)), |
|
|
l($next_image_url, "pblog/$nid$next_image", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)), |
|
|
l($next_image_url1, "pblog/$nid$next_image1", array('attributes' => '', 'absolute' => TRUE, 'html' => TRUE)) |
|
|
)); |
|
|
$output .= theme_table($header, $rows); |
|
|
return $output; |
|
| 285 |
} |
} |
| 286 |
} |
} |
| 287 |
|
|
| 288 |
function pblog_form($node) { |
function pblog_form(&$node) { |
| 289 |
|
$type = node_get_types('type', $node); |
| 290 |
$form['#attributes'] = array("enctype" => "multipart/form-data"); |
$form['#attributes'] = array("enctype" => "multipart/form-data"); |
| 291 |
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5); |
|
| 292 |
$form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); |
$form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => !empty($node->title) ? $node->title : NULL, '#weight' => -5); |
| 293 |
|
$form['body_filter'] = node_body_field($node, $type->body_label, $type->min_word_count); |
| 294 |
|
$form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); |
| 295 |
$form['body_filter']['format'] = filter_form("2"); // Its got to be full html because it uses images |
$form['body_filter']['format'] = filter_form("2"); // Its got to be full html because it uses images |
| 296 |
$form['image'] = array('#type' => 'file', '#title' => t('Zip File'), '#description' => t('Select a zip file containing just images or a single image.')); |
$form['image'] = array('#type' => 'file', '#title' => t('Zip File'), '#description' => t('Select a zip file containing just images or a single image.')); |
| 297 |
if (isset($node->nid)) { // we are editing an existing node |
if (isset($node->nid)) { // we are editing an existing node |
| 536 |
|
|
| 537 |
function pblog_admin() { |
function pblog_admin() { |
| 538 |
|
|
| 539 |
$form['onthisdate_maxdisp'] = array( |
$form['pblog_stripsize'] = array( |
| 540 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 541 |
'#title' => t('Maximum number of links'), |
'#title' => t('Number of images in strip'), |
| 542 |
'#default_value' => variable_get('onthisdate_maxdisp', 3), |
'#default_value' => variable_get('pblog_stripsize', 5), |
| 543 |
'#size' => 2, |
'#size' => 2, |
| 544 |
'#maxlength' => 2, |
'#maxlength' => 2, |
| 545 |
'#description' => t("The maximum number of links to display in the block."), |
'#description' => t("Number of images to use in the strip on the bottom of the image windows. 0 disables the strip. If you dont use a odd number it will be increased by 1 to create a odd number."), |
| 546 |
'#required' => TRUE, |
'#required' => TRUE, |
| 547 |
); |
); |
| 548 |
|
|