Пример #1
0
 private static function cargar()
 {
     if (!self::$loaded) {
         self::loadDirectoryRecursive(dirname(__FILE__) . '/../app');
         self::loadDirectoryRecursive(dirname(__FILE__) . '/../plugins');
         self::$loaded = true;
     }
 }
Пример #2
0
 public static function xpathQuery($query, $node = null)
 {
     if ($node == null) {
         $doc = Moriarti::get('view');
     } else {
         $doc = $node->ownerDocument;
     }
     $xpath = new DOMXPath($doc);
     return $xpath->query($query, $node);
 }
Пример #3
0
 public function __construct($code, $data = null)
 {
     $this->code = $code;
     $time_start = microtime(true);
     Moriarti::dispatch($this, $data);
     $time_end = microtime(true);
     //Subtract the two times to get seconds
     $time = $time_end - $time_start;
     file_put_contents(__DIR__ . '/messages.log', $this->code . ' - ' . $time . "\r\n", FILE_APPEND);
 }
Пример #4
0
<?php

Moriarti::register(1, '/bd/query/*', function ($code, $data) {
    $queryName = explode("/", $code)[3];
    $filename = dirname(__FILE__) . '/queries/' . $queryName . '.inc';
    if (file_exists($filename)) {
        ob_start();
        include $filename;
        $query = ob_get_clean();
    } else {
        throw new \Exception("Can't find query " . $queryName);
    }
    $result = Moriarti::get('bd')->prepare($query);
    $result->execute($data);
    Moriarti::store($queryName, $result->fetchAll());
});
Пример #5
0
<?php

Moriarti::register(0, '/on/exception/*', function ($tipo, $data) {
    new Message('/view/adminlte/public/500', $data);
});
Пример #6
0
<?php

Moriarti::register(3, '/view/adminlte/private/*', function ($code, $data) {
    $doc = Moriarti::get('view');
    DOMUtil::findElementsByClassName('messages-text')->item(0)->nodeValue = 'Tienes 100 mensajes';
    DOMUtil::findElementsByClassName('messages-count')->item(0)->nodeValue = 100;
});
Пример #7
0
<?php

Moriarti::register(0, '/bd/*', function ($tipo, $data) {
    $settings = Moriarti::get('plugins/bd');
    $bd = new PDO('mysql:host=' . $settings['data']['host'] . ';dbname=' . $settings['data']['database'], $settings['data']['user'], $settings['data']['password']);
    $bd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $bd->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    Moriarti::store('bd', $bd);
});
Пример #8
0
<?php

// rewrite relative urls to match template location
Moriarti::register(1, '/on/render/*', function ($code, $data) {
    $xpath = new DOMXPath($data);
    $template = Moriarti::get('plugins/template')['data']['active'];
    $notSrcAbs = "[not(starts-with(@src, 'http'))]";
    $notHrefAbs = "[not(starts-with(@href, 'http'))]";
    // rewrite <link href> <script src> and <img src> with relative urls
    $linkhrefs = $xpath->query("//link{$notHrefAbs}/@href | //script{$notSrcAbs}/@src | //img{$notSrcAbs}/@src");
    foreach ($linkhrefs as $linkhref) {
        // add prefix with right location
        $linkhref->nodeValue = "/plugins/template/{$template}/layout/" . $linkhref->nodeValue;
    }
});
Пример #9
0
<?php

Moriarti::register(3, '/view/adminlte/private/*', function ($code, $data) {
    foreach (DOMUtil::xpathQuery("//text()[. = 'USER_NAME']") as $userName) {
        $userName->nodeValue = $_SESSION['USER']['NAME'];
    }
});
Пример #10
0
<?php

Moriarti::register(9, '/view/adminlte/public/500', function ($code, $data) {
    $doc = Moriarti::get('view')->getElementById('titleError')->nodeValue = 'Error';
    $doc = Moriarti::get('view')->getElementById('msgError')->nodeValue = $data->getMessage();
    $doc = Moriarti::get('view')->getElementById('lineError')->nodeValue = $data->getFile() . ' - ' . $data->getLine();
});
Пример #11
0
<?php

Moriarti::register(1, '/http/*/login', function ($tipo, $data) {
    Moriarti::store('layout', 'login');
});
Moriarti::register(1, '/http/POST/login', function ($tipo, $data) {
    $user = $_POST["username"];
    $pass = $_POST["password"];
    $encrypted_password = sha1($pass);
    new Message("/bd/query/validateLogin", [':name' => $user, ':password' => $pass]);
    if (!empty(Moriarti::get('validateLogin'))) {
        $_SESSION['USER'] = Moriarti::get('validateLogin')[0];
        header("Location: .");
        die;
    } else {
        new Message("/on/warning", "User or password incorrect");
    }
});
Moriarti::register(1, '/http/GET/logout', function ($code, $data) {
    session_destroy();
    header("Location: .");
    die;
});
Пример #12
0
<?php

Moriarti::register(9, '/view/adminlte/private/*', function ($code, $data) {
    $view = explode('/', $code)[4];
    $doc = Moriarti::get('view');
    $list = DOMUtil::findElementsByClassName('sidebar-menu')->item(0);
    $item = $list->firstChild;
    foreach (Moriarti::get('userMenu') as $menu) {
        $menuref = str_replace(' ', '', strtolower($menu));
        $newItem = $item->cloneNode(true);
        $list->appendChild($newItem);
        DOMUtil::xpathQuery('.//span', $newItem)->item(0)->nodeValue = $menu;
        DOMUtil::xpathQuery('.//a/@href', $newItem)->item(0)->nodeValue = $menuref;
        if ($view === $menuref) {
            $newItem->setAttribute('class', 'active');
        }
    }
    $item->parentNode->removeChild($item);
});
Пример #13
0
<?php

Moriarti::register(0, '/on/warning', function ($tipo, $data) {
    Moriarti::storeArr('warning', $data);
});
Moriarti::register(0, '/on/info', function ($tipo, $data) {
    Moriarti::storeArr('info', $data);
});
Moriarti::register(0, '/on/error', function ($tipo, $data) {
    Moriarti::storeArr('error', $data);
});
Пример #14
0
<?php

Moriarti::register(1, '/http/*', function ($tipo, $data) {
    if (isset($_GET['lang'])) {
        $_SESSION['lang'] = $_GET['lang'];
    }
});
Moriarti::register(1, '/on/render/*', function ($code, $data) {
    if (isset($_SESSION['lang'])) {
        $lang = $_SESSION['lang'];
    } else {
        $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
    }
    $view = explode('/', $code)[3];
    $xpath = new DOMXPath($data);
    // translate all texts
    $translations = Moriarti::get('plugins/template-translation')['data']['translations'];
    $texts = $xpath->evaluate('//text()[not(parent::script)][string-length() > 0]');
    foreach ($texts as $node) {
        $key = trim($node->nodeValue);
        if ($key == '') {
            continue;
        }
        if (isset($translations[$lang][$key])) {
            $node->nodeValue = $translations[$lang][$key];
        }
        if (isset($translations[$lang . '/' . $view][$key])) {
            $node->nodeValue = $translations[$lang . '/' . $view][$key];
        }
    }
});
Пример #15
0
<?php

Moriarti::register(9, '/view/adminlte/*', function ($code, $data) {
    // show warnings
    $doc = Moriarti::get('view');
    $notifications = $doc->getElementByID('notifications');
    if ($notifications != null) {
        $content = file_get_contents(__DIR__ . '/view/notifications/warning.html');
        $warningDoc = DOMUtil::parseHTML($content);
        foreach (Moriarti::getArr('warning') as $warningTxt) {
            DOMUtil::findElementsByClassName('warning-message', $warningDoc)->item(0)->nodeValue = $warningTxt;
            DOMUtil::importDOM($notifications, $warningDoc);
        }
        $content = file_get_contents(__DIR__ . '/view/notifications/error.html');
        $errorDoc = DOMUtil::parseHTML($content);
        foreach (Moriarti::getArr('error') as $errorTxt) {
            DOMUtil::findElementsByClassName('error-message', $errorDoc)->item(0)->nodeValue = $errorTxt;
            DOMUtil::importDOM($notifications, $errorDoc);
        }
        $content = file_get_contents(__DIR__ . '/view/notifications/info.html');
        $infoDoc = DOMUtil::parseHTML($content);
        foreach (Moriarti::getArr('info') as $infoTxt) {
            DOMUtil::findElementsByClassName('info-message', $infoDoc)->item(0)->nodeValue = $infoTxt;
            DOMUtil::importDOM($notifications, $infoDoc);
        }
    }
});
Пример #16
0
<?php 
Moriarti::register(1, '/http/*', function ($tipo, $data) {
    ini_set('display_errors', 1);
    if (isset($_SESSION['USER'])) {
        Moriarti::store('layout', 'private');
    } else {
        Moriarti::store('layout', 'public');
    }
});
Пример #17
0
<?php

Moriarti::register(0, '/http/*', function ($code, $data) {
    $view = substr($code, strrpos($code, "/") + 1);
    // implode('/',$tmp);
    $exclude = Moriarti::get('plugins/firewall')['data']['exclude'];
    if (!isset($_SESSION['USER']) && !in_array($view, $exclude)) {
        header("Location: login");
        die;
    }
});
Пример #18
0
<?php

Moriarti::register(1, '/view/adminlte/private/*', function ($code, $data) {
    Moriarti::store('userMenu', ['Control Panel', 'Profile', 'Settings']);
});