| | 70 | function get_images_from_uri($uri) { |
|---|
| | 71 | $content = wp_remote_fopen($uri); |
|---|
| | 72 | if ( false === $content ) |
|---|
| | 73 | return ''; |
|---|
| | 74 | |
|---|
| | 75 | $pattern = '/src=[\'"]?([^\'" >]+)[\'" >]/'; |
|---|
| | 76 | preg_match_all($pattern, $content, $matches); |
|---|
| | 77 | if ( empty($matches[1]) ) |
|---|
| | 78 | return ''; |
|---|
| | 79 | |
|---|
| | 80 | $from_host = parse_url($uri); |
|---|
| | 81 | $from_host = $from_host['host']; |
|---|
| | 82 | $from_host = explode('.', $from_host); |
|---|
| | 83 | $count = count($from_host); |
|---|
| | 84 | $from_host = $from_host[$count - 2] . '.' . $from_host[$count - 1]; |
|---|
| | 85 | |
|---|
| | 86 | $sources = array(); |
|---|
| | 87 | foreach ($matches[1] as $src) { |
|---|
| | 88 | if ( false !== strpos($src, '&') ) |
|---|
| | 89 | continue; |
|---|
| | 90 | |
|---|
| | 91 | $img_host = parse_url($src); |
|---|
| | 92 | $img_host = $img_host['host']; |
|---|
| | 93 | if ( false === strpos($img_host, $from_host) ) |
|---|
| | 94 | continue; |
|---|
| | 95 | |
|---|
| | 96 | $sources[] = $src; |
|---|
| | 97 | } |
|---|
| | 98 | return "'" . implode("','", $sources) . "'"; |
|---|
| | 99 | } |
|---|
| | 100 | |
|---|
| | 101 | // Clean up the data being passed in |
|---|
| | 102 | $title = stripslashes($_GET['t']); |
|---|
| | 103 | |
|---|
| | 104 | if ( !empty($_GET['load']) && 'photo' == $_GET['load'] ) { |
|---|
| | 105 | ?> |
|---|
| | 106 | <script type="text/javascript"> |
|---|
| | 107 | <?php if ( user_can_richedit() ) { |
|---|
| | 108 | $language = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); |
|---|
| | 109 | ?> |
|---|
| | 110 | |
|---|
| | 111 | tinyMCE.init({ |
|---|
| | 112 | mode: "textareas", |
|---|
| | 113 | editor_selector: "mceEditor", |
|---|
| | 114 | language : "<?php echo $language; ?>", |
|---|
| | 115 | width: "100%", |
|---|
| | 116 | theme : "advanced", |
|---|
| | 117 | theme_advanced_buttons1 : "bold,italic,underline,blockquote,separator,strikethrough,bullist,numlist,undo,redo,link,unlink", |
|---|
| | 118 | theme_advanced_buttons2 : "", |
|---|
| | 119 | theme_advanced_buttons3 : "", |
|---|
| | 120 | theme_advanced_toolbar_location : "top", |
|---|
| | 121 | theme_advanced_toolbar_align : "left", |
|---|
| | 122 | theme_advanced_statusbar_location : "bottom", |
|---|
| | 123 | theme_advanced_resizing : true, |
|---|
| | 124 | theme_advanced_resize_horizontal : false, |
|---|
| | 125 | skin : "wp_theme", |
|---|
| | 126 | dialog_type : "modal", |
|---|
| | 127 | relative_urls : false, |
|---|
| | 128 | remove_script_host : false, |
|---|
| | 129 | convert_urls : false, |
|---|
| | 130 | apply_source_formatting : false, |
|---|
| | 131 | remove_linebreaks : true, |
|---|
| | 132 | accessibility_focus : false, |
|---|
| | 133 | tab_focus : ":next", |
|---|
| | 134 | plugins : "safari,inlinepopups" |
|---|
| | 135 | }); |
|---|
| | 136 | <?php } ?> |
|---|
| | 137 | var last = null; |
|---|
| | 138 | function pick(img) { |
|---|
| | 139 | if (last) last.style.backgroundColor = '#f4f4f4'; |
|---|
| | 140 | if (img) { |
|---|
| | 141 | document.getElementById('photo_src').value = img.src; |
|---|
| | 142 | img.style.backgroundColor = '#44f'; |
|---|
| | 143 | } |
|---|
| | 144 | last = img; |
|---|
| | 145 | return false; |
|---|
| | 146 | } |
|---|
| | 147 | |
|---|
| | 148 | jQuery(document).ready(function() { |
|---|
| | 149 | var img, img_tag, aspect, w, h, skip, i, strtoappend = ""; |
|---|
| | 150 | var my_src = [<?php echo get_images_from_uri(clean_url($_GET['u'])); ?>]; |
|---|
| | 151 | |
|---|
| | 152 | for (i = 0; i < my_src.length; i++) { |
|---|
| | 153 | img = new Image(); |
|---|
| | 154 | img.src = my_src[i]; |
|---|
| | 155 | img_attr = 'id="img' + i + '" onclick="pick(this);"'; |
|---|
| | 156 | skip = false; |
|---|
| | 157 | if (img.width && img.height) { |
|---|
| | 158 | if (img.width * img.height < 2500) skip = true; |
|---|
| | 159 | aspect = img.width / img.height; |
|---|
| | 160 | if (aspect > 1) { |
|---|
| | 161 | // Image is wide |
|---|
| | 162 | scale = 75 / img.width; |
|---|
| | 163 | } else { |
|---|
| | 164 | // Image is tall or square |
|---|
| | 165 | scale = 75 / img.height; |
|---|
| | 166 | } |
|---|
| | 167 | if (scale < 1) { |
|---|
| | 168 | w = parseInt(img.width * scale); |
|---|
| | 169 | h = parseInt(img.height * scale); |
|---|
| | 170 | } else { |
|---|
| | 171 | w = img.width; |
|---|
| | 172 | h = img.height; |
|---|
| | 173 | } |
|---|
| | 174 | img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"'; |
|---|
| | 175 | } |
|---|
| | 176 | if (!skip) { |
|---|
| | 177 | strtoappend += '<a href="' + img.src + '" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>' |
|---|
| | 178 | } |
|---|
| | 179 | } |
|---|
| | 180 | jQuery('#img_container').html(strtoappend); |
|---|
| | 181 | |
|---|
| | 182 | tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox |
|---|
| | 183 | }); |
|---|
| | 184 | </script> |
|---|
| | 185 | |
|---|
| | 186 | <form action="quick-post.php?action=post" method="post" id="photo_form"> |
|---|
| | 187 | <?php wp_nonce_field('quick-post') ?> |
|---|
| | 188 | <input type="hidden" name="source" value="bookmarklet"/> |
|---|
| | 189 | <input type="hidden" name="post_type" value="photo"/> |
|---|
| | 190 | <div id="posting"> |
|---|
| | 191 | <h2><?php _e('Post Title') ?></h2> |
|---|
| | 192 | <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/> |
|---|
| | 193 | |
|---|
| | 194 | <h2><?php _e('Caption') ?></h2> |
|---|
| | 195 | <div class="editor-container"> |
|---|
| | 196 | <textarea name="content" id="photo_post_two" style="height:130px;width:100%;" class="mceEditor"><?php echo stripslashes($_GET['s']);?> |
|---|
| | 197 | <br><a href="<?php echo clean_url($_GET['u']);?>"><?php echo $title;?></a></textarea> |
|---|
| | 198 | </div> |
|---|
| | 199 | |
|---|
| | 200 | <h2><?php _e('Photo URL') ?></h2> |
|---|
| | 201 | <input name="photo_src" id="photo_src" class="text" onkeydown="pick(0);"/> |
|---|
| | 202 | |
|---|
| | 203 | <style type="text/css"> |
|---|
| | 204 | #img_container img { |
|---|
| | 205 | width: 75px; |
|---|
| | 206 | height: 75px; |
|---|
| | 207 | padding: 2px; |
|---|
| | 208 | background-color: #f4f4f4; |
|---|
| | 209 | margin-right: 7px; |
|---|
| | 210 | margin-bottom: 7px; |
|---|
| | 211 | cursor: pointer; |
|---|
| | 212 | } |
|---|
| | 213 | </style> |
|---|
| | 214 | <div id="img_container" style="border:solid 1px #ccc; background-color:#f4f4f4; padding:5px; width:370px; margin-top:10px; overflow:auto; height:100px;"> |
|---|
| | 215 | </div> |
|---|
| | 216 | |
|---|
| | 217 | <h2><?php _e('Link Photo to following URL') ?></h2><?php _e('(leave blank to leave the photo unlinked)') ?> |
|---|
| | 218 | <input name="photo_link" id="photo_link" class="text" value="<?php echo attribute_escape($_GET['u']);?>"/> |
|---|
| | 219 | |
|---|
| | 220 | <?php tag_input(); ?> |
|---|
| | 221 | |
|---|
| | 222 | <div> |
|---|
| | 223 | <input type="submit" value="<?php _e('Create Photo') ?>" style="margin-top:15px;" onclick="document.getElementById('photo_saving').style.display = '';"/> |
|---|
| | 224 | |
|---|
| | 225 | <a href="#" onclick="if (confirm('<?php _e('Are you sure?') ?>')) { self.close(); } else { return false; }" style="color:#007BFF;"><?php _e('Cancel') ?></a> |
|---|
| | 226 | <img src="/images/bookmarklet_loader.gif" alt="" id="photo_saving" style="width:16px; height:16px; vertical-align:-4px; display:none;"/> |
|---|
| | 227 | </div> |
|---|
| | 228 | </div> |
|---|
| | 229 | <div id="categories"> |
|---|
| | 230 | <h2><?php _e('Categories') ?></h2> |
|---|
| | 231 | <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> |
|---|
| | 232 | <?php wp_category_checklist($post_ID) ?> |
|---|
| | 233 | </ul> |
|---|
| | 234 | </div> |
|---|
| | 235 | </form> |
|---|
| | 236 | <?php |
|---|
| | 237 | exit; |
|---|
| | 238 | } |
|---|
| 196 | | </div> |
|---|
| 197 | | |
|---|
| 198 | | <!-- Photo --> |
|---|
| 199 | | <div id="section-2"> |
|---|
| 200 | | <form action="quick-post.php?action=post" method="post" id="photo_form"> |
|---|
| 201 | | <?php wp_nonce_field('quick-post') ?> |
|---|
| 202 | | <input type="hidden" name="source" value="bookmarklet"/> |
|---|
| 203 | | <input type="hidden" name="post_type" value="photo"/> |
|---|
| 204 | | <div id="posting"> |
|---|
| 205 | | <h2><?php _e('Post Title') ?></h2> |
|---|
| 206 | | <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/> |
|---|
| 207 | | |
|---|
| 208 | | <h2><?php _e('Caption') ?></h2> |
|---|
| 209 | | <div class="editor-container"> |
|---|
| 210 | | <textarea name="content" id="photo_post_two" style="height:130px;width:100%;" class="mceEditor"><?php echo "" .stripslashes($_GET['s']);?> |
|---|
| 211 | | <br><a href="<?php echo clean_url($_GET['u']);?>"><?php echo $title;?></a></textarea> |
|---|
| 212 | | </div> |
|---|
| 213 | | |
|---|
| 214 | | <h2><?php _e('Photo URL') ?></h2> |
|---|
| 215 | | <input name="photo_src" id="photo_src" class="text" onkeydown="pick(0);"/> |
|---|
| 216 | | |
|---|
| 217 | | <style type="text/css"> |
|---|
| 218 | | #img_container img { |
|---|
| 219 | | width: 75px; |
|---|
| 220 | | height: 75px; |
|---|
| 221 | | padding: 2px; |
|---|
| 222 | | background-color: #f4f4f4; |
|---|
| 223 | | margin-right: 7px; |
|---|
| 224 | | margin-bottom: 7px; |
|---|
| 225 | | cursor: pointer; |
|---|
| 226 | | } |
|---|
| 227 | | </style> |
|---|
| 228 | | |
|---|
| 229 | | <div id="img_container" style="border:solid 1px #ccc; background-color:#f4f4f4; padding:5px; width:370px; margin-top:10px; overflow:auto; height:100px;"> |
|---|
| 230 | | <script type="text/javascript"> |
|---|
| 231 | | var img, img_tag, aspect, w, h, skip, i, strtoappend = ""; |
|---|
| 232 | | var my_src = ['<?php echo str_replace(",", "','", rtrim($_GET['imagez'], ","));?>']; |
|---|
| 233 | | var last = null; |
|---|
| 234 | | |
|---|
| 235 | | function pick(img) { |
|---|
| 236 | | if (last) last.style.backgroundColor = '#f4f4f4'; |
|---|
| 237 | | if (img) { |
|---|
| 238 | | document.getElementById('photo_src').value = img.src; |
|---|
| 239 | | img.style.backgroundColor = '#44f'; |
|---|
| 240 | | } |
|---|
| 241 | | last = img; |
|---|
| 242 | | return false; |
|---|
| 243 | | } |
|---|
| 244 | | for (i = 0; i < my_src.length; i++) { |
|---|
| 245 | | img = new Image(); |
|---|
| 246 | | img.src = my_src[i]; |
|---|
| 247 | | img_attr = 'id="img' + i + '" onclick="pick(this);"'; |
|---|
| 248 | | skip = false; |
|---|
| 249 | | if (img.width && img.height) { |
|---|
| 250 | | if (img.width * img.height < 2500) skip = true; |
|---|
| 251 | | aspect = img.width / img.height; |
|---|
| 252 | | if (aspect > 1) { |
|---|
| 253 | | // Image is wide |
|---|
| 254 | | scale = 75 / img.width; |
|---|
| 255 | | } else { |
|---|
| 256 | | // Image is tall or square |
|---|
| 257 | | scale = 75 / img.height; |
|---|
| 258 | | } |
|---|
| 259 | | if (scale < 1) { |
|---|
| 260 | | w = parseInt(img.width * scale); |
|---|
| 261 | | h = parseInt(img.height * scale); |
|---|
| 262 | | } else { |
|---|
| 263 | | w = img.width; |
|---|
| 264 | | h = img.height; |
|---|
| 265 | | } |
|---|
| 266 | | img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"'; |
|---|
| 267 | | } |
|---|
| 268 | | if (!skip) { |
|---|
| 269 | | strtoappend += '<a href="' + img.src + '" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>' |
|---|
| 270 | | } |
|---|
| 271 | | } |
|---|
| 272 | | if (jQuery.browser.safari) { |
|---|
| 273 | | document.getElementById('img_container').innerHTML = strtoappend; |
|---|
| 274 | | } else { |
|---|
| 275 | | document.write(strtoappend); |
|---|
| 276 | | } |
|---|
| 277 | | </script> |
|---|
| 278 | | </div> |
|---|
| 279 | | |
|---|
| 280 | | <h2><?php _e('Link Photo to following URL') ?></h2><?php _e('(leave blank to leave the photo unlinked)') ?> |
|---|
| 281 | | <input name="photo_link" id="photo_link" class="text" value="<?php echo attribute_escape($_GET['u']);?>"/> |
|---|
| 282 | | |
|---|
| 283 | | <?php tag_input(); ?> |
|---|
| 284 | | |
|---|
| 285 | | <div> |
|---|
| 286 | | <input type="submit" value="<?php _e('Create Photo') ?>" style="margin-top:15px;" onclick="document.getElementById('photo_saving').style.display = '';"/> |
|---|
| 287 | | |
|---|
| 288 | | <a href="#" onclick="if (confirm('<?php _e('Are you sure?') ?>')) { self.close(); } else { return false; }" style="color:#007BFF;"><?php _e('Cancel') ?></a> |
|---|
| 289 | | <img src="/images/bookmarklet_loader.gif" alt="" id="photo_saving" style="width:16px; height:16px; vertical-align:-4px; display:none;"/> |
|---|
| 290 | | </div> |
|---|
| 291 | | </div> |
|---|
| 292 | | <div id="categories"> |
|---|
| 293 | | <h2><?php _e('Categories') ?></h2> |
|---|
| 294 | | <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> |
|---|
| 295 | | <?php wp_category_checklist($post_ID) ?> |
|---|
| 296 | | </ul> |
|---|
| 297 | | </div> |
|---|
| 298 | | </form> |
|---|