Skip to content

Commit

Permalink
Closes #5106 - system notification consolidation.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaMer0n committed Nov 16, 2023
1 parent a96dde2 commit 1b69719
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 23 deletions.
80 changes: 65 additions & 15 deletions e107_admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,20 @@ function __construct()
return null;
}


if(!e107::getDb()->isTable('admin_log')) // Upgrade from v1.x to v2.x required.
{
$this->upgradeRequiredFirst = true;
}

// eHelper::clearSystemNotification(); // clear the notifications.

// Files that can cause comflicts and problems.
$fileInspector = e107::getFileInspector();
$this->deprecated = $fileInspector::getCachedDeprecatedFiles();

$this->checkCoreVersion();
$this->checkDependencies();

if(!empty($_POST['delete-deprecated']))
{
Expand Down Expand Up @@ -205,15 +209,18 @@ function __construct()
$this->checkDeveloperMode();


if($this->refresh == true)

if($this->refresh)
{
e107::getRedirect()->go(e_REQUEST_SELF);
}

// delete half-completed user accounts. (previously called in header.php )
e107::getUserSession()->deleteExpired();

}
}



private function checkPaths()
{
Expand All @@ -232,9 +239,13 @@ private function checkPaths()
else
{
$message = e107::getParser()->lanVars(ADLAN_187,$dr,true);
$mes->addWarning($message);
eHelper::addSystemNotification('check_paths_'.sha1($dr), $message);
}
}
else
{
eHelper::clearSystemNotification('check_paths_'.sha1($dr));
}
}

}
Expand Down Expand Up @@ -284,7 +295,7 @@ private function checkCoreUpdate()
// auto db update
if ('0' != ADMINPERMS)
{
return null;
return;
}

if($this->upgradeRequiredFirst)
Expand Down Expand Up @@ -488,13 +499,13 @@ private function checkWritable()
if(deftrue('e_MEDIA') && is_dir(e_MEDIA) && !is_writable(e_MEDIA))
{
$message = str_replace("[x]", e_MEDIA, ADLAN_193);
$mes->addWarning($message);
$mes->addWarning($message);
}

if(deftrue('e_SYSTEM') && is_dir(e_SYSTEM) && !is_writable(e_SYSTEM))
{
$message = str_replace("[x]", e_SYSTEM, ADLAN_193);
$mes->addWarning($message);
$mes->addWarning($message);
}

$files = e107::getFile()->scandir(e_IMAGE."avatars",'jpg,gif,png,jpeg');
Expand Down Expand Up @@ -526,7 +537,8 @@ private function checkIncompatiblePlugins()
{
if($this->upgradeRequiredFirst)
{
return null;
eHelper::clearSystemNotification('checkIncompatiblePlugins');
return;
}

$mes = e107::getMessage();
Expand All @@ -543,15 +555,21 @@ private function checkIncompatiblePlugins()

if(!empty($installedPlugs[$folder]) && ($version == $installedPlugs[$folder] || $version === '*'))
{
$inCompatText .= "<li><a title='".LAN_UNINSTALL."' href='".e_ADMIN."plugin.php?mode=installed&action=uninstall&path=".$folder."'>".$folder." v".$installedPlugs[$folder]."</a></li>";
$url = e_ADMIN."plugin.php?searchquery=$folder&filter_options=&mode=installed&action=list&etrigger_filter=etrigger_filter";
$inCompatText .= "<li><a title='".LAN_VIEW."' href='".$url."'>".$folder." v".$installedPlugs[$folder]."</a></li>";
}
}

if($inCompatText)
{
$text = "<ul>".$inCompatText."</ul>";
$mes->addWarning(ADLAN_189."&nbsp;<br /><br />".$text);
}
eHelper::addSystemNotification('checkIncompatiblePlugins', ADLAN_189."&nbsp;<br /><br />".$text);
// $mes->addWarning(ADLAN_189."&nbsp;<br /><br />".$text);
}
else
{
eHelper::clearSystemNotification('checkIncompatiblePlugins');
}

}

Expand All @@ -560,7 +578,7 @@ private function checkPasswordEncryption()
{
if($this->upgradeRequiredFirst)
{
return null;
return;
}

$us = e107::getUserSession();
Expand All @@ -570,8 +588,12 @@ private function checkPasswordEncryption()
{
$message = LAN_PASSWORD_WARNING;
$srch = array('[',']');
$repl = array("<a class='alert-link' href='".e_ADMIN."prefs.php#nav-core-prefs-security'>","</a>");
$mes->addWarning(str_replace($srch,$repl,$message));
$repl = array("<a class='text-info' href='".e_ADMIN."prefs.php#nav-core-prefs-security'>","</a>");
eHelper::addSystemNotification('checkPasswordEncryption', str_replace($srch,$repl,$message));
}
else
{
eHelper::clearSystemNotification('checkPasswordEncryption');
}

}
Expand All @@ -583,15 +605,39 @@ private function checkDeveloperMode()

if($pref['developer'] && (strpos(e_SELF,'localhost') === false) && (strpos(e_SELF,'127.0.0.1') === false))
{
e107::getMessage()->addWarning($tp->toHTML(LAN_DEVELOPERMODE_CHECK, true));
eHelper::addSystemNotification('checkDeveloperMode', $tp->toHTML(LAN_DEVELOPERMODE_CHECK, true));
}
else
{
eHelper::clearSystemNotification('checkDeveloperMode');
}
}



private function checkDependencies()
{
if(PHP_MAJOR_VERSION < 8)
{
$lanFallback = 'Your website is currently running an [outdated version of PHP], which may pose a security risk. If your plugins will allow it, we recommend upgrading to [x] to ensure that your website is secure and up-to-date.';
$lan = defset('LAN_PHP_OUTDATED', $lanFallback);
$url = e_ADMIN.'phpinfo.php';

$lan = e107::getParser()->lanVars($lan, 'PHP 8.2');

$srch = array('[',']');
$repl = [
"<a class='text-info' href='$url'>",
"</a>"
];

$lan = str_replace($srch, $repl, $lan);
eHelper::addSystemNotification('checkDependencies', $lan);
}
else
{
eHelper::clearSystemNotification('checkDependencies');
}

}

Expand Down Expand Up @@ -674,9 +720,13 @@ private function checkHtaccess() // upgrade scenario
{
if(rename(e_BASE."e107.htaccess", e_BASE.".htaccess")===false)
{
e107::getMessage()->addWarning("Please rename your <b>e107.htaccess</b> file to <b>.htaccess</b>");
eHelper::addSystemNotification('checkHtaccess', "Please rename your <b>e107.htaccess</b> file to <b>.htaccess</b>");
}
}
else
{
eHelper::clearSystemNotification('checkDependencies');
}
}


Expand Down
79 changes: 74 additions & 5 deletions e107_core/shortcodes/batch/admin_shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,55 @@ public function renderAddonUpdate($list)
return $text;
}

public function sc_admin_notifications()
{
// $content = @file_get_contents(e_SYSTEM."adminNotifications.json");
if(!$array = eHelper::getSystemNotification())
{
return '';
}


/*return '<ul class="admin-notifications nav navbar-nav navbar-right">
<li class="dropdown">
<a class="dropdown-toggle " title="" role="button" data-toggle="dropdown" data-bs-toggle="dropdown" href="#" aria-expanded="true">
<i class="fas fa-bell fa-fw"></i></a>
</li>
</ul>';*/

$count = count($array);
$lanNotify = defset('LAN_SYSTEM_NOTIFICATIONS_X', '[x] System Notifications');
$lan = e107::getParser()->lanVars($lanNotify, $count);


$text = '<ul id="admin-notifications" class=" nav navbar-nav navbar-right">
<li class="dropdown">
<a class="dropdown-toggle " title="'.$lan.'" role="button" data-toggle="dropdown" data-bs-toggle="dropdown" href="#" aria-expanded="true">
<i class="fas fa-beat fa-bell fa-fw text-warning"></i>';

$text .= ($count > 1) ? '<sup class="text-warning">'.$count.'</sup>' : '';
$text .= '</a>
<ul class="dropdown-menu" role="menu">';

foreach($array as $row)
{
$text .= '<li class="dropdown-item-text">'.$row['message'].'</li>';
}

$text .= '
</ul>
</li>
</ul>';

return $text;

}


/**
* Checks for a new version of e107 that could be available for download.
* @return string|null
*/
public function sc_admin_update()
{
if (!ADMIN) { return null; }
Expand All @@ -1708,6 +1756,7 @@ public function sc_admin_update()

if(empty($pref['check_updates']))
{
eHelper::clearSystemNotification('sc_admin_update');
return null;
}

Expand All @@ -1733,13 +1782,18 @@ public function sc_admin_update()
}

$data = e107::unserialize($cached);
$message = e107::getParser()->lanVars(LAN_NEWVERSION,$data['version']);

eHelper::addSystemNotification('sc_admin_update', "<a class='text-info' href='".$data['url']."' target='_blank'>$message</a>");

if($data === false || isset($data['status']))
{
eHelper::clearSystemNotification('sc_admin_update');
return null;
}



// Don't check for updates if running locally (comment out the next line to allow check - but
// remember it can cause delays/errors if its not possible to access the Internet
if(e_DEBUG !== true)
Expand All @@ -1748,13 +1802,15 @@ public function sc_admin_update()
}




return '<ul class="core-update-available nav navbar-nav navbar-left">
<li class="dropdown open">
<a class="dropdown-toggle " title="Core Update Available" role="button" data-toggle="dropdown" data-bs-toggle="dropdown" href="#" aria-expanded="true">
<i class="fa fa-cloud-download text-success"></i>
</a>
<ul class="dropdown-menu" role="menu">
<li class="nav-header navbar-header dropdown-header">'.e107::getParser()->lanVars(LAN_NEWVERSION,$data['version']).'</li>
<li class="nav-header navbar-header dropdown-header">'.$message.'</li>
<li><a href="'.$data['url'].'" rel="external"><i class="fa fa-download" ></i> '.LAN_DOWNLOAD.'</a></li>
<li><a href="'.$data['infourl'].'" rel="external"><i class="fa fa-file-text-o "></i> Release Notes</a></li>
</ul>
Expand Down Expand Up @@ -2085,11 +2141,24 @@ public function sc_admin_navigation($parm=null)
}

// $template = $$tmpl;
if(e107::getSession()->get('core-update-status')===true)
{
$lan = defset('LAN_DATABASE_UPDATE', "An update is available for your database. We recommend [running this update] as soon as possible to ensure that your database is secure and up-to-date.");
$srch = array('[',']');
$repl = [
"<a class='text-info' href='".e_ADMIN_ABS."e107_update.php'>",
"</a>"
];
eHelper::addSystemNotification('core_update', str_replace($srch, $repl, $lan));
}
else
{
eHelper::clearSystemNotification('core_update');
}
// $upStatus = (e107::getSession()->get('core-update-status') === true) ? '<span title="' .ADLAN_120. '" class="text-info"><i class="fa fa-database"></i></span>' : '<!-- -->';


$upStatus = (e107::getSession()->get('core-update-status') === true) ? '<span title="' .ADLAN_120. '" class="text-info"><i class="fa fa-database"></i></span>' : '<!-- -->';

return varset($template['start']). '<li><a id="e-admin-core-update" tabindex="0" href="'.e_ADMIN_ABS.'e107_update.php" class="e-popover text-primary" role="button" data-container="body" data-toggle="popover" data-bs-toggle="popover" data-placement="right" data-trigger="bottom" data-content="'.$tp->toAttribute(ADLAN_120).'">'.$upStatus.'</a></li>' .varset($template['end']);
return;
// return varset($template['start']). '<li><a id="e-admin-core-update" tabindex="0" href="'.e_ADMIN_ABS.'e107_update.php" class="e-popover text-primary" role="button" data-container="body" data-toggle="popover" data-bs-toggle="popover" data-placement="right" data-trigger="bottom" data-content="'.$tp->toAttribute(ADLAN_120).'">'.$upStatus.'</a></li>' .varset($template['end']);

}

Expand Down
1 change: 1 addition & 0 deletions e107_core/templates/admin_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
{ADMIN_MULTISITE}
{ADMIN_PM}
{ADMIN_DEBUG}
{ADMIN_NOTIFICATIONS}
{ADMIN_UPDATE}
</div>
</div>
Expand Down
35 changes: 35 additions & 0 deletions e107_handlers/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4864,6 +4864,8 @@ class eHelper
protected static $_idRegEx = '#[^\w\-]#';
protected static $_styleRegEx = '#[^\w\s\-\.;:!]#';

protected static $_systemNotify = 'systemNotifications';

/**
* @param $string
* @return array|string|string[]|null
Expand All @@ -4873,6 +4875,39 @@ public static function secureClassAttr($string)
return preg_replace(self::$_classRegEx, '', $string);
}


/**
* @return array
*/
public static function getSystemNotification()
{
return (array) e107::getSession()->get(self::$_systemNotify);
}


/**
* @param string $id
* @param string $message
* @return array|e_core_session|null
*/
public static function addSystemNotification($id, $message)
{
return e107::getSession()->set(self::$_systemNotify.'/'.$id.'/message', $message);
}


/**
* @param $id
* @return array|e_core_session|null
*/
public static function clearSystemNotification($id = '')
{
$key = !empty($id) ? self::$_systemNotify.'/'.$id : self::$_systemNotify;

return e107::getSession()->clear($key);
}


/**
* @param $string
* @return array|string|string[]|null
Expand Down

0 comments on commit 1b69719

Please sign in to comment.