function run(&$filter_chain, &$request, &$response) { $toolkit =& Limb :: toolkit(); $action_resolver =& $toolkit->getRequestResolver('action'); $service_resolver =& $toolkit->getRequestResolver('service'); if(!is_object($service_resolver) || !is_object($action_resolver)) return throw_error(new LimbException('request resolvers not set')); $service =& $service_resolver->resolve($request); if(!$action =& $action_resolver->resolve($request)) { $toolkit->setService($service); } elseif($service->actionExists($action)) { $service->setCurrentAction($action); $toolkit->setService($service); } else { $service404 = new Service('404'); $toolkit->setService($service404); } $filter_chain->next(); }
function run() { $this->_registerFileResolvers(); $this->_registerToolkit(); $this->_loadPackages(); $toolkit =& Limb :: toolkit(); $request =& $toolkit->getRequest(); $response =& $toolkit->getResponse(); $filter_chain = new FilterChain($request, $response); $this->_registerFilters($filter_chain); $filter_chain->process(); if(catch_error('LimbException', $e)) { Debug :: writeException($e); } elseif(catch_error('LimbException', $e)) { echo 'Unexpected PHP exception in ' . $e->getFile() . ' in line ' . $e->getLine(); echo '<br>'; echo '<pre>'; echo $e->getTraceAsString(); echo '</pre>'; echo 'Report this error to the LIMB developers, please.'; exit(); } }
function getValue() { $value = $this->base->getValue(); $locale_value = $this->_getLocale(); $toolkit =& Limb :: toolkit(); $locale =& $toolkit->getLocale($locale_value); if(isset($this->parameters[2]) && $this->parameters[2]->getValue()) $fract_digits = $this->parameters[2]->getValue(); else $fract_digits = $locale->fract_digits; if(isset($this->parameters[3]) && $this->parameters[3]->getValue()) $decimal_symbol = $this->parameters[3]->getValue(); else $decimal_symbol = $locale->decimal_symbol; if(isset($this->parameters[4]) && $this->parameters[4]->getValue()) $thousand_separator = $this->parameters[4]->getValue(); else $thousand_separator = $locale->thousand_separator; if ($this->isConstant()) return number_format($value, $fract_digits, $decimal_symbol, $thousand_separator); else RaiseError('compiler', 'UNRESOLVED_BINDING'); }
function testFetch() { $time = mktime(6, 0, 0, 3, 6, 2005); $day = 24 * 60 * 60; $toolkit =& Limb::toolkit(); $db_table =& $toolkit->createDBTable('StatsUri'); $db_table->insert(array('id' => $uri_id1 = 1, 'uri' => $uri1 = '/news')); $db_table->insert(array('id' => $uri_id2 = 2, 'uri' => $uri2 = '/articles')); $db_table =& $toolkit->createDBTable('StatsHit'); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id1, 'action' => 'any', 'time' => $time1 = $time, 'ip' => $ip = Ip::encode('192.168.0.1'))); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id1, 'action' => 'any', 'time' => $time2 = $time + $day, 'ip' => $ip)); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id1, 'action' => 'any', 'time' => $time3 = $time + $day, 'ip' => $ip)); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id2, 'action' => 'any', 'time' => $time4 = $time + 2 * $day, 'ip' => $ip)); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id1, 'action' => 'any', 'time' => $time5 = $time + 3 * $day, 'ip' => $ip)); $request =& $toolkit->getRequest(); $request->set('start_date', date('Y-m-d', $time2)); $request->set('finish_date', date('Y-m-d', $time5)); // Must find three records only $dao = new StatsPagesReportDAO(); $rs =& $dao->fetch(); $this->assertTrue(is_a($rs, 'StatsPercentageRecordSet')); $this->assertEqual($rs->getRowCount(), 2); $rs->rewind(); $record =& $rs->current(); $this->assertEqual($record->get('uri'), $uri1); $rs->next(); $record =& $rs->current(); $this->assertEqual($record->get('uri'), $uri2); }
public function getDataset(&$counter, $params = array()) { $request = Limb::toolkit()->getRequest(); $datasource = Limb::toolkit()->getDatasource('RequestedObjectDatasource'); $datasource->setRequest($request); if (!($arr = $datasource->fetch())) { return new ArrayDataset(); } $db_table = Limb::toolkit()->createDBTable('SysClass'); $classes = $db_table->getList('', 'class_name'); $result = array(); $params = array(); foreach ($classes as $class_id => $class_data) { $result[$class_id] = $class_data; $result[$class_id]['path'] = $arr['path']; $params['class_id'] = $class_id; $result[$class_id]['node_id'] = $arr['node_id']; foreach ($arr['actions'] as $action_name => $action_params) { $arr['actions'][$action_name]['extra'] = $params; } $result[$class_id]['actions'] = $arr['actions']; } $counter = sizeof($result); return new ArrayDataset($result); }
public function perform() { $request = Limb::toolkit()->getRequest(); $response = Limb::toolkit()->getResponse(); $datasource = Limb::toolkit()->getDatasource('RequestedObjectDatasource'); $datasource->setRequest($request); if (!($object_data = $datasource->fetch())) { return Limb::STATUS_ERROR; } if (!file_exists(MEDIA_DIR . $object_data['media_id'] . '.media')) { $response->header("HTTP/1.1 404 Not found"); if (!$request->hasAttribute('icon')) { return Limb::STATUS_ERROR; } $response->commit(); //for speed return; //for tests, fix!!! } if ($request->hasAttribute('icon')) { $this->_fillIconResponse($response, $request, $object_data); $response->commit(); //for speed return; //for tests, fix!!! } $response->header("Content-type: {$object_data['mime_type']}"); $response->header('Content-Disposition: attachment; filename="' . $object_data['file_name'] . '"'); $response->readfile(MEDIA_DIR . $object_data['media_id'] . '.media'); return Limb::STATUS_OK; }
function perform(&$request, &$response) { if ($request->hasAttribute('popup')) { $response->write(closePopupNoParentReloadResponse()); } $request->setStatus(Request::STATUS_FAILURE); if (!($version = $request->get('version'))) { return; } if (!($node_id = $request->get('version_node_id'))) { return; } $toolkit =& Limb::toolkit(); $datasource =& $toolkit->getDatasource('SingleObjectDatasource'); $datasource->setNodeId($node_id); if (!($site_object = wrapWithSiteObject($datasource->fetch()))) { return; } if (!is_subclass_of($site_object, 'ContentObject')) { return; } if (!$site_object->recoverVersion((int) $version)) { return; } if ($request->hasAttribute('popup')) { $response->write(closePopupResponse($request)); } $request->setStatus(Request::STATUS_SUCCESS); }
function tearDown() { $this->toolkit->tally(); $this->tree->tally(); Limb :: popToolkit(); }
function tearDown() { $this->toolkit->tally(); $this->authorizer->tally(); ClearTestingTemplates(); Limb::restoreToolkit('SimpleACL'); }
public function getDataset(&$counter, $params = array()) { $request = Limb::toolkit()->getRequest(); if (!($class_id = $request->get('class_id'))) { return new ArrayDataset(); } $db_table = Limb::toolkit()->createDBTable('SysClass'); $class_data = $db_table->getRowById($class_id); if (!$class_data) { return new ArrayDataset(); } $site_object = Limb::toolkit()->createSiteObject($class_data['ClassName']); $site_object_controller = $site_object->getController(); $actions = $site_object_controller->getActionsDefinitions(); $result = array(); foreach ($actions as $action => $action_params) { if (!isset($action_params['can_have_access_template']) || !$action_params['can_have_access_template']) { continue; } if (isset($action_params['action_name'])) { $result[$action]['action_name'] = $action_params['action_name']; } else { $result[$action]['action_name'] = str_replace('_', ' ', strtoupper($action[0]) . substr($action, 1)); } } $counter = sizeof($result); return new ArrayDataset($result); }
function tearDown() { $this->toolkit->tally(); $this->uow->tally(); Limb :: restoreToolkit(); }
public function perform() { $toolkit = Limb::toolkit(); $toolkit->getUser()->logout(); $toolkit->getResponse()->redirect('/'); return LIMB::STATUS_OK; }
public function run($filter_chain, $request, $response) { Debug::addTimingPoint('authentication filter started'); $this->initializeUser(); $toolkit = Limb::toolkit(); $datasource = $toolkit->getDatasource('RequestedObjectDatasource'); if (!($node = $datasource->mapRequestToNode($request))) { $this->process404Error($request, $response); $filter_chain->next(); return; } $behaviour = $this->getBehaviourByObjectId($node['object_id']); $controller = $this->_getController($behaviour); if (!($action = $controller->getRequestedAction())) { $this->process404Error($request, $response); $filter_chain->next(); return; } $datasource->setRequest($request); if (!($object_data = $datasource->fetch())) { $response->redirect('/root/login?redirect=' . urlencode($_SERVER['REQUEST_URI'])); return; } $authoriser = Limb::toolkit()->getAuthorizer(); $authoriser->assignActionsToObjects($object_data); if (!isset($object_data['actions']) || !isset($object_data['actions'][$action])) { $response->redirect('/root/login?redirect=' . urlencode($_SERVER['REQUEST_URI'])); return; } $filter_chain->next(); }
public function validate($dataspace) { if(!$value = $dataspace->get($this->field_name)) return; $tree = Limb :: toolkit()->getTree(); if(!$tree->isNode($this->parent_node_id)) return; if(!$nodes = $tree->getChildren($this->parent_node_id)) return; foreach($nodes as $id => $node) { if($node['identifier'] != $value) continue; if($this->node_id == self :: UNKNOWN_NODE_ID) { $this->error(Strings :: get('error_duplicate_tree_identifier', 'error')); break; } elseif($id != $this->node_id) { $this->error(Strings :: get('error_duplicate_tree_identifier', 'error')); break; } } }
function getCounterRecord() { $toolkit =& Limb :: toolkit(); $db =& new SimpleDb($toolkit->getDbConnection()); $db->select('sys_stat_counter', '*'); return $db->getRow(); }
function loadPackages() { include_once(LIMB_DIR . '/core/util/ini_support.inc.php'); $toolkit =& Limb :: toolkit(); $ini =& $toolkit->getINI('packages.ini'); $this->_packages = array(); $groups = $ini->getAll(); $packages = $ini->getOption('packages'); if (!count($packages)) return throw_error(new LimbException('no packages in package.ini!')); foreach($packages as $package_path) { $package_data = array(); include($package_path . '/setup.php'); $this->_definePackageConstant($PACKAGE_NAME, $package_path); $package_data['path'] = $package_path; $package_data['name'] = $PACKAGE_NAME; $this->_packages[] = $package_data; } }
function testFetch() { $time = mktime(6, 0, 0, 3, 6, 2005); $day = 24 * 60 * 60; $toolkit =& Limb::toolkit(); $db_table =& $toolkit->createDBTable('StatsHit'); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time1 = $time, 'ip' => $ip1 = Ip::encode('192.168.0.1'))); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time2 = $time + $day, 'ip' => $ip1)); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time3 = $time + $day, 'ip' => $ip2 = Ip::encode('192.168.0.2'))); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time4 = $time + 2 * $day, 'ip' => $ip1)); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time5 = $time + 3 * $day, 'ip' => $ip1)); $request =& $toolkit->getRequest(); $request->set('start_date', date('Y-m-d', $time2)); $request->set('finish_date', date('Y-m-d', $time4)); // Must find three records only $dao = new StatsHitsReportDAO(); $rs =& $dao->fetch(); $this->assertEqual($rs->getRowCount(), 3); $rs->rewind(); $record =& $rs->current(); $this->assertEqual($record->get('ip'), $ip1); $this->assertEqual($record->get('stats_referer_id'), 1); $this->assertEqual($record->get('session_id'), 'any'); $this->assertEqual($record->get('action'), 'any'); $this->assertEqual($record->get('time'), $time2); }
protected function check($value) { if(empty($value)) $this->error(Strings :: get('error_invalid_tree_node_id', 'error')); elseif(!Limb :: toolkit()->getTree()->getNode((int)$value)) $this->error(Strings :: get('error_invalid_tree_node_id', 'error')); }
public function fetchRequested() { $datasource = Limb :: toolkit()->getDatasource('RequestedObjectDatasource'); $request = Limb :: toolkit()->getRequest(); $datasource->setRequest($request); $this->import($datasource->fetch()); }
function perform(&$request, &$response) { $request->setStatus(Request::STATUS_SUCCESS); if ($request->hasAttribute('popup')) { $response->write(closePopupResponse($request)); } $toolkit =& Limb::toolkit(); $datasource =& $toolkit->getDatasource('RequestedObjectDatasource'); $datasource->setRequest($request); if (!($object = wrapWithSiteObject($datasource->fetch()))) { return; } $site_object_controller =& $object->getController(); $action = $site_object_controller->getAction($request); switch ($action) { case 'publish': $status = $this->getPublishStatus($object); break; case 'unpublish': $status = $this->getUnpublishStatus($object); break; default: return; break; } $object->set('status', $status); $object->update(false); $this->_applyAccessPolicy($object, $action); $datasource->flushCache(); }
function _getTotalHits() { $toolkit =& Limb::toolkit(); $dao =& $toolkit->createDAO('StatsHitsReportDAO'); $rs =& $dao->fetch(); $this->total_hits = $rs->getTotalRowCount(); }
public function renderAttributes() { $this->_processAttributes(); if (!$this->path) { $action_path = $_SERVER['PHP_SELF']; if($node_id = Limb :: toolkit()->getRequest()->get('node_id')) $action_path .= '?node_id=' . $node_id; } else $action_path = $this->path; if (strpos($action_path, '?') === false) $action_path .= '?'; else $action_path .= '&'; if($this->action) $action_path .= 'action=' . $this->action; if ((bool)$this->reload_parent) { $action_path .= '&reload_parent=1'; } $this->attributes['onclick'] = $this->onclick; $this->attributes['onclick'] .= "submitForm(this.form, '{$action_path}')"; parent :: renderAttributes(); unset($this->attributes['onclick']); }
function addUrlQueryItems($url, $items=array()) { $str_params = ''; $request = Limb :: toolkit()->getRequest(); if (($node_id = $request->get('node_id')) && !isset($items['node_id'])) $items['node_id'] = $node_id; if(strpos($url, '?') === false) $url .= '?'; foreach($items as $key => $val) { $url = preg_replace("/&*{$key}=[^&]*/", '', $url); $str_params .= "&$key=$val"; } $items = explode('#', $url); $url = $items[0]; $fragment = isset($items[1]) ? '#' . $items[1] : ''; return $url . $str_params . $fragment; }
function &_initSQL() { include_once LIMB_DIR . '/core/db/ComplexSelectSQL.class.php'; $toolkit =& Limb::toolkit(); $sql = new ComplexSelectSQL('SELECT stats_uri.uri, stats_uri.id as stats_uri_id, COUNT(stats_uri_id) as hits' . ' %fields% FROM ' . ' stats_uri, stats_hit as master' . '%tables% %left_join% ' . 'WHERE master.stats_uri_id = stats_uri.id %where% ' . 'GROUP BY uri %group%' . 'ORDER BY hits DESC %order%'); return $sql; }
function getDataset(&$counter, $params = array()) { $counter = 0; $toolkit =& Limb::toolkit(); $request =& $toolkit->getRequest(); if (!($version = $request->get('version'))) { return new EmptyDataset(); } if (!($node_id = $request->get('version_node_id'))) { return new EmptyDataset(); } $version = (int) $version; $node_id = (int) $node_id; $datasource =& $toolkit->getDatasource('SingleObjectDatasource'); $datasource->setNodeId($node_id); if (!($site_object = wrapWithSiteObject($datasource->fetch()))) { return new EmptyDataset(); } if (!is_subclass_of($site_object, 'ContentObject')) { return new EmptyDataset(); } if (($version_data = $site_object->fetchVersion($version)) === false) { return new EmptyDataset(); } $result = array(); foreach ($version_data as $attrib => $value) { $data['attribute'] = $attrib; $data['value'] = $value; $result[] = $data; } return new ArrayDataset($result); }
function StatsSearchPhraseRegisterTest() { parent::LimbTestCase(__FILE__); $toolkit =& Limb::toolkit(); $this->conn =& $toolkit->getDbConnection(); $this->db =& new SimpleDb($this->conn); }
function setUp() { $toolkit =& Limb :: toolkit(); $this->db =& new SimpleDb($toolkit->getDbConnection()); $this->_cleanUp(); }
protected function _updateLog($node_id, $action, $status_code) { $ip_register = $this->_getIpRegister(); $referer_register = $this->_getRefererRegister(); $uri_register = $this->_getUriRegister(); $this->db->sqlInsert('sys_stat_log', array('ip' => $ip_register->getClientIp(), 'time' => $this->getRegisterTimeStamp(), 'node_id' => $node_id, 'stat_referer_id' => $referer_register->getRefererPageId(), 'stat_uri_id' => $uri_register->getUriId(), 'user_id' => Limb::toolkit()->getUser()->getId(), 'session_id' => session_id(), 'action' => $action, 'status' => $status_code)); }
function setUp() { parent :: setUp(); $this->db =& DbFactory :: instance(); $tree = Limb :: toolkit()->getTree(); $values['identifier'] = 'root'; $this->node_id_root = $tree->createRootNode($values, false, true); $values['identifier'] = 'ru'; $values['object_id'] = 1; $this->node_id_ru = $tree->createSubNode($this->node_id_root, $values); $values['identifier'] = 'document'; $values['object_id'] = 10; $this->node_id_document = $tree->createSubNode($this->node_id_ru, $values); $values['identifier'] = 'doc1'; $values['object_id'] = 20; $this->node_id_doc1 = $tree->createSubNode($this->node_id_ru, $values); $values['identifier'] = 'doc2'; $values['object_id'] = 30; $this->node_id_doc2 = $tree->createSubNode($this->node_id_ru, $values); }
function _loadVariations() { $this->cached_dataset = new ArrayDataset(array()); $cached_records = array(); $ids = ''; $records = array(); for ($this->iterator->rewind(); $this->iterator->valid(); $this->iterator->next()) { $record =& $this->iterator->current(); $id = $record->get('id'); $ids .= $id . ','; $cached_records[$id] =& $record->export(); } if (!$cached_records) { return; } $ids = rtrim($ids, ','); $sql = "SELECT\n iv.id as id,\n iv.image_id as image_id,\n iv.media_id as media_id,\n iv.variation as variation,\n iv.width as width,\n iv.height as height,\n m.media_file_id as media_file_id,\n m.size as size,\n m.mime_type as mime_type,\n m.file_name as file_name,\n m.etag as etag\n FROM image_variation iv, media m\n WHERE iv.media_id = m.id AND\n iv.image_id IN ({$ids})"; $toolkit =& Limb::toolkit(); $conn =& $toolkit->getDbConnection(); $stmt =& $conn->newStatement($sql); $rs =& $stmt->getRecordSet(); for ($rs->rewind(); $rs->valid(); $rs->next()) { $variation = $rs->current(); $variation_data = $variation->export(); foreach (array_keys($cached_records) as $id) { if ($id == $variation_data['image_id']) { $cached_records[$id]['variations'][$variation_data['variation']] = $variation_data; break; } } } $this->cached_dataset->importDataSetAsArray($cached_records); }