/** * Get Menu Links * * Takes an array of pages and returns an array suitable for use in links. */ private function get_menu_links($pages) { global $DATA, $this_page; $links = array(); foreach ($pages as $page) { //get meta data $menu = $DATA->page_metadata($page, 'menu'); if ($menu) { $title = $menu['text']; } else { $title = $DATA->page_metadata($page, 'title'); } $url = $DATA->page_metadata($page, 'url'); $tooltip = $DATA->page_metadata($page, 'heading'); //check for external vs internal menu links if (!valid_url($url)) { $URL = new \URL($page); $url = $URL->generate(); } //make the link if ($page == $this_page) { $links[] = array('href' => '#', 'title' => '', 'classes' => '', 'text' => $title); } else { $links[] = array('href' => $url, 'title' => $tooltip, 'classes' => '', 'text' => $title); } } return $links; }
/** * Alter a URL before Semantic Proxy processes it. * * @param $url * The URL to alter. */ function hook_semanticproxy_url_alter(&$url) { // SemanticProxy obeys robots.txt and as such will not follow redirects, etc. For example, // RSS feeds for Google News Search will send you through Google News to redirect to the real source. // SemanticProxy will give a <em>Content Permissions Validator Exception</em> and not follow the // link b/c Google's robots.txt disallows following /news. We try to strip those out. $host = parse_url($url, PHP_URL_HOST); // Google's robot.txt disallows the follow by bots, so lets extract the real source if ($host == 'news.google.com') { $querystring = parse_url($url, PHP_URL_QUERY); // Split on &, but not if the & is in an html entity. This is a better impl of parse_str(). $args = preg_split('|&(?!.[a-z0-9]{1,6}+;)|ims', $querystring); if (!is_array($args)) { return; } // Process query string args, find the 'url' arg and return the value if it's a valid URL foreach ($args as $arg) { list($key, $val) = explode('=', $arg, 2); if ($key == 'url') { $val = urldecode($val); if (valid_url($val, TRUE)) { $url = $val; return; } } } } }
public function validate($form, &$form_state) { // Make sure the URL is valid. $url = $form_state['values']['url']; if ($url && !valid_url($url, true)) { form_set_error('url', t('That URL is invalid. You must enter an absolute URL.')); // TODO: Add logic to test the connection to the server and throw validation errors if it fails. } }
function setup() { //store callback url in viewstate if needed $callback = get_http_var('callback'); if (isset($callback)) { if (valid_url($callback)) { $callback = urldecode($callback); $this->viewstate['callback'] = $callback; } } }
function setup() { //store callback url in viewstate if needed $callback = get_http_var('callback'); if (isset($callback)) { if (valid_url($callback)) { $callback = urldecode($callback); $this->viewstate['callback'] = $callback; } } //create a new upload id and add to viewstate $this->viewstate['upload_key'] = md5(uniqid(rand(), true)); }
function setup() { //clear session session_delete("image_ids"); //store callback url in viewstate if needed $callback = get_http_var('callback'); if (isset($callback)) { if (valid_url($callback)) { $callback = urldecode($callback); $this->viewstate['callback'] = $callback; } } }
function setup() { $image_ids = session_read("image_ids"); if (!isset($image_ids) || count($image_ids) == 0) { redirect("addupload.php"); } //store callback url in viewstate if needed $callback = get_http_var('callback'); if (isset($callback)) { if (valid_url($callback)) { $callback = urldecode($callback); $this->viewstate['callback'] = $callback; } } }
/** * Validating the purl isn't duplicated. */ public function validateSinglePurl($field_name, $value, $wrapper, $property_wrapper) { $purl = $wrapper->domain->value(); $modifier = array('provider' => 'spaces_og', 'value' => $purl, 'id' => $wrapper->getIdentifier()); if (strlen($modifier['value']) < 3) { $this->setError('domain', 'The site address should be at least 3 characters.'); } if ($this->countPurlInstances($purl)) { $this->setError('domain', 'A site with this address already exists.'); } module_load_include('form.inc', 'vsite_register'); if (!valid_url($modifier['value']) || !_vsite_register_valid_url($modifier['value'])) { $this->setError('domain', 'The site address has invalid characters.'); } }
array_push($categories, (string) $cat); } $obj->categories = $categories; break; case 'description': $url = (string) $data->value->string; break; //this is used for title //this is used for title default: $obj->{$data->name} = (string) $data->value->string; } } //Make the webrequest //Only if we have a valid url if (valid_url($url, true)) { // Load Requests Library include 'requests/Requests.php'; Requests::register_autoloader(); $headers = array('Content-Type' => 'application/json'); $response = Requests::post($url, $headers, json_encode($obj)); if ($response->success) { success('<string>' . $response->status_code . '</string>'); } else { failure($response->status_code); } } else { //since the url was invalid, we return 400 (Bad Request) failure(400); } }
function email($to, $subject, $message) { $from = "*****@*****.**"; $header = "Content-Type: text/html" . "\r\n" . "From: {$from}"; $result = valid_url($message); if ($result == '1') { $message = file_get_contents($message); } $result = mail($to, $subject, $message, $header); }
function budgets_supplier_validate(&$node) { guifi_log(GUIFILOG_TRACE, 'function budgets_supplier_validate()', $node->op . '-' . $node->delete); if ($node->op == $node->delete) { return; } if (!$node->ack) { form_set_error('ack', t('You should accept the Terms & Conditions to proceed')); } if ($node->caps['caps_services']['isp'] > 2 and empty($node->certs['tp_certs']['ISP'])) { form_set_error('certs][tp_certs][ISP', t('You should have the NRA or equivalent certificate to operate as ISP')); } foreach ($node->certs as $type => $cert) { foreach ($cert as $key => $value) { if ($value != '') { // Using a date if (date('j/n/Y', $value) == FALSE) { form_set_error('certs][' . $type . '][' . $key, t('Date %date must be in dd/mm/YYYY format', array('%date' => $value))); } } } } /* foreach ($node->caps as $type =>$ap) { foreach ($cap as $key=>$value) { if ($value != '') { // Validate that capability is meant for volunteers if (date('j/n/Y',$value)==FALSE) form_set_error('caps]['.$type.']['.$key,t('Date %date must be in dd/mm/YYYY format',array('%date'=>$value))); } } } */ foreach ($node->zones as $k => $zone_str) { $zone = explode('-', $zone_str); // form_set_error('zones]['.$k,t('%zone is not a valid zone',array('%zone'=>$zone_str))); if ($zone_str != '') { $qzone = db_fetch_object(db_query('SELECT id FROM {guifi_zone} WHERE id=%d', $zone[0])); if (!$qzone->id) { form_set_error('zones][' . $k, t('%zone is not a valid zone', array('%zone' => $zone[0]))); } } } if (!is_numeric($node->default_tax_rate)) { form_set_error('default_tax_rate', t('%rate has to be numeric', array('%rate' => $node->default_tax_rate))); } if (!empty($node->web_url) and !valid_url($node->web_url)) { form_set_error('web_url', t('The URL %url is invalid. Please enter a fully-qualified URL, such as http://guifi.net/node/9876', array('%url' => $value['url']))); } foreach ($node->accounting_urls as $k => $value) { if (!empty($value['url'])) { if (!valid_url($value['url'], TRUE)) { form_set_error('accounting_urls][' . $k . '][url', t('The URL %url is invalid. Please enter a fully-qualified URL, such as http://guifi.net/node/9876', array('%url' => $value['url']))); } } if (!empty($value['node_id'])) { $n = explode('-', $value['node_id']); if (!is_numeric($n[0]) or guifi_get_nodename($n[0]) == NULL) { form_set_error('accounting_urls][' . $k . '][node_id', t('%s is not a valid node', array('%s' => $value['node_id']))); } } } }
/** * Validate the event form. */ function watersportkampen_bootstrap_event_save_validate($form, &$form_state) { $values = $form_state['values']; // Validate age. if ($values['age'] && !is_numeric($values['age'])) { form_set_error('age', t('Please fill in correct age')); } // Validate period. if ($values['when']['date_control']['type'] == 'period') { $period = $values['when']['date_control']['period']; // Form validation hasn't processed the dates values yet, so don't validate. if (!is_array($period['start_date']) && !is_array($period['end_date'])) { // The dates. try { CultureFeed_Cdb_Data_Calendar::validateDate($period['start_date']); CultureFeed_Cdb_Data_Calendar::validateDate($period['end_date']); } catch (UnexpectedValueException $e) { form_set_error('when][date_control][period', t('Please fill in correct date and time')); } // Order of dates. $start_date = strtotime($period['start_date']); $end_date = strtotime($period['end_date']); if ($start_date > $end_date) { form_set_error('when][date_control][period', t('Date field is invalid. The end date is earlier than the beginning date.')); } } } // Validate timestamps. if ($values['when']['date_control']['type'] == 'timestamps') { $timestamps = $values['when']['date_control']['timestamps']['stamps']; foreach ($timestamps as $key => $timestamp) { // Form validation hasn't processed the dates values yet, so don't validate. if (is_array($timestamp['date'])) { continue; } // The date. try { CultureFeed_Cdb_Data_Calendar::validateDate($timestamp['date']); } catch (UnexpectedValueException $e) { form_set_error('when][date_control][timestamps][stamps][' . $key, t('Please fill in correct date and time')); } // The times. $start_time = isset($timestamp['start_time']) ? strtotime($timestamp['start_time']) : ''; $end_time = isset($timestamp['end_time']) ? strtotime($timestamp['end_time']) : ''; if ($start_time && $end_time && $start_time > $end_time) { form_set_error('when][date_control][timestamps][stamps][' . $key, t('Date field is invalid. The end time is earlier than the beginning time.')); } } } // Validate weekscheme. if ($values['when']['date_control']['type'] == 'period' || $values['when']['date_control']['type'] == 'permanent') { $opening_times = $values['when']['date_control']['opening_times']; // Validate the weekscheme. if (!$opening_times['all_day']) { foreach ($opening_times['days'] as $day => $opening_times) { foreach ($opening_times as $key => $opening_time) { if (!empty($opening_time['open_from']) || !empty($opening_time['open_till'])) { $parents = array('when', 'date_control', 'opening_times', 'days', $day, $key); if (substr_count($opening_time['open_from'], ':') == 1) { $opening_time['open_from'] .= ':00'; form_set_value(array('#parents' => array_merge($parents, array('open_from'))), $opening_time['open_from'], $form_state); } if (substr_count($opening_time['open_till'], ':') == 1) { $opening_time['open_till'] .= ':00'; form_set_value(array('#parents' => array_merge($parents, array('open_till'))), $opening_time['open_till'], $form_state); } try { CultureFeed_Cdb_Data_Calendar::validateTime($opening_time['open_from']); } catch (Exception $e) { form_set_error('when][date_control][opening_times][days][' . $day . '][' . $key . '][open_from', t('Please fill in correct time.')); } try { CultureFeed_Cdb_Data_Calendar::validateTime($opening_time['open_till']); } catch (Exception $e) { form_set_error('when][date_control][opening_times][days][' . $day . '][' . $key . '][open_till', t('Please fill in correct time.')); } } } } } } // Validate copyright if (!empty($values['photo']['upload']) && $values['photo']['copyright'] != 1) { form_set_error('photo', t('Please agree to the general conditions of UiTdatabank and declare that you have the necessary rights or permissions to distribute the image through UiTdatabank.')); } if (!empty($values['photo']['upload']) && empty($values['photo']['copyright_text'])) { form_set_error('photo', t('Copyright field is required.')); } // Validate location $location = culturefeed_entry_ui_location_form_validate($form, $form_state); // Validate Links $i = 0; foreach ($values['links'] as $link_data) { if (!empty($link_data['URL'])) { if (!preg_match("@^https?://@", $link_data['URL'])) { $link_data['URL'] = 'http://' . $link_data['URL']; } if (!valid_url($link_data['URL'], TRUE)) { form_set_error('links][' . $i . '][URL', t('Not a valid URL')); } } $i++; } // Validate organiser. if (!empty($values['organiser']['actor']['organiser_actor_id'])) { try { $organiser = culturefeed_search_item_load($values['organiser']['actor']['organiser_actor_id'], 'actor'); if (!$organiser) { form_set_error('organiser', t('We could not validate the organizer')); } } catch (Exception $e) { watchdog_exception('culturefeed_entry_ui', $e); form_set_error('organiser', t('We could not validate the organizer')); } } else { $organiser = NULL; } foreach ($values['wrapper'] as $extra) { if (is_array($extra)) { // Contacts if (!empty($extra['channel_input'])) { //if mail is selected if ($extra['channel'] == 1) { if (!valid_email_address($extra['channel_input'])) { form_set_error('channel_input', t('Not a valid email address')); } } } } } $errors = form_get_errors(); if (empty($errors)) { _watersportkampen_bootstrap_event_form_save_event($form, $form_state, $location, $organiser); } }
function dynacouncil_create_virtual() { global $wpdb; $url = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); $result = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . 'dynacouncil' . " WHERE council_id = " . $url . " ORDER BY id DESC LIMIT 1"); if ($result) { // if($url == '534') // { // foreach($) $council_website = valid_url($result[0]->council_website); $deputy_website = valid_url($result[0]->deputy_url, $result[0]->district_deputy . '<br/>District Deputy #' . $result[0]->deputy_number); $insurance_website = valid_url($result[0]->insurance_url, $result[0]->insurance_representative); $fourth_website = valid_url($result[0]->fourth_degree_url, $result[0]->fourth_degree_council); // is_url($result[0]->council_website) ? $council_website = '<a href="' . $result[0]->council_website . '">' . $result[0]->council_website . '</a>' : $result[0]->council_website ; $args = array('slug' => 'councils/' . $result[0]->council_id, 'title' => 'Council #' . $result[0]->council_id . ' - ' . $result[0]->council_name, 'content' => '<strong>District Deputy</strong><br/>' . $deputy_website . '<br/><br/>' . '<strong>Insurance Representative</strong><br/>' . $insurance_website . '<br/><br/>' . '<strong>Council Contact</strong><br/>' . $result[0]->council_contact_title . '<br/>' . $result[0]->council_contact_name . '<br/>Phone: ' . $result[0]->council_contact_phone . '<br/>Email: ' . $result[0]->council_contact_email . '<br/><br/>' . '<strong>Meeting Time and Location</strong><br/>' . $result[0]->meeting_time . '<br/><br/>' . $result[0]->meeting_location . '<br/>' . $result[0]->meeting_address . '<br/><br/>' . '<strong>Website</strong><br/>' . $council_website . '<br/><br/>' . '<strong>4th Degree Assembly Serving This Council</strong><br/>' . $fourth_website); $pg = new DynacouncilVirtualPage($args); } // } }
/** * Process inline images.. * * @param \Swift_Message $m * The message which inline images are to be added to. * @param array $images * The images which are to be added as inline images to the provided * message. */ protected function embed(\Swift_Message $m, array $images) { // Iterate through each array element. foreach ($images as $image) { if ($image instanceof \stdClass) { // Validate required fields. if (empty($image->uri) || empty($image->filename) || empty($image->filemime) || empty($image->cid)) { continue; } // Keep track of the 'cid' assigned to the embedded image. $cid = NULL; // Get image data. if (valid_url($image->uri, TRUE)) { $content = file_get_contents($image->uri); } else { $content = file_get_contents(drupal_realpath($image->uri)); } $filename = $image->filename; $filemime = $image->filemime; // Embed image. $cid = $m->embed(\Swift_Image::newInstance($content, $filename, $filemime)); // The provided 'cid' needs to be replaced with the 'cid' returned // by the Swift Mailer library. $body = $m->getBody(); $body = preg_replace('/cid.*' . $image->cid . '/', $cid, $body); $m->setBody($body); } } }
/** * Validate social urls with valid_url(); */ function fontfolio_social_url_validate($element, &$form_state, $form) { if ($element['#value'] && !valid_url($element['#value'], TRUE)) { form_set_error($element['#name'], t('The @social_url is not valid URL. Please try to copy/paste it one more time.', array('@social_url' => $element['#title']))); } }
public static function normalizeDataToSimpleXml($data, $class_name = NULL, $options = LIBXML_NOCDATA) { if (is_object($data) && is_a($data, 'SimpleXMLElement')) { return $data; } elseif (is_file($data) || valid_url($data, TRUE)) { $xml = simplexml_load_file($data, $class_name, $options); if ($xml === FALSE) { throw new Exception("Unable to parse XML from {$data}"); } else { return $xml; } } else { $xml = simplexml_load_string((string) render($data), $class_name, $options); if ($xml === FALSE) { throw new Exception("Unable to parse XML"); } else { return $xml; } } }
/** * Function to check if the specified file URL is valid or not */ function is_valid_file_url($url) { // replace space characters in the URL with '%20' to support file name // with space characters $url = preg_replace('/\\s/', '%20', $url); if (!valid_url($url, true)) { return false; } // URL end with slach (/) and no file name if (preg_match('/\\/$/', $url)) { return false; } // in case of FTP, we just return TRUE (the file exists) if (preg_match('/ftps?:\\/\\/.*/i', $url)) { return true; } // extract file name and extention $filename = basename($url); $extension = explode(".", $filename); // file name does not have extension if (($num = count($extension)) <= 1) { return false; } $ext = $extension[$num - 1]; // get valid extensions settings from Drupal $result = db_query("SELECT value FROM {variable} \n WHERE name = :name", array(':name' => 'pubdlcnt_valid_extensions'))->fetchField(); $valid_extensions = unserialize($result); if (!empty($valid_extensions)) { // check if the extension is a valid extension or not (case insensitive) $s_valid_extensions = strtolower($valid_extensions); $s_ext = strtolower($ext); $s_valid_ext_array = explode(" ", $s_valid_extensions); if (!in_array($s_ext, $s_valid_ext_array)) { return false; } } // if (!url_exists($url)) { // // Since this is not running for ECF, we'll comment it. // return false; // } return true; // it seems that the file URL is valid }
public function get_menu_links($pages) { global $DATA, $this_page; $links = array(); foreach ($pages as $page) { //get meta data $menu = $DATA->page_metadata($page, 'menu'); if ($menu) { $title = $menu['text']; } else { $title = $DATA->page_metadata($page, 'title'); } $url = $DATA->page_metadata($page, 'url'); //check for external vs internal menu links if (!valid_url($url)) { $URL = new URL($page); $url = $URL->generate(); } //make the link if ($page == $this_page) { $links[] = $title; } else { $links[] = '<a href="' . $url . '">' . $title . '</a>'; } } return $links; }
} else { //get him to the the respected link header("Location: " . $url); } } else { //tag not found $message = <<<MSG The tag you specified, <b><u>{$request_uri}</u></b> is not yet linked to any URL. That also mean that it is available and you can use it to link one of your URL.<br/> Enter a URL you want to link to the tag <b><u>{$request_uri}</u></b><br/><br/><form name='linkurl' action='#'> <input name='url' type='text' size='30' style="border: 1px #000000 solid; solid;text-align: center;font-family: 'Arial, Sans-Serif';font-size:16px;background-color: #B1B1B1;padding: 5px;" onkeydown="if (event.keyCode==13) {document.linkurl.url.click();}" /> <input type='button' value='Link it!' onclick="parent.location='{$FULLPATH}{$request_uri}|'+document.linkurl.url.value"/> </form> MSG; } } elseif (valid_url($request_uri)) { if ($tag = register_url($request_uri)) { //tag registration successful //store this info and take it to the tag page where he will be congratulated $_SESSION['newtag'] = $tag; header("Location: " . $FULLPATH . $tag); } else { //the URL was valid but some error occured. Contact the admin. die('<br/>An error occured, URL not registered'); } } elseif ($tag_url = get_tag_url($request_uri)) { if ($tag = register_url_tag($tag_url[1], $tag_url[0])) { //15min $_SESSION['newtag'] = $tag; header("Location: " . $FULLPATH . $tag); } else {
/** * Get the redirect_url for this webform as used by the submit handler. * * This is mainly a c&p of the relevant parts of * @see webform_client_form_submit(). */ public function getRedirect($submission = NULL) { $node = $this->node; $redirect_url = $node->webform['redirect_url']; // Clean up the redirect URL and filter it for webform tokens. $redirect_url = trim($node->webform['redirect_url']); if ($submission) { $redirect_url = _webform_filter_values($redirect_url, $node, $submission, NULL, FALSE, TRUE); } // Remove the domain name from the redirect. $redirect_url = preg_replace('/^' . preg_quote($GLOBALS['base_url'], '/') . '\\//', '', $redirect_url); if ($redirect_url == '<none>') { return NULL; } elseif ($redirect_url == '<confirmation>') { $options = array(); if ($submission) { $options['query']['sid'] = $submission->sid; } return array('node/' . $node->nid . '/done', $options); } elseif (valid_url($redirect_url, TRUE)) { return $redirect_url; } elseif ($redirect_url && strpos($redirect_url, 'http') !== 0) { $parts = \Drupal\Component\Utility\UrlHelper::parse($redirect_url); if ($submission) { $parts['query']['sid'] = $submission->sid; } $query = $parts['query']; return array($parts['path'], array('query' => $query, 'fragment' => $parts['fragment'])); } return $redirect_url; }