Skip to content

Commit

Permalink
karma 2.14.2: PHP 8 compat fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
onli committed Nov 4, 2022
1 parent 87cc16e commit f3fa105
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions serendipity_event_karma/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2.14.2: Fix errors in PHP 8
2.14.1: Fix error in PHP 7 by casting variables
2.14: Added legal gdpr/dsgvo info
2.12: Iconfont a11y fix (yellowled)
Expand Down
33 changes: 19 additions & 14 deletions serendipity_event_karma/serendipity_event_karma.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function introspect(&$propbag)
$propbag->add('description', PLUGIN_KARMA_BLAHBLAH);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking, Grischa Brockhaus, Judebert, Gregor Voeltz, Ian');
$propbag->add('version', '2.14.1');
$propbag->add('version', '2.14.2');
$propbag->add('requirements', array(
'serendipity' => '1.6',
'smarty' => '2.6.7',
Expand Down Expand Up @@ -482,7 +482,7 @@ function prepareExits($entries, $get = false) {
}

if ($get) {
return $exits[$entries];
return $exits[$entries] ?? null;
}

return true;
Expand All @@ -493,7 +493,9 @@ function getExits($entryid, $get_prepared = false) {
static $karma_exits = null;

if ($karma_exits === null) {
$karma_exits = ' <span class="serendipity_karmaVoting_exits_sep">|</span> <span class="serendipity_karmaVoting_exits">' . TOP_EXITS . '</span> <span class="serendipity_karmaVoting_exits_num">(%d)</span>';
// TOP_EXITS is a language constant of serendipity_plugin_entrylinks. To keep old behaviour we use it here, but
// check for its existence to make PHP 8 happy
$karma_exits = ' <span class="serendipity_karmaVoting_exits_sep">|</span> <span class="serendipity_karmaVoting_exits">' . (defined('TOP_EXITS') ? TOP_EXITS : 'TOP_EXITS') . '</span> <span class="serendipity_karmaVoting_exits_num">(%d)</span>';
}

if ($get_prepared) {
Expand Down Expand Up @@ -770,7 +772,10 @@ function vote(karmaVote,karmaId) {

// Hook for ajax calls
case 'external_plugin':
$theUri = (string)str_replace('&amp;', '&', $eventData);
$theUri = "";
try {
$theUri = (string)str_replace('&amp;', '&', $eventData);
} catch (Error $e) {}
$uri_parts = explode('?', $theUri);

// Try to get request parameters from eventData name
Expand Down Expand Up @@ -1279,7 +1284,7 @@ function vote(karmaVote,karmaId) {
$pairs = explode('&amp;', $url_parts['query']);
foreach($pairs as $pair) {
$parts = explode('=', $pair);
$q_parts[$parts[0]] = $parts[1];
$q_parts[$parts[0]] = ($parts[1] ?? null);
}
foreach($q_parts as $key => $value) {
if (in_array($key, $exclude)) {
Expand Down Expand Up @@ -1416,12 +1421,12 @@ function vote(karmaVote,karmaId) {
*/

// Substitute the % stuff and add it to the footer
$eventData[$i]['properties']['myvote'] = $myvote;
$eventData[$i]['properties']['points'] = $points;
$eventData[$i]['properties']['votes'] = $votes;
$eventData[$i]['properties']['visits'] = $visits;
$eventData[$i]['properties']['myvote'] = ($myvote ?? '');
$eventData[$i]['properties']['points'] = ($points ?? '');
$eventData[$i]['properties']['votes'] = ($votes ?? '');
$eventData[$i]['properties']['visits'] = ($visits ?? '');

$footer .= sprintf($karma_block, $myvote, $points, $votes, $visits, $url);
$footer .= sprintf($karma_block, $myvote ?? '', $points ?? '', $votes ?? '', $visits ?? '', $url);

} // foreach key in entries
}// End switch on karma voting status
Expand Down Expand Up @@ -1562,7 +1567,7 @@ function vote(karmaVote,karmaId) {
</div>
<div class='form_field'>
<label for='serendipity_filter_ip'>".IP."</label>
<label for='serendipity_filter_ip'>". (defined('IP') ? IP : 'IP') ."</label>
<input id='serendipity_filter_ip' name='serendipity[filter][ip]' type='text' value='".(function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['GET']['filter']['ip']) : htmlspecialchars($serendipity['GET']['filter']['ip'], ENT_COMPAT, LANG_CHARSET))."'>
</div>
Expand Down Expand Up @@ -1607,7 +1612,7 @@ function vote(karmaVote,karmaId) {
// Sorting (controls go after filtering controls in form above)
$sort_order = array(
'votetime' => DATE,
'user_agent' => USER_AGENT,
'user_agent' => defined('USER_AGENT') ? USER_AGENT : 'USER_AGENT',
'title' => TITLE,
'entryid' => 'ID');
if (empty($serendipity['GET']['sort']['ordermode']) || $serendipity['GET']['sort']['ordermode'] != 'ASC') {
Expand Down Expand Up @@ -1967,7 +1972,7 @@ function getImageFiles() {
$img_data = serendipity_getimagesize($path . '/' . $filename);
if (!isset($img_data['noimage'])) {
// Curly braces are just a different syntax of associative array assignment
$images{$filename} = array('fname'=>$filename, 'width'=>$img_data[0], 'height'=>$img_data[1]);
$images[$filename] = array('fname'=>$filename, 'width'=>$img_data[0], 'height'=>$img_data[1]);
}
}
}
Expand Down Expand Up @@ -2115,7 +2120,7 @@ function set_valid_image_data() {
// Is the (possibly default) image valid?
if ($this->image_name) {
$imagesize = serendipity_getimagesize(dirname(__FILE__) . "/img/" . $this->image_name);
if ($imagesize['noimage']) {
if (isset($imagesize['noimage']) && $imagesize['noimage']) {
// No valid image; use text-only
$this->image_name = '0';
} else {
Expand Down

0 comments on commit f3fa105

Please sign in to comment.