public function read($id = false) { $data = array(); $q = ""; if (!empty($id)) { $q = "WHERE `id`={$id}"; } $start = isset($_GET['start']) ? $_GET['start'] : 0; $limit = isset($_GET['limit']) ? $_GET['limit'] : 10; $query = "SELECT * FROM `blog` {$q} ORDER BY `last_update` DESC LIMIT {$start},{$limit}"; $result = $this->db->query($query); $nbrows = $this->db->fetchRow($this->db->query("SELECT COUNT(*) FROM `blog`")); $nbrows = $nbrows[0]; while ($row = $this->db->fetchAssoc($result)) { $data[] = $row; } if (MyHelpers::isAjax()) { // prepare the metadata $ret['metaData'] = $this->makeMetaData($result); $ret['total'] = $nbrows; $ret['data'] = $this->Char2Utf8($data); $ret['success'] = true; $ret['message'] = true; return json_encode($ret); } return $data; }
/** * Display Template */ public function render() { // extract the variables for view pages extract($this->_variables); // the view path $path = MyHelpers::UrlContent('~/views/'); // start buffering ob_start(); // render page content if (empty($this->viewPath)) { include $path . $this->_controller . DS . $this->_action . '.php'; } else { include $this->viewPath; } // get the body contents $this->_bodyContent = ob_get_contents(); // clean the buffer ob_end_clean(); // check if we have any layout defined if (!empty($this->layout) && !MyHelpers::isAjax()) { // we need to check the path contains app prefix (~) $this->layout = MyHelpers::UrlContent($this->layout); // start buffer (minify pages) ob_start('MyHelpers::minify_content'); // include the template include $this->layout; } else { ob_start('MyHelpers::minify_content_js'); // just output the content echo $this->_bodyContent; } // end buffer ob_end_flush(); }
public function index() { $data = $this->_model->read(); if (MyHelpers::isAjax()) { header('Content-type: application/json'); echo $data; } else { $this->view->set('items', $data); return $this->view(); } }
/** * unknownAction */ public function unknownAction($params = array()) { // feed 404 header to the client header("HTTP/1.0 404 Not Found"); // find custom 404 page $path = MyHelpers::UrlContent("~/views/shared/_404.php"); // if we have custom 404 page, then use it if (file_exists($path)) { $this->view->viewPath = $path; return $this->view(); } else { exit; //Do not do any more work in this script. } }
protected function ResetCounters() { if (self::$m_bEnabled_Duration) { $this->m_fStarted = MyHelpers::getmicrotime(); } if (self::$m_bEnabled_Memory) { $this->m_iInitialMemory = self::memory_get_usage(); } }
public function __toString() { return MyHelpers::beautifulstr($this->m_data, 100, true); }
protected static function show_list($oObjectSet) { $oObjectSet->Rewind(); $aData = array(); while ($oItem = $oObjectSet->Fetch()) { $aValues = array(); foreach (MetaModel::GetAttributesList(get_class($oItem)) as $sAttCode) { $aValues[$sAttCode] = $oItem->GetAsHTML($sAttCode); } //echo $oItem->GetKey()." => ".implode(", ", $aValues)."</br>\n"; $aData[] = $aValues; } echo MyHelpers::make_table_from_assoc_array($aData); }
public function AddCondition($sFilterCode, $value, $sOpCode = null) { MyHelpers::CheckKeyInArray('filter code in class: ' . $this->GetClass(), $sFilterCode, MetaModel::GetClassFilterDefs($this->GetClass())); $oFilterDef = MetaModel::GetClassFilterDef($this->GetClass(), $sFilterCode); $oField = new FieldExpression($sFilterCode, $this->GetClassAlias()); if (empty($sOpCode)) { if ($sFilterCode == 'id') { $sOpCode = '='; } else { $oAttDef = MetaModel::GetAttributeDef($this->GetClass(), $sFilterCode); $oNewCondition = $oAttDef->GetSmartConditionExpression($value, $oField, $this->m_aParams); $this->AddConditionExpression($oNewCondition); return; } } MyHelpers::CheckKeyInArray('operator', $sOpCode, $oFilterDef->GetOperators()); // Preserve backward compatibility - quick n'dirty way to change that API semantic // switch ($sOpCode) { case 'SameDay': case 'SameMonth': case 'SameYear': case 'Today': case '>|': case '<|': case '=|': throw new CoreException('Deprecated operator, please consider using OQL (SQL) expressions like "(TO_DAYS(NOW()) - TO_DAYS(x)) AS AgeDays"', array('operator' => $sOpCode)); break; case "IN": if (!is_array($value)) { $value = array($value); } $sListExpr = '(' . implode(', ', CMDBSource::Quote($value)) . ')'; $sOQLCondition = $oField->Render() . " IN {$sListExpr}"; break; case "NOTIN": if (!is_array($value)) { $value = array($value); } $sListExpr = '(' . implode(', ', CMDBSource::Quote($value)) . ')'; $sOQLCondition = $oField->Render() . " NOT IN {$sListExpr}"; break; case 'Contains': $this->m_aParams[$sFilterCode] = "%{$value}%"; $sOperator = 'LIKE'; break; case 'Begins with': $this->m_aParams[$sFilterCode] = "{$value}%"; $sOperator = 'LIKE'; break; case 'Finishes with': $this->m_aParams[$sFilterCode] = "%{$value}"; $sOperator = 'LIKE'; break; default: $this->m_aParams[$sFilterCode] = $value; $sOperator = $sOpCode; } switch ($sOpCode) { case "IN": case "NOTIN": $oNewCondition = Expression::FromOQL($sOQLCondition); break; case 'Contains': case 'Begins with': case 'Finishes with': default: $oRightExpr = new VariableExpression($sFilterCode); $oNewCondition = new BinaryExpression($oField, $sOperator, $oRightExpr); } $this->AddConditionExpression($oNewCondition); }
?> </div> <!-- Footer --> <div id="footer"> <div class="content"> <div class="col"> <h2>Footer 1</h2> <?php include MyHelpers::UrlContent('~/views/shared/_text1Part.php'); ?> </div> <div class="col"> <h2>Footer 2</h2> <div class="contact"> <?php include MyHelpers::UrlContent('~/views/shared/_text1Part.php'); ?> </div> </div> </div> <div class="content"> <div id='copyright'> <p> <span> Copyright © <script type='text/javascript'> var creditsyear = new Date();document.write(creditsyear.getFullYear()); </script> <a href='<?php echo $cfg['site']['address']; ?>
/** * Designed as an action to be called when a stop watch threshold times out * or from within the framework */ public function ApplyStimulus($sStimulusCode, $bDoNotWrite = false) { $sStateAttCode = MetaModel::GetStateAttributeCode(get_class($this)); if (empty($sStateAttCode)) { return false; } MyHelpers::CheckKeyInArray('object lifecycle stimulus', $sStimulusCode, MetaModel::EnumStimuli(get_class($this))); $aStateTransitions = $this->EnumTransitions(); if (!array_key_exists($sStimulusCode, $aStateTransitions)) { // This simulus has no effect in the current state... do nothing return; } $aTransitionDef = $aStateTransitions[$sStimulusCode]; // Change the state before proceeding to the actions, this is necessary because an action might // trigger another stimuli (alternative: push the stimuli into a queue) $sPreviousState = $this->Get($sStateAttCode); $sNewState = $aTransitionDef['target_state']; $this->Set($sStateAttCode, $sNewState); // $aTransitionDef is an // array('target_state'=>..., 'actions'=>array of handlers procs, 'user_restriction'=>TBD $bSuccess = true; foreach ($aTransitionDef['actions'] as $sActionHandler) { // std PHP spec $aActionCallSpec = array($this, $sActionHandler); if (!is_callable($aActionCallSpec)) { throw new CoreException("Unable to call action: " . get_class($this) . "::{$sActionHandler}"); return; } $bRet = call_user_func($aActionCallSpec, $sStimulusCode); // if one call fails, the whole is considered as failed if (!$bRet) { $bSuccess = false; } } if ($bSuccess) { $sClass = get_class($this); // Stop watches foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) { if ($oAttDef instanceof AttributeStopWatch) { $oSW = $this->Get($sAttCode); if (in_array($sNewState, $oAttDef->GetStates())) { $oSW->Start($this, $oAttDef); } else { $oSW->Stop($this, $oAttDef); } $this->Set($sAttCode, $oSW); } } if (!$bDoNotWrite) { $this->DBWrite(); } // Change state triggers... $sClassList = implode("', '", MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL)); $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnStateLeave AS t WHERE t.target_class IN ('{$sClassList}') AND t.state='{$sPreviousState}'")); while ($oTrigger = $oSet->Fetch()) { $oTrigger->DoActivate($this->ToArgs('this')); } $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnStateEnter AS t WHERE t.target_class IN ('{$sClassList}') AND t.state='{$sNewState}'")); while ($oTrigger = $oSet->Fetch()) { $oTrigger->DoActivate($this->ToArgs('this')); } } return $bSuccess; }
protected function DoExecScenario($aSingleScenario) { echo "<div style=\"padding: 10;\">\n"; echo "<h3 style=\"background-color: #ddddff; padding: 10;\">{$aSingleScenario['desc']}</h3>\n"; $sClass = $aSingleScenario['target_class']; $aTargetData = $aSingleScenario['target_data']; $aSourceData = $aSingleScenario['source_data']; $aTargetAttributes = array_shift($aTargetData); $aSourceAttributes = array_shift($aSourceData); if (count($aSourceData) + 1 != count($aTargetData)) { throw new Exception("Target data must contain exactly " . (count($aSourceData) + 1) . " items, found " . count($aTargetData)); } // Create the data source // $oDataSource = new SynchroDataSource(); $oDataSource->Set('name', 'Test data sync ' . time()); $oDataSource->Set('description', 'unit test - created automatically'); $oDataSource->Set('status', 'production'); $oDataSource->Set('user_id', 0); $oDataSource->Set('scope_class', $sClass); $oDataSource->Set('scope_restriction', ''); $oDataSource->Set('full_load_periodicity', $aSingleScenario['full_load_periodicity']); $oDataSource->Set('reconciliation_policy', $aSingleScenario['reconciliation_policy']); $oDataSource->Set('action_on_zero', $aSingleScenario['action_on_zero']); $oDataSource->Set('action_on_one', $aSingleScenario['action_on_one']); $oDataSource->Set('action_on_multiple', $aSingleScenario['action_on_multiple']); $oDataSource->Set('delete_policy', $aSingleScenario['delete_policy']); $oDataSource->Set('delete_policy_update', $aSingleScenario['delete_policy_update']); $oDataSource->Set('delete_policy_retention', $aSingleScenario['delete_policy_retention']); $iDataSourceId = $this->ObjectToDB($oDataSource, true); $oAttributeSet = $oDataSource->Get('attribute_list'); while ($oAttribute = $oAttributeSet->Fetch()) { if (array_key_exists($oAttribute->Get('attcode'), $aSingleScenario['attributes'])) { $aAttribInfo = $aSingleScenario['attributes'][$oAttribute->Get('attcode')]; if (array_key_exists('reconciliation_attcode', $aAttribInfo)) { $oAttribute->Set('reconciliation_attcode', $aAttribInfo['reconciliation_attcode']); } $oAttribute->Set('update', $aAttribInfo['do_update']); $oAttribute->Set('reconcile', $aAttribInfo['do_reconcile']); } else { $oAttribute->Set('update', false); $oAttribute->Set('reconcile', false); } $this->UpdateObjectInDB($oAttribute); } // Prepare list of prefixes -> make sure objects are unique with regard to the reconciliation scheme $aPrefixes = array(); // attcode => prefix foreach ($aSourceAttributes as $iDummy => $sAttCode) { $aPrefixes[$sAttCode] = ''; // init with something } foreach ($aSingleScenario['attributes'] as $sAttCode => $aAttribInfo) { if (isset($aAttribInfo['automatic_prefix']) && $aAttribInfo['automatic_prefix']) { $aPrefixes[$sAttCode] = 'TEST_' . $iDataSourceId . '_'; } } // List existing objects (to be ignored in the analysis // $oAllObjects = new DBObjectSet(new DBObjectSearch($sClass)); $aExisting = $oAllObjects->ToArray(true); $sExistingIds = implode(', ', array_keys($aExisting)); // Create the initial object list // $aInitialTarget = $aTargetData[0]; foreach ($aInitialTarget as $aObjFields) { $oNewTarget = MetaModel::NewObject($sClass); foreach ($aTargetAttributes as $iAtt => $sAttCode) { $oNewTarget->Set($sAttCode, $aPrefixes[$sAttCode] . $aObjFields[$iAtt]); } $this->ObjectToDB($oNewTarget); } foreach ($aTargetData as $iRow => $aExpectedObjects) { sleep(2); // Check the status (while ignoring existing objects) // if (empty($sExistingIds)) { $oObjects = new DBObjectSet(DBObjectSearch::FromOQL("SELECT {$sClass}")); } else { $oObjects = new DBObjectSet(DBObjectSearch::FromOQL("SELECT {$sClass} WHERE id NOT IN({$sExistingIds})")); } $aFound = $oObjects->ToArray(); $aErrors_Unexpected = array(); foreach ($aFound as $iObj => $oObj) { // Is this object in the expected objects list $bFoundMatch = false; foreach ($aExpectedObjects as $iExp => $aValues) { $bDoesMatch = true; foreach ($aTargetAttributes as $iCol => $sAttCode) { if ($oObj->Get($sAttCode) != $aPrefixes[$sAttCode] . $aValues[$iCol]) { $bDoesMatch = false; break; } } if ($bDoesMatch) { $bFoundMatch = true; unset($aExpectedObjects[$iExp]); break; } } if (!$bFoundMatch) { $aErrors_Unexpected[] = $oObj->GetKey(); } } // Display the current status // echo "<p>Status at step {$iRow}</p>\n"; $aCurrentDataSet = array(); foreach ($aFound as $iObj => $oObj) { $aObjDesc = array('Status' => in_array($iObj, $aErrors_Unexpected) ? 'unexpected' : 'ok', 'Object' => $oObj->GetHyperLink()); foreach ($aTargetAttributes as $iCol => $sAttCode) { $aObjDesc[$sAttCode] = $oObj->Get($sAttCode); } $aCurrentDataSet[] = $aObjDesc; } if (count($aExpectedObjects) > 0) { foreach ($aExpectedObjects as $iExp => $aValues) { $aObjDesc = array('Status' => 'missing', 'Object' => 'n/a'); foreach ($aTargetAttributes as $iCol => $sAttCode) { $aObjDesc[$sAttCode] = $aPrefixes[$sAttCode] . $aValues[$iCol]; } $aCurrentDataSet[] = $aObjDesc; } } echo MyHelpers::make_table_from_assoc_array($aCurrentDataSet); if (count($aErrors_Unexpected) > 0 || count($aExpectedObjects) > 0) { throw new UnitTestException("The current status in iTop does not match the expectations"); } // If not on the final row, run a data exchange sequence // if (array_key_exists($iRow, $aSourceData)) { $aToBeLoaded = $aSourceData[$iRow]; $sCsvData = implode(';', $aSourceAttributes) . "\n"; foreach ($aToBeLoaded as $aDataRow) { $aFinalData = array(); foreach ($aDataRow as $iCol => $value) { if (is_null($value)) { $aFinalData[] = '<NULL>'; } else { $sAttCode = $aSourceAttributes[$iCol]; $aFinalData[] = $aPrefixes[$sAttCode] . $value; } } $sCsvData .= implode(';', $aFinalData) . "\n"; } $aPostData = array('csvdata' => $sCsvData); $aImportArgs = array('data_source_id' => $iDataSourceId, 'separator' => ';', 'simulate' => 0, 'output' => 'details'); $aGetParams = array(); $aGetParamReport = array(); foreach ($aImportArgs as $sArg => $sValue) { $aGetParams[] = $sArg . '=' . urlencode($sValue); $aGetParamReport[] = $sArg . '=' . $sValue; } $sGetParams = implode('&', $aGetParams); $sLogin = isset($aSingleScenario['login']) ? $aSingleScenario['login'] : '******'; $sPassword = isset($aSingleScenario['password']) ? $aSingleScenario['password'] : '******'; $sRes = self::DoPostRequestAuth('../synchro/synchro_import.php?' . $sGetParams, $aPostData, $sLogin, $sPassword); // Report the load results // if (strlen($sCsvData) > 5000) { $sCsvDataViewable = 'INPUT TOO LONG TO BE DISPLAYED (' . strlen($sCsvData) . ")\n" . substr($sCsvData, 0, 500) . "\n... TO BE CONTINUED"; } else { $sCsvDataViewable = $sCsvData; } $sCsvDataViewable = htmlentities($sCsvDataViewable, ENT_QUOTES, 'UTF-8'); echo "<div style=\"\">\n"; echo " <pre class=\"vardump\">{$sCsvDataViewable}</pre>\n"; echo "</div>\n"; echo "<pre class=\"vardump\" style=\"clear: both; padding: 15; background-color: black; color: green;\">{$sRes}</pre>\n"; if (stripos($sRes, 'exception') !== false) { throw new UnitTestException('Encountered an Exception during the last import/synchro'); } } } return; echo "</div>\n"; }
} // if we cannot find any, then find library/mvc directory if (!$valid) { $valid = file_exists($classFile = $rootPath . 'library' . DS . 'mvc' . DS . $className . '.class.php'); } // if we cannot find any, then find application/controllers directory if (!$valid) { $valid = file_exists($classFile = $rootPath . 'application' . DS . 'controllers' . DS . $className . '.php'); } // if we cannot find any, then find application/models directory if (!$valid) { $valid = file_exists($classFile = $rootPath . 'application' . DS . 'models' . DS . $className . '.php'); } // if we have valid fild, then include it if ($valid) { require_once $classFile; } else { /* Error Generation Code Here */ } }); // remove the magic quotes MyHelpers::removeMagicQuotes(); // unregister globals MyHelpers::unregisterGlobals(); // register route $router = new Router($_route); // finaly we dispatch the output $router->dispatch(); // close session to speed up the concurrent connections // http://php.net/manual/en/function.session-write-close.php session_write_close();
public function AddCondition_RelatedTo(DBObjectSearch $oFilter, $sRelCode, $iMaxDepth) { MyHelpers::CheckValueInArray('relation code', $sRelCode, MetaModel::EnumRelations()); $this->m_aRelatedTo[] = array('flt' => $oFilter, 'relcode' => $sRelCode, 'maxdepth' => $iMaxDepth); }
protected function CreateObject($sClass, $aData, $sClassDesc = '') { $mu_t1 = MyHelpers::getmicrotime(); $oMyObject = MetaModel::NewObject($sClass); foreach ($aData as $sProp => $value) { if (is_array($value)) { // transform into a link set $sCSVSpec = implode('|', $value); $oAttDef = MetaModel::GetAttributeDef($sClass, $sProp); $value = $oAttDef->MakeValueFromString($sCSVSpec, $bLocalizedValue = false, $sSepItem = '|', $sSepAttribute = ';', $sSepValue = ':', $sAttributeQualifier = '"'); } $oMyObject->Set($sProp, $value); } $iId = $oMyObject->DBInsertTrackedNoReload($this->m_oChange, true); $sClassId = "{$sClass} ({$sClassDesc})"; $this->m_aCreatedByDesc[$sClassId][] = $iId; $this->m_aCreatedByClass[$sClass][] = $iId; $mu_t2 = MyHelpers::getmicrotime(); $this->m_aStatsByClass[$sClass][] = $mu_t2 - $mu_t1; return $iId; }
/** * Minify output css content */ public static function minify_content_css($content) { $filename = self::UrlContent('~/library/min/lib/Minify/CSS.php', ''); if (!MyHelpers::isLocalhost() && file_exists($filename)) { require_once $filename; $content = Minify_CSS::minify($content); } return $content; }
public static function Dump() { MyHelpers::var_dump_html(self::$m_aData); }
public function Exec() { if ($this->sSql != '') { $iRepeat = utils::ReadParam('repeat', 3); try { $fRefTime = MyHelpers::getmicrotime(); for ($i = 0; $i < $iRepeat; $i++) { $resQuery = CMDBSource::Query($this->sSql); } $this->fExecDuration = (MyHelpers::getmicrotime() - $fRefTime) / $iRepeat; // This is not relevant... if (preg_match_all('|\\s*JOIN\\s*\\(\\s*`|', $this->sSql, $aMatches)) { $this->iTableCount = 1 + count($aMatches[0]); } else { $this->iTableCount = 1; } } catch (Exception $e) { $this->aErrors[] = "Failed to execute the SQL:" . $e->getMessage(); $resQuery = null; } if ($resQuery) { while ($aRow = CMDBSource::FetchArray($resQuery)) { $this->aRows[] = $aRow; } CMDBSource::FreeResult($resQuery); } } }
/** * @param hash $aOrderBy Array of '[<classalias>.]attcode' => bAscending */ public function MakeSelectQuery($aOrderBy = array(), $aArgs = array(), $aAttToLoad = null, $aExtendedDataSpec = null, $iLimitCount = 0, $iLimitStart = 0, $bGetCount = false) { // Check the order by specification, and prefix with the class alias // and make sure that the ordering columns are going to be selected // $sClass = $this->GetClass(); $sClassAlias = $this->GetClassAlias(); $aOrderSpec = array(); foreach ($aOrderBy as $sFieldAlias => $bAscending) { if (!is_bool($bAscending)) { throw new CoreException("Wrong direction in ORDER BY spec, found '{$bAscending}' and expecting a boolean value"); } $iDotPos = strpos($sFieldAlias, '.'); if ($iDotPos === false) { $sAttClass = $sClass; $sAttClassAlias = $sClassAlias; $sAttCode = $sFieldAlias; } else { $sAttClassAlias = substr($sFieldAlias, 0, $iDotPos); $sAttClass = $this->GetClassName($sAttClassAlias); $sAttCode = substr($sFieldAlias, $iDotPos + 1); } if ($sAttCode != 'id') { MyHelpers::CheckValueInArray('field name in ORDER BY spec', $sAttCode, MetaModel::GetAttributesList($sAttClass)); $oAttDef = MetaModel::GetAttributeDef($sAttClass, $sAttCode); foreach ($oAttDef->GetOrderBySQLExpressions($sAttClassAlias) as $sSQLExpression) { $aOrderSpec[$sSQLExpression] = $bAscending; } } else { $aOrderSpec['`' . $sAttClassAlias . $sAttCode . '`'] = $bAscending; } // Make sure that the columns used for sorting are present in the loaded columns if (!is_null($aAttToLoad) && !isset($aAttToLoad[$sAttClassAlias][$sAttCode])) { $aAttToLoad[$sAttClassAlias][$sAttCode] = MetaModel::GetAttributeDef($sAttClass, $sAttCode); } } $oSQLQuery = $this->GetSQLQuery($aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, $iLimitCount, $iLimitStart, $bGetCount); $aScalarArgs = array_merge(MetaModel::PrepareQueryArguments($aArgs), $this->GetInternalParams()); try { $bBeautifulSQL = self::$m_bTraceQueries || self::$m_bDebugQuery || self::$m_bIndentQueries; $sRes = $oSQLQuery->RenderSelect($aOrderSpec, $aScalarArgs, $iLimitCount, $iLimitStart, $bGetCount, $bBeautifulSQL); if ($sClassAlias == '_itop_') { IssueLog::Info('SQL Query (_itop_): ' . $sRes); } } catch (MissingQueryArgument $e) { // Add some information... $e->addInfo('OQL', $this->ToOQL()); throw $e; } $this->AddQueryTraceSelect($aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, $iLimitCount, $iLimitStart, $bGetCount, $sRes); return $sRes; }
public function getTraceAsHtml() { $aBackTrace = $this->getTrace(); return MyHelpers::get_callstack_html(0, $this->getTrace()); // return "<pre>\n".$this->getTraceAsString()."</pre>\n"; }
<?php if (!MyHelpers::isAjax()) { $this->layout = '~/views/shared/_defaultLayout.php'; if (isset($_GET['extjs']) && $_GET['extjs'] == true) { $this->section['head'] = "\n\t\t<!-- Sencha ExtJs 4.2.2 perm link -->\n\t\t<script src='http://docs.sencha.com/extjs/4.2.2/extjs-build/examples/shared/include-ext.js'></script>\n\t\t<link href='http://docs.sencha.com/extjs/4.2.2/extjs-build/examples/feed-viewer/Feed-Viewer.css' rel='stylesheet' type='text/css'/>\n\t\t<script>\n Ext.Loader.setConfig({enabled: true});\n Ext.Loader.setPath('Ext.ux', 'http://docs.sencha.com/extjs/4.2.2/extjs-build/examples/ux');\n Ext.require([\n 'Ext.ux.PreviewPlugin'\n ]);\n\t\t// Start loading the page \n\t\tExt.onReady(function(){\n\t\t\tExt.create('Ext.data.JsonStore', {\n\t\t\t storeId:'blogStore',\n\t\t\t autoLoad:true,\n\t\t\t\tproxy: {\n\t\t\t\t type: 'ajax',\n\t\t\t\t url: '/mvc/blog', // our data link\n\t\t\t\t reader: {\n\t\t\t\t type: 'json'\n\t\t\t\t }\n\t\t\t\t }\n\t\t\t});\n\t\t\t\n\t\t\tExt.create('Ext.grid.Panel', {\n\t\t\t title: 'Blog Posts',\n\t\t\t store: Ext.data.StoreManager.lookup('blogStore'),\n\t viewConfig: {\n\t itemId: 'view',\n\t plugins: [{\n\t pluginId: 'preview',\n\t ptype: 'preview',\n\t bodyField: 'content',\n\t expanded: true\n\t }]\n\t },\n\t\t\t columns: [\n\t\t\t { text: 'ID', dataIndex: 'id' },\n\t\t\t { text: 'Title', dataIndex: 'title', flex: 1, renderer: this.formatTitle},\n\t\t\t { text: 'Author', dataIndex: 'author', hidden: true, width: 200},\n\t\t\t { text: 'Last Update', dataIndex: 'last_update', renderer: this.formatDate, width: 200}\n\t\t\t ],\n\t\t\t dockedItems: [{\n\t\t\t xtype: 'pagingtoolbar',\n\t\t\t store: Ext.data.StoreManager.lookup('blogStore'), // same store GridPanel is using\n\t\t\t dock: 'bottom',\n\t\t\t displayInfo: true\n\t\t\t }],\n\t\t\t formatTitle: function(value, p, record){\n\t\t\t return Ext.String.format('<div class=\"topic\"><b>{0}</b><span class=\"author\">{1}</span></div>', value, record.get('author') || \"Unknown\");\n\t\t\t },\n\t\t\t formatDate: function(date){\n\t\t\t if (!date) {\n\t\t\t return '';\n\t\t\t }\n\t\t\t\n\t\t\t var now = new Date(), d = Ext.Date.clearTime(now, true), notime = Ext.Date.clearTime(date, true).getTime();\n\t\t\t\n\t\t\t if (notime === d.getTime()) {\n\t\t\t return 'Today ' + Ext.Date.format(date, 'g:i a');\n\t\t\t }\n\t\t\t\n\t\t\t d = Ext.Date.add(d, 'd', -6);\n\t\t\t if (d.getTime() <= notime) {\n\t\t\t return Ext.Date.format(date, 'D g:i a');\n\t\t\t }\n\t\t\t return Ext.Date.format(date, 'Y/m/d g:i a');\n\t\t\t },\n\t\t\t renderTo: 'bloglist'\n\t\t\t});\t\n\t\t});\t\t\n\t\t</script>\n"; } if (isset($_GET['extjs']) && $_GET['extjs'] == true) { ?> <div class="block bgWhite"> <div class="content"><div id='bloglist'></div></div> </div> <?php } else { ?> <div class="block bgWhite"> <div class="content"> <img src="http://catalizt.com/wp-content/uploads/2013/07/blog-banner.jpg" width="990" alt="" /> </div> <div class="content"> <?php foreach ($items as $item) { ?> <a href="./blog/detail/<?php echo $item['id']; ?> "> <h1 style="font-size: 20px; font-weight: bold; margin-bottom:5px;"><?php echo $item['title']; ?> </h1>
public static function debug_breakpoint_notempty($arg) { if (empty($arg)) { return; } echo "<H1> Debug breakpoint (triggered on non-empty value) </H1>\n"; MyHelpers::var_dump_html($arg); MyHelpers::dump_callstack(); exit; }
/** * Displays a blob document *inline* (if possible, depending on the type of the document) * @return string */ public function DisplayDocumentInline(WebPage $oPage, $sAttCode) { $oDoc = $this->Get($sAttCode); $sClass = get_class($this); $Id = $this->GetKey(); switch ($oDoc->GetMainMimeType()) { case 'text': case 'html': $data = $oDoc->GetData(); switch ($oDoc->GetMimeType()) { case 'text/html': case 'text/xml': $oPage->add("<iframe id='preview_{$sAttCode}' src=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/ajax.render.php?operation=display_document&class={$sClass}&id={$Id}&field={$sAttCode}\" width=\"100%\" height=\"400\">Loading...</iframe>\n"); break; default: $oPage->add("<pre>" . htmlentities(MyHelpers::beautifulstr($data, 1000, true), ENT_QUOTES, 'UTF-8') . "</pre>\n"); } break; case 'application': switch ($oDoc->GetMimeType()) { case 'application/pdf': $oPage->add("<iframe id='preview_{$sAttCode}' src=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/ajax.render.php?operation=display_document&class={$sClass}&id={$Id}&field={$sAttCode}\" width=\"100%\" height=\"400\">Loading...</iframe>\n"); break; default: $oPage->add(Dict::S('UI:Document:NoPreview')); } break; case 'image': $oPage->add("<img src=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/ajax.render.php?operation=display_document&class={$sClass}&id={$Id}&field={$sAttCode}\" />\n"); break; default: $oPage->add(Dict::S('UI:Document:NoPreview')); } }
public static function Init_SetZListItems($sListCode, $aItems, $sTargetClass = null) { MyHelpers::CheckKeyInArray('list code', $sListCode, self::$m_aListInfos); if (!$sTargetClass) { $sTargetClass = self::GetCallersPHPClass("Init"); } // Discard attributes that do not make sense // (missing classes in the current module combination, resulting in irrelevant ext key or link set) // self::Init_CheckZListItems($aItems, $sTargetClass); self::$m_aListData[$sTargetClass][$sListCode] = $aItems; }