Commit 6d57abf2 authored by M.Nowocyn's avatar M.Nowocyn

Fixed a bug in Singleton instances.

Add trigger function to ikobb.js.
Add croppie for simple picture editing and upload function.
Replaced in Event Handler ever eval function through the PHP possible functions to fix possible bugs.
Minor changes in Core.
Add Language support in Core::Link. It will contain the $_GET['lang'] all the time for every Link that is created with Core::Link().
parent 268eb536
......@@ -17,6 +17,9 @@
*/
namespace Iko;
use Iko\Event\Register;
error_reporting(E_ALL);
/**
......@@ -36,6 +39,7 @@ class Core implements iCore
public static $currentfile;
public static $templatepath;
public static $installpath;
public static $serverpath;
public static $currentpath;
public static $installPathLink;
public static $javascriptFile;
......@@ -142,30 +146,11 @@ class Core implements iCore
$current_file_PHP = $_SERVER["DOCUMENT_ROOT"] ?? "";
$current_file = $_SERVER['PHP_DOCUMENT_ROOT'] ?? $_SERVER['DOCUMENT_ROOT'];//Load Current Directory
$core_path = dirname(__FILE__);
$win = false;
if (strpos(
$core_path,
"\\"
) > 0) { //If there is \ for a Windows based System. It will replaced with /
$win = true;
}
if ($win == true) {
$current_file = str_replace(
"\\",
"/",
$current_file
); // \ -> /
$core_path = str_replace(
"\\",
"/",
$core_path
);
$current_file_PHP = str_replace(
"\\",
"/",
$current_file_PHP
);
}
Core::OSunrelatedPath($current_file);
Core::OSunrelatedPath($core_path);
Core::OSunrelatedPath($current_file_PHP);
$url = str_replace(
"core",
"",
......@@ -193,6 +178,7 @@ class Core implements iCore
if ($url == "") {
$url = "/";
}
return $url;
}
......@@ -203,7 +189,7 @@ class Core implements iCore
*
* Rewrite a given Path to a UNIX path
*/
public static function OSunrelatedPath (string $path)
public static function OSunrelatedPath (string &$path)
{
$win = false;
if (strpos(
......@@ -259,10 +245,10 @@ class Core implements iCore
);
$dir = "./";
if (count($base) > 1) {
if ($update) {
/*if ($update) {
unset($base[ count($base) - 1 ]);
unset($base[ count($base) - 1 ]);
}
}*/
for ($i = 0; $i < count($base); $i++) {
if ($base[ $i ] != "" && $i > 1) {
$dir .= "../";
......@@ -274,8 +260,8 @@ class Core implements iCore
}
/**
* @param string $attachment
* @param string $type
* @param string $attachment
* @param string $type
* @param boolean $get
*
* @return string // Get the Path to the Current file or it will be generate a string for such other files.
......@@ -617,6 +603,15 @@ class Core implements iCore
else {
$link = $module . $page . $sub;
}
if (isset($_GET['lang'])) {
$lang = defineGet(
"lang",
""
);
if ($lang != "" && \Iko\Language::exist($lang)) {
$get['lang'] = $lang;
}
}
// generate the last part of the URL ?example=something
if (count($get) > 0) {
if (self::isRewriteURL()) {
......@@ -695,8 +690,8 @@ class Core implements iCore
"x+"
);
if (fwrite(
$handle,
'<?php'
$handle,
'<?php'
) === false) {
throw new \Exception(
"Iko | error | 0001 | https://git.ikobb.de/IkoBB/IkoBB/wikis/Error-Warning-Info-Code#error-core | Error while creating file " . $config_file . " . Check directory permissions."
......
<?php
/**
* Created by PhpStorm.
* User: Marcel
* Date: 21.05.2017
* Time: 01:49
*/
namespace Iko\Event;
use Iko\Core;
use Iko\Lib\Multiton\Cache\Mixed;
use Iko\Module;
use PDO;
class Cron extends Mixed
{
const TABLE = "{prefix}cron";
const NAME = "cron_name";
const GET = "getCronName";
public static function get ( $cronName = NULL, $reload = FALSE )
{
if ( is_array( $cronName ) ) {
$name = $cronName[1];
$cronName = ( $cronName[0] instanceof Module ) ? $cronName[0]->getName() : $cronName[0];
$cronName .= $name;
unset( $name );
}
return parent::get(
$cronName,
$reload
); // TODO: Change the autogenerated stub
}
private static function convert ( $cronName )
{
if ( is_array( $cronName ) ) {
$name = $cronName[1];
$cronName = ( $cronName[0] instanceof Module ) ? $cronName[0]->getName() : $cronName[0];
$cronName .= $name;
unset( $name );
}
return $cronName;
}
public static function delete ( Cron $cron ): bool
{
Core::PDO()->beginTransaction();
$statement = Core::PDO()->exec(
"DELETE FROM " . self::TABLE . " WHERE " . self::NAME . " = " . Core::PDO()->quote( $cron->getCronName() )
);
if ( $statement !== FALSE ) {
Core::PDO()->commit();
return TRUE;
}
else {
Core::PDO()->rollBack();
}
return FALSE;
}
public static function create ( Module $module, string $name, int $interval, string $function )
{
if ( function_exists( $function ) ) {
$cronName = self::convert(
array (
$module,
$name )
);
if ( !self::exist( $cronName ) ) {
Core::PDO()->beginTransaction();
$sql = "INSERT INTO " . self::TABLE . "(cron_";
Core::PDO()->exec();
}
}
}
public static function init ()
{
$all = self::getAll();
}
protected $interval = 0;
protected $lastTrigger = 0;
protected $module;
protected $name = "";
protected $cronName = "";
protected $function = "";
protected function __construct ( $cronName )
{
$cronName = self::convert( $cronName );
$this->cronName = $cronName;
$statement = Core::PDO()->query( "SELECT * FROM " . self::TABLE . " WHERE " . self::NAME . " = $cronName" );
$fetch = $statement->fetch( PDO::FETCH_ASSOC );
foreach ( $fetch as $key => $value ) {
$temp_key = str_replace(
"cron_",
"",
$key
);
$this->{$temp_key} = $value;
}
$this->module = Module::get( $this->module );
}
/**
* @return string
*/
public function getCronName (): string
{
return $this->cronName;
}
/**
* @return \Iko\Module
*/
public function getModule (): Module
{
return $this->module;
}
/**
* @return int
*/
public function getLastTrigger (): int
{
return $this->lastTrigger;
}
/**
* @param int $lastTrigger
*/
public function setLastTrigger ( int $lastTrigger )
{
$this->lastTrigger = $lastTrigger;
}
/**
* @return string
*/
public function getName (): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName ( string $name )
{
$this->name = $name;
}
/**
* @return int
*/
public function getInterval (): int
{
return $this->interval;
}
/**
* @param int $interval
*/
public function setInterval ( int $interval )
{
$this->interval = $interval;
}
/**
* @param mixed|string $cronName
*/
public function setCronName ( $cronName )
{
$this->cronName = $cronName;
}
/**
* @return string
*/
public function getFunction (): string
{
return $this->function;
}
/**
* @param string $function
*/
public function setFunction ( string $function )
{
$this->function = $function;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Marcel
* Date: 21.05.2017
* Time: 01:49
*/
namespace Iko\Event;
use Iko\Core;
use Iko\Lib\Multiton\Cache\Mixed;
use Iko\Module;
use PDO;
class Cron extends Mixed
{
const TABLE = "{prefix}cron";
const ID = "cron_id";
const NAME = "cron_name";
const MODULE = Module::NAME;
const LAST_TRIGGER = "last_trigger_time";
const INTERVAL = "cron_interval";
const CLASS_STRING = "cron_class";
const FUNCTION = "cron_function";
const ACTIVE = "cron_active";
const IS_STATIC = "cron_static_function";
const INITAL_OVER = "cron_inital_over";
public static function get ($id = null, $reload = false)
{
$module = null;
$name = "";
if (is_array($id)) {
$module = $id[0];
$name = $id[1];
if (!$module instanceof Module) {
$module = $module->getName();
}
return self::search(
array (
self::NAME => $name,
self::MODULE => $module)
);
}
return parent::get(
$id,
$reload
); // TODO: Change the autogenerated stub
}
public static function delete (Cron $cron): bool
{
Core::PDO()->beginTransaction();
$statement = Core::PDO()->exec(
"DELETE FROM " . self::TABLE . " WHERE " . self::ID . " = " . $cron->getID()
);
if ($statement !== false) {
Core::PDO()->commit();
return true;
}
else {
Core::PDO()->rollBack();
}
return false;
}
private static function checkBacktrace (Module $module)
{
$backtrace = debug_backtrace(
\DEBUG_BACKTRACE_PROVIDE_OBJECT,
3
);
$last = $backtrace[1];
$exp = explode(
Core::getInstallPath(),
Core::OSunrelatedPath($last["file"])
);
if (count($exp) > 1) {
$file = "./" . $exp[1];
if (strpos(
$file,
$module->getPath()
) === 0) {
return true;
}
elseif (strpos(
$file,
"./core/module/loader.php"
) === 0) {
$object = $backtrace[2]["object"];
if ($object instanceof Module\Loader) {
if ($object->getModule() === $module) {
return true;
}
}
}
}
return false;
} //
public static function create (Module $module, string $name, string $class, string $func, bool $isFuncStatic = false, $canInitialOver = null): bool
{
try {
$reflection = new \ReflectionClass($class);
}
catch (\ReflectionException $exception) {
return false;
}
if (function_exists($function)) {
$cronName = self::convert(
array (
$module,
$name)
);
if (!self::exist($cronName)) {
Core::PDO()->beginTransaction();
$sql = "INSERT INTO " . self::TABLE . "(cron_";
Core::PDO()->exec();
}
}
}
public static function init ()
{
$all = self::getAll();
}
protected $id;
protected $interval = 0;
protected $lastTrigger = 0;
protected $module;
protected $name = "";
protected $function = "";
protected $active = false;
protected $call = null;
protected $class = "";
protected function __construct (int $id)
{
$statement = Core::PDO()->query("SELECT * FROM " . self::TABLE . " WHERE " . self::ID . " = " . $id);
$fetch = $statement->fetch(PDO::FETCH_ASSOC);
$this->id = intval($fetch[ self::ID ]);
$this->interval = $fetch[ self::INTERVAL ];
$this->lastTrigger = $fetch[ self::LAST_TRIGGER ];
$this->module = Module::get(self::MODULE);
$this->name = $fetch[ self::NAME ];
$this->function = $fetch[ self::FUNCTION ];
$this->class = $fetch[ self::CLASS_STRING ];
$this->active = $fetch[ self::ACTIVE ];
}
public function getID (): int
{
return $this->id;
}
/**
* @return string
*/
public function getName (): string
{
return $this->name;
}
/**
* @return \Iko\Module
*/
public function getModule (): Module
{
return $this->module;
}
/**
* @return int
*/
public function getLastTrigger (): int
{
return $this->lastTrigger;
}
/**
* @return int
*/
public function getInterval (): int
{
return $this->interval;
}
/**
* @param int $interval
*/
public function setInterval (int $interval)
{
$this->interval = $interval;
}
}
\ No newline at end of file
......@@ -111,8 +111,7 @@ class Handler
}
//If the Class can get over a special static function it will use them from the class. It will get as a return value from the function eval
elseif (isset($value["can_init_over"]) && $value["can_init_over"] != NULL) {
$class = eval("return " . $class . "::" . $value["can_init_over"] . "(" . var_export($init_Args,
TRUE) . ");");
$class = $class::{$value["can_init_over"]}($init_Args);
}
//The simplest way is to create a new instance like $var = new class($init_args); with the reflectionclass
else {
......@@ -123,8 +122,11 @@ class Handler
}
//Will call the function over eval with the same parameter like in a normal class.
else {
$var = eval("return " . $class . "::" . $function . "(" . var_export($name,
TRUE) . "," . var_export($args, TRUE) . ", " . var_export($var, TRUE) . ");");
$var = $class::{$function}(
$name,
$args,
$var
);
}
//If the returned $var is a bool statement it will be handled with the $false_counter
if ($type == "event" && $var === FALSE) {
......@@ -182,7 +184,7 @@ class Handler
$class = $value["instance"];
}
elseif (isset($value["can_init_over"]) && $value["can_init_over"] != NULL) {
$class = eval("return " . $class . "::" . $value["can_init_over"] . "(" . $init_Args . ");");
$class = $class::{$value["can_init_over"]}($init_Args);
}
else {
$class = $reflection->newInstance($init_Args);
......@@ -190,8 +192,10 @@ class Handler
$class->$function($name, $args);
}
else {
eval($class . "::" . $function . "(" . var_export($name, TRUE) . "," . var_export($args,
TRUE) . ");");
$class::{$function}(
$name,
$args
);
}
}
}
......
.croppie-container {
width: 100%;
height: 100%;
}
.croppie-container .cr-image {
z-index: -1;
position: absolute;
top: 0;
left: 0;
transform-origin: 0 0;
max-height: none;
max-width: none;
}
.croppie-container .cr-boundary {
position: relative;
overflow: hidden;
margin: 0 auto;
z-index: 1;
width: 100%;
height: 100%;
}
.croppie-container .cr-viewport,
.croppie-container .cr-resizer {
position: absolute;
border: 2px solid #FFFFFF;
margin: auto;
top: 0;
bottom: 0;
right: 0;
left: 0;
box-shadow: 0 0 2000px 2000px rgba(0, 0, 0, 0.5);
z-index: 0;
}
.croppie-container .cr-resizer {
z-index: 2;
box-shadow: none;
pointer-events: none;
}
.croppie-container .cr-resizer-vertical,
.croppie-container .cr-resizer-horisontal {
position: absolute;
pointer-events: all;
}
.croppie-container .cr-resizer-vertical::after,
.croppie-container .cr-resizer-horisontal::after {
display: block;
position: absolute;
box-sizing: border-box;
border: 1px solid black;
background: #FFFFFF;
width: 10px;
height: 10px;
content: '';
}
.croppie-container .cr-resizer-vertical {
bottom: -5px;
cursor: row-resize;
width: 100%;
height: 10px;
}
.croppie-container .cr-resizer-vertical::after {
left: 50%;
margin-left: -5px;
}
.croppie-container .cr-resizer-horisontal {
right: -5px;
cursor: col-resize;
width: 10px;
height: 100%;
}
.croppie-container .cr-resizer-horisontal::after {
top: 50%;
margin-top: -5px;
}
.croppie-container .cr-original-image {
display: none;
}
.croppie-container .cr-vp-circle {
border-radius: 50%;
}
.croppie-container .cr-overlay {
z-index: 1;
position: absolute;
cursor: move;
touch-action: none;
}
.croppie-container .cr-slider-wrap {
width: 75%;
margin: 15px auto;
text-align: center;
}
.croppie-result {
position: relative;
overflow: hidden;
}
.croppie-result img {
position: absolute;
}
.croppie-container .cr-image,
.croppie-container .cr-overlay,
.croppie-container .cr-viewport {
-webkit-transform: translateZ(0);
-moz-transform: translateZ(0);
-ms-transform: translateZ(0);
transform: translateZ(0);
}
/*************************************/
/***** STYLING RANGE INPUT ***********/
/*************************************/
/*http://brennaobrien.com/blog/2014/05/style-input-type-range-in-every-browser.html */
/*************************************/
.cr-slider {
-webkit-appearance: none;
/*removes default webkit styles*/
/*border: 1px solid white; *//*fix for FF unable to apply focus style bug */
width: 300px;
/*required for proper track sizing in FF*/
max-width: 100%;
padding-top: 8px;
padding-bottom: 8px;
background-color: transparent;
}
.cr-slider::-webkit-slider-runnable-track {
width: 100%;
height: 3px;
background: rgba(0, 0, 0, 0.5);
border: 0;
border-radius: 3px;
}
.cr-slider::-webkit-slider-thumb {
-webkit-appearance: none;
border: none;
height: 16px;
width: 16px;
border-radius: 50%;
background: #DDDDDD;
margin-top: -6px;
}
.cr-slider:focus {
outline: none;
}
/*
.cr-slider:focus::-webkit-slider-runnable-track {
background: #ccc;
}
*/
.cr-slider::-moz-range-track {
width: 100%;
height: 3px;
background: rgba(0, 0, 0, 0.5);
border: 0;
border-radius: 3px;
}
.cr-slider::-moz-range-thumb {
border: none;
height: 16px;
width: 16px;
border-radius: 50%;
background: #DDDDDD;