static function remove_metadata_field() { $migrated = modOpts::GetOption('metadata_migrated'); if ($migrated) { return; } try { $obj = utopia::GetInstance('uWidgets', false); $obj->BypassSecurity(true); $ds = database::query('SELECT * FROM tabledef_Widgets WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uCustomWidget')); while ($row = $ds->fetch()) { $pk = $row['widget_id']; $meta = utopia::jsonTryDecode($row['__metadata']); foreach ($meta as $field => $val) { $obj->UpdateField($field, $val, $pk); } } $obj->BypassSecurity(false); $ds = database::query('UPDATE tabledef_Widgets SET `__metadata` = NULL WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uCustomWidget')); } catch (Exception $e) { } try { $obj = utopia::GetInstance('uWidgets', false); $obj->BypassSecurity(true); $ds = database::query('SELECT * FROM tabledef_Widgets WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uTextWidget')); while ($row = $ds->fetch()) { $pk = $row['widget_id']; $meta = utopia::jsonTryDecode($row['__metadata']); foreach ($meta as $field => $val) { $obj->UpdateField($field, $val, $pk); } } $obj->BypassSecurity(false); $ds = database::query('UPDATE tabledef_Widgets SET `__metadata` = NULL WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uTextWidget')); } catch (Exception $e) { } try { $obj = utopia::GetInstance('uWidgets', false); $obj->BypassSecurity(true); $ds = database::query('SELECT * FROM tabledef_Widgets WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uTwitterWidget')); while ($row = $ds->fetch()) { $pk = $row['widget_id']; $meta = utopia::jsonTryDecode($row['__metadata']); foreach ($meta as $field => $val) { $obj->UpdateField($field, $val, $pk); } } $obj->BypassSecurity(false); $ds = database::query('UPDATE tabledef_Widgets SET `__metadata` = NULL WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uTwitterWidget')); } catch (Exception $e) { } $ds = database::query('SHOW TABLES'); while ($t = $ds->fetch(PDO::FETCH_NUM)) { try { database::query('ALTER TABLE ' . $t[0] . ' DROP `__metadata`'); } catch (Exception $e) { } } modOpts::SetOption('metadata_migrated', true); }
public static function GetUserRole() { uUserLogin::TryLogin(); if (!isset($_SESSION['current_user'])) { return FALSE; } if (!self::$roleCache) { $obj = utopia::GetInstance('uUsersList'); $obj->BypassSecurity(true); $user = $obj->LookupRecord(array('user_id' => $_SESSION['current_user']), true); $obj->BypassSecurity(false); if ($user['_roles_pk'] === NULL) { return FALSE; } $obj = utopia::GetInstance('uUserRoles'); $obj->BypassSecurity(true); $role = $obj->LookupRecord($user['_roles_pk'], true); // clear fixed filters $obj->BypassSecurity(false); self::$roleCache = array($role['role_id'], utopia::jsonTryDecode($role['allow'])); } return self::$roleCache; }
static function DrawInput($fieldName, $inputType, $defaultValue = '', $possibleValues = NULL, $attributes = NULL, $noSubmit = FALSE) { $out = ''; if ($attributes === NULL) { $attributes = array(); } // $defaultValue = str_replace(DEFAULT_CURRENCY_HTML,DEFAULT_CURRENCY,$defaultValue); // $defaultValue = str_replace(DEFAULT_CURRENCY,DEFAULT_CURRENCY_HTML,$defaultValue); // if (!isset($attributes['id'])) $attributes['id'] = $fieldName; // if(!isset($attributes['name']) && !$noSubmit) $attributes['name'] = $fieldName; $attributes['name'] = $fieldName; if (isset($attributes['class'])) { $attributes['class'] .= ' inputtype inputtype-' . $inputType; } else { $attributes['class'] = 'inputtype inputtype-' . $inputType; } $defaultValue = utopia::jsonTryDecode($defaultValue); $attr = BuildAttrString($attributes); if (isset(self::$customInputs[$inputType])) { return call_user_func_array(self::$customInputs[$inputType], array($fieldName, $inputType, $defaultValue, $possibleValues, $attributes, $noSubmit)); } switch ($inputType) { case itNONE: $out .= $defaultValue; break; case itBUTTON: if (isset($attributes['class'])) { $attributes['class'] .= ' btn'; } else { $attributes['class'] = 'btn'; } $attributes['class'] .= ' btn-' . $inputType; $attributes['class'] = str_replace('inputtype ', '', $attributes['class']); $attr = BuildAttrString($attributes); $out .= '<button' . $attr . '>' . $defaultValue . '</button>'; break; case itSUBMIT: if (isset($attributes['class'])) { $attributes['class'] .= ' btn'; } else { $attributes['class'] = 'btn'; } $attributes['class'] .= ' btn-' . $inputType; $attributes['class'] = str_replace('inputtype ', '', $attributes['class']); $attr = BuildAttrString($attributes); $out .= '<input' . $attr . ' type="submit" value="' . $defaultValue . '"/>'; break; case itRESET: if (isset($attributes['class'])) { $attributes['class'] .= ' btn'; } else { $attributes['class'] = 'btn'; } $attributes['class'] .= ' btn-' . $inputType; $attributes['class'] = str_replace('inputtype ', '', $attributes['class']); $attr = BuildAttrString($attributes); $out .= '<input' . $attr . ' type="reset" value="' . $defaultValue . '"/>'; break; case itCHECKBOX: if (is_array($possibleValues)) { $at = array(); if (isset($attributes['styles'])) { $at['styles'] = $attributes['styles']; } $at = BuildAttrString($at); if (!preg_match('/^usql\\-/', $fieldName)) { $attributes['name'] = $attributes['name'] . '[]'; $attr = BuildAttrString($attributes); } $out .= '<span' . $at . ' class="inputtype inputtype-checkboxlist">'; foreach ($possibleValues as $key => $val) { $checked = (string) $key === $defaultValue || is_array($defaultValue) && in_array($key, $defaultValue) ? ' checked="checked"' : ''; $val = htmlentities($val, ENT_COMPAT, CHARSET_ENCODING); $out .= "<label><input{$attr} type=\"checkbox\"{$checked} value=\"{$key}\"/>{$val}</label>"; } $out .= '</span>'; } else { $checked = $defaultValue == 1 ? ' checked="checked"' : ''; $out .= "<input{$attr} type=\"checkbox\"{$checked} value=\"1\"/>"; } break; case itOPTION: if (!is_array($possibleValues)) { ErrorLog('Option field specified but no possible values found'); return ''; } $count = 0; $defaultExists = false; foreach ($possibleValues as $key => $val) { $count++; $attributes['id'] = "{$fieldName}-{$count}"; $attr = BuildAttrString($attributes); $checked = $key == $defaultValue || is_array($defaultValue) && in_array($key, $defaultValue) ? ' checked="checked"' : ''; if ($checked != '') { $defaultExists = true; } $out .= "<input type=\"radio\" {$attr} value=\"{$key}\"{$checked}/>{$val}<br/>"; } if (!$defaultExists && $defaultValue != '') { $out .= "<input type=\"radio\" {$attr} value=\"{$val}\" checked=\"true\">{$defaultValue}"; } break; case itPASSWORD: case itPLAINPASSWORD: $out .= "<input type=\"password\" {$attr} value=\"\"/>"; break; case itTEXT: $defaultValue = str_replace('"', '"', $defaultValue); $out .= "<input type=\"text\" {$attr} value=\"{$defaultValue}\"/>"; break; case itTEXTAREA: //sanitise value. if (!utopia::SanitiseValue($defaultValue, 'string') && !utopia::SanitiseValue($defaultValue, 'NULL')) { $defaultValue = 'Value has been sanitised: ' . var_export($defaultValue, true); } $defaultValue = htmlentities($defaultValue, ENT_COMPAT, CHARSET_ENCODING); $out .= "<textarea {$attr}>{$defaultValue}</textarea>"; break; case itCOMBO: if (empty($possibleValues)) { $possibleValues = array(); } $out .= "<select {$attr}>"; if (!isset($possibleValues[''])) { // blank value does not exist. if (isset($attributes['placeholder']) && $attributes['placeholder'] && !isset($possibleValues[$attributes['placeholder']])) { $blankVal = $attributes['placeholder']; } else { $blankVal = ' '; } $possibleValues = array('' => $blankVal) + $possibleValues; } else { // blank value exists, ensure it is at the top. $v = $possibleValues['']; unset($possibleValues['']); $possibleValues = array('' => $v) + $possibleValues; } $defaultExists = false; if (is_array($possibleValues)) { foreach ($possibleValues as $key => $val) { if ($val === false) { continue; } $selected = ''; if ($defaultValue !== '' && (is_array($defaultValue) && in_array($key, $defaultValue) || (string) $key === (string) $defaultValue)) { $defaultExists = true; $selected = ' selected="selected"'; } $valOutput = $key !== $val ? " value=\"{$key}\"" : ''; $out .= "<option{$valOutput}{$selected}>{$val}</option>"; } } if (!$defaultExists && $defaultValue) { $out .= "<optgroup label=\"No longer available\"><option selected=\"selected\">{$defaultValue}</option></optgroup>"; } $out .= "</select>"; break; case itLISTBOX: if (!is_array($possibleValues)) { ErrorLog('Listbox field specified but no possible values found'); return ''; } $out .= "<select size=5 {$attr}><option value=\"\"></option>"; foreach ($possibleValues as $name => $val) { if (empty($val)) { continue; } $selected = $val == $defaultValue || is_array($defaultValue) && in_array($val, $defaultValue) ? ' selected="selected"' : ''; $out .= "<option value=\"{$val}\"{$selected}>{$name}</option>"; } $out .= "</select>"; break; case itFILE: //$defaultValue = htmlentities($defaultValue,ENT_QUOTES,CHARSET_ENCODING); //$defaultValue = htmlentities($defaultValue); $out .= "<input type=\"file\" {$attr}/>"; break; case itDATE: //$formattedVal = ($defaultValue === SQL_FORMAT_EMPTY_TIMESTAMP) || ($defaultValue === SQL_FORMAT_EMPTY_DATE) || ($defaultValue === NULL) || ($defaultValue === '') ? '' : $defaultValue;//date('d/m/Y',strptime($defaultValue,'d/m/Y')); $formattedVal = $defaultValue; $out .= "<input type=\"text\" {$attr} value=\"{$formattedVal}\"/>"; break; default: $defaultValue = str_replace('"', '"', $defaultValue); $out .= "<input type=\"{$inputType}\" {$attr} value=\"{$defaultValue}\"/>"; break; } return $out; }
static function DrawData($rec) { if (!$rec['module'] || !class_exists($rec['module'])) { return $rec['no_rows']; } if (!($instance = utopia::GetInstance($rec['module'], false))) { return 'Could not load Data Source'; } $instance->_SetupParents(); $instance->_SetupFields(); // clear filters $rec['clear_filter'] = (array) utopia::jsonTryDecode($rec['clear_filter']); foreach ($rec['clear_filter'] as $uid) { $instance->RemoveFilter($uid); } // add filters utopia::MergeVars($rec['filter']); if ($rec['filter']) { $instance->AddFilter($rec['filter'], ctCUSTOM); } // add Order utopia::MergeVars($rec['order']); if ($rec['order']) { $instance->ordering = NULL; $instance->AddOrderBy($rec['order']); } $dataset = $instance->GetDataset(); // init limit utopia::MergeVars($rec['limit']); $rec['limit'] = trim($rec['limit']); $instance->GetLimit($limit, $page); // page is governed by a different query arg for widgets, below $page = stripos($rec['content'], '{pagination}') !== FALSE && isset($_GET['_p_' . $rec['block_id']]) ? $_GET['_p_' . $rec['block_id']] : 0; $offset = $limit * $page; if ($rec['limit']) { if (strpos($rec['limit'], ',') === FALSE) { $limit = $rec['limit']; $offset = $limit * $page; } else { list($offset, $limit) = explode(',', $rec['limit']); $offset = trim($offset); $limit = trim($limit); } } if (!($total = $dataset->CountRecords())) { return $rec['no_rows']; } // get rows if ($offset > $total) { return $rec['no_rows']; } // get content $content = $append = $prepend = ''; $html = str_get_html($rec['content'], true, true, DEFAULT_TARGET_CHARSET, false); $ele = ''; if ($html) { $ele = $html->find('._ri', 0); if ($ele) { $ele = $ele->innertext; } else { $ele = $html->find('._r', 0); if ($ele) { $ele = $ele->outertext; } else { $ele = ''; } } } else { $html = $rec['content']; } $repeatable = $html; if ($ele) { // found a repeatable element // split content at this element. prepare for apend and prepend. list($append, $prepend) = explode($ele, $repeatable); $repeatable = $ele; } $dataset->GetOffset($offset, $limit); while ($row = $dataset->fetch()) { $c = $repeatable; $instance->MergeFields($c, $row); $content .= $c; } $ret = $append . $content . $prepend; // process full doc $ret = str_ireplace('{total}', $total, $ret); if ($page !== NULL && is_numeric($limit)) { $pages = max(ceil($total / $limit), 1); ob_start(); $cPage = utopia::OutputPagination($pages, '_p_' . $rec['block_id']); $ret = str_ireplace('{pagination}', ob_get_clean(), $ret); $ret = str_ireplace('{pages}', $pages, $ret); $ret = str_ireplace('{current_page}', $cPage, $ret); } while (utopia::MergeVars($ret)) { } return $ret; }
public static function getEditor($id = '') { $thisObj = utopia::GetInstance(__CLASS__); $canEdit = uEvents::TriggerEvent('CanAccessModule', $thisObj) !== FALSE; // get content $rec = uCMS_View::findPage(); if (!$rec) { return; } // page not found $content = $rec['content_published']; if ($rec['content_time'] == 0) { $content = $rec['content']; } if ($canEdit && (isset($_GET['edit']) || isset($_GET['preview']))) { $content = $rec['content']; } $content = utopia::jsonTryDecode($content); if (!is_array($content)) { $content = array('' => $content); } if (!isset($content[$id])) { $content[$id] = ''; } if ($canEdit && isset($_GET['edit'])) { $rec['content:' . $id] = $content[$id]; return $thisObj->GetCell('content:' . $id, $rec); } $content = $content[$id]; $content = $thisObj->PreProcess('content', $content, $rec); utopia::MergeVars($content); return $content; }