| 10 |
*/ |
*/ |
| 11 |
|
|
| 12 |
|
|
|
/* function pblog_menu($may_cache) { |
|
|
$items = array(); |
|
|
// After every change to this unload and reload module and run update.php |
|
|
if ($may_cache) { |
|
|
// www.example.com/pblog/829/picture.jpg |
|
|
$items[] = array('path' => 'pblog', 'title' => t('Pblog'), |
|
|
'callback' => 'pblog_image', |
|
|
'access' => user_access('access pblog')); |
|
|
} |
|
|
return $items; |
|
|
} */ |
|
|
|
|
| 13 |
function pblog_menu() { |
function pblog_menu() { |
| 14 |
$items['pblog/%/%'] = array( |
$items['pblog/%/%'] = array( |
| 15 |
'title' => 'Pblog', |
'title' => 'Pblog', |
| 16 |
'page callback' => 'pblog_image', |
'page callback' => 'pblog_image', |
| 17 |
'page arguments' => array(1, 2), |
'page arguments' => array(1, 2), |
| 18 |
'access arguments' => array('access Pblog'), |
'access arguments' => array('access pblog'), |
| 19 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 20 |
); |
); |
| 21 |
|
|
| 22 |
|
$items['admin/settings/pblog'] = array( |
| 23 |
|
'title' => 'Pblog module settings', |
| 24 |
|
'description' => 'Change your settings for pblog module', |
| 25 |
|
'page callback' => 'drupal_get_form', |
| 26 |
|
'page arguments' => array('pblog_admin'), |
| 27 |
|
'access arguments' => array('access administration pages'), |
| 28 |
|
'type' => MENU_NORMAL_ITEM, |
| 29 |
|
); |
| 30 |
|
|
| 31 |
|
|
| 32 |
return $items; |
return $items; |
| 33 |
|
|
| 48 |
); |
); |
| 49 |
} |
} |
| 50 |
|
|
| 51 |
|
function pblog_access($op, $node) { |
| 52 |
|
global $user; |
| 53 |
|
|
| 54 |
|
if ($op == 'create') { |
| 55 |
|
// Only users with permission to do so may create this node type. |
| 56 |
|
return user_access('create pblog'); |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
// Users who create a node may edit or delete it later, assuming they have the |
| 60 |
|
// necessary permissions. |
| 61 |
|
if ($op == 'update' || $op == 'delete') { |
| 62 |
|
if (user_access('edit pblog') && ($user->uid == $node->uid)) { |
| 63 |
|
return TRUE; |
| 64 |
|
} |
| 65 |
|
} |
| 66 |
|
} |
| 67 |
|
|
| 68 |
function pblog_view($node, $teaser = FALSE, $page = FALSE) { |
function pblog_view($node, $teaser = FALSE, $page = FALSE) { |
| 69 |
$file_dir = file_directory_path(); |
$file_dir = file_directory_path(); |
| 70 |
$img_array = array(); |
$img_array = array(); |
| 183 |
&& 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 (!preg_match("/-mini.jpg$/", $file) && !preg_match("/-med.jpg$/", $file) |
| 187 |
|
&& !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 |
} |
} |
| 190 |
} |
} |
| 224 |
} |
} |
| 225 |
else $prev_image = $img_array[$current_image - 1]; |
else $prev_image = $img_array[$current_image - 1]; |
| 226 |
|
|
| 227 |
$trans = array("med" => "mini"); |
$trans = array("med" => "strip"); |
| 228 |
$trans2 = array("-med" => ""); |
$trans2 = array("-med" => ""); |
| 229 |
$next_image_url1 = theme_image("$file_dir/pblog/$nid". strtr($next_image1, $trans), 'Next Image', 'Next Image'); |
$next_image_url1 = theme_image("$file_dir/pblog/$nid". strtr($next_image1, $trans), 'Next Image', 'Next Image'); |
| 230 |
$next_image_url = theme_image("$file_dir/pblog/$nid". strtr($next_image, $trans), 'Next Image', 'Next Image'); |
$next_image_url = theme_image("$file_dir/pblog/$nid". strtr($next_image, $trans), 'Next Image', 'Next Image'); |
| 262 |
return $form; |
return $form; |
| 263 |
} |
} |
| 264 |
|
|
| 265 |
|
function pblog_update($node){ |
| 266 |
|
$file = file_save_upload('image'); |
| 267 |
|
if ($file) { |
| 268 |
|
drupal_set_message("file_check_upload = SUCCESS", 'status'); |
| 269 |
|
// for extra debugging drupal_set_message('$file = '. print_r($file, true), 'status'); |
| 270 |
|
} |
| 271 |
|
else { |
| 272 |
|
drupal_set_message("file_save_upload = FAILURE ". print_r($node, true), 'error'); |
| 273 |
|
drupal_set_message("Your file could not be upload please check it is not bigger than the upload_max_filesize of: ". ini_get(upload_max_filesize), 'error'); |
| 274 |
|
return; |
| 275 |
|
} |
| 276 |
|
|
| 277 |
|
// full path to the file |
| 278 |
|
$fpath = escapeshellcmd($file->filepath); |
| 279 |
|
|
| 280 |
|
$image_dir = file_create_path("pblog/$node->nid"); |
| 281 |
|
|
| 282 |
|
if (!file_exists($image_dir)) { |
| 283 |
|
mkdir($image_dir); |
| 284 |
|
drupal_set_message('This is weird, editing pblog but I need to creating directory '. $image_dir, 'status'); |
| 285 |
|
if (!file_exists("$image_dir")){ |
| 286 |
|
drupal_set_message('Unable to Create Directory '. $image_dir, 'error'); |
| 287 |
|
} |
| 288 |
|
} |
| 289 |
|
|
| 290 |
|
// check what kind of file it is, zip gzip or just a pic. Then move |
| 291 |
|
// unzip or do what ever. |
| 292 |
|
$extension = substr(strrchr($file->filename, '.'), 0); |
| 293 |
|
switch ($extension) { |
| 294 |
|
case ".gz": |
| 295 |
|
// untar and gzip stuff in dir |
| 296 |
|
`tar xvzf $fpath --directory $image_dir`; |
| 297 |
|
`rm /tmp/$fpath`; |
| 298 |
|
break; |
| 299 |
|
case ".zip": |
| 300 |
|
// assume unzip file into dir |
| 301 |
|
// `unzip /tmp/$f -d $image_dir`; |
| 302 |
|
// More complex but more portable way of doing things |
| 303 |
|
if (class_exists('ZipArchive')) { |
| 304 |
|
$zip = new ZipArchive; |
| 305 |
|
if ($zip->open($fpath) === TRUE) { |
| 306 |
|
$zip->extractTo($image_dir); |
| 307 |
|
$zip->close(); |
| 308 |
|
} |
| 309 |
|
else { |
| 310 |
|
form_set_error('image', t('The uploaded file was not a zip archive.')); |
| 311 |
|
} |
| 312 |
|
} |
| 313 |
|
else { |
| 314 |
|
drupal_set_message("php does not have built in zip support using system call to the unzip binary".'status'); |
| 315 |
|
`unzip $fpath -d $image_dir`; |
| 316 |
|
} |
| 317 |
|
|
| 318 |
|
`rm $fpath`; |
| 319 |
|
break; |
| 320 |
|
default: |
| 321 |
|
// assume your not dealing with an idiot and copy the file across. |
| 322 |
|
// What we actually need to do is loop through all the files and copy the ones that are useful |
| 323 |
|
// ie jpg jpeg bmp or gif images |
| 324 |
|
$dst = "pblog/$node->nid"; |
| 325 |
|
file_copy($fpath, $dst); |
| 326 |
|
break; |
| 327 |
|
} |
| 328 |
|
// make thumbnails of all files in the dir. |
| 329 |
|
if ($handle = opendir($image_dir)) { |
| 330 |
|
while (false !== ($file = readdir($handle))) { |
| 331 |
|
if ($file != '.' && $file != '..' && !preg_match("/-mini.jpg$/", $file) |
| 332 |
|
&& !preg_match("/-med.jpg$/", $file)) { |
| 333 |
|
// do a little cleaning |
| 334 |
|
$s = escapeshellcmd($file); |
| 335 |
|
$s_root = substr($s, 0, -4); |
| 336 |
|
// normal thumbnail |
| 337 |
|
/* old school using system calls |
| 338 |
|
$command = 'convert -size 120x120 "'. $image_dir .'/'. $s .'" -resize 120x120 +profile "*" "'. $image_dir .'/'. $s_root .'-mini.jpg"'; |
| 339 |
|
exec($command); |
| 340 |
|
// black and white thumbnail cos its arty |
| 341 |
|
$command2 = 'convert -size 120x120 "'. $image_dir .'/'. $s .'" -resize 120x120 +profile "*" -colorspace gray "'. $image_dir .'/'. $s_root .'-bw-mini.jpg"'; |
| 342 |
|
exec($command2); |
| 343 |
|
// medium size for dialup losers |
| 344 |
|
$command3 = 'convert -size 500x375 "'. $image_dir .'/'. $s .'" -resize 500x375 +profile "*" "'. $image_dir .'/'. $s_root .'-med.jpg"'; |
| 345 |
|
exec($command3); |
| 346 |
|
*/ |
| 347 |
|
image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-strip.jpg', 90, 90); |
| 348 |
|
if (file_exists($image_dir .'/'. $s_root .'-strip.jpg')) { |
| 349 |
|
drupal_set_message('Creating strip '. $s_root, 'status'); |
| 350 |
|
} else { |
| 351 |
|
drupal_set_message('Unable to creating thumbnail '. $s_root, 'error'); |
| 352 |
|
} |
| 353 |
|
|
| 354 |
|
image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-mini.jpg', 120, 120); |
| 355 |
|
if (file_exists($image_dir .'/'. $s_root .'-mini.jpg')) { |
| 356 |
|
drupal_set_message('Creating thumbnail '. $s_root, 'status'); |
| 357 |
|
} else { |
| 358 |
|
drupal_set_message('Unable to creating thumbnail '. $s_root, 'error'); |
| 359 |
|
} |
| 360 |
|
|
| 361 |
|
image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-med.jpg', 500, 375); |
| 362 |
|
if (file_exists($image_dir .'/'. $s_root .'-med.jpg')) { |
| 363 |
|
drupal_set_message('Creating medium image '. $s_root, 'status'); |
| 364 |
|
} else { |
| 365 |
|
drupal_set_message('Unable to creating medium image '. $s_root, 'error'); |
| 366 |
|
} |
| 367 |
|
} |
| 368 |
|
} |
| 369 |
|
} |
| 370 |
|
} |
| 371 |
|
|
| 372 |
/* |
/* |
| 373 |
* Function should do stuff to data from form. |
* Function should do stuff to data from form. |
| 379 |
// for extra debugging drupal_set_message('$file = '. print_r($file, true), 'status'); |
// for extra debugging drupal_set_message('$file = '. print_r($file, true), 'status'); |
| 380 |
} |
} |
| 381 |
else { |
else { |
| 382 |
drupal_set_message("file_save_upload = FAILURE ". print_r($node, true), 'status'); |
drupal_set_message("file_save_upload = FAILURE ". print_r($node, true), 'error'); |
| 383 |
|
drupal_set_message("Your file could not be upload please check it is not bigger than the upload_max_filesize of: ". ini_get(upload_max_filesize), 'error'); |
| 384 |
|
return; |
| 385 |
} |
} |
| 386 |
|
|
| 387 |
// full path to the file |
// full path to the file |
| 391 |
$pblog_dir = file_create_path("/pblog"); |
$pblog_dir = file_create_path("/pblog"); |
| 392 |
if (!file_exists($pblog_dir)) { |
if (!file_exists($pblog_dir)) { |
| 393 |
mkdir($pblog_dir); |
mkdir($pblog_dir); |
| 394 |
|
drupal_set_message('Creating Directory '. $pblog_dir, 'status'); |
| 395 |
|
if (!file_exists($pblog_dir)){ |
| 396 |
|
drupal_set_message('Unable to Create Directory '. $image_dir, 'error'); |
| 397 |
|
} |
| 398 |
} |
} |
| 399 |
$image_dir = file_create_path("pblog/$node->nid"); |
$image_dir = file_create_path("pblog/$node->nid"); |
| 400 |
|
|
| 401 |
if (!file_exists("$image_dir")) { |
if (!file_exists($image_dir)) { |
| 402 |
mkdir("$image_dir"); |
mkdir($image_dir); |
| 403 |
|
drupal_set_message('Creating Directory '. $image_dir, 'status'); |
| 404 |
|
if (!file_exists("$image_dir")){ |
| 405 |
|
drupal_set_message('Unable to Create Directory '. $image_dir, 'error'); |
| 406 |
|
} |
| 407 |
} |
} |
| 408 |
|
|
| 409 |
// check what kind of file it is, zip gzip or just a pic. Then move |
// check what kind of file it is, zip gzip or just a pic. Then move |
| 463 |
$command3 = 'convert -size 500x375 "'. $image_dir .'/'. $s .'" -resize 500x375 +profile "*" "'. $image_dir .'/'. $s_root .'-med.jpg"'; |
$command3 = 'convert -size 500x375 "'. $image_dir .'/'. $s .'" -resize 500x375 +profile "*" "'. $image_dir .'/'. $s_root .'-med.jpg"'; |
| 464 |
exec($command3); |
exec($command3); |
| 465 |
*/ |
*/ |
| 466 |
|
image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-strip.jpg', 90, 90); |
| 467 |
|
if (file_exists($image_dir .'/'. $s_root .'-strip.jpg')) { |
| 468 |
|
drupal_set_message('Creating strip '. $s_root, 'status'); |
| 469 |
|
} else { |
| 470 |
|
drupal_set_message('Unable to creating thumbnail '. $s_root, 'error'); |
| 471 |
|
} |
| 472 |
|
|
| 473 |
image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-mini.jpg', 120, 120); |
image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-mini.jpg', 120, 120); |
| 474 |
|
if (file_exists($image_dir .'/'. $s_root .'-mini.jpg')) { |
| 475 |
|
drupal_set_message('Creating thumbnail '. $s_root, 'status'); |
| 476 |
|
} else { |
| 477 |
|
drupal_set_message('Unable to creating thumbnail '. $s_root, 'error'); |
| 478 |
|
} |
| 479 |
|
|
| 480 |
image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-med.jpg', 500, 375); |
image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-med.jpg', 500, 375); |
| 481 |
|
if (file_exists($image_dir .'/'. $s_root .'-med.jpg')) { |
| 482 |
|
drupal_set_message('Creating medium image '. $s_root, 'status'); |
| 483 |
|
} else { |
| 484 |
|
drupal_set_message('Unable to creating medium image '. $s_root, 'error'); |
| 485 |
|
} |
| 486 |
} |
} |
| 487 |
} |
} |
| 488 |
} |
} |
| 492 |
if ($node->nid != '') { |
if ($node->nid != '') { |
| 493 |
system("rm -r pblog/$node->nid"); } |
system("rm -r pblog/$node->nid"); } |
| 494 |
else { |
else { |
| 495 |
print "not a valid node id"; |
drupal_set_message('not a valid node id', 'error'); |
| 496 |
} |
} |
| 497 |
} |
} |
| 498 |
|
|
| 499 |
|
function pblog_admin() { |
| 500 |
|
|
| 501 |
|
$form['onthisdate_maxdisp'] = array( |
| 502 |
|
'#type' => 'textfield', |
| 503 |
|
'#title' => t('Maximum number of links'), |
| 504 |
|
'#default_value' => variable_get('onthisdate_maxdisp', 3), |
| 505 |
|
'#size' => 2, |
| 506 |
|
'#maxlength' => 2, |
| 507 |
|
'#description' => t("The maximum number of links to display in the block."), |
| 508 |
|
'#required' => TRUE, |
| 509 |
|
); |
| 510 |
|
|
| 511 |
|
return system_settings_form($form); |
| 512 |
|
} |