/** * Execute the action */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get parameters $charset = $this->getContainer()->getParameter('kernel.charset'); $searchTerm = \SpoonFilter::getPostValue('term', null, ''); $term = $charset == 'utf-8' ? \SpoonFilter::htmlspecialchars($searchTerm) : \SpoonFilter::htmlentities($searchTerm); $limit = (int) $this->get('fork.settings')->get('Search', 'autocomplete_num_items', 10); // validate if ($term == '') { $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.'); } else { // get matches $matches = FrontendSearchModel::getStartsWith($term, FRONTEND_LANGUAGE, $limit); // get search url $url = FrontendNavigation::getURLForBlock('Search'); // loop items and set search url foreach ($matches as &$match) { $match['url'] = $url . '?form=search&q=' . $match['term']; } // output $this->output(self::OK, $matches); } }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $charset = $this->getContainer()->getParameter('kernel.charset'); $searchTerm = \SpoonFilter::getPostValue('term', null, ''); $term = $charset == 'utf-8' ? \SpoonFilter::htmlspecialchars($searchTerm) : \SpoonFilter::htmlentities($searchTerm); // validate search term if ($term == '') { $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.'); } else { // previous search result $previousTerm = \SpoonSession::exists('searchTerm') ? \SpoonSession::get('searchTerm') : ''; \SpoonSession::set('searchTerm', ''); // save this term? if ($previousTerm != $term) { // format data $this->statistics = array(); $this->statistics['term'] = $term; $this->statistics['language'] = LANGUAGE; $this->statistics['time'] = FrontendModel::getUTCDate(); $this->statistics['data'] = serialize(array('server' => $_SERVER)); $this->statistics['num_results'] = FrontendSearchModel::getTotal($term); // save data FrontendSearchModel::save($this->statistics); } // save current search term in cookie \SpoonSession::set('searchTerm', $term); // output $this->output(self::OK); } }
/** * Retrieve the initial or submitted value. * * @param bool[optional] $allowHTML Is HTML allowed? * @return string */ public function getValue($allowHTML = null) { // redefine default value $value = $this->value; // added to form if ($this->isSubmitted()) { // post/get data $data = $this->getMethod(true); // submitted by post/get (may be empty) if (isset($data[$this->attributes['name']])) { // value $value = $data[$this->getName()]; $value = is_scalar($value) ? (string) $value : 'Array'; if (!$allowHTML) { $value = Spoon::getCharset() == 'utf-8' ? SpoonFilter::htmlspecialchars($value) : SpoonFilter::htmlentities($value); } } } return $value; }
/** * Retrieve the method post/get. * * @return string */ public function getMethod() { // prevent against xss $method = SPOON_CHARSET == 'utf-8' ? SpoonFilter::htmlspecialchars($this->method) : SpoonFilter::htmlentities($this->method); return $method; }
/** * Retrieve the initial or submitted value. * * @return string * @param bool[optional] $allowHTML Is HTML allowed? */ public function getValue($allowHTML = null) { // redefine html & default value $allowHTML = $allowHTML !== null ? (bool) $allowHTML : $this->isHTML; $value = $this->value; // contains html if ($this->isHTML) { // set value $value = SPOON_CHARSET == 'utf-8' ? SpoonFilter::htmlspecialchars($value) : SpoonFilter::htmlentities($value); } // form submitted if ($this->isSubmitted()) { // post/get data $data = $this->getMethod(true); // submitted by post (may be empty) if (isset($data[$this->getName()])) { // value $value = $data[$this->attributes['name']]; // maximum length? if (isset($this->attributes['maxlength']) && $this->attributes['maxlength'] > 0) { $value = mb_substr($value, 0, (int) $this->attributes['maxlength'], SPOON_CHARSET); } // html allowed? if (!$allowHTML) { $value = SPOON_CHARSET == 'utf-8' ? SpoonFilter::htmlspecialchars($value) : SpoonFilter::htmlentities($value); } } } return $value; }
public function testHtmlentities() { // setup $input = 'Ik heb "géén" bananen vandaag'; $expectedResult = 'Ik heb "géén" bananen vandaag'; // perform test $this->assertEquals($expectedResult, SpoonFilter::htmlentities(utf8_decode($input), 'iso-8859-1')); $this->assertEquals($expectedResult, SpoonFilter::htmlentities($input, 'utf-8')); $expectedResult = 'Ik heb "géén" bananen vandaag'; $this->assertEquals($expectedResult, SpoonFilter::htmlentities($input, null, ENT_QUOTES)); }
/** * Reads an feed into a SpoonRSS object. * * @return SpoonRSS Returns as an instance of SpoonRSS. * @param string $URL An URL where the feed is located or the XML of the feed. * @param string[optional] $type The type of feed, possible values are: url, string. */ public static function readFromFeed($URL, $type = 'url') { // redefine var $URL = (string) $URL; $type = (string) SpoonFilter::getValue($type, array('url', 'string'), 'url'); // validate if ($type == 'url' && !SpoonFilter::isURL($URL)) { throw new SpoonFeedException('This (' . SpoonFilter::htmlentities($URL) . ') isn\'t a valid URL.'); } if (!self::isValid($URL, $type)) { throw new SpoonFeedException('Invalid feed'); } // load xmlstring if ($type == 'url') { $xmlString = SpoonHTTP::getContent($URL); } else { $xmlString = $URL; } // convert to simpleXML $XML = @simplexml_load_string($xmlString); // validate the feed if ($XML === false) { throw new SpoonFeedException('Invalid rss-string.'); } // get title, link and description $title = (string) $XML->channel->title; $link = (string) $XML->channel->link; $description = (string) $XML->channel->description; // create instance $RSS = new SpoonFeedRSS($title, $link, $description); // add items foreach ($XML->channel->item as $item) { // try to read try { // read xml $item = SpoonFeedRSSItem::readFromXML($item); $RSS->addItem($item); } catch (Exception $e) { // ignore exceptions } } // add category if (isset($XML->channel->category)) { foreach ($XML->channel->category as $category) { if (isset($category['domain'])) { $RSS->addCategory((string) $category, (string) $category['domain']); } else { $RSS->addCategory((string) $category); } } } // add skip day if (isset($XML->channel->skipDays)) { // loop ski-days foreach ($XML->channel->skipDays->day as $day) { // try to add try { // add skip-day $RSS->addSkipDay((string) $day); } catch (Exception $e) { // ignore exceptions } } } // add skip hour if (isset($XML->channel->skipHours)) { foreach ($XML->channel->skipHours->hour as $hour) { // try to add try { // add skip hour $RSS->addSkipHour((int) $hour); } catch (Exception $e) { // ignore exceptions } } } // set cloud if (isset($XML->channel->cloud['domain']) && isset($XML->channel->cloud['port']) && isset($XML->channel->cloud['path']) && isset($XML->channel->cloud['registerProce-dure']) && isset($XML->channel->cloud['protocol'])) { // read attributes $cloudDomain = (string) $XML->channel->cloud['domain']; $cloudPort = (int) $XML->channel->cloud['port']; $cloudPath = (string) $XML->channel->cloud['path']; $cloudRegisterProcedure = (string) $XML->channel->cloud['registerProce-dure']; $cloudProtocol = (string) $XML->channel->cloud['protocol']; // set property $RSS->setCloud($cloudDomain, $cloudPort, $cloudPath, $cloudRegisterProcedure, $cloudProtocol); } // set copyright if (isset($XML->channel->copyright)) { $copyright = (string) $XML->channel->copyright; $RSS->setCopyright($copyright); } // set docs if (isset($XML->channel->docs)) { $docs = (string) $XML->channel->docs; $RSS->setDocs($docs); } // set generator if it is present if (isset($XML->channel->generator)) { $generator = (string) $XML->channel->generator; $RSS->setGenerator($generator); } // set image if it is present if (isset($XML->channel->image->title) && isset($XML->channel->image->url) && isset($XML->channel->image->link)) { // read properties $imageTitle = (string) $XML->channel->image->title; $imageURL = (string) $XML->channel->image->url; $imageLink = (string) $XML->channel->image->link; // read optional properties if (isset($XML->channel->image->width)) { $imageWidth = (int) $XML->channel->image->width; } else { $imageWidth = null; } if (isset($XML->channel->image->height)) { $imageHeight = (int) $XML->channel->image->height; } else { $imageHeight = null; } if (isset($XML->channel->image->description)) { $imageDescription = (string) $XML->channel->image->description; } else { $imageDescription = null; } // try to set image try { // set image $RSS->setImage($imageURL, $imageTitle, $imageLink, $imageWidth, $imageHeight, $imageDescription); } catch (Exception $e) { // ignore exceptions } } // set language if its is present if (isset($XML->channel->language)) { $language = (string) $XML->channel->language; $RSS->setLanguage($language); } // set last build date if it is present if (isset($XML->channel->lastBuildDate)) { $lastBuildDate = (int) strtotime($XML->channel->lastBuildDate); $RSS->setLastBuildDate($lastBuildDate); } // set managing editor if (isset($XML->channel->managingEditor)) { $managingEditor = (string) $XML->channel->managingEditor; $RSS->setManagingEditor($managingEditor); } // set publication date if (isset($XML->channel->pubDate)) { $publicationDate = (int) strtotime($XML->channel->pubDate); $RSS->setPublicationDate($publicationDate); } // set rating if (isset($XML->channel->rating)) { $rating = (string) $XML->channel->rating; $RSS->setRating($rating); } // set ttl if (isset($XML->channel->ttl)) { $ttl = (int) $XML->channel->ttl; $RSS->setTTL($ttl); } // set webmaster if (isset($XML->channel->webmaster)) { $webmaster = (string) $XML->channel->webmaster; $RSS->setWebmaster($webmaster); } // return return $RSS; }
/** * Sets the confirm message. * * @return void * @param string $message * @param string[optional] $custom */ public function setConfirm($message, $custom = null) { $this->confirm = true; $this->confirmMessage = SpoonFilter::htmlentities((string) $message); $this->confirmCustom = (string) $custom; }
/** * Parse SEO specific data */ private function parseSeo() { // when on the homepage of the default language, set the clean site url as canonical, because of redirect fix $queryString = trim($this->URL->getQueryString(), '/'); $language = $this->get('fork.settings')->get('Core', 'default_language', SITE_DEFAULT_LANGUAGE); if ($queryString == $language) { $this->canonical = rtrim(SITE_URL, '/'); if ($this->getContainer()->getParameter('site.multilanguage')) { $this->canonical .= '/' . $language; } } // any canonical URL provided? if ($this->canonical != '') { $url = $this->canonical; } else { // get the chunks of the current url $urlChunks = parse_url($this->URL->getQueryString()); // a canonical url should contain the domain. So make sure you // redirect your website to a single url with .htaccess $url = rtrim(SITE_URL, '/'); if (isset($urlChunks['port'])) { $url .= ':' . $urlChunks['port']; } if (isset($urlChunks['path'])) { $url .= '/' . $urlChunks['path']; } // any items provided through GET? if (isset($urlChunks['query'])) { // the items we should add into the canonical url $itemsToAdd = array('page'); $addToUrl = array(); // loop all items in GET and check if we should ignore them foreach ($_GET as $key => $value) { if (in_array($key, $itemsToAdd)) { $addToUrl[$key] = $value; } } // add GET-params if (!empty($addToUrl)) { $url .= '?' . http_build_query($addToUrl); } } } // prevent against xss $charset = $this->getContainer()->getParameter('kernel.charset'); $url = $charset == 'utf-8' ? \SpoonFilter::htmlspecialchars($url) : \SpoonFilter::htmlentities($url); $this->addLink(array('rel' => 'canonical', 'href' => $url)); if ($this->get('fork.settings')->get('Core', 'seo_noodp', false)) { $this->addMetaData(array('name' => 'robots', 'content' => 'noodp')); } if ($this->get('fork.settings')->get('Core', 'seo_noydir', false)) { $this->addMetaData(array('name' => 'robots', 'content' => 'noydir')); } }
/** * Validate the form */ private function validateForm() { // set search term $charset = $this->getContainer()->getParameter('kernel.charset'); $searchTerm = \SpoonFilter::getPostValue('term', null, ''); $this->term = $charset == 'utf-8' ? \SpoonFilter::htmlspecialchars($searchTerm) : \SpoonFilter::htmlentities($searchTerm); // validate if ($this->term == '') { $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.'); } }
/** * Validate the form */ private function validateForm() { // set search term $searchTerm = SpoonFilter::getPostValue('term', null, ''); $this->term = SPOON_CHARSET == 'utf-8' ? SpoonFilter::htmlspecialchars($searchTerm) : SpoonFilter::htmlentities($searchTerm); // validate if ($this->term == '') { $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.'); } }
/** * Reads an feed into a SpoonRSS object. * * @return SpoonAtomRSS Returns as an instance of SpoonAtomRSS. * @param string $URL An URL where the feed is located or the XML of the feed. * @param string[optional] $type The type of feed, possible values are: url, string. * @param bool[optional] $force Force to read this feed without validation. */ public static function readFromFeed($URL, $type = 'url', $force = false) { // redefine var $URL = (string) $URL; $type = (string) SpoonFilter::getValue($type, array('url', 'string'), 'url'); // validate if ($type == 'url' && !SpoonFilter::isURL($URL)) { throw new SpoonFeedException('This (' . SpoonFilter::htmlentities($URL) . ') isn\'t a valid URL.'); } if (!$force) { if (!self::isValid($URL, $type)) { throw new SpoonFeedException('Invalid feed'); } } // load xmlstring if ($type == 'url') { $xmlString = SpoonHTTP::getContent($URL); } else { $xmlString = $URL; } // convert to simpleXML $XML = @simplexml_load_string($xmlString); // validate the feed if ($XML === false) { throw new SpoonFeedException('Invalid rss-string.'); } // get title, link and description $title = (string) $XML->title; $id = (string) $XML->id; // create instance $RSS = new SpoonFeedAtomRSS($title, $id); // add authors if (isset($XML->author)) { foreach ($XML->author as $author) { // get the values $author['name'] = (string) $XML->author->name; $author['email'] = isset($XML->author->email) ? (string) $XML->author->email : null; $author['uri'] = isset($XML->author->uri) ? (string) $XML->author->uri : null; // set the values $RSS->addAuthor($author); } } // add contributors if (isset($XML->contributor)) { foreach ($XML->contributor as $contributor) { $name = (string) $contributor['name']; $email = isset($contributor['scheme']) ? (string) $contributor['email'] : null; $uri = isset($contributor['label']) ? (string) $contributor['uri$contributor'] : null; // set property $RSS->addContributor($name, $email, $uri); } } // add categories if (isset($XML->category)) { foreach ($XML->category as $category) { // build category $cat['term'] = (string) $category['term']; if (isset($category['scheme'])) { $cat['scheme'] = (string) $category['scheme']; } if (isset($category['label'])) { $cat['label'] = (string) $category['label']; } // set property $RSS->addCategory($cat); } } // add links if (isset($XML->link)) { foreach ($XML->link as $link) { // build link $aLink['href'] = $link['href']; if (isset($link['rel'])) { $aLink['rel'] = $link['rel']; } if (isset($link['type'])) { $aLink['type'] = $link['type']; } if (isset($link['title'])) { $aLink['title'] = $link['title']; } if (isset($link['hreflang'])) { $aLink['hreflang'] = $link['hreflang']; } if (isset($link['length'])) { $aLink['length'] = $link['length']; } // set property $RSS->addLink($aLink); } } // add items foreach ($XML->entry as $item) { // try to read try { // read xml $item = SpoonFeedAtomRSSItem::readFromXML($item); $RSS->addItem($item); } catch (Exception $e) { // ignore exceptions } } // set updated date if (isset($XML->updated)) { $RSS->setUpdatedDate((int) strtotime($XML->updated)); } // set generator if (isset($XML->generator)) { $RSS->setGenerator((string) $XML->generator); } // set icon if (isset($XML->icon)) { $RSS->setIcon((string) $XML->icon); } // set logo if (isset($XML->logo)) { $RSS->setLogo((string) $XML->logo); } // set rights if (isset($XML->rights)) { $RSS->setRights((string) $XML->rights); } // return return $RSS; }
/** * Parse SEO specific data */ private function parseSeo() { // any canonical URL provided? if ($this->canonical != '') { $url = $this->canonical; } else { // get the chunks of the current url $urlChunks = parse_url($this->URL->getQueryString()); // a canonical url should contain the domain. So make sure you redirect your website to a single url with .htaccess $url = rtrim(SITE_URL, '/'); if (isset($urlChunks['port'])) { $url .= ':' . $urlChunks['port']; } if (isset($urlChunks['path'])) { $url .= '/' . $urlChunks['path']; } // any items provided through GET? if (isset($urlChunks['query'])) { // the items we should add into the canonical url $itemsToAdd = array('page'); $addToUrl = array(); // loop all items in GET and check if we should ignore them foreach ($_GET as $key => $value) { if (in_array($key, $itemsToAdd)) { $addToUrl[$key] = $value; } } // add GET-params if (!empty($addToUrl)) { $url .= '?' . http_build_query($addToUrl); } } } // prevent against xss $url = SPOON_CHARSET == 'utf-8' ? SpoonFilter::htmlspecialchars($url) : SpoonFilter::htmlentities($url); // canonical $this->addLink(array('rel' => 'canonical', 'href' => $url)); // noodp, noydir if (FrontendModel::getModuleSetting('core', 'seo_noodp', false)) { $this->addMetaData(array('name' => 'robots', 'content' => 'noodp')); } if (FrontendModel::getModuleSetting('core', 'seo_noydir', false)) { $this->addMetaData(array('name' => 'robots', 'content' => 'noydir')); } }