/** * returns an array with two positions: $array["username"] and $array["blogname"] as * extracted from the request. This method is static * * @static * @return an associative array */ function getSubdomainInfoFromRequest() { $config =& Config::getConfig(); $url = new Url($config->getValue("subdomains_base_url")); $lp = new LinkParser($url->getHost()); $server = HttpVars::getServer(); $httpHost = $server["HTTP_HOST"]; $result = $lp->parseLink($httpHost); return $result; }
public function addSubreddit(LinkParser $linkParser) { if ($this->linkExists($this->arrayWithSubreddits, $linkParser->getSubredditUrl())) { throw new Exception("You're already subscribed to this subreddit"); } else { $id = $this->discoverId($this->arrayWithSubreddits); $this->arrayWithSubreddits[$id] = $linkParser->getSubredditUrl(); return $id; } }
/** * @return */ function identify() { foreach ($this->_formats as $key => $format) { $lp = new LinkParser($format); $params = $lp->parseLink($this->_request); if ($params) { // return the key assigned to the format that matched $this->_params = $params; return $key; } } }
public function parse($comment) { if (preg_match_all('/{\\@link(.*?)}/', $comment, $matches)) { foreach ($matches[0] as $key => $rawLink) { $linkParser = new LinkParser($this->scope); $linkFormatted = $linkParser->parse($matches[1][$key]); $comment = str_replace($rawLink, $linkFormatted, $comment); } } if (preg_match_all('/{\\@hook(.*?)}/', $comment, $matches)) { foreach ($matches[0] as $key => $rawLink) { $link = new Link($matches[1][$key]); $anchor = strtolower(str_replace('.', '', $link->getDestination())); $linkFormatted = sprintf('[%s](/api-reference/events#%s)', $link->getDescription(), $anchor); $comment = str_replace($rawLink, $linkFormatted, $comment); } } return $comment; }
public function executeSearchRequest(sfWebRequest $request) { if (LinkParser::FilterByPeriod($request)) { $errors = LinkParser::ValidateSearchRequest($request, true); $this->by_period = true; $this->DoSearch($errors, $request, true); } else { $errors = LinkParser::ValidateSearchRequest($request); $this->DoSearch($errors, $request); } }
public static function ValidateSearchRequest($request, $check_dates = false) { $date_from = $request->getParameter('date_from'); $date_to = $request->getParameter('date_to'); $city_name = $request->getParameter('city'); $features = $request->getParameter('features'); $errors = array(); // City______________ $city = Doctrine_Core::getTable('City')->FindByNameLike($city_name); if (is_object($city) === false) { $error = 'City ' . $request->getParameter('city') . ' not found ... '; array_push($errors, $error); } $city_validator = new sfValidatorString(array('required' => true), array('required' => 'Please enter City to search')); try { $city_name = $city_validator->clean($city_name); } catch (sfValidatorError $e) { array_push($errors, $e); } // Dates______________ if ($check_dates) { if (strlen($date_from) > 1 === false) { array_push($errors, "Please enter date from."); } if (strlen($date_to) > 1 === false) { array_push($errors, "Please enter date to."); } if (strtotime($date_from) >= strtotime($date_to)) { array_push($errors, "Bad date range."); } if (LinkParser::CheckDate($date_from, '-', true) === false) { array_push($errors, "Invalid format for date from."); } if (LinkParser::CheckDate($date_to, '-', true) === false) { array_push($errors, "Invalid format for date to."); } } return $errors; }
<?php include_once '../config.php'; require_once ROOT_NAME . "/src/classes/LinkParser.php"; require_once ROOT_NAME . "/src/classes/CookieManager.php"; require_once ROOT_NAME . "/src/classes/SubredditsFactory.php"; require_once ROOT_NAME . "/src/classes/SubredditDownloader.php"; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $url = $_POST["subreddit"]; try { $linkParser = new LinkParser($url); $cookieManager = new CookieManager($_COOKIE); $downloader = new SubredditDownloader($linkParser->getSubredditUrl()); $idInCookie = $cookieManager->addSubreddit($linkParser); $cookieManager->setCookie(); $subreddit = new Subreddit($downloader); echo json_encode(['id' => $idInCookie, 'subreddit' => $subreddit]); } catch (Exception $e) { echo json_encode($e->getMessage()); } } elseif ($_SERVER['REQUEST_METHOD'] === 'GET') { $id = $_GET["id"]; try { $cookieManager = new CookieManager($_COOKIE); $subreddit = SubredditsFactory::create($cookieManager, $id); echo json_encode(['id' => $id, 'subreddit' => $subreddit]); } catch (Exception $e) { echo json_encode($e->getMessage()); } }
public function __construct($url, $user = null) { $this->url = $url; $results = new LinkParser($url); $this->url_data = $results->getLinkData(); }