| 1 |
<?php |
<?php |
| 2 |
// $Id: flickrstickr.module,v 1.26 2007/01/22 13:22:12 aronnovak Exp $ |
// $Id$ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 20 |
*/ |
*/ |
| 21 |
define('FLICKRSTICKR_TAGPREG_APPENDIX', '/<img [^<>]*src="http:\/\/static.flickr.com\/([0-9]+)\/([0-9]+)_(.{10}).*\#(left|center|right)_([0-9]*)_([0-9]*)"[^<>]*>/'); |
define('FLICKRSTICKR_TAGPREG_APPENDIX', '/<img [^<>]*src="http:\/\/static.flickr.com\/([0-9]+)\/([0-9]+)_(.{10}).*\#(left|center|right)_([0-9]*)_([0-9]*)"[^<>]*>/'); |
| 22 |
|
|
|
|
|
| 23 |
/** |
/** |
| 24 |
* If run PHP4, need to define file_put_contents. In PHP5 this is native function |
* If run PHP4, need to define file_put_contents. In PHP5 this is native function |
| 25 |
* |
* |
| 59 |
function flickrstickr_menu($may_cache) { |
function flickrstickr_menu($may_cache) { |
| 60 |
$items = array(); |
$items = array(); |
| 61 |
if (!$may_cache) { |
if (!$may_cache) { |
| 62 |
$items[] = array('path' => 'flickrstickr/xml/user', |
$items[] = array( |
| 63 |
'title' => t('xml proxy'), |
'path' => 'flickrstickr/xml/user', |
| 64 |
'callback' => 'flickrstickr_proxy_user', |
'title' => t('xml proxy'), |
| 65 |
'access' => TRUE, |
'callback' => 'flickrstickr_proxy_user', |
| 66 |
'type' => MENU_CALLBACK, |
'access' => TRUE, |
| 67 |
'weight' => 5); |
'type' => MENU_CALLBACK, |
| 68 |
$items[] = array('path' => 'flickrstickr/xml/images', |
'weight' => 5, |
| 69 |
'title' => t('xml proxy'), |
); |
| 70 |
'callback' => 'flickrstickr_proxy_images', |
$items[] = array( |
| 71 |
'access' => TRUE, |
'path' => 'flickrstickr/xml/images', |
| 72 |
'type' => MENU_CALLBACK, |
'title' => t('xml proxy'), |
| 73 |
'weight' => 5); |
'callback' => 'flickrstickr_proxy_images', |
| 74 |
|
'access' => TRUE, |
| 75 |
|
'type' => MENU_CALLBACK, |
| 76 |
|
'weight' => 5, |
| 77 |
|
); |
| 78 |
|
$items[] = array(
'path' => 'admin/settings/flickrstickr',
'title' => 'FlickrStickr',
'callback' => 'drupal_get_form',
'callback arguments' => array('flickrstickr_settings'),
'access' => user_access('administer site configuration'),
); |
| 79 |
} |
} |
| 80 |
return $items; |
return $items; |
| 81 |
} |
} |
| 87 |
function flickrstickr_proxy_user() { |
function flickrstickr_proxy_user() { |
| 88 |
header("Content-type: text/xml; charset=UTF-8"); |
header("Content-type: text/xml; charset=UTF-8"); |
| 89 |
$apikey = flickrstickr_getapikey(); |
$apikey = flickrstickr_getapikey(); |
| 90 |
$content = flickrstrick_get_url("http://www.flickr.com/services/rest/?method=flickr.people.findByUsername&api_key=".$apikey."&username=".urlencode(arg(3)), "r"); |
$content = flickrstrick_get_url("http://www.flickr.com/services/rest/?method=flickr.people.findByUsername&api_key=". $apikey ."&username=". urlencode(arg(3)), "r"); |
| 91 |
echo $content; |
echo $content; |
| 92 |
} |
} |
| 93 |
|
|
| 103 |
$userid = urlencode(arg(3)); |
$userid = urlencode(arg(3)); |
| 104 |
$page = urlencode(arg(5)); |
$page = urlencode(arg(5)); |
| 105 |
if ($userid == "!recent!") { |
if ($userid == "!recent!") { |
| 106 |
$query = "http://www.flickr.com/services/rest/?method=flickr.photos.getRecent&api_key=". $apikey ."&per_page=". $flickrstickr['imgno'] . "&page=" . $page; |
$query = "http://www.flickr.com/services/rest/?method=flickr.photos.getRecent&api_key=". $apikey ."&per_page=". $flickrstickr['imgno'] ."&page=". $page; |
| 107 |
} |
} |
| 108 |
else { |
else { |
| 109 |
$query = "http://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=". $apikey ."&per_page=". $flickrstickr['imgno'] . "&page=" . $page; |
$query = "http://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=". $apikey ."&per_page=". $flickrstickr['imgno'] ."&page=". $page; |
| 110 |
if (arg(3) != "all") { |
if (arg(3) != "all") { |
| 111 |
$query .= "&user_id=". $userid; |
$query .= "&user_id=". $userid; |
| 112 |
} |
} |
| 113 |
if (arg(4) != null) { |
if (arg(4) != null) { |
| 114 |
$query .= "&tags=". urlencode(arg(4)); |
$query .= "&tags=". urlencode(arg(4)); |
| 115 |
} |
} |
|
|
|
| 116 |
} |
} |
| 117 |
echo flickrstrick_get_url($query); |
echo flickrstrick_get_url($query); |
| 118 |
} |
} |
| 126 |
} |
} |
| 127 |
$flickrstickr = flickrstickr_getuserparam(); |
$flickrstickr = flickrstickr_getuserparam(); |
| 128 |
if ($type == 'form' && $category == 'account') { |
if ($type == 'form' && $category == 'account') { |
| 129 |
$options_link = array('none' => 'None', 'flickr_img' => 'Flickr image page'); |
$options_link = array( |
| 130 |
$options_sizes = array('100' => 'Thumbnail', '240' => 'Small', '500' => 'Medium', '1000' => 'Large'); |
'none' => 'None', |
| 131 |
$options_format = array('filter' => 'Filter tag', 'html' => 'plain html'); |
'flickr_img' => 'Flickr image page', |
| 132 |
|
); |
| 133 |
|
$options_sizes = array( |
| 134 |
|
'100' => 'Thumbnail', |
| 135 |
|
'240' => 'Small', |
| 136 |
|
'500' => 'Medium', |
| 137 |
|
'1000' => 'Large', |
| 138 |
|
); |
| 139 |
|
$options_format = array( |
| 140 |
|
'filter' => 'Filter tag', |
| 141 |
|
'html' => 'plain html', |
| 142 |
|
); |
| 143 |
$form = array(); |
$form = array(); |
| 144 |
$form['flickrstickr'] = array('#type' => 'fieldset', '#title' => t('Flickr image sticker settings')); |
$form['flickrstickr'] = array( |
| 145 |
$form['flickrstickr']['flickrstickr_imgno'] = array('#type' => 'textfield', |
'#type' => 'fieldset', |
| 146 |
'#title' => t('Flickr image sticker settings'), |
'#title' => t('Flickr image sticker settings'), |
| 147 |
'#default_value' => $flickrstickr['imgno'], |
); |
| 148 |
'#maxlength' => 5, |
$form['flickrstickr']['flickrstickr_imgno'] = array( |
| 149 |
'#size' => 5, |
'#type' => 'textfield', |
| 150 |
'#description' => t('Number of recent photos to retrieve.'), |
'#title' => t('Flickr image sticker settings'), |
| 151 |
'#required' => TRUE); |
'#default_value' => $flickrstickr['imgno'], |
| 152 |
$form['flickrstickr']['flickrstickr_username'] = array('#type' => 'textfield', |
'#maxlength' => 5, |
| 153 |
'#title' => t('Default flickr username'), |
'#size' => 5, |
| 154 |
'#default_value' => $flickrstickr['username'], |
'#description' => t('Number of recent photos to retrieve.'), |
| 155 |
'#maxlength' => 15, |
'#required' => TRUE, |
| 156 |
'#size' => 15); |
); |
| 157 |
$form['flickrstickr']['flickrstickr_link'] = array('#type' => 'select', |
$form['flickrstickr']['flickrstickr_username'] = array( |
| 158 |
'#title' => t('Photo Link Destination'), |
'#type' => 'textfield', |
| 159 |
'#default_value' => $flickrstickr['link'], |
'#title' => t('Default flickr username'), |
| 160 |
'#options' => $options_link, |
'#default_value' => $flickrstickr['username'], |
| 161 |
'#description' => t('Where the photos inserted into your post should link to.'), |
'#maxlength' => 15, |
| 162 |
'#required' => TRUE); |
'#size' => 15, |
| 163 |
/*$form['flickrstickr']['flickrstickr_format'] = array('#type' => 'select', |
); |
| 164 |
'#title' => t('Inserted tag'), |
$form['flickrstickr']['flickrstickr_link'] = array( |
| 165 |
'#default_value' => $flickrstickr['format'], |
'#type' => 'select', |
| 166 |
'#options' => $options_format, |
'#title' => t('Photo Link Destination'), |
| 167 |
'#description' => t('TODO'), |
'#default_value' => $flickrstickr['link'], |
| 168 |
'#required' => TRUE); |
'#options' => $options_link, |
| 169 |
$form['flickrstickr']['flickrstickr_size'] = array('#type' => 'select', |
'#description' => t('Where the photos inserted into your post should link to.'), |
| 170 |
'#title' => t('Inserted tag'), |
'#required' => TRUE, |
| 171 |
'#default_value' => $flickrstickr['size'], |
); |
| 172 |
'#options' => $options_sizes, |
return $form; |
|
'#description' => t('TODO'), |
|
|
'#required' => TRUE);*/ |
|
|
|
|
|
if (flickrstickr_isdrupal47()) { |
|
|
return $form; |
|
|
} |
|
|
else { |
|
|
$group = ""; |
|
|
foreach ($form['flickrstickr'] as $key => $value) { |
|
|
if (preg_match('/\#/', $key)) { |
|
|
continue; |
|
|
} |
|
|
if ($value['#type'] == 'textfield') { |
|
|
$group .= form_textfield($value['#title'], $key, $value['#value'], $value['#size'], $value['#maxlength'], $value['#description']); |
|
|
} |
|
|
else if ($value['#type'] == 'select') { |
|
|
$group .= form_select($value['#title'], $key, $value['#default_value'], $value['#options'], $value['#description']); |
|
|
} |
|
|
} |
|
|
return array(array('title ' => t('Flickr sticker settings'), 'data' => form_group(t('Flickrstickr'), $group), 'weight' => 2)); |
|
|
} |
|
| 173 |
} |
} |
|
return array(); |
|
| 174 |
} |
} |
| 175 |
|
|
| 176 |
/** |
/** |
| 178 |
*/ |
*/ |
| 179 |
function flickrstickr_form_alter($form_id, & $form) { |
function flickrstickr_form_alter($form_id, & $form) { |
| 180 |
if (preg_match('/_node_form$/', $form_id) && user_access('flickrstickr access')) { |
if (preg_match('/_node_form$/', $form_id) && user_access('flickrstickr access')) { |
| 181 |
$form['flickrstickr'] = array('#type' => 'fieldset', |
$form['flickrstickr'] = array( |
| 182 |
'#title' => t('Flickr image insert'), |
'#type' => 'fieldset', |
| 183 |
'#collapsible' => TRUE, |
'#title' => t('Flickr image insert'), |
| 184 |
'#collapsed' => TRUE, |
'#collapsible' => TRUE, |
| 185 |
'#weight' => 20); |
'#collapsed' => TRUE, |
| 186 |
$form['flickrstickr']['images'] = array('#type' => 'markup', |
'#weight' => 20, |
| 187 |
'#value' => _flickrstickr_htmlpart(), |
); |
| 188 |
'#weight' => -1); |
$form['flickrstickr']['images'] = array( |
| 189 |
|
'#type' => 'markup', |
| 190 |
|
'#value' => _flickrstickr_htmlpart(), |
| 191 |
|
'#weight' => -1, |
| 192 |
|
); |
| 193 |
} |
} |
| 194 |
} |
} |
| 195 |
|
|
| 200 |
global $user; |
global $user; |
| 201 |
global $base_url; |
global $base_url; |
| 202 |
$flickrstickr = flickrstickr_getuserparam(); |
$flickrstickr = flickrstickr_getuserparam(); |
| 203 |
$base_path = ''; |
$base_path = base_path(); |
|
if (flickrstickr_isdrupal47()) { |
|
|
$base_path = base_path(); |
|
|
} |
|
| 204 |
drupal_set_html_head('<link rel="stylesheet" type="text/css" href="'. $base_path. drupal_get_path('module', 'flickrstickr').'/flickrstickr.css" media="screen" />'); |
drupal_set_html_head('<link rel="stylesheet" type="text/css" href="'. $base_path. drupal_get_path('module', 'flickrstickr').'/flickrstickr.css" media="screen" />'); |
| 205 |
drupal_set_html_head('<script src="'. $base_path. drupal_get_path('module', 'flickrstickr'). '/flickrstickr.js"></script>'); |
drupal_set_html_head('<script src="'. $base_path. drupal_get_path('module', 'flickrstickr'). '/flickrstickr.js"></script>'); |
| 206 |
// This line is needed because of floating image selector |
// This line is needed because of floating image selector |
| 270 |
else { |
else { |
| 271 |
$inserted = '<img class=\"flickrstickr_image\" src=\"http://static.flickr.com/"+images[id].server+"/"+images[id].id+"_"+images[id].secret+".jpg\"/>'; |
$inserted = '<img class=\"flickrstickr_image\" src=\"http://static.flickr.com/"+images[id].server+"/"+images[id].id+"_"+images[id].secret+".jpg\"/>'; |
| 272 |
} |
} |
|
|
|
| 273 |
if ($flickrstickr['link'] != 'none') { |
if ($flickrstickr['link'] != 'none') { |
| 274 |
$inserted = '<a href=\"http://www.flickr.com/photos/"+images[id].owner+"/"+images[id].id+"\">'. $inserted .'</a>'; |
$inserted = '<a href=\"http://www.flickr.com/photos/"+images[id].owner+"/"+images[id].id+"\">'. $inserted .'</a>'; |
| 275 |
} |
} |
| 284 |
*/ |
*/ |
| 285 |
function flickrstickr_getuserparam() { |
function flickrstickr_getuserparam() { |
| 286 |
global $user; |
global $user; |
| 287 |
$flickrstickr['link'] = (isset($user->flickrstickr_link) ? $user->flickrstickr_link : "none"); |
$flickrstickr['link'] = isset($user->flickrstickr_link) ? $user->flickrstickr_link : "none"; |
| 288 |
$flickrstickr['imgno'] = (isset($user->flickrstickr_imgno) ? $user->flickrstickr_imgno : 10); |
$flickrstickr['imgno'] = isset($user->flickrstickr_imgno) ? $user->flickrstickr_imgno : 10; |
| 289 |
$flickrstickr['size'] = (isset($user->flickrstickr_size) ? $user->flickrstickr_size : "100"); |
$flickrstickr['size'] = isset($user->flickrstickr_size) ? $user->flickrstickr_size : "100"; |
| 290 |
$flickrstickr['format'] = (isset($user->flickrstickr_format) ? $user->flickrstickr_format : "filter"); |
$flickrstickr['format'] = isset($user->flickrstickr_format) ? $user->flickrstickr_format : "filter"; |
| 291 |
$flickrstickr['username'] = (isset($user->flickrstickr_username) ? $user->flickrstickr_username : ""); |
$flickrstickr['username'] = isset($user->flickrstickr_username) ? $user->flickrstickr_username : ""; |
| 292 |
return $flickrstickr; |
return $flickrstickr; |
| 293 |
} |
} |
| 294 |
|
|
| 312 |
return $output; |
return $output; |
| 313 |
} |
} |
| 314 |
|
|
| 315 |
|
/* |
| 316 |
global $user; |
global $user; |
| 317 |
$node = array('uid' => $user->uid, 'name' => $user->name, 'type' => 'image'); |
$node = array('uid' => $user->uid, 'name' => $user->name, 'type' => 'image'); |
| 318 |
|
*/ |
| 319 |
|
|
| 320 |
/** |
/** |
| 321 |
* implements hook_filter |
* implements hook_filter |
| 334 |
// The order is important! The APPENDIX filter must be before the FLICKRTAG filter! |
// The order is important! The APPENDIX filter must be before the FLICKRTAG filter! |
| 335 |
$text = preg_replace_callback(FLICKRSTICKR_TAGPREG_APPENDIX, 'flickrstickr_processappendix', str_replace("<img", "\n<img", $text)); |
$text = preg_replace_callback(FLICKRSTICKR_TAGPREG_APPENDIX, 'flickrstickr_processappendix', str_replace("<img", "\n<img", $text)); |
| 336 |
$text = preg_replace_callback(FLICKRSTICKR_TAGPREG_FLICKRTAG, 'flickrstickr_processflickrtag', $text); |
$text = preg_replace_callback(FLICKRSTICKR_TAGPREG_FLICKRTAG, 'flickrstickr_processflickrtag', $text); |
|
|
|
| 337 |
return $text; |
return $text; |
| 338 |
default: |
default: |
| 339 |
return $text; |
return $text; |
| 340 |
} |
} |
| 341 |
} |
} |
| 342 |
|
|
|
|
|
| 343 |
/** |
/** |
| 344 |
* filter callback function for flicktrag solution |
* filter callback function for flicktrag solution |
| 345 |
* |
* |
| 491 |
*/ |
*/ |
| 492 |
function flickrstickr_getlocalrurl($nid, $size, &$orient) { |
function flickrstickr_getlocalrurl($nid, $size, &$orient) { |
| 493 |
global $base_url; |
global $base_url; |
| 494 |
$image = node_load(array('nid' => $nid)); |
$image = node_load($nid); |
| 495 |
if (!$image) { |
if (!$image) { |
| 496 |
return ''; |
return ''; |
| 497 |
} |
} |
| 731 |
* implements hook_settings |
* implements hook_settings |
| 732 |
*/ |
*/ |
| 733 |
function flickrstickr_settings() { |
function flickrstickr_settings() { |
| 734 |
if (!function_exists('_image_build_derivatives')) { |
$form = array(); |
| 735 |
drupal_set_message(t('Flickrstickr requires image module. Please install or enable it!'), 'error'); |
$form['settings'] = array( |
| 736 |
} |
'#type' => 'fieldset', |
| 737 |
if (!user_access('flickrstickr admin')) { |
'#title' => t('FlickrStickr settings'), |
| 738 |
drupal_access_denied(); |
); |
| 739 |
} |
$form['settings']['flickrstickr_flickrkey'] = array( |
| 740 |
|
'#type' => 'textfield', |
| 741 |
$form['settings'] = array('#type' => 'fieldset', |
'#title' => t('Flickrapi key'), |
| 742 |
'#title' => t('FlickrStickr settings')); |
'#default_value' => flickrstickr_getapikey(), |
| 743 |
$form['settings']['flickrstickr_flickrkey'] = array('#type' => 'textfield', |
'#maxlength' => 36, |
| 744 |
'#title' => t('Flickrapi key'), |
'#size' => 36, |
| 745 |
'#default_value' => flickrstickr_getapikey(), |
); |
| 746 |
'#maxlength' => 36, |
return system_settings_form($form); |
|
'#size' => 36); |
|
|
return $form; |
|
| 747 |
} |
} |
| 748 |
|
|
| 749 |
/** |
/** |
| 776 |
curl_setopt($ch, CURLOPT_URL, $url); |
curl_setopt($ch, CURLOPT_URL, $url); |
| 777 |
curl_setopt($ch, CURLOPT_HEADER, 0); |
curl_setopt($ch, CURLOPT_HEADER, 0); |
| 778 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 779 |
return curl_exec($ch); |
$output = curl_exec($ch); |
| 780 |
|
$error = curl_error($ch); |
| 781 |
|
if($error) watchdog("flickrstickr", $error); |
| 782 |
|
curl_close($ch); |
| 783 |
|
return $output; |
| 784 |
} |
} |
|
|
|
|
?> |
|