Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions classes/Visualizer/Gutenberg/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ public function gutenberg_block_callback( $atts ) {
return '';
}

// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
if ( $atts['lazy'] == -1 || $atts['lazy'] == false ) {
if ( $atts['lazy'] === '-1' || $atts['lazy'] === false ) {
$atts['lazy'] = 'no';
}

Expand Down Expand Up @@ -472,11 +471,12 @@ public function get_visualizer_data( $post ) {
$permissions = get_post_meta( $post_id, Visualizer_Pro::CF_PERMISSIONS, true );

if ( empty( $permissions ) ) {
$permissions = array( 'permissions' => array(
$permissions = array(
'permissions' => array(
'read' => 'all',
'edit' => 'roles',
'edit-specific' => array( 'administrator' ),
),
),
);
}

Expand Down Expand Up @@ -824,7 +824,7 @@ public function get_permission_data( $data ) {
foreach ( $users as $user ) {
$options[ $i ]['value'] = $user->ID;
$options[ $i ]['label'] = $user->display_name;
$i++;
++$i;
}
}
break;
Expand All @@ -838,7 +838,7 @@ public function get_permission_data( $data ) {
foreach ( get_editable_roles() as $name => $info ) {
$options[ $i ]['value'] = $name;
$options[ $i ]['label'] = $name;
$i++;
++$i;
}
}
break;
Expand Down
52 changes: 26 additions & 26 deletions classes/Visualizer/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public function __construct( Visualizer_Plugin $plugin ) {
$this->_addFilter( Visualizer_Plugin::FILTER_HANDLE_REVISIONS, 'handleExistingRevisions', 10, 2 );
$this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, 'getDataAs', 10, 3 );
$this->_addAction( 'pre_get_posts', 'PreGetPosts' );
register_shutdown_function( array($this, 'onShutdown') );

register_shutdown_function( array( $this, 'onShutdown' ) );
}

/**
Expand Down Expand Up @@ -114,16 +113,16 @@ protected function _addAction( $tag, $method, $methodClass = null, $priority = 1
* @param string $tag The name of the AJAX action to which the $method is hooked.
* @param string $method Optional. The name of the method to be called. If the name of the method is not provided, tag name will be used as method name.
* @param bool $methodClass The root of the method.
* @param boolean $private Optional. Determines if we should register hook for logged in users.
* @param boolean $public Optional. Determines if we should register hook for not logged in users.
* @param boolean $logged_in Optional. Determines if we should register hook for logged in users.
* @param boolean $logged_out Optional. Determines if we should register hook for not logged in users.
* @return Visualizer_Module
*/
protected function _addAjaxAction( $tag, $method = '', $methodClass = null, $private = true, $public = false ) {
if ( $private ) {
protected function _addAjaxAction( $tag, $method = '', $methodClass = null, $logged_in = true, $logged_out = false ) {
if ( $logged_in ) {
$this->_addAction( 'wp_ajax_' . $tag, $method, $methodClass );
}

if ( $public ) {
if ( $logged_out ) {
$this->_addAction( 'wp_ajax_nopriv_' . $tag, $method, $methodClass );
}

Expand Down Expand Up @@ -169,7 +168,7 @@ protected function _addShortcode( $tag, $method ) {
*
* @since 3.2.0
*/
public function getDataAs( $final, $chart_id, $type ) {
public function getDataAs( $data, $chart_id, $type ) {
return $this->_getDataAs( $chart_id, $type );
}

Expand Down Expand Up @@ -290,8 +289,8 @@ private function _getCSV( $rows, $filename, $enclose ) {
}
rewind( $fp );
$csv = '';
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
while ( ( $array = fgetcsv( $fp ) ) !== false ) {
$array = fgetcsv( $fp );
while ( $array !== false ) {
if ( strlen( $csv ) > 0 ) {
$csv .= PHP_EOL;
}
Expand All @@ -307,7 +306,8 @@ private function _getCSV( $rows, $filename, $enclose ) {
}
$array = $temp_array;
}
$csv .= implode( ',', $array );
$csv .= implode( ',', $array );
$array = fgetcsv( $fp );
}
fclose( $fp );

Expand All @@ -333,7 +333,7 @@ private function _getExcel( $rows, $filename ) {
unset( $rows[1] );
$rows = array_values( $rows );
$rows = array_map(
function( $r ) {
function ( $r ) {
return array_map( 'strval', $r );
},
$rows
Expand Down Expand Up @@ -405,7 +405,7 @@ private function _getHTML( $rows ) {
foreach ( $rows as $row ) {
// skip the data type row.
if ( 1 === $index ) {
$index++;
++$index;
continue;
}

Expand All @@ -418,7 +418,7 @@ private function _getHTML( $rows ) {
}
}
$table .= '</tr>';
$index++;
++$index;
}
$table .= '</table>';

Expand All @@ -433,9 +433,9 @@ private function _getHTML( $rows ) {
/**
* Disable revisions temporarily for visualizer post type.
*/
protected final function disableRevisionsTemporarily() {
final protected function disableRevisionsTemporarily() {
add_filter(
'wp_revisions_to_keep', function( $num, $post ) {
'wp_revisions_to_keep', function ( $num, $post ) {
if ( $post->post_type === Visualizer_Plugin::CPT_VISUALIZER ) {
return 0;
}
Expand All @@ -449,7 +449,7 @@ protected final function disableRevisionsTemporarily() {
*
* @return bool If any revisions were found.
*/
public final function undoRevisions( $chart_id, $restore = false ) {
final public function undoRevisions( $chart_id, $restore = false ) {
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'undoRevisions for %d with%s restore', $chart_id, ( $restore ? '' : 'out' ) ), 'debug', __FILE__, __LINE__ );
if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
return false;
Expand Down Expand Up @@ -481,7 +481,7 @@ public final function undoRevisions( $chart_id, $restore = false ) {
/**
* If existing revisions exist for the chart, restore the earliest version and then create a new revision to initiate editing.
*/
public final function handleExistingRevisions( $chart_id, $chart ) {
final public function handleExistingRevisions( $chart_id, $chart ) {

do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'handleExistingRevisions for %d', $chart_id ), 'debug', __FILE__, __LINE__ );
if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
Expand Down Expand Up @@ -533,7 +533,7 @@ protected function get_user_customization_js() {
}

try {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();
global $wp_filesystem;
if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base' ) ) {
Expand All @@ -558,18 +558,18 @@ protected function get_user_customization_js() {
}

if ( ! $wp_filesystem->exists( $dir ) ) {
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
if ( ( $done = $wp_filesystem->mkdir( $dir ) ) === false ) {
$done = $wp_filesystem->mkdir( $dir );
if ( $done === false ) {
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ );
return $default;
}
}

// if file does not exist, copy.
if ( ! $wp_filesystem->exists( $file ) ) {
$src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' );
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) {
$src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' );
$done = $wp_filesystem->copy( $src, $file );
if ( $done === false ) {
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ );
return $default;
}
Expand All @@ -591,7 +591,7 @@ protected function load_chart_type( $chart_id ) {
if ( 'Visualizer_Render_Sidebar_Type_DataTable_DataTable' === $name ) {
$name = 'Visualizer_Render_Sidebar_Type_DataTable_Tabular';
}
$class = new $name;
$class = new $name();
}

if ( is_null( $class ) && Visualizer_Module::is_pro() ) {
Expand Down Expand Up @@ -752,7 +752,7 @@ public static function can_show_feature( $feature ) {
/**
* Gets the features for the provided license type.
*/
public static final function get_features_for_license( $plan ) {
final public static function get_features_for_license( $plan ) {
$is_new_personal = apply_filters( 'visualizer_is_new_personal', false );
switch ( $plan ) {
case 1:
Expand Down
1 change: 0 additions & 1 deletion classes/Visualizer/Module/AMP.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,4 @@ public function get_chart( $chart, $data, $series, $settings ) {
}
return $output['csv'];
}

}
14 changes: 6 additions & 8 deletions classes/Visualizer/Module/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,14 @@ public function __construct( Visualizer_Plugin $plugin ) {
if ( defined( 'TI_E2E_TESTING' ) ) {
$this->load_cypress_hooks();
}

}
/**
* Display review notice.
*/
public function render_review_notice( $footer_text ) {
$current_screen = get_current_screen();

$visualizer_page_ids = ['toplevel_page_visualizer', 'visualizer_page_viz-support', 'visualizer_page_ti-about-visualizer' ];
$visualizer_page_ids = array( 'toplevel_page_visualizer', 'visualizer_page_viz-support', 'visualizer_page_ti-about-visualizer' );

if ( ! empty( $current_screen ) && isset( $current_screen->id ) ) {
foreach ( $visualizer_page_ids as $page_to_check ) {
Expand Down Expand Up @@ -134,7 +133,7 @@ public function render_review_notice( $footer_text ) {
private function load_cypress_hooks() {
// all charts should load on the same page without pagination.
add_filter(
'visualizer_query_args', function( $args ) {
'visualizer_query_args', function ( $args ) {
$args['posts_per_page'] = 20;
return $args;
}, 10, 1
Expand Down Expand Up @@ -253,8 +252,7 @@ public function restoreRevision( $post_id, $revision_id ) {
* @access public
*/
public function init() {
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' == get_user_option( 'rich_editing' ) ) {
if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' === get_user_option( 'rich_editing' ) ) {
$this->_addFilter( 'mce_external_languages', 'add_tinymce_lang', 10, 1 );
$this->_addFilter( 'mce_external_plugins', 'tinymce_plugin', 10, 1 );
$this->_addFilter( 'mce_buttons', 'register_mce_button', 10, 1 );
Expand All @@ -268,7 +266,7 @@ public function init() {
* @since ?
* @access friendly
*/
function get_strings_for_block( $settings ) {
public function get_strings_for_block( $settings ) {
$class = new Visualizer_Module_Language();
$strings = $class->get_strings();
$array = array( 'visualizer_tinymce_plugin' => json_encode( $strings ) );
Expand Down Expand Up @@ -797,7 +795,7 @@ public function handleGetProSubMenu() {
/**
* Adds the screen options for pagination.
*/
function addScreenOptions() {
public function addScreenOptions() {
$screen = get_current_screen();

// bail if it's some other page.
Expand All @@ -816,7 +814,7 @@ function addScreenOptions() {
/**
* Returns the screen option for pagination.
*/
function setScreenOptions( $status, $option, $value ) {
public function setScreenOptions( $status, $option, $value ) {
if ( 'visualizer_library_per_page' === $option ) {
return $value;
}
Expand Down
22 changes: 10 additions & 12 deletions classes/Visualizer/Module/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public function __construct( Visualizer_Plugin $plugin ) {
$this->_addAjaxAction( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY, 'saveFilter' );

$this->_addFilter( 'visualizer_get_sidebar', 'getSidebar', 10, 2 );

}

/**
Expand Down Expand Up @@ -539,7 +538,8 @@ public function renderChartPages() {
if ( ! empty( $_POST ) ) {
$_POST = map_deep( $_POST, 'wp_strip_all_tags' );
}
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
$chart = $chart_id ? get_post( $chart_id ) : null;
if ( ! $chart_id || ! $chart || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
if ( empty( $_GET['lang'] ) || empty( $_GET['parent_chart_id'] ) ) {
$this->deleteOldCharts();
$default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line';
Expand Down Expand Up @@ -738,7 +738,7 @@ private function loadCodeEditorAssets( $chart_id ) {
wp_register_script( 'visualizer-codemirror-closebrackets', '//codemirror.net/addon/edit/closebrackets.js', array( 'visualizer-codemirror-core' ), Visualizer_Plugin::VERSION );
wp_register_script( 'visualizer-codemirror-sql', '//codemirror.net/mode/sql/sql.js', array( 'visualizer-codemirror-core' ), Visualizer_Plugin::VERSION );
wp_register_script( 'visualizer-codemirror-sql-hint', '//codemirror.net/addon/hint/sql-hint.js', array( 'visualizer-codemirror-core' ), Visualizer_Plugin::VERSION );
wp_register_script( 'visualizer-codemirror-hint', '//codemirror.net/addon/hint/show-hint.js', array( 'visualizer-codemirror-sql', 'visualizer-codemirror-sql-hint', 'visualizer-codemirror-placeholder', 'visualizer-codemirror-matchbrackets', 'visualizer-codemirror-closebrackets' ), Visualizer_Plugin::VERSION );
wp_register_script( 'visualizer-codemirror-hint', '//codemirror.net/addon/hint/show-hint.js', array( 'visualizer-codemirror-sql', 'visualizer-codemirror-sql-hint', 'visualizer-codemirror-placeholder', 'visualizer-codemirror-matchbrackets', 'visualizer-codemirror-closebrackets' ), Visualizer_Plugin::VERSION );
wp_register_style( 'visualizer-codemirror-core', '//codemirror.net/lib/codemirror.css', array(), Visualizer_Plugin::VERSION );
wp_register_style( 'visualizer-codemirror-hint', '//codemirror.net/addon/hint/show-hint.css', array( 'visualizer-codemirror-core' ), Visualizer_Plugin::VERSION );

Expand Down Expand Up @@ -862,10 +862,8 @@ private function _handleDataAndSettingsPage() {
array(
'ajax' => array(
'url' => admin_url( 'admin-ajax.php' ),
'nonces' => array(
),
'actions' => array(
),
'nonces' => array(),
'actions' => array(),
),
)
);
Expand Down Expand Up @@ -1028,7 +1026,7 @@ private function handleCSVasString( $data, $editor_type ) {
}
$row = explode( ',', $row );
$row = array_map(
function( $r ) {
function ( $r ) {
return '' === $r ? ' ' : $r;
},
$row
Expand Down Expand Up @@ -1079,7 +1077,7 @@ private function handleTabularData() {
if ( empty( $type ) ) {
$exclude[] = $index;
}
$index++;
++$index;
}

// when N headers are being renamed, the number of headers increases by N
Expand Down Expand Up @@ -1156,9 +1154,10 @@ public function uploadData() {
// check chart, if chart exists
// do not use filter_input as it does not work for phpunit test cases, use filter_var instead
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
$chart = $chart_id ? get_post( $chart_id ) : null;
if (
! $chart_id ||
! ( $chart = get_post( $chart_id ) ) ||
! $chart ||
$chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ||
! current_user_can( 'edit_post', $chart_id )
) {
Expand Down Expand Up @@ -1214,8 +1213,7 @@ public function uploadData() {
if ( isset( $_POST['vz-import-time'] ) ) {
apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $remote_data, $_POST['vz-import-time'] );
}
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
} elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
} elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] === 0 ) {
$source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
} elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) {
$source = $this->handleCSVasString( $_POST['chart_data'], $_POST['editor-type'] );
Expand Down
Loading
Loading