public function attach($key, $file) { $fileObject = Lib::file($file['tmp_name'], $file['name']); $copiedFile = $fileObject->copy(Config::getBasePath() . '/' . Config::$attachmentFolder, $key . '-' . $file['name']); $attachmentTable = Lib::table('comment_attachment'); $attachmentTable->link($this); $attachmentTable->filename = $copiedFile->filename; $attachmentTable->name = $file['name']; $attachmentTable->store(); }
public function initTables() { $db = Lib::db(); foreach (glob(Config::getBasePath() . '/schemas/*.sql') as $file) { $sql = file_get_contents($file); $db->query($sql); } echo 'Completed'; exit; }
public static function getRouters() { static $routers = array(); if (empty($routers)) { foreach (glob(Config::getBasePath() . '/routers/*.php') as $routerFile) { $name = basename($routerFile, '.php'); $routers[] = Lib::router($name); } } return $routers; }
public function save() { $keys = array('project', 'content', 'url', 'category'); if (!Req::haspost($keys)) { return $this->fail('Insufficient data.'); } $identifier = Lib::cookie(Lib::hash(Config::$userkey)); $user = Lib::table('user'); $isLoggedIn = !empty($identifier) && $user->load(array('identifier' => $identifier)); if (!$isLoggedIn) { return $this->fail('You are not authorized.'); } $post = Req::post($keys); extract($post); $projectTable = Lib::table('project'); if (!$projectTable->load(array('name' => $project))) { return $this->fail('No such project.'); } $reportTable = Lib::table('report'); $reportTable->link($projectTable); $reportTable->link($user); $reportTable->content = $content; $reportTable->category_id = $category; $reportTable->url = $url; $reportTable->store(); /* 'screenshot-63cg2rb5v47snhfr' => array (size=5) 'name' => string '2013-09-01 17.14.14.jpg' (length=23) 'type' => string 'image/jpeg' (length=10) 'tmp_name' => string '/private/var/tmp/phpZmeqEX' (length=26) 'error' => int 0 'size' => int 134583 */ $files = Req::file(); if (!empty($files)) { foreach ($files as $key => $file) { $fileObject = Lib::file($file['tmp_name'], $file['name']); $copiedFile = $fileObject->copy(Config::getBasePath() . '/' . Config::$screenshotFolder, $fileObject->generateTemporaryFilename($key . '-')); $screenshotTable = Lib::table('screenshot'); $screenshotTable->link($reportTable); $screenshotTable->filename = $copiedFile->filename; $screenshotTable->store(); } } return $this->success(); }
public function main() { $slug = Req::get('slug'); $this->set('slug', $slug); if (file_exists(Config::getBasePath() . '/assets/css/' . $slug . '.' . (Config::env() === 'development' ? 'less' : 'css'))) { $this->css[] = $slug; } if (file_exists(Config::getBasePath() . '/assets/js/' . $slug . '.' . (Config::env() === 'development' ? 'coffee' : 'js'))) { $this->js[] = $slug; } $page = $this->getPages()->{$slug}; $this->set('slug', $slug); $this->set('page', $page); $this->set('pagetitle', $page->title); $this->set('pagedate', $page->date); $content = $this->loadTemplate($slug . '/content'); $this->set('content', $content); }
/** * * @return string the base URL to use for calls to the APIs */ public function getBasePath() { return $this->config->getBasePath(); }