Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 516 lines (452 sloc) 30.548 kb
ff03138 Randy Hoyt Creating classes, adding OpenPhoto tab to Media Manager
randyhoyt authored
1 <?php
2 /*
3 Plugin Name: OpenPhoto for WordPress
1ea823a Randy Jensen stored consumer keys properly
authored
4 Version: 0.9.1
ff03138 Randy Hoyt Creating classes, adding OpenPhoto tab to Media Manager
randyhoyt authored
5 Plugin URI: https://github.com/openphoto/openphoto-wordpress
6 Author: Randy Hoyt, Randy Jensen
7 Author URI: http://cultivatr.com/
8 Description: Connects a WordPress installation to an OpenPhoto installation.
9 */
10
11 class WP_OpenPhoto {
12
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
13 function WP_OpenPhoto() {
ff03138 Randy Hoyt Creating classes, adding OpenPhoto tab to Media Manager
randyhoyt authored
14 $this->__construct();
15 }
16
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
17 function __construct() {
c477ba7 Randy Hoyt Authentication
randyhoyt authored
18 new WP_OpenPhoto_Settings;
ff03138 Randy Hoyt Creating classes, adding OpenPhoto tab to Media Manager
randyhoyt authored
19 add_filter('media_upload_tabs', array( &$this, 'media_add_openphoto_tab' ));
20 add_action('media_upload_openphoto', array( &$this, 'media_include_openphoto_iframe'));
21 }
22
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
23 function media_add_openphoto_tab( $tabs ) {
ff03138 Randy Hoyt Creating classes, adding OpenPhoto tab to Media Manager
randyhoyt authored
24 $tab = array('openphoto' => __('OpenPhoto', 'openphoto'));
25 return array_merge($tabs, $tab);
26 }
27
28 function media_include_openphoto_iframe() {
29 return wp_iframe( array( &$this, 'media_render_openphoto_tab'));
30 }
31
32 function media_render_openphoto_tab() {
33 media_upload_header();
731b448 Randy Hoyt Modify tags dropdown
randyhoyt authored
34
506dc05 Randy Hoyt Pagination
randyhoyt authored
35 $post_id = intval($_REQUEST['post_id']);
36 $m = trim($_REQUEST['m']);
37 $pg = trim($_REQUEST['pg']);
ff03138 Randy Hoyt Creating classes, adding OpenPhoto tab to Media Manager
randyhoyt authored
38
c477ba7 Randy Hoyt Authentication
randyhoyt authored
39 $openphoto = get_option('openphoto_wordpress_settings');
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
40 $client = new OpenPhotoOAuth(str_replace('http://','',$openphoto['host']),$openphoto["oauth_consumer_key"],$openphoto["oauth_consumer_secret"],$openphoto["oauth_token"],$openphoto["oauth_token_secret"]);
731b448 Randy Hoyt Modify tags dropdown
randyhoyt authored
41
42 // get photos
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
43 $sizes['thumbnail']['w'] = get_option('thumbnail_size_w');
44 $sizes['thumbnail']['h'] = get_option('thumbnail_size_h');
45 $sizes['thumbnail']['crop'] = get_option('thumbnail_crop');
46 $sizes['thumbnail'] = $sizes['thumbnail']['w'] . 'x' . $sizes['thumbnail']['h'];
47 if ($sizes['thumbnail']['crop']==1) $sizes['thumbnail'] .= 'xCR';
48 $sizes['medium']['w'] = get_option('medium_size_w');
49 $sizes['medium']['h'] = get_option('medium_size_h');
50 $sizes['medium'] = $sizes['medium']['w'] . 'x' . $sizes['medium']['h'];
51 $sizes['large']['w'] = get_option('large_size_w');
52 $sizes['large']['h'] = get_option('large_size_h');
53 $sizes['large'] = $sizes['large']['w'] . 'x' . $sizes['large']['h'];
da9f33c Randy Hoyt Modify tags dropdown
randyhoyt authored
54
42db635 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
55 $parameters['returnSizes'] = '32x32xCR,128x128,'. $sizes['thumbnail'] . ',' . $sizes['medium'] . ',' . $sizes['large'];
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
56 if(!empty($m)) $parameters['tags'] = $m;
57 if(!empty($pg)) $parameters['page'] = $pg;
ed64d22 Randy Hoyt Generate smaller image sizes; use dimensions from API
randyhoyt authored
58 $parameters['generate'] = 'true';
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
59 $response = $client->get("/photos/list.json", $parameters);
60 $response = json_decode($response);
c477ba7 Randy Hoyt Authentication
randyhoyt authored
61 $photos = $response->result;
731b448 Randy Hoyt Modify tags dropdown
randyhoyt authored
62
63 // get tags
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
64 $response = $client->get("/tags/list.json");
731b448 Randy Hoyt Modify tags dropdown
randyhoyt authored
65 $response = json_decode($response);
66 $tags = $response->result;
da9f33c Randy Hoyt Modify tags dropdown
randyhoyt authored
67 ?>
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
68 <script>
69 jQuery(document).ready(function() {
99bf2a9 Randy Jensen removed cookie code for now
authored
70
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
71 jQuery('.op-send-to-editor').click(function() {
72 var parent_el, title_text, alt_text, caption_text, url_text, alignment, size, size_alt, op_single, img;
73 parent_el = jQuery(this).parents('tbody');
74 title_text = parent_el.find('.title-text').val();
75 alt_text = parent_el.find('.alt-text').val();
76 caption_text = parent_el.find('.caption-text').val();
77 caption_text.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
78 url_text = parent_el.find('.url-text').val();
79 alignment = parent_el.find('.alignment-area input[type="radio"]]:checked').val();
99bf2a9 Randy Jensen removed cookie code for now
authored
80 size = parent_el.find('.size-area input[type="radio"]]:checked').val();
e806c26 Randy Hoyt Tweaks
randyhoyt authored
81 size_height = parent_el.find('.size-area input[type="radio"]]:checked').attr('data-image-height');
82 size_width = parent_el.find('.size-area input[type="radio"]]:checked').attr('data-image-width');
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
83 size_alt = parent_el.find('.size-area input[type="radio"]]:checked').attr('alt');
84 size_class = 'size-' + size;
e806c26 Randy Hoyt Tweaks
randyhoyt authored
85 height = size_height;
86 width = size_width;
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
87 op_single = parent_el.find('#op-single').attr('name');
88 img = '';
48a6e92 Randy Hoyt Tweaks
randyhoyt authored
89
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
90 if (alt_text === "") {
91 alt_text = title_text;
92 }
93
94 title_text = title_text;
95
96 if (alignment == 'none') {
97 alignment = 'alignnone';
98 } else if (alignment == 'left') {
99 alignment = ' alignleft ';
100 } else if (alignment == 'center') {
101 alignment = ' aligncenter ';
102 } else if (alignment == 'right') {
103 alignment = ' alignright ';
104 }
105
68e088a Randy Hoyt Tweaks
randyhoyt authored
106 if (caption_text != "") {
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
107 img += '[caption id="'+op_single+'" align="'+alignment + '" width="' + width + '" caption="'+caption_text+'"]';
68e088a Randy Hoyt Tweaks
randyhoyt authored
108 aligment = '';
109 }
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
110
02e34c2 Randy Jensen fixed href linking bug
authored
111 img += '<a href="'+url_text+'" id="'+op_single+'"><img class="'+alignment + ' ' + size_class + ' ' + '" title="' + title_text + '" src="' + size_alt + '" alt="' + alt_text + '" width="' + width + '" height="' + height + '" /></a>';
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
112
68e088a Randy Hoyt Tweaks
randyhoyt authored
113 if (caption_text != "") {
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
114 img += '[/caption]';
68e088a Randy Hoyt Tweaks
randyhoyt authored
115 }
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
116
117 var win = window.dialogArguments || opener || parent || top;
118 win.send_to_editor(img);
119
120 return false;
121 });
122 });
123 </script>
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
124
125 <form id="op-filter" action="?post_id=<?php echo $post_id ?>&type=image&tab=openphoto" method="post">
126 <input type="hidden" name="type" value="image">
127 <input type="hidden" name="tab" value="library">
128 <input type="hidden" name="post_id" value="<?php echo $post_id ?>">
129 <input type="hidden" name="post_mime_type" value="">
130 <ul class="subsubsub">
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
131 <?php
132 if ( $photos ) {
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
133 $total_pages = $photos[0]->totalPages;
134 $current_page = $photos[0]->currentPage;
135 $total_photos = $photos[0]->totalRows;
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
136 echo '<li>Total Images <span class="count">(<span id="image-counter">'. $total_photos . '</span>)</span></li>';
137 }
138
139 ?></ul>
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
140 <div class="tablenav">
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
141 <?php
e806c26 Randy Hoyt Tweaks
randyhoyt authored
142 if ( $photos ) {
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
143 if ($total_pages > 1) {
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
144 echo '<div class="tablenav-pages">';
b5414b6 Randy Hoyt Reworking settings page
randyhoyt authored
145
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
146 if ($current_page > 1) {
147 echo '<a class="next page-numbers" href="?post_id='. $post_id . '&amp;type=image&amp;tab=openphoto&amp;m=' . $m . '&amp;pg='. ($current_page-1) . '">&laquo;</a> ';
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
148 }
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
149 for( $i=1;$i<=$total_pages;$i++ ) {
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
150 $current = "";
151 if ($current_page == $i) {
152 $current = ' current ';
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
153 echo '<span class="page-numbers'. $current . '">'. $i . '</span> ';
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
154 } else {
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
155 echo '<a class="page-numbers" href="?post_id=' . $post_id . '&amp;type=image&amp;tab=openphoto&amp;m=' . $m . '&amp;pg='. $i . '">'. $i . '</a> ';
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
156 }
157 }
e806c26 Randy Hoyt Tweaks
randyhoyt authored
158
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
159 if ($current_page < $total_pages) {
160 echo '<a class="next page-numbers" href="?post_id='. $post_id . '&amp;type=image&amp;tab=openphoto&amp;m=' . $m . '&amp;pg='. ($current_page+1) . '">&raquo;</a> ';
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
161 }
162 echo '</div>';
163 }
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
164 }
165
166 if ( $tags ) {
167 ?><div class="alignleft actions">
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
168 <select name="m">
169 <option value="0">Show all tags</option>
170 <?php
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
171 foreach( $tags as $tag ) {
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
172 $tag->id = trim($tag->id);
173 $selected = "";
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
174 if ( $tag->id==$m ) $selected = ' selected="selected"';
e806c26 Randy Hoyt Tweaks
randyhoyt authored
175 if ($tag->count > 0) echo '<option value="'.$tag->id .'"' . $selected . '>' . $tag->id . ' (' . $tag->count . ')</option>';
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
176 }
177 ?>
178 </select>
179 <input type="submit" name="post-query-submit" id="op-post-query-submit" class="button-secondary" value="Filter »">
68e088a Randy Hoyt Tweaks
randyhoyt authored
180 </div>
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
181 <br class="clear">
1ea823a Randy Jensen stored consumer keys properly
authored
182 <?php } ?></div>
67483e5 Randy Hoyt Switching to OAuth library, progress on sizing
randyhoyt authored
183 </form>
184 <?php
63981e7 Randy Hoyt Fixing image address for original image; aspect ratio for all non-origin...
randyhoyt authored
185 if ( $photos ) {
68e088a Randy Hoyt Tweaks
randyhoyt authored
186
da9f33c Randy Hoyt Modify tags dropdown
randyhoyt authored
187 echo '<form enctype="multipart/form-data" method="post" action="'.home_url().'/wp-admin/media-upload.php?type=image&amp;tab=library&amp;post_id='.$post_id.'" class="media-upload-form validate" id="library-form">';
0908cab Randy Jensen almost final changes to image insertion into post
authored
188 echo '<input type="hidden" id="_wpnonce" name="_wpnonce" value="5acb57476d" /><input type="hidden" name="_wp_http_referer" value="/wp-admin/media-upload.php?post_id='.$post_id.'&amp;type=image&amp;tab=library" />';
7379825 Randy Jensen js open/close fixed. actual post id being used now
authored
189 echo '<script type="text/javascript">
190 <!--
191 jQuery(function($){
192 var preloaded = $(".media-item.preloaded");
193 if ( preloaded.length > 0 ) {
194 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, "")},"");});
195 updateMediaForm();
196 }
197 });
198 -->
199 </script>';
daa96f6 Randy Jensen start of styling now added
authored
200 echo '<div id="media-items">';
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
201
1914b73 Randy Hoyt Changing logic to retrieve to address #5
randyhoyt authored
202 foreach( $photos as $unique_id => $photo ) {
203
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
204 echo '<div id="media-item-'.$unique_id.'" class="media-item child-of-'.$post_id.' preloaded"><div class="progress" style="display: none; "></div><div id="media-upload-error-'.$unique_id.'"></div><div class="filename"></div>';
205 echo '<input type="hidden" id="type-of-'.$unique_id.'" value="image">';
daa96f6 Randy Jensen start of styling now added
authored
206 echo '<a class="toggle describe-toggle-on" href="#">Show</a>';
207 echo '<a class="toggle describe-toggle-off" href="#">Hide</a>';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
208 echo '<input type="hidden" name="attachments['.$unique_id.'][menu_order]" value="0">';
daa96f6 Randy Jensen start of styling now added
authored
209 echo '<div class="filename new"><span class="title">';
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
210 if (! empty($photo->title) ) {
daa96f6 Randy Jensen start of styling now added
authored
211 echo $photo->title;
212 } else {
213 substr(strrchr($photo->pathOriginal, "/"), 1 );
214 }
215 echo '</span></div>';
7379825 Randy Jensen js open/close fixed. actual post id being used now
authored
216 echo '<table class="slidetoggle describe startclosed">';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
217 echo '<thead class="media-item-info" id="media-head-'.$unique_id.'">';
daa96f6 Randy Jensen start of styling now added
authored
218 echo '<tr valign="top">';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
219 echo '<td class="A1B1" id="thumbnail-head-'.$unique_id.'">';
63981e7 Randy Hoyt Fixing image address for original image; aspect ratio for all non-origin...
randyhoyt authored
220 echo '<p style="height:100px;padding-right:10px;"><a href="http://'.$photo->appId.$photo->pathOriginal.'" target="_blank"><img class="thumbnail" src="'.$photo->path128x128.'" alt="" style="margin-top: 3px;"></a></p>';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
221 //echo '<p><input type="button" id="imgedit-open-btn-'.$unique_id.'" onclick="imageEdit.open( '.$unique_id.', &quot;98f2ea4727&quot; )" class="button" value="Edit Image"> <img src="'.home_url().'/wp-admin/images/wpspin_light.gif" class="imgedit-wait-spin" alt=""></p>';
daa96f6 Randy Jensen start of styling now added
authored
222 echo '</td>';
223 echo '<td>';
224 echo '<p><strong>File name:</strong> '.substr(strrchr($photo->pathOriginal, "/"), 1 ).'</p>';
225 echo '<p><strong>File type:</strong> .'.substr(strrchr($photo->pathOriginal, "."), 1 ).'</p>';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
226 echo '<p><strong>Upload date:</strong> '.date('F d Y', (int) $photo->dateUploaded).'</p>';
227 echo '<p><strong>Dimensions:</strong> <span id="media-dims-'.$unique_id.'">'.$photo->width.'&nbsp;×&nbsp;'.$photo->height.'</span> </p>';
daa96f6 Randy Jensen start of styling now added
authored
228 echo '</td>';
229 echo '</tr>';
230 echo '</thead>';
231 echo '<tbody>';
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
232 echo '<input type="hidden" name="op-attachment-'.$photo->id.'" id="op-single" >';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
233 echo '<tr><td colspan="2" class="imgedit-response" id="imgedit-response-'.$unique_id.'"></td></tr>';
234 echo '<tr><td style="display:none" colspan="2" class="image-editor" id="image-editor-'.$unique_id.'"></td></tr>';
daa96f6 Randy Jensen start of styling now added
authored
235 echo '<tr class="post_title form-required">';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
236 echo '<th valign="top" scope="row" class="label"><label for="attachments['.$unique_id.'][post_title]"><span class="alignleft">Title</span><span class="alignright"><abbr title="required" class="required">*</abbr></span><br class="clear"></label></th>';
237 echo '<td class="field"><input type="text" class="text title-text" id="attachments['.$unique_id.'][post_title]" name="attachments['.$unique_id.'][post_title]" value="'.substr(strrchr($photo->pathOriginal, "/"), 1 ).'" aria-required="true"></td>';
daa96f6 Randy Jensen start of styling now added
authored
238 echo '</tr>';
239 echo '<tr class="image_alt">';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
240 echo '<th valign="top" scope="row" class="label"><label for="attachments['.$unique_id.'][image_alt]"><span class="alignleft">Alternate Text</span><br class="clear"></label></th>';
241 echo '<td class="field"><input type="text" class="text alt-text" id="attachments['.$unique_id.'][image_alt]" name="attachments['.$unique_id.'][image_alt]" value=""><p class="help">Alt text for the image, e.g. "The Mona Lisa"</p></td>';
daa96f6 Randy Jensen start of styling now added
authored
242 echo '</tr>';
243 echo '<tr class="post_excerpt">';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
244 echo '<th valign="top" scope="row" class="label"><label for="attachments['.$unique_id.'][post_excerpt]"><span class="alignleft">Caption</span><br class="clear"></label></th>';
245 echo '<td class="field"><input type="text" class="text caption-text" id="attachments['.$unique_id.'][post_excerpt]" name="attachments['.$unique_id.'][post_excerpt]" value=""></td>';
daa96f6 Randy Jensen start of styling now added
authored
246 echo '</tr>';
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
247 //echo '<tr class="post_content">';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
248 //echo '<th valign="top" scope="row" class="label"><label for="attachments['.$unique_id.'][post_content]"><span class="alignleft">Description</span><br class="clear"></label></th>';
249 //echo '<td class="field"><textarea id="attachments['.$unique_id.'][post_content]" name="attachments['.$unique_id.'][post_content]"></textarea></td>';
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
250 //echo '</tr>';
daa96f6 Randy Jensen start of styling now added
authored
251 echo '<tr class="url">';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
252 echo '<th valign="top" scope="row" class="label"><label for="attachments['.$unique_id.'][url]"><span class="alignleft">Link URL</span><br class="clear"></label></th>';
daa96f6 Randy Jensen start of styling now added
authored
253 echo '<td class="field">';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
254 echo '<input type="text" class="text urlfield url-text" name="attachments['.$unique_id.'][url]" value="http://'.$photo->host.$photo->pathOriginal.'"><br>';
daa96f6 Randy Jensen start of styling now added
authored
255 echo '<button type="button" class="button urlnone" title="">None</button>';
1770892 Randy Jensen testing some stuff
authored
256 echo '<button type="button" class="button urlfile" title="http://'.$photo->host.$photo->pathOriginal.'">File URL</button>';
63981e7 Randy Hoyt Fixing image address for original image; aspect ratio for all non-origin...
randyhoyt authored
257 echo '<button type="button" class="button urlpost" title="http://'.$photo->appId. '/photo/'. $photo->id . '/view">OpenPhoto URL</button>';
daa96f6 Randy Jensen start of styling now added
authored
258 echo '<p class="help">Enter a link URL or click above for presets.</p>';
259 echo '</td>';
260 echo '</tr>';
261 echo '<tr class="align">';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
262 echo '<th valign="top" scope="row" class="label"><label for="attachments['.$unique_id.'][align]"><span class="alignleft">Alignment</span><br class="clear"></label></th>';
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
263 echo '<td class="field alignment-area">';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
264 echo '<input type="radio" name="attachments['.$unique_id.'][align]" id="image-align-none-'.$unique_id.'" value="none" checked="checked"><label for="image-align-none-'.$unique_id.'" class="align image-align-none-label">None</label>';
265 echo '<input type="radio" name="attachments['.$unique_id.'][align]" id="image-align-left-'.$unique_id.'" value="left"><label for="image-align-left-'.$unique_id.'" class="align image-align-left-label">Left</label>';
266 echo '<input type="radio" name="attachments['.$unique_id.'][align]" id="image-align-center-'.$unique_id.'" value="center"><label for="image-align-center-'.$unique_id.'" class="align image-align-center-label">Center</label>';
267 echo '<input type="radio" name="attachments['.$unique_id.'][align]" id="image-align-right-'.$unique_id.'" value="right"><label for="image-align-right-'.$unique_id.'" class="align image-align-right-label">Right</label>';
daa96f6 Randy Jensen start of styling now added
authored
268 echo '</td>';
269 echo '</tr>';
270 echo '<tr class="image-size">';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
271 echo '<th valign="top" scope="row" class="label"><label for="attachments['.$unique_id.'][image-size]"><span class="alignleft">Size</span><br class="clear"></label></th>';
bf1a206 Randy Hoyt Adding width and height for caption
randyhoyt authored
272 echo '<td class="field size-area">';
bb7eb44 Randy Hoyt Never enlarge image; default the smallest available size to checked
randyhoyt authored
273 $checked = ' checked="checked"';
63981e7 Randy Hoyt Fixing image address for original image; aspect ratio for all non-origin...
randyhoyt authored
274 $thumbnail_width = $photo->{"photo".$sizes['thumbnail']}[1];
275 $thumbnail_height = $photo->{"photo".$sizes['thumbnail']}[2];
bb7eb44 Randy Hoyt Never enlarge image; default the smallest available size to checked
randyhoyt authored
276 echo '<div class="image-size-item">';
277 if ($thumbnail_width < $photo->width || $thumbnail_height < $photo->height) {
278 echo '<input type="radio" name="attachments['.$unique_id.'][image-size]" id="image-size-thumbnail-'.$unique_id.'" value="thumbnail" alt="'.$photo->{"photo".$sizes['thumbnail']}[0] . '" data-image-height="'.$thumbnail_height.'" data-image-width="'.$thumbnail_width.'"' . $checked . '><label for="image-size-thumbnail-'.$unique_id.'">Thumbnail</label> <label for="image-size-thumbnail-'.$unique_id.'" class="help">(' . $thumbnail_width. '&nbsp;×&nbsp;' . $thumbnail_height . ')</label>';
279 $checked = "";
280 } else {
281 echo '<input type="radio" disabled="disabled" /><label for="image-size-thumbnail-'.$unique_id.'">Thumbnail</label>';
282 }
283 echo '</div>';
63981e7 Randy Hoyt Fixing image address for original image; aspect ratio for all non-origin...
randyhoyt authored
284 $medium_width = $photo->{"photo".$sizes['medium']}[1];
285 $medium_height = $photo->{"photo".$sizes['medium']}[2];
bb7eb44 Randy Hoyt Never enlarge image; default the smallest available size to checked
randyhoyt authored
286 echo '<div class="image-size-item">';
287 if ($medium_width < $photo->width || $medium_height < $photo->height) {
288 echo '<input type="radio" name="attachments['.$unique_id.'][image-size]" id="image-size-medium-'.$unique_id.'" value="medium" alt="'.$photo->{"photo".$sizes['medium']}[0].'" data-image-height="'.$medium_height.'" data-image-width="'.$medium_width.'"' . $checked . '><label for="image-size-medium-'.$unique_id.'">Medium</label> <label for="image-size-medium-'.$unique_id.'" class="help">(' . $medium_width . '&nbsp;×&nbsp;' . $medium_height . ')</label>';
289 $checked = "";
290 } else {
291 echo '<input type="radio" disabled="disabled" /><label for="image-size-medium-'.$unique_id.'">Medium</label>';
292 }
293 echo '</div>';
63981e7 Randy Hoyt Fixing image address for original image; aspect ratio for all non-origin...
randyhoyt authored
294 $large_width = $photo->{"photo".$sizes['large']}[1];
295 $large_height = $photo->{"photo".$sizes['large']}[2];
bb7eb44 Randy Hoyt Never enlarge image; default the smallest available size to checked
randyhoyt authored
296 echo '<div class="image-size-item">';
297 if ($large_width < $photo->width || $large_height < $photo->height) {
298 echo '<input type="radio" name="attachments['.$unique_id.'][image-size]" id="image-size-large-'.$unique_id.'" value="large" alt="'.$photo->{"photo".$sizes['large']}[0].'" data-image-height="'.$large_height.'" data-image-width="'.$large_width.'"' . $checked . '><label for="image-size-large-'.$unique_id.'">Large</label> <label for="image-size-large-'.$unique_id.'" class="help">('. $large_width . '&nbsp;×&nbsp;'. $large_height . ')</label>';
299 $checked = "";
300 } else {
301 echo '<input type="radio" disabled="disabled" /><label for="image-size-large-'.$unique_id.'">Large</label>';
302 }
303 echo '</div>';
63981e7 Randy Hoyt Fixing image address for original image; aspect ratio for all non-origin...
randyhoyt authored
304 echo '<div class="image-size-item"><input type="radio" name="attachments['.$unique_id.'][image-size]" id="image-size-full-'.$unique_id.'" value="full" alt="http://'.$photo->host.$photo->pathOriginal.'" data-image-height="'.$photo->height.'" data-image-width="'.$photo->width.'"' . $checked . '><label for="image-size-full-'.$unique_id.'">Full Size</label> <label for="image-size-full-'.$unique_id.'" class="help">('.$photo->width.'&nbsp;×&nbsp;'.$photo->height.')</label></div>';
daa96f6 Randy Jensen start of styling now added
authored
305 echo '</td>';
306 echo '</tr>';
307 echo '<tr class="submit">';
308 echo '<td></td>';
309 echo '<td class="savesend">';
f90c739 Randy Hoyt Some progress on pagination
randyhoyt authored
310 echo '<input type="submit" name="send['.$unique_id.']" id="send['.$unique_id.']" class="op-send-to-editor button" value="Insert into Post">';
311 //echo '<input type="submit" name="send['.$unique_id.']" id="send['.$unique_id.']" class="button" value="Insert into Post"> ';
312 //echo '<a class="wp-post-thumbnail" id="wp-post-thumbnail-'.$unique_id.'" href="#" onclick="WPSetAsThumbnail(&quot;'.$unique_id.'&quot;, &quot;2cf0f581b0&quot;);return false;">Use as featured image</a> ';
313 //echo '<a href="#" class="del-link" onclick="document.getElementById(\'del_attachment_'.$unique_id.'\').style.display=\'block\';return false;">Delete</a>';
314 //echo ' <div id="del_attachment_'.$unique_id.'" class="del-attachment" style="display:none;">You are about to delete <strong>splash_1920x1200.jpg</strong>.';
315 //echo '<a href="post.php?action=delete&amp;post='.$unique_id.'&amp;_wpnonce=3bfab9cd8c" id="del['.$unique_id.']" class="button">Continue</a>';
0908cab Randy Jensen almost final changes to image insertion into post
authored
316 //echo '<a href="#" class="button" onclick="this.parentNode.style.display=\'none\';return false;">Cancel</a>';
daa96f6 Randy Jensen start of styling now added
authored
317 echo '</div>';
c477ba7 Randy Hoyt Authentication
randyhoyt authored
318 echo '</td>';
319 echo '</tr>';
daa96f6 Randy Jensen start of styling now added
authored
320 echo '</tbody>';
321 echo '</table>';
322 echo '</div>';
323
c477ba7 Randy Hoyt Authentication
randyhoyt authored
324 }
325
daa96f6 Randy Jensen start of styling now added
authored
326 echo '</div>';
7379825 Randy Jensen js open/close fixed. actual post id being used now
authored
327
328 echo '<p class="ml-submit">';
329 echo '<input type="submit" name="save" id="save" class="button savebutton" value="Save all changes">';
330 echo '<input type="hidden" name="post_id" id="post_id" value="'.$post_id.'">';
331 echo '</p>';
332
c477ba7 Randy Hoyt Authentication
randyhoyt authored
333 echo '</form>';
334
0908cab Randy Jensen almost final changes to image insertion into post
authored
335 }
c477ba7 Randy Hoyt Authentication
randyhoyt authored
336 }
ff03138 Randy Hoyt Creating classes, adding OpenPhoto tab to Media Manager
randyhoyt authored
337 }
338
c477ba7 Randy Hoyt Authentication
randyhoyt authored
339 class WP_OpenPhoto_Settings {
ff03138 Randy Hoyt Creating classes, adding OpenPhoto tab to Media Manager
randyhoyt authored
340
c477ba7 Randy Hoyt Authentication
randyhoyt authored
341 function WP_OpenPhoto_Settings()
ff03138 Randy Hoyt Creating classes, adding OpenPhoto tab to Media Manager
randyhoyt authored
342 {
c477ba7 Randy Hoyt Authentication
randyhoyt authored
343 $this->__construct();
ff03138 Randy Hoyt Creating classes, adding OpenPhoto tab to Media Manager
randyhoyt authored
344 }
345
346 function __construct()
347 {
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
348 add_action( 'admin_init', array( &$this, 'settings_init') );
349 add_action( 'admin_menu', array( &$this, 'settings_add_openphoto_page') );
c477ba7 Randy Hoyt Authentication
randyhoyt authored
350 }
ff03138 Randy Hoyt Creating classes, adding OpenPhoto tab to Media Manager
randyhoyt authored
351
c477ba7 Randy Hoyt Authentication
randyhoyt authored
352 function settings_init() {
353 register_setting( 'openphoto_wordpress_settings', 'openphoto_wordpress_settings', array(&$this,'settings_validate_submission'));
354 }
355
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
356 function settings_add_openphoto_page() {
357 add_options_page( 'Configure OpenPhoto Integration', 'OpenPhoto', 'manage_options', 'openphoto_wordpress_settings', array( &$this, 'settings_render_openphoto_page') );
c477ba7 Randy Hoyt Authentication
randyhoyt authored
358 }
359
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
360 function settings_render_openphoto_page() {
c477ba7 Randy Hoyt Authentication
randyhoyt authored
361
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
362 $openphoto = get_option('openphoto_wordpress_settings');
363
364 $action = $_REQUEST['action'];
365 if ( "update" == $action ) {
c477ba7 Randy Hoyt Authentication
randyhoyt authored
366
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
367 $nonce=$_REQUEST['_wpnonce'];
368 if (! wp_verify_nonce($nonce, 'openphoto_wordpress_settings') ) wp_die('You do not have permission to save this page.');
c477ba7 Randy Hoyt Authentication
randyhoyt authored
369
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
370 $input = $_REQUEST['openphoto_wordpress_settings'];
371 $newinput['host'] = trim($input['host']);
372 $newinput['oauth_consumer_key'] = trim($input['oauth_consumer_key']);
373 $newinput['oauth_consumer_secret'] = trim($input['oauth_consumer_secret']);
374 $newinput['unauthorized_token'] = trim($input['unauthorized_token']);
375 $newinput['unauthorized_token_secret'] = trim($input['unauthorized_token_secret']);
376 $newinput['oauth_token'] = trim($input['oauth_token']);
377 $newinput['oauth_token_secret'] = trim($input['oauth_token_secret']);
378 $newinput['oauth_verifier'] = trim($input['oauth_verifier']);
1ea823a Randy Jensen stored consumer keys properly
authored
379
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
380 if ( $newinput['host'] != $openphoto['host'] ) {
381 $host_changed = true;
382 }
c477ba7 Randy Hoyt Authentication
randyhoyt authored
383
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
384 $openphoto = $newinput;
385 update_option('openphoto_wordpress_settings',$openphoto);
386
387 if ($host_changed || empty( $openphoto['oauth_token'] ) || empty( $openphoto['oauth_token_secret'] ) ) {
5f2fd1c Randy Hoyt Adding noheader=true to the option form.
randyhoyt authored
388 wp_redirect(trailingslashit(esc_attr($openphoto['host'])) . 'v1/oauth/authorize?oauth_callback=' . urlencode(admin_url("options-general.php?page=openphoto_wordpress_settings&action=authenticate")) . '&name=' . urlencode('OpenPhoto WordPress Plugin (' . ereg_replace("(https?)://", "", get_bloginfo('url')) . ')'));
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
389 } else {
390 wp_redirect('options-general.php?page=openphoto_wordpress_settings&message=1');
c477ba7 Randy Hoyt Authentication
randyhoyt authored
391 }
392
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
393 } elseif ( "authenticate" == $action ) {
394
395 // if all the values are set
396 if ( isset($_REQUEST["oauth_consumer_key"]) &&
397 isset($_REQUEST["oauth_consumer_key"]) &&
398 isset($_REQUEST["oauth_consumer_secret"]) &&
399 isset($_REQUEST["oauth_token"]) &&
400 isset($_REQUEST["oauth_token_secret"]) &&
401 isset($_REQUEST["oauth_verifier"]) ) {
402
403 // if even one of the values in the database is different than those in the request
404 if ( $openphoto['oauth_consumer_key'] != $_REQUEST["oauth_consumer_key"] ||
405 $openphoto['oauth_consumer_secret'] != $_REQUEST["oauth_consumer_secret"] ||
406 $openphoto['unauthorized_token'] != $_REQUEST["oauth_token"] ||
407 $openphoto['unauthorized_token_secret'] != $_REQUEST["oauth_token_secret"] ||
408 $openphoto['oauth_verifier'] != $_REQUEST["oauth_verifier"]) {
409 /*
410 $curl_post = array('oauth_consumer_key' => $_REQUEST["oauth_consumer_key"],'oauth_consumer_secret' => $_REQUEST["oauth_consumer_secret"], 'oauth_token' => $_REQUEST["oauth_token"], 'oauth_token_secret' => $_REQUEST["oauthoauth_token_secret_token"], 'oauth_token_secret' => $_REQUEST["oauthoauth_token_secret_token"], 'oauth_verifier' => $_REQUEST['oauth_verifier']);
411 $curl_options = array(
412 CURLOPT_POST => 1,
413 CURLOPT_HEADER => 0,
414 CURLOPT_URL => trailingslashit($openphoto['host']) . 'v1/oauth/token/access',
415 CURLOPT_FRESH_CONNECT => 1,
416 CURLOPT_RETURNTRANSFER => 1,
417 CURLOPT_POSTFIELDS => http_build_query($curl_post)
418 );
419 $ch = curl_init();
420 curl_setopt_array($ch, $curl_options);
421 $response = curl_exec($ch);
422 curl_close($ch);
423
424 */
425 if( !class_exists( 'WP_Http' ) )
426 include_once( ABSPATH . WPINC. '/class-http.php' );
427 $request = new WP_Http;
428 $body = array(
429 'oauth_consumer_key' => $_REQUEST["oauth_consumer_key"],
430 'oauth_consumer_secret' => $_REQUEST["oauth_consumer_secret"],
431 'oauth_token' => $_REQUEST["oauth_token"],
432 'oauth_token_secret' => $_REQUEST["oauthoauth_token_secret_token"],
433 'oauth_token_secret' => $_REQUEST["oauthoauth_token_secret_token"],
434 'oauth_verifier' => $_REQUEST['oauth_verifier']
435 );
436 $url = trailingslashit($openphoto['host']) . 'v1/oauth/token/access';
437 $result = $request->request( $url, array( 'method' => 'POST', 'body' => $body) );
438
439 if ($result['response']['code'] == 200) {
440 $access = wp_parse_args($result['body']);
1ea823a Randy Jensen stored consumer keys properly
authored
441 $openphoto['oauth_consumer_key'] = $_REQUEST["oauth_consumer_key"];
442 $openphoto['oauth_consumer_secret'] = $_REQUEST["oauth_consumer_secret"];
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
443 $openphoto['oauth_token'] = $access['oauth_token'];
444 $openphoto['oauth_token_secret'] = $access['oauth_token_secret'];
445
446 if ( isset($access['oauth_token']) && $access['oauth_token_secret']) {
447 $message = 2;
448 } else {
449 $message = 3;
450 }
451 } else {
452 $message = 3;
453 }
454 }
455
456 update_option('openphoto_wordpress_settings',$openphoto);
457 wp_redirect('options-general.php?page=openphoto_wordpress_settings&message=' . $message);
c477ba7 Randy Hoyt Authentication
randyhoyt authored
458
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
459 }
460 }
461
c477ba7 Randy Hoyt Authentication
randyhoyt authored
462 echo '<div class="wrap">';
463 echo '<div class="icon32" id="icon-options-general"><br /></div>';
464 echo '<h2>Configure OpenPhoto Integration</h2>';
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
465
466 switch ( $_REQUEST['message'] ) {
467 case 1:
468 echo '<div id="setting-error-settings_updated" class="updated settings-error"><p><strong>Settings saved.</strong></p></div>';
469 break;
470 case 2:
471 echo '<div id="setting-error-settings_updated" class="updated settings-error"><p><strong>Your OpenPhoto credentials have been retrieved, and your settings have been saved.</strong></p></div>';
472 break;
473 case 3:
474 echo '<div id="setting-error-settings_updated" class="updated settings-error"><p><strong>There was an error retrieving your OpenPhoto credentials; please save these settings to try again.</strong></p></div>';
475 break;
476 }
477
5f2fd1c Randy Hoyt Adding noheader=true to the option form.
randyhoyt authored
478 echo '<form action="?page=openphoto_wordpress_settings&noheader=true" method="post" id="openphoto_wordpress_settings_form">';
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
479 echo '<input type="hidden" id="_wpnonce" name="_wpnonce" value="' . wp_create_nonce('openphoto_wordpress_settings') . '" />';
480 echo '<input type="hidden" name="action" value="update" />';
c477ba7 Randy Hoyt Authentication
randyhoyt authored
481 echo '<table class="form-table">';
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
482 echo '<tr valign="top"><th scope="row">Host</th><td><input id="openphoto_wordpress_settings_host" name="openphoto_wordpress_settings[host]" size="100" type="text" value="' . esc_attr($openphoto['host']) . '" />';
c477ba7 Randy Hoyt Authentication
randyhoyt authored
483 echo '<p class="description"><em>Enter the web address of the home page of your OpenPhoto installation.</em></p></td></tr>';
06ef9ed Randy Hoyt Hide OAuth credentials field to eliminate confusion in #4
randyhoyt authored
484 echo '<tr style="display: none;" valign="top"><th scope="row">Consumer Key</th><td><input id="openphoto_wordpress_settings_oauth_consumer_key" name="openphoto_wordpress_settings[oauth_consumer_key]" size="40" type="text" value="' . esc_attr($openphoto['oauth_consumer_key']) . '" /></td></tr>';
485 echo '<tr style="display: none;" valign="top"><th scope="row">Consumer Secret</th><td><input id="openphoto_wordpress_settings_oauth_consumer_secret" name="openphoto_wordpress_settings[oauth_consumer_secret]" size="40" type="text" value="' . esc_attr($openphoto['oauth_consumer_secret']) . '" /></td></tr>';
486 echo '<tr style="display: none;" valign="top"><th scope="row">Token</th><td><input id="openphoto_wordpress_settings_oauth_token" name="openphoto_wordpress_settings[oauth_token]" size="40" type="text" value="' . esc_attr($openphoto['oauth_token']) . '" /></td></tr>';
487 echo '<tr style="display: none;" valign="top"><th scope="row">Token Secret</th><td><input id="openphoto_wordpress_settings_oauth_token_secret" name="openphoto_wordpress_settings[oauth_token_secret]" size="40" type="text" value="' . esc_attr($openphoto['oauth_token_secret']) . '" /></td></tr>';
c477ba7 Randy Hoyt Authentication
randyhoyt authored
488 echo '</table>';
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
489 echo '<input id="openphoto_wordpress_settings_unauthorized_token" name="openphoto_wordpress_settings[unauthorized_token]" type="hidden" value="' . esc_attr($openphoto['unauthorized_token']) . '" />';
490 echo '<input id="openphoto_wordpress_settings_unauthorized_token_secret" name="openphoto_wordpress_settings[unauthorized_token_secret]" type="hidden" value="' . esc_attr($openphoto['unauthorized_token_secret']) . '" />';
491 echo '<input id="openphoto_wordpress_settings_oauth_verifier" name="openphoto_wordpress_settings[oauth_verifier]" type="hidden" value="' . esc_attr($openphoto['oauth_verifier']) . '" />';
492 echo '<p class="submit"><input class="button-primary" name="submit" type="submit" value="' . esc_attr('Save Changes') . '" /></p>';
c477ba7 Randy Hoyt Authentication
randyhoyt authored
493 echo '</form>';
494 echo '</div>';
495
496 }
497
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
498 function settings_validate_submission( $input ) {
c477ba7 Randy Hoyt Authentication
randyhoyt authored
499
500 $newinput['host'] = trim($input['host']);
501 $newinput['oauth_consumer_key'] = trim($input['oauth_consumer_key']);
502 $newinput['oauth_consumer_secret'] = trim($input['oauth_consumer_secret']);
503 $newinput['unauthorized_token'] = trim($input['unauthorized_token']);
504 $newinput['unauthorized_token_secret'] = trim($input['unauthorized_token_secret']);
505 $newinput['oauth_token'] = trim($input['oauth_token']);
506 $newinput['oauth_token_secret'] = trim($input['oauth_token_secret']);
507 $newinput['oauth_verifier'] = trim($input['oauth_verifier']);
508
509 return $newinput;
510 }
ff03138 Randy Hoyt Creating classes, adding OpenPhoto tab to Media Manager
randyhoyt authored
511
e0fd550 Randy Hoyt Reworking settings page
randyhoyt authored
512 }
513
514 new WP_OpenPhoto;
e806c26 Randy Hoyt Tweaks
randyhoyt authored
515 require_once('openphoto-php/OpenPhotoOAuth.php');
Something went wrong with that request. Please try again.