Skip to content
Merged
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
31 changes: 18 additions & 13 deletions ad/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\config
}

/**
* Get specific ad
* Get a specific ad
*
* @param int $ad_id Advertisement ID
* @return array Array with advertisement data
Expand Down Expand Up @@ -100,7 +100,14 @@ public function get_ads($ad_locations, $user_groups, $non_content_page = false)

// Get user's current time and convert to UTC equivalent for comparison
$user_now = $this->user->create_datetime();
$sql_time = $this->user->get_timestamp_from_format('Y-m-d H:i:s', $user_now->format('Y-m-d H:i:s'), new \DateTimeZone('UTC'));
$sql_time = (int) gmmktime(
(int) $user_now->format('H'),
(int) $user_now->format('i'),
(int) $user_now->format('s'),
(int) $user_now->format('m'),
(int) $user_now->format('d'),
(int) $user_now->format('Y')
);

$sql = 'SELECT al.location_id, a.ad_id, a.ad_code, a.ad_centering, a.ad_consent
FROM ' . $this->ad_locations_table . ' al
Expand All @@ -127,13 +134,11 @@ public function get_ads($ad_locations, $user_groups, $non_content_page = false)
}

$current_location_id = '';
$data = array_filter($data, function ($row) use (&$current_location_id) {
return array_filter($data, static function ($row) use (&$current_location_id) {
$return = $current_location_id !== $row['location_id'];
$current_location_id = $row['location_id'];
return $return;
});

return $data;
}

/**
Expand Down Expand Up @@ -173,7 +178,7 @@ public function get_ads_by_owner($user_id)
/**
* Increment views for specified ads
*
* Note, that views are incremented only by one even when
* Note that views are incremented only by one even when
* an ad is displayed multiple times on the same page.
*
* @param array $ad_ids IDs of ads to increment views
Expand All @@ -191,7 +196,7 @@ public function increment_ads_views($ad_ids)
}

/**
* Increment clicks for specified ad
* Increment clicks for a specified ad
*
* @param int $ad_id ID of an ad to increment clicks
* @return void
Expand All @@ -205,7 +210,7 @@ public function increment_ad_clicks($ad_id)
}

/**
* Insert new advertisement to the database
* Insert a new advertisement to the database
*
* @param array $data New ad data
* @return int New advertisement ID
Expand All @@ -216,7 +221,7 @@ public function insert_ad($data)
$ad_groups = $data['ad_groups'];
$data = $this->intersect_ad_data($data);

// add a row to ads table
// add a row to the ad table
$sql = 'INSERT INTO ' . $this->ads_table . ' ' . $this->db->sql_build_array('INSERT', $data);
$this->db->sql_query($sql);
$ad_id = (int) $this->db->sql_nextid();
Expand Down Expand Up @@ -286,7 +291,7 @@ public function remove_ad_owner(array $user_ids)
}

/**
* Get all locations for specified advertisement
* Get all locations for a specified advertisement
*
* @param int $ad_id Advertisement ID
* @return array List of template locations for specified ad
Expand Down Expand Up @@ -490,7 +495,7 @@ public static function get_google_consent_aware_script_sources($ad_code)
{
$sources = array();

if (!preg_match_all('#<script\b([^>]*)>#is', $ad_code, $matches))
if (!preg_match_all('#<script\b([^>]*)>#i', $ad_code, $matches))
{
return $sources;
}
Expand Down Expand Up @@ -633,7 +638,7 @@ protected function sql_random()
}

/**
* Add rows to ad_group table.
* Add rows to the ad_group table.
*
* @param int $ad_id Advertisement ID
* @param array $ad_groups List of groups that should not see this ad
Expand All @@ -653,7 +658,7 @@ protected function insert_ad_group_data($ad_id, $ad_groups)
}

/**
* Remove all rows of specified ad in ad_group table
* Remove all rows of the specified ad in the ad_group table
*
* @param int $ad_id Advertisement ID
* @return void
Expand Down