Example #1
0
	/**
	 * When Kohana::$environment is set to Kohana::DEVELOPMENT
	 * the asset will be served from this Controller.
	 * Otherwise the file will be served here once and then
	 * copied to DOCROOT and subsequently served from there.
	 *
	 * @return  void
	 */
	public function action_copy()
	{
		$asset = $this->request->param('asset');
		$last_modified = date(DATE_RFC1123, filemtime($asset));
		
		if ($last_modified === $this->request->headers('if-modified-since'))
		{
			// Speed up the request by sending not modified
			$this->response->status(304);
			return;
		}
	
		if (Publicize::should_copy_to_docroot())
		{
			$uri = $this->request->param('uri');
			Publicize::copy_to_docroot($asset, $uri);
		}

		$extension = pathinfo($asset, PATHINFO_EXTENSION);

		// Bug in 3.2 prevents 'Content-Type' to work as expected -> 'content-type'
		// see: https://github.com/kohana/core/commit/4605ccb6957a7b3a9854792328c937d1db003502
		$this->response->headers(array(
			'content-type'   => File::mime_by_ext($extension),
			'Content-Length' => (string) filesize($asset),
			'Last-Modified'  => $last_modified,
		));

		$this->response->body(file_get_contents($asset));
	}
Example #2
0
 /**
  * Puts together an array of choices for a specific service.
  *
  * @param string $service The social service.
  * @return array An associative array with profile links and display names.
  */
 private function get_customize_select($service)
 {
     $choices = array('' => __('— Select —', 'jetpack'));
     $connected_services = $this->publicize->get_services('connected');
     if (isset($connected_services[$service])) {
         foreach ($connected_services[$service] as $c) {
             $choices[$this->publicize->get_profile_link($service, $c)] = $this->publicize->get_display_name($service, $c);
         }
     }
     return $choices;
 }
 /**
  * Puts together an array of choices for a specific service.
  *
  * @param string $service The social service.
  * @return array An associative array with profile links and display names.
  */
 private function get_customize_select($service)
 {
     $choices = array('' => __('— Select —', 'jetpack'));
     $connected_services = $this->publicize->get_services('connected');
     if (isset($connected_services[$service])) {
         foreach ($connected_services[$service] as $c) {
             $profile_link = $this->publicize->get_profile_link($service, $c);
             if (false === $profile_link) {
                 continue;
             }
             $choices[$profile_link] = $this->publicize->get_display_name($service, $c);
         }
     }
     if (1 === count($choices)) {
         return array();
     }
     return $choices;
 }
Example #4
0
	function broken_connection( $service_name, $id ) { ?>
		<div id="thickbox-content">
			<div class='error'>
				<p><?php printf( __( 'There was a problem connecting to %s. Please disconnect and try again.', 'jetpack' ), Publicize::get_service_label( $service_name ) ); ?></p>
			</div>
		</div><?php
	}
    function display_connection_error()
    {
        $code = false;
        if (isset($_GET['service'])) {
            $service_name = $_GET['service'];
            $error = sprintf(__('There was a problem connecting to %s to create an authorized connection. Please try again in a moment.', 'jetpack'), Publicize::get_service_label($service_name));
        } else {
            if (isset($_GET['publicize_error'])) {
                $code = strtolower($_GET['publicize_error']);
                switch ($code) {
                    case '400':
                        $error = __('An invalid request was made. This normally means that something intercepted or corrupted the request from your server to the Jetpack Server. Try again and see if it works this time.', 'jetpack');
                        break;
                    case 'secret_mismatch':
                        $error = __('We could not verify that your server is making an authorized request. Please try again, and make sure there is nothing interfering with requests from your server to the Jetpack Server.', 'jetpack');
                        break;
                    case 'empty_blog_id':
                        $error = __('No blog_id was included in your request. Please try disconnecting Jetpack from WordPress.com and then reconnecting it. Once you have done that, try connecting Publicize again.', 'jetpack');
                        break;
                    case 'empty_state':
                        $error = sprintf(__('No user information was included in your request. Please make sure that your user account has connected to Jetpack. Connect your user account by going to the <a href="%s">Jetpack page</a> within wp-admin.', 'jetpack'), Jetpack::admin_url());
                        break;
                    default:
                        $error = __('Something which should never happen, happened. Sorry about that. If you try again, maybe it will work.', 'jetpack');
                        break;
                }
            } else {
                $error = __('There was a problem connecting with Publicize. Please try again in a moment.', 'jetpack');
            }
        }
        // Using the same formatting/style as Jetpack::admin_notices() error
        ?>
		<div id="message" class="jetpack-message jetpack-err">
			<div class="squeezer">
				<h4><?php 
        echo wp_kses($error, array('a' => array('href' => true), 'code' => true, 'strong' => true, 'br' => true, 'b' => true));
        ?>
</h4>
				<?php 
        if ($code) {
            ?>
				<p><?php 
            printf(__('Error code: %s', 'jetpack'), esc_html(stripslashes($code)));
            ?>
</p>
				<?php 
        }
        ?>
			</div>
		</div>
		<?php 
    }
    function refresh_tokens_message()
    {
        global $post;
        $post_id = $post ? $post->ID : 0;
        $services = $this->get_services('all');
        // Same core nonce works for all services
        $keyring_nonce = wp_create_nonce('keyring-request');
        $expired_tokens = false;
        if (is_array($services) && count($services)) {
            foreach ($services as $name => $service) {
                if ($connections = $this->get_connections($name)) {
                    foreach ($connections as $connection) {
                        $cmeta = $this->get_connection_meta($connection);
                        // If the token for this connection is expired, or expires soon, then warn
                        if (!$this->is_expired($cmeta['expires'])) {
                            continue;
                        }
                        if (!$expired_tokens) {
                            ?>
							<div class="error below-h2 publicize-token-refresh-message">
							<p><?php 
                            echo esc_html(__('Before you hit Publish, please refresh your connection to make sure we can Publicize your post:', 'jetpack'));
                            ?>
</p>
							<?php 
                            $expired_tokens = true;
                        }
                        // No need to request for a specific token id, since the token store detects duplication and updates a single token per service
                        $nonce = wp_create_nonce("keyring-request-" . $name);
                        $url = $this->refresh_url($name);
                        ?>
						<p style="text-align: center;" id="publicize-token-refresh-<?php 
                        echo esc_attr($name);
                        ?>
" class="publicize-token-refresh-button">
							<a href="<?php 
                        echo esc_url($url);
                        ?>
" class="button" target="_refresh_<?php 
                        echo esc_attr($name);
                        ?>
">
								<?php 
                        printf(__('Refresh connection with %s', 'jetpack'), Publicize::get_service_label($name));
                        ?>
							</a>
						</p><?php 
                    }
                }
            }
        }
        if ($expired_tokens) {
            echo '</div>';
        }
    }
 function callback($path = '', $blog_id = 0, $connection_id = 0)
 {
     // Verify required Publicize Jetpack module is active
     if (!class_exists('Publicize') || method_exists('Jetpack', 'is_module_active') && !Jetpack::is_module_active('publicize')) {
         return new WP_Error('missing_jetpack_module', 'The Publicize module must be activated in order to use this endpoint.', 400);
     }
     $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id), false);
     if (is_wp_error($blog_id)) {
         return $blog_id;
     }
     $current_user = wp_get_current_user();
     if (!$current_user->ID) {
         return new WP_Error('authorization_required', 'An active access token must be used to query information about the current user.', 403);
     }
     // Attempt to find connection
     $connection = WPCOM_JSON_API_Get_Connection_Endpoint::get_connection_by_id($connection_id);
     if (empty($connection)) {
         return new WP_Error('unknown_connection', 'Connection not found.', 404);
     }
     // Verify that user has permission to view this connection
     if ($current_user->ID != $connection['user_ID'] && 0 != $connection['user_ID']) {
         return new WP_Error('authorization_required', 'You do not have permission to access this resource.', 403);
     }
     // Remove publicize connections related to the connection
     $publicize = new Publicize();
     $is_deleted = false !== $publicize->disconnect($connection['service'], $connection_id);
     if ($is_deleted) {
         do_action('rest_api_delete_publicize_connection', $connection_id);
     }
     return array('ID' => (int) $connection_id, 'deleted' => $is_deleted);
 }
Example #8
0
 function display_connection_error()
 {
     if (isset($_GET['service'])) {
         $service_name = $_GET['service'];
         $m = sprintf(__('There was a problem connecting to %s to create an authorized connection. Please try again in a moment.', 'jetpack'), Publicize::get_service_label($service_name));
     } else {
         $m = __('There was a problem connecting with Publicize. Please try again in a moment.', 'jetpack');
     }
     echo "<div class='error'>\n";
     echo '<p>' . esc_html($m) . "</p>\n";
     echo "</div>\n\n";
 }
Example #9
0
<?php defined('SYSPATH') or die('No direct script access.');

if (Publicize::should_set_route())
{
	// Set route
	Publicize::set_route();
}