Skip to content

Commit

Permalink
Update to version 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joepdooper committed Apr 2, 2024
1 parent 7141272 commit d6318af
Show file tree
Hide file tree
Showing 98 changed files with 1,017 additions and 785 deletions.
22 changes: 11 additions & 11 deletions core/classes/Ivy/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,53 @@ class Button {

public static function delete($name = null, $value = null, $id = null, $formaction = null): void
{
include Template::setTemplateFile('buttons/button.delete.php');
include Template::setTemplateFile('buttons/button.confirm.php');
include Template::file('buttons/button.delete.php');
include Template::file('buttons/button.confirm.php');
}

public static function remove($name = null, $value = null): void
{
include Template::setTemplateFile('buttons/button.remove.php');
include Template::file('buttons/button.remove.php');
}

public static function close($name = null, $value = null): void
{
include Template::setTemplateFile('buttons/button.close.php');
include Template::file('buttons/button.close.php');
}

public static function save($text = null, $value = null): void
{
include Template::setTemplateFile('buttons/button.save.php');
include Template::file('buttons/button.save.php');
}

public static function confirm($text = null, $value = null): void
{
include Template::setTemplateFile('buttons/button.confirm.php');
include Template::file('buttons/button.confirm.php');
}

public static function submit($text = null): void
{
include Template::setTemplateFile('buttons/button.submit.php');
include Template::file('buttons/button.submit.php');
}

public static function link($url = null, $text = null, $icon = null, $label = null): void
{
include Template::setTemplateFile('buttons/button.link.php');
include Template::file('buttons/button.link.php');
}

public static function upload($name = null, $value = null, $id = null): void
{
include Template::setTemplateFile('buttons/button.upload.php');
include Template::file('buttons/button.upload.php');
}

public static function switch($name = null, $value = null, $id = null): void
{
include Template::setTemplateFile('buttons/button.switch.php');
include Template::file('buttons/button.switch.php');
}

public static function visible($name = null, $value = null, $id = null): void
{
include Template::setTemplateFile('buttons/button.visible.php');
include Template::file('buttons/button.visible.php');
}

}
21 changes: 21 additions & 0 deletions core/classes/Ivy/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace Ivy;

use HTMLPurifier_Config;
use HTMLPurifier;

class Controller {

protected $db;
protected $auth;
protected $router;

public function __construct() {
global $db, $auth, $router;

$this->db = $db;
$this->auth = $auth;
$this->router = $router;
}

}
21 changes: 15 additions & 6 deletions core/classes/Ivy/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ public function __construct()
`item_template`.`table`,
`item_template`.`file`,
`plugin`.`url`,
`plugin`.`active`
FROM `items`, `item_template`, `plugin`
WHERE `item_template`.`id` = `items`.`template`
AND `plugin`.`url` = `item_template`.`plugin_url`
AND `plugin`.`active` != '0'
";
`plugin`.`active`,
`position`.`value` AS `position`
FROM `items`
INNER JOIN `item_template` ON `item_template`.`id` = `items`.`template`
INNER JOIN `plugin` ON `plugin`.`url` = `item_template`.`plugin_url`
LEFT JOIN `position` ON `position`.`id` = `items`.`position_id`
WHERE `plugin`.`active` != '0'";
}

// -- get
Expand Down Expand Up @@ -84,4 +85,12 @@ public function delete()
}
}

public static function position($position, $items) {

return array_filter($items, function($item) use ($position) {
return property_exists($item, 'position') && $item->position === $position;
});

}

}
71 changes: 37 additions & 34 deletions core/classes/Ivy/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,49 @@

class Message {

public string $tpl;
public string $tpl;

function __construct() {
if(!isset($_SESSION["flash_messages"])){
$_SESSION["flash_messages"] = array();
function __construct() {
if(!isset($_SESSION["flash_messages"])){
$_SESSION["flash_messages"] = array();
}
$this->tpl = '';
}
$this->tpl = '';
}

public static function add($value, $redirect = null): void
{
if (isset($_SESSION["flash_messages"]) && !in_array($value, $_SESSION["flash_messages"])){
$_SESSION["flash_messages"][] = $value;
public static function add($value, $redirect = null): void
{
if (isset($_SESSION["flash_messages"]) && !in_array($value, $_SESSION["flash_messages"])){
$_SESSION["flash_messages"][] = $value;
}
if ($redirect){
if (headers_sent()) {
print'<script> location.replace("' . $redirect .'"); </script>';
} else {
header('location:' . $redirect, true, 302);
exit;
}
}
}
if ($redirect){
if (headers_sent()) {
print'<script> location.replace("' . $redirect .'"); </script>';
} else {
header('location:' . $redirect, true, 302);
exit;
}
}
}

public function display($value = null): void
{
if($value && !empty($this->tpl)){
include $this->tpl;
}
elseif(!empty($_SESSION["flash_messages"]) && !empty($this->tpl)){
foreach($_SESSION["flash_messages"] as $key => $value){
include $this->tpl;
}
public function display($value = null): void
{
if($value && !empty($this->tpl)){
include Template::file($this->tpl, $value);
}
elseif(!empty($_SESSION["flash_messages"]) && !empty($this->tpl)){
foreach($_SESSION["flash_messages"] as $key => $value){
$message = new \stdClass;
$message->id = $key;
$message->text = $value;
include Template::file($this->tpl, $message);
}
}
$this->remove();
}
$this->remove();
}

private function remove(): void
{
$_SESSION["flash_messages"] = array();
}
private function remove(): void
{
$_SESSION["flash_messages"] = array();
}

}
13 changes: 13 additions & 0 deletions core/classes/Ivy/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ public function where($column, $value = null, $operator = '=')
return $this;
}

// -- whereNot
public function whereNot($column, $value)
{
if (strpos($this->query, 'WHERE') === false) {
$this->query .= " WHERE `{$this->table}`.`{$column}` != :{$column}";
} else {
$this->query .= " AND `{$this->table}`.`{$column}` != :{$column}";
}
$this->bindings[$column] = $value;

return $this;
}

// -- join
public function join($table, $firstColumn, $operator, $secondColumn)
{
Expand Down
44 changes: 1 addition & 43 deletions core/classes/Ivy/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,8 @@ class Plugin extends Model {

protected $table = 'plugin';
protected $path = _BASE_PATH . 'admin/plugin';
public array $actives;
public \stdClass $plugin;

public function run(): void
{
$plugins = $this->get()->data();
if ($plugins) {
foreach ($plugins as $plugin) {
if ($plugin->active == '1') {
$this->actives[] = $plugin->name;
}
}
$_SESSION['plugin_actives'] = $this->actives;
foreach ($plugins as $plugin) {
if ($plugin->active == '1') {
$this->includeHooks($plugin);
}
}
}
}

public function includeHooks($plugin): void
{
global $auth;

$this->plugin = $plugin;

if (file_exists(_PUBLIC_PATH . _PLUGIN_PATH . $this->plugin->url . DIRECTORY_SEPARATOR . 'hooks/hook.basic.php')) {
include _PUBLIC_PATH . _PLUGIN_PATH . $this->plugin->url . DIRECTORY_SEPARATOR . 'hooks/hook.basic.php';
}
if($auth->isLoggedIn()){
if(User::canEditAsEditor($auth)){
if (file_exists(_PUBLIC_PATH . _PLUGIN_PATH . $this->plugin->url . DIRECTORY_SEPARATOR . 'hooks/hook.editor.php')) {
include _PUBLIC_PATH . _PLUGIN_PATH . $this->plugin->url . DIRECTORY_SEPARATOR . 'hooks/hook.editor.php';
}
}
if(User::canEditAsAdmin($auth)){
if (file_exists(_PUBLIC_PATH . _PLUGIN_PATH . $this->plugin->url . DIRECTORY_SEPARATOR . 'hooks/hook.admin.php')) {
include _PUBLIC_PATH . _PLUGIN_PATH . $this->plugin->url . DIRECTORY_SEPARATOR . 'hooks/hook.admin.php';
}
}
}
}

function post(): void
{
global $db;
Expand Down Expand Up @@ -153,7 +111,7 @@ private function loadPluginInfo($plugin)
$path = $dir . $file;
$url = realpath($path);

if (is_file($url)) {
if ($url) {
if (strpos($url, $dir) === 0) {
$content = file_get_contents($url);
$plugin = json_decode($content);
Expand Down
2 changes: 1 addition & 1 deletion core/classes/Ivy/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function post() {
'id' => $this->data->id,
'users_image' => ''
]);
(new \Image\Item)->delete_file($this->data->users_image);
(new \Image\Item)->delete_set($this->data->users_image);
}

if($_FILES['users_image']['tmp_name']){
Expand Down
36 changes: 27 additions & 9 deletions core/classes/Ivy/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,38 @@ class Template extends Model {
public static string $route;
public static string $id;
public static string $url = "";
public static string $file;
public static \stdClass $content;
public static ?string $file;
public static array $positions = array();
public static mixed $content;

public static function setTemplateFile($file, $content = null): bool|string
public static function file($file, $content = null, $position = null): bool|string
{
if($content) {
self::$content = $content;
}
if (file_exists(_TEMPLATE_SUB . $file)) {
return _TEMPLATE_SUB . $file;
self::$file = _TEMPLATE_SUB . $file;
} elseif(file_exists(_TEMPLATE_BASE . $file)) {
return _TEMPLATE_BASE . $file;
self::$file = _TEMPLATE_BASE . $file;
} elseif(file_exists($file)) {
return $file;
self::$file = $file;
} else {
self::$file = false;
}
if($content) {
self::$content = $content;
}
if($position) {
self::$positions[$position]['file'] = self::$file;
self::$positions[$position]['content'] = $content;
}
return self::$file;
}

public static function position($position, $content = null): string|bool
{
if($content){
self::$positions[$position]['content'] = $content;
}
if (array_key_exists($position, self::$positions)) {
return self::file(self::$positions[$position]['file'], self::$positions[$position]['content']);
} else {
return false;
}
Expand Down
7 changes: 3 additions & 4 deletions core/classes/Ivy/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,11 @@ function login(): void
function logout(): void
{

global $auth, $hooks;
global $auth;

if($_SERVER['REQUEST_METHOD'] === 'POST'){

$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
$hooks = new \Hooks();

$hooks->do_action('start_logout_action');

Expand All @@ -114,7 +113,7 @@ function logout(): void

$hooks->do_action('end_logout_action');

Message::add('Logout succesfully',_BASE_PATH);
Message::add('Logout successfully',_BASE_PATH);

}

Expand Down
7 changes: 5 additions & 2 deletions core/include/const.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?php
// version
define('_IVY_VERSION', '0.6.0');
define('_IVY_VERSION', '0.7.0');
// public
define('_PUBLIC', DIRECTORY_SEPARATOR . 'public');
// subfolder
$scriptPath = str_replace('\\', '/', dirname($_SERVER['SCRIPT_FILENAME']));
$scriptPath = rtrim($scriptPath, '/'); // Remove trailing slash
$scriptPath = str_replace($_SERVER['DOCUMENT_ROOT'], '', $scriptPath);
// $scriptPath = str_replace(_PUBLIC, '', $scriptPath);
$scriptPath = ($scriptPath !== '' ? $scriptPath : '');
define('_SUBFOLDER', $scriptPath . '/');
define('_SUBFOLDER', $scriptPath . DIRECTORY_SEPARATOR);
// root
define('_ROOT', $_SERVER['DOCUMENT_ROOT']);
// protocol http or https
Expand Down
Loading

0 comments on commit d6318af

Please sign in to comment.