I'm creating a custom module that has uses the form API and sends an email on submission- however, I want to make the 'from' email name to be the site name (eg, <My Drupal Site> no-reply#myhttphost.com). In phptemplate you can use $site_name, but that doesn't work from a module it seems. I've tried calling &$variables or &$variable or &$vars in the function argument and DSMed it but still nothing. Any ideas?
Many thanks!
Matt
You can use:
variable_get('site_name');
anywhere in a module or template file :)
I'd suggest the approach used in core:
variable_get('site_name', 'Drupal');
It's good practice to include the default value in variable_get().
Done...I dug through the set and get code and none of it ever is sanitized...sanitizing serialized objects would probably break stuff so it makes sense
Related
My PHP knowledge is very basic. I've built a child theme and the functions.php is all from bits and pieces found on the web. All works great at the moment, and I've reused it on another website. But in several places I had to manually input blog name, email address, etc. What I want is to make it reusable without any further interventions over it. I've covered all problems, but one: changing the default wordpress#example.com email.
// Changing default wordpress email settings
add_filter('wp_mail_from', 'new_mail_from');
function new_mail_from($old) {
return 'notifications#example.com';
}
This works, although to make it reusable without intervention I need to somehow retrieve the site's URL without http:// and www. I've made a test page and used:
$my_site = str_replace('www.','', $_SERVER['SERVER_NAME']);
echo 'notifications#'.$my_site;
It worked on the test.php file, but not in Wordpress' functions.php. The mail is sent and received, but the sender is 'notifications#' with nothing after #. I've used it as
return 'notifications#'.#my_site;
I've tried another approach:
$custom_email = 'notifications#'.str_replace('www.','', $_SERVER['SERVER_NAME']);
function new_mail_from($old) {
return $custom_email;
}
This one doesn't show any sender at all, it's from "unknown sender".
I've tried to work with site_url() instead of $_SERVER, but I haven't managed to make it work either. I didn't tried using home_url() because maybe in some cases home_url() will use a custom page (like a landing page).
Is there a way to solve this problem I have?
Thank you.
Ok, with a bit of help from a friend, I've found something that works:
function new_mail_from($old) {
$custom_email = 'notifications#'.str_replace('www.','', $_SERVER['SERVER_NAME']);
return $custom_email;
}
So basically all I need is to put $custom_email inside the function.
#MadBreaks Now... I know your advice was to avoid str_replace, but I didn't manage to understand parse_url and how to use it. Why isn't str_replace a good choice?
#Victory $_SERVER['SERVER_NAME'] and $_SERVER['HTTP_HOST'] did for me the same thing. Could you please tell me what's the difference? Or pros and cons in using each of them in this situation? Thank you.
I'm trying to modify the user's address right after registration.
When you create a new user, The address needs to be modified and a trailing string needs to be added, such as this : ####.
I've created an addon, added the path /controllers/frontend/profiles.post.php,
I've attached to the $mode == 'add' , That's where I'm stuck.
How can I know which variables are available to me, It seems there's no way to debug, var_dump or echo. nothing seems to work.
The file is executing because if I type some broken syntax the server returns 500 internal error,
So my main question :
How can you debug at all any CS-cart addon?
Patrick,
To find out what variables do you have you can use fn_print_r($_REQUEST)
where
fn_print_r - good looking cs-cart wrapper of print_r
Actually the variables from profiles.php are not available in profiles.post.php because these are different variable scopes.
So most probably the only variables you will have is global PHP like $_REQUEST $_SERVER etc..
Take a look at discussion or bestsellers add-on - they have products.post.php controllers which work absolutly the same ways a profiles.post.php and any other post controllers.
I cannot seem to figure out where to set the trusted_dir variable in Smarty 3. Now anytime I use a {insert name="func_name" script="thescript"} I get the error "missing script file".
Does anyone out there know how to allow this? $smarty->security is set to false.
Thank you.
EDIT: As of the posting of this question, this functionality has not been added to Smarty 3 yet, but a Smarty admin has assured me he will get onto adding the functionality ASAP. (http://www.smarty.net/forums/viewtopic.php?p=65549), so we should see it soon.
EDIT 2 The functionality has now been added to Smarty 3 and works as in Smarty 2! :-)
http://www.smarty.net/manual/en/variable.trusted.dir.php
It basically says that you have to enable security to access it.
To set the trusted_dir you would do something similiar to this:
$Smarty->trusted_dir = array(
'my_first_dir',
'my_second_dir/my_third_dir'
);
which would allow scripts from my_first_dir and my_third_dir (which is located within my_second_dir).
I'm trying to output some HTML in an XML template and Symfony's escaping method is messing it up. So I tried making a copy of settings.yml in the module's config folder, but it seems to be completely ignored. Is there an easy way to change the escaping_strategy and/or escaping_method settings per module or even per template?
While output escaping is turned on you still have access to the raw value through $sf_data. For example, if the HTML you're trying to output was stored in a variable called html in your action:
$this->html = '<b>My HTML</b>';
You could get the unescaped value with this:
<?php echo $sf_data->getRaw('html') ?>
http://www.symfony-project.org/book/1_0/07-Inside-the-View-Layer#chapter_07_sub_activating_output_escaping
I don't believe there is a way to disable this functionality on a per-module basis.
getRaw only works if the variable is passed from the action. for variable within view use
sfOutputEscaperGetterDecorator::unescape($html)
Just run into this problem today and i manage to solve it by setting sfConfig::set('sf_escaping_strategy', false) in my controller (either in preExecute method for all the actions in that module or in a specific action - executeWhatever).
I am using Jumi to include a number of PHP scripts on Joomla! articles and it works great. The problem I am having is with passing variables (in the form of $_GET parameters) to a PHP script.
Lets say I have a script "index.php" and I wish to pass the $_GET[] parameter "var" with the value of "10". This would normally be accomplished by pointing to: index.php?var=10. How do "emulate" this functionality with Jumi? I was hoping it would be as simple as:
{jumi [directory/index.php] [var=10]}
The above syntax however is not correct.
Any input would be appreciated.
-- Nicholas
After some trial and error and guidance from the official Joomla! forums I did solve my problem. Rather than passing a true $_GET[] parameter you can pass a $jumi array and reference that.
I wanted to avoid having to rewrite much of my script so what I did was the following.
1) Make the Jumi call like this:
{jumi [directory/index.php] [value]}
2) In index.php:
if(isset($jumi[0]))
{
$_GET['PARAM_YOU_WANT_SET'] = $jumi[0];
}
This is a very simple example of a quick and easy way to emulate passing a $_GET[] parameter to a script using Jumi. This approach saved me a great deal of time because I didn't have to rewrite my controller.
-- Nicholas
This is an old thread I know but there is something that some people might want to know.
If you are wanting to use Jumi with extra parameters in a Module then Nicholas' tip won't work but there is a way to do it.
There is a "Code written" section of the module and a "Source of code" section.
Put the url/path to the file in the "Source of code" section and then define your variables in the "Code written" section...it will pass the variable to the source file before executing so it will do what is desired.