Osclass forums
Support forums => General help => 3.7.x => Topic started by: marius-ciclistu on July 12, 2017, 07:50:28 pm
-
The field I'm talking about can be seen here: https://demo.osclass.org/general/item/send-friend/808
The bellow code is colecting the subject from the file: oc-content/themes/bender/item-send-friend.php
<div class="control-group">
<label class="control-label" for="subject">
<?php _e('Subject (optional)', 'bender'); ?>
</label>
<div class="controls">
<?php ContactForm::the_subject(); ?>
</div>
</div>
But in the admin area there is no {Subject} to relate to and put it in the email.
In oc-includes/osclass/emails.php the function does not have the subject.
function fn_email_send_friend($aItem) {
$mPages = new Page();
$aPage = $mPages->findByInternalName('email_send_friend');
$locale = osc_current_user_locale();
if(isset($aPage['locale'][$locale]['s_title'])) {
$content = $aPage['locale'][$locale];
} else {
$content = current($aPage['locale']);
}
$item_url = osc_item_url();
$item_url = '<a href="'.$item_url.'" >'.$item_url.'</a>';
$words = array();
$words[] = array(
'{FRIEND_NAME}',
'{USER_NAME}',
'{USER_EMAIL}',
'{FRIEND_EMAIL}',
'{ITEM_TITLE}',
'{COMMENT}',
'{ITEM_URL}',
'{ITEM_LINK}'
);
$words[] = array(
$aItem['friendName'],
$aItem['yourName'],
$aItem['yourEmail'],
$aItem['friendEmail'],
removeunderline($aItem['s_title']),
$aItem['message'],
osc_item_url(),
$item_url
);
$title = osc_apply_filter('email_send_friend_title_after', osc_mailBeauty(osc_apply_filter('email_title', osc_apply_filter('email_send_friend_title', $content['s_title'], $aItem)), $words), $aItem);
$body = osc_apply_filter('email_send_friend_description_after', osc_mailBeauty(osc_apply_filter('email_description', osc_apply_filter('email_send_friend_description', $content['s_text'], $aItem)), $words), $aItem);
$params = array(
'from' => osc_contact_email(),
'from_name' => osc_page_title(),
'reply_to' => $aItem['yourEmail'],
'subject' => $title,
'to' => $aItem['friendEmail'],
'to_name' => $aItem['friendName'],
'body' => $body
);
if( osc_notify_contact_friends() ) {
$params['add_bcc'] = osc_contact_email();
}
osc_sendMail($params);
}
osc_add_hook('hook_email_send_friend', 'fn_email_send_friend');
Question:
$words[] = array(
'{FRIEND_NAME}',
'{USER_NAME}',
'{USER_EMAIL}',
'{FRIEND_EMAIL}',
'{ITEM_TITLE}',
'{COMMENT}',
'{ITEM_URL}',
'{ITEM_LINK}',
'{SUBJECT}' // new code
);
$words[] = array(
$aItem['friendName'],
$aItem['yourName'],
$aItem['yourEmail'],
$aItem['friendEmail'],
removeunderline($aItem['s_title']),
$aItem['message'],
osc_item_url(),
$item_url,
code //what to insert here?
);
aItem['subject'] ?
The function for that subject from oc-includes/osclass/frm/Contact.form.class.php
static public function the_subject() {
if( Session::newInstance()->_getForm("subject") != "" ) {
$subject = Session::newInstance()->_getForm("subject");
parent::generic_input_text("subject", $subject, null, false);
} else {
parent::generic_input_text("subject", "", null, false);
}
return true;
}
and the generic_input_text function from oc-includes/osclass/frm/Form.form.class.php
static protected function generic_input_text($name, $value, $maxLength = null, $readOnly = false, $autocomplete = true) {
$name = osc_esc_html($name);
echo '<input id="' . preg_replace('|([^_a-zA-Z0-9-]+)|', '', $name) . '" type="text" name="' . $name . '" value="' . osc_esc_html(htmlentities($value, ENT_COMPAT, "UTF-8")) . '"';
if (isset($maxLength)) echo ' maxlength="' . osc_esc_html($maxLength) . '"';
if (!$autocomplete) echo ' autocomplete="off"';
if ($readOnly) echo ' disabled="disabled" readonly="readonly"';
echo ' />';
}
-
You mention in 'In oc-includes/osclass/emails.php the function does not have the subject.' there is no subject but there is; ''subject' => $title,'
I am trying to understand what you want to do, can you explain a bit more?
The field I'm talking about can be seen here: https://demo.osclass.org/general/item/send-friend/808
The bellow code is colecting the subject from the file: oc-content/themes/bender/item-send-friend.php
<div class="control-group">
<label class="control-label" for="subject">
<?php _e('Subject (optional)', 'bender'); ?>
</label>
<div class="controls">
<?php ContactForm::the_subject(); ?>
</div>
</div>
But in the admin area there is no {Subject} to relate to and put it in the email.
In oc-includes/osclass/emails.php the function does not have the subject.
function fn_email_send_friend($aItem) {
$mPages = new Page();
$aPage = $mPages->findByInternalName('email_send_friend');
$locale = osc_current_user_locale();
if(isset($aPage['locale'][$locale]['s_title'])) {
$content = $aPage['locale'][$locale];
} else {
$content = current($aPage['locale']);
}
$item_url = osc_item_url();
$item_url = '<a href="'.$item_url.'" >'.$item_url.'</a>';
$words = array();
$words[] = array(
'{FRIEND_NAME}',
'{USER_NAME}',
'{USER_EMAIL}',
'{FRIEND_EMAIL}',
'{ITEM_TITLE}',
'{COMMENT}',
'{ITEM_URL}',
'{ITEM_LINK}'
);
$words[] = array(
$aItem['friendName'],
$aItem['yourName'],
$aItem['yourEmail'],
$aItem['friendEmail'],
removeunderline($aItem['s_title']),
$aItem['message'],
osc_item_url(),
$item_url
);
$title = osc_apply_filter('email_send_friend_title_after', osc_mailBeauty(osc_apply_filter('email_title', osc_apply_filter('email_send_friend_title', $content['s_title'], $aItem)), $words), $aItem);
$body = osc_apply_filter('email_send_friend_description_after', osc_mailBeauty(osc_apply_filter('email_description', osc_apply_filter('email_send_friend_description', $content['s_text'], $aItem)), $words), $aItem);
$params = array(
'from' => osc_contact_email(),
'from_name' => osc_page_title(),
'reply_to' => $aItem['yourEmail'],
'subject' => $title,
'to' => $aItem['friendEmail'],
'to_name' => $aItem['friendName'],
'body' => $body
);
if( osc_notify_contact_friends() ) {
$params['add_bcc'] = osc_contact_email();
}
osc_sendMail($params);
}
osc_add_hook('hook_email_send_friend', 'fn_email_send_friend');
Question:
$words[] = array(
'{FRIEND_NAME}',
'{USER_NAME}',
'{USER_EMAIL}',
'{FRIEND_EMAIL}',
'{ITEM_TITLE}',
'{COMMENT}',
'{ITEM_URL}',
'{ITEM_LINK}',
'{SUBJECT}' // new code
);
$words[] = array(
$aItem['friendName'],
$aItem['yourName'],
$aItem['yourEmail'],
$aItem['friendEmail'],
removeunderline($aItem['s_title']),
$aItem['message'],
osc_item_url(),
$item_url,
code //what to insert here?
);
aItem['subject'] ?
The function for that subject from oc-includes/osclass/frm/Contact.form.class.php
static public function the_subject() {
if( Session::newInstance()->_getForm("subject") != "" ) {
$subject = Session::newInstance()->_getForm("subject");
parent::generic_input_text("subject", $subject, null, false);
} else {
parent::generic_input_text("subject", "", null, false);
}
return true;
}
and the generic_input_text function from oc-includes/osclass/frm/Form.form.class.php
static protected function generic_input_text($name, $value, $maxLength = null, $readOnly = false, $autocomplete = true) {
$name = osc_esc_html($name);
echo '<input id="' . preg_replace('|([^_a-zA-Z0-9-]+)|', '', $name) . '" type="text" name="' . $name . '" value="' . osc_esc_html(htmlentities($value, ENT_COMPAT, "UTF-8")) . '"';
if (isset($maxLength)) echo ' maxlength="' . osc_esc_html($maxLength) . '"';
if (!$autocomplete) echo ' autocomplete="off"';
if ($readOnly) echo ' disabled="disabled" readonly="readonly"';
echo ' />';
}
-
That email does not pass the subject entered(optionally) by a user that sends a link to a friend.
See the attached picture. That field is not used/passed into the array that replaces the {....} with the values entered by the user in the email_send_friend email template.
-
Ah okay, you want to add an optional subject that user can enter instead of the default subject created by Osclass, correct?
-
I want to use that subject that the user enters (because it's default in osclass), and I want to insert it in the email title, yes, but I'm not shure how to put it in that array.
$words[] = array(
$aItem['friendName'],
$aItem['yourName'],
$aItem['yourEmail'],
$aItem['friendEmail'],
removeunderline($aItem['s_title']),
$aItem['message'],
osc_item_url(),
$item_url,
code //what to insert here?
);
-
You mention in 'In oc-includes/osclass/emails.php the function does not have the subject.' there is no subject but there is; ''subject' => $title,'
I am trying to understand what you want to do, can you explain a bit more?
''subject' => $title, is the email's subject and gets the title string formed here:
$title = osc_apply_filter('email_send_friend_title_after', osc_mailBeauty(osc_apply_filter('email_title', osc_apply_filter('email_send_friend_title', $content['s_title'], $aItem)), $words), $aItem);
But I'm talking about another subject as you saw in the previous picture.
If that value is lost, then I should remove that field from there, as it is useless.
EDIT: Where does this code put the subject string?
static public function the_subject() {
if( Session::newInstance()->_getForm("subject") != "" ) {
$subject = Session::newInstance()->_getForm("subject");
parent::generic_input_text("subject", $subject, null, false);
} else {
parent::generic_input_text("subject", "", null, false);
}
return true;
}
-
Ok, I'll have a look at the sent-friends form, been a while since I looked at it 8)
The code:
static public function the_subject() {
if( Session::newInstance()->_getForm("subject") != "" ) {
$subject = Session::newInstance()->_getForm("subject");
parent::generic_input_text("subject", $subject, null, false);
} else {
parent::generic_input_text("subject", "", null, false);
}
return true;
}
seems to perform a GET (key) related to the 'form' key using the Osclass SESSION class.
The subject (or "") is returned to parent form (form used when calling this function) based on the FORM class.
Checkout the Session.php class in /osclass/core folder.
-
I'm learning as I write to you now:
In that file there is :
class Session {
//attributes
private $session;
private static $instance;
public static function newInstance() {
if(!self::$instance instanceof self) {
self::$instance = new self;
}
return self::$instance;
}
And all I can understand is that this Session::newInstance() means that the newInstance() function from Session class is called.
-
Yes, the session class (object) keeps certain values, the instantiating of the class either creates a new class or re-opens the existing one and returns that one. This means there's Always one class to work with and prevents multiple classes from being created in memory. The session class is 'alive' during the session of a visitor. Each visitor will have it's own 'session' object holding values which are used by system. Similar working for cookie class etc.
I'm learning as I write to you now:
In that file there is :
class Session {
//attributes
private $session;
private static $instance;
public static function newInstance() {
if(!self::$instance instanceof self) {
self::$instance = new self;
}
return self::$instance;
}
And all I can understand is that this Session::newInstance() means that the newInstance() function from Session class is called.
-
Thanks for this, but just now, this is way over my head :D I didn't get so far with learning php, but leaving this aside, it seems strange to collect that field and then not use it, from osclass script's point of view.
So if someone could point out the line of code that can be inserted here:
Code: [Select]
$words[] = array(
'{FRIEND_NAME}',
'{USER_NAME}',
'{USER_EMAIL}',
'{FRIEND_EMAIL}',
'{ITEM_TITLE}',
'{COMMENT}',
'{ITEM_URL}',
'{ITEM_LINK}',
'{SUBJECT}' // new code
);
$words[] = array(
$aItem['friendName'],
$aItem['yourName'],
$aItem['yourEmail'],
$aItem['friendEmail'],
$aItem['s_title'],
$aItem['message'],
osc_item_url(),
$item_url,
code //what to insert here?
);
I would apreciate it.
If not, I'll remove that field from that page, no big deal.
EDIT:
Is that field passed via aItem['subject']?
-
I just tested with
$aItem['subject']
It doesn't work.
EDIT:
in oc-includes/osclass/ItemActions.php the following code calls the hook with the aItem as parameter.
public function send_friend()
{
// get data for this function
$aItem = $this->prepareDataForFunction( 'send_friend' );
$item = $aItem['item'];
$s_title = $aItem['s_title'];
View::newInstance()->_exportVariableToView('item', $item);
osc_run_hook('hook_email_send_friend', $aItem);
$item_url = osc_item_url();
$item_url = '<a href="'.$item_url.'" >'.$item_url.'</a>';
Params::setParam('item_url', $item_url );
osc_add_flash_ok_message( sprintf(_m('We just sent your message to %s'), $aItem['friendName']) );
return true;
}
And the following code does not have the subject:
/**
* Return an array with all data necessary for do the action
* @param <type> $action
*/
private function prepareDataForFunction( $action )
{
$aItem = array();
switch ( $action ){
case 'send_friend':
$item = $this->manager->findByPrimaryKey( Params::getParam('id') );
if ($item===false || !is_array($item) || count($item)==0)
break;
$aItem['item'] = $item;
View::newInstance()->_exportVariableToView('item', $aItem['item']);
$aItem['yourName'] = Params::getParam('yourName');
$aItem['yourEmail'] = Params::getParam('yourEmail');
$aItem['friendName'] = Params::getParam('friendName');
$aItem['friendEmail'] = Params::getParam('friendEmail');
$aItem['s_title'] = $item['s_title'];
$aItem['message'] = Params::getParam('message');
break;
case 'contact':
-
Incredible simple solution.
PLEASE INTEGRATE THIS INTO THE DOWNLOAD PACKAGE.
Step 1:
EDIT /oc-includes/osclass/ItemActions.php
put this code:
/**
* Return an array with all data necessary for do the action
* @param <type> $action
*/
private function prepareDataForFunction( $action )
{
$aItem = array();
switch ( $action ){
case 'send_friend':
$item = $this->manager->findByPrimaryKey( Params::getParam('id') );
if ($item===false || !is_array($item) || count($item)==0)
break;
$aItem['item'] = $item;
View::newInstance()->_exportVariableToView('item', $aItem['item']);
$aItem['yourName'] = Params::getParam('yourName');
$aItem['yourEmail'] = Params::getParam('yourEmail');
$aItem['friendName'] = Params::getParam('friendName');
$aItem['friendEmail'] = Params::getParam('friendEmail');
$aItem['s_title'] = $item['s_title'];
$aItem['message'] = Params::getParam('message');
$aItem['subject'] = Params::getParam('subject');
break;
instead of this
/**
* Return an array with all data necessary for do the action
* @param <type> $action
*/
private function prepareDataForFunction( $action )
{
$aItem = array();
switch ( $action ){
case 'send_friend':
$item = $this->manager->findByPrimaryKey( Params::getParam('id') );
if ($item===false || !is_array($item) || count($item)==0)
break;
$aItem['item'] = $item;
View::newInstance()->_exportVariableToView('item', $aItem['item']);
$aItem['yourName'] = Params::getParam('yourName');
$aItem['yourEmail'] = Params::getParam('yourEmail');
$aItem['friendName'] = Params::getParam('friendName');
$aItem['friendEmail'] = Params::getParam('friendEmail');
$aItem['s_title'] = $item['s_title'];
$aItem['message'] = Params::getParam('message');
break;
Step 2.
oc-includes/osclass/emails.php
put this code:
function fn_email_send_friend($aItem) {
$mPages = new Page();
$aPage = $mPages->findByInternalName('email_send_friend');
$locale = osc_current_user_locale();
if(isset($aPage['locale'][$locale]['s_title'])) {
$content = $aPage['locale'][$locale];
} else {
$content = current($aPage['locale']);
}
$item_url = osc_item_url();
$item_url = '<a href="'.$item_url.'" >'.$item_url.'</a>';
$words = array();
$words[] = array(
'{FRIEND_NAME}',
'{USER_NAME}',
'{USER_EMAIL}',
'{FRIEND_EMAIL}',
'{ITEM_TITLE}',
'{COMMENT}',
'{ITEM_URL}',
'{ITEM_LINK}',
'{SUBJECT}'
);
$words[] = array(
$aItem['friendName'],
$aItem['yourName'],
$aItem['yourEmail'],
$aItem['friendEmail'],
removeunderline($aItem['s_title']),
$aItem['message'],
osc_item_url(),
$item_url,
$aItem['subject']
);
instead of:
function fn_email_send_friend($aItem) {
$mPages = new Page();
$aPage = $mPages->findByInternalName('email_send_friend');
$locale = osc_current_user_locale();
if(isset($aPage['locale'][$locale]['s_title'])) {
$content = $aPage['locale'][$locale];
} else {
$content = current($aPage['locale']);
}
$item_url = osc_item_url();
$item_url = '<a href="'.$item_url.'" >'.$item_url.'</a>';
$words = array();
$words[] = array(
'{FRIEND_NAME}',
'{USER_NAME}',
'{USER_EMAIL}',
'{FRIEND_EMAIL}',
'{ITEM_TITLE}',
'{COMMENT}',
'{ITEM_URL}',
'{ITEM_LINK}'
);
$words[] = array(
$aItem['friendName'],
$aItem['yourName'],
$aItem['yourEmail'],
$aItem['friendEmail'],
removeunderline($aItem['s_title']),
$aItem['message'],
osc_item_url(),
$item_url
);
Step 3
/oc-includes/osclass/classes/EmailVariables.php
Add this code
),'email_send_friend' => array(
'{FRIEND_NAME}',
'{USER_NAME}',
'{USER_EMAIL}',
'{FRIEND_EMAIL}',
'{ITEM_TITLE}',
'{COMMENT}',
'{ITEM_URL}',
'{ITEM_LINK}',
'{SUBJECT}'
instead of:
),'email_send_friend' => array(
'{FRIEND_NAME}',
'{USER_NAME}',
'{USER_EMAIL}',
'{FRIEND_EMAIL}',
'{ITEM_TITLE}',
'{COMMENT}',
'{ITEM_URL}',
'{ITEM_LINK}'
Final step: Edit email_send_friend in admin area so it includes the {SUBJECT}
-
Nice catch!
I 'd rather see this as an Admin config option 8)
Incredible simple solution.
PLEASE INTEGRATE THIS INTO THE DOWNLOAD PACKAGE.
-
Nice catch!
I 'd rather see this as an Admin config option 8)
Incredible simple solution.
PLEASE INTEGRATE THIS INTO THE DOWNLOAD PACKAGE.
Well if you do the above modifications, you will see {SUBJECT} in your email model send friend right sidebar.
-
Well it's nice to see another 'mod' in the forums anyway, there are several more and it definately helps getting ideas and helping others so thank you is in place ;)