/** * Set url * * @param string $url * @return CTA */ public function setOriginalUrl($url) { $this->originalUrl = ParserUtil::sanitizeUrl($url); return $this; }
/** * Set homepage * * @param string $homepage * @return System */ public function setHomepage($homepage) { $this->homepage = ParserUtil::sanitizeUrl($homepage); return $this; }
/** * Finds a Location by the URL and automatically creates the Location if it * does not exist and if the respective Location module supports auto * generation of Locations. ** * @param $url * @param $operation Operation * @return bool|Location|null|object */ public function findLocationByUrl($url, $operation, $alias = null) { $url = ParserUtil::sanitizeUrl($url); /* * If not a Location, then see if the URL is inside a connected * Channel's top-level Locations. To do so, check if one of these * criteria apply: * - The Location URL matches the beginning of the CTA URL * - The Location identifier is included in the CTA URL as well * as the domain */ if (ParserUtil::urlExists($url)) { $urlParts = parse_url($url); if ($urlParts['scheme'] == 'http') { $urlAltScheme = str_replace('http://', 'https://', $url); } elseif ($urlParts['scheme'] == 'https') { $urlAltScheme = str_replace('https://', 'http://', $url); } $repository = $this->em->getRepository('CampaignChainCoreBundle:Location'); $query = $repository->createQueryBuilder('location')->where("(:url LIKE CONCAT('%', location.url, '%')) OR " . "(:url_alt_scheme LIKE CONCAT('%', location.url, '%')) OR " . "(" . "location.identifier IS NOT NULL AND " . ":url LIKE CONCAT('%', location.identifier, '%') AND " . "location.url LIKE :host" . ")")->andWhere('location.parent IS NULL')->setParameter('url', $url)->setParameter('url_alt_scheme', $urlAltScheme)->setParameter('host', $urlParts['host'] . '%')->getQuery(); /** @var Location $matchingLocation */ $matchingLocation = $query->getOneOrNullResult(); if ($matchingLocation) { /* * Create a new Location based on the tracking alias * within the matching Location's Channel. * * If no tracking alias was provided, we take the * default LocationModule to create a new Location. */ if (!$alias) { // Done if the URL is exactly the same in the matching Location. if ($matchingLocation->getUrl() == $url || $matchingLocation->getUrl() == $urlAltScheme) { return $matchingLocation; } // Let's move on to create a new Location with the default module. $locationService = $this->container->get('campaignchain.core.location'); /** @var LocationModule $locationModule */ $locationModule = $locationService->getLocationModule(self::DEFAULT_LOCATION_BUNDLE_NAME, self::DEFAULT_LOCATION_MODULE_IDENTIFIER); if (!$locationModule) { throw new \Exception('No Location module found for bundle "' . $matchingLocation->getChannel()->getBundle()->getName() . ' and module ' . $matchingLocation->getChannel()->getChannelModule()->getIdentifier() . '"'); } } else { /* * Get the Location module within the matching Location's * Channel and with the given tracking alias. */ /** @var LocationModule $locationModule */ $locationModule = $this->getLocationModuleByTrackingAlias($matchingLocation->getChannel()->getChannelModule(), $alias); // Done if the matching Location also matches the alias and URL. if ($matchingLocation->getLocationModule() == $locationModule && ($matchingLocation->getUrl() == $url || $matchingLocation->getUrl() == $urlAltScheme)) { return $matchingLocation; } /* * See if there is already another Location that matches the * aliase's Location module and the URL. */ $repository = $this->em->getRepository('CampaignChainCoreBundle:Location'); $query = $repository->createQueryBuilder('location')->where('location.locationModule = :locationModule')->andWhere('(location.url = :url OR location.url = :url_alt_scheme')->setParameter('locationModule', $locationModule)->setParameter('url', $url)->setParameter('url_alt_scheme', $urlAltScheme)->getQuery(); /** @var Location $location */ $location = $query->getOneOrNullResult(); // We found an existing Location, we're done. if ($location) { return $location; } if (!$locationModule) { throw new \Exception('Cannot map tracking alias "' . $alias . '" to a "' . 'Location module that belongs to Channel module "' . $matchingLocation->getChannel()->getBundle()->getName() . '/' . $matchingLocation->getChannel()->getChannelModule()->getIdentifier() . '"'); } } /* * If the matching Location provides auto-generation of Locations, * then let's create a new child Location. */ $ctaServiceName = $locationModule->getServices()['job_cta']; if ($ctaServiceName) { // Create the new Location $location = new Location(); $location->setUrl($url); $location->setOperation($operation); $location->setChannel($matchingLocation->getChannel()); $location->setParent($matchingLocation); // Update the Location module to be the current // one. $location->setLocationModule($locationModule); // Let the module's service process the new // Location. $ctaService = $this->container->get($ctaServiceName); return $ctaService->execute($location); } else { throw new \Exception('No CTA Job service defined for Location module ' . 'of bundle "' . $locationModule->getBundle()->getName() . '" ' . 'and module "' . $locationModule->getIdentifier() . '"'); } } else { return false; } } throw new \Exception('The URL ' . $url . ' does not exist.'); }
/** * @param mixed $archiveUrlLong */ public function setArchiveUrlLong($archiveUrlLong) { $this->archiveUrlLong = ParserUtil::sanitizeUrl($archiveUrlLong); }
/** * Set coverInfoUrl * * @param string $coverInfoUrl * @return User */ public function setCoverInfoUrl($coverInfoUrl) { $this->coverInfoUrl = ParserUtil::sanitizeUrl($coverInfoUrl); return $this; }
/** * Set websiteUrl * * @param string $websiteUrl * @return User */ public function setWebsiteUrl($websiteUrl) { $this->websiteUrl = ParserUtil::sanitizeUrl($websiteUrl); return $this; }
/** * Search for a url in the message, * if we find one, then we fetch it * * @param NewsItemEntity $newsItem entity from the DB or the form context * @param NewsItemEntity $data entity from the form * @return NewsItemEntity */ private function searchUrl(NewsItemEntity $newsItem) { $pattern = '/[-a-zA-Z0-9:%_\\+.~#?&\\/\\/=]{2,256}\\.[a-z]{2,10}\\b(\\/[-a-zA-Z0-9:%_\\+.~#?&\\/\\/=]*)?/i'; if (!preg_match($pattern, $newsItem->getMessage(), $matches)) { // No link found, so set link data to null. return $this->unsetUrl($newsItem); } $url = $matches[0]; $result = $this->scrapeUrl($url); if (empty($result)) { return $this->unsetUrl($newsItem); } $newsItem->setLinkUrl(ParserUtil::sanitizeUrl($url)); $newsItem->setLinkTitle($result['title']); $newsItem->setLinkDescription($result['description']); return $newsItem; }
/** * Set profileUrl * * @param string $profileUrl * @return User */ public function setProfileUrl($profileUrl) { $this->profileUrl = ParserUtil::sanitizeUrl($profileUrl); return $this; }
/** * Set url * * @param string $url * @return Status */ public function setUrl($url) { $this->url = ParserUtil::sanitizeUrl($url); return $this; }
/** * Set registrationUrl * * @param string $registrationUrl * @return Webinar */ public function setRegistrationUrl($registrationUrl) { $this->registrationUrl = ParserUtil::sanitizeUrl($registrationUrl); return $this; }
/** * Set referrerUrl * * @param string $referrerUrl * @return ReportCTA */ public function setReferrerUrl($referrerUrl) { $this->referrerUrl = ParserUtil::sanitizeUrl($referrerUrl); return $this; }