Skip to content

Enhance code quality by optimizing logic and aligning with coding standards #2126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
18 changes: 8 additions & 10 deletions app/admin/RTMediaAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,9 @@ public function __construct() {
if ( isset( $rtmedia_option['general_showAdminMenu'] ) && 1 === intval( $rtmedia_option['general_showAdminMenu'] ) ) {
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 100, 1 );
}
} else {
if ( is_array( $rtmedia->options ) ) {
if ( 1 === intval( $rtmedia->options['general_showAdminMenu'] ) ) {
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 100, 1 );
}
} elseif ( is_array( $rtmedia->options ) ) {
if ( 1 === intval( $rtmedia->options['general_showAdminMenu'] ) ) {
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 100, 1 );
}
}

Expand Down Expand Up @@ -1403,10 +1401,10 @@ public function linkback() {
*/
public function export_settings() {

// permission check.
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array( 'message' => esc_html__( 'You do not have permission to export settings.', 'buddypress-media' ) ) );
}
// permission check.
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array( 'message' => esc_html__( 'You do not have permission to export settings.', 'buddypress-media' ) ) );
}

$rtmedia_option = get_option( 'rtmedia-options' );

Expand Down Expand Up @@ -1435,7 +1433,7 @@ public function import_settings( $file_path ) {
}

$settings_data_json_string = file_get_contents( $file_path );
$settings_data_json = json_decode( $settings_data_json_string, true );
$settings_data_json = json_decode( $settings_data_json_string, true );
wp_delete_file( $file_path );

if ( empty( $settings_data_json ) ) {
Expand Down
18 changes: 9 additions & 9 deletions app/admin/RTMediaFormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public static function selectBox( $args ) { // phpcs:ignore WordPress.NamingConv
* @access static
*
* @param array $args arguments to display textarea.
* @param bool $echo Do echo or not.
* @param bool $display Do echo or not.
*
* @return string $chk_obj->get_textarea( $args )
*/
public static function textarea( $args, $echo = true ) {
public static function textarea( $args, $display = true ) {
$defaults = array(
'key' => '',
'desc' => '',
Expand All @@ -83,7 +83,7 @@ public static function textarea( $args, $echo = true ) {

$chk_obj = new rtForm();

if ( $echo ) {
if ( $display ) {
$chk_obj->display_textarea( $args );
} else {
return $chk_obj->get_textarea( $args );
Expand All @@ -98,11 +98,11 @@ public static function textarea( $args, $echo = true ) {
* @access static
*
* @param array $args arguments to display checkbox.
* @param bool $echo Do echo or not.
* @param bool $display Do echo or not.
*
* @return string $chk_obj->get_switch( $args )
*/
public static function checkbox( $args, $echo = true ) {
public static function checkbox( $args, $display = true ) {
$defaults = array(
'key' => '',
'desc' => '',
Expand All @@ -129,7 +129,7 @@ public static function checkbox( $args, $echo = true ) {

$chk_obj = new rtForm();

if ( $echo ) {
if ( $display ) {
$chk_obj->display_switch( $args );
} else {
return $chk_obj->get_switch( $args );
Expand Down Expand Up @@ -265,13 +265,13 @@ public static function textbox( $args ) {
* @access static
*
* @param array $args arguments to create link.
* @param bool $echo Echo or not.
* @param bool $display Echo or not.
*
* @return string $link_obj
*
* @throws rtFormInvalidArgumentsException Invalid argument exception.
*/
public static function link( $args, $echo = true ) {
public static function link( $args, $display = true ) {

$defaults = array(
'href' => '',
Expand Down Expand Up @@ -299,7 +299,7 @@ public static function link( $args, $echo = true ) {

$link_obj = new rtForm();

if ( $echo ) {
if ( $display ) {

$link_obj->display_link( $args );
} else {
Expand Down
1 change: 0 additions & 1 deletion app/admin/RTMediaUploadTermsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public function enqueue_scripts_styles() {
);

wp_localize_script( 'rtmedia-upload-terms-main', 'rtm_upload_terms_error_msgs', $translation_data );

}

/**
Expand Down
3 changes: 1 addition & 2 deletions app/helper/RTMediaActivityModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ public function check( $activity_id = '' ) {

if ( $results ) {
return true;
} else {
return false;
}
return false;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions app/helper/RTMediaCommentNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public function format_comment_notifications( $params ) {
esc_url( $return['link'] ),
esc_html( $return['text'] )
);
} else {
return $return;
}
return $return;
}
return '';
}

/**
Expand Down Expand Up @@ -143,7 +143,6 @@ public function remove_comment_notification( $comment_id ) {
BP_Notifications_Notification::delete( array( 'id' => $comment_notification_id ) );
delete_comment_meta( $comment_id, 'comment_notification_id' );
}

}
}

Expand Down
3 changes: 1 addition & 2 deletions app/helper/RTMediaInteractionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ public function check( $user_id = '', $media_id = '', $action = '' ) {

if ( $results ) {
return true;
} else {
return false;
}
return false;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions app/helper/RTMediaLikeNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,8 @@ public function format_like_notifications( $params ) {
esc_url( $return['link'] ),
esc_html( $return['text'] )
);
} else {
return $return;
}
return $return;
}
}

Expand Down
28 changes: 11 additions & 17 deletions app/helper/RTMediaModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,22 @@ public function get( $columns, $offset = false, $per_page = false, $order_by = '
$allowed_order_columns = array( 'media_id', 'media_title', 'file_size', 'ratings_average', 'likes' ); // Define allowed columns.
list( $order_column, $order_direction ) = explode( ' ', $order_by . ' ' ); // Default to space if no direction provided.

if ( ! in_array( strtolower( $order_column ), $allowed_order_columns ) || ! in_array(
if ( ! in_array( strtolower( $order_column ), $allowed_order_columns, true ) || ! in_array(
strtolower( $order_direction ),
array(
'asc',
'desc',
'',
)
),
true
) ) {
$order_by = 'media_id desc'; // Default order.
}

$qorder_by = '';
if ( $order_by ) {
$order_by = esc_sql( $order_by );
$qorder_by = " ORDER BY {$this->table_name}.{$order_by}";
} else {
$qorder_by = '';
}

// phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
Expand Down Expand Up @@ -459,20 +459,17 @@ public function get_other_album_count( $profile_id, $context = 'profile' ) {

if ( 'profile' === $context ) {
$sql .= $wpdb->prepare( ' AND media_author=%d ', $profile_id );
} else {
if ( 'group' === $context ) {
$sql .= $wpdb->prepare( ' AND context_id=%d ', $profile_id );
}
} elseif ( 'group' === $context ) {
$sql .= $wpdb->prepare( ' AND context_id=%d ', $profile_id );
}

$sql .= 'limit 100';
$result = $wpdb->get_results( $sql ); // phpcs:ignore

if ( isset( $result ) ) {
return count( $result );
} else {
return 0;
}
return 0;
}

/**
Expand Down Expand Up @@ -500,20 +497,17 @@ public function get_media_count() {
$counts = $rtmedia_nav_obj->actual_counts( $bp->groups->current_group->id, 'group' );
$other_count = $this->get_other_album_count( $bp->groups->current_group->id, 'group' );
}
} else {

if ( function_exists( 'bp_displayed_user_id' ) ) {
$counts = $rtmedia_nav_obj->actual_counts( bp_displayed_user_id(), 'profile' );
$other_count = $this->get_other_album_count( bp_displayed_user_id(), 'profile' );
}
} elseif ( function_exists( 'bp_displayed_user_id' ) ) {
$counts = $rtmedia_nav_obj->actual_counts( bp_displayed_user_id(), 'profile' );
$other_count = $this->get_other_album_count( bp_displayed_user_id(), 'profile' );
}

$remaining_all_media = ( ! empty( $counts['total']['all'] ) ) ? $counts['total']['all'] : 0;
$remaining_album = ( isset( $counts['total']['album'] ) ) ? $counts['total']['album'] + $other_count : 0;
$remaining_photos = ( ! empty( $counts['total']['photo'] ) ) ? $counts['total']['photo'] : 0;
$remaining_videos = ( ! empty( $counts['total']['video'] ) ) ? $counts['total']['video'] : 0;
$remaining_music = ( ! empty( $counts['total']['music'] ) ) ? $counts['total']['music'] : 0;
$remaining_docs = ( ! empty( $counts['total']['document'] ) ) ? $counts['total']['document'] : 0;
$remaining_docs = ( ! empty( $counts['total']['document'] ) ) ? $counts['total']['document'] : 0;
}

$media_counts = array(
Expand Down
16 changes: 8 additions & 8 deletions app/helper/rtDimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private function get_default_id() {
* @access private
*/
private function update_default_id() {
self::$id_count ++;
++self::$id_count;
}

/**
Expand All @@ -70,21 +70,22 @@ private function get_default_class() {
*
* @access private
*
* @param string $element element.
* @param null $class class.
* @param string $element element.
* @param array|null $embedd_class class.
*
* @return string
*
* @throws rtFormsInvalidArgumentsException Form invalid argument exception.
*/
private function embedd_class( $element, $class = null ) {
private function embedd_class( $element, $embedd_class = null ) {
$html = 'class= "' . $this->get_default_class();

if ( isset( $class ) ) {
if ( isset( $embedd_class ) ) {

if ( is_array( $class ) ) {
$html .= ' ' . implode( ' ', $class );
if ( is_array( $embedd_class ) ) {
$html .= ' ' . implode( ' ', $embedd_class );
} else {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
throw new rtFormsInvalidArgumentsException( 'class [' . $element . ']' );
}
}
Expand Down Expand Up @@ -192,5 +193,4 @@ public function get_dimensions( $attributes = '' ) {
public function display_dimensions( $args = '' ) {
echo wp_kses( $this->get_dimensions( $args ), RTMedia::expanded_allowed_tags() );
}

}
6 changes: 3 additions & 3 deletions app/helper/rtProgress.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ public function __construct() {
* @access public
*
* @param float $progress Current progress.
* @param bool $echo Echo.
* @param bool $display Echo.
*
* @return string $progress_ui
*/
public function progress_ui( $progress, $echo = true ) {
public function progress_ui( $progress, $display = true ) {
$progress_ui = '
<div id="rtprogressbar">
<div style="width:' . esc_attr( $progress ) . '%"></div>
</div>
';

if ( $echo ) {
if ( $display ) {
echo wp_kses( $progress_ui, RTMedia::expanded_allowed_tags() );
} else {
return $progress_ui;
Expand Down
1 change: 1 addition & 0 deletions app/importers/BPMediaAlbumimporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ public static function bpmedia_ajax_import_step_favorites() {
'meta_key' => 'bp_favorite_activities',
'offset' => $offset,
'number' => 1,
'fields' => 'ID',
)
);

Expand Down
9 changes: 3 additions & 6 deletions app/importers/BPMediaImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ public static function _active( $path ) { // phpcs:ignore PSR2.Methods.MethodDec
$plugins = get_plugins();
if ( array_key_exists( $path, $plugins ) ) {
return 0;
} else {
return - 1;
}
return - 1;
}

/**
Expand Down Expand Up @@ -221,10 +220,8 @@ public static function delete( $path ) {
}

return rmdir( $path );
} else {
if ( true === is_file( $path ) ) {
return unlink( $path );
}
} elseif ( true === is_file( $path ) ) {
return unlink( $path );
}

return false;
Expand Down
5 changes: 1 addition & 4 deletions app/importers/RTMediaActivityUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public function rtmedia_activity_upgrade( $lastid = 0, $limit = 1 ) {
echo '0';
wp_die();
}

}

/**
Expand Down Expand Up @@ -199,11 +198,9 @@ public function add_rtmedia_media_activity_upgrade_notice() {
/**
* Get pending count.
*
* @param bool|int $activity_id Activity id.
*
* @return int
*/
public function get_pending_count( $activity_id = false ) {
public function get_pending_count() {
global $wpdb;
$rtmedia_activity_model = new RTMediaActivityModel();
$rtmedia_model = new RTMediaModel();
Expand Down
Loading