Example #1
0
 /**
  * /
  * @param  Record $record [description]
  * @param  [type] $token  [description]
  * @return [type]         [description]
  */
 public function sendSignUpConfirmation(Record $record, $token)
 {
     $siteTitle = $this->app->config('site.title');
     $subject = 'Activate your account';
     $body = "Welcome to {$siteTitle}. \n To activate your account, click on the link:\n<a>";
     $body .= $this->app->urlFor('confirm_signup', array('token' => $token, 'user_id' => $record->get('id')));
     $body .= '</a>';
     $this->app->postman->createMessage($this->app->config('system.email'), $siteTitle, $subject, $body);
     return $this->app->postman->sendMessage($record->get('email'), $record->get('name'));
 }
Example #2
0
 /**
  * [bindExtraToZone description]
  * @param  [type] $layout [description]
  * @return [type]         [description]
  */
 private function bindExtraToZone($layout)
 {
     // Get extra array by type from theme.php
     $extra_arr = $this->theme->config('extra_' . $this->extra_type);
     // Get extra template and pass extra object to template
     $extra_tpl = $this->theme->view('partials.extras.' . key($extra_arr));
     $extra_tpl['extra'] = $this->extra;
     // Set extra template to ZONE var
     $layout[strtoupper($extra_arr[$this->extra_type])] = trim(implode("\n", array($extra_tpl)));
     return $layout;
 }
Example #3
0
 /**
  * /
  * @param  [type] $app [description]
  * @return [type]      [description]
  */
 public function route($app)
 {
     /*
      * MUSTACHE TEMPLATES
      */
     $app->get('/template/:name', function ($name) use($app) {
         $file = '/public/assets/mustache/' . $name . '.mustache';
         if (!is_file($file) || !is_readable($file)) {
             throw new \Exception("File not accessible", 1);
         }
         $body = file_get_contents($file);
         if (!$body) {
             throw new \Exception("File not accessible", 1);
         }
         $app->response->headers->set('Content-Type', $type);
         $app->response->setBody($body);
         $app->stop();
     });
     /*
      * ASSETS
      */
     $app->get('/asset/:name/:extension', function ($name, $extension) use($app) {
         if (in_array($extension, array('css', 'js', 'gif', 'jpg', 'jpeg', 'png'))) {
             switch ($extension) {
                 case 'css':
                     $type = 'text/css';
                     break;
                 case 'js':
                     $type = 'application/javascript';
                     break;
                 default:
                     throw new \Exception("Unrecognized asset mimetype.", 01);
                     break;
             }
             $file = '/public/assets/' . $extension . '/' . $name . '.' . $extension;
             if (!is_file($file) || !is_readable($file)) {
                 throw new \Exception("File not accessible", 1);
             }
             $body = file_get_contents($file);
             if (!$body) {
                 throw new \Exception("Empty file", 1);
             }
             $app->response->headers->set('Content-Type', $type);
             $app->response->setBody($body);
         }
         $app->stop();
     });
     /*
      * IMAGE FILES
      * (TODO: implement Imagine PHP lib)
      */
     $app->get('/media/:name/:extension', function ($name, $extension) use($app) {
         if (in_array($extension, array('gif', 'jpg', 'jpeg', 'png'))) {
             switch ($extension) {
                 case 'jpg':
                     $type = 'image/jpeg';
                     break;
                 case 'jpeg':
                     $type = 'image/jpeg';
                     break;
                 case 'gif':
                     $type = 'image/gif';
                     break;
                 case 'png':
                     $type = 'image/png';
                     break;
                 default:
                     throw new \Exception("Unrecognized media mimetype.", 01);
                     break;
             }
             $app->response->headers->set('Content-Type', $type);
             $file = '/public/media/' . $name . '.' . $extension;
             if (!is_file($file) || !is_readable($file)) {
                 throw new \Exception("File not accessible", 1);
             }
             $body = file_get_contents($file);
             if (!$body) {
                 throw new \Exception("Empty file", 1);
             }
             $app->response->setBody($body);
         }
         $app->stop();
     });
     /*
      * FORCE DOWNLOAD
      * (TODO: log downloaded files)
      */
     $app->get('/download/:name/:extension', function ($name, $extension) use($app) {
         $file = '/public/media/' . $name . '.' . $extension;
         if (!is_file($file) || !is_readable($file)) {
             throw new \Exception("File not accessible", 1);
         }
         $body = file_get_contents('/public/media/' . $name . '.' . $extension);
         if (!$body) {
             throw new \Exception("Empty file", 1);
         }
         $mimes = $app->config('mimetypes.download');
         if (isset($mimes[$extension])) {
             $app->response->headers->set('Content-Type', $mimes[$extension]);
             $app->response->setBody($body);
         }
         $app->stop();
     });
     return $app;
 }
Example #4
0
 /**
  * /
  * @param  [type] $app [description]
  * @return [type]      [description]
  */
 public function route($app)
 {
     /*
      * USERS
      */
     $app->get('/api/user(/:pg(/:key(/:order)))', function ($pg = 1, $key = 'modified', $order = 'desc') use($app) {
         $result = User::query($app->db, 'find', $pg, $app->config('per_page'), $key, $order);
         $app->handler->handleApiResponse($result);
     })->name('api_user_list')->conditions(array('pg' => '\\d+', 'key' => '\\w+', 'order' => 'asc|desc'));
     $app->get('/api/user/:id/show', function ($id) use($app) {
         $result = User::query($app->db, 'show', $id);
         $app->handler->handleApiResponse($result);
     })->name('api_user_show')->conditions(array());
     $app->get('/api/user/profile', function ($id) use($app) {
         $result = User::query($app->db, 'show', $app->sessionDataStore->getUserId());
         $app->handler->handleApiResponse($result);
     })->name('api_user_profile');
     $app->post('/api/user/delete', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $id = $record->get('id');
         $result = User::query($app->db, 'delete', $id);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'user', $id, 'delete', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'DELETE')->name('api_user_delete');
     $app->map('/api/user/save', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = User::query($app->db, 'save', $record);
         $id = $record->has('id') ? $record->get('id') : $result->getLastInsertId();
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), $model, $id, 'save', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('api_user_save');
     /*
      * TYPES
      */
     $app->get('/api/type(/:pg(/:key(/:order)))', function ($pg = 1, $key = 'name', $order = 'asc') use($app) {
         $result = Type::query($app->db, 'display');
         $app->handler->handleApiResponse($result);
     })->name('api_type_list')->conditions(array('pg' => '\\d+', 'key' => '\\w+', 'order' => 'asc|desc'));
     $app->post('/api/type/delete', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $id = $record->get('id');
         $result = Type::query($app->db, 'delete', $id);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'type', $id, 'delete', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->name('api_type_delete');
     $app->post('/api/type/save', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Type::query($app->db, 'save', $record);
         $id = $record->has('id') ? $record->get('id') : $result->get('last.insert.id');
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), $model, $id, 'save', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->name('api_type_save');
     /*
      * SYSTEM
      */
     $app->get('/api/config', function () use($app) {
         $result = Config::query($app->db, 'display');
         $app->handler->handleApiResponse($result);
     })->name('api_config_list')->conditions(array());
     $app->map('/api/config', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Config::query($app->db, 'save', $record);
         $id = $record->has('id') ? $record->get('id') : $result->getLastInsertId();
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'config', $id, 'save', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('api_config_save');
     $app->get('/api/log(/:pg)', function ($pg = 1) use($app) {
         $result = Log::query($app->db, 'find', $pg, $app->config('per_page'));
         $app->handler->handleApiResponse($result);
     })->name('api_log_list')->conditions(array('pg' => '\\d+'));
     /*
      * LANG
      */
     $app->get('/api/lang/:lang', function ($lang) use($app) {
         $app->session->set('language', $lang);
     })->name('api_set_lang')->conditions(array('lang' => '\\w+'));
     /*
      * NONCE
      */
     $app->get('/api/nonce', function () use($app) {
         $app->nonce->generate();
         $result = new Result(array('success' => true, 'message' => 'Nonce has been generated.', 'nonce' => $app->nonce->get()));
         $app->handler->handleApiResponse($result);
     });
     return $app;
 }
Example #5
0
 /**
  * /
  * @param  [type] $app [description]
  * @return [type]      [description]
  */
 public function route($app)
 {
     $app->get('/api/project/:id/devs', function () use($app) {
         $result = Project::query($app->db, 'getDevs', $id);
         $app->handler->handleApiResponse($result);
     })->name('project_devs')->conditions(array('id' => '\\d+'));
     $app->get('/api/project/:id/users', function () use($app) {
         $result = Project::query($app->db, 'getUsers', $id);
         $app->handler->handleApiResponse($result);
     })->name('project_users')->conditions(array('id' => '\\d+'));
     $app->get('/api/project/:id/tickets', function () use($app) {
         $result = Project::query($app->db, 'getTickets', $id);
         $app->handler->handleApiResponse($result);
     })->name('project_tickets')->conditions(array('id' => '\\d+'));
     $app->get('/api/project/:id/invoices', function () use($app) {
         $result = Project::query($app->db, 'getInvoices', $id);
         $app->handler->handleApiResponse($result);
     })->name('project_invoices')->conditions(array('id' => '\\d+'));
     $app->get('/api/project/:id/hours', function () use($app) {
         $result = Project::query($app->db, 'getBillableHours', $id);
         $app->handler->handleApiResponse($result);
     })->name('project_hours')->conditions(array('id' => '\\d+'));
     $app->get('/api/invoice(/:pg(/:key(/:order)))', function ($pg = 1, $key = 'title', $order = 'asc') use($app) {
         $result = Invoice::query($app->db, 'find', $pg, $app->config('per_page'), $key, $order);
         $app->handler->handleApiResponse($result);
     })->name('invoice_list')->conditions(array('pg' => '\\d+', 'key' => '\\w+', 'order' => '\\w+'));
     $app->get('/api/invoice/:id/show', function ($id) use($app) {
         $result = Invoice::query($app->db, 'show', $id);
         $app->handler->handleApiResponse($result);
     })->name('invoice_show')->conditions(array('id' => '\\d+'));
     $app->map('/api/invoice/delete', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Invoice::query($app->db, 'delete', $id);
         $app->handler->handleApiResponse($result);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'invoice', $id, 'delete', '', '', $app->nonce->get());
     })->via('POST', 'DELETE')->name('invoice_delete');
     $app->get('/api/project/:id/invoice/create', function ($id) use($app) {
         $result = Project::query($app->db, 'createInvoice', $id);
         $app->handler->handleApiResponse($result);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'project', $id, 'create_invoice', 'invoice', $result->getLastInsertId(), $app->nonce->get());
     })->name('project_create_invoice')->conditions(array('id' => '\\d+'));
     $app->get('/api/project(/:pg(/:key(/:order)))', function ($pg = 1, $key = 'title', $order = 'asc') use($app) {
         $result = Project::query($app->db, 'find', $pg, $app->config('per_page'), $key, $order);
         $app->handler->handleApiResponse($result);
     })->name('project_list')->conditions(array('pg' => '\\d+', 'key' => '\\w+', 'order' => '\\w+'));
     $app->get('/api/project/:id/show', function ($id) use($app) {
         $result = Project::query($app->db, 'show', $id);
         $app->handler->handleApiResponse($result);
     })->name('project_show')->conditions(array('id' => '\\d+'));
     $app->map('/api/project/save', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Project::query($app->db, 'save', $record);
         $id = $record->has('id') ? $record->get('id') : $result->getLastInsertId();
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'project', $id, 'save', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('project_save');
     $app->map('/api/project/delete', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Project::query($app->db, 'delete', $id);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'project', $id, 'delete', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'DELETE')->name('project_delete');
     $app->get('/api/track/:ticket_id/start', function ($ticket_id) use($app) {
         $result = TimeTracking::query($app->db, 'start', $ticket_id);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'time_started', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->name('track_start')->conditions(array('ticket_id' => '\\d+'));
     $app->get('/api/track/:ticket_id/stop', function ($ticket_id) use($app) {
         $result = TimeTracking::query($app->db, 'stop', $ticket_id);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'time_stoped', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->name('track_stop')->conditions(array('ticket_id' => '\\d+'));
     $app->get('/api/ticket/latest', function () use($app) {
         $result = Ticket::query($app->db, 'find', 'modified');
         $app->handler->handleApiResponse($result);
     })->name('ticket_latest');
     $app->get('/api/ticket/list(/:pg', function ($pg = 1) use($app) {
         $result = Ticket::query($app->db, 'findAll', $pg, $per_page);
         $app->handler->handleApiResponse($result);
     })->name('ticket_list');
     $app->map('/api/ticket/save', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Ticket::query($app->db, 'save', $record);
         $id = $record->has('id') ? $record->get('id') : $result->getLastInsertId();
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'save', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('ticket_save');
     $app->map('/api/ticket/priority', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Ticket::query($app->db, 'changePriority', $id, $priority);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'change_priority', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('ticket_change_priority');
     $app->map('/api/ticket/delete', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Ticket::query($app->db, 'delete', $id);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'delete', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'DELETE')->name('ticket_delete');
     $app->get('/api/ticket/:id/dev', function ($id) use($app) {
         $app->handler->handleApiResponse($result);
     })->name('ticket_dev')->conditions(array('id' => '\\d+'));
     $app->map('/api/ticket/close', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $closed = Ticket::query($app->db, 'close', $record->get('id'));
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'close', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('ticket_close');
     $app->map('/api/ticket/comment', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $user_id = $app->sessionDataStore->getUserId();
         $result = Ticket::query($app->db, 'comment', $id, $user_id, $record->get('comment'));
         Log::query($app->db, 'log', $user_id, 'ticket', $id, 'close');
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('ticket_comment');
     $app->map('/api/ticket/call', function () use($app) {
         $record = $app->handler->handlePostRequest();
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'close', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('ticket_request_call');
     return $app;
 }