| 1 |
<?php |
<?php |
| 2 |
// $Id: flickrstickr.module,v 1.20 2006/12/17 18:21:32 aronnovak Exp $ |
// $Id: flickrstickr.module,v 1.21 2006/12/17 18:26:51 aronnovak Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 31 |
function flickrstickr_file_put_contents($filename, $data) { |
function flickrstickr_file_put_contents($filename, $data) { |
| 32 |
$mode = 'w'; |
$mode = 'w'; |
| 33 |
$file = @fopen($filename, $mode); |
$file = @fopen($filename, $mode); |
| 34 |
if ($f === false) { |
if ($file === FALSE) { |
| 35 |
return 0; |
return 0; |
| 36 |
} |
} |
| 37 |
else { |
else { |
| 361 |
$size = $matches[5]; |
$size = $matches[5]; |
| 362 |
$popup_size = isset($matches[6]) ? $matches[6] : $size; |
$popup_size = isset($matches[6]) ? $matches[6] : $size; |
| 363 |
} |
} |
|
// change alex: for the time being, only pull from local cache |
|
|
//find cached version |
|
|
// change alex: |
|
|
// $filepath = "files/images/".$matches[1]."_".$matches[2]."_".$matches[3].".jpg"; |
|
|
$filepath = "images/". $matches[1] ."_". $matches[2] ."_". $matches[3] .".jpg"; |
|
|
$result = db_query("SELECT nid FROM {files} WHERE filepath='%s'", $filepath); |
|
| 364 |
|
|
| 365 |
$filepath = "files/". $filepath; |
$filepath = "images/". $matches[1] ."_". $matches[2] ."_". $matches[3]; |
| 366 |
|
$result = db_query("SELECT nid, filepath FROM {files} WHERE filepath LIKE '%s'", '%' .$filepath. '%'); |
| 367 |
|
|
| 368 |
|
|
| 369 |
// In any case link the original image |
// In any case link the original image |
| 370 |
$big_path = $filepath; |
$big_path = $filepath; |
| 371 |
$image = db_fetch_object($result); |
$image = db_fetch_object($result); |
| 372 |
|
$filepath = $image->filepath; |
| 373 |
$orient = 0; |
$orient = 0; |
| 374 |
if ($image) { |
if ($image) { |
| 375 |
$nid = $image->nid; |
$nid = $image->nid; |
| 435 |
} |
} |
| 436 |
|
|
| 437 |
/** |
/** |
| 438 |
* filter callback function for url appendix solution |
* Filter callback function for url appendix solution |
| 439 |
* |
* |
| 440 |
*/ |
*/ |
| 441 |
function flickrstickr_processappendix($matches) { |
function flickrstickr_processappendix($matches) { |
|
//print_r($matches); |
|
| 442 |
$flickrtag = '[flickr:' . $matches[1] . '/' . $matches[2] . '/' . $matches[3] |
$flickrtag = '[flickr:' . $matches[1] . '/' . $matches[2] . '/' . $matches[3] |
| 443 |
. '|' . $matches[4] . '|' . $matches[5] . '|' . $matches[6] . ']'; |
. '|' . $matches[4] . '|' . $matches[5] . '|' . $matches[6] . ']'; |
|
//print_r($flickrtag); |
|
| 444 |
return $flickrtag; |
return $flickrtag; |
| 445 |
} |
} |
| 446 |
|
|
| 535 |
|
|
| 536 |
global $user; |
global $user; |
| 537 |
$image_info = flickrstickr_getflickrimageinfo($matches[2], $matches[3]); |
$image_info = flickrstickr_getflickrimageinfo($matches[2], $matches[3]); |
| 538 |
//original (Large) size always exist in jpeg format |
|
| 539 |
$orient = 0; |
$orient = 0; |
| 540 |
// change alex |
// File extension detection later! |
| 541 |
// $path = "files/flickrstickr/".$matches[1]."_".$matches[2]."_".$matches[3].'.jpg'; |
$path = "files/images/". $matches[1] ."_". $matches[2] ."_". $matches[3]; |
|
$path = "files/images/". $matches[1] ."_". $matches[2] ."_". $matches[3] .'.jpg'; |
|
| 542 |
// think of leaving out the file_exists check |
// think of leaving out the file_exists check |
| 543 |
if (file_exists($path)) { |
if (file_exists($path)) { |
| 544 |
//check that the node still exist |
//check that the node still exist |
| 545 |
$filepath = "images/". $matches[1] ."_". $matches[2] ."_". $matches[3] .".jpg"; |
$filepath = "images/". $matches[1] ."_". $matches[2] ."_". $matches[3]; |
| 546 |
$result = db_query("SELECT nid FROM {files} WHERE filepath='%s'", $filepath); |
$result = db_query("SELECT nid FROM {files} WHERE filepath LIKE %'%s'%", $filepath); |
| 547 |
$image = db_fetch_object($result); |
$image = db_fetch_object($result); |
| 548 |
if ($image) { |
if ($image) { |
| 549 |
return ''; |
return ''; |
| 561 |
$max = $i; |
$max = $i; |
| 562 |
} |
} |
| 563 |
} |
} |
|
//$url = flickrstickr_getflickrurl($matches[1],$matches[2],$matches[3],'o',$orient); |
|
| 564 |
|
|
| 565 |
$url = $sizes[$max]['source']; |
$url = $sizes[$max]['source']; |
| 566 |
|
// Nasty thing: the last 3 character of the url, but the flickr API don't send the originaltype field reliably |
| 567 |
|
$extension = substr($url, strlen($url) - 3, 3); |
| 568 |
|
$path .= '.'. $extension; |
| 569 |
$content = flickrstrick_get_url($url); |
$content = flickrstrick_get_url($url); |
| 570 |
flickrstickr_file_put_contents($path, $content); |
flickrstickr_file_put_contents($path, $content); |
| 571 |
|
|
| 658 |
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); |
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); |
| 659 |
xml_parse_into_struct($parser, $xml, $values, $tags); |
xml_parse_into_struct($parser, $xml, $values, $tags); |
| 660 |
xml_parser_free($parser); |
xml_parser_free($parser); |
| 661 |
|
|
| 662 |
foreach ($tags['title'] as $key) { |
foreach ($tags['title'] as $key) { |
| 663 |
if ($values[$key]['type'] != 'complete') { |
if ($values[$key]['type'] != 'complete') { |
| 664 |
continue; |
continue; |
| 674 |
$info['description'] = $values[$key]['value']; |
$info['description'] = $values[$key]['value']; |
| 675 |
break; |
break; |
| 676 |
} |
} |
| 677 |
if ($info['description'] == null) { |
if ($info['description'] == NULL) { |
| 678 |
$info['description'] = '';; |
$info['description'] = '';; |
| 679 |
} |
} |
| 680 |
return $info; |
return $info; |