/** * Add our own stuff to the templates */ public function inject_template(midgardmvc_core_request $request) { // Replace the default MeeGo sidebar with our own $route = $request->get_route(); $route->template_aliases['content-sidebar'] = 'cmp-show-sidebar'; $route->template_aliases['main-menu'] = 'cmp-show-main_menu'; midgardmvc_core::get_instance()->head->add_link(array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => MIDGARDMVC_STATIC_URL . '/com_meego_planet/planet.css')); }
public function inject_template(midgardmvc_core_request $request) { if (!$this->connected) { self::get_connected(); } $mvc = midgardmvc_core::get_instance(); $request->add_component_to_chain($mvc->component->get('com_meego_ratings'), true); }
/** * Some template hack */ public function inject_template(midgardmvc_core_request $request) { $route = $request->get_route(); $request->set_data_item('admin', false); if ($this->mvc->authentication->is_user()) { if ($this->mvc->authentication->get_user()->is_admin()) { $request->set_data_item('admin', true); } } }
public function setUp() { // Create database and open connection parent::setUp(); $this->local_configuration = array('services_dispatcher' => 'manual', 'services_authentication' => 'basic', 'providers_component' => 'midgardmvc', 'providers_hierarchy' => 'configuration', 'components' => array('midgardmvc_core' => true), 'nodes' => array('title' => 'Midgard MVC', 'content' => '<p>Welcome to Midgard MVC</p>', 'component' => 'midgardmvc_core', 'children' => array('subdir' => array('title' => 'Subfolder', 'content' => '<p>Welcome to a subfolder</p>', 'component' => 'midgardmvc_core')))); $this->_core = midgardmvc_core::get_instance($this->local_configuration); $request = new midgardmvc_core_request(); $request->add_component_to_chain($this->_core->component->get('midgardmvc_core')); $request->set_data_item('test_mode', true); $this->_core->context->create($request); }
public function get_routes(midgardmvc_core_request $request) { $routes = array(); $components = array_reverse($request->get_component_chain()); foreach ($components as $component) { $component_routes = $component->get_routes($request); foreach ($component_routes as $route_id => $route) { $routes[$route_id] = $route; } } return $routes; }
public function test_get_request() { $original = new midgardmvc_core_request(); $this->_core->context->create($original); $current = $this->_core->context->get_current_context(); $second = new midgardmvc_core_request(); $second->set_method('post'); $this->_core->context->create($second); $request = $this->_core->context->get_request($current); $this->assertEquals($original, $request); $this->_core->context->delete(); $this->_core->context->delete(); }
public function test_get_element_include() { $request = midgardmvc_core_request::get_for_intent('/subdir'); $routes = midgardmvc_core::get_instance()->component->get_routes($request); $request->set_route($routes['index']); midgardmvc_core::get_instance()->context->create($request); $original_element = file_get_contents(midgardmvc_core::get_component_path('midgardmvc_core') . '/templates/ROOT.xhtml'); $element = midgardmvc_core::get_instance()->templating->get_element($this->_core->context->get_request(), 'ROOT'); $this->assertNotEquals($original_element, $element, 'Template returned by templating service should not be the same as the template file because of includes'); $this->assertTrue(strpos($element, '<h1 property="mgd:title" tal:content="current_component/object/title">Title</h1>') !== false); midgardmvc_core::get_instance()->context->delete(); }
public function test_get_routes() { $request = midgardmvc_core_request::get_for_intent('/'); $routes = midgardmvc_core::get_instance()->component->get_routes($request); $this->assertTrue(is_array($routes)); $this->assertTrue(isset($routes['index'])); $this->assertTrue($routes['index'] instanceof midgardmvc_core_route); $this->assertTrue(isset($routes['login']), 'Root node should provide login route'); $request = midgardmvc_core_request::get_for_intent('/subdir'); $routes = midgardmvc_core::get_instance()->component->get_routes($request); $this->assertTrue(is_array($routes)); $this->assertTrue(isset($routes['index'])); $this->assertTrue($routes['index'] instanceof midgardmvc_core_route); $this->assertFalse(isset($routes['login']), 'Subnode should not provide login route'); }
/** * Parse request URL into components and return a corresponding MVC request object * * @return midgardmvc_core_request */ public function get_request() { $request = new midgardmvc_core_request(); $request->set_method($this->appserver_context['env']['REQUEST_METHOD']); if (isset($this->appserver_context['env']['HTTP_X_HTTP_METHOD_OVERRIDE'])) { $request->set_method($this->appserver_context['env']['HTTP_X_HTTP_METHOD_OVERRIDE']); } // Parse URL into components (Mjolnir doesn't do this for us) $url_components = parse_url("http://{$this->appserver_context['env']['HTTP_HOST']}{$this->appserver_context['env']['REQUEST_URI']}"); // Handle GET parameters if (!empty($url_components['query'])) { $get_parameters = array(); parse_str($url_components['query'], $get_parameters); $request->set_query($get_parameters); } $request->resolve_node($url_components['path']); return $request; }
/** * @expectedException midgardmvc_exception_httperror */ public function test_dispatch_invalidmethod() { $request = midgardmvc_core_request::get_for_intent('/'); $routes = midgardmvc_core::get_instance()->component->get_routes($request); $request->set_route($routes['index']); $request->set_method('TRACE'); midgardmvc_core::get_instance()->dispatcher->dispatch($request); }
public function test_serve() { $_ENV['MIDGARD_ENV_GLOBAL_CACHEDIR'] = '/tmp'; $request = midgardmvc_core_request::get_for_intent('/'); $routes = midgardmvc_core::get_instance()->component->get_routes($request); $request->set_route($routes['index']); midgardmvc_core::get_instance()->dispatcher->set_request($request); $request = midgardmvc_core::get_instance()->process(); ob_start(); midgardmvc_core::get_instance()->serve($request); $content = ob_get_clean(); $this->assertTrue(strpos($content, '<h1 property="mgd:title">Midgard MVC</h1>') !== false); }
/** * @todo: docs */ public function inject_process(midgardmvc_core_request $request) { $request->add_component_to_chain($this->mvc->component->get('net_nemein_party'), true); }
public function test_intent_path() { $newreq = midgardmvc_core_request::get_for_intent('/subdir'); $this->assertEquals('/subdir/', $newreq->get_path()); }
public function get_routes(midgardmvc_core_request $request) { $node_is_root = false; if ($request->get_node() == midgardmvc_core::get_instance()->hierarchy->get_root_node()) { $node_is_root = true; } if (isset($this->cached_routes[$node_is_root])) { return $this->cached_routes[$node_is_root]; } $routes = array(); if (!isset($this->manifest['routes'])) { return $routes; } foreach ($this->manifest['routes'] as $route_id => $route) { if (isset($route['root_only']) && $route['root_only'] && !$node_is_root) { // Drop root-only routes from subnodes continue; } if (isset($route['test_only']) && $route['test_only'] && !$request->isset_data_item('test_mode')) { // Drop test-only routes when not in unit tests continue; } if (isset($route['subrequest_only']) && $route['subrequest_only'] && !$request->is_subrequest()) { // Drop routes that are usable via subrequest only from the main request continue; } // Handle the required route parameters if (!isset($route['controller'])) { throw new Exception("Route {$route_id} of {$this->name} has no controller defined"); } if (!isset($route['action'])) { throw new Exception("Route {$route_id} of {$this->name} has no action defined"); } if (!isset($route['path'])) { throw new Exception("Route {$route_id} of {$this->name} has no path defined"); } if (!isset($route['template_aliases'])) { $route['template_aliases'] = array(); } if (!isset($route['mimetype'])) { $route['mimetype'] = 'text/html'; // $route['mimetype'] = 'application/xhtml+xml'; } $routes[$route_id] = new midgardmvc_core_route($route_id, $route['path'], $route['controller'], $route['action'], $route['template_aliases'], $route['mimetype']); } $this->cached_routes[$node_is_root] = $routes; return $routes; }
public function inject_template(midgardmvc_core_request $request) { // We inject the template to provide Open Keidas styling $request->add_component_to_chain(midgardmvc_core::get_instance()->component->get('fi_openkeidas_articles'), true); }
/** * Generates an URL for given route_id with given arguments * * @param string $route_id the id of the route to generate a link for * @param array $args associative arguments array * @param mixed $intent Component name, node object, node GUID or node path * @return string url */ public function generate_url($route_id, array $args, $intent) { // Create a request from the intent and assign it to a context $request = midgardmvc_core_request::get_for_intent($intent); $this->midgardmvc->context->create($request); $this->midgardmvc->component->inject($request, 'process'); $routes = $this->midgardmvc->component->get_routes($request); if (!isset($routes[$route_id])) { if (empty($routes)) { throw new OutOfBoundsException("Route ID '{$route_id}' not found in routes of request. Routes configuration is also empty " . $request->get_identifier()); } throw new OutOfBoundsException("Route ID '{$route_id}' not found in routes of request " . $request->get_identifier()); } $route = $routes[$route_id]; $request->set_arguments($route->set_variables($args)); $this->midgardmvc->context->delete(); return $request->get_path(); }
/** * Some template hack */ public function inject_template(midgardmvc_core_request $request) { $this->mvc = midgardmvc_core::get_instance(); if (!$this->connected) { self::get_connected(); } if (!$this->mvc->configuration->exists('default')) { // workaround to avoid an exception while templating return true; } $this->request = $request; $route = $this->request->get_route(); if ($route->id == "apps_index") { $route->template_aliases['topbar'] = 'cmp-welcome-text'; } else { $route->template_aliases['topbar'] = 'cmp-menubar'; } // login link with redirect specified $request->set_data_item('redirect_link', $this->mvc->context->get_request(0)->get_path()); // placeholder for a link to list staging apps $request->set_data_item('staging_link', false); // set if user is admin $request->set_data_item('admin', false); // admins get a link to category management UI $request->set_data_item('category_admin_url', false); // flag to show newest and hottest blocks $request->set_data_item('bottomblocks', false); if ($this->mvc->authentication->is_user()) { if ($this->mvc->authentication->get_user()->is_admin()) { $request->set_data_item('admin', true); $category_admin_url = $this->mvc->dispatcher->generate_url('basecategories_admin_index', array(), $request); $request->set_data_item('category_admin_url', $category_admin_url); } } $matched = $route->get_matched(); if (!$matched && $route->id == 'search') { // if we have a search we may be lucky and get a nicely set matched array $matched = $this->request->get_query(); } if (is_array($matched) && array_key_exists('os', $matched) && array_key_exists('version', $matched) && array_key_exists('ux', $matched)) { $os = $matched['os']; $ux = $matched['ux']; $redirect = false; $decoded = ''; if (array_key_exists('basecategory', $matched)) { $decoded = rawurldecode($matched['basecategory']); $matched['basecategory'] = $decoded; if (array_key_exists($decoded, $this->mvc->configuration->basecategory_css_map)) { $matched['basecategory_css'] = $this->mvc->configuration->basecategory_css_map[$decoded]; } else { $matched['basecategory_css'] = strtolower($decoded); } } else { $matched['basecategory'] = false; $matched['basecategory_css'] = ''; } if (!array_key_exists($matched['os'], $this->mvc->configuration->os_map)) { $redirect = true; $os = $this->mvc->configuration->default['os']; } // if the matched UX is not configured then we shout out loud if (!array_key_exists($matched['ux'], $this->mvc->configuration->os_ux[$os])) { $redirect = true; $ux = $this->mvc->configuration->latest[$os]['ux']; } $matched['prettyversion'] = $matched['version']; if (array_key_exists('versions', $this->mvc->configuration->os_map[$matched['os']])) { if (array_key_exists($matched['version'], $this->mvc->configuration->os_map[$matched['os']]['versions'])) { $matched['prettyversion'] = $this->mvc->configuration->os_map[$matched['os']]['versions'][$matched['version']]; } } if ($redirect) { //throw new midgardmvc_exception_notfound("Please pick a valid UX, " . $matched['ux'] . " does not exist.", 404); com_meego_packages_controllers_basecategory::redirect($os, $matched['version'], $ux); } // gather available UXes for the popups // @todo: this piece of code is only needed for some of the routes // so we should not run it when not needed $uxes = array(); $versions = array(); $repositories = com_meego_packages_controllers_application::get_top_project_repos(); $latest = $this->mvc->configuration->latest; foreach ($repositories as $repository) { if (array_key_exists($repository->repoos, $latest) && $repository->repoosversion == $latest[$repository->repoos]['version']) { if (!strlen($repository->repoosux)) { // No UX means a core or universal repo, so we populate all UXes foreach ($this->mvc->configuration->os_ux[$repository->repoos] as $configured_ux => $configured_ux_title) { $uxes[$repository->repoos . $configured_ux] = com_meego_packages_controllers_application::populate_repo_ux($repository, $configured_ux); } } else { $uxes[$repository->repoos . $repository->repoosux] = com_meego_packages_controllers_application::populate_repo_ux($repository); } } if ($matched['os'] == $repository->repoos) { // all versions of the matched, current UX if ($repository->repoosux == '' || $repository->repoosux == 'universal' || $repository->repoosux == $matched['ux'] && !array_key_exists($repository->repoosversion, $versions)) { $prettyversion = $repository->repoosversion; if (array_key_exists('versions', $this->mvc->configuration->os_map[$repository->repoos])) { if (array_key_exists($repository->repoosversion, $this->mvc->configuration->os_map[$repository->repoos]['versions'])) { $prettyversion = $this->mvc->configuration->os_map[$repository->repoos]['versions'][$repository->repoosversion]; } } $_repo = com_meego_packages_controllers_application::populate_repo_ux($repository, $matched['ux']); $versions[$repository->repoosversion] = array('version' => $repository->repoosversion, 'url' => $_repo['url'], 'prettyversion' => $prettyversion); } } // if we are not serving a staging_ route then // check if the repo's project has a staging project configured if ($route->id == "basecategories_os_version_ux" && substr($route->id, 0, 8) != 'staging_' && $repository->repoos == $os && $this->mvc->configuration->top_projects[$repository->projectname]['staging']) { //echo "call count of apps\n"; ob_flush(); $cnt = com_meego_packages_controllers_application::count_number_of_apps($repository->repoos, $repository->repoosversion, 0, $matched['ux'], 'staging'); if ($cnt) { $workflows = com_meego_packages_controllers_workflow::get_open_workflows_for_osux($repository->repoos, $repository->repoosversion, $matched['ux']); if (count($workflows)) { // if there is at least 1 workflow then we set and show the link in the templates $link = $this->mvc->dispatcher->generate_url('staging_basecategories_os_version_ux', array('os' => $os, 'version' => (string) $repository->repoosversion, 'ux' => $matched['ux']), 'com_meego_packages'); $request->set_data_item('staging_link', $link); } } } } krsort($uxes); ksort($versions); $request->set_data_item('uxes', $uxes); $request->set_data_item('versions', $versions); } // in case there is no matched stuff from the request we will use the defaults configured if (!is_array($matched)) { $matched = array(); } if (is_array($matched) && (!array_key_exists('os', $matched) || !array_key_exists('version', $matched) || !array_key_exists('prettyversion', $matched) || !array_key_exists('ux', $matched))) { $default_os = $this->mvc->configuration->default['os']; $matched = array_merge($matched, $this->mvc->configuration->latest[$default_os]); $matched['os'] = $this->mvc->configuration->default['os']; $matched['prettyversion'] = $matched['version']; if (array_key_exists('versions', $this->mvc->configuration->os_map[$matched['os']])) { if (array_key_exists($matched['version'], $this->mvc->configuration->os_map[$matched['os']]['versions'])) { $matched['prettyversion'] = $this->mvc->configuration->os_map[$matched['os']]['versions'][$matched['version']]; } } $this->part = 'packages'; } // Add the CSS and JS files needed by Packages $this->add_head_elements(); $matched['configured_ux'] = ucwords($this->mvc->configuration->os_ux[$matched['os']][$matched['ux']]); if (array_key_exists('client', $this->mvc->configuration->os_ux[$matched['os']])) { $matched['appsclient'] = $this->mvc->configuration->os_ux[$matched['os']]['client']; } else { $matched['appsclient'] = false; } $request->set_data_item('matched', $matched); if (count($matched)) { // if we have matched then show the newest and hottest blocks $request->set_data_item('bottomblocks', true); } $request->set_data_item('submit_app_url', $this->mvc->configuration->submit_app_url); // don't show newest and hottest blocks if any of these were requested explicitly if ($route->id == "newest_apps" || $route->id == "hottest_apps") { $request->set_data_item('bottomblocks', false); } $request->set_data_item('staging_area', false); if (substr($route->id, 0, 8) == 'staging_') { $request->set_data_item('staging_area', true); $request->set_data_item('staging_back_link', false); $request->set_data_item('community_qa_url', $this->mvc->configuration->community_qa_url); $link = false; if (substr($route->id, 0, 28) == 'staging_apps_by_basecategory') { $link = $this->mvc->dispatcher->generate_url('staging_basecategories_os_version_ux', array('os' => $matched['os'], 'version' => (string) $matched['version'], 'ux' => $matched['ux']), 'com_meego_packages'); } if (substr($route->id, 0, 21) == 'staging_apps_by_name') { $link = '..'; } if ($link) { $request->set_data_item('staging_back_link', $link); } } }
private function display_tal(midgardmvc_core_request $request, $content, array $data) { $tal = new PHPTAL($request->get_template_identifier()); $tal->setPhpCodeDestination($this->midgardmvc->cache->template->get_cache_directory()); $tal->uimessages = false; if ($this->midgardmvc->configuration->enable_uimessages) { if ($this->midgardmvc->uimessages->has_messages() && $this->midgardmvc->uimessages->can_view()) { $tal->uimessages = $this->midgardmvc->uimessages->render(); } } $tal->midgardmvc = $this->midgardmvc; $tal->request = $request; // FIXME: Remove this once Qaiku has upgraded $tal->MIDCOM = $this->midgardmvc; foreach ($data as $key => $value) { $tal->{$key} = $value; } $tal->setSource($content); $translator =& $this->midgardmvc->i18n->set_translation_domain($request->get_component()->name); $tal->setTranslator($translator); try { $content = $tal->execute(); } catch (PHPTAL_TemplateException $e) { throw new midgardmvc_exception("PHPTAL: {$e->srcFile} line {$e->srcLine}: " . $e->getMessage()); } return $content; }
/** * Process application comments and ratings * * It intercepts the POST and checks if multiple rating is allowed * and the user can rate the object * If the user has already rated an object and multiple rating is not allowed * then it takes away rating from the POST and passes on the request * to the proper controller that will process it. * */ public function post_comment_application(array $args) { if (!self::can_rate($args['to'])) { unset($_POST['rating']); } $route_id = 'rating_create'; $request = midgardmvc_core_request::get_for_intent('com_meego_ratings_caching', false); $request->add_component_to_chain($this->mvc->component->get('com_meego_ratings_caching')); $routes = $this->mvc->component->get_routes($request); $request->set_arguments($routes[$route_id]->set_variables($args)); $request->set_route($routes[$route_id]); $request->set_method('post'); $this->mvc->dispatcher->dispatch($request); }
private static function bootstrap_request() { $request = new midgardmvc_core_request(); $core = midgardmvc_core::get_instance()->component->get('midgardmvc_core'); $request->add_component_to_chain($core); $route = new midgardmvc_core_route('midgardmvc_show_error', '', '', '', array()); $request->set_route($route); $request->set_component($core); midgardmvc_core::get_instance()->context->create($request); return $request; }
/** * Sets the breadcrumb * A bit lame way though... * * @param object midgardmvc_core_request object to assign 'breadcrumb' for templates */ public function set_breadcrumb(midgardmvc_core_request $request) { $nexturl = ''; $breadcrumb = array(); $cnt = 0; foreach ($request->argv as $arg) { $nexturl .= '/' . $arg; $item = array('title' => ucfirst($arg), 'localurl' => $nexturl, 'last' => count($request->argv) - 1 == $cnt ? true : false); $breadcrumb[] = $item; ++$cnt; } $request->set_data_item('breadcrumb', $breadcrumb); }