Skip to content

Commit

Permalink
More escaping (#62)
Browse files Browse the repository at this point in the history
* More phpcs for escaping
* Update recaptcha code to not add extra parameter
* Remove or fix a few old ignore statements
* Include an excluded file from phpcs
* phpstan and syntax fixes
* Fix php 8 undefined property
* Use awpcp.min.js if src is not available
  • Loading branch information
stephywells authored Jun 13, 2024
1 parent 7008cf3 commit 51296bd
Show file tree
Hide file tree
Showing 181 changed files with 1,697 additions and 836 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = function( grunt ) {
'**/*', '!**/*~', '!**/**.less', '!**/less/**', '!**/**.css.map',
'!**/.*', '!phpcs.xml', '!composer.json', '!**/**.sh',
'!composer.lock', '!grunt/**', '!Gruntfile.js',
'!**/*.src.js',
'!**/*.src.js', '!**/stubs.php', '!**/**.neon',
'!node_modules/**', '!package.json', '!package-lock.json',
'!phpunit.xml', '!Pipfile*', '!tasks.py',
'!Vagrantfile', '!tests/**', '!bin/**', '!vendor/**',
Expand Down
2 changes: 1 addition & 1 deletion README.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Plugin Name: WordPress Classifieds Plugin - Ad Directory & Listings by AWP Classifieds
Contributors: awpcp, sswells, srwells
Tags: listings, classified ads, classified, classifieds, directory plugin, classifieds script, classified theme, wp classified, ads
Requires at least: 4.9
Requires at least: 6.2.0
Requires PHP: 5.6
Tested up to: 6.4.3
Stable tag: 4.3.2
Expand Down
7 changes: 5 additions & 2 deletions admin/admin-panel-credit-plans-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ public function column_price($item) {

public function single_row($item) {
static $row_class = '';
$row_class = ( $row_class == '' ? ' class="alternate"' : '' );
$row_class = $row_class === '' ? 'alternate' : '';

echo '<tr id="credit-plan-' . esc_attr( $item->id ) . '" data-id="' . esc_attr( $item->id ) . '"' . $row_class . '>';
echo '<tr id="credit-plan-' . esc_attr( $item->id ) . '" data-id="' . esc_attr( $item->id ) . '"';
echo ' class="' . esc_attr( $row_class ) . '"';
echo '>';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $this->single_row_columns( $item );
echo '</tr>';
}
Expand Down
7 changes: 5 additions & 2 deletions admin/admin-panel-fees-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,12 @@ public function column_private($item) {

public function single_row($item) {
static $row_class = '';
$row_class = ( $row_class == '' ? ' class="alternate"' : '' );
$row_class = $row_class === '' ? 'alternate' : '';

echo '<tr id="fee-' . esc_attr( $item->id ) . '" data-id="' . esc_attr( $item->id ) . '"' . $row_class . '>';
echo '<tr id="fee-' . esc_attr( $item->id ) . '" data-id="' . esc_attr( $item->id ) . '"';
echo ' class="' . esc_attr( $row_class ) . '"';
echo '>';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $this->single_row_columns( $item );
echo '</tr>';
}
Expand Down
23 changes: 3 additions & 20 deletions admin/admin-panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,21 +406,11 @@ public function notices() {
if ( $show_quick_start_quide_notice && is_awpcp_admin_page() && ! $show_drip_autoresponder ) {
wp_enqueue_style( 'awpcp-admin-style' );

ob_start();
include(AWPCP_DIR . '/admin/templates/admin-quick-start-guide-notice.tpl.php');
$html = ob_get_contents();
ob_end_clean();

echo $html;
include AWPCP_DIR . '/admin/templates/admin-quick-start-guide-notice.tpl.php';
}

if (get_awpcp_option('show-widget-modification-notice')) {
ob_start();
include(AWPCP_DIR . '/admin/templates/admin-widget-modification-notice.tpl.php');
$html = ob_get_contents();
ob_end_clean();

echo $html;
include AWPCP_DIR . '/admin/templates/admin-widget-modification-notice.tpl.php';
}

if ( awpcp_get_var( array( 'param' => 'action' ) ) === 'awpcp-manage-credits' ) {
Expand Down Expand Up @@ -472,14 +462,7 @@ private function get_message_for_blocking_manual_upgrade_notice() {
private function load_notice_for_manual_upgrades( $message ) {
wp_enqueue_style( 'awpcp-admin-style' );

ob_start();
include( AWPCP_DIR . '/admin/templates/admin-pending-manual-upgrade-notice.tpl.php' );
$html = ob_get_contents();
ob_end_clean();

echo $html;

return;
include AWPCP_DIR . '/admin/templates/admin-pending-manual-upgrade-notice.tpl.php';
}

private function load_notice_for_non_blocking_manual_uprades() {
Expand Down
1 change: 1 addition & 0 deletions admin/categories/class-delete-categories-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class AWPCP_Delete_Categories_Admin_Page {
private $categories_logic;
private $categories;
private $request;
protected $router;

public function __construct( $categories_logic, $categories, $router, $request ) {
$this->categories_logic = $categories_logic;
Expand Down
3 changes: 2 additions & 1 deletion admin/class-csv-exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AWPCP_CSVExporter {
private $exported = 0;
private $listing;
private $listing_data;
private $images_archive;

public function __construct( $settings, $settings_api, $workingdir = null, $listings = array() ) {
$this->settings = array_merge( $this->settings, $settings );
Expand Down Expand Up @@ -300,7 +301,7 @@ private function prepare_images() {
continue;
}

$this->images_archive = ( ! isset( $this->images_archive ) ) ? $this->get_pclzip_instance( $this->workingdir . 'images.zip' ) : $this->images_archive;
$this->images_archive = $this->images_archive === null ? $this->get_pclzip_instance( $this->workingdir . 'images.zip' ) : $this->images_archive;
$success = $this->images_archive->add( $img_path, PCLZIP_OPT_REMOVE_ALL_PATH );
if ( $success ) {
$images[] = basename( $img_path );
Expand Down
6 changes: 6 additions & 0 deletions admin/class-export-settings-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class AWPCP_Export_Settings_Admin_Page {
*/
private $template_renderer;

/**
* @var Request
*/
private $request;

/**
* Constructor.
*/
Expand All @@ -66,6 +71,7 @@ public function on_admin_init() {
header( 'Content-Disposition: attachment; filename=' . $filename );
header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ), true );

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $this->settings_reader->read_all();

exit();
Expand Down
1 change: 1 addition & 0 deletions admin/class-import-listings-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function enqueue_scripts() {
}

public function dispatch() {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $this->handle_request();
}

Expand Down
1 change: 1 addition & 0 deletions admin/class-missing-paypal-merchant-id-setting-notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function maybe_show_notice() {
return;
}

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $this->render_notice();
}

Expand Down
2 changes: 1 addition & 1 deletion admin/fees/class-fees-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public function transfer() {
'fees' => AWPCP_Fee::query(),
);

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$template = AWPCP_DIR . '/admin/templates/admin-panel-fees-delete.tpl.php';

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $this->render( $template, $params );
}

Expand Down
8 changes: 5 additions & 3 deletions admin/form-fields/class-form-fields-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ public function column_slug( $item ) {

public function single_row( $item ) {
static $row_class = '';

$row_class = ( $row_class === '' ? ' class="alternate"' : '' );
$row_class = $row_class === '' ? 'alternate' : '';

// the 'field-' part in the id attribute is important. The jQuery UI Sortable plugin relies on that
// to build a serialized string with the current order of fields.
echo '<tr id="field-' . esc_attr( $item->get_slug() ) . '" data-id="' . esc_attr( $item->get_slug() ) . '"' . $row_class . '>';
echo '<tr id="field-' . esc_attr( $item->get_slug() ) . '" data-id="' . esc_attr( $item->get_slug() ) . '"';
echo ' class="' . esc_attr( $row_class ) . '"';
echo '>';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $this->single_row_columns( $item );
echo '</tr>';
}
Expand Down
3 changes: 3 additions & 0 deletions admin/import/class-csv-importer-delegate.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class AWPCP_CSV_Importer_Delegate {
);

private $messages = array();
protected $users_cache = array();
protected $options = array();
protected $extra_fields;

public function __construct( $import_session, $columns, $listings_payments, $mime_types, $categories_logic, $categories, $listings_logic, $listings, $payments, $media_manager ) {
$this->import_session = $import_session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ public function __construct( $request ) {
public function show_contact_information_fields( $user ) {
$profile = (array) get_user_meta( $user->ID, 'awpcp-profile', true );

ob_start();
include( AWPCP_DIR . '/templates/admin/profile/contact-information-fields.tpl.php' );
$content = ob_get_contents();
ob_end_clean();

echo $content;
include AWPCP_DIR . '/templates/admin/profile/contact-information-fields.tpl.php';
}

public function save_contact_information( $user_id ) {
Expand Down
31 changes: 17 additions & 14 deletions admin/templates/admin-page.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@
<?php endif; ?>

<?php
if ( $should_show_title ) {
$heading_params = array(
'attributes' => array(
'class' => 'awpcp-page-header',
),
'content' => $page_title, // no need to escape; title() is allowed to output html
'echo' => true,
);
if ( $should_show_title ) {
$heading_params = array(
'attributes' => array(
'class' => 'awpcp-page-header',
),
'content' => $page_title, // no need to escape; title() is allowed to output html
'echo' => true,
);

awpcp_html_admin_first_level_heading( $heading_params );
}
?>
awpcp_html_admin_first_level_heading( $heading_params );
}

<?php $sidebar = $show_sidebar ? awpcp_admin_sidebar() : ''; ?>
<?php echo $sidebar; ?>
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $sidebar = $show_sidebar ? awpcp_admin_sidebar() : '';
?>

<div class="awpcp-main-content <?php echo empty( $sidebar ) ? 'without-sidebar' : 'with-sidebar'; ?>">
<div class="awpcp-inner-content">
<?php echo $content; ?>
<?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $content;
?>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<fieldset class="inline-edit-col-right"><div class="inline-edit-col">
<label><span class="title"><?php echo esc_html( __( 'Description', 'another-wordpress-classifieds-plugin' ) ); ?></span></label>
<textarea name="description" cols="54" rows="6"><?php echo stripslashes( awpcp_get_property( $entry, 'description' ) ) ?></textarea>
<textarea name="description" cols="54" rows="6"><?php echo esc_textarea( stripslashes( awpcp_get_property( $entry, 'description' ) ) ); ?></textarea>
</fieldset>

<p class="submit inline-edit-save">
Expand Down
18 changes: 13 additions & 5 deletions admin/templates/admin-panel-credit-plans.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
?><div class="metabox-holder">
<div class="awpcp-credit-system-settings-postbox postbox">
<?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo awpcp_html_postbox_handle( array( 'content' => esc_html( __( 'Credit System Settings', 'another-wordpress-classifieds-plugin' ) ) ) );
awpcp_html_postbox_handle(
array(
'content' => __( 'Credit System Settings', 'another-wordpress-classifieds-plugin' ),
'echo' => true,
)
);
?>
<div class="inside">
<form action="<?php echo esc_attr( admin_url( 'options.php' ) ); ?>" method="post">
Expand All @@ -32,7 +36,11 @@

<?php $url = $page->url( array( 'action' => 'add-credit-plan' ) ); ?>
<?php $label = __( 'Add Credit Plan', 'another-wordpress-classifieds-plugin' ); ?>
<?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<a class="add button-primary" title="<?php echo esc_attr( $label ); ?>" href="<?php echo esc_attr( $url ); ?>" accesskey="s"><?php echo esc_html( $label ); ?></a>
<?php echo $table->display(); ?>
<a class="add button-primary" title="<?php echo esc_attr( $label ); ?>" href="<?php echo esc_attr( $url ); ?>" accesskey="s">
<?php echo esc_html( $label ); ?>
</a>
<?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $table->display();
?>
</form>
Loading

0 comments on commit 51296bd

Please sign in to comment.