__construct(); } function __construct() { new WP_OpenPhoto_Settings; add_filter('media_upload_tabs', array( &$this, 'media_add_openphoto_tab' )); add_action('media_upload_openphoto', array( &$this, 'media_include_openphoto_iframe')); } function media_add_openphoto_tab( $tabs ) { $tab = array('openphoto' => __('OpenPhoto', 'openphoto')); return array_merge($tabs, $tab); } function media_include_openphoto_iframe() { return wp_iframe( array( &$this, 'media_render_openphoto_tab')); } function media_render_openphoto_tab() { if ( $wp_version >= 3.5 ) { // do nothing } else { media_upload_header(); } $post_id = intval($_REQUEST['post_id']); $m = trim($_REQUEST['m']); $pg = trim($_REQUEST['pg']); $openphoto = get_option('openphoto_wordpress_settings'); $client = new OpenPhotoOAuth(str_replace('http://','',$openphoto['host']),$openphoto["oauth_consumer_key"],$openphoto["oauth_consumer_secret"],$openphoto["oauth_token"],$openphoto["oauth_token_secret"]); // get photos $sizes['thumbnail']['w'] = get_option('thumbnail_size_w'); $sizes['thumbnail']['h'] = get_option('thumbnail_size_h'); $sizes['thumbnail']['crop'] = get_option('thumbnail_crop'); $sizes['thumbnail'] = $sizes['thumbnail']['w'] . 'x' . $sizes['thumbnail']['h']; if (isset($sizes['thumbnail']['crop']) && $sizes['thumbnail']['crop']==1) $sizes['thumbnail'] .= 'xCR'; $sizes['medium']['w'] = get_option('medium_size_w'); $sizes['medium']['h'] = get_option('medium_size_h'); $sizes['medium'] = $sizes['medium']['w'] . 'x' . $sizes['medium']['h']; $sizes['large']['w'] = get_option('large_size_w'); $sizes['large']['h'] = get_option('large_size_h'); $sizes['large'] = $sizes['large']['w'] . 'x' . $sizes['large']['h']; $parameters['returnSizes'] = '32x32xCR,128x128,'. $sizes['thumbnail'] . ',' . $sizes['medium'] . ',' . $sizes['large']; if(!empty($m)) $parameters['tags'] = $m; if(!empty($pg)) $parameters['page'] = $pg; $parameters['generate'] = 'true'; $parameters['generated'] = 'true'; $response = $client->get("/photos/list.json", $parameters); $response = json_decode($response); $photos = $response->result; // get tags $response = $client->get("/tags/list.json"); $response = json_decode($response); $tags = $response->result; ?>
1) { echo '
'; if ($current_page > 1) { echo ' '; } for( $i=1;$i<=$total_pages;$i++ ) { $current = ""; if ($current_page == $i) { $current = ' current '; echo ''. $i . ' '; } else { echo ''. $i . ' '; } } if ($current_page < $total_pages) { echo ' '; } echo '
'; } } if ( $tags ) { ?>

'; echo ''; echo ''; echo '
'; $size_for_image_url_link = $openphoto['size']; if ($size_for_image_url_link == "") $size_for_image_url_link = "original"; foreach( $photos as $unique_id => $photo ) { $src = array(); $src["thumbnail"] = $photo->{"photo".$sizes['thumbnail']}[0]; $src["medium"] = $photo->{"photo".$sizes['medium']}[0]; $src["large"] = $photo->{"photo".$sizes['large']}[0]; $src["original"] = $photo->pathOriginal; if (strpos($src["original"],"http")===false) $src["original"] = 'http://'.$photo->host.$photo->pathOriginal; // in older versions of the API, pathOriginal did not have the full address $info = pathinfo(basename($src["original"])); $photo->extension = $info['extension']; if ("" == $photo->title) {$photo->title = basename($src["original"],'.'.$photo->extension);} echo '
'; echo ''; echo 'Show'; echo 'Hide'; echo ''; echo '
'; echo esc_attr($photo->title); echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; //echo ''; //echo ''; //echo ''; //echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; echo '

'; //echo '

'; echo '
'; echo '

File name: '.$photo->title.'

'; echo '

File type: '.$photo->extension.'

'; echo '

Upload date: '.date('F d Y', (int) $photo->dateUploaded).'

'; echo '

Dimensions: '.$photo->width.' × '.$photo->height.'

'; echo '

Alt text for the image, e.g. "The Mona Lisa"

'; echo '
'; echo ''; echo ''; echo ''; echo '

Enter a link URL or click above for presets.

'; echo '
'; echo ''; echo ''; echo ''; echo ''; echo '
'; $checked = ' checked="checked"'; $thumbnail_width = $photo->{"photo".$sizes['thumbnail']}[1]; $thumbnail_height = $photo->{"photo".$sizes['thumbnail']}[2]; echo '
'; if ($thumbnail_width < $photo->width || $thumbnail_height < $photo->height) { echo ' '; $checked = ""; } else { echo ''; } echo '
'; $medium_width = $photo->{"photo".$sizes['medium']}[1]; $medium_height = $photo->{"photo".$sizes['medium']}[2]; echo '
'; if ($medium_width < $photo->width || $medium_height < $photo->height) { echo ' '; $checked = ""; } else { echo ''; } echo '
'; $large_width = $photo->{"photo".$sizes['large']}[1]; $large_height = $photo->{"photo".$sizes['large']}[2]; echo '
'; if ($large_width < $photo->width || $large_height < $photo->height) { echo ' '; $checked = ""; } else { echo ''; } echo '
'; echo '
'; echo '
'; echo ''; //echo ' '; //echo 'Use as featured image '; //echo 'Delete'; //echo ' '; echo '
'; echo '
'; } echo '
'; echo '

'; echo ''; echo ''; echo '

'; echo ''; } } } class WP_OpenPhoto_Settings { function WP_OpenPhoto_Settings() { $this->__construct(); } function __construct() { add_action( 'admin_init', array( &$this, 'settings_init') ); add_action( 'admin_menu', array( &$this, 'settings_add_openphoto_page') ); } function settings_init() { register_setting( 'openphoto_wordpress_settings', 'openphoto_wordpress_settings', array(&$this,'settings_validate_submission')); } function settings_add_openphoto_page() { add_options_page( 'Configure OpenPhoto Integration', 'OpenPhoto', 'manage_options', 'openphoto_wordpress_settings', array( &$this, 'settings_render_openphoto_page') ); } function settings_render_openphoto_page() { $openphoto = get_option('openphoto_wordpress_settings'); $action = $_REQUEST['action']; if ( "update" == $action ) { $nonce=$_REQUEST['_wpnonce']; if (! wp_verify_nonce($nonce, 'openphoto_wordpress_settings') ) wp_die('You do not have permission to save this page.'); $input = $_REQUEST['openphoto_wordpress_settings']; $newinput['host'] = trim($input['host']); $newinput['size'] = trim($input['size']); $newinput['oauth_consumer_key'] = trim($input['oauth_consumer_key']); $newinput['oauth_consumer_secret'] = trim($input['oauth_consumer_secret']); $newinput['unauthorized_token'] = trim($input['unauthorized_token']); $newinput['unauthorized_token_secret'] = trim($input['unauthorized_token_secret']); $newinput['oauth_token'] = trim($input['oauth_token']); $newinput['oauth_token_secret'] = trim($input['oauth_token_secret']); $newinput['oauth_verifier'] = trim($input['oauth_verifier']); if ( $newinput['host'] != $openphoto['host'] ) { $host_changed = true; } $openphoto = $newinput; update_option('openphoto_wordpress_settings',$openphoto); if ($host_changed || empty( $openphoto['oauth_token'] ) || empty( $openphoto['oauth_token_secret'] ) ) { wp_redirect(trailingslashit(esc_attr($openphoto['host'])) . 'v1/oauth/authorize?oauth_callback=' . urlencode(admin_url("options-general.php?page=openphoto_wordpress_settings&action=authenticate&noheader=true")) . '&name=' . urlencode('OpenPhoto WordPress Plugin (' . ereg_replace("(https?)://", "", get_bloginfo('url')) . ')')); } else { wp_redirect('options-general.php?page=openphoto_wordpress_settings&message=1'); } } elseif ( "authenticate" == $action ) { // if all the values are set if ( isset($_REQUEST["oauth_consumer_key"]) && isset($_REQUEST["oauth_consumer_key"]) && isset($_REQUEST["oauth_consumer_secret"]) && isset($_REQUEST["oauth_token"]) && isset($_REQUEST["oauth_token_secret"]) && isset($_REQUEST["oauth_verifier"]) ) { // if even one of the values in the database is different than those in the request if ( $openphoto['oauth_consumer_key'] != $_REQUEST["oauth_consumer_key"] || $openphoto['oauth_consumer_secret'] != $_REQUEST["oauth_consumer_secret"] || $openphoto['unauthorized_token'] != $_REQUEST["oauth_token"] || $openphoto['unauthorized_token_secret'] != $_REQUEST["oauth_token_secret"] || $openphoto['oauth_verifier'] != $_REQUEST["oauth_verifier"]) { /* $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']); $curl_options = array( CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_URL => trailingslashit($openphoto['host']) . 'v1/oauth/token/access', CURLOPT_FRESH_CONNECT => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_POSTFIELDS => http_build_query($curl_post) ); $ch = curl_init(); curl_setopt_array($ch, $curl_options); $response = curl_exec($ch); curl_close($ch); */ if( !class_exists( 'WP_Http' ) ) include_once( ABSPATH . WPINC. '/class-http.php' ); $request = new WP_Http; $body = 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'] ); $url = trailingslashit($openphoto['host']) . 'v1/oauth/token/access'; $result = $request->request( $url, array( 'method' => 'POST', 'body' => $body) ); if ($result['response']['code'] == 200) { $access = wp_parse_args($result['body']); $openphoto['oauth_consumer_key'] = $_REQUEST["oauth_consumer_key"]; $openphoto['oauth_consumer_secret'] = $_REQUEST["oauth_consumer_secret"]; $openphoto['oauth_token'] = $access['oauth_token']; $openphoto['oauth_token_secret'] = $access['oauth_token_secret']; if ( isset($access['oauth_token']) && $access['oauth_token_secret']) { $message = 2; } else { $message = 3; } } else { $message = 3; } } update_option('openphoto_wordpress_settings',$openphoto); wp_redirect('options-general.php?page=openphoto_wordpress_settings&message=' . $message); } } echo '
'; echo '

'; echo '

Configure OpenPhoto Integration

'; switch ( $_REQUEST['message'] ) { case 1: echo '

Settings saved.

'; break; case 2: echo '

Your OpenPhoto credentials have been retrieved, and your settings have been saved.

'; break; case 3: echo '

There was an error retrieving your OpenPhoto credentials; please save these settings to try again.

'; break; } echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
Host'; echo '

Enter the web address of the home page of your OpenPhoto installation.

Size for Links

Select which size of the image the File URL link should reference when an image is inserted into a post.

Consumer Key
Consumer Secret
Token
Token Secret
'; echo ''; echo ''; echo ''; echo '

'; echo '
'; echo '
'; } function settings_validate_submission( $input ) { $newinput['host'] = trim($input['host']); $newinput['size'] = trim($input['size']); $newinput['oauth_consumer_key'] = trim($input['oauth_consumer_key']); $newinput['oauth_consumer_secret'] = trim($input['oauth_consumer_secret']); $newinput['unauthorized_token'] = trim($input['unauthorized_token']); $newinput['unauthorized_token_secret'] = trim($input['unauthorized_token_secret']); $newinput['oauth_token'] = trim($input['oauth_token']); $newinput['oauth_token_secret'] = trim($input['oauth_token_secret']); $newinput['oauth_verifier'] = trim($input['oauth_verifier']); return $newinput; } } new WP_OpenPhoto; require_once('openphoto-php/OpenPhotoOAuth.php');