Skip to content

Commit

Permalink
Fixed updated wpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Sep 17, 2018
1 parent 8c61dbf commit 2a4a725
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 86 deletions.
27 changes: 17 additions & 10 deletions plugin/admin/admin-pages/basic/root-selection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ function html() {
function enqueue_ajax( $hook ) {
if ( 'toplevel_page_sgdg_basic' === $hook ) {
\Sgdg\enqueue_script( 'sgdg_root_selection_ajax', '/admin/js/root_selection.js', [ 'jquery' ] );
wp_localize_script( 'sgdg_root_selection_ajax', 'sgdgRootpathLocalize', [
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'sgdg_root_selection' ),
'root_dir' => \Sgdg\Options::$root_path->get( [] ),
'team_drive_list' => esc_html__( 'Team drive list', 'skaut-google-drive-gallery' ),
]);
wp_localize_script(
'sgdg_root_selection_ajax',
'sgdgRootpathLocalize',
[
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'sgdg_root_selection' ),
'root_dir' => \Sgdg\Options::$root_path->get( [] ),
'team_drive_list' => esc_html__( 'Team drive list', 'skaut-google-drive-gallery' ),
]
);
}
}

Expand Down Expand Up @@ -77,10 +81,13 @@ function path_ids_to_names( $client, $path ) {
}
}
foreach ( array_slice( $path, 1 ) as $path_element ) {
$response = $client->files->get( $path_element, [
'supportsTeamDrives' => true,
'fields' => 'name',
]);
$response = $client->files->get(
$path_element,
[
'supportsTeamDrives' => true,
'fields' => 'name',
]
);
$ret[] = $response->getName();
}
return $ret;
Expand Down
18 changes: 11 additions & 7 deletions plugin/admin/tinymce.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ function register_scripts_styles() {
}
\Sgdg\enqueue_style( 'sgdg_tinymce', '/admin/css/tinymce.css' );
\Sgdg\enqueue_script( 'sgdg_tinymce', '/admin/js/tinymce.js' );
wp_localize_script( 'sgdg_tinymce', 'sgdgTinymceLocalize', [
'dialog_title' => esc_html__( 'Google Drive gallery', 'skaut-google-drive-gallery' ),
'root_name' => esc_html__( 'Google Drive gallery', 'skaut-google-drive-gallery' ),
'insert_button' => esc_html__( 'Insert', 'skaut-google-drive-gallery' ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'sgdg_editor_plugin' ),
]);
wp_localize_script(
'sgdg_tinymce',
'sgdgTinymceLocalize',
[
'dialog_title' => esc_html__( 'Google Drive gallery', 'skaut-google-drive-gallery' ),
'root_name' => esc_html__( 'Google Drive gallery', 'skaut-google-drive-gallery' ),
'insert_button' => esc_html__( 'Insert', 'skaut-google-drive-gallery' ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'sgdg_editor_plugin' ),
]
);
}

function handle_ajax() {
Expand Down
35 changes: 22 additions & 13 deletions plugin/frontend/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ function path_names( $client, array $path, array $used_path = [] ) {
$client->getClient()->setUseBatch( true );
$batch = $client->createBatch();
foreach ( $path as $segment ) {
$request = $client->files->get( $segment, [
'supportsTeamDrives' => true,
'fields' => 'name',
]);
$request = $client->files->get(
$segment,
[
'supportsTeamDrives' => true,
'fields' => 'name',
]
);
$batch->add( $request, $segment );
}
$responses = $batch->execute();
Expand Down Expand Up @@ -97,8 +100,8 @@ function apply_path( $client, $root, array $path ) {
}

function directories( $client, $dir ) {
$ids = [];
$names = [];
$ids = [];
$names = [];

$page_token = null;
do {
Expand Down Expand Up @@ -254,13 +257,19 @@ function images( $client, $dir ) {
$page_token = $response->getNextPageToken();
} while ( null !== $page_token );
if ( \Sgdg\Options::$image_ordering->getBy() === 'time' ) {
usort( $ret, function( $a, $b ) {
$asc = $a['timestamp'] - $b['timestamp'];
return \Sgdg\Options::$image_ordering->getOrder() === 'ascending' ? $asc : -$asc;
});
array_walk( $ret, function( &$item ) {
unset( $item['timestamp'] );
});
usort(
$ret,
function( $a, $b ) {
$asc = $a['timestamp'] - $b['timestamp'];
return \Sgdg\Options::$image_ordering->getOrder() === 'ascending' ? $asc : -$asc;
}
);
array_walk(
$ret,
function( &$item ) {
unset( $item['timestamp'] );
}
);
}
return $ret;
}
29 changes: 18 additions & 11 deletions plugin/frontend/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ function register() {

function add() {
\Sgdg\register_script( 'sgdg_block', '/frontend/js/block.js', [ 'wp-blocks', 'wp-element' ] );
wp_localize_script( 'sgdg_block', 'sgdgBlockLocalize', [
'block_name' => esc_html__( 'Google Drive gallery', 'skaut-google-drive-gallery' ),
'block_description' => esc_html__( 'A WordPress gallery using Google Drive as file storage', 'skaut-google-drive-gallery' ),
'root_name' => esc_html__( 'Google Drive gallery', 'skaut-google-drive-gallery' ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'sgdg_editor_plugin' ),
]);
wp_localize_script(
'sgdg_block',
'sgdgBlockLocalize',
[
'block_name' => esc_html__( 'Google Drive gallery', 'skaut-google-drive-gallery' ),
'block_description' => esc_html__( 'A WordPress gallery using Google Drive as file storage', 'skaut-google-drive-gallery' ),
'root_name' => esc_html__( 'Google Drive gallery', 'skaut-google-drive-gallery' ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'sgdg_editor_plugin' ),
]
);
\Sgdg\enqueue_style( 'sgdg_block', '/frontend/css/block.css' );
register_block_type( 'skaut-google-drive-gallery/gallery', [
'editor_script' => 'sgdg_block',
'render_callback' => '\\Sgdg\\Frontend\\Block\\html',
] );
register_block_type(
'skaut-google-drive-gallery/gallery',
[
'editor_script' => 'sgdg_block',
'render_callback' => '\\Sgdg\\Frontend\\Block\\html',
]
);
}

function html( $attributes ) {
Expand Down
12 changes: 8 additions & 4 deletions plugin/frontend/class-arrayoption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

class ArrayOption extends Option {
public function register() {
register_setting( $this->page, $this->name, [
'type' => 'string',
'sanitize_callback' => [ $this, 'sanitize' ],
]);
register_setting(
$this->page,
$this->name,
[
'type' => 'string',
'sanitize_callback' => [ $this, 'sanitize' ],
]
);
}

public function sanitize( $value ) {
Expand Down
12 changes: 8 additions & 4 deletions plugin/frontend/class-booleanoption.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ public function __construct( $name, $default_value, $page, $section, $title ) {
}

public function register() {
register_setting( $this->page, $this->name, [
'type' => 'boolean',
'sanitize_callback' => [ $this, 'sanitize' ],
]);
register_setting(
$this->page,
$this->name,
[
'type' => 'boolean',
'sanitize_callback' => [ $this, 'sanitize' ],
]
);
}

public function sanitize( $value ) {
Expand Down
12 changes: 8 additions & 4 deletions plugin/frontend/class-integeroption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

class IntegerOption extends Option {
public function register() {
register_setting( $this->page, $this->name, [
'type' => 'integer',
'sanitize_callback' => [ $this, 'sanitize' ],
]);
register_setting(
$this->page,
$this->name,
[
'type' => 'integer',
'sanitize_callback' => [ $this, 'sanitize' ],
]
);
}

public function sanitize( $value ) {
Expand Down
38 changes: 26 additions & 12 deletions plugin/frontend/class-orderingoption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,35 @@

class OrderingOption extends Option {
public function __construct( $name, $default_by, $default_order, $page, $section, $title ) {
parent::__construct( $name, [
'by' => ( 'name' === $default_by ? 'name' : 'time' ),
'order' => ( 'ascending' === $default_order ? 'ascending' : 'descending' ),
], $page, $section, $title );
parent::__construct(
$name,
[
'by' => ( 'name' === $default_by ? 'name' : 'time' ),
'order' => ( 'ascending' === $default_order ? 'ascending' : 'descending' ),
],
$page,
$section,
$title
);
}

public function register() {
register_setting( $this->page, $this->name . '_order', [
'type' => 'string',
'sanitize_callback' => [ $this, 'sanitize_order' ],
]);
register_setting( $this->page, $this->name . '_by', [
'type' => 'string',
'sanitize_callback' => [ $this, 'sanitize' ],
]);
register_setting(
$this->page,
$this->name . '_order',
[
'type' => 'string',
'sanitize_callback' => [ $this, 'sanitize_order' ],
]
);
register_setting(
$this->page,
$this->name . '_by',
[
'type' => 'string',
'sanitize_callback' => [ $this, 'sanitize' ],
]
);
}

public function sanitize_order( $value ) {
Expand Down
12 changes: 8 additions & 4 deletions plugin/frontend/class-stringoption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

class StringOption extends Option {
public function register() {
register_setting( $this->page, $this->name, [
'type' => 'string',
'sanitize_callback' => [ $this, 'sanitize' ],
]);
register_setting(
$this->page,
$this->name,
[
'type' => 'string',
'sanitize_callback' => [ $this, 'sanitize' ],
]
);
}
public function html() {
echo( '<input type="text" name="' . esc_attr( $this->name ) . '" value="' . esc_attr( get_option( $this->name, $this->default_value ) ) . '" class="regular-text">' );
Expand Down
12 changes: 7 additions & 5 deletions plugin/frontend/google-api-lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

function get_raw_client() {
$client = new \Sgdg\Vendor\Google_Client();
$client->setAuthConfig( [
'client_id' => \Sgdg\Options::$client_id->get(),
'client_secret' => \Sgdg\Options::$client_secret->get(),
'redirect_uris' => [ esc_url_raw( admin_url( 'admin.php?page=sgdg_basic&action=oauth_redirect' ) ) ],
]);
$client->setAuthConfig(
[
'client_id' => \Sgdg\Options::$client_id->get(),
'client_secret' => \Sgdg\Options::$client_secret->get(),
'redirect_uris' => [ esc_url_raw( admin_url( 'admin.php?page=sgdg_basic&action=oauth_redirect' ) ) ],
]
);
$client->setAccessType( 'offline' );
$client->setApprovalPrompt( 'force' );
$client->addScope( \Sgdg\Vendor\Google_Service_Drive::DRIVE_READONLY );
Expand Down
28 changes: 16 additions & 12 deletions plugin/frontend/shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,22 @@ function html( $atts ) {
wp_enqueue_script( 'sgdg_justified-layout' );

wp_enqueue_script( 'sgdg_gallery_init' );
wp_localize_script( 'sgdg_gallery_init', 'sgdgShortcodeLocalize', [
'ajax_url' => admin_url( 'admin-ajax.php' ),
'grid_height' => \Sgdg\Options::$grid_height->get(),
'grid_spacing' => \Sgdg\Options::$grid_spacing->get(),
'preview_speed' => \Sgdg\Options::$preview_speed->get(),
'preview_arrows' => \Sgdg\Options::$preview_arrows->get(),
'preview_closebutton' => \Sgdg\Options::$preview_close_button->get(),
'preview_quitOnEnd' => \Sgdg\Options::$preview_loop->get_inverted(),
'preview_activity' => \Sgdg\Options::$preview_activity_indicator->get(),
'breadcrumbs_top' => esc_html__( 'Gallery', 'skaut-google-drive-gallery' ),
'empty_gallery' => esc_html__( 'The gallery is empty.', 'skaut-google-drive-gallery' ),
]);
wp_localize_script(
'sgdg_gallery_init',
'sgdgShortcodeLocalize',
[
'ajax_url' => admin_url( 'admin-ajax.php' ),
'grid_height' => \Sgdg\Options::$grid_height->get(),
'grid_spacing' => \Sgdg\Options::$grid_spacing->get(),
'preview_speed' => \Sgdg\Options::$preview_speed->get(),
'preview_arrows' => \Sgdg\Options::$preview_arrows->get(),
'preview_closebutton' => \Sgdg\Options::$preview_close_button->get(),
'preview_quitOnEnd' => \Sgdg\Options::$preview_loop->get_inverted(),
'preview_activity' => \Sgdg\Options::$preview_activity_indicator->get(),
'breadcrumbs_top' => esc_html__( 'Gallery', 'skaut-google-drive-gallery' ),
'empty_gallery' => esc_html__( 'The gallery is empty.', 'skaut-google-drive-gallery' ),
]
);
wp_enqueue_style( 'sgdg_gallery_css' );
wp_add_inline_style( 'sgdg_gallery_css', '.sgdg-dir-name {font-size: ' . \Sgdg\Options::$dir_title_size->get() . ';}' );

Expand Down

0 comments on commit 2a4a725

Please sign in to comment.