public function execute() { $view = $this->getView(); $fac = new ModelFactory('PageModel'); $fac->where('baseurl LIKE /blog/view/%'); $fac->where('published_status = published'); $fac->where('published <= ' . \Core\Date\DateTime::NowGMT()); $fac->limit($this->getSetting('count')); switch ($this->getSetting('sort')) { case 'newest': $fac->order('published DESC'); break; case 'popular': $fac->order('popularity DESC'); break; case 'random': $fac->order('RAND()'); break; } if (!$fac->count()) { // If there are no results found, then do not display the widget. return ''; } $view->assign('sort', $this->getSetting('sort')); $view->assign('title', $this->getSetting('title')); $view->assign('links', $fac->get()); }
public function execute() { $view = $this->getView(); $fac = new ModelFactory('PageModel'); if ($this->getSetting('blog')) { $fac->where('parenturl = /blog/view/' . $this->getSetting('blog')); } $fac->where('parenturl LIKE /blog/view/%'); $fac->where('published_status = published'); $fac->where('published <= ' . \Core\Date\DateTime::NowGMT()); $fac->limit($this->getSetting('count')); switch ($this->getSetting('sort')) { case 'newest': $fac->order('published DESC'); break; case 'popular': $fac->order('popularity DESC'); break; case 'random': $fac->order('RAND()'); break; } if (!$fac->count()) { // If there are no results found, then do not display the widget. return ''; } $view->assign('count', $this->getSetting('count')); $view->assign('sort', $this->getSetting('sort')); $view->assign('title', $this->getSetting('title')); // The template is expecting an array, if count is 1, only a single Model is returned from the factory. $view->assign('links', $this->getSetting('count') == 1 ? [$fac->get()] : $fac->get()); }
/** * Check the user's IP and see if it's blacklisted. */ public static function CheckIP() { $factory = new \ModelFactory('IpBlacklistModel'); /*$factory->whereGroup( 'OR', [ 'expires > ' . \CoreDateTime::Now('U', \Time::TIMEZONE_GMT), 'expires = 0' ] );*/ $where = new \Core\Datamodel\DatasetWhereClause(); $ips = []; $longip = ip2long(REMOTE_IP); for ($i = 32; $i > 0; $i--) { if ($i < 16) { // Skip anything smaller than a /16. break; } $mask = ~((1 << 32 - $i) - 1); $ips[] = long2ip($longip & $mask) . '/' . $i; //$where->addWhere('ip_addr = ' . long2ip($longip & $mask) . '/' . $i); } $factory->where('ip_addr IN ' . implode(',', $ips)); $factory->limit(1); $ban = $factory->get(); if (!$ban) { // Ok, you may pass. return; } // Check the date if ($ban->get('expires') != 0 && $ban->get('expires') < DateTime::NowGMT()) { // Well it has one, but it's already expired. // Go ahead and clean it up. $ban->delete(); return; } // else... hehehe, happy happy fun time for you! \SystemLogModel::LogSecurityEvent('/security/blocked', 'Blacklisted IP tried to access the site (' . REMOTE_IP . ')', 'Blacklisted IP tried to access the site!<br/>Remote IP: ' . REMOTE_IP . '<br/>Matching Range: ' . $ban->get('ip_addr') . '<br/>Requested URL: ' . CUR_CALL); header('HTTP/1.0 420 Enhance Your Calm'); die($ban->get('message')); }
public function view() { $view = $this->getView(); $factory = new ModelFactory('GalleryImageModel'); if ($this->getSetting('order') == 'random') { $factory->order('RAND()'); } else { $factory->order($this->getSetting('order')); } if ($this->getSetting('album')) { $factory->where('albumid = ' . $this->getSetting('album')); $album = GalleryAlbumModel::Construct($this->getSetting('album')); $link = $album->get('baseurl'); } else { $link = null; } $factory->limit($this->getSetting('count')); $images = $factory->get(); $view->assign('images', $images); $view->assign('dimensions', $this->getSetting('dimensions')); $view->assign('link', $link); $view->assign('uselightbox', $this->getSetting('uselightbox') && Core::IsComponentAvailable('jquery-lightbox')); }
/** * The view for the admin dashboard. Gets the last executed crons and displays that to the admin. */ public function dashboard() { // This dashboard has no effect if the user can't view crons. if (!\Core\user()->checkAccess('p:/cron/viewlog')) { return ''; } $view = $this->getView(); // Get the latest cron and its execution information and display that to the dashboard. $checks = [['cron' => 'hourly', 'modify' => '-1 hour', 'label' => 'hour'], ['cron' => 'daily', 'modify' => '-1 day', 'label' => 'day'], ['cron' => 'weekly', 'modify' => '-1 week', 'label' => 'week'], ['cron' => 'monthly', 'modify' => '-1 month', 'label' => 'month']]; $crons = array(); foreach ($checks as $k => $check) { $time = new CoreDateTime(); $cronfac = new ModelFactory('CronLogModel'); $cronfac->limit(1); $cronfac->where('cron = ' . $check['cron']); $cronfac->order('created desc'); $c = $cronfac->get(); if ($c) { $crons[] = $c; } } $view->title = 't:STRING_LATEST_CRON_RESULTS'; $view->assign('crons', $crons); }
/** * Factory shortcut function to do a search for the specific records and return them as a raw array. * * @static * * @param array $where * @param null $limit * @param null $order * * @return array */ public static function FindRaw($where = [], $limit = null, $order = null) { $fac = new ModelFactory(get_called_class()); $fac->where($where); $fac->limit($limit); $fac->order($order); //var_dump($fac); return $fac->getRaw(); }
/** * Given all the user defined filter, sort, and what not, apply those values to the ModelFactory if possible. * * @since 2.4.0 * @param ModelFactory $factory */ public function applyToFactory(ModelFactory $factory){ if($this->hassort){ $factory->order($this->getOrder()); } if($this->haspagination){ // Determine the starting count if the page is requested. if($this->_currentpage > 1){ $startat = $this->_limit * ($this->_currentpage - 1); $factory->limit($startat . ', ' . $this->_limit); } else{ $factory->limit($this->_limit); } } foreach($this->_elements as $el){ /** @var $el FormElement */ $name = $el->get('name'); $idxname = $name; if(strpos($name, 'filter[') === 0){ $name = substr($name, 7, -1); } // If this element is not in the index of elements, skip to the next element. if(!isset($this->_elementindexes[$idxname])){ continue; } // If this doesn't have a link attribute, just skip. if(!$el->get('link')){ continue; } // No value, just skip. if($el->get('value') === '' || $el->get('value') === null){ continue; } // If there is a "" option, interpret that as empty and allow "0" to be used. if($el->get('value') === '0'){ if($el->get('options') && isset($el->get('options')[''])){ // '' is set... proceed. } else{ continue; } } $value = $el->get('value'); // Was there a prefix and/or suffix requested? if($el->get('linkvalueprefix')){ $value = $el->get('linkvalueprefix') . $value; } if($el->get('linkvaluesuffix')){ $value = $value . $el->get('linkvaluesuffix'); } // If this link is a date object, convert a date string to its unix timestamp representation. if($el instanceof FormDateInput || $el->get('dateformat')){ // Default to a unix timestamp, but allow the user to override this. // This is useful for saving a date in the datastore as a human-readable format. $format = $el->get('dateformat') ? $el->get('dateformat') : 'U'; $date = new CoreDateTime($value); $value = $date->getFormatted($format, Time::TIMEZONE_GMT); } if($el->get('linkname')){ $name = $el->get('linkname'); } // New support for multiple link names! if(!is_array($name)){ $name = [$name]; } $statements = []; foreach($name as $n){ switch($el->get('link')){ case FilterForm::LINK_TYPE_STANDARD: case FilterForm::LINK_TYPE_GT: case FilterForm::LINK_TYPE_GE: case FilterForm::LINK_TYPE_LT: case FilterForm::LINK_TYPE_LE: $statements[] = $n . $el->get('link') . $value; break; case FilterForm::LINK_TYPE_STARTSWITH: $statements[] = $n . ' LIKE ' . $value . '%'; break; case FilterForm::LINK_TYPE_CONTAINS: $statements[] = $n . ' LIKE %' . $value . '%'; break; } } if(sizeof($statements) > 1){ // Create a sub where clause for these. $subwhere = new \Core\Datamodel\DatasetWhereClause(); $subwhere->setSeparator('OR'); foreach($statements as $s){ $subwhere->addWhere($s); } // Add this sub clause to the main where clause. $factory->where($subwhere); } else{ // A single command just gets added to the main clause. $factory->where($statements[0]); } } // Might as well update the count now, it can always be updated later. $this->setTotalCount($factory->count()); }
/** * Get the page model for the current page. * * @return PageModel */ public function getPageModel() { if ($this->_pagemodel === null) { $uri = $this->uriresolved; $pagefac = new ModelFactory('PageModel'); $pagefac->where('rewriteurl = ' . $uri); //$pagefac->where('fuzzy = 0'); $pagefac->limit(1); if(Core::IsComponentAvailable('multisite') && MultiSiteHelper::IsEnabled()){ $pagefac->whereGroup('OR', array('site = -1', 'site = ' . MultiSiteHelper::GetCurrentSiteID())); } $p = $pagefac->get(); // Split this URL, it'll be used somewhere. $pagedat = $this->splitParts(); if ($p) { // :) Found it $this->_pagemodel = $p; } elseif ($pagedat && isset($pagedat['baseurl'])) { // Is this even a valid controller? // This will allow a page to be called with it being in the pages database. $p = new PageModel($pagedat['baseurl']); if(!$p->exists()){ $p->set('rewriteurl', $pagedat['rewriteurl']); } $this->_pagemodel = $p; } else { // No page in the database and no valid controller... sigh $this->_pagemodel = new PageModel(); } //var_dump($p); die(); // Make sure all the parameters from both standard GET and core parameters are tacked on. if ($pagedat && $pagedat['parameters']) { foreach ($pagedat['parameters'] as $k => $v) { $this->_pagemodel->setParameter($k, $v); } } if (is_array($_GET)) { foreach ($_GET as $k => $v) { if (is_numeric($k)) continue; $this->_pagemodel->setParameter($k, $v); } } } return $this->_pagemodel; }