function __construct($template_path = false)
 {
     $this->app = \StarterKit\App::getInstance();
     $template_path = $template_path ? $template_path : $this->app->twig_config['template_path'];
     $this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem($template_path, ['cache' => $this->app->twig_config['cache'], 'auto_reload' => $this->app->twig_config['auto_reload']]));
     $this->twig->addExtension(new \Twig_Extension_StringLoader());
 }
 public function cancel()
 {
     $db = $this->db;
     $details = $this->details;
     if (\StarterKit\App::getInstance()->remote_addr == $details['remote_addr']) {
         $db->trash('recover', $details['id']);
         $this->success = true;
     }
     return $this;
 }
Exemple #3
0
 public function sendEmail($recipient, $template, $data)
 {
     $db = \StarterKit\App::getInstance()->db;
     $template_info = $db->getRow('SELECT * FROM mailtemplate WHERE title=:title', [':title' => $template]);
     if (empty($template_info)) {
         throw new \exception('mail template doesnt exist');
     }
     $data['inner_html'] = preg_replace('\\[#(\\w+)\\]', '{{$1}}', $template_info['html']);
     $html = $this->create_html('mail_template.twig', $data);
     $this->send($html, $template_info['subject'], $template_info['from'], $recipient);
 }
Exemple #4
0
 function __construct()
 {
     $this->app = $app = \StarterKit\App::getInstance();
     $this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem($this->app->twig_config['template_path']));
     $this->twig->addExtension(new \Twig_Extension_StringLoader());
     if (!$app->debug) {
         if ($app->slim->request->getPath() !== '/api/init') {
             if ($app->slim->request->isPost()) {
                 $fail = false;
                 if (!isset($app->post['c'])) {
                     $fail = true;
                 } else {
                     if (urldecode($app->post['c']) !== $app->session['csrf']) {
                         $fail = true;
                     }
                 }
                 if ($fail !== false) {
                     $app->halt(403, 'Access Denied');
                 }
             }
             if ($app->slim->request->isGet()) {
                 $fail = false;
                 if (!isset($app->get['c'])) {
                     $fail = true;
                 } else {
                     if (urldecode($app->get['c']) !== $app->session['csrf']) {
                         $fail = true;
                     }
                 }
                 if ($fail !== false) {
                     $app->halt(403, 'Access Denied');
                 }
             }
         }
     }
 }
 function __construct()
 {
     $this->app = \StarterKit\App::getInstance();
     $this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem($this->app->twig_config['template_path']));
     $this->twig->addExtension(new \Twig_Extension_StringLoader());
 }
Exemple #6
0
 public function is_spamming()
 {
     if ($this->banned == 0) {
         $t = time();
         $this->sent[] = $t;
         $this->sent = array_filter($this->sent, function ($x) use($t) {
             return $x >= $t - 60;
         });
         $result = count($this->sent) >= 5;
         if ($result) {
             $this->spam_flags += 1;
             if ($this->spam_flags > 5) {
                 \StarterKit\App::getInstance()->db->flagUserComments($this->id);
                 $this->banned = 1;
                 //soft bans. if they become a problem admin bans.
                 return true;
             }
             return false;
         }
     } else {
         return true;
     }
 }
<?php

//provides a database connection for cron jobs.
require 'config.php';
require 'vendor/autoload.php';
require 'StarterKit/App.php';
\StarterKit\App::registerAutoloader();
$db = \StarterKit\DB::getInstance($config['db_args']);
$cache = \StarterKit\Cache::getInstance($config['cache_args']);
Exemple #8
0
<?php

define('LIB_PATH', realpath(__DIR__ . '/../libs') . '/');
$libs = ['vendor/autoload.php', 'StarterKit/App.php', 'config.php'];
foreach ($libs as $lib) {
    require LIB_PATH . $lib;
}
\StarterKit\App::registerAutoloader();
$app = \StarterKit\App::getInstance($config);
$app->hook('slim.before', function () use($app) {
    $app->__before();
});
$app->hook('slim.before.router', function () use($app) {
    $app->__beforeRouter();
});
$app->hook('slim.before.dispatch', function () use($app) {
    $app->__beforeDispatch();
});
$app->hook('slim.after', function () use($app) {
    $app->__after();
});
//v1 of the api
$app->group('/api/v1', function () use($app) {
    $app->map('/:method', function ($method) {
        (new \StarterKit\Routes\API())->__try($method);
    })->via('GET', 'POST');
    $app->error(function (exception $e) {
        echo json_encode(['error' => 1, 'message' => '500 Internal Server Error']);
    });
    $app->notFound(function () {
        echo json_encode(['error' => 1, 'message' => '404 Not Found']);
Exemple #9
0
 function __construct()
 {
     $this->app = \StarterKit\App::getInstance();
     parent::__construct();
 }
Exemple #10
0
 public function update()
 {
     $db = \StarterKit\App::getInstance()->db;
     $t = $db->model('admin', $this->id);
     $self = get_object_vars($this);
     unset($self['id'], $self['menu'], $self['permissions'], $self['dashboard'], $self['stats'], $self['mlist_stats']);
     foreach ($self as $k => $v) {
         if ($k == 'permissions') {
             //do nothing, we cant allow stale permissions to overwrite what the admin may have changed
         } else {
             $t->{$k} = $v;
         }
     }
     $db->store($t);
     $this->buildMenu();
     $this->buildDashboard();
     $this->buildStats();
     $this->buildMasterlistStats();
     $db->cachedCall('fetchAdmin', [$this->name], 0, true);
 }
Exemple #11
0
 public function browseFiles($type)
 {
     $res = [];
     $app = \StarterKit\App::getInstance();
     $videos = glob($app->public_html . 'uploads/*.mp4');
     $images = glob($app->public_html . 'uploads/*.{jpg,png,gif}', GLOB_BRACE);
     if ($type == 'video') {
         foreach ($videos as $v) {
             array_push($res, ['thumb' => rtrim($v, '.mp4') . '.png', 'src' => $v]);
         }
     } else {
         foreach ($images as $v) {
             $n = pathinfo($v, PATHINFO_FILENAME) . '.mp4';
             if (!in_array($n, $videos)) {
                 array_push($res, ['thumb' => $v, 'src' => $v]);
             }
         }
     }
     $res = array_map(function ($k) {
         foreach ($k as &$kk) {
             $kk = array_pop(explode('/', $kk));
         }
         return $k;
     }, $res);
     return $res;
 }
Exemple #12
0
 private function delFile($file)
 {
     if (empty($file)) {
         return;
     }
     if (strpos($file, '/') !== false) {
         $file = array_pop(explode('/', $file));
     }
     $app = \StarterKit\App::getInstance();
     unlink($app->public_html . 'uploads/' . $file);
 }