public function executeGet_button(sfWebRequest $request) { $this->getResponse()->setContentType('application/json'); $lParams = $request->getParameter('likebutton'); $lUrl = "http://www.spreadly.com"; $lSocial = 0; if (isset($lParams['url']) && UrlUtils::isUrlValid($lParams['url'])) { $lUrl = $lParams['url']; } if (isset($lParams['wt']) && $lParams['wt'] == 'stand_social') { $lSocial = 1; } if (isset($lParams['text'])) { $lLabel = $lParams['text']; } if (isset($lParams['color'])) { $lColor = $lParams['color']; } $lService = isset($lParams['service']) ? $lParams['service'] : null; $lReturn['iframe'] = $this->getPartial('configurator/preview_widgets', array('pUrl' => $lUrl, 'pSocial' => $lSocial, 'pService' => $lService)); return $this->renderText(json_encode($lReturn)); }
public function executeTracking_url(sfWebRequest $request) { $this->info = $this->error = null; $host_id = $request->getParameter("host_id", null); if (!$host_id) { $this->redirect('domain_profiles/index'); } $domainProfile = DomainProfileTable::getInstance()->find($host_id); if ($request->getMethod() == "POST") { $trackingUrl = $request->getParameter("tracking_url", null); if (trim($trackingUrl)) { if (UrlUtils::isUrlValid($trackingUrl)) { $domainProfile->setTrackingUrl($trackingUrl); $domainProfile->save(); $this->info = "URL successfully saved."; } else { $this->error = "URL is not valid."; } } else { $domainProfile->setTrackingUrl(null); $domainProfile->save(); $this->info = "URL successfully deleted."; } } $this->domainProfile = $domainProfile; }
/** * shortens a valid url and returns a short url * * @param string $pUrl * @return string * @throws ModelException */ public static function shortenUrl($pUrl) { $lUrl = urldecode($pUrl); $lUrl = str_replace(" ", "+", $lUrl); if (!UrlUtils::isUrlValid($lUrl)) { throw new ModelException("invalid url"); } if ($lShortUrl = self::getByUrl($lUrl)) { return $lShortUrl->getShortedUrl(); } else { $lShortUrl = new ShortUrl(); $lShortUrl->setUrl($lUrl); $lShortUrl->save(); return $lShortUrl->getShortedUrl(); } }
/** * auto links a url * * @param string $text_or_link * @param int $truncate_after * @param array $options */ function auto_link_to($text_or_link, $truncate_after = 30, $options = array()) { if (UrlUtils::isUrlValid($text_or_link)) { $options['title'] = $text_or_link; return link_to(truncate_text($text_or_link, $truncate_after), $text_or_link, $options); } else { return $text_or_link; } }
/** * a simple validator * * */ public function validate() { $errors = array(); $required = array('name', 'motivation_title', 'motivation_text', 'spread_title', 'spread_text', 'spread_url', 'spread_img', 'spread_tos', 'coupon_type', 'coupon_title', 'coupon_text', 'billing_type', 'target_quantity'); if ($this->getCouponType() == "url") { $required[] = "coupon_url"; } elseif ($this->getCouponType() == "code") { $required[] = "coupon_code"; $required[] = "coupon_redeem_url"; } elseif ($this->getCouponType() == "download") { $required[] = "coupon_url"; } elseif ($this->getCouponType() == "unique_code") { $required[] = "webhook_url"; $required[] = "coupon_redeem_url"; } // check required fields foreach ($required as $field) { if (empty($this->{$field})) { $errors[] = "'" . $field . "' is required"; } } $url_fields = array('spread_url', 'coupon_url', 'coupon_webhook_url', 'coupon_redeen_url', 'spread_tos'); // validate url fields foreach ($url_fields as $field) { if (!empty($this->{$field}) && !UrlUtils::isUrlValid($this->{$field})) { $errors[] = "'" . $field . "' must be a valid url"; } } $int_fields = array('target_quantity'); // validate int fields foreach ($int_fields as $field) { if (!empty($this->{$field}) && !is_numeric($this->{$field})) { $errors[] = "'" . $field . "' must be of type float"; } } if (count($errors) > 0) { return $errors; } else { return true; } }