Commit 19c5e0a5 authored by Ognjen Cvetković's avatar Ognjen Cvetković

re 🤖 re

parent e81d812c
<?php
namespace WebTree;
namespace WebTree; //todo comply with psr
use WebTree\lib\int\Data\Constants;
use WebTree\Twig;
use WebTree\ImageHelper;
use WebTree\Admin;
use WebTree\Integrations;
......@@ -17,36 +16,41 @@ use WebTree\User;
use WebTree\Loader;
use Siler\Http\Request as request;
use Siler\Route;
use Siler\Http\Response;
use Siler\Twig;
/**
* WebTree Class.
*
* Main class called WebTree
*/
class WebTree {
class WebTree
{
public static $version = '0.0.1';
public static $locations;
public static $dirname = 'views';
public static $twig_cache = false;
public static $cache = false;
public static $auto_meta = true;
public static $autoescape = false;
public static $version = '0.0.1';
public static $locations;
public static $dirname = 'views';
public static $twig_cache = false;
public static $cache = false;
public static $auto_meta = true;
public static $autoescape = false;
public static $context_cache = array();
public static $context_cache = array();
/**
* @codeCoverageIgnore
*/
public function __construct() {
if ( !defined('THEPATH') ) {
/**
* @codeCoverageIgnore
*/
public function __construct()
{
if (!defined('THEPATH')) {
return;
}
self::init();
}
}
public static function context() {
public static function context()
{
return self::get_context();
}
......@@ -56,7 +60,7 @@ class WebTree {
* @return array
*/
public static function get_context() {
if ( empty(self::$context_cache) ) {
if (empty(self::$context_cache)) {
$tangle = new Tangle();
$user = new User();
......@@ -92,7 +96,7 @@ class WebTree {
* @codeCoverageIgnore
*/
protected static function init() {
if ( !defined('WEBTREE_LOADED') ) {
if (!defined('WEBTREE_LOADED')) {
Constants::init_constants();
define('WEBTREE_LOADED', true);
}
......@@ -112,30 +116,29 @@ class WebTree {
}
}
public function killRegex($regex){
public function killRegex($regex) {
$exec = "ps aux|grep -E '$regex' | grep -v grep | awk '{print $2}'";
exec($exec,$output);
exec($exec, $output);
if (count($output) > 0 ) {
if (count($output) > 0) {
$exec = "kill " . $output[0];
$this->executeIt($exec);
return $output[0];
}
return false;
}
public function psRegex($regex){
public function psRegex($regex)
{
$exec = "ps aux|grep -E '$regex' | grep -v grep | awk '{print $2}'";
exec($exec,$output);
exec($exec, $output);
if (count($output) > 0 ) {
if (count($output) > 0) {
return $output[0];
}
return false;
}
function executeIt($exec, $mode = 'sudo') {
......@@ -146,7 +149,7 @@ class WebTree {
exec("$bin_exec \"" . $exec . "\"", $output);
return $output;
} else if ($exec_mode == "sudo") {
} elseif ($exec_mode == "sudo") {
$bin_exec = "/usr/bin/sudo";
exec("$bin_exec sh -c \"$exec\"", $output);
......@@ -157,17 +160,15 @@ class WebTree {
return $output;
}
// return false;
}
function recursiveDelete($str) {
if (is_file($str)) {
return @unlink($str);
}
elseif (is_dir($str)) {
$scan = glob(rtrim($str,'/').'/*');
foreach($scan as $index=>$path) {
} elseif (is_dir($str)) {
$scan = glob(rtrim($str, '/').'/*');
foreach ($scan as $index => $path) {
self::recursiveDelete($path);
}
return @rmdir($str);
......@@ -175,10 +176,21 @@ class WebTree {
return false;
}
public function clearCache() {
public function clearCache()
{
$files = glob('cache/*'); // get all file names
self::recursiveDelete('cache/');
return true; //todo
}
public static function renderView($view, $context, $options = []) { //todo testing
try {
$html = Twig\render($view, $context);
} catch (\Twig\Error\LoaderError $e) {
} catch (\Twig\Error\RuntimeError $e) {
} catch (\Twig\Error\SyntaxError $e) {
}
return Response\html($html);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment