I've searched all over for examples of this, but I haven't found any. I'm trying to create an alias for path which includes query arguments, like profile?arg1=113.
It doesn't matter if I provide path_save() with the plain string representation of the path, or if I provide it with url().
url('profile', array('query' => array('arg1' => $uid)))
Either way, ? and = show up as escaped characters on the URL aliases admin page, which naturally means the path can't be found.
How can I keep the ? and = from being escaped?
12/19/12 Edit 1: the larger context is that I'm trying to set up the alias when a Profile2 profile is being saved (i.e., in mymodule_profile2_presave()) - that's when I'll have all the information I need to programmatically set up the alias.
12/19/12 Edit 2: I just realized that the problem isn't on the insert side - the url_alias table actually has unescaped characters in it. The problem is that Drupal doesn't urldecode the path before using it...
12/20/12 Edit 3: Found a solution using Redirect instead of path aliases. Redirect properly decodes the query string!
You cannot attach the query string to the destination of an alias. The code executed from drupal_path_initialize() doesn't handle the query string correctly.
The function contains the following code.
$_GET['q'] = drupal_get_normal_path($_GET['q']);
Suppose that you have "example" as path alias that points to "node/93?uid=1"; that code would set $_GET['q'] to 'node/93?uid=1', while you are expecting $_GET['q'] to get 'node/93', and $_GET['uid'] to be set to 1.
What you could do is implementing hook_inbound_alter() with code similar to the following one.
function mymodule_url_inbound_alter(&$path, $original_path, $path_language) {
list ($path, $query) = explode('?', $path);
$_GET += drupal_get_query_array($query);
}
Related
I am new to drupal 7, I am trying to create hook_file_presave / hook_file_validate / hook_field_validate function, That checks if pdf file that is uploaded on site is not password protected.
I can easily check using php if file is password protected. But when I display error message, it only displays error message also uploads file. I think i am not using right hook.
function simpletest_file_presave($destination){
// here is my logic
drupal_set_message(t('file is encrypted >>>>>>>> '. $filename), 'error');
return;
}
Here you can see file shouldn't be uploaded buit its there with remove button.
It's been a while since I've touched Drupal, but I first thought about hook_file_validate().
But as explained here you could implement hook_form_FORM_ID_alter() in order to add your own file upload validator and then return an array of errors to display.
Important: When you use the t() function to translate your message don't append the filename to your string because this will create multiple translated strings, one for each uploaded file so it will never be translated as it will always vary. To avoid that, use a placeholder and pass the filename as string parameter, like this:
$error_message = t(
'The file "#filename" is encrypted! Please upload a PDF without password protection.',
['#filename' => $filename_without_path]
);
See the API documentation for the t() and format_string() functions
When I tried to parse this URL:
http://localhost:3000/torrent?previous=%2Ftorrent%3Fprevious%3D%252Fuser%26route%3D&route=torrent-item
I was expecting route = 'torrent-item' (String), but FlowRouter router value is ["", "torrent-item"] (Array)
online - https://ts-vcompile.herokuapp.com/user#!/torrent?previous=%2Ftorrent%3Fprevious%3D%252Fuser%26route%3D&route=torrent-item
repo - https://github.com/HedCET/TorrentSearch
There is one key route in queryparameter which has no value. So default value assumed is an empty string. It will always return you an array of keys with same name(in this case 'route').
So you will not get route = 'torrent-item'
previous=%2Ftorrent%3Fprevious%3D%252Fuser%26route%3D&route=torrent-item
Your URL decodes as
http://localhost:3000/torrent?previous=/torrent?previous=%2Fuser&route=&route=torrent-item
cf: http://meyerweb.com/eric/tools/dencoder/
so you have &route=&route=torrent-item which will return ["", "torrent-item"] since route is there twice.
You just need to figure how to encode this URL properly to read it right.
If it's a URL you are reading from somewhere, then you need to parse the multiple arguments of the array to find what you want.
I am working on a URL filtering project . I have a database given to me which contain URLs need to be blocked (eg: a.b.com/d/e).
I get uri and domain from http request. I compare what I get with my database and redirect users without any problem. So far so good.
Problems starts with urls that contains query string and other magics with URL. As an example if user enters a.b.com/d/e?junk. What I get won't match with my database, and users will bypass my filter and they will still be able to go a.b.com/d/e.
I tried some useless actions like slicing everything after special chars like "?,#". But having problems with url like : youtube.com/watch?v=12vh55_1ul8, which becames like youtube.com/watch and blocks all youtube. That solution causes me more problems.
Now I am very confused how to handle this problem. Is there any guide or any library which I can use in C++ ?
Try this code:
string str (get_requsted_uri());
string str2 ("http://getaroundfilters.com/article/889/proxy");
if (str.find(str2) != string::npos) {
block();
} else {
get_and_return_webpage(str);
}
I have moved a newly built WordPress site from a sub directory in the remote server, to the root directory. I have a couple of custom post types with meta data associated with them, including images metadata (i.e. file & URL). Obviously I had to remove the sub directory from the URL. I did so with a replace SQL query.
Now wordpress doesn't recognize the meta data. When I write the following code:
$img = get_post_meta($post->ID,"mf_logo",true);
var_dump($img);
I get "bool(false)". I have tried to upload a new image, and it is showing. I then manually changed its URL through MySQL and again it wasn't recognized.
It is important to note that the problem only happens with meta data in the form of array, and not with 'normal' meta-data
Your kind help would be most appreciated.
When using meta data (update_post_meta, get_post_meta...) arrays will be automatically serialized in db :
http://codex.wordpress.org/Function_Reference/update_post_meta
A passed array will be serialized into a string.
And you cannot simply replace strings in a serialized array :
$data = array('key'=>'value');
echo serialize($data);
This will output : a:1:{s:3:"key";s:5:"value";}
If you simply replace key or value with a shorter/longer string, il will break the data :
a:1:{s:3:"key";s:5:"replace";} is incorrect
a:1:{s:3:"key";s:7:"replace";} is correct
You can make a batch to handle this.
But prior to this, do you know you can let wordpress in its own directory and make it accessible from root directory, without breaking links ?
Take a look here : http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory#Using_a_pre-existing_subdirectory_install
I have a page something.aspx, with associated codebehind something.aspx.cs. In that codebehind, I want to know the filesystem location of something.aspx. Is there any convenient way to get it?
Update: I got several excellent answers, which unfortunately didn't work because of something else crazy I'm doing. I'm encoding some additional information on the URL I pass in, so it looks like this:
http://server/path/something.aspx/info1/info2/info3.xml
The server deals with this OK (and I'm not using querystring parameters to work around some other code that I didn't write). But when I call Server.MapPath(Request.Url.ToString()) I get an error that the full URL with the 'info' segments isn't a valid virtual path.
// File path
string absoluteSystemPath = Server.MapPath("~/relative/path.aspx");
// Directory path
string dir = System.IO.Path.GetDirectoryName(absoluteSystemPath);
// Or simply
string dir2 = Server.MapPath("~/relative");
Request.PhysicalPath
Server.MapPath is among the most used way to do it.
string physicalPath = Server.MapPath(Request.Url);
Server.MapPath( Request.AppRelativeCurrentExecutionFilePath )