static function LinkToDocument($obj, $event, $templateDoc) { $head = $templateDoc->getElementsByTagName('head')->item(0); array_sort_subkey(self::$linkFiles, 'order'); $beforeRef = $head->getElementsByTagName('link')->length ? $head->getElementsByTagName('link')->item(0) : null; foreach (self::$linkFiles as $path) { // already exists? $exists = false; foreach ($templateDoc->getElementsByTagName('link') as $l) { if ($l->getAttribute('rel') == 'stylesheet' && $l->getAttribute('href') == $path['path']) { $exists = true; break; } } if ($exists) { continue; } $node = $templateDoc->createElement('link'); $node->setAttribute('type', 'text/css'); $node->setAttribute('rel', 'stylesheet'); $node->setAttribute('href', $path['path']); if ($beforeRef) { $head->insertBefore($node, $beforeRef); } else { $head->appendChild($node); } } }
public static function DrawAdminBar() { if (!self::$items) { return ''; } $items = self::$items; array_sort_subkey($items, 'order'); $arr = array(); $body = array(); foreach ($items as $r => $itm) { $r = 'menu_' . $r; $class = array($r); if ($itm['class']) { $class[] = $itm['class']; } if ($itm['menu'] && $itm['body']) { $class[] = 'toggle'; } $classt = ' class="' . implode(' ', $class) . '"'; if ($itm['menu'] !== FALSE) { $arr[] = '<li' . $classt . ' rel="' . $r . '">' . $itm['menu'] . '</li>'; } $class[] = 'admin-body-item'; $classt = ' class="' . implode(' ', $class) . '"'; if ($itm['body'] !== FALSE) { $body[] = '<div' . $classt . '>' . $itm['body'] . '</div>'; } } return '<div class="u-admin admin-bar"><div class="admin-toggle"><span/></div><div class="admin-container"><ul class="admin-menu">' . implode('', $arr) . '</ul><div class="admin-body">' . implode('', $body) . '</div></div></div>'; }
public function getWidgets() { // static $rows = array(); foreach (uWidgets::$staticWidgets as $name => $widget) { $rows[] = array('block_id' => $name, 'block_type' => 'Fixed Widgets'); } // widgets $o = utopia::GetInstance(__CLASS__); $widgets = $o->GetDataset()->fetchAll(); array_sort_subkey($widgets, 'block_type'); $rows = array_merge($rows, $widgets); $obj = utopia::GetInstance('uWidgets'); $newUrl = $obj->GetURL(); $rows = array($newUrl, $rows); header('Content-Type: application/json'); echo json_encode($rows); }
public static function GetMenu($group = '', $level = 1) { $group = strtolower($group); if (!isset(self::$items[$group])) { return ''; } $level = $level - 1; array_sort_subkey(self::$items[$group], 'pos'); $lastWasBlank = true; $items = array(); foreach (self::$items[$group] as $item) { if (empty($item['url']) && $lastWasBlank) { continue; } $attrs = $item['attr']; if (isset($attrs['class'])) { $attrs['class'] .= ' ' . strtolower($item['id']); } else { $attrs['class'] = strtolower($item['id']); } $attrs = BuildAttrString($attrs); $ret = '<li ' . $attrs . '>'; if (!empty($item['url'])) { $ret .= '<a href="' . $item['url'] . '" title="' . $item['text'] . '">' . $item['text'] . '</a>'; } else { $ret .= ' '; } if ($level !== 0) { $ret .= self::GetMenu($item['id'], $level); } $ret .= '</li>'; $items[] = $ret; $lastWasBlank = empty($item['url']); } if (!$items) { return ''; } $ret = '<ul class="u-menu ' . $group . '">' . implode('', $items) . '</ul>'; return $ret; }
public static function TriggerEvent($eventName, $object = null, $eventData = array()) { $module = null; if (is_object($object)) { $module = get_class($object); } if (is_string($object)) { $module = $object; $object = utopia::GetInstance($object); } $module = strtolower($module); $eventName = strtolower($eventName); if (!isset(self::$callbacks[$eventName])) { return TRUE; } $process = array_unique(array($module, '')); if (!is_array($eventData)) { $eventData = array($eventData); } $eventData = array_merge(array(&$object, $eventName), $eventData); // accumulate all handlers $handlers = array(); foreach ($process as $module) { if (!isset(self::$callbacks[$eventName][$module])) { continue; } $handlers = array_merge($handlers, self::$callbacks[$eventName][$module]); } // sort handlers array_sort_subkey($handlers, 'order'); // execute handlers, break if any return FALSE; $return = true; foreach ($handlers as $callback) { $return = $return && call_user_func_array($callback['callback'], $eventData) !== FALSE; } return $return; }
public function ShowData($dataset = null) { echo '<h1>' . $this->GetTitle() . '</h1>'; echo '{list.' . get_class($this) . '}'; array_sort_subkey($this->fields, 'order'); $this->GetLimit($limit, $page); if (!$dataset) { $dataset = $this->GetDataset(); } $dataset->GetPage($page, $limit); $num_rows = $dataset->CountRecords(); uEvents::TriggerEvent('OnShowDataList', $this); // first draw header for list if (!isset($GLOBALS['inlineListCount'])) { $GLOBALS['inlineListCount'] = 0; } else { $GLOBALS['inlineListCount']++; } ob_start(); if (!$this->isAjax) { echo '<form class="uf" action="" onsubmit="this.action = window.location" method="post"><input type="hidden" name="__ajax" value="updateField">'; } echo "<div class=\"table-wrapper\"><table class=\"" . get_class($this) . " layoutListSection module-content\">"; $sectionFieldTitles = array(); // TODO: pagination for list record display if (!$this->flag_is_set(LIST_HIDE_HEADER)) { echo '<thead>'; ob_start(); // start of SECTION headers if (count($this->layoutSections) > 1) { echo '<tr>'; // need first 'empty' column for buttons? if ($this->flag_is_set(ALLOW_DELETE)) { echo "<td> </td>"; } $sectionCount = 0; $sectionID = NULL; $keys = array_keys($this->fields); $lastFieldName = end($keys); foreach ($this->fields as $fieldName => $fieldData) { if ($fieldData['visiblename'] === NULL) { continue; } if ($sectionID === NULL) { $sectionID = $fieldData['layoutsection']; } if ($fieldData['layoutsection'] !== $sectionID) { // write the section, and reset the count $sectionName = $this->layoutSections[$sectionID]['title']; $secClass = empty($sectionName) ? '' : ' sectionHeader'; echo "<td colspan=\"{$sectionCount}\" class=\"{$secClass}\">" . nl2br($sectionName) . "</td>"; $sectionCount = 0; $sectionID = $fieldData['layoutsection']; } $sectionFieldTitles[$sectionID] = array_key_exists($sectionID, $sectionFieldTitles) ? $sectionFieldTitles[$sectionID] : !empty($fieldData['visiblename']); $sectionCount++; } $sectionName = $this->layoutSections[$sectionID]['title']; $secClass = empty($sectionName) ? '' : ' sectionHeader'; echo "<td colspan=\"{$sectionCount}\" class=\"{$secClass}\">" . nl2br($sectionName) . "</td>"; echo "</tr>"; } // start of FIELD headers $colcount = 0; echo '<tr class="field-headers">'; if ($this->flag_is_set(ALLOW_DELETE)) { echo '<th"></th>'; $colcount++; } foreach ($this->fields as $fieldName => $fieldData) { if ($fieldData['visiblename'] === NULL) { continue; } $colcount++; // sort? $icon = ''; $o = $this->GetOrderBy(true); if (is_array($o)) { foreach ($o as $order) { if (strpos($order, '`' . $fieldName . '`') !== FALSE) { $icon = ' sort-up'; if (stripos($order, 'desc') !== FALSE) { $icon = ' sort-down'; } break; } } } echo '<th class="field-' . $fieldName . ' sortable' . $icon . '" data-field="' . $fieldName . '" data-mid="' . $this->GetModuleId() . '">'; // title echo nl2br($fieldData['visiblename']); echo "</th>"; } echo '</tr>'; // close column headers $header_output = ob_get_clean(); if ($this->flag_is_set(ALLOW_FILTER) && $this->hasEditableFilters === true && $this->hideFilters !== TRUE) { echo '<tr class="noprint"><td class="uFilters" colspan="' . $colcount . '">'; // other filters foreach ($this->filters as $fType) { foreach ($fType as $filterset) { //flag_is_set($fieldData['options'],ALLOW_FILTER)) { foreach ($filterset as $filterInfo) { if ($filterInfo['it'] === itNONE) { continue; } echo $this->GetFilterBox($filterInfo); } } } echo '</td></tr>'; } if ($num_rows > 0 || $this->flag_is_set(ALLOW_ADD) || $this->hasEditableFilters === true) { echo $header_output; } echo "</thead>\n"; } // now display data rows // process POST filters $total = array(); $totalShown = array(); timer_start('Draw Rows: ' . get_class($this)); $gUrl = ''; $body = "<tbody{$gUrl}>"; if ($num_rows == 0) { } else { $i = 0; $fields = $this->GetFields(); while ($row = $dataset->fetch()) { $i++; // move totals here foreach ($fields as $fieldName => $fieldData) { switch ($this->GetFieldType($fieldName)) { case ftNUMBER: case ftCURRENCY: case ftPERCENT: if (!array_key_exists($fieldName, $total)) { $total[$fieldName] = 0; } if (!array_key_exists($fieldName, $totalShown)) { $totalShown[$fieldName] = 0; } $preProcessValue = floatval(preg_replace('/[^0-9\\.-]/', '', $this->PreProcess($fieldName, $row[$fieldName], $row))); if ($i <= 150) { $totalShown[$fieldName] += $preProcessValue; } $total[$fieldName] += $preProcessValue; break; default: break; } } $body .= $this->DrawRow($row); } } $body .= "</tbody>"; timer_end('Draw Rows: ' . get_class($this)); $foot = ''; $canadd = false; foreach ($this->fields as $fieldName => $fieldData) { if ($this->flag_is_set(ALLOW_ADD, $fieldName)) { $canadd = true; break; } } if ($canadd) { $hideNew = $this->GetMaxRows() && $num_rows >= $this->GetMaxRows() ? ' style="display:none"' : ''; $foot .= '<tr class="newRow"' . $hideNew . '>'; if ($this->flag_is_set(ALLOW_DELETE)) { $foot .= "<td class=\"new-ident\"></td>"; } foreach ($this->fields as $fieldName => $fieldData) { if ($fieldData['visiblename'] === NULL) { continue; } $classes = array(); $class = count($classes) > 0 ? ' class="' . join(' ', $classes) . '"' : ''; if ($this->flag_is_set(ALLOW_ADD, $fieldName)) { $foot .= "<td{$class}>" . $this->GetCell($fieldName, NULL) . '</td>'; } // TODO: Default value not showing on new records (list) } $foot .= '</tr>'; } if (!empty($total) && $this->flag_is_set(SHOW_TOTALS)) { $foot .= '<tr>'; if ($this->flag_is_set(ALLOW_DELETE)) { $foot .= "<td class=\"totals-ident\"></td>"; } foreach ($this->fields as $fieldName => $fieldData) { if ($fieldData['visiblename'] === NULL) { continue; } $classes = array(); $class = count($classes) > 0 ? ' class="' . join(' ', $classes) . '"' : ''; if (array_key_exists($fieldName, $total)) { $foot .= "<td{$class}><b>"; if ($totalShown[$fieldName] != $total[$fieldName]) { $foot .= htmlentities($this->PreProcess($fieldName, $totalShown[$fieldName])) . '(shown)<br/>'; } $foot .= htmlentities($this->PreProcess($fieldName, $total[$fieldName])); $foot .= '</b></td>'; } else { $foot .= "<td{$class}></td>"; } } $foot .= '</tr>'; } if (!empty($foot)) { echo "<tfoot>{$foot}</tfoot>"; } echo $body; // now finish table echo "</table></div>"; //"</div>"; if (!$this->isAjax) { echo '</form>'; } if ($limit) { $pages = max(ceil($num_rows / $limit), 1); ob_start(); utopia::OutputPagination($pages, '_p_' . $this->GetModuleId()); $pagination = ob_get_clean(); if ($pagination) { echo '<div class="pagination right module-content">' . $pagination . '</div>'; } } echo '<div class="right module-content">Showing ' . ($page * $limit + 1) . ' - ' . min($page * $limit + $limit, $num_rows) . ' of ' . $num_rows . '</div>'; $cont = ob_get_clean(); echo $cont; }
static function LinkList_Get($listName, $id = NULL, $listAttrs = NULL, $linkAttrs = NULL) { if (!$id) { $id = "ulist_{$listName}"; } $id = " id=\"{$id}\""; $list =& self::$lists["linklist_{$listName}"]; if (!is_array($list)) { return; } array_sort_subkey($list, 'order'); $return = ""; foreach ($list as $order => $info) { $attrsList = ""; $attrsLink = ""; if (isset($info['attrList']) && is_array($info['attrList']) && isset($info['attrList']['class'])) { $info['attrList']['class'] .= " linklist-link"; } else { $info['attrList']['class'] = "linklist-link"; } if (isset($info['attrList']) && is_array($info['attrList']) || is_array($listAttrs)) { if (is_array($listAttrs)) { foreach ($listAttrs as $attr => $val) { $info['attrList'][$attr] = $val; } } foreach ($info['attrList'] as $k => $v) { $attrsList .= " {$k}=\"{$v}\""; } } if (isset($info['attrLink']) && is_array($info['attrLink']) || is_array($linkAttrs)) { if (is_array($linkAttrs)) { foreach ($linkAttrs as $attr => $val) { $info['attrLink'][$attr] = $val; } } foreach ($info['attrLink'] as $k => $v) { $attrsLink .= " {$k}=\"{$v}\""; } } if (empty($info['text']) && !empty($info['url'])) { $return .= "<li{$attrsList}>" . $info['url'] . "</li>"; } elseif (empty($info['url'])) { if (empty($info['text'])) { // style=\"line-height:5px;height:5px;width:5px;\" $return .= "<li class=\"linklist-sep\"> </li>"; } else { $return .= "<li{$attrsList}><a{$attrsLink}>" . htmlspecialchars($info['text']) . "</a></li>"; } //<div$attrsLink>{$info['text']}</div>"; } else { $href = empty($info['url']) ? '' : " href=\"" . htmlspecialchars($info['url']) . "\""; $return .= "<li{$attrsList}><a{$attrsLink}{$href}>" . htmlspecialchars($info['text']) . "</a></li>"; } } $return = trim($return, "\n"); return "\n<ul{$id} class=\"linklist\">{$return}</ul>"; }
static function RunSearch($q, $adv = null) { $scores = array(); foreach (self::$recipients as $module => $info) { $fields = $info[0]; $obj = utopia::GetInstance($module); $pk = $obj->GetPrimaryKey(); $dataset = $obj->GetDataset(); while ($row = $dataset->fetch()) { $score = 0; foreach ($fields as $field) { if (!isset($row[$field])) { continue; } $score += self::SearchCompareScore($q, $row[$field]); } if ($score > 0) { $scores[] = array($score, $module, $row[$pk], $info); } } } if ($adv) { foreach ($scores as $k => $s) { if ($s[1] != self::$types[$adv]) { unset($scores[$k]); } } // return call_user_func(self::$types[$adv]['callback'],$q,$scores); } array_sort_subkey($scores, 0, false); return $scores; }
public function GetNestedArray($parent = '') { $this->BypassSecurity(true); $dataset = $this->GetDataset(); $this->BypassSecurity(false); $relational = array(); $rows = uCMS_View::fetchAll(); foreach ($rows as $row) { $row['children'] = array(); $relational[$row['cms_id']] = $row; } array_sort_subkey($relational, 'position'); $unset = array(); foreach ($relational as $k => $i) { if ($i['parent'] && array_key_exists($i['parent'], $relational)) { $unset[] = $k; $relational[$i['parent']]['children'][$k] =& $relational[$k]; } } $relational = $relational; foreach ($unset as $u) { unset($relational[$u]); } return self::findkey($relational, $parent); }
static function BuildJavascript() { $textarr = self::$includeText; foreach (self::$includeFiles as $info) { if (!file_exists($info['path'])) { continue; } $textarr[] = array('text' => file_get_contents($info['path']), 'order' => $info['order']); } array_sort_subkey($textarr, 'order'); $body = self::GetJavascriptConstants(); foreach ($textarr as $info) { $body .= $info['text'] . ';' . PHP_EOL; } return $body; }