/** * Construct a new website validator instance * @param array $options options for this instance * @return null */ public function __construct(array $options = array()) { parent::__construct($options); $this->regex = '/^' . $this->regexHttp . '$/'; $this->code = self::CODE; $this->message = self::MESSAGE; }
/** * Construct a new e-mail address validator * @param array $options options for this validator * @return null */ public function __construct(array $options = array()) { parent::__construct($options); $regexEmail = '(' . $this->regexAlphaDigit . '|' . $this->regexSafe . ')+@' . $this->regexHostName; $this->regex = '/^' . $regexEmail . '$/'; $this->code = self::CODE; $this->message = self::MESSAGE; }
/** * Construct the validator * @param array $options options for the validator, not applicable on this implementation * @return null */ public function __construct(array $options = array()) { parent::__construct($options); $tokenChars = $this->regexAlphaDigit . '|[_-]|\\.'; $regexDatabase = '(\\/(' . $tokenChars . ')+)*\\/(' . $tokenChars . ')+'; $regexDsn = $this->regexScheme . ':\\/\\/(' . $this->regexLogin . ')?' . $regexDatabase; $this->regex = '/^' . $regexDsn . '$/'; $this->code = self::CODE; $this->message = self::MESSAGE; }
/** * Transform and validate the url params in config;. */ public function validateConfigs() { $urlValidator = new UrlValidator(); $urlValidator->urlParams = $this->urlParams; $urlValidator->transformUrlParams($this->appConfigs); $this->urlParams = $urlValidator->urlParams; }
public function edit($params) { if (!isset($params['id']) || !($id = (int) $params['id'])) { throw new Redirect404Exception(); return; } $language = OW::getLanguage(); $config = OW::getConfig(); $sponsor = SPONSORS_BOL_Service::getInstance()->findSponsorById($id); if (!$sponsor->id) { throw new Redirect404Exception(); return; } $sponsorForm = new Form('sponsorForm'); $sponsorForm->setEnctype('multipart/form-data'); $element = new TextField('sponsorName'); $element->setRequired(true); $element->setLabel($language->text('sponsors', 'sponsor_name')); $element->setInvitation($language->text('sponsors', 'sponsor_name_desc')); $element->setValue($sponsor->name); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorEmail'); $element->setRequired(true); $validator = new EmailValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_email_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_email')); $element->setInvitation($language->text('sponsors', 'sponsor_email_desc')); $element->setValue($sponsor->email); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorWebsite'); $element->setRequired(true); $validator = new UrlValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_url_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_website')); $element->setInvitation($language->text('sponsors', 'sponsor_website_desc')); $element->setHasInvitation(true); $element->setValue($sponsor->website); $sponsorForm->addElement($element); $element = new TextField('sponsorAmount'); $element->setRequired(true); $minAmount = $config->getValue('sponsors', 'minimumPayment'); $validator = new FloatValidator(0); $validator->setErrorMessage($language->text('sponsors', 'invalid_amount_value')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_payment_amount')); $element->setInvitation($language->text('sponsors', 'admin_payment_amount_desc')); $element->setHasInvitation(true); $element->setValue($sponsor->price); $sponsorForm->addElement($element); $element = new TextField('sponsorValidity'); $element->setRequired(true); $element->setValue($sponsor->validity); $validator = new IntValidator(0); $validator->setErrorMessage($language->text('sponsors', 'invalid_numeric_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsorship_validatity')); $element->setInvitation($language->text('sponsors', 'sponsorship_validatity_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new FileField('sponsorImage'); $element->setLabel($language->text('sponsors', 'sponsorsh_image_file')); $sponsorForm->addElement($element); $element = new Submit('editSponsor'); $element->setValue(OW::getLanguage()->text('sponsors', 'edit_sponsor_btn')); $sponsorForm->addElement($element); if (OW::getRequest()->isPost()) { if ($sponsorForm->isValid($_POST)) { $values = $sponsorForm->getValues(); $allowedImageExtensions = array('jpg', 'jpeg', 'gif', 'png', 'tiff'); $sponsorImageFile = ""; if (isset($_FILES['sponsorImage']) && in_array(UTIL_File::getExtension($_FILES['sponsorImage']['name']), $allowedImageExtensions)) { $backupPath = OW::getPluginManager()->getPlugin('sponsors')->getUserFilesDir() . $_FILES['sponsorImage']['name']; move_uploaded_file($_FILES['sponsorImage']['tmp_name'], $backupPath); $sponsorImageFile = $_FILES['sponsorImage']['name']; } $sponsor->name = $values['sponsorName']; $sponsor->email = $values['sponsorEmail']; $sponsor->website = $values['sponsorWebsite']; $sponsor->price = $values['sponsorAmount']; if (!empty($sponsorImageFile)) { $sponsor->image = $sponsorImageFile; } $sponsor->userId = $sponsor->userId; $sponsor->status = $sponsor->status; $sponsor->validity = $values['sponsorValidity']; if (SPONSORS_BOL_Service::getInstance()->addSponsor($sponsor)) { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_edit_ok')); } else { OW::getFeedback()->error(OW::getLanguage()->text('sponsors', 'sponsor_edit_error')); } } } $this->addForm($sponsorForm); $fields = array(); foreach ($sponsorForm->getElements() as $element) { if (!$element instanceof HiddenField) { $fields[$element->getName()] = $element->getName(); } } $this->assign('formData', $fields); $this->assign('currentLogoImage', OW::getPluginManager()->getPlugin('sponsors')->getUserFilesUrl() . $sponsor->image); $this->setPageHeading(OW::getLanguage()->text('sponsors', 'edit_sponsor_heading')); $this->setPageTitle(OW::getLanguage()->text('sponsors', 'edit_sponsor_heading')); $this->setPageHeadingIconClass('ow_ic_edit'); }
/** * Reformat * * Attempts to reformat a URL string to replace missing data parts, * IE if the URL does not have HTTP : or // prefixes, * * @param string $url Url to format * @throws InvalidArgumentException If the URL string is empty * @return Returns an array containing the original and reformatted URL * if the new URL validates. Returns FALSE otherwise. */ public static function reformat($url) { $url = trim($url); if (strlen($url) <= 0) { throw new \InvalidArgumentException('URL string cannot be empty.', 0); } preg_match('/(http)?(:)?(\\/\\/)?(www.|www2.)?([a-zA-Z0-9-]{0,})?([.a-z]{3,4})?/i', $url, $matches); $prefix = strlen($matches[1]) < 4 ? 'http' : $matches[1]; $colon = strlen($matches[2]) < 1 ? ':' : $matches[2]; $slashes = strlen($matches[3]) < 2 ? '//' : $matches[3]; // WWW or www2 is not required for a valid URL so accept empty results $www = $matches[4]; $primaryUrl = !isset($matches[5]) ? '' : $matches[5]; $postfix = !isset($matches[6]) ? '.com' : $matches[6]; $newUrl = $prefix . $colon . $slashes . $www . $primaryUrl . $postfix; if (UrlValidator::validate($newUrl)) { return array('original' => $url, 'url' => $newUrl); } return false; }
public function __construct() { parent::__construct(); }
public function isValid($value) { if (!empty($_POST['local-url']) && empty($_POST['external-url'])) { return true; } if (!empty($_POST['external-url'])) { return parent::isValid($_POST['external-url']); } return false; }
public function manage($params) { $groupId = (int) $params['groupId']; if (empty($groupId)) { throw new Redirect404Exception(); } $service = GROUPS_BOL_Service::getInstance(); $feedService = GROUPRSS_BOL_FeedService::getInstance(); $language = OW::getLanguage(); $config = OW::getConfig(); $userId = OW::getUser()->getId(); $groupDto = $service->findGroupById($groupId); if ($groupDto === null) { throw new Redirect404Exception(); } $whoCanAdd = $config->getValue('grouprss', 'actionMember'); if ($whoCanAdd == 'admin' && !OW::getUser()->isAdmin()) { throw new Redirect404Exception(); } $mypaths = explode("/", UTIL_Url::selfUrl()); $groupId = strtolower(end($mypaths)); if ($groupId == 'customize') { $groupId = strtolower(prev($mypaths)); } if ($whoCanAdd == 'creator' && $feedService->getGroupCreater($groupId) !== $userId) { throw new Redirect404Exception(); } if ($whoCanAdd == 'both') { if (!OW::getUser()->isAdmin() && $feedService->getGroupCreater($groupId) !== $userId) { throw new Redirect404Exception(); } } $userList = $service->findGroupUserIdList($groupId); $userService = BOL_UserService::getInstance(); $feedService = GROUPRSS_BOL_FeedService::getInstance(); $newForm = new Form('newForm'); $element = new Selectbox('feedUser'); $element->setLabel($language->text('grouprss', 'newsfeed_user')); $element->setRequired(); foreach ($userList as $key => $user) { $element->addOption($user, $userService->getDisplayName($user)); } $newForm->addElement($element); $element = new TextField('feedUrl'); $element->setRequired(true); $validator = new UrlValidator(); $validator->setErrorMessage($language->text('grouprss', 'invalid_feed_url')); $element->addValidator($validator); $element->setLabel($language->text('grouprss', 'new_feed_url')); $newForm->addElement($element); $element = new TextField('feedCount'); $element->setValue("2"); $element->setRequired(); $element->setLabel(OW::getLanguage()->text('grouprss', 'user_feed_count')); $validator = new IntValidator(1, 50); $validator->setErrorMessage(OW::getLanguage()->text('grouprss', 'invalid_feed_count_error')); $element->addValidator($validator); $newForm->addElement($element); $element = new Submit('addFeed'); $element->setValue(OW::getLanguage()->text('grouprss', 'add_new_feed')); $newForm->addElement($element); if (OW::getRequest()->isPost()) { if ($newForm->isValid($_POST)) { $values = $newForm->getValues(); $userId = $values['feedUser']; $feedUrl = $values['feedUrl']; $feedCount = $values['feedCount']; if ($feedService->isDuplicate($groupId, $feedUrl)) { OW::getFeedback()->error($language->text('grouprss', 'add_feed_duplicate_error')); } else { $feedService->addFeed($groupId, $userId, $feedUrl, $feedCount); OW::getFeedback()->info($language->text('grouprss', 'add_feed_success')); GROUPRSS_BOL_FeedService::getInstance()->addAllGroupFeed(); } } } $this->addForm($newForm); $allFeeds = $feedService->findByGroup($groupId); $feedDetails = array(); $deleteFeeds = array(); foreach ($allFeeds as $feed) { $feedDetails[$feed->id]['feedID'] = $feed->id; $feedDetails[$feed->id]['groupID'] = $feed->groupId; $feedDetails[$feed->id]['userID'] = $feed->userId; $feedDetails[$feed->id]['userName'] = $userService->getDisplayName($feed->userId); $feedDetails[$feed->id]['userURL'] = $userService->getUserUrl($feed->userId); $feedDetails[$feed->id]['feedURL'] = $feed->feedUrl; $feedDetails[$feed->id]['feedCount'] = $feed->feedCount; $feedDetails[$feed->id]['timestamp'] = $feed->timestamp; $deleteFeeds[$feed->id] = OW::getRouter()->urlFor(__CLASS__, 'delete', array('id' => $feed->id, 'groupId' => $groupId)); } $this->assign('feedDetails', $feedDetails); $this->assign('deleteFeeds', $deleteFeeds); OW::getDocument()->addStyleSheet(OW::getPluginManager()->getPlugin('grouprss')->getStaticCssUrl() . 'style.css'); OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('grouprss')->getStaticJsUrl() . 'jquery.tablesorter.min.js'); $this->setPageHeading(OW::getLanguage()->text('grouprss', 'manage_settings_title')); $this->setPageTitle(OW::getLanguage()->text('grouprss', 'manage_settings_title')); $this->setPageHeadingIconClass('ow_ic_gear_wheel'); }
public function sponsor() { $language = OW::getLanguage(); $config = OW::getConfig(); $sponsorForm = new Form('sponsorForm'); $sponsorForm->setEnctype('multipart/form-data'); $element = new TextField('sponsorName'); $element->setRequired(true); $element->setLabel($language->text('sponsors', 'sponsor_name')); $element->setInvitation($language->text('sponsors', 'sponsor_name_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorEmail'); $element->setRequired(true); $validator = new EmailValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_email_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_email')); $element->setInvitation($language->text('sponsors', 'sponsor_email_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorWebsite'); $element->setRequired(true); $validator = new UrlValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_url_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_website')); $element->setInvitation($language->text('sponsors', 'sponsor_website_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); if ($config->getValue('sponsors', 'minimumPayment') > 0) { $element = new TextField('sponsorAmount'); $element->setRequired(true); $element->setValue($config->getValue('sponsors', 'minimumPayment')); $minAmount = $config->getValue('sponsors', 'minimumPayment'); $validator = new FloatValidator($minAmount); $validator->setErrorMessage($language->text('sponsors', 'invalid_sponsor_amount', array('minAmount' => $minAmount))); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_payment_amount')); $element->setInvitation($language->text('sponsors', 'sponsor_payment_amount_desc', array('minAmount' => $minAmount))); $element->setHasInvitation(true); $sponsorForm->addElement($element); } $element = new FileField('sponsorImage'); $element->setLabel($language->text('sponsors', 'sponsorsh_image_file')); $sponsorForm->addElement($element); if ($config->getValue('sponsors', 'minimumPayment') > 0) { $element = new BillingGatewaySelectionField('gateway'); $element->setRequired(true); $element->setLabel($language->text('sponsors', 'payment_gatway_selection')); $sponsorForm->addElement($element); } $element = new Submit('becomeSponsor'); $element->setValue(OW::getLanguage()->text('sponsors', 'become_sponsor_btn')); $sponsorForm->addElement($element); if (OW::getRequest()->isPost()) { if ($sponsorForm->isValid($_POST)) { $values = $sponsorForm->getValues(); if (isset($_FILES['sponsorImage']) && in_array(UTIL_File::getExtension($_FILES['sponsorImage']['name']), $this->allowedImageExtensions)) { $backupPath = OW::getPluginManager()->getPlugin('sponsors')->getUserFilesDir() . $_FILES['sponsorImage']['name']; move_uploaded_file($_FILES['sponsorImage']['tmp_name'], $backupPath); $sponsorImageFile = $_FILES['sponsorImage']['name']; } else { $sponsorImageFile = "defaultSponsor.jpg"; } if (isset($values['sponsorAmount']) && $values['gateway']) { $billingService = BOL_BillingService::getInstance(); if (empty($values['gateway']['url']) || empty($values['gateway']['key']) || !($gateway = $billingService->findGatewayByKey($values['gateway']['key']) || !$gateway->active)) { OW::getFeedback()->error($language->text('base', 'billing_gateway_not_found')); $this->redirect(); } $productAdapter = new SPONSORS_CLASS_SponsorProductAdapter(); $sale = new BOL_BillingSale(); $sale->pluginKey = 'sponsors'; $sale->entityDescription = $language->text('sponsors', 'sponsor_payment_gateway_text'); $sale->entityKey = $productAdapter->getProductKey(); $sale->entityId = time(); $sale->price = floatval($values['sponsorAmount']); $sale->period = null; $sale->userId = OW::getUser()->getId() ? OW::getUser()->getId() : 0; $sale->recurring = 0; $extraData = array(); $extraData['sponsorName'] = $values['sponsorName']; $extraData['sponsorEmail'] = $values['sponsorEmail']; $extraData['sponsorWebsite'] = $values['sponsorWebsite']; $extraData['sponsorAmount'] = $values['sponsorAmount']; $extraData['sponsorImage'] = $sponsorImageFile; $extraData['status'] = $config->getValue('sponsors', 'autoApprove') == '1' ? 1 : 0; $extraData['validity'] = $config->getValue('sponsors', 'sponsorValidity'); $sale->setExtraData($extraData); $saleId = $billingService->initSale($sale, $values['gateway']['key']); if ($saleId) { $billingService->storeSaleInSession($saleId); $billingService->setSessionBackUrl($productAdapter->getProductOrderUrl()); OW::getApplication()->redirect($values['gateway']['url']); } } else { $sponsor = new SPONSORS_BOL_Sponsor(); $sponsor->name = $values['sponsorName']; $sponsor->email = $values['sponsorEmail']; $sponsor->website = $values['sponsorWebsite']; $sponsor->price = 0; $sponsor->image = $sponsorImageFile; $sponsor->userId = OW::getUser()->getId() ? OW::getUser()->getId() : 0; $sponsor->status = $config->getValue('sponsors', 'autoApprove') == '1' ? 1 : 0; $sponsor->validity = $config->getValue('sponsors', 'sponsorValidity'); $sponsor->timestamp = time(); if (SPONSORS_BOL_Service::getInstance()->addSponsor($sponsor)) { if ($sponsor->status == 1) { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_live_notification')); } else { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_live_notification_after_approval')); } } else { OW::getFeedback()->error(OW::getLanguage()->text('sponsors', 'sponsor_add_error')); } } } } $this->addForm($sponsorForm); $fields = array(); foreach ($sponsorForm->getElements() as $element) { if (!$element instanceof HiddenField) { $fields[$element->getName()] = $element->getName(); } } $this->assign('formData', $fields); $this->setPageHeading(OW::getLanguage()->text('sponsors', 'become_sponsor_heading')); $this->setPageTitle(OW::getLanguage()->text('sponsors', 'become_sponsor_title')); $this->setPageHeadingIconClass('ow_ic_gear_wheel'); }