Skip to content

Commit

Permalink
Fix compatibility with PHP 8.1 (typecho#1324)
Browse files Browse the repository at this point in the history
* Fix compatibility with PHP 8.1

PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in typecho/var/Widget/Archive.php on line 1292

* Fix login

* Fix write

* Fix manage

* Fix PHP Deprecated
  • Loading branch information
sy-records authored Feb 15, 2022
1 parent 13dc5e8 commit f34d142
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions admin/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
if ($user->hasLogin()) {
$response->redirect($options->adminUrl);
}
$rememberName = htmlspecialchars(\Typecho\Cookie::get('__typecho_remember_name'));
$rememberName = htmlspecialchars(\Typecho\Cookie::get('__typecho_remember_name', ''));
\Typecho\Cookie::delete('__typecho_remember_name');

$bodyClass = 'body-100';
Expand All @@ -25,7 +25,7 @@
</p>
<p class="submit">
<button type="submit" class="btn btn-l w-100 primary"><?php _e('登录'); ?></button>
<input type="hidden" name="referer" value="<?php echo htmlspecialchars($request->get('referer')); ?>" />
<input type="hidden" name="referer" value="<?php echo htmlspecialchars($request->get('referer') ?? ''); ?>" />
</p>
<p>
<label for="remember">
Expand Down
2 changes: 1 addition & 1 deletion admin/manage-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
(isset($request->status) ? 'status=' . htmlspecialchars($request->get('status')) : '') .
(isset($request->cid) ? (isset($request->status) ? '&' : '') . 'cid=' . htmlspecialchars($request->get('cid')) : '') : '')); ?>"><?php _e('&laquo; 取消筛选'); ?></a>
<?php endif; ?>
<input type="text" class="text-s" placeholder="<?php _e('请输入关键字'); ?>" value="<?php echo htmlspecialchars($request->keywords); ?>"<?php if ('' == $request->keywords): ?> onclick="value='';name='keywords';" <?php else: ?> name="keywords"<?php endif; ?>/>
<input type="text" class="text-s" placeholder="<?php _e('请输入关键字'); ?>" value="<?php echo htmlspecialchars($request->keywords ?? ''); ?>"<?php if ('' == $request->keywords): ?> onclick="value='';name='keywords';" <?php else: ?> name="keywords"<?php endif; ?>/>
<?php if(isset($request->status)): ?>
<input type="hidden" value="<?php echo htmlspecialchars($request->get('status')); ?>" name="status" />
<?php endif; ?>
Expand Down
2 changes: 1 addition & 1 deletion admin/manage-medias.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class="i-caret-down"></i></button>
<a href="<?php $options->adminUrl('manage-medias.php'); ?>"><?php _e('&laquo; 取消筛选'); ?></a>
<?php endif; ?>
<input type="text" class="text-s" placeholder="<?php _e('请输入关键字'); ?>"
value="<?php echo htmlspecialchars($request->keywords); ?>"<?php if ('' == $request->keywords): ?> onclick="value='';name='keywords';" <?php else: ?> name="keywords"<?php endif; ?>/>
value="<?php echo htmlspecialchars($request->keywords ?? ''); ?>"<?php if ('' == $request->keywords): ?> onclick="value='';name='keywords';" <?php else: ?> name="keywords"<?php endif; ?>/>
<button type="submit" class="btn btn-s"><?php _e('筛选'); ?></button>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion admin/manage-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class="i-caret-down"></i></button>
<a href="<?php $options->adminUrl('manage-pages.php'); ?>"><?php _e('&laquo; 取消筛选'); ?></a>
<?php endif; ?>
<input type="text" class="text-s" placeholder="<?php _e('请输入关键字'); ?>"
value="<?php echo htmlspecialchars($request->keywords); ?>" name="keywords"/>
value="<?php echo htmlspecialchars($request->keywords ?? ''); ?>" name="keywords"/>
<button type="submit" class="btn btn-s"><?php _e('筛选'); ?></button>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion admin/manage-users.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class="i-caret-down"></i></button>
<a href="<?php $options->adminUrl('manage-users.php'); ?>"><?php _e('&laquo; 取消筛选'); ?></a>
<?php endif; ?>
<input type="text" class="text-s" placeholder="<?php _e('请输入关键字'); ?>"
value="<?php echo htmlspecialchars($request->keywords); ?>" name="keywords"/>
value="<?php echo htmlspecialchars($request->keywords ?? ''); ?>" name="keywords"/>
<button type="submit" class="btn btn-s"><?php _e('筛选'); ?></button>
</div>
</form>
Expand Down
4 changes: 2 additions & 2 deletions admin/write-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class="edit-draft-notice"><?php _e('当前正在编辑的是保存于%s的草稿
if ($page->have()) {
$permalink = str_replace('{cid}', $page->cid, $permalink);
}
$input = '<input type="text" id="slug" name="slug" autocomplete="off" value="' . htmlspecialchars($page->slug) . '" class="mono" />';
$input = '<input type="text" id="slug" name="slug" autocomplete="off" value="' . htmlspecialchars($page->slug ?? '') . '" class="mono" />';
?>
<p class="mono url-slug">
<label for="slug" class="sr-only"><?php _e('网址缩略名'); ?></label>
Expand All @@ -43,7 +43,7 @@ class="edit-draft-notice"><?php _e('当前正在编辑的是保存于%s的草稿
<p>
<label for="text" class="sr-only"><?php _e('页面内容'); ?></label>
<textarea style="height: <?php $options->editorSize(); ?>px" autocomplete="off" id="text"
name="text" class="w-100 mono"><?php echo htmlspecialchars($page->text); ?></textarea>
name="text" class="w-100 mono"><?php echo htmlspecialchars($page->text ?? ''); ?></textarea>
</p>

<?php include 'custom-fields.php'; ?>
Expand Down
8 changes: 4 additions & 4 deletions admin/write-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class="edit-draft-notice"><?php _e('你正在编辑的是保存于 %s 的草稿,
$post->cid, $post->category, $post->year, $post->month, $post->day
], $permalink);
}
$input = '<input type="text" id="slug" name="slug" autocomplete="off" value="' . htmlspecialchars($post->slug) . '" class="mono" />';
$input = '<input type="text" id="slug" name="slug" autocomplete="off" value="' . htmlspecialchars($post->slug ?? '') . '" class="mono" />';
?>
<p class="mono url-slug">
<label for="slug" class="sr-only"><?php _e('网址缩略名'); ?></label>
Expand All @@ -47,7 +47,7 @@ class="edit-draft-notice"><?php _e('你正在编辑的是保存于 %s 的草稿,
<p>
<label for="text" class="sr-only"><?php _e('文章内容'); ?></label>
<textarea style="height: <?php $options->editorSize(); ?>px" autocomplete="off" id="text"
name="text" class="w-100 mono"><?php echo htmlspecialchars($post->text); ?></textarea>
name="text" class="w-100 mono"><?php echo htmlspecialchars($post->text ?? ''); ?></textarea>
</p>

<?php include 'custom-fields.php'; ?>
Expand Down Expand Up @@ -134,15 +134,15 @@ class="i-caret-down"></i></button>
<option
value="hidden"<?php if ($post->status == 'hidden'): ?> selected<?php endif; ?>><?php _e('隐藏'); ?></option>
<option
value="password"<?php if (strlen($post->password) > 0): ?> selected<?php endif; ?>><?php _e('密码保护'); ?></option>
value="password"<?php if (strlen($post->password ?? '') > 0): ?> selected<?php endif; ?>><?php _e('密码保护'); ?></option>
<option
value="private"<?php if ($post->status == 'private'): ?> selected<?php endif; ?>><?php _e('私密'); ?></option>
<?php endif; ?>
<option
value="waiting"<?php if (!$user->pass('editor', true) || $post->status == 'waiting'): ?> selected<?php endif; ?>><?php _e('待审核'); ?></option>
</select>
</p>
<p id="post-password"<?php if (strlen($post->password) == 0): ?> class="hidden"<?php endif; ?>>
<p id="post-password"<?php if (strlen($post->password ?? '') == 0): ?> class="hidden"<?php endif; ?>>
<label for="protect-pwd" class="sr-only">内容密码</label>
<input type="text" name="password" id="protect-pwd" class="text-s"
value="<?php $post->password(); ?>" size="16"
Expand Down
2 changes: 1 addition & 1 deletion var/Typecho/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function sendHeaders()
$timeout = 1;
}

setrawcookie($key, rawurlencode($value), $timeout, $path, $domain);
setrawcookie($key, rawurlencode($value), $timeout, $path, $domain ?? '');
}
}

Expand Down
2 changes: 1 addition & 1 deletion var/Widget/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ public function remember(string $cookieName, bool $return = false)
if ($return) {
return $value;
} else {
echo htmlspecialchars($value);
echo htmlspecialchars($value ?? '');
}
}

Expand Down
2 changes: 1 addition & 1 deletion var/Widget/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function pass(string $group, bool $return = false): bool
} else {
//防止循环重定向
$this->response->redirect(defined('__TYPECHO_ADMIN__') ? $this->options->loginUrl .
(0 === strpos($this->request->getReferer(), $this->options->loginUrl) ? '' :
(0 === strpos($this->request->getReferer() ?? '', $this->options->loginUrl) ? '' :
'?referer=' . urlencode($this->request->makeUriByRequest())) : $this->options->siteUrl, false);
}
}
Expand Down

0 comments on commit f34d142

Please sign in to comment.