Skip to content

Commit

Permalink
phpcs manual fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hinanaya committed May 29, 2024
1 parent 73e7f01 commit 64e05a7
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 73 deletions.
2 changes: 1 addition & 1 deletion classes/obfdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function error()
*/
public function assoc_list()
{
if ($this->result===false) {
if ($this->result === false) {
return false;
}

Expand Down
14 changes: 6 additions & 8 deletions controllers/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,11 @@ public function country_list()
*/
public function language_list()
{
// limited to individual living languages
if(!defined('OB_SHOW_ALL_LANGUAGES') || OB_SHOW_ALL_LANGUAGES !== true) {
if (!defined('OB_SHOW_ALL_LANGUAGES') || OB_SHOW_ALL_LANGUAGES !== true) {
// limited to individual living languages
$languages = $this->models->medialanguages('get_main');
}

// all languages
else {
} else {
// all languages
$languages = $this->models->medialanguages('get_all');
}

Expand All @@ -519,11 +517,11 @@ public function language_list()
// get top languages, add popularity to the languages
$top_languages = $this->models->medialanguages('get_top');
$language_popularities = [];
foreach($top_languages as $index=>$top_language) {
foreach ($top_languages as $index => $top_language) {
$language_popularities[$top_language] = $index;
}

foreach($languages as &$language) {
foreach ($languages as &$language) {
$language['popularity'] = $language_popularities[$language['language_id']] ?? null;
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/playlists.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public function save()
}

// Save playlist thumbnail.
if($thumbnail) {
if ($thumbnail) {
$thmb_result = $this->models->uploads('thumbnail_save', $id, 'playlist', $thumbnail);
if (!$thmb_result[0]) {
if ($new_playlist === true) {
Expand Down
10 changes: 5 additions & 5 deletions models/medialanguages_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function get_all()

/**
* Get living languages only.
*
*
* @return languages
*/
public function get_main()
Expand All @@ -58,9 +58,9 @@ public function get_main()
}


/**
/**
* Get top languages by media count.
*
*
* @return languages
*/
public function get_top($args = [])
Expand All @@ -74,8 +74,8 @@ public function get_top($args = [])

$tmp = $this->db->assoc_list();

foreach($tmp as $language) {
$languages[] = $language['language'];
foreach ($tmp as $language) {
$languages[] = $language['language'];
}

return $languages;
Expand Down
4 changes: 3 additions & 1 deletion models/mediametadata_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function get_all()
{
$this->db->orderby('order_id');
$fields = $this->db->get('media_metadata');
if(!$fields) return [];
if (! $fields) {
return [];
}

foreach ($fields as &$field) {
if (!$field['settings']) {
Expand Down
4 changes: 2 additions & 2 deletions models/players_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public function get($params)
}

if ($default_playlist) {
$results[$index]['default_playlist_name']=$default_playlist['name'];
$results[$index]['default_playlist_id']=$default_playlist['id'];
$results[$index]['default_playlist_name'] = $default_playlist['name'];
$results[$index]['default_playlist_id'] = $default_playlist['id'];
}

// get our station ids
Expand Down
2 changes: 1 addition & 1 deletion models/playlists_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public function validate_dynamic_properties($search_query, $num_items, $num_item

//T Invalid search criteria.
if (array_search($filter['op'], array('like','not_like','is','not','gte','lte','has','not_has')) === false) {
return array(false,'Invalid search criteria.'.$filter['op']);
return array(false, 'Invalid search criteria.' . $filter['op']);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions models/users_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ public function user_manage_key_permissions_save($id, $data, $user_id)
return $validation;
}

// redo format for v2 permissions to make it easier to deal with later (TODO: fix v1
// redo format for v2 permissions to make it easier to deal with later (TODO: fix v1
// too even if it's currently dependent on newlines for api.php)
$permissions_v2 = json_encode(array_map(
fn($i) => explode(' ', $i),
fn($i) => explode(' ', $i),
preg_split('/\r\n|\r|\n/', $data['permissions_v2'])
));

Expand Down
2 changes: 1 addition & 1 deletion remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function __construct()
$this->db->where('id', $_POST['id']);
$this->player = $this->db->get_one('players');

if(!$this->player) {
if (! $this->player) {
$this->send_xml_error('player not found');
}

Expand Down
90 changes: 44 additions & 46 deletions updates/20230418.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function run()
$matches = array_values(array_filter($new_langs, fn($new) => $new['ref_name'] == $old['name']));

if (empty($matches)) {
continue;
continue;
}

// Find all media items using the old language item, adding the new
Expand Down Expand Up @@ -139,7 +139,9 @@ public function run()
$this->db->where('name', $remain_lang['name']);
$old_langs = $this->db->get('media_languages') ?? [];

if (empty($old_langs)) continue;
if (empty($old_langs)) {
continue;
}

// We have an ISO-639-3 code: get the new ID from the languages table, then
// iterate over all the media items with old language IDs and set the language
Expand All @@ -148,7 +150,9 @@ public function run()
$this->db->where('id', $remain_lang['iso639-3']);
$iso_lang = $this->db->get('languages')[0]['language_id'] ?? null;

if (! $iso_lang) die('Failed to find language for ISO 639-3 code ' . $remain_lang['iso639-3']);
if (! $iso_lang) {
die('Failed to find language for ISO 639-3 code ' . $remain_lang['iso639-3']);
}

// Add comment if available even for pre-existing language codes.
if (isset($remain_lang['comment'])) {
Expand Down Expand Up @@ -181,7 +185,9 @@ public function run()
'ref_name' => $old['name']
]);

if (! $iso_lang) die('Failed to create new language with ISO 639-3 code '. $iso_new_code);
if (! $iso_lang) {
die('Failed to create new language with ISO 639-3 code ' . $iso_new_code);
}

$this->db->where('language_id', $old['id']);
$this->db->update('media', [
Expand Down Expand Up @@ -214,56 +220,48 @@ public function run()
}

// update serialize data to new language IDs
foreach(['dayparting', 'media_searches', 'playlists_items'] as $table) {

foreach (['dayparting', 'media_searches', 'playlists_items'] as $table) {
$rows = $this->db->get($table);

// foreach row, json decode filters
foreach ($rows as $row) {

if($table=='dayparting') {
if ($table == 'dayparting') {
$column = 'filters';
$settings = json_decode($row[$column], true);
}

elseif($table=='media_searches') {
} elseif ($table == 'media_searches') {
$column = 'query';
$settings = unserialize($row[$column]);
}

elseif($table=='playlists_items') {
} elseif ($table == 'playlists_items') {
$column = 'properties';
$properties = json_decode($row[$column], true);
$settings = &$properties['query'] ?? null;
}

else {
} else {
break;
}

// query must come from advanced search
if(!isset($settings['mode']) || $settings['mode']!='advanced') {
if (!isset($settings['mode']) || $settings['mode'] != 'advanced') {
continue;
}

// query must have filters
if(!isset($settings['filters']) || !is_array($settings['filters'])) {
if (! isset($settings['filters']) || ! is_array($settings['filters'])) {
continue;
}

$has_update = false;
foreach($settings['filters'] as &$filter) {
if($filter['filter'] == 'language') {
foreach ($settings['filters'] as &$filter) {
if ($filter['filter'] == 'language') {
$filter['val'] = $old_to_new_lang_id[$filter['val']] ?? $filter['val'];
$has_update = true;
}
}

if(!$has_update) {
if (! $has_update) {
continue;
}

$settings_encoded = $table=='media_searches' ? serialize($settings) : json_encode($settings);
$settings_encoded = ($table == 'media_searches') ? serialize($settings) : json_encode($settings);

/*
echo 'Updating '.$table.' '.$row['id'].' '.$column."\n";
Expand All @@ -284,31 +282,31 @@ public function run()
// Function created by ChatGPT
private function increment_string($str)
{
$str = strrev($str); // Reverse the string for easier iteration
$len = strlen($str);
$carry = 1; // Start with a carry to increment the first character

for ($i = 0; $i < $len; $i++) {
$char = ord($str[$i]) - ord('a') + $carry; // Get the base-26 value of the character

if ($char >= 26) { // If there is a carry
$char %= 26;
$carry = 1;
} else {
$carry = 0;
}
$str = strrev($str); // Reverse the string for easier iteration
$len = strlen($str);
$carry = 1; // Start with a carry to increment the first character

for ($i = 0; $i < $len; $i++) {
$char = ord($str[$i]) - ord('a') + $carry; // Get the base-26 value of the character

if ($char >= 26) { // If there is a carry
$char %= 26;
$carry = 1;
} else {
$carry = 0;
}

$str[$i] = chr(ord('a') + $char); // Update the character in the string
$str[$i] = chr(ord('a') + $char); // Update the character in the string

if ($carry == 0) { // No further carry, break the loop
break;
}
}
if ($carry == 0) { // No further carry, break the loop
break;
}
}

if ($carry) { // If there's still a carry after the loop
$str .= 'a'; // Append an 'a' to the string
}
if ($carry) { // If there's still a carry after the loop
$str .= 'a'; // Append an 'a' to the string
}

return strrev($str); // Reverse the string back to its original order
return strrev($str); // Reverse the string back to its original order
}
}
6 changes: 3 additions & 3 deletions updates/20231113.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public function items()

public function run()
{
if(!$this->db->column_exists('players', 'longitude')) {
if (! $this->db->column_exists('players', 'longitude')) {
$this->db->query('ALTER TABLE `players` ADD COLUMN `longitude` DECIMAL(8,5) DEFAULT NULL;');
if ($this->db->error()) {
echo $this->db->error();
return false;
}
}

if(!$this->db->column_exists('players', 'latitude')) {
if (! $this->db->column_exists('players', 'latitude')) {
$this->db->query('ALTER TABLE `players` ADD COLUMN `latitude` DECIMAL(8,5) DEFAULT NULL;');
if ($this->db->error()) {
echo $this->db->error();
Expand All @@ -31,4 +31,4 @@ public function run()

return true;
}
}
}
2 changes: 1 addition & 1 deletion updates/20231117.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ public function run()

return true;
}
}
}
2 changes: 1 addition & 1 deletion updates/20240212.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public function run()

return true;
}
}
}

0 comments on commit 64e05a7

Please sign in to comment.