public static function DrawDashboard() { // get large widget area ob_start(); uEvents::TriggerEvent('ShowDashboard'); $largeContent = ob_get_clean(); if ($largeContent) { echo '<div class="dash-large">' . $largeContent . '</div>'; } // get small widget area $smallContent = ''; $w = utopia::GetModulesOf('uDashboardWidget'); foreach ($w as $wid) { $wid = $wid['module_name']; $ref = new ReflectionClass($wid); ob_start(); if ($ref->hasMethod('Draw100')) { $wid::Draw100(); } elseif ($ref->hasMethod('Draw50')) { $wid::Draw50(); } elseif ($ref->hasMethod('Draw25')) { $wid::Draw25(); } $content = ob_get_clean(); if (!$content) { continue; } $smallContent .= '<div class="widget-container ' . $wid . '"><h1>' . $wid::GetTitle() . '</h1><div class="module-content">' . $content . '</div></div>'; } if ($smallContent) { echo '<div class="dash-small">' . $smallContent . '</div>'; } }
public static function CreateLinkMenu($module = null) { $cm = utopia::GetCurrentModule(); if ($module === null) { $module = $cm; } if (isset(self::$done[$module])) { return; } self::$done[$module] = true; $cmAdmin = is_subclass_of($cm, 'iAdminModule'); $modules = utopia::GetChildren($module); $highestpos = 0; foreach ($modules as $mid => $children) { if ($cmAdmin && !is_subclass_of($mid, 'iAdminModule')) { continue; } if (!$cmAdmin && is_subclass_of($mid, 'iAdminModule')) { continue; } foreach ($children as $child) { if (isset($child['callback'])) { continue; } if (isset($child['fieldLinks']) && $mid !== $cm) { continue; } if (uEvents::TriggerEvent('CanAccessModule', $mid) === FALSE) { continue; } if ($module !== $cm && $child['parent'] === '/') { continue; } $parent = '_modlinks_'; if (isset($child['parent']) && $child['parent'] !== '/') { $parent .= $child['parent']; } $obj = utopia::GetInstance($mid); $position = $obj->GetSortOrder(); if (isset($child['fieldLinks']) && $mid === $cm) { $position = 0; } if ($position > $highestpos) { $highestpos = $position; } uMenu::AddItem($parent . $mid, $obj->GetTitle(), $obj->GetURL(), $parent, null, $position); } self::CreateLinkMenu($mid); } if ($module === $cm) { // add separators $i = -10001; while ($i < $highestpos) { uMenu::AddItem('_sep_' . $i, '', '', '_modlinks_', null, $i); $i = $i + 1000; } } }
public function UpdateField($fieldName, $newValue, &$pkVal = NULL, $fieldType = NULL) { if ($fieldName == 'username') { $newValue = trim($newValue); // does this email already exist? $r = database::query('SELECT * FROM `' . $this->tablename . '` WHERE `username` = ?', array($newValue)); if ($r->fetch()) { uNotices::AddNotice('This email is already registered to an account.', NOTICE_TYPE_ERROR); return FALSE; } if (preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i', $newValue)) { // email address has been updated - set email_confirm and email_confirm_code if ($pkVal === NULL) { parent::UpdateField('username', $newValue, $pkVal); } parent::UpdateField('email_confirm', $newValue, $pkVal); } else { parent::UpdateField('username', $newValue, $pkVal); } return TRUE; } if ($pkVal === NULL) { parent::UpdateField('username', 'unverified_' . uCrypt::GetRandom(75), $pkVal); } if ($fieldName == 'email_confirm_code' && $newValue === true) { // get old username $r = database::query('SELECT username, email_confirm FROM `' . $this->tablename . '` WHERE user_id = ?', array($pkVal)); if ($r && ($row = $r->fetch()) && $row['email_confirm']) { $old = $row['username']; $new = $row['email_confirm']; // set username to email_confirm parent::UpdateField('username', 'email_confirm', $pkVal, ftRAW); // clear email_confirm + code parent::UpdateField('email_confirm', '', $pkVal); parent::UpdateField('email_confirm_code', '', $pkVal); if ($old != $new) { uEvents::TriggerEvent('UsernameChanged', NULL, array($old, $new)); } } return; } parent::UpdateField($fieldName, $newValue, $pkVal, $fieldType); }
public function RunModule() { uEvents::TriggerEvent('InitSitemap'); $grp = isset($_GET['group']) ? $_GET['group'] : ''; if (!isset(self::$items[$grp])) { utopia::PageNotFound(); } utopia::CancelTemplate(); header('Content-Type: application/xml', true); echo '<?xml version="1.0" encoding="UTF-8"?>'; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; foreach (self::$items[$grp] as $entry) { echo '<url>'; foreach ($entry as $k => $v) { echo "\t<{$k}>{$v}</{$k}>"; } echo '</url>'; } echo '</urlset>'; die; }
public function ShowData() { //check pk and ptable are set up if (is_empty($this->GetTabledef())) { ErrorLog('Primary table not set up for ' . get_class($this)); return; } echo '<h1>' . $this->GetTitle() . '</h1>'; echo '{list.' . get_class($this) . '}'; $row = null; $num_rows = 0; if (!isset($_GET['_n_' . $this->GetModuleId()])) { $this->GetLimit($limit, $page); $dataset = $this->GetDataset(); $num_rows = $dataset->CountRecords(); $row = $dataset->GetPage($page, $limit)->fetch(); } $pagination = ''; $this->GetLimit($limit); if ($limit) { $pages = max(ceil($num_rows / $limit), 1); ob_start(); utopia::OutputPagination($pages, '_p_' . $this->GetModuleId()); $pagination = ob_get_clean(); } $records = $num_rows == 0 ? "There are no records to display." : 'Total Rows: ' . $num_rows; $pager = '<div class="right">' . $pagination . '</div>'; uEvents::TriggerEvent('OnShowDataDetail', $this); if ($this->flag_is_set(ALLOW_DELETE) && $row) { $fltr =& $this->FindFilter($this->GetPrimaryKey(), ctEQ, itNONE); $delbtn = $this->GetDeleteButton($this->GetFilterValue($fltr['uid']), 'Delete Record'); utopia::AppendVar('footer_left', $delbtn); } // if (!$this->IsNewRecord()) { // records exist, lets get the first. // pagination? // if (mysql_num_rows($result) > 1) { // multiple records exist in this set, sort out pagination // } // } $order = $this->GetSortOrder(); $extraCount = 1; $secCount = count($this->layoutSections); foreach ($this->layoutSections as $sectionID => $sectionInfo) { $out = ''; if ($secCount > 1) { $sectionName = $sectionInfo['title']; if ($sectionName === '') { if ($sectionID === 0) { $SN = 'General'; } else { $SN = "Extra ({$extraCount})"; $extraCount++; } } else { $SN = ucwords($sectionName); } $out .= '<h2>' . $SN . '</h2>'; } if (!$this->isAjax) { $out .= '<form class="uf" action="" onsubmit="this.action = window.location" method="post">'; } $out .= "<div class=\"table-wrapper\"><table class=\"module-content layoutDetailSection\">"; $fields = $this->GetFields(true, $sectionID); $hasFieldHeaders = false; foreach ($fields as $fieldName => $fieldData) { $hasFieldHeaders = $hasFieldHeaders || !empty($fieldData['visiblename']); } $fieldCount = count($fields); foreach ($fields as $fieldName => $fieldData) { $targetUrl = $this->GetTargetUrl($fieldName, $row); $out .= "<tr>"; if ($hasFieldHeaders) { $out .= "<td class=\"fld\">" . $fieldData['visiblename'] . "</td>"; } $out .= '<td>' . $this->GetCell($fieldName, $row, $targetUrl) . '</td>'; $out .= "</tr>"; } $out .= "</table></div>"; if (!$this->isAjax) { $out .= '</form>'; } echo $out; } if ($num_rows > 1) { echo '<div class="oh"><b>' . $records . '</b>' . $pager . '</div>'; } }
public static function OutputTemplate() { uEvents::TriggerEvent('BeforeOutputTemplate'); if (!self::UsingTemplate()) { ob_end_clean(); echo utopia::GetVar('content'); return; } if (isset($_GET['inline']) && !is_numeric($_GET['inline'])) { $_GET['inline'] = 0; } if (self::UsingTemplate(TEMPLATE_BLANK) || isset($_GET['inline']) && $_GET['inline'] == 0) { $template = utopia::GetVar('content'); } else { $tCount = -1; // do all by default if (isset($_GET['inline'])) { $tCount = $_GET['inline'] - 1; } $template = ''; $css = self::GetTemplateCSS(); foreach ($css as $cssfile) { uCSS::LinkFile($cssfile); } // first get list of parents $templates = array(); $templateDir = utopia::GetTemplateDir(true); if (!file_exists($templateDir)) { $templateDir = utopia::GetAbsolutePath($templateDir); } if (file_exists($templateDir)) { $templates[] = $templateDir; } while ($tCount-- && file_exists($templateDir . '/template.ini')) { $inifile = parse_ini_file($templateDir . '/template.ini'); if (!isset($inifile['parent'])) { break; } if (file_exists(PATH_ABS_ROOT . $inifile['parent'])) { $templateDir = PATH_ABS_ROOT . $inifile['parent']; } else { $templateDir = dirname($templateDir) . '/' . $inifile['parent']; } $templates[] = $templateDir; } foreach ($templates as $templateDir) { // set templatedir self::SetVar('templatedir', self::GetRelativePath($templateDir)); $templatePath = $templateDir . '/template.php'; $template = get_include_contents($templatePath); // mergevars while (self::MergeVars($template)) { } // setvar self::SetVar('content', $template); } if (!$template) { $template = '{utopia.content}'; } } ob_end_clean(); while (self::MergeVars($template)) { } $template = str_replace('<head>', '<head>' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>', $template); // Make all resources secure if (self::IsRequestSecure()) { $template = str_replace('http://' . self::GetDomainName(), 'https://' . self::GetDomainName(), $template); } do { if (self::UsingTemplate() && class_exists('DOMDocument')) { libxml_use_internal_errors(true); $doc = new DOMDocument(); $doc->formatOutput = false; $doc->preserveWhiteSpace = true; $doc->validateOnParse = true; if (!$doc->loadHTML('<?xml encoding="UTF-8">' . utf8_decode($template))) { break; } $isSnip = stripos($template, '<html') === false; $doc->encoding = 'UTF-8'; // no html tag? break out. if (!$doc->getElementsByTagName('html')->length) { break; } // remove multiple xmlns attributes $doc->documentElement->removeAttributeNS(NULL, 'xmlns'); // assert BODY tag if (!$doc->getElementsByTagName('body')->length) { $node = $doc->createElement("body"); $doc->getElementsByTagName('html')->item(0)->appendChild($node); } // assert HEAD tag if (!$doc->getElementsByTagName('head')->length) { // create head node $node = $doc->createElement("head"); $body = $doc->getElementsByTagName('body')->item(0); $newnode = $body->parentNode->insertBefore($node, $body); } // add HEAD children $head = $doc->getElementsByTagName('head')->item(0); // set title if (!$head->getElementsByTagName('title')->length) { $node = $doc->createElement('title'); $node->appendChild($doc->createTextNode(utopia::GetTitle(true))); $head->appendChild($node); } if (utopia::GetDescription(true)) { $node = $doc->createElement('meta'); $node->setAttribute('name', 'description'); $node->setAttribute('content', utopia::GetDescription(true)); $head->appendChild($node); } if (utopia::GetKeywords(true)) { $node = $doc->createElement('meta'); $node->setAttribute('name', 'keywords'); $node->setAttribute('content', utopia::GetKeywords(true)); $head->appendChild($node); } $node = $doc->createElement('meta'); $node->setAttribute('name', 'generator'); $node->setAttribute('content', 'uCore PHP Framework'); $head->appendChild($node); // template is all done, now lets run a post process event try { uEvents::TriggerEvent('ProcessDomDocument', null, array(&$doc)); } catch (Exception $e) { uErrorHandler::EchoException($e); } $ctNode = null; foreach ($head->getElementsByTagName('meta') as $meta) { if ($meta->hasAttribute('http-equiv') && strtolower($meta->getAttribute('http-equiv')) == 'content-type') { $ctNode = $meta; break; } } if (!$ctNode) { $ctNode = $doc->createElement('meta'); $head->appendChild($ctNode); } $ctNode->setAttribute('http-equiv', 'content-type'); $ctNode->setAttribute('content', 'text/html;charset=' . CHARSET_ENCODING); if ($ctNode !== $head->firstChild) { $head->insertBefore($ctNode, $head->firstChild); } $doc->normalizeDocument(); if (strpos(strtolower($doc->doctype->publicId), ' xhtml ')) { $template = $doc->saveXML(); } else { $template = $doc->saveHTML(); } $template = preg_replace('/<\\?xml encoding="UTF-8"\\??>\\n?/i', '', $template); if ($isSnip && !self::$noSnip) { $template = preg_replace('/.*<body[^>]*>\\s*/ims', '', $template); // remove everything up to and including the body open tag $template = preg_replace('/\\s*<\\/body>.*/ims', '', $template); // remove everything after and including the body close tag } } } while (false); while (self::MergeVars($template)) { } if (isset($_GET['callback'])) { $output = json_encode(array('title' => self::GetTitle(true), 'content' => $template)); header('Content-Type: application/javascript'); echo $_GET['callback'] . '(' . $output . ')'; return; } echo $template; }
public function UpdateField($fieldName, $newValue, &$pkVal = NULL, $fieldType = NULL) { $this->AssertTable(); uEvents::TriggerEvent('BeforeUpdateField', $this, array($fieldName, $newValue, &$pkVal, $fieldType)); //AjaxEcho('//'.str_replace("\n",'',get_class($this)."@UpdateField($fieldName,,$pkVal)\n")); if ($fieldType === NULL) { $fieldType = $this->fields[$fieldName]['type']; } if (is_array($newValue)) { $newValue = json_encode($newValue); } if ($newValue) { switch ($fieldType) { case ftRAW: break; case ftDATE: case ftTIME: case ftDATETIME: // datetime // datetime case ftTIMESTAMP: $parsed = utopia::strtotime($newValue); $newValue = $newValue == '' ? 'NULL' : date('Y-m-d H:i:s', $parsed); break; case ftFLOAT: // float // float case ftDECIMAL: $l = setlocale(LC_ALL, 'en_US'); $newValue = floatval($newValue); setlocale(LC_ALL, $l); break; case ftBOOL: // bool // bool case ftPERCENT: // percent // percent case ftCURRENCY: // currency // currency case ftNUMBER: $newValue = $newValue === '' ? '' : preg_replace('/[^0-9\\.-]/', '', $newValue); break; } } if (($newValue === '' || $newValue === NULL) && $this->GetFieldProperty($fieldName, 'null') !== SQL_NOT_NULL) { $newValue = NULL; } $updateQry = array(); $raw = $fieldType == ftRAW; $args = array(); if ($pkVal === NULL) { $query = 'INSERT INTO ' . $this->tablename . ' (`' . $fieldName . '`) VALUES (' . ($raw ? $newValue : '?') . ')'; if (!$raw) { $args[] = $newValue; } } else { $query = 'UPDATE ' . $this->tablename . ' SET `' . $fieldName . '` = ' . ($raw ? $newValue : '?') . ' WHERE `' . $this->GetPrimaryKey() . '` = ?'; if (!$raw) { $args[] = $newValue; } $args[] = $pkVal; } database::query($query, $args); if ($fieldName == $this->GetPrimaryKey() && $newValue !== NULL) { // this allows us to get the real evaluated value of the new primary key $stm = database::query('SELECT ? AS new_pk', array($newValue)); $row = $stm->fetch(); $pkVal = $row['new_pk']; } elseif ($pkVal === NULL) { $pkVal = database::connect()->lastInsertId(); } uEvents::TriggerEvent('AfterUpdateField', $this, array($fieldName, $newValue, &$pkVal, $fieldType)); }
$row['module_name']::Initialise(); timer_end('Init: ' . $row['module_name']); } timer_end('Static Initialise'); uConfig::DefineConfig(); uConfig::ValidateConfig(); uEvents::TriggerEvent('ConfigDefined'); timer_start('Before Init'); uEvents::TriggerEvent('BeforeInit'); timer_end('Before Init'); timer_start('Table Initialise'); uTableDef::TableExists(null); // cache table exists $allmodules = utopia::GetModulesOf('uTableDef'); foreach ($allmodules as $row) { // must run second due to requiring GLOB_MOD to be setup fully timer_start('Init: ' . $row['module_name']); $obj = utopia::GetInstance($row['module_name']); $obj->AssertTable(); // setup Parents timer_end('Init: ' . $row['module_name']); } timer_end('Table Initialise'); define('INIT_COMPLETE', TRUE); timer_start('After Init'); uEvents::TriggerEvent('InitComplete'); uEvents::TriggerEvent('AfterInit'); timer_end('After Init'); if ($_SERVER['HTTP_HOST'] !== 'cli') { utopia::UseTemplate(TEMPLATE_DEFAULT); }
public function GetTitle() { $rec = self::findPage(); if (!$rec) { $rec = self::GetHomepage(); } if (!$rec) { $rec = $this->LookupRecord(); } if (isset($_GET['preview']) && uEvents::TriggerEvent('CanAccessModule', 'uCMS_Edit') !== FALSE) { return $rec['title'] . ' (Preview)'; } return $rec['title']; }
public static function LoginForm() { if (self::IsLoggedIn()) { return; } ?> <div class="login-wrap widget-container"> <h1>Log In</h1> <form class="module-content" action="<?php echo $_SERVER['REQUEST_URI']; ?> " method="POST"> <div class="form-field"> <label for="__login_u">Email/Username</label>{login_user} </div> <div class="form-field"> <label for="__login_p">Password</label>{login_pass} </div> <label><input type="checkbox" value="1" name="remember_me" /> Remember Me</label><?php $o = utopia::GetInstance('uResetPassword'); echo utopia::DrawInput('', itSUBMIT, 'Log In', null, array('class' => 'right')); echo '<a href="' . $o->GetURL(null) . '" class="forgotten-password">Forgotten Password?</a>'; echo '</form><script type="text/javascript">$(function (){$(\'#__login_u\').focus()})</script>'; uEvents::TriggerEvent('LoginButtons'); echo '</div>'; // register uEvents::TriggerEvent('AfterShowLogin'); }