I have created a custom home.php file inside my template dir of wordpress.
It's okay but the encoding is broken and I do not understand how to fix it.
The page is a simply custom .php page.
Here you can see: http://tomsblog.it/
More info:
- I get the informations from a utf8_general_ci database
- The page is encoded with UTF-8
- The php code is a simple mysql_fetch_object
$result = $mysql->query("SELECT * FROM blogs WHERE id = 5");
$article = mysql_fetch_object($result);
echo $article->title;
Thanks
can you check the database how the data is storing meaning like it is storing correctly if not you have a problem try to replace the data on a tables here is the link may this help you
UPDATE:
check database character set in wp_config.php file ie. in root folder define('DB_CHARSET', 'utf8');
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
I am trying to pass the variables from one page to another in Drupal 7. Since in Drupal 7 we do not create the php file as such the content of the page gets saved as a plain text in DB, no files get created, so GET/POST are out of the solution.
How can I do this?
Content is saved in database, but every content is defined in some content type. And for every content type you can have different template file. Inside that template file you can put your php code reading GET/POST, or what ever.
So, you can use the usual way and read parameters from template, do what ever you want with them.
One way is to use variable_set() to save the value to database and variable_get() to retrieve the value from database.
To save the value:
variable_set('my_variable_unique_id', 'the value to be saved.');
To read the value back:
$myVariable = variable_get('my_variable_unique_id', 'default value in case could not find a saved value for the variable.');
I got lots of not followed page on Google Webmaster. I check them and is because lots of url are like http://www.mysite.net/2013/06/burn-notice-7%C3%9702-sub-espanol-online.html
whe the correct url have to be http://www.mysite.net/2013/06/burn-notice-7x02-sub-espanol-online.html
Im try to post a title wit many "x" on it and the only that weird %C3%97 when I post for example a new serie episode like this title: Burn Notice 7x02 Sub Español Online. When the x is between number appear %C3%97 and that made my posts duplicate.
So I try to fix changed the database collation from latin1_swedish_ci to utf8_general_ci but is still the same happend. I check as well my wp-config.php and is define('DB_CHARSET', 'utf8');
Please, some body know any good solution to fix all this situation? The database is quite big and supouse if I find a solution I need update the old url.
Thank you on advance
The URL you say Google is using:
http://www.mysite.net/2013/06/burn-notice-7%C3%9702-sub-espanol-online.html
is almost the same as the URL:
http://www.mysite.net/2013/06/burn-notice-7x02-sub-espanol-online.html
as the percent encoded characters actually repreesent Unicode Character 'MULTIPLICATION SIGN' aka it's an '×' not an 'x'. Google is just using the percent encoded version to be safe. That means that your database is probably fine, as it is showing URLs as valid UTF8.
The problem probably lies in how you're interpreting the requested URL and trying to match it to the database. PHP should already be decoding the percent encoded value to '×', so either:
Something is breaking the string (e.g. calling a non-multibyte safe function like strtolower() instead of mb_strtolower()).
Your PHP code is connecting to the database in a character set other than UTF8, please check that your my.cnf file contains 'default-character-set=utf8' in the client section.
or there's some other issue. The URL does appear valid though.
I'm using permalinks in WP as: domain.com/category/post_name
The issue is that post names have non-latin characters such as chinese, hebrew, and arabic. So it encodes them to something like: %20%18%6b%20 therefore it counts every symbol's character as an actual character, ending up with 3x times more length that it truncates some very short slugs.
How to fix that? Or at least how to extend the length limit at least? I've tried to extend the length of the database field "post_name" from 200 to 500, But it's still truncating short.
You can change post_name by appling the filters for sanitize_title...
Short example:
add_filter('sanitize_title', 'sanitize_title_custom', 10, 3);
function sanitize_title_custom($title, $raw_title, $context){
// do some proccesing with title or raw_title
// assign new result to $title ($title = str_replace(" ","-", $raw_title);// as example )
return $title;
}
but, be careful... bad sanitizing can be security risk... sql injections etc...
Wordpress should not be encoding your post slugs like that. I use utf8 characters in titles and slugs all the time for clients. It works fine.
Are you sure that your database table's charset is utf8? If so, has it been overridden for any of the columns? Also check wp-config.php for define('DB_CHARSET', 'utf8');
I would also disable any plugins and test your permalinks again. Maybe one of your plugins is screwing with your post slugs.
This is a common situation that frustrates me too.
Check this plugin. Clean Trunks
You can set the the maximum url length on plugin configuration page.
(Default: 35 characters.)
Also you have the option to edit stopword list supplied.
Hope this will help. Cheers !!!
For non English URL:
I'm using IIS with fcgi and I found the solution for non english slug in different places on the web:
for Hebrew: here
for more info about IIS7 URL Rewrite and Symbols : here
generally except the IIS configuration for pretty url you need to add to the end of the wp-config.php:
if (isset($_SERVER['UNENCODED_URL']))
$_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
here you will find more about UNENCODED_URL
Why not remove these bad characters when creating/saving the permalink?
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