public function read() { $slug = $this->inputfilter->clean($this->app->get('PARAMS.slug'), 'PATH'); $flash = \Dsc\Flash::instance(); $this->app->set('flash', $flash); $height = $this->app->get('PARAMS.height'); $width = $this->app->get('PARAMS.width'); if ($height && $width) { $this->app->set('height', $height); $this->app->set('width', $width); } $model = $this->getModel(); $item = $this->getItem(); if (empty($item->id)) { return $this->app->error(404, 'Invalid Item'); } $this->app->set('model', $model); $this->app->set('item', $item); // $flash->store((array) $item->cast()); switch ($item->storage) { case "s3": case "cloudfiles": case "cdn": $this->app->reroute($item->url); break; case "gridfs": default: $this->app->set('meta.title', $item->slug); $view = \Dsc\System::instance()->get('theme'); echo $view->renderLayout('Assets/Site/Views::assets/view.php'); break; } }
public function index() { // when ACL is ready // $this->checkAccess( __CLASS__, __FUNCTION__ ); $model = $this->getModel(); $state = $model->populateState()->getState(); \Base::instance()->set('state', $state); $paginated = $model->paginate(); \Base::instance()->set('paginated', $paginated); $categories_db = (array) $this->getModel("categories")->getItems(); $categories = array(array('text' => 'All Categories', 'value' => ' '), array('text' => '- Uncategorized -', 'value' => '--')); array_walk($categories_db, function ($cat) use(&$categories) { $categories[] = array('text' => $cat->title, 'value' => (string) $cat->slug); }); \Base::instance()->set('categories', $categories); $all_tags = array(array('text' => 'All Tags', 'value' => ' '), array('text' => '- Untagged -', 'value' => '--')); $tags = (array) $this->getModel()->getTags(); array_walk($tags, function ($tag) use(&$all_tags) { $all_tags[] = array('text' => $tag, 'value' => $tag); }); \Base::instance()->set('all_tags', $all_tags); $this->app->set('meta.title', 'Posts | Blog'); $this->app->set('allow_preview', $this->canPreview(true)); $view = \Dsc\System::instance()->get('theme'); echo $view->render('Blog/Admin/Views::posts/list.php'); }
public function html() { \Base::instance()->set('module', $this); \Dsc\System::instance()->get('theme')->registerViewPath(__DIR__ . '/Views/', 'Modules/Html/Views'); $string = \Dsc\System::instance()->get('theme')->renderLayout('Modules/Html/Views::default.php'); return $string; }
public function restore() { //TODO try catch here $this->getItem()->restore(); \Dsc\System::instance()->addMessage("Item was restored", 'success'); $this->app->reroute($this->list_route); }
public function saveAsk() { $this->app->set('pagetitle', 'About'); $this->app->set('subtitle', ''); $view = \Dsc\System::instance()->get('theme'); echo $view->render('Faq/Site/Views::faq/index.php'); }
public function findAsset($resource = null) { if (empty($resource)) { return; } // TODO allow this to be modified, both by an admin interface and via a class::method $approved_extensions = array('bmp', 'gif', 'ico', 'jpg', 'jpeg', 'odg', 'png', 'svg', '3gp', 'amv', 'avi', 'divx', 'mov', 'mp4', 'mpg', 'qt', 'rm', 'wmv', 'swf', 'm4a', 'mp3', 'ogg', 'wma', 'wav', 'eot', 'otf', 'ttf', 'woff', 'csv', 'doc', 'odp', 'ods', 'odt', 'pdf', 'ppt', 'txt', 'xcf', 'xls'); // Is the extension of the requested asset in the list of approved extensions? $extension = strtolower(pathinfo($resource, PATHINFO_EXTENSION)); if (!in_array($extension, $approved_extensions)) { \Base::instance()->error(500); return; } $global_app_name = \Base::instance()->get('APP_NAME'); // Loop through all the registered paths and try to find the requested asset // If it is found, send it with \Web::instance()->send($file, null, 0, false); $paths = (array) \Base::instance()->get($global_app_name . '.dsc.minify.paths'); foreach ($paths as $path) { $file = realpath($path . $resource); if (file_exists($file)) { \Base::instance()->set('file', $file); $theme = \Dsc\System::instance()->get('theme'); echo $theme->renderView('Minify\\Views::asset.php'); return; } } // File not found. \Base::instance()->error(500); return; }
public function update() { $id = $this->inputfilter->clean($this->app->get('PARAMS.id'), 'cmd'); try { $item = (new \Shop\Models\PaymentMethods())->setState('filter.identifier', $id)->getItem(); if (empty($item->id)) { throw new \Exception('Payment Method not found'); } $enabled = $this->app->get('POST.enabled'); if (strlen($enabled)) { $item->enabled = false; if (!empty($enabled)) { $item->enabled = true; } } if ($settings_array = (array) $this->inputfilter->clean($this->app->get('POST.settings'), 'array')) { $item->settings = $settings_array; } $item->save(); \Dsc\System::addMessage('Settings updated', 'success'); $this->app->reroute('/admin/shop/payment-method/edit/' . $id); } catch (\Exception $e) { \Dsc\System::addMessage("Invalid Payment Method", 'error'); \Dsc\System::addMessage($e->getMessage(), 'error'); $this->app->reroute('/admin/shop/payment-methods'); return; } }
public static function passes(\Modules\Models\Modules $module, $route = null, $options = array()) { // if this ruleset is ignored, return null if (!in_array($module->{'assignment.login_status.method'}, array('include', 'exclude'))) { return null; } $user = \Dsc\System::instance()->get('auth')->getIdentity(); $is_logged_in = empty($user->id) ? false : true; $match = false; switch ($module->{'assignment.login_status.value'}) { case "1": if ($is_logged_in) { $match = true; } break; case "0": default: if (!$is_logged_in) { $match = true; } break; } switch ($module->{'assignment.login_status.method'}) { case "exclude": $passes = $match ? false : true; break; default: $passes = $match; break; } return $passes; }
public function read() { // TODO Check ACL against page. $slug = $this->inputfilter->clean($this->app->get('PARAMS.slug'), 'cmd'); $model = $this->getModel()->populateState()->setState('filter.type', true)->setState('filter.slug', $slug); $preview = $this->input->get("preview", 0, 'int'); if ($preview) { $this->canPreview(); } else { $model->setState('filter.published_today', true)->setState('filter.publication_status', 'published'); } try { $item = $model->getItem(); if (empty($item->id)) { throw new \Exception(); } } catch (\Exception $e) { \Dsc\System::instance()->addMessage("Invalid Item", 'error'); $this->app->error('404'); return; } $this->app->set('item', $item); $this->app->set('meta.title', $item->seoTitle()); $this->app->set('meta.description', $item->seoDescription()); \Pages\Models\Activities::track('Viewed Page', array('Page Title' => $item->seoTitle(), 'page_id' => (string) $item->id)); $view = \Dsc\System::instance()->get('theme'); $view_file = 'view.php'; if ($item->{'display.view'} && $view->findViewFile('Pages/Site/Views::pages/view/' . $item->{'display.view'})) { $view_file = 'view/' . $item->{'display.view'}; } echo $view->renderTheme('Pages/Site/Views::pages/' . $view_file); }
/** * * @param unknown_type $message * @param unknown_type $type */ public static function addMessage($message, $type = 'info') { $messages = \Dsc\System::instance()->session->get('system.messages') ? \Dsc\System::instance()->session->get('system.messages') : array(); switch (strtolower($type)) { case "good": case "success": $type = "success"; break; case "high": case "bad": case "danger": case "error": $type = "danger"; break; case "low": case "warn": case "warning": case "notice": $type = "warning"; break; default: $type = "info"; break; } $messages = array_merge((array) $messages, array(array('message' => $message, 'type' => $type))); \Dsc\System::instance()->session->set('system.messages', $messages); }
public function isShippingMethodEnabled($method = null) { $result = false; switch ($method) { case 'ups': $result = $this->{'shipping.ups.enabled'} && $this->{'shipping.ups.key'} && $this->{'shipping.ups.password'}; break; case 'usps': $result = $this->{'shipping.usps.enabled'} && $this->{'shipping.usps.key'}; break; case 'fedex': $result = $this->{'shipping.fedex.enabled'}; break; case 'stamps': $result = $this->{'shipping.stamps.enabled'}; break; case 'dhl': $result = $this->{'shipping.dhl.enabled'}; break; case null: // are ANY of the social providers enabled? $enabled = $this->enabledShippingMethods(); if (!empty($enabled)) { $result = true; } break; default: $event = \Dsc\System::instance()->trigger('onShippingMethodEnabled', array('method' => $provider, 'result' => null)); $result = $event->getArgument('result'); break; } return $result; }
public function index() { $this->app->set('meta.title', 'Dashboard | Pusher'); // $this->pusher->trigger('my-channel', 'my_event', 'hello world'); $view = \Dsc\System::instance()->get('theme'); echo $view->render('Pusher/Admin/Views::home/index.php'); }
public function read() { // TODO Check ACL against page. $slug = $this->inputfilter->clean($this->app->get('PARAMS.slug'), 'cmd'); $model = $this->getModel()->populateState()->setState('filter.slug', $slug); $preview = $this->input->get("preview", 0, 'int'); if ($preview) { $this->canPreview(); } else { $model->setState('filter.published_today', true)->setState('filter.publication_status', 'published'); } try { $item = $model->getItem(); if (empty($item->id)) { throw new \Exception(); } } catch (\Exception $e) { \Dsc\System::instance()->addMessage("Invalid Item", 'error'); $this->app->error('404'); return; } $this->app->set('item', $item); $this->app->set('meta.title', $item->seoTitle()); $this->app->set('meta.description', $item->seoDescription()); $view = \Dsc\System::instance()->get('theme'); echo $view->renderTheme('Forums/Site/Views::posts/read.php'); }
public function read() { $f3 = \Base::instance(); $slug = $this->inputfilter->clean($f3->get('PARAMS.slug'), 'cmd'); $model = $this->getModel()->populateState()->setState('filter.slug', $slug); $preview = $this->input->get("preview", 0, 'int'); if ($preview) { $this->canPreview(); } else { $model->setState('filter.published_today', true)->setState('filter.publication_status', 'published'); } try { $item = $model->getItem(); if (empty($item->id)) { throw new \Exception(); } // increase the view count $item->hit(); } catch (\Exception $e) { \Dsc\System::instance()->addMessage("Invalid Item", 'error'); $f3->reroute('/blog'); return; } $author = $this->getModel('users')->setState('filter.id', $item->{'author.id'})->getItem(); $related = $item->getRelatedPosts(); \Base::instance()->set('item', $item); \Base::instance()->set('author', $author); \Base::instance()->set('related', $related); $this->app->set('meta.title', $item->seoTitle() . ' | Blog'); $this->app->set('meta.description', $item->seoDescription()); \Blog\Models\Activities::track('Viewed Blog Post', array('Blog Title' => $item->seoTitle(), 'post_id' => (string) $item->id)); $view = \Dsc\System::instance()->get('theme'); echo $view->render('Blog/Site/Views::posts/view.php'); }
protected function runSite() { $f3 = \Base::instance(); $f3->set('ONERROR', function ($f3) { $response = \Redirect\Factory::handleError(); // Run the response through a Listener event $event = \Dsc\System::instance()->trigger('onError', array('response' => $response)); $response = $event->getArgument('response'); switch ($response->action) { case "handle": $f3->call($response->callable_handle); break; case "html": echo $response->html; break; case "redirect": $f3->reroute($response->redirect_route); break; default: // by returning false, let f3 default error handler handle the error return false; break; } }); }
public function index() { // TODO get the slug param. lookup the category. Check ACL against both category. // get paginated list of pages pages associated with this category // only pages that are published as of now $f3 = \Base::instance(); $id = $this->inputfilter->clean($f3->get('PARAMS.id'), 'alnum'); $model = $this->getModel()->populateState()->setState('filter.creator.id', $id); try { $author = (new \Users\Models\Users())->setState('filter.id', $id)->getItem(); if (empty($author->id)) { throw new \Exception(); } $paginated = $model->paginate(); } catch (\Exception $e) { \Dsc\System::instance()->addMessage("Invalid Items", 'error'); $f3->reroute('/'); return; } $state = $model->getState(); \Base::instance()->set('state', $state); \Base::instance()->set('paginated', $paginated); $this->app->set('meta.title', 'Pages by ' . $author->fullName()); $view = \Dsc\System::instance()->get('theme'); echo $view->render('Pages/Site/Views::pages/category.php'); }
public static function track($action, $properties = array()) { if (class_exists('\\Activity\\Models\\Actions')) { \Activity\Models\Actions::track($action, $properties); } if (class_exists('\\Admin\\Models\\Settings') && class_exists('\\KM')) { $settings = \Admin\Models\Settings::fetch(); if ($settings->enabledIntegration('kissmetrics') && $settings->{'integration.kissmetrics.key'}) { \KM::init($settings->{'integration.kissmetrics.key'}); $identity = \Dsc\System::instance()->get('auth')->getIdentity(); if ($identity->email) { \KM::identify($identity->email); } elseif (isset($_COOKIE['km_ni'])) { \KM::identify($_COOKIE['km_ni']); } elseif (isset($_COOKIE['km_ai'])) { \KM::identify($_COOKIE['km_ai']); } else { $mongo_id = new \MongoId(); \KM::identify((string) $mongo_id); } \KM::record($action, $properties); } } return null; }
public function email() { $f3 = \Base::instance(); $id = $this->inputfilter->clean($f3->get('PARAMS.id'), 'alnum'); $token = $this->inputfilter->clean($f3->get('PARAMS.token'), 'alnum'); $data = array('sender_name' => $this->input->get('sender_name', null, 'string'), 'sender_email' => $this->input->get('sender_email', null, 'string'), 'recipient_name' => $this->input->get('recipient_name', null, 'string'), 'recipient_email' => $this->input->get('recipient_email', null, 'string'), 'message' => $this->input->get('message', null, 'string')); // TODO Validate the input from the form, require at least emails and names if (empty($data['sender_name']) || empty($data['sender_email']) || empty($data['recipient_name']) || empty($data['recipient_email'])) { \Dsc\System::instance()->addMessage("Please complete all required fields. All name and email fields are required.", 'error'); $f3->reroute('/shop/giftcard/' . $id . '/' . $token); return; } try { $item = (new \Shop\Models\OrderedGiftCards())->setState('filter.id', $id)->setState('filter.token', $token)->getItem(); if (empty($item->id)) { throw new \Exception(); } } catch (\Exception $e) { \Dsc\System::instance()->addMessage("Invalid Gift Card", 'error'); $f3->reroute('/shop'); return; } // use the model to send the email so the model can add the history try { $item->sendEmailShareGiftCard($data); } catch (\Exception $e) { \Dsc\System::instance()->addMessage("Error sending email.", 'error'); $f3->reroute('/shop/giftcard/' . $id . '/' . $token); return; } \Dsc\System::instance()->addMessage("Gift card has been sent to " . $data['recipient_email']); $f3->reroute('/shop'); }
/** * Determines whether or not this condition passes * * @param string $route * @param unknown $options */ public function passes(\Modules\Models\Modules $module, $route = null, $options = array()) { // if this ruleset is ignored, return null if (!in_array($module->{'assignment.shop_orders.method'}, array('include'))) { return null; } // user must be logged in for this condition to ever evaluate to be true $user = \Dsc\System::instance()->auth->getIdentity(); if (empty($user->id)) { return false; } $customer = new \Shop\Models\Customers($user); $order_count = $customer->ordersCount(true); $return = null; switch ($module->{'assignment.shop_orders.has_converted'}) { case "1": // user has made an order if ($order_count > 0) { $return = true; } else { $return = false; } break; case "0": // user has never made an order if ($order_count > 0) { $return = false; } else { $return = true; } break; } return $return; }
public function charge() { $id = $this->inputfilter->clean($this->app->get('PARAMS.id'), 'alnum'); $request = $this->getModel()->setState('filter.id', $id)->getItem(); $settings = \Striper\Models\Settings::fetch(); // Set your secret key: remember to change this to your live secret key in production // See your keys here https://manage.stripe.com/account \Stripe::setApiKey($settings->{$settings->mode . '.secret_key'}); // Get the credit card token submitted by the form $token = $this->inputfilter->clean($this->app->get('POST.stripeToken'), 'string'); // Create the charge on Stripe's servers - this will charge the user's card try { $charge = \Stripe_Charge::create(array("amount" => $request->amountForStripe(), "currency" => "usd", "card" => $token, "description" => $request->{'client.email'})); // this needs to be created empty in model $request->acceptPayment($charge); // SEND email to the client $request->sendChargeEmailClient($charge); $request->sendChargeEmailAdmin($charge); $this->app->set('charge', $charge); $this->app->set('paymentrequest', $request); $view = \Dsc\System::instance()->get('theme'); echo $view->render('Striper/Site/Views::paymentrequest/success.php'); } catch (\Stripe_CardError $e) { // The card has been declined $view = \Dsc\System::instance()->get('theme'); echo $view->render('Striper/Site/Views::paymentrequest/index.php'); } }
public function index() { $this->app->set('pagetitle', 'Transactions'); $this->app->set('subtitle', ''); $view = \Dsc\System::instance()->get('theme'); echo $view->render('Finances/Site/Views::transactions/index.php'); }
public function beforeRoute() { parent::beforeRoute(); $this->requireIdentity(); //TODO remove this hack, after ACL is finished $user = $this->auth->getIdentity(); //TODO maybe the Role gets stored in the session to avoid one more DB query every load, or maybe none of this makes it to the future if (!empty($user->id) && $this->app->get('safemode.enabled') && $user->id == $this->app->get('safemode.id')) { return; } $role = $user->getRole(); if (empty($role->slug)) { $this->auth->logout(); \Dsc\System::addMessage('Not Authorized'); $this->app->reroute('/admin/login'); } if ($role->slug == 'root') { //root always has access no farther checks needed } elseif (empty($role->adminaccess)) { //if this role is not admin and not given admin permissions $this->auth->logout(); \Dsc\System::addMessage('Not Authorized'); $this->app->reroute('/admin/login'); } }
/** * Clone an item. Data from $values takes precedence of data from cloned object. * * @param unknown_type $mapper * @param unknown_type $values * @param unknown_type $options */ public function saveAs($document = array(), $options = array()) { $item_data = $this->cast(); // preserve any key=>values from the original item that are not in the new document array $new_values = array_merge($document, array_diff_key($item_data, $document)); unset($new_values[$this->getItemKey()]); if ($existing = $this->pathExists($this->path)) { if ($new_values['title'] == $existing->title) { //THEY CHANGED THE TITLE SO lets unset slug and path and regenerate unset($new_values['slug']); unset($new_values['path']); } else { //Set path to something like string/string-2 $i = 2; do { $new_values['slug'] = $new_values['slug'] . '-' . $i; $new_values['path'] = $this->path . '-' . $i; if ($this->pathExists($new_values['path'])) { $i++; } else { $i = false; } } while ($i); } if ($new_values['details']['url'] == $existing->{'details.url'}) { //TODO I am not sure if we should append this as well or just alert them, I assume they would clone it to make a simliar URL so adding text to it could be annoying \Dsc\System::instance()->addMessage('Item shares a URL with another menu Item be sure to change it', 'warning'); } } $item = new static($new_values); return $item->insert(array(), $options); }
public function beforeRoute() { if (!class_exists('imagick')) { \Dsc\System::instance()->addMessage("ImageMagic is required for Assets to function correctly", 'warning'); } parent::beforeRoute(); }
public function index() { $f3 = \Base::instance(); $path = $this->inputfilter->clean($f3->get('PARAMS.1'), 'string'); $model = $this->getModel(); try { $category = (new \Blog\Models\Categories())->setState('filter.path', $path)->getItem(); if (empty($category->id)) { throw new \Exception(); } $paginated = $model->populateState()->setState('filter.category.id', $category->id)->setState('filter.publication_status', 'published')->setState('filter.published_today', true)->paginate(); } catch (\Exception $e) { \Dsc\System::instance()->addMessage("Invalid Items", 'error'); $f3->reroute('/blog'); return; } $state = $model->getState(); \Base::instance()->set('state', $state); \Base::instance()->set('paginated', $paginated); \Base::instance()->set('category', $category); $this->app->set('meta.title', $category->seoTitle() . ' | Blog'); $this->app->set('meta.description', $category->seoDescription()); $view = \Dsc\System::instance()->get('theme'); echo $view->render('Blog/Site/Views::categories/index.php'); }
public function html() { $f3 = \Base::instance(); \Dsc\System::instance()->get('theme')->registerViewPath(__DIR__ . '/Views/', 'Blog/Modules/Posts/Views'); $string = \Dsc\System::instance()->get('theme')->renderLayout('Blog/Modules/Posts/Views::default.php'); return $string; }
protected function displayEdit() { $item = $this->getItem(); if (empty($item) || $item->product_type != 'giftcards') { \Dsc\System::addMessage('Item is not a giftcard', 'error'); $this->app->reroute('/admin/shop/giftcards'); } $f3 = \Base::instance(); $flash = \Dsc\Flash::instance(); $variants = array(); if ($flashed_variants = $flash->old('variants')) { foreach ($flashed_variants as $variant) { $key = implode("-", (array) $variant['attributes']); if (empty($key)) { $key = $variant['id']; } $variants[$key] = $variant; } } $old = array_merge($flash->get('old'), array('variants' => $variants)); $flash->store($old); $model = new \Shop\Models\Categories(); $categories = $model->getList(); \Base::instance()->set('categories', $categories); \Base::instance()->set('selected', 'null'); $all_tags = $this->getModel()->getTags(); \Base::instance()->set('all_tags', $all_tags); $this->app->set('meta.title', 'Edit Gift Card | Shop'); $view = \Dsc\System::instance()->get('theme'); $view->event = $view->trigger('onDisplayShopProductsEdit', array('item' => $this->getItem(), 'tabs' => array(), 'content' => array())); echo $view->render('Shop\\Admin\\Views::giftcards/edit.php'); }
public static function setActive() { if (!\Audit::instance()->isbot()) { if (class_exists('\\Activity\\Models\\Actors')) { $actor = \Activity\Models\Actors::fetch(); if ($actor->isExcluded()) { return; } } if (\Dsc\System::instance()->get('input')->get('ping', null, 'int') != 1) { $fw = \Base::instance(); $path = $fw->hive()['PATH']; switch ($path) { // ignore certain paths, even if they aren't specifically pings case strpos($path, '/minify/') === 0 ? true : false: case "/minify/css": case "/minify/js": break; default: (new \Dsc\Mongo\Collections\Sessions())->store(); break; } } } \Dsc\Mongo\Collections\Sessions::throttledCleanup(); }
/** * Parse an existing crontab * * @param Crontab $crontab * * @return CrontabFileHandler */ public function parseExistingCrontab(Crontab $crontab) { $result = exec($this->crontabCommand($crontab) . ' -l', $output, $retval); if (!empty($output)) { //\Dsc\System::addMessage(\Dsc\Debug::dump($output)); foreach ($output as $line) { if (trim($line) == '') { continue; } try { $job = \Dsc\Cron\Job::parse($line); $crontab->addJob($job); } catch (\Exception $e) { \Dsc\System::addMessage('Encountered error (' . $e->getMessage() . ') when parsing cron job: ' . $line, 'error'); } } } /* // parsing cron file $process = new Process($this->crontabCommand($crontab).' -l'); $process->run(); foreach ($this->parseString($process->getOutput()) as $job) { $crontab->addJob($job); } $this->error = $process->getErrorOutput(); */ return $this; }
public function index() { $f3 = \Base::instance(); $id = $this->inputfilter->clean($f3->get('PARAMS.id'), 'alnum'); $safemode_user = \Base::instance()->get('safemode.username'); // slug contaings safeuser username ==> redirect to blog home page if ($safemode_user == $id) { \Dsc\System::instance()->addMessage("Unknown Author", 'error'); $f3->reroute('/blog'); return; } try { $author = $this->getModel('users')->setState('filter.username', $id)->getItem(); if (empty($author->id)) { throw new \Exception(); } } catch (\Exception $e) { \Dsc\System::instance()->addMessage("Unknown Author", 'error'); $f3->reroute('/blog'); return; } $model_posts = $this->getModel('posts')->populateState()->setState('filter.author.username', $id)->setState('filter.published_today', true)->setState('filter.publication_status', 'published'); try { $paginated = $model_posts->paginate(); } catch (\Exception $e) { $paginated = null; } $state = $model_posts->getState(); \Base::instance()->set('state', $state); \Base::instance()->set('paginated', $paginated); \Base::instance()->set('author', $author); $this->app->set('meta.title', $author->fullName() . ' | Blog'); $view = \Dsc\System::instance()->get('theme'); echo $view->render('Blog/Site/Views::author/index.php'); }