function is_postspage() { if ($itm = IoC::resolve('page')) { return $itm->id == Config::get('metadata.posts_page'); } return false; }
function page_status() { if ($itm = IoC::resolve('page')) { return $itm->status; } return ''; }
private function _isUnread() { if (Auth::guest()) { return false; } $markAsReadAfter = value(Config::get('forums::forums.mark_as_read_after')); if (!IoC::registered('topicsview')) { IoC::singleton('topicsview', function () use($markAsReadAfter) { return Forumview::where('updated_at', '>=', date('Y-m-d H:i:s', $markAsReadAfter))->where('user_id', '=', Auth::user()->id)->lists('topic_id'); }); } $tv = IoC::resolve('topicsview'); $nb = count($tv); $view = Forumtopic::where('forumcategory_id', '=', $this->id)->where('updated_at', '>=', date('Y-m-d H:i:s', $markAsReadAfter)); if ($nb > 0) { $view = $view->where_not_in('id', $tv); } $view = $view->count(); if ($nb == 0 && $view > 0) { return true; } if ($view > 0) { return true; } return false; }
private static function parse() { // get uri $uri = Request::uri(); // lets log our initial uri Log::info('Requested URI: ' . $uri); // route definitions $routes = array(); // posts host page if ($page = IoC::resolve('posts_page')) { $routes[$page->slug . '/(:any)'] = 'article/$1'; } // fallback to 'admin' $admin_folder = Config::get('application.admin_folder', 'admin'); // static routes $routes = array_merge($routes, array($admin_folder . '/(:any)/(:any)/(:any)' => 'admin/$1/$2/$3', $admin_folder . '/(:any)/(:any)' => 'admin/$1/$2', $admin_folder . '/(:any)' => 'admin/$1', $admin_folder => 'admin', 'search/(:any)' => 'search/$1', 'search' => 'search', 'rss' => 'rss', '(:any)' => 'page/$1')); // define wild-cards $search = array(':any', ':num'); $replace = array('[0-9a-zA-Z~%\\.:_\\-]+', '[0-9]+'); // parse routes foreach ($routes as $route => $translated) { // replace wildcards $route = str_replace($search, $replace, $route); // look for matches if (preg_match('#^' . $route . '#', $uri, $matches)) { // replace matched values foreach ($matches as $k => $match) { $translated = str_replace('$' . $k, $match, $translated); } // return on first match return $translated; } } return $uri; }
function menu_active() { if ($itm = IoC::resolve('menu_item')) { return $itm->active; } return ''; }
public function action_index() { $markdown = IoC::resolve('markdown'); $data['toc'] = $markdown->transform(File::get(VIEW_PATH . 'contents.md')); $data['default_contents'] = $markdown->transform(File::get(VIEW_PATH . 'start/install.md')); return View::make('home.index', $data); }
/** * Test to send a real-world message * * @return void */ public function testSendEmail() { require 'fixtures/message.php'; $postmark = IoC::resolve('postmark'); $return = $postmark->send(new Message('*****@*****.**')); $this->assertTrue($return); }
/** * * @param string $name * @return object */ public function __get($name) { self::$called_class = get_called_class(); if (method_exists('\\system\\services\\SystemServiceRegistry', $name) || method_exists('\\application\\services\\AppServiceRegistry', $name)) { return IoC::resolve($name); } }
function comments_open() { if ($itm = IoC::resolve('article')) { return $itm->comments ? true : false; } return false; }
public function test_can_resolve_out_of_the_ioc_container() { IoC::bind('foo', function () { return new Foo(); }); $this->assertInstanceOf('Foo', IoC::make('foo')); }
public function post_review() { $this->filter('before', 'jboardOnly'); $input = Input::all(); //grab our input $rules = array('decision' => 'required', 'denyreason' => 'required', 'initials' => 'required|alpha|min:2', 'amtreduce' => 'numeric', 'details' => 'required'); //validation rules $validation = Validator::make($input, $rules); //let's run the validator if ($validation->fails()) { return Redirect::to('jboard/review/' . Input::get('ticketid'))->with_errors($validation); } //insert ruling into database Ruling::create(array('decision' => Input::get('decision'), 'denyreason' => Input::get('denyreason'), 'reasoning' => Input::get('details'), 'intials' => Input::get('initials'), 'CWID' => Input::get('cwid'), 'amtReduce' => Input::get('amtreduce'), 'ticketID' => Input::get('ticketid'))); //let's close the ticket now $close = DB::table('tickets')->where('ticketID', '=', Input::get('ticketid'))->update(array('appealStatus' => '1')); return Redirect::to('jboard/')->with('alertMessage', 'Ruling submitted successfully.'); DB::table('tickets')->where('ticketID', '=', Input::get('ticketid'))->update(array('appealStatus' => '1')); ///////////////////// // Now we're going to email the appellant to let them know that their appeal has been reviewed. ///////////////////// // Get the Swift Mailer instance $mailer = IoC::resolve('mailer'); //set the appellant's email address using CWID $email = Input::get('cwid') . '@marist.edu'; //set html body of email $body = "This autogenerated email is to let you know that your appeal has been reviewed and closed by the Justice Board. Please login to the Online Parking Appeal System at <a href='http://sga.marist.edu/parkingappeals/'>http://sga.marist.edu/parkingappeals/</a>. Please do not reply to this message. <br><br> Thank you, <br> Student Government Association Justice Board"; // Construct the message $message = Swift_Message::newInstance('[Marist SGA] Your Parking Appeal Has Been Reviewed')->setFrom(array('*****@*****.**' => 'SGA Judicial Board'))->setTo(array($email => 'Appellant'))->addPart('This email is autogenerated to let you know that your appeal has been reviewed by the Justice Board. Please login to the Online Parking Appeal System at http://sga.marist.edu/parkingappeals to review the decision. ', 'text/plain')->setBody($body, 'text/html'); // Send the email $mailer->send($message); return Redirect::to('jboard/')->with('alertMessage', 'Ruling submitted successfully.'); }
/** * run() is the start-point of the CLI request, the * first argument specifies the command, and sub-sequent * arguments are passed as arguments to the chosen generator. * * @param $arguments array The command and its arguments. * @return void */ public function run($arguments = array()) { if (!count($arguments)) { $this->_help(); } // setup ansi support Common::detect_windows(); // assign the params $command = $arguments[0] !== '' ? $arguments[0] : 'help'; $args = array_slice($arguments, 1); switch ($command) { case "controller": case "c": new Generators_Controller($args); break; case "model": case "m": new Generators_Model($args); break; case "alias": new Generators_Alias($args); break; case "migration": case "mig": IoC::resolve('task: migrate')->make($args); break; case "bundle": case "b": new Generators_Bundle($args); break; case "test": case "t": new Generators_Test($args); break; case "task": case "ta": new Generators_Task($args); break; case "class": case "cl": new Generators_Class($args); break; case "install": case "i": IoC::resolve('task: bundle')->install($args); break; case "config": case "co": new Generators_Config($args); break; case "view": case "v": new Generators_View($args); break; default: $this->_help(); break; } }
/** * Add an item to the session flash data. * * This is useful for passing status messages or other temporary data to the next request. * * <code> * // Create a redirect response and flash something to the session * return Redirect::to('user/profile')->with('message', 'Welcome Back!'); * </code> * * @param string $key * @param mixed $value * @return Response */ public function with($key, $value) { if (Config::get('session.driver') == '') { throw new \LogicException('A session driver must be set before setting flash data.'); } IoC::core('session')->flash($key, $value); return $this; }
public function purchaseDiscountedProduct($product, $discountPercentage) { $origPrice = $product->getPrice(); $newPrice = $origPrice - $discountPercentage / 100 * $origPrice; $discountedProduct = IoC::make('Product', [$product->getName(), $newPrice]); $this->logger->log("Applying discount to " . $product->getName()); $this->purchase($discountedProduct); }
/** * Run the test and create a TestLog. */ public function run() { $tester = IoC::resolve('tester'); $passed = $tester->test($this->type, $this->url, $this->options); $message = $passed ? 'Test Passed' : 'Test Failed'; #todo: more descriptive messages Test\Log::create(array('test_id' => $this->id, 'message' => $message, 'passed' => $passed)); }
public function action_index($folder = null) { //if ( ! Request::ajax()) //return; //Bundle::start('juploader'); $uploader = IoC::resolve('Uploader'); $uploader->with_uploader('Uploader\\DatabaseUploadHandler')->with_argument('1')->with_option('script_url', URL::to_action('juploader::dbupload@index'))->Start(); return $uploader->get_response(); }
public function setUp() { IoC::register('Logger', function () { return $this->getMock('stdClass', ['log']); }); IoC::register('Product', function ($name, $price) { return new Product($name, $price); }); $this->product = new Product('Water', 5.99); }
public static function generate() { // create a dom xml object static::$document = new DOMDocument('1.0', 'UTF-8'); // create our rss feed $rss = static::element('rss', null, array('version' => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom')); static::$document->appendChild($rss); // create channel $channel = static::element('channel'); $rss->appendChild($channel); // title $title = static::element('title', Config::get('metadata.sitename')); $channel->appendChild($title); // link $url = 'http://' . $_SERVER['HTTP_HOST']; $link = static::element('link', $url); $channel->appendChild($link); // description $description = static::element('description', Config::get('metadata.description')); $channel->appendChild($description); // laguage // http://www.rssboard.org/rss-language-codes $language = static::element('language', Config::get('application.language', 'en')); $channel->appendChild($language); $ttl = static::element('ttl', 60); $channel->appendChild($ttl); $docs = static::element('docs', 'http://blogs.law.harvard.edu/tech/rss'); $channel->appendChild($docs); $copyright = static::element('copyright', Config::get('metadata.sitename')); $channel->appendChild($copyright); // atom self link $atom = static::element('atom:link', null, array('href' => $url, 'rel' => 'self', 'type' => 'application/rss+xml')); $channel->appendChild($atom); // articles $params = array('status' => 'published', 'sortby' => 'id', 'sortmode' => 'desc'); foreach (Posts::list_all($params) as $post) { $item = static::element('item'); $channel->appendChild($item); // title $title = static::element('title', $post->title); $item->appendChild($title); // link $url = 'http://' . $_SERVER['HTTP_HOST'] . Url::make(IoC::resolve('posts_page')->slug . '/' . $post->slug); $link = static::element('link', $url); $item->appendChild($link); // description $description = static::element('description', $post->description); $item->appendChild($description); // date $date = static::element('pubDate', date(DATE_RSS, $post->created)); $item->appendChild($date); } // dump xml tree return static::$document->saveXML(); }
function search_results() { $posts = IoC::resolve('search'); if ($result = $posts->valid()) { // register single post IoC::instance('article', $posts->current(), true); // move to next $posts->next(); } return $result; }
public static function call($name = '') { $page = IoC::resolve('page'); if (empty($name)) { $name = 'main'; } if ($func = isset(static::$stack[$page->slug][$name]) ? static::$stack[$page->slug][$name] : false) { return is_callable($func) ? $func() : ''; } return ''; }
function posts_prev($text = 'Previous', $default = '') { $per_page = Config::get('metadata.posts_per_page'); $offset = Input::get('offset', 0); $total = IoC::resolve('total_posts'); $pages = ceil($total / $per_page); $page = $offset / $per_page; if ($offset > 0) { return '<a href="' . current_url() . '?offset=' . ($offset - $per_page) . '">' . $text . '</a>'; } return $default; }
public function search($term = '') { if (Input::method() == 'POST') { if (Input::post('term') !== false) { return Response::redirect('search/' . rawurlencode(Input::post('term'))); } } $search = Posts::search($term, array('status' => 'published')); IoC::instance('search', $search, true); $page = new StdClass(); $page->title = 'Search'; IoC::instance('page', $page, true); Template::render('search'); }
public function __construct() { parent::__construct(); $this->data['site_name'] = Config::get('settings::core.site_name'); $this->data['meta_title'] = ''; $this->data['meta_description'] = ''; $this->data['meta_keywords'] = ''; if (Bundle::exists('themes')) { $this->theme = IoC::resolve('Theme'); } // @TODO add fallback if themes module for // some reason is not installed/enabled $this->filter('before', 'mwi.base_controller_start', array($this)); }
function posts($params = array()) { if (has_posts() === false) { return false; } $posts = IoC::resolve('posts'); if ($result = $posts->valid()) { // register single post IoC::instance('article', $posts->current(), true); // move to next $posts->next(); } return $result; }
public static function extend($post) { if (is_array($post)) { $posts = array(); foreach ($post as $itm) { $posts[] = static::extend($itm); } return $posts; } if (is_object($post)) { $page = IoC::resolve('posts_page'); $post->url = Url::make($page->slug . '/' . $post->slug); return $post; } return false; }
public function search($term = '') { if (Input::method() == 'POST') { if (Input::post('term') !== false) { return Response::redirect('search/' . rawurlencode(Input::post('term'))); } } $search = Posts::search($term, array('status' => 'published', 'limit' => Config::get('metadata.posts_per_page', 10), 'offset' => Input::get('offset', 0))); IoC::instance('search', $search, true); $total = Posts::search_count($term, array('status' => 'published')); IoC::instance('total_search', $total, true); $page = new StdClass(); $page->id = -1; $page->title = 'Search'; IoC::instance('page', $page, true); Template::render('search'); }
public static function generate() { // create a dom xml object static::$document = new DOMDocument('1.0', 'UTF-8'); // create our rss feed $rss = static::element('rss', null, array('version' => '2.0')); static::$document->appendChild($rss); // create channel $channel = static::element('channel'); $rss->appendChild($channel); // title $title = static::element('title', Config::get('metadata.sitename')); $channel->appendChild($title); // link $link = static::element('link', 'http://' . $_SERVER['HTTP_HOST']); $channel->appendChild($link); // description $description = static::element('description', Config::get('metadata.description')); $channel->appendChild($description); // articles $params = array('status' => 'published', 'sortby' => 'id', 'sortmode' => 'desc'); foreach (Posts::list_all($params) as $post) { $item = static::element('item'); $channel->appendChild($item); // title $title = static::element('title', $post->title); $item->appendChild($title); // link $url = 'http://' . $_SERVER['HTTP_HOST'] . Url::make(IoC::resolve('posts_page')->slug . '/' . $post->slug); $link = static::element('link', $url); $item->appendChild($link); // description $description = static::element('description', $post->description); $item->appendChild($description); // date $date = static::element('pubDate', date(DATE_RSS, $post->created)); $item->appendChild($date); } // dump xml tree return static::$document->saveXML(); }
private function doRequest($URI, $data = []) { Input::$input = $data; Laravel\Routing\Filter::register(require APP_PATH . 'filters' . EXT); $loader = new Laravel\Routing\Loader(APP_PATH, ROUTE_PATH); $router = new Laravel\Routing\Router($loader, CONTROLLER_PATH); IoC::instance('laravel.routing.router', $router); Laravel\Request::$route = $router->route(Laravel\Request::method(), Laravel\URI::current()); if (!is_null(Request::$route)) { $response = Request::$route->call(); } else { Laravel\Routing\Filter::run(['before'], [], true); $response = Laravel\Response::json(['msg' => 'Not found'], 404); \Laravel\Routing\Filter::run(['after'], [$response], true); } ob_start(); $response->send(); $output = ob_get_contents(); ob_end_clean(); return $output; }
public function post($post_data, $timeout = 5) { $cookie_file = $this->_cookie->file; $ch = curl_init(); $header = $this->_header; $header['Content-Type'] = 'application/json'; curl_setopt_array($ch, [CURLOPT_COOKIEJAR => $cookie_file, CURLOPT_COOKIEFILE => $cookie_file, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_URL => $this->_url, CURLOPT_AUTOREFERER => false, CURLOPT_FOLLOWLOCATION => false, CURLOPT_CONNECTTIMEOUT => $timeout, CURLOPT_TIMEOUT => $timeout, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'] ?: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)', CURLOPT_HTTPHEADER => $header]); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); \Gini\Logger::of('core')->debug('RPC => {url}: {data}', ['url' => $this->_url, 'data' => $post_data]); $data = curl_exec($ch); $errno = curl_errno($ch); if ($errno) { $message = curl_error($ch); curl_close($ch); \Gini\Logger::of('core')->error('RPC cURL error: {message}', ['message' => $message]); throw IoC::construct('\\Gini\\RPC\\Exception', "transport error: {$message}", -32300); } curl_close($ch); return $data; }
public function post_index() { $rules = array('issue' => 'required'); $validation = Validator::make(Input::all(), $rules); if ($validation->fails()) { Messages::add('error', 'Please make sure you fill out the form to let us know what problem you are having.'); return Redirect::to('admin/' . $this->views . '')->with_input(); } else { // Get the Swift Mailer instance $mailer = IoC::resolve('mailer'); // Construct the message $message = Swift_Message::newInstance('Message From Website')->setFrom(array($this->data['user']->email => $this->data['user']->fullname))->setTo(array('*****@*****.**' => 'Framework Support For ' . COMPANY_NAME))->setBody('<p><strong>' . $this->data['user']->fullname . ' has emailed you:</strong></p> <q>' . Input::get('issue') . '</q> <p><strong>Email Address: </strong> ' . $this->data['user']->email . '</p> <p><strong>IP Address: </strong> ' . Request::ip() . '</p> <p><strong>User Agent: </strong> ' . Request::server('HTTP_USER_AGENT') . '</p>', 'text/html'); // Send the email $mailer->send($message); Messages::add('success', '<strong>Support Issue Sent</strong> We\'ll be in touch shortly.'); return Redirect::to('admin/help'); } }