Example #1
0
 private static function generateRepo($name_, $node_)
 {
     $uri = $node_->getAttribute('uri');
     if ($node_->hasAttribute('login') && $node_->hasAttribute('password')) {
         $uri = unparse_url(array_merge(parse_url($uri), array('user' => $node_->getAttribute('login'), 'pass' => $node_->getAttribute('password'))));
     }
     return array('DISPLAY' => $name_, 'DRIVER' => 'fs', 'DRIVER_OPTIONS' => array('PATH' => $uri, 'CREATE' => false, 'RECYCLE_BIN' => '', 'CHMOD_VALUE' => '0660', 'DEFAULT_RIGHTS' => '', 'PAGINATION_THRESHOLD' => 500, 'PAGINATION_NUMBER' => 200));
 }
Example #2
0
 public static function form()
 {
     $args = func_get_args();
     $options = array_pop($args);
     // use empty string as default action
     if (!isset($options['hash']['action'])) {
         $options['hash']['action'] = "";
     }
     // use GET method as default
     if (!isset($options['hash']['method'])) {
         $options['hash']['method'] = 'get';
     }
     // evaluate action url
     $app_key = \Hook\Application\Context::getKey();
     $action_url = parse_url($options['hash']['action']);
     if (!isset($action_url['query'])) {
         $action_url['query'] = 'X-App-Id=' . $app_key->app_id . '&X-App-Key=' . $app_key->key;
     }
     $options['hash']['action'] = unparse_url($action_url);
     $html = '<form' . html_attributes($options['hash']) . '>' . "\n" . $options['fn']() . '</form>';
     return $html;
 }
Example #3
0
 /**
  * Rebuild a full-featured URL
  */
 public function testUnparseFull()
 {
     $ref = 'http://*****:*****@hostname:9090/path' . '?arg1=value1&arg2=value2#anchor';
     $this->assertEquals($ref, unparse_url(parse_url($ref)));
 }
Example #4
0
/**
 * Enter description here...
 *
 * @param unknown_type $base
 * @param unknown_type $url
 * @return unknown
 * @author adrian-php at sixfingeredman dot net
 */
function resolve_url($base, $url)
{
    if (!strlen($base)) {
        return $url;
    }
    // Step 2
    if (!strlen($url)) {
        return $base;
    }
    // Step 3
    if (preg_match('!^[a-z]+:!i', $url)) {
        return $url;
    }
    $base = parse_url($base);
    if ($url[0] == "#") {
        // Step 2 (fragment)
        $base['fragment'] = substr($url, 1);
        return unparse_url($base);
    }
    unset($base['fragment']);
    unset($base['query']);
    if (substr($url, 0, 2) == "//") {
        // Step 4
        return unparse_url(array('scheme' => $base['scheme'], 'path' => substr($url, 2)));
    } else {
        if ($url[0] == "/") {
            // Step 5
            $base['path'] = $url;
        } else {
            // Step 6
            $path = explode('/', $base['path']);
            $url_path = explode('/', $url);
            // Step 6a: drop file from base
            array_pop($path);
            // Step 6b, 6c, 6e: append url while removing "." and ".." from
            // the directory portion
            $end = array_pop($url_path);
            foreach ($url_path as $segment) {
                if ($segment == '.') {
                    // skip
                } else {
                    if ($segment == '..' && $path && $path[sizeof($path) - 1] != '..') {
                        array_pop($path);
                    } else {
                        $path[] = $segment;
                    }
                }
            }
            // Step 6d, 6f: remove "." and ".." from file portion
            if ($end == '.') {
                $path[] = '';
            } else {
                if ($end == '..' && $path && $path[sizeof($path) - 1] != '..') {
                    $path[sizeof($path) - 1] = '';
                } else {
                    $path[] = $end;
                }
            }
            // Step 6h
            $base['path'] = join('/', $path);
        }
    }
    // Step 7
    return glue_url($base);
}
Example #5
0
    /**
     * Display an user info.
     *
     *
     * @since Product Express 1.0
     */
    function product_express_edit_param($link){
        $parsed_url = parse_url($link);
        if(isset($parsed_url['query'])) {
            if(!strstr($parsed_url['query'], "ref=producthunt")) {
                $parsed_url['query'] = "ref=producthunt&".$parsed_url['query'];
            }

        }else{
            $parsed_url['query'] = "ref=producthunt";
        }
        return unparse_url($parsed_url);
    }
Example #6
0
/**
 * Adds Link tags to the head of the page, for CPTs' feeds.
 */
function wprss_cpt_feeds()
{
    // Get all post types
    $post_types = get_post_types(array('public' => true, '_builtin' => false));
    // If current page is archive page for a particular post type
    if (is_post_type_archive()) {
        // Remove post type from the post types list
        unset($post_types[get_post_type()]);
    }
    // Filter which post types to use
    // False: none
    // True: all
    // Array: particular post types
    // String: Single post type
    $post_type_feeds = apply_filters('wprss_cpt_feeds', FALSE);
    switch (gettype($post_type_feeds)) {
        // If it's a boolean ...
        case 'boolean':
            // If it is FALSE, exit function. Do nothing. Simply.
            if ($post_type_feeds === FALSE) {
                return;
            }
            // Otherwise, if TRUE, no further action is needed.
            break;
            // If it's a string ...
        // If it's a string ...
        case 'string':
            // If the post type does not exist, stop
            if (!isset($post_types[$post_type_feeds])) {
                return;
            }
            // Otherwise, only use this post type
            $single = $post_types[$post_type_feeds];
            $post_types = array($single => $single);
            break;
            // If it's an array ...
        // If it's an array ...
        case 'array':
            $post_types = array_intersect($post_types, $post_type_feeds);
            break;
            // If any other type, stop.
        // If any other type, stop.
        default:
            return;
    }
    // Get only the values of the post types
    $post_types = array_values($post_types);
    // Get the site name and RSS feed URL, parsed as an array
    $siteName = get_bloginfo("name");
    $feedURL = parse_url(get_bloginfo('rss2_url'));
    // Foreach post type
    foreach ($post_types as $i => $post_type) {
        // Get its RSS feed URL
        $feed = get_post_type_archive_feed_link($post_type);
        // If it doesnt have one, use the interal WP feed URL using the post_type query arg
        if ($feed === '' || !is_string($feed)) {
            // Start with the feed URL of the site
            $feed = $feedURL;
            // If there are no query args, set to an emprty string
            if (!isset($feed['query'])) {
                $feed['query'] = '';
            }
            // If the query is not empty, we need to add an ampersand
            if (strlen($feed['query']) > 0) {
                $feed['query'] .= '&';
            }
            // Add the post_type query arg
            $feed['query'] .= "post_type={$post_type}";
            // Unparse the URL array into a string
            $feed = unparse_url($feed);
        }
        // Get the Post Type Pretty Name
        $obj = get_post_type_object($post_type);
        $name = $obj->labels->name;
        // Print the <link> tag
        $feedname = sprintf(__('%1$s &raquo; %2$s Feed', 'wprss'), $siteName, $name);
        printf(__('<link rel="%1$s" type="%2$s" title="%3$s" href="%4$s" />' . "\n", 'wprss'), "alternate", "application/rss+xml", $feedname, $feed);
    }
}
 public function executeSendResetPasswordRequest($email, $webosUrl)
 {
     $manager = $this->managers()->getManagerOf('user');
     $tokenManager = $this->managers()->getManagerOf('userToken');
     $emailManager = $this->managers()->getManagerOf('email');
     $translationManager = $this->managers()->getManagerOf('translation');
     $resetPasswordSettings = $this->executeCanResetPassword();
     if (!$resetPasswordSettings['enabled']) {
         throw new \RuntimeException('Resetting password by e-mail is currently disabled', 403);
     }
     $user = $manager->getByEmail($email);
     if (empty($user)) {
         throw new \RuntimeException('Cannot find user with e-mail "' . $email . '"', 404);
     }
     $userToken = $tokenManager->getByUser($user['id']);
     $newTokenData = array('userId' => $user['id'], 'key' => sha1(mt_rand() . '42' . microtime()), 'timestamp' => time(), 'ip' => $_SERVER['REMOTE_ADDR']);
     if (!empty($userToken)) {
         //The user has already a token
         if ($userToken['timestamp'] + $resetPasswordSettings['delay'] > $newTokenData['timestamp']) {
             throw new \RuntimeException('Too many reset password requests were sent. Please try again later', 429);
         }
         $tokenManager->delete($userToken['id']);
     }
     //Create a new token
     $userToken = new UserToken($newTokenData);
     $tokenManager->insert($userToken);
     //Send an e-mail with token key
     $dict = $translationManager->load('webos');
     $parsedUrl = parse_url($webosUrl);
     $query = 'app=gnome-reset-password&token_id=' . $userToken['id'] . '&token_key=' . $newTokenData['key'];
     if (!empty($parseUrl['query'])) {
         $parsedUrl['query'] .= '&' . $query;
     } else {
         $parsedUrl['query'] = $query;
     }
     $resetPasswordUrl = unparse_url($parsedUrl);
     $to = $user['email'];
     $subject = $dict->get('${webos} password reset confirmation', array('webos' => 'Symbiose'));
     $message = '<html><head><title>' . $subject . '</title></head><body>' . '<p>' . $dict->get('Hi ${realname},', array('realname' => $user['realname'])) . '</p>' . '<p>' . $dict->get('You have recently let us know that you need to reset your password.  Please follow this link: ${link}', array('link' => '<a href="' . $resetPasswordUrl . '">' . $resetPasswordUrl . '</a>')) . '<br />' . $dict->get('(If clicking the link did not work, try copying and pasting it into your browser.)') . '</p>' . '<p>' . $dict->get('Alternatively, you can enter the following key:') . '<br />' . $newTokenData['key'] . '</p>' . '<p>' . $dict->get('If you did not request to reset your password, please disregard this message.') . '</p>' . '<p>' . $dict->get('Thanks,') . '<br />' . $dict->get('The ${webos} team', array('webos' => 'Symbiose')) . '</p></body></html>';
     $headers = 'MIME-Version: 1.0' . "\r\n";
     $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
     $headers .= 'To: ' . $to . "\r\n";
     $headers .= 'From: ' . $resetPasswordSettings['emailFrom'] . "\r\n";
     $email = new Email(array('to' => $user['email'], 'subject' => $subject, 'message' => $message, 'headers' => $headers));
     try {
         $emailManager->send($email);
     } catch (\Exception $e) {
         //Mail not sent
         $tokenManager->delete($userToken['id']);
         throw $e;
     }
 }
Example #8
0
 /**
  * Returns a string representation of this URL
  */
 public function __toString()
 {
     return unparse_url($this->parts);
 }
Example #9
0
$email_body = "SMS received to {$smsnum_recv}\n\nTime: {$time}\n\nFrom: {$smsnum_sender}\n\n{$geo}Message: {$sms_message}";
// Use either Gearman or non-asynchronous fallback
if ($config['OPTS']['USE_GEARMAN']) {
    $gmc = new GearmanClient();
    $gmc->addServers($config['OPTS']['GEARMAN_SERVERS']);
    // If attachments, spawn background download, else spawn background email
    if ($req['NUMMEDIA'] > 0) {
        $email_body .= "\n\nAttachments:\n\n{ATTACHMENTS}";
        $res = $gmc->doBackground('fetch_media', json_encode(array('SID' => $recipientSID, 'MEDIA' => $req, 'MAIL' => array('TO' => $email_to, 'SUBJECT' => $email_subject, 'BODY' => $email_body))));
    } else {
        $res = $gmc->doBackground('send_email', json_encode(array('TO' => $email_to, 'SUBJECT' => $email_subject, 'BODY' => $email_body)));
    }
} else {
    // MMS attachments
    $attachments = '';
    if ($req['NUMMEDIA'] > 0) {
        $attachments = "\n\nAttachments:\n";
        foreach ($req as $k => $v) {
            if (substr($k, 0, 8) == 'MEDIAURL') {
                $purl = parse_url($v);
                $url = unparse_url($purl, $config['ACCOUNTS'][$recipientSID]['APISID'], $config['ACCOUNTS'][$recipientSID]['APISECRET']);
                $attachments .= "* {$url}\n";
            }
        }
    }
    $email_body .= $attachments;
    // Email recipient
    send_email($email_to, $config['OPTS']['EMAIL_FROM'], $email_subject, $email_body);
}
// Done processing, send blank response
print_TwiML();
Example #10
0
 public function gplusurl($v)
 {
     if (!$v) {
         return $v;
     }
     $u = parse_url($v);
     $q = array();
     if (isset($u['query'])) {
         $q = parse_str($u['query']);
     }
     $q['rel'] = 'author';
     $u['query'] = http_build_query($q);
     return unparse_url($u);
 }
Example #11
0
    $work = json_decode($job->workload());
    $mail = send_email($work->TO, $config['OPTS']['EMAIL_FROM'], $work->SUBJECT, $work->BODY);
    // Do some garbage collection and return results
    unset($work);
    gc_collect_cycles();
    return $mail;
});
$gmw->addFunction('fetch_media', function (GearmanJob $job) use(&$config) {
    $work = json_decode($job->workload());
    // This could be done using curl_multi, but we don't need parallelism
    // here since it's already a background task.
    $attachments = '';
    $fails = 0;
    for ($i = 0; $i < $work->MEDIA->NUMMEDIA; $i++) {
        $purl = parse_url($work->MEDIA->{'MEDIAURL' . $i});
        $url = unparse_url($purl, $config['ACCOUNTS'][$work->SID]['APISID'], $config['ACCOUNTS'][$work->SID]['APISECRET']);
        $filename = time() . '-' . sprintf('%u', crc32($url)) . '.' . mime_to_ext($work->MEDIA->{'MEDIACONTENTTYPE' . $i});
        // Fetch media item and write to file
        $ch = curl_init();
        $fp = fopen($config['OPTS']['MEDIA_PATH'] . '/' . $filename, 'w');
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FILE, $fp);
        // Twilio media URLs are api.twilio.com, but they have redirects to Amazon AWS
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $ex = curl_exec($ch);
        curl_close($ch);
        fclose($fp);
        // Delete the file if there was an error, and bump the fail count
Example #12
0
function get_current_url()
{
    $host = $_SERVER['SERVER_NAME'];
    $port = $_SERVER['SERVER_PORT'];
    $req_uri = $_SERVER['REQUEST_URI'];
    $https = !empty($_SERVER['HTTPS']);
    $parts = array('scheme' => $https ? 'https' : 'http', 'host' => $host, 'port' => $port);
    if ($https and $port == 443 or !$https and $port == 80) {
        unset($parts['port']);
    }
    $uri = unparse_url($parts) . $req_uri;
    return $uri;
}
 protected function preProvideApi(Provision $feature)
 {
     $optionsFijas = $feature->getOptions();
     $autoconfigurar = isset($optionsFijas) && isset($optionsFijas['auto-configurar']) && $optionsFijas['auto-configurar'];
     $options = array();
     $modeloProyecto = $this->getModeloProyecto();
     $iniServer = \toba_modelo_rest::get_ini_server($modeloProyecto);
     $iniUsuarios = \toba_modelo_rest::get_ini_usuarios($modeloProyecto);
     if ($autoconfigurar && !$iniServer->existe_entrada("autenticacion")) {
         echo "Autoconfigurando API...";
         $iniServer->agregar_entrada("autenticacion", "digest");
         $iniServer->guardar();
     }
     if ($autoconfigurar && empty($iniUsuarios->get_entradas())) {
         $iniUsuarios->agregar_entrada($this->getProyectoId(), array("password" => md5(uniqid(rand(), true))));
         $iniUsuarios->guardar();
     }
     if ($iniServer->existe_entrada("autenticacion")) {
         $options['auth']['type'] = $iniServer->get_datos_entrada("autenticacion");
     }
     //TODO: esta tomando el primer usuario y lo manda. Es totalmente inseguro, esto tiene que ir hacia un modelo clave privada/crt
     $usuarios = $iniUsuarios->get_entradas();
     if (!empty($usuarios)) {
         foreach ($usuarios as $usuario => $datos) {
             $options['auth']['userId'] = $usuario;
             $options['auth']['userPass'] = $datos['password'];
             break;
         }
     }
     $endpoint = $this->getProyectoUrl() . '/rest/';
     if (isset($_SERVER['DOCKER_NAME'])) {
         //HACK: en el caso de docker la IP interna difiere de la externa. Se trata de sacar con la variable DOCKER_NAME
         $parts = parse_url($endpoint);
         if (isset($parts['host'])) {
             $parts['host'] = $_SERVER['DOCKER_NAME'];
         }
         if (isset($parts['port'])) {
             unset($parts['port']);
         }
         $endpoint = unparse_url($parts);
     }
     $feature->setEndpoint($endpoint);
     $feature->setOptions($options);
 }
function urlAppendTracking($url, $tracking)
{
    $tmpUrl = parse_url($url);
    $query = '';
    if (is_string($tracking)) {
        $query = $tracking;
    } elseif (is_array($tracking)) {
        $query = http_build_query($tracking);
    }
    if ($query != '') {
        $tmpUrl['query'] = isset($tmpUrl['query']) ? $tmpUrl['query'] . '&' . $query : $query;
    }
    return unparse_url($tmpUrl);
}
Example #15
0
        // Parse url of current page
        $enterData['referer'] = unparse_url(TRUE, TRUE);
        // $_SERVER['HTTP_REFERER'];
        // log_write($_SERVER['HTTP_REFERER']." rewrited to ".$enterData['referer']);
    } else {
        $link_arr['referer_order_url'] = unparse_url(TRUE, TRUE);
    }
}
// Getting enter URL
$enterData['enter_url'] = unparse_url(TRUE);
$jsonEnterData = json_encode($enterData);
if (!isset($_COOKIE['enter_data'])) {
    setcookie('enter_data', $jsonEnterData, time() + $cookie_time, '/');
}
// Getting curent (order) url
$link_arr['order_url'] = unparse_url(FALSE);
// UTM data in json to cookie
$link_json = json_encode($link_arr);
// Save and redeclare data to coockie
if (isset($_COOKIE['link'])) {
    if ($link_json != '[]') {
        setcookie('link', '', time() - 60);
        setcookie('link', $link_json, time() + $cookie_time, '/');
    }
} else {
    setcookie('link', $link_json, time() + $cookie_time, '/');
}
// Get the country
//include(SXPATH.'bx24/SxGeo.php');
//$SxGeo = new SxGeo(SXPATH.'bx24/SxGeo.dat');
//$cntr = $SxGeo->getCountry(GetRealIp());