/** * Builds the list items (<li>) elements for a menu category * with the provided items, recursively if need be. * * @param array $items * @return string */ protected function buildItems(array $items) { $requestPath = $this->_router->getRequestPath(); $rawRequestPath = $this->_router->getRawRequestPath(); $list = '<ul class="menu-category">' . "\n\t"; foreach ($items as $item) { $item['url'] = ltrim($item['url'], '/'); $class = 'menu-' . $item['id']; if ($item['url'] == $rawRequestPath || $item['url'] == $requestPath) { $class .= ' menu-current'; } // Create the correct URL for the menu item to use if ($item['url'] == 'admin') { $item['url'] = $this->_router->makeUrl('', '', '', 'admin'); } else { if ($item['url'] == false) { $item['url'] = $this->_router->makeUrl('', '', '', 'main'); } else { if (strpos($item['url'], 'www.') === 0) { $item['url'] = 'http://' . $item['url']; } else { if (!zula_url_has_scheme($item['url'])) { if ($item['url'][0] == '#') { $item['url'] = $this->_router->getCurrentUrl() . $item['url']; } else { if (strpos($item['url'], '/')) { $item['url'] = $this->_router->makeUrl($item['url']); } else { $item['url'] = $this->_router->makeUrl($item['url'], null, null, 'main'); } } } } } } // Gather children and append the list item $children = empty($item['children']) ? '' : $this->buildItems($item['children']); $list .= sprintf('<li class="%1$s"><a href="%2$s" title="%3$s">%4$s</a>%5$s</li>' . "\n", $class, $item['url'], zula_htmlspecialchars($item['attr_title'] ? $item['attr_title'] : $item['name']), zula_htmlspecialchars($item['name']), $children); } return $list . '</ul>'; }
/** * Attempts to log a user in with the credentials provided by the form. * * @return string */ public function loginSection() { $this->_session->storePrevious(false); $loggedIn = false; if ($this->maxLoginAttempts > 0 && $this->_model()->getLoginAttempts() >= $this->maxLoginAttempts) { $this->_event->error(t('Maximum number of login attempts reached')); } else { if ($this->_input->has('post', 'session/identifier')) { $_SESSION['post-restore'] = $this->_input->getAll('post'); unset($_SESSION['post-restore']['session']); // Validate the provided value $identifier = $this->_input->post('session/identifier', false); $validator = $this->loginMethod == 'username' ? new Validator_Length(0, 24) : new Validator_Email(); if (($result = $validator->validate($identifier)) === true) { try { $uid = $this->_model()->checkCredentials($identifier, $this->_input->post('session/password', false), $this->loginMethod); $rememberMe = $this->_input->has('post', 'session/remember'); if ($this->_session->switchUser($uid, $rememberMe) === false) { $this->_event->error(t('Sorry, this user account is currently locked')); } else { $loggedIn = true; // Check if the users password has expired $expiresAfter = $this->_config->get('session/expire_pw'); $expiresOn = $this->_date->getDateTime($this->_session->getUser('last_pw_change'))->modify('+ ' . $expiresAfter . ' seconds'); if ($expiresAfter > 0 && $expiresOn < new DateTime()) { $_SESSION['mod']['session']['changePw'] = true; } } } catch (Session_UserNotActivated $e) { $this->_event->error(t('This user account has not yet been activated')); } catch (Session_InvalidCredentials $e) { $this->_event->error(t('Username and/or password provided are incorrect')); } } else { $this->_event->error(sprintf($result, 'Username/Email')); } } } // Return the user back to the correct location $destination = $this->_config->get('session/login_destination'); if ($destination == 'previous' || $loggedIn === false) { if (empty($_SESSION['previous_url'])) { $url = $this->_router->makeUrl('/'); } else { $url = $_SESSION['previous_url']; } } else { if ($destination == 'home') { $url = $this->_router->getBaseUrl(); } else { if ($destination == 'custom') { $url = $this->_config->get('session/login_destination_url'); if (!zula_url_has_scheme($url)) { $url = $this->_router->makeUrl($url); } } } } return zula_redirect($url); }
/** * 'router_pre_parse' Hook * * @param string $url * @return string */ public function hookRouterPreParse($url) { $resolvedUrl = trim($url, '/ '); do { $break = false; if (isset($this->aliases[$resolvedUrl])) { $redirect = $this->aliases[$resolvedUrl]['redirect']; $resolvedUrl = $this->aliases[$resolvedUrl]['url']; } else { $break = true; } } while ($break === false && $url !== $resolvedUrl); if (!empty($redirect) && $url != $resolvedUrl) { if (zula_url_has_scheme($resolvedUrl)) { $url = $resolvedUrl; } else { // Don't use makeFullUrl since that will re-alias this URL! $url = $this->_router->getBaseUrl(); if ($this->_router->getType() == 'standard') { $url .= 'index.php?url='; } $url .= $resolvedUrl; } zula_redirect($url); die; # Eww, but needed. } return $resolvedUrl; }
/** * Adds on the scheme/protocol to a provided URL if it * does not already have one. Defaults to adding http. * * @param string $url * @param string $scheme * @return string */ function zula_url_add_scheme($url, $scheme = 'http') { return zula_url_has_scheme($url) ? $url : $scheme . '://' . $url; }
/** * Edits/Updates a URL alias (Sets Alias and URL) * * @param int $id * @param string $alias * @param string $url * @param bool|int $redirect * @return bool */ public function edit($id, $alias, $url, $redirect) { $aliasDetails = $this->getDetails($id); if ($redirect == false && zula_url_has_scheme($url)) { $redirect = true; } $pdoSt = $this->_sql->prepare('UPDATE {PREFIX}mod_aliases SET alias = :alias, url = :url, redirect = :redirect WHERE id = :id'); $pdoSt->bindValue(':alias', $alias); $pdoSt->bindValue(':url', $url); $pdoSt->bindValue(':redirect', (int) $redirect, PDO::PARAM_INT); $pdoSt->bindValue(':id', $aliasDetails['id'], PDO::PARAM_INT); $pdoSt->execute(); $this->_cache->delete('aliases'); Hooks::notifyAll('aliases_edit', $id, $alias, $url, $redirect); return (bool) $pdoSt->rowCount(); }