I have a php script which creates its own button, as I am using an open source framework. What I want is to use an image to create a button instead of a the link the is created. Here is the line for which I need the button:
<td class="main button_marg"><?php echo tep_draw_button(IMAGE_BUTTON_REVIEWS . (($reviews['count'] > 0) ? ' (' . $reviews['count'] . ')' : ''), 'comment', tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params())); ?></td>
That is the script I am using to create the review button, but I would like to insert an image into it. Any ideas would be most appreciative.
This is the code for tep_draw_button() function:
function tep_draw_button($title = null, $icon = null, $link = null, $priority = null, $params = null) {
static $button_counter = 1;
$types = array('submit', 'button', 'reset');
if ( !isset($params['type']) ) {
$params['type'] = 'submit';
}
if ( !in_array($params['type'], $types) ) {
$params['type'] = 'submit';
}
if ( ($params['type'] == 'submit') && isset($link) ) {
$params['type'] = 'button';
}
if (!isset($priority)) {
$priority = 'secondary';
}
$button = '<span class="tdbLink">';
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '<a id="tdb' . $button_counter . '" href="' . $link . '"';
if ( isset($params['newwindow']) ) {
$button .= ' target="_blank"';
}
} else {
$button .= '<button id="tdb' . $button_counter . '" type="' . tep_output_string($params['type']) . '"';
}
if ( isset($params['params']) ) {
$button .= ' ' . $params['params'];
}
$button .= '>' . $title;
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '</a>';
} else {
$button .= '</button>';
}
$button .= '</span><script type="text/javascript">$("#tdb' . $button_counter . '").button(';
$args = array();
if ( isset($icon) ) {
if ( !isset($params['iconpos']) ) {
$params['iconpos'] = 'left';
}
if ( $params['iconpos'] == 'left' ) {
$args[] = 'icons:{primary:"ui-icon-' . $icon . '"}';
} else {
$args[] = 'icons:{secondary:"ui-icon-' . $icon . '"}';
}
}
if (empty($title)) {
$args[] = 'text:false';
}
if (!empty($args)) {
$button .= '{' . implode(',', $args) . '}';
}
$button .= ').addClass("ui-priority-' . $priority . '").parent().removeClass("tdbLink");</script>';
$button_counter++;
return $button;
}
?>
You can probably override the style by using some css:
#your_button_id{ background: url(); height: x; width: x; etc... }
.your_button_class{ background: url(); height: x; width: x; etc... }
Try this:
To call the button, use the function with the parameters as they are below:
$image['src'] = 'http://yoururl.com/image.jpg'; // Image Source
$image['height'] = 600; // Image Height
$image['width'] = 300; // Image Width
tep_draw_button(IMAGE_BUTTON_REVIEWS . (($reviews['count'] > 0) ? ' (' . $reviews['count'] . ')' : ''), 'comment', tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params()), null, null, $image);
Then modify the tep_draw_button function like so. If you have an image source in the function parameter, the image will be placed in as a link rather than as a button.
<?
function tep_draw_button($title = null, $icon = null, $link = null, $priority = null, $params = null, $image = null) {
static $button_counter = 1;
if($image != null){
$button = '<span class="tdbLink">';
$button .= '<a id="tdb' . $button_counter . '" href="' . $link . '"';
$button .= '><img src="'. $image['src'] .'"';
if(is_numeric($image['height'])) $button .= ' height="'.$image['height'].'"';
if(is_numeric($image['width'])) $button .= ' width="'.$image['width'].'"';
$button .= 'alt="'.$title.'" /></a></span>';
}else{
$types = array('submit', 'button', 'reset');
if ( !isset($params['type']) ) {
$params['type'] = 'submit';
}
if ( !in_array($params['type'], $types) ) {
$params['type'] = 'submit';
}
if ( ($params['type'] == 'submit') && isset($link) ) {
$params['type'] = 'button';
}
if (!isset($priority)) {
$priority = 'secondary';
}
$button = '<span class="tdbLink">';
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '<a id="tdb' . $button_counter . '" href="' . $link . '"';
if ( isset($params['newwindow']) ) {
$button .= ' target="_blank"';
}
} else {
$button .= '<button id="tdb' . $button_counter . '" type="' . tep_output_string($params['type']) . '"';
}
if ( isset($params['params']) ) {
$button .= ' ' . $params['params'];
}
$button .= '>' . $title;
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '</a>';
} else {
$button .= '</button>';
}
$button .= '</span><script type="text/javascript">$("#tdb' . $button_counter . '").button(';
$args = array();
if ( isset($icon) ) {
if ( !isset($params['iconpos']) ) {
$params['iconpos'] = 'left';
}
if ( $params['iconpos'] == 'left' ) {
$args[] = 'icons:{primary:"ui-icon-' . $icon . '"}';
} else {
$args[] = 'icons:{secondary:"ui-icon-' . $icon . '"}';
}
}
if (empty($title)) {
$args[] = 'text:false';
}
if (!empty($args)) {
$button .= '{' . implode(',', $args) . '}';
}
$button .= ').addClass("ui-priority-' . $priority . '").parent().removeClass("tdbLink");</script>';
$button_counter++;
}
return $button;
}
?>
Let me know if this works, or if you need it tweaked at all. It's hard for me to test since I don't have an oscommerce instance on my machine to test on.
Related
I am using the Divi Theme.
The shortcode is working, however it is displaying directly under the header rather than where I place the shortcode within the Divi Builder.
I read more about WP shortcodes and it looked like we should be using return rather than echo, but when I change it to return it does not display at all on the page.
Thanks!
function breadcrumb() {
$delimiter = '»'; // delimiter between crumbs
$home = 'Home'; // text for the 'Home' link
$showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
$before = '<span class="current">'; // tag before the current crumb
$after = '</span>'; // tag after the current crumb
global $post;
$homeLink = get_bloginfo('url');
echo '<div id="crumbs">' . $home . ' ' . $delimiter . ' ';
if (is_single() && !is_attachment()) {
if (get_post_type() != 'post') {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
return '' . $post_type->labels->singular_name . '';
if ($showCurrent == 1) {
return ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
} else {
$cat = get_the_category();
$cat = $cat[0];
$cats = get_category_parents($cat, true, ' ' . $delimiter . ' ');
if ($showCurrent == 0) {
$cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
}
echo $cats;
if ($showCurrent == 1) {
echo $before . get_the_title() . $after;
}
}
} elseif (!is_single() && !is_page() && get_post_type() != 'post' && !is_404()) {
$post_type = get_post_type_object(get_post_type());
return $before . $post_type->labels->singular_name . $after;
} elseif (is_attachment()) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID);
$cat = $cat[0];
return get_category_parents($cat, true, ' ' . $delimiter . ' ');
echo '' . $parent->post_title . '';
if ($showCurrent == 1) {
echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
} elseif (is_page() && !$post->post_parent) {
if ($showCurrent == 1) {
return $before . get_the_title() . $after;
}
} elseif (is_page() && $post->post_parent) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '' . get_the_title($page->ID) . '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
for ($i = 0; $i < count($breadcrumbs); $i++) {
return $breadcrumbs[$i];
if ($i != count($breadcrumbs)-1) {
return ' ' . $delimiter . ' ';
}
}
if ($showCurrent == 1) {
return ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
}
return '</div>';
}
function breadcrumb() {
$delimiter = '»'; // delimiter between crumbs
$home = 'Home'; // text for the 'Home' link
$showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
$before = '<span class="current">'; // tag before the current crumb
$after = '</span>'; // tag after the current crumb
global $post;
$homeLink = get_bloginfo('url');
$bredcrumb = '<div id="crumbs">' . $home . ' ' . $delimiter . ' ';
if (is_single() && !is_attachment()) {
if (get_post_type() != 'post') {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
$bredcrumb .='' . $post_type->labels->singular_name . '';
if ($showCurrent == 1) {
$bredcrumb .=' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
} else {
$cat = get_the_category();
$cat = $cat[0];
$cats = get_category_parents($cat, true, ' ' . $delimiter . ' ');
if ($showCurrent == 0) {
$cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
}
$bredcrumb .= $cats;
if ($showCurrent == 1) {
$bredcrumb .= $before . get_the_title() . $after;
}
}
} elseif (!is_single() && !is_page() && get_post_type() != 'post' && !is_404()) {
$post_type = get_post_type_object(get_post_type());
$bredcrumb .= $before . $post_type->labels->singular_name . $after;
} elseif (is_attachment()) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID);
$cat = $cat[0];
$bredcrumb .= get_category_parents($cat, true, ' ' . $delimiter . ' ');
$bredcrumb .= '' . $parent->post_title . '';
if ($showCurrent == 1) {
$bredcrumb .= ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
} elseif (is_page() && !$post->post_parent) {
if ($showCurrent == 1) {
$bredcrumb .= $before . get_the_title() . $after;
}
} elseif (is_page() && $post->post_parent) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '' . get_the_title($page->ID) . '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
for ($i = 0; $i < count($breadcrumbs); $i++) {
$bredcrumb .= $breadcrumbs[$i];
if ($i != count($breadcrumbs)-1) {
$bredcrumb .= ' ' . $delimiter . ' ';
}
}
if ($showCurrent == 1) {
$bredcrumb .= ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
}
$bredcrumb .= '</div>';
echo $bredcrumb;
return $bredcrumb;
I have been working on a Gravity Forms extension for a client. The concept is to add a new field type with 4 inputs. I have tried about 10 different variations on how people build custom gravity form fields, but I keep running into the same issue.
When creating a custom field, if I use only 1 input under the naming convention of input_{field_id} the form will save and validate properly. But the moment I try to add more than one field using the names input_{field_id}.{i} just like the built in fields the form will no longer save my data.
<?php if ( ! class_exists( 'GFForms' ) ) { die(); }
class GF_Field_Attendees extends GF_Field {
public $type = 'attendees';
public function get_form_editor_field_title() { return esc_attr__( 'Attendees', 'gravityforms' ); }
public function get_form_editor_button() {
return array(
'group' => 'advanced_fields',
'text' => $this->get_form_editor_field_title(),
'onclick' => "StartAddField('".$this->type."');",
);
}
public function get_form_editor_field_settings() {
return array(
'conditional_logic_field_setting',
'prepopulate_field_setting',
'error_message_setting',
'label_setting',
'admin_label_setting',
'rules_setting',
'duplicate_setting',
'description_setting',
'css_class_setting',
);
}
public function is_conditional_logic_supported() { return true; }
public function get_field_input( $form, $value = '', $entry = null ) {
$form_id = $form['id'];
$field_id = intval( $this->id );
$first = esc_attr( GFForms::get( 'input_' . $this->id . '_1', $value ) );
$last = esc_attr( GFForms::get( 'input_' . $this->id . '_2', $value ) );
$email = esc_attr( GFForms::get( 'input_' . $this->id . '_3', $value ) );
$phone = esc_attr( GFForms::get( 'input_' . $this->id . '_4', $value ) );
$disabled_text = $is_form_editor ? "disabled='disabled'" : '';
$class_suffix = $is_entry_detail ? '_admin' : '';
$first_tabindex = GFCommon::get_tabindex();
$last_tabindex = GFCommon::get_tabindex();
$email_tabindex = GFCommon::get_tabindex();
$phone_tabindex = GFCommon::get_tabindex();
$required_attribute = $this->isRequired ? 'aria-required="true"' : '';
$invalid_attribute = $this->failed_validation ? 'aria-invalid="true"' : 'aria-invalid="false"';
$first_markup = '<span id="input_'.$field_id.'_'.$form_id.'.1_container" class="attendees_first">';
$first_markup .= '<input type="text" name="input_'.$field_id.'.1" id="input_'.$field_id.'_'.$form_id.'_1" value="'.$first.'" aria-label="First Name" '.$first_tabindex.' '.$disabled_text.' '.$required_attribute.' '.$invalid_attribute.'>';
$first_markup .= '<label for="input_'.$field_id.'_'.$form_id.'_1">First Name</label>';
$first_markup .= '</span>';
$last_markup = '<span id="input_'.$field_id.'_'.$form_id.'.2_container" class="attendees_last">';
$last_markup .= '<input type="text" name="input_'.$field_id.'.2" id="input_'.$field_id.'_'.$form_id.'_2" value="'.$last.'" aria-label="Last Name" '.$last_tabindex.' '.$disabled_text.' '.$required_attribute.' '.$invalid_attribute.'>';
$last_markup .= '<label for="input_'.$field_id.'_'.$form_id.'_2">Last Name</label>';
$last_markup .= '</span>';
$email_markup = '<span id="input_'.$field_id.'_'.$form_id.'.3_container" class="attendees_email">';
$email_markup .= '<input type="text" name="input_'.$field_id.'.3" id="input_'.$field_id.'_'.$form_id.'_3" value="'.$email.'" aria-label="Email" '.$email_tabindex.' '.$disabled_text.' '.$required_attribute.' '.$invalid_attribute.'>';
$email_markup .= '<label for="input_'.$field_id.'_'.$form_id.'_3">Email</label>';
$email_markup .= '</span>';
$phone_markup = '<span id="input_'.$field_id.'_'.$form_id.'.4_container" class="attendees_phone">';
$phone_markup .= '<input type="text" name="input_'.$field_id.'.4" id="input_'.$field_id.'_'.$form_id.'_4" value="'.$phone.'" aria-label="Phone #" '.$phone_tabindex.' '.$disabled_text.' '.$required_attribute.' '.$invalid_attribute.'>';
$phone_markup .= '<label for="input_'.$field_id.'_'.$form_id.'_4">Phone #</label>';
$phone_markup .= '</span>';
$css_class = $this->get_css_class();
return "<div class='ginput_complex{$class_suffix} ginput_container {$css_class} gfield_trigger_change' id='{$field_id}'>
{$first_markup}
{$last_markup}
{$email_markup}
{$phone_markup}
<div class='gf_clear gf_clear_complex'></div>
</div>";
}
public function get_css_class() {
$first_input = GFFormsModel::get_input( $this, $this->id . '_2' );
$last_input = GFFormsModel::get_input( $this, $this->id . '_3' );
$email_input = GFFormsModel::get_input( $this, $this->id . '_4' );
$phone_input = GFFormsModel::get_input( $this, $this->id . '_5' );
$css_class = '';
$visible_input_count = 0;
if ( $first_input && ! rgar( $first_input, 'isHidden' ) ) {
$visible_input_count++;
$css_class .= 'has_first_name ';
} else {
$css_class .= 'no_first_name ';
}
if ( $last_input && ! rgar( $last_input, 'isHidden' ) ) {
$visible_input_count++;
$css_class .= 'has_last_name ';
} else {
$css_class .= 'no_last_name ';
}
if ( $email_input && ! rgar( $email_input, 'isHidden' ) ) {
$visible_input_count++;
$css_class .= 'has_email ';
} else {
$css_class .= 'no_email ';
}
if ( $phone_input && ! rgar( $phone_input, 'isHidden' ) ) {
$visible_input_count++;
$css_class .= 'has_phone ';
} else {
$css_class .= 'no_phone ';
}
$css_class .= "gf_attendees_has_{$visible_input_count} ginput_container_attendees ";
return trim( $css_class );
}
public function get_value_submission( $field_values, $get_from_post ) {
if(!$get_from_post) {
return $field_values;
}
return $_POST;
}
}
GF_Fields::register( new GF_Field_Attendees() );
I have spend about 20 hours trying different fixes and searching the internet to get this working, with no luck to show for it. At one point I was able to get the form fields to save using a different method (see below), but I could not make the field required or use conditional login on it, which is a must.
$group_title = "Attendees";
$group_name = "attendees";
$group_fields = array(
'attendee_first' => 'First Name',
'attendee_last' => 'Last Name',
'attendee_email' => 'Email',
'attendee_phone' => 'Phone'
);
$group_values = array();
add_filter('gform_add_field_buttons', add_field);
function add_field($field_group)
{
global $group_title, $group_name;
foreach ($field_group as &$group) {
if ($group['name'] == 'advanced_fields') {
$group['fields'][] = array (
'class' => 'button',
'value' => __($group_title, 'gravityforms'),
'onclick' => "StartAddField('".$group_name."');",
'data-type' => $group_name
);
break;
}
}
return $field_group;
}
add_filter('gform_field_type_title', add_field_title, 10, 2);
function add_field_title($title, $field_type)
{
global $group_title, $group_name;
if ($field_type == $group_name) {
$title = __($group_title, 'gravityforms');
}
return $title;
}
add_filter('gform_field_input', 'render_fields', 10, 5);
function render_fields($input, $field, $value, $entry_id, $form_id)
{
global $group_name, $group_fields;
if ($field->type == $group_name)
{
$i = 1;
$input = '<div class="ginput_complex ginput_container">';
foreach ($group_fields as $key => $val) {
$input .= '<span id="input_'.$field['id'].'_'.$form_id.'_'.$i.'_container" class="name_suffix ">';
$input .= '<input type="text" name="input_'.$field['id'].'_'.$i.'" id="input_'.$field['id'].'_'.$form_id.'_'.$i.'" value="'.$value[$field['id'].'.'.$i].'" class="'.esc_attr($key).'" aria-label="'.$val.'">';
$input .= '<label for="input_'.$field['id'].'_'.$form_id.'_'.$i.'">'.$val.'</label>';
$input .= '</span>';
$i ++;
if ($i % 10 == 0) { $i++; }
}
$input .= '</div>';
}
return $input;
}
add_action('gform_editor_js_set_default_values', set_default_values);
function set_default_values()
{
global $group_title, $group_name, $group_fields;
?>
case '<?php echo $group_name; ?>' :
field.label = '<?php _e($group_title, 'gravityforms'); ?>';
field.inputs = [
<?php
$i = 1;
foreach ($group_fields as $key => $val) { ?>
new Input(field.id + 0.<?php echo $i; ?>, '<?php echo esc_js(__($val, 'gravityforms')); ?>'),
<?php
$i++;
if ($i % 10 == 0) { $i++; }
} ?>
];
break;
<?php
}
add_filter( 'gform_entry_field_value', 'category_names', 10, 4 );
function category_names( $value, $field, $lead, $form )
{
global $group_name, $group_values;
if($field->type == $group_name)
{
$array = array();
$output = "";
foreach($field->inputs as $input)
{
$array[$input['label']] = $value[$input['id']];
$output .= "<strong>".$input['label'].":</strong> ";
$output .= $value[$input['id']]."<br>";
}
$group_values[] = $array;
return $output;
}
return $value;
}
If anyone can help me with either issue, it would be greatly appreciated.
Class update:
Cleaned Up get_field_input
Added get_value_submission
After working with the Gravity Forms support team for a few days, we were able to come up with this solution. Everything seems to be working now. Hope this helps someone in the future.
class GF_Field_Attendees extends GF_Field {
public $type = 'attendees';
public function get_form_editor_field_title() {
return esc_attr__( 'Attendees', 'gravityforms' );
}
public function get_form_editor_button() {
return array(
'group' => 'advanced_fields',
'text' => $this->get_form_editor_field_title(),
);
}
public function get_form_editor_field_settings() {
return array(
'conditional_logic_field_setting',
'prepopulate_field_setting',
'error_message_setting',
'label_setting',
'admin_label_setting',
'rules_setting',
'duplicate_setting',
'description_setting',
'css_class_setting',
);
}
public function is_conditional_logic_supported() {
return true;
}
public function get_field_input( $form, $value = '', $entry = null ) {
$is_entry_detail = $this->is_entry_detail();
$is_form_editor = $this->is_form_editor();
$form_id = $form['id'];
$field_id = intval( $this->id );
$first = $last = $email = $phone = '';
if ( is_array( $value ) ) {
$first = esc_attr( rgget( $this->id . '.1', $value ) );
$last = esc_attr( rgget( $this->id . '.2', $value ) );
$email = esc_attr( rgget( $this->id . '.3', $value ) );
$phone = esc_attr( rgget( $this->id . '.4', $value ) );
}
$disabled_text = $is_form_editor ? "disabled='disabled'" : '';
$class_suffix = $is_entry_detail ? '_admin' : '';
$first_tabindex = GFCommon::get_tabindex();
$last_tabindex = GFCommon::get_tabindex();
$email_tabindex = GFCommon::get_tabindex();
$phone_tabindex = GFCommon::get_tabindex();
$required_attribute = $this->isRequired ? 'aria-required="true"' : '';
$invalid_attribute = $this->failed_validation ? 'aria-invalid="true"' : 'aria-invalid="false"';
$first_markup = '<span id="input_' . $field_id . '_' . $form_id . '.1_container" class="attendees_first">';
$first_markup .= '<input type="text" name="input_' . $field_id . '.1" id="input_' . $field_id . '_' . $form_id . '_1" value="' . $first . '" aria-label="First Name" ' . $first_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
$first_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_1">First Name</label>';
$first_markup .= '</span>';
$last_markup = '<span id="input_' . $field_id . '_' . $form_id . '.2_container" class="attendees_last">';
$last_markup .= '<input type="text" name="input_' . $field_id . '.2" id="input_' . $field_id . '_' . $form_id . '_2" value="' . $last . '" aria-label="Last Name" ' . $last_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
$last_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_2">Last Name</label>';
$last_markup .= '</span>';
$email_markup = '<span id="input_' . $field_id . '_' . $form_id . '.3_container" class="attendees_email">';
$email_markup .= '<input type="text" name="input_' . $field_id . '.3" id="input_' . $field_id . '_' . $form_id . '_3" value="' . $email . '" aria-label="Email" ' . $email_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
$email_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_3">Email</label>';
$email_markup .= '</span>';
$phone_markup = '<span id="input_' . $field_id . '_' . $form_id . '.4_container" class="attendees_phone">';
$phone_markup .= '<input type="text" name="input_' . $field_id . '.4" id="input_' . $field_id . '_' . $form_id . '_4" value="' . $phone . '" aria-label="Phone #" ' . $phone_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
$phone_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_4">Phone #</label>';
$phone_markup .= '</span>';
$css_class = $this->get_css_class();
return "<div class='ginput_complex{$class_suffix} ginput_container {$css_class} gfield_trigger_change' id='{$field_id}'>
{$first_markup}
{$last_markup}
{$email_markup}
{$phone_markup}
<div class='gf_clear gf_clear_complex'></div>
</div>";
}
public function get_css_class() {
$first_input = GFFormsModel::get_input( $this, $this->id . '.1' );
$last_input = GFFormsModel::get_input( $this, $this->id . '.2' );
$email_input = GFFormsModel::get_input( $this, $this->id . '.3' );
$phone_input = GFFormsModel::get_input( $this, $this->id . '.4' );
$css_class = '';
$visible_input_count = 0;
if ( $first_input && ! rgar( $first_input, 'isHidden' ) ) {
$visible_input_count ++;
$css_class .= 'has_first_name ';
} else {
$css_class .= 'no_first_name ';
}
if ( $last_input && ! rgar( $last_input, 'isHidden' ) ) {
$visible_input_count ++;
$css_class .= 'has_last_name ';
} else {
$css_class .= 'no_last_name ';
}
if ( $email_input && ! rgar( $email_input, 'isHidden' ) ) {
$visible_input_count ++;
$css_class .= 'has_email ';
} else {
$css_class .= 'no_email ';
}
if ( $phone_input && ! rgar( $phone_input, 'isHidden' ) ) {
$visible_input_count ++;
$css_class .= 'has_phone ';
} else {
$css_class .= 'no_phone ';
}
$css_class .= "gf_attendees_has_{$visible_input_count} ginput_container_attendees ";
return trim( $css_class );
}
public function get_form_editor_inline_script_on_page_render() {
// set the default field label for the field
$script = sprintf( "function SetDefaultValues_%s(field) {
field.label = '%s';
field.inputs = [new Input(field.id + '.1', '%s'), new Input(field.id + '.2', '%s'), new Input(field.id + '.3', '%s'), new Input(field.id + '.4', '%s')];
}", $this->type, $this->get_form_editor_field_title(), 'First Name', 'Last Name', 'Email', 'Phone' ) . PHP_EOL;
return $script;
}
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
if ( is_array( $value ) ) {
$first = trim( rgget( $this->id . '.1', $value ) );
$last = trim( rgget( $this->id . '.2', $value ) );
$email = trim( rgget( $this->id . '.3', $value ) );
$phone = trim( rgget( $this->id . '.4', $value ) );
$return = $first;
$return .= ! empty( $return ) && ! empty( $last ) ? " $last" : $last;
$return .= ! empty( $return ) && ! empty( $email ) ? " $email" : $email;
$return .= ! empty( $return ) && ! empty( $phone ) ? " $phone" : $phone;
} else {
$return = '';
}
if ( $format === 'html' ) {
$return = esc_html( $return );
}
return $return;
}
}
GF_Fields::register( new GF_Field_Attendees() );
I've been having difficulties getting the value from rgget for the fields and I had to change it to the following to get it to work:
rgget( 'input_' . $this->id . '_1', $value )
i installed a Joomla template and some errors are appearing in homepage, the Errors are related to the Sp Page Builder component.
How can i fix these errors?
Here's a document with the erros - https://drive.google.com/open?id=0B1toGflgmV7fZi1SQ051QWZxZFE
And the site.php
<?php
/**
* Flex 1.0 #package SP Page Builder
* Template Name - Flex
* #author Aplikko http://www.aplikko.com
* #copyright Copyright (c) 2015 Aplikko
* #license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
// no direct access
defined('_JEXEC') or die;
JLoader::register('JHtmlString', JPATH_LIBRARIES.'/joomla/html/html/string.php');
AddonParser::addAddon('sp_latest_posts','sp_latest_posts_addon');
function get_categories($parent=1) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select('*')
->from($db->quoteName('#__categories'))
->where($db->quoteName('extension') . ' = ' . $db->quote('com_content'))
->where($db->quoteName('published') . ' = ' . $db->quote(1))
->where($db->quoteName('parent_id') . ' = ' . $db->quote($parent))
->order($db->quoteName('created_time') . ' DESC');
$db->setQuery($query);
$cats = $db->loadObjectList();
$categories = array($parent);
foreach ($cats as $key => $cat) {
$categories[] = $cat->id;
}
return $categories;
}
function sp_latest_posts_addon($atts){
extract(spAddonAtts(array(
"title" => '',
"heading_selector" => 'h3',
"title_fontsize" => '',
"title_text_color" => '',
"title_margin_top" => '',
"title_margin_bottom" => '',
"show_image" => '',
"show_date" => '',
"show_category" => '',
"show_intro_text" => '',
"show_author" => '',
"item_limit" => '',
"intro_text_limit" => '100',
"column_no" => '3',
"image_alignment" => '',
"category" => '',
"style" => '',
"class" => '',
), $atts));
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
// Database Query
require_once JPATH_SITE . '/components/com_content/helpers/route.php';
// Access filter
$access = !JComponentHelper::getParams('com_content')->get('show_noauth');
$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select('a.*')
->from($db->quoteName('#__content', 'a'))
->select($db->quoteName('b.alias', 'category_alias'))
->select($db->quoteName('b.title', 'category'))
->join('LEFT', $db->quoteName('#__categories', 'b') . ' ON (' . $db->quoteName('a.catid') . ' = ' . $db->quoteName('b.id') . ')')
->where($db->quoteName('b.extension') . ' = ' . $db->quote('com_content'))
->where($db->quoteName('a.state') . ' = ' . $db->quote(1))
->where($db->quoteName('a.catid')." IN (" . implode( ',', get_categories($category) ) . ")")
->where($db->quoteName('a.access')." IN (" . implode( ',', $authorised ) . ")")
->order($db->quoteName('a.created') . ' DESC')
->setLimit($item_limit);
$db->setQuery($query);
$items = $db->loadObjectList();
// End Database Query
$style == 'flex' ? $flex_style = ' flex' : '';
$style == 'blog' ? $blog_style = ' blog' : '';
$blog_style = $output = '<div class="sppb-addon sppb-addon-latest-posts'.$flex_style.$blog_style.' sppb-row ' . $class . '">';
if ($title) {
$output .= '<div class="sppb-section-title">';
$output .= '<'.$heading_selector.' class="sppb-addon-title" style="' . $title_style . '"> ' . $title . '</' . $heading_selector . '>';
$output .= '</div>'; // END :: title
}
$output .= '<div class="sppb-addon-content">';
$output .= '<div class="latest-posts clearfix">';
foreach(array_chunk($items, $column_no) as $items) {
$output .= '<div>';
foreach ($items as $item) {
$item->slug = $item->id . ':' . $item->alias;
$item->catslug = $item->catid . ':' . $item->category_alias;
$item->user = JFactory::getUser($item->created_by)->name;
if ($access || in_array($item->access, $authorised)) {
// We know that user has the privilege to view the article
$item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language));
$item->catlink = JRoute::_(ContentHelperRoute::getCategoryRoute($item->catslug, $item->catid, $item->language));
} else {
$item->link = JRoute::_('index.php?option=com_users&view=login');
$item->catlink = JRoute::_('index.php?option=com_users&view=login');
}
$tplParams = JFactory::getApplication()->getTemplate(true)->params;
$params = $item->params;
$attribs = json_decode($item->attribs);
$images = json_decode($item->images);
$imgsize = $tplParams->get('blog_list_image', 'default');
$intro_image = '';
if(isset($attribs->spfeatured_image) && $attribs->spfeatured_image != '') {
if($imgsize == 'default') {
$intro_image = $attribs->spfeatured_image;
} else {
$intro_image = $attribs->spfeatured_image;
$basename = basename($intro_image);
$list_image = JPATH_ROOT . '/' . dirname($intro_image) . '/' . JFile::stripExt($basename) . '_'. $imgsize .'.' . JFile::getExt($basename);
if(file_exists($list_image)) {
$intro_image = JURI::root(true) . '/' . dirname($intro_image) . '/' . JFile::stripExt($basename) . '_'. $imgsize .'.' . JFile::getExt($basename);
}
}
} elseif(isset($images->image_intro) && !empty($images->image_intro)) {
$intro_image = $images->image_intro;
}
if($column_no == '1') {
if ($show_image) {
$image_alignment == 'left' ? $img_column = 'sppb-col-sm-4 column-1 pull-left match-height' : $img_column = 'sppb-col-sm-4 column-1 pull-right match-height';
}
if ($show_image) {
$image_alignment == 'right' ? $content_column = 'sppb-col-sm-8 column-1 pull-left match-height' : $content_column = 'sppb-col-sm-8 column-1 pull-right match-height';
} else {
$image_alignment == 'right' ? $content_column = 'sppb-col-sm-12 column-1' : $content_column = 'sppb-col-sm-12 column-1';
}
$h2style = ' style="font-size:180%;line-height:1.4;"';
$img_wrapper_margin = ' style="margin:0;"';
if ($image_alignment == 'left') {
$inner_padding = ' style="padding:0 0 0 30px;"';
} else {
$inner_padding = ' style="padding:0 30px 0 0;"';
}
}
// match-height
$column_no > '1' ? $match_height = ' match-height' : '';
// Flex Style
if($style == 'flex') {
$output .= '<div class="latest-post sppb-col-sm-' . round(12/$column_no) . ' columns-'.$column_no.'">';
$output .= '<div class="latest-post-item">';
if($column_no == '1') {
$output .= '<div class="row-fluid">';
}
if(!empty($intro_image) || (isset($images->image_intro) && !empty($images->image_intro))) {
if ($show_image) {
if($column_no == '1') {
$output .= '<div style="padding:0" class="'.$img_column.'">';
}
$output .= '<div class="img-wrapper">';
$output .= '<img class="post-img" src="' . $intro_image . '" alt="' . $item->title . '" /><div class="caption-content">' . $item->title . '<em class="caption-category"><span class="posted-in">'. JText::_('COM_SPPAGEBUILDER_ADDON_POSTED_IN') .'</span>'. $item->category . '</em></div>';
$output .= '</div>';
if($column_no == '1') {
$output .= '</div>';
}
}
}
if($column_no == '1') {
$output .= '<div'.$inner_padding.' class="'.$content_column.'">';
}
$output .= '<div class="latest-post-inner match-height">';
if (($show_date || $show_intro_text || $show_author) != 1) {
$output .= '<h2 style="margin:0" class="entry-title">' . $item->title . '</h2>';
} else {
$output .= '<h2'.$h2style.' class="entry-title">' . $item->title . '</h2>';
}
if ($show_date) {
$output .= '<div class="entry-meta"><span class="entry-date">' . JHtml::_('date', $item->created, 'DATE_FORMAT_LC1') . '</span></div>';
}
if ($show_intro_text) {
$output .= '<p class="intro-text" >' . JHtml::_('string.truncate', strip_tags($item->introtext), $intro_text_limit) . '</p>';
}
$show_author || $show_category ? $output .= '<hr />' : '';
if ($show_author) {
$output .= '<span class="post-author"><span class="entry-author">' . JText::_('COM_SPPAGEBUILDER_ADDON_POSTED_BY'). '</span> ' . $item->user . '</span>';
}
if ($show_category) {
$show_author ? $posted_in_category = ' cat-inline' : '';
$output .= '<span class="category'.$posted_in_category.'"><span class="posted-in">'. JText::_('COM_SPPAGEBUILDER_ADDON_CATEGORY') .'</span>'. $item->category . '</span>';
}
if($column_no == '1') {
$output .= '</div>';
$output .= '</div>';
}
$output .= '</div>';
if($column_no == '1') {
$output .= '<div class="post-divider"></div>';
}
$output .= '</div>';
// Default & Blog styles
} else {
$output .= '<div class="latest-post sppb-col-sm-' . round(12/$column_no) . ' columns-'.$column_no.'">';
$output .= '<div class="latest-post-inner' . $match_height . '">';
if($column_no == '1') {
$output .= '<div class="row-fluid">';
}
if ($show_image) {
if($column_no == '1') {
$output .= '<div class="'.$img_column.'">';
}
$output .= '<div'.$img_wrapper_margin.' class="img-wrapper">';
$output .= '<img class="post-img" src="' . $intro_image . '" alt="' . $item->title . '" />';
$output .= '</div>';
if($column_no == '1') {
$output .= '</div>';
}
}
if($column_no == '1') {
$output .= '<div class="'.$content_column.'">';
}
if ($show_date) {
$output .= '<div class="entry-meta"><span class="entry-date"> ' . JHtml::_('date', $item->created, 'DATE_FORMAT_LC1') . '</span></div>';
}
$output .= '<h2'.$h2style.' class="entry-title">' . $item->title . '</h2>';
if ($show_intro_text) {
$output .= '<p class="intro-text" >' . JHtml::_('string.truncate', strip_tags($item->introtext), $intro_text_limit) . '</p>';
}
$show_author || $show_category ? $output .= '<hr />' : '';
if ($show_author) {
$output .= '<span class="post-author"><span class="entry-author">' . JText::_('COM_SPPAGEBUILDER_ADDON_POSTED_BY'). ' ' . $item->user . '</span></span>';
}
if ($show_category) {
$show_author ? $posted_in_category = ' cat-inline' : '';
$output .= '<span class="category'.$posted_in_category.'"><span class="posted-in">'. JText::_('COM_SPPAGEBUILDER_ADDON_CATEGORY') .'</span>'. $item->category . '</span>';
}
if($column_no == '1') {
$output .= '</div>';
$output .= '</div>';
}
$output .= '</div>';
}
$output .= '</div>';
}
$output .= '</div>';
}
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
$column_no == '1' ? $column_no_1 = '.column-1 {margin:10px auto;padding:0!important;}' : '';
// Add styles #media rulepost-img
if($style == 'flex') {
$custom_style = ''
. '#media screen and (max-width: 768px) {'
. $column_no_1
. '.img-wrapper a {font-size:150%;line-height:1.5;}'
. '}';
$doc->addStyleDeclaration($custom_style);
}
if ($column_no>='3') {
$custom_style_3 = ''
. '#media screen and (min-width: 992px) and (max-width: 1199px){'
. '.columns-'.$column_no.'{width:33.3333%;}'
. '}'
. '#media screen and (min-width: 768px) and (max-width: 991px){'
. '.columns-'.$column_no.'{width:50%}'
. '}';
$doc->addStyleDeclaration($custom_style_3);
}
if($column_no=='5') {
$custom_style_5 = ''
. '.columns-'.$column_no.' {width:20%}'
. '#media screen and (min-width: 992px) and (max-width: 1199px){'
. '.columns-'.$column_no.'{width:33.3333%;}'
. '}'
. '#media screen and (min-width: 768px) and (max-width: 991px){'
. '.columns-'.$column_no.'{width:50%}'
. '}'
. '#media screen and (max-width: 767px){'
. '.columns-'.$column_no.'{width:100%}'
. '}';
$doc->addStyleDeclaration($custom_style_5);
}
return $output;
}
Thanks!
There is many errors, but all of them are variable that have not been declared before using it, as example :
$style == 'flex' ? $flex_style = ' flex' : '';
$style == 'blog' ? $blog_style = ' blog' : '';
$blog_style = $output = '<div class="sppb-addon sppb-addon-latest-posts'.$flex_style.$blog_style.' sppb-row ' . $class . '">';
In this case $flex_style and $blog_style are not declared, you should write this instead :
$flex_style = style == 'flex' ? ' flex' : '';
$blog_style = $style == 'blog' ? ' blog' : '';
That is just an example, but if you search a little you'll find other issue like this one.
I am trying to aggregate the latest posts by several blogs using their rss feed. The code below is working fine for most platforms including blogg.se . Although it is strangely not working with a blog from blogg.se called, http://sofiasinredning.blogg.se/index.rss .
function wpse_187819_get_feed_html( $url, $bloggauthor ) {
if ( !is_admin() ) {
if ( is_wp_error( $rss = fetch_feed( $url ) ) )
return;
$maxitems = $rss->get_item_quantity( 1 );
$rss_items = $rss->get_items( 0, $maxitems );
$html = '<ul class="rss-items rss-old" id="wows-feeds">';
if (!empty($bloggauthor)) {
$authorcredit = '<span class="field-label">' . $bloggauthor . '</span>';
} else { $authorcredit = '<span class="field-label"> Name </span>';}
if ( $maxitems ) {
foreach ( $rss_items as $item ) {
$title = esc_attr( $item->get_title() );
$link = esc_url( $item->get_permalink() );
$stringses = $item-> get_description();
global $wp_query;
$lengthses = '';
if ( $wp_query->is_page ) {
$lengthses = '100';
} elseif ( $wp_query->is_home ) {
$lengthses = '100';
} elseif ( $wp_query->is_single ) {
$lengthses = '700';
} elseif ( $wp_query->is_category ) {
$lengthses = '100';
} elseif ( $wp_query->is_tag ) {
$lengthses = '50';
} elseif ( $wp_query->is_tax ) {
$lengthses = '30';
} elseif ( $wp_query->is_archive ) {
if ( $wp_query->is_day ) {
$lengthses = '60';
} elseif ( $wp_query->is_month ) {
$lengthses = '60';
} elseif ( $wp_query->is_year ) {
$lengthses = '60';
} elseif ( $wp_query->is_author ) {
$lengthses = '400';
} else {
$lengthses = '500';
}
} elseif ( $wp_query->is_search ) {
$lengthses = '400';
} elseif ( $wp_query->is_404 ) {
$lengthses = '';
}
$date = $item->get_date('F Y');
$suffix = '…';
$short_desc = trim(str_replace(array(" ", "/r", "/n", "/t"), '', strip_tags($stringses)));
$desc = trim(substr($short_desc, 0, $lengthses));
$lastchar = substr($desc, 0, 1);
if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
$desc .= $suffix;
$html .= '<li class="item"><a target="_blanc" href="' . $link . '" title="' . $title . '">';
if ( preg_match( '/<img.+?src="(.+?)"/', $item->get_content(), $matches ) ) {
$html .= '<span class="rss-image"><div class="square attachment-special" style="background-image: url(' . $matches[1] . ');"><img style="opacity: 0;" class="attachment-special" src="' . $matches[1] . '"/></div></span></a>';
}
elseif ($enclosure = $item->get_enclosure()) {
$html .= '<span class="rss-image"><div class="square attachment-special" style="background-image: url(' . $enclosure->get_link() . ');"><img style="opacity: 0;" class="attachment-special" src="' . $enclosure->get_link() . '"/></div></span></a>';
}
else {
$html .= '<img class="attachment-special" src="' . get_stylesheet_directory_uri() . '/img/logga/500x500.png"/></a>';
}
$html .= '<div class="item-content"><h5 class="pink-text">' . $authorcredit . '</h5><a target="_blanc" href="' . $link . '" title="' . $title . '"><span class="data"><h1 class="entry-title">' . $title . '</h1></span></a>';
$html .= '<p>' . $desc . '</p>';
$html .= '</li>';
}
} else {
$html .= '<li>No items</li>';
}
$html .= '</ul>';
echo $html;
}
}
Thanks in advance
On this site (link to product page: http://www.boatingsupplynow.com/product_info.php?cPath=979_1044&products_id=29943) the images appear stretched.
I have applied 2 different image stretch contribution fixes, neither seem to work. I have attached a screenshot of my images settings on the admin side. Please help!!
<?php
/*
$Id$
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2010 osCommerce
Released under the GNU General Public License
*/
////
// The HTML href link wrapper function
function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {
global $request_type, $session_started, $SID;
$page = tep_output_string($page);
if (!tep_not_null($page)) {
die('</td></tr></table></td></tr></table><br /><br /><font color="#ff0000"><strong>Error!</strong></font><br /><br /><strong>Unable to determine the page link!<br /><br />');
}
if ($connection == 'NONSSL') {
$link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
} elseif ($connection == 'SSL') {
if (ENABLE_SSL == true) {
$link = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG;
} else {
$link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
}
} else {
die('</td></tr></table></td></tr></table><br /><br /><font color="#ff0000"><strong>Error!</strong></font><br /><br /><strong>Unable to determine connection method on a link!<br /><br />Known methods: NONSSL SSL</strong><br /><br />');
}
if (tep_not_null($parameters)) {
$link .= $page . '?' . tep_output_string($parameters);
$separator = '&';
} else {
$link .= $page;
$separator = '?';
}
while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1);
// Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined
if ( ($add_session_id == true) && ($session_started == true) && (SESSION_FORCE_COOKIE_USE == 'False') ) {
if (tep_not_null($SID)) {
$_sid = $SID;
} elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL == true) ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) {
if (HTTP_COOKIE_DOMAIN != HTTPS_COOKIE_DOMAIN) {
$_sid = tep_session_name() . '=' . tep_session_id();
}
}
}
if (isset($_sid)) {
$link .= $separator . tep_output_string($_sid);
}
while (strstr($link, '&&')) $link = str_replace('&&', '&', $link);
if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
$link = str_replace('?', '/', $link);
$link = str_replace('&', '/', $link);
$link = str_replace('=', '/', $link);
} else {
$link = str_replace('&', '&', $link);
}
return $link;
}
////
// The HTML image wrapper function
// Replaces original OScommerce img tag's with call-to image.php(GD-library imagecopyresampled)
// JPG, BMP images will optimized prior to downloading
// GIF, PNG will not be optimized
// Frank Swayze 09/28/2008
function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '', $stretch='false') {
if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {
return false;
}
$img_type = exif_imagetype($src);
// alt is added to the img tag even if it is null to prevent browsers from outputting
// the image filename as default
// calculate any missing dimensions from function call. Necessary if image is to be resized.
if (empty($width) || empty($height)) {
if ($image_size = #getimagesize($src)) {
if (empty($width) && !empty($height)) {
$ratio = $height / $image_size[1];
$width = intval($image_size[0] * $ratio);
} elseif (!empty($width) && empty($height)) {
$ratio = $width / $image_size[0];
$height = intval($image_size[1] * $ratio);
} elseif (empty($width) && empty($height)) {
$width = $image_size[0];
$height = $image_size[1];
}
} elseif (IMAGE_REQUIRED == 'false') {
return false;
}
}
if (($img_type != IMAGETYPE_GIF && $img_type != IMAGETYPE_PNG) && (!(file_exists(DIR_FS_CATALOG . $src)) || filesize(DIR_FS_CATALOG . $src) > 30)) { // if checks for existance of file and skips resizing for files less than 3000bytes( 3 Kb)
$image = '<img src="image.php?src=' . htmlspecialchars($src) . '&width=' . htmlspecialchars($width) . '&height=' . htmlspecialchars($height) . '"';
} else {
$image = '<img src="' . htmlspecialchars($src) . '" width="' . htmlspecialchars($width) . '" height="' . htmlspecialchars($height) . '"';
}
$image .= ' border="0" alt="' . htmlspecialchars($alt) . '"';
if (!empty($alt)) {
$image .= ' title=" ' . htmlspecialchars($alt) . ' "';
}
if (!empty($parameters)) $image .= ' ' . $parameters;
$image .= '>';
return $image;
}
////
// The HTML form submit button wrapper function
// Outputs a button in the selected language
function tep_image_submit($image, $alt = '', $parameters = '') {
global $language;
$image_submit = '<input type="image" src="' . tep_output_string(DIR_WS_LANGUAGES . $language . '/images/buttons/' . $image) . '" alt="' . tep_output_string($alt) . '"';
if (tep_not_null($alt)) $image_submit .= ' title=" ' . tep_output_string($alt) . ' "';
if ( (CONFIG_CALCULATE_IMAGE_SIZE == 'true') )
{
if ($image_size = #getimagesize($src))
{
if (empty($width) && tep_not_null($height))
{
if (($image_size[1] < $height) && ($stretch=='false'))
{
// EC - if width hasn't been passed in, the image height is smaller than the setting, and stretch is false, use original dimensions
$width=$image_size[0];
$height=$image_size[1];
}
else
{
// EC - if width hasn't been passed, and the image height is larger than the setting, height ends up as the setting and width is modified to suit
$ratio = $height / $image_size[1];
$width = $image_size[0] * $ratio;
}
}
elseif (tep_not_null($width) && empty($height))
{
// EC - if height hasn't been passed in, the image width is smaller than the setting, and stretch is false, use original dimensions
if (($image_size[0] < $width) && ($stretch=='false'))
{
$width=$image_size[0];
$height=$image_size[1];
}
else
{
// EC - if height hasn't been passed, and the image width is larger than the setting, width ends up as the setting and height is modified to suit
$ratio = $width / $image_size[0];
$height = $image_size[1] * $ratio;
}
}
elseif (empty($width) && empty($height))
{
// EC - if neither height nor width are passed in, just use the original dimensions
$width = $image_size[0];
$height = $image_size[1];
}
//EC - added the following elseif for calculating based on stretch/no-stretch
elseif (tep_not_null($width) && tep_not_null($height))
{
if ((($image_size[0] > $width) || ($image_size[1] > $height)) && ($stretch=='false'))
{
// EC - if width and height are both passed in, either original height or width are larger than the setting, and stretch is false, resize both dimensions to suit
$new_ratio=$height / $width;
$image_ratio=$image_size[1] / $image_size[0];
if ($new_ratio >= $image_ratio)
{
$height=$image_size[1]*($width/$image_size[0]);
}
else
{
$width=$image_size[0]*($height/$image_size[1]);
}
}
elseif ($stretch=='false')
{
// EC - if we got here, both width and height have been passed in, both original height and width are smaller than setting, and stretch is set to false. So just use original dimensions.
$width=$image_size[0];
$height=$image_size[1];
}
}
}
elseif (IMAGE_REQUIRED == 'false')
{
return false;
}
}
if (tep_not_null($width) && tep_not_null($height)) {
$image .= ' width="' . tep_output_string($width) . '" height="' . tep_output_string($height) . '"';
}
if (tep_not_null($parameters)) $image_submit .= ' ' . $parameters;
$image_submit .= ' />';
return $image_submit;
}
////
// Output a function button in the selected language
function tep_image_button($image, $alt = '', $parameters = '') {
global $language;
return tep_image(DIR_WS_LANGUAGES . $language . '/images/buttons/' . $image, $alt, '', '', $parameters);
}
////
// Output a separator either through whitespace, or with an image
function tep_draw_separator($image = 'pixel_black.gif', $width = '100%', $height = '1') {
return tep_image(DIR_WS_IMAGES . $image, '', $width, $height);
}
////
// Output a form
function tep_draw_form($name, $action, $method = 'post', $parameters = '', $tokenize = false) {
global $sessiontoken;
$form = '<form name="' . tep_output_string($name) . '" action="' . tep_output_string($action) . '" method="' . tep_output_string($method) . '"';
if (tep_not_null($parameters)) $form .= ' ' . $parameters;
$form .= '>';
if ( ($tokenize == true) && isset($sessiontoken) ) {
$form .= '<input type="hidden" name="formid" value="' . tep_output_string($sessiontoken) . '" />';
}
return $form;
}
////
// Output a form input field
function tep_draw_input_field($name, $value = '', $parameters = '', $type = 'text', $reinsert_value = true) {
global $HTTP_GET_VARS, $HTTP_POST_VARS;
$field = '<input type="' . tep_output_string($type) . '" name="' . tep_output_string($name) . '"';
if ( ($reinsert_value == true) && ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) ) {
if (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) {
$value = stripslashes($HTTP_GET_VARS[$name]);
} elseif (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) {
$value = stripslashes($HTTP_POST_VARS[$name]);
}
}
if (tep_not_null($value)) {
$field .= ' value="' . tep_output_string($value) . '"';
}
if (tep_not_null($parameters)) $field .= ' ' . $parameters;
$field .= ' />';
return $field;
}
////
// Output a form password field
function tep_draw_password_field($name, $value = '', $parameters = 'maxlength="40"') {
return tep_draw_input_field($name, $value, $parameters, 'password', false);
}
////
// Output a selection field - alias function for tep_draw_checkbox_field() and tep_draw_radio_field()
function tep_draw_selection_field($name, $type, $value = '', $checked = false, $parameters = '') {
global $HTTP_GET_VARS, $HTTP_POST_VARS;
$selection = '<input type="' . tep_output_string($type) . '" name="' . tep_output_string($name) . '"';
if (tep_not_null($value)) $selection .= ' value="' . tep_output_string($value) . '"';
if ( ($checked == true) || (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name]) && (($HTTP_GET_VARS[$name] == 'on') || (stripslashes($HTTP_GET_VARS[$name]) == $value))) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name]) && (($HTTP_POST_VARS[$name] == 'on') || (stripslashes($HTTP_POST_VARS[$name]) == $value))) ) {
$selection .= ' checked="checked"';
}
if (tep_not_null($parameters)) $selection .= ' ' . $parameters;
$selection .= ' />';
return $selection;
}
////
// Output a form checkbox field
function tep_draw_checkbox_field($name, $value = '', $checked = false, $parameters = ' style="background:none;border:0px;"') {
return tep_draw_selection_field($name, 'checkbox', $value, $checked, $parameters);
}
////
// Output a form radio field
function tep_draw_radio_field($name, $value = '', $checked = false, $parameters = ' style="background:none;border:0px;"') {
return tep_draw_selection_field($name, 'radio', $value, $checked, $parameters);
}
////
// Output a form textarea field
// The $wrap parameter is no longer used in the core xhtml template
function tep_draw_textarea_field($name, $wrap, $width, $height, $text = '', $parameters = '', $reinsert_value = true) {
global $HTTP_GET_VARS, $HTTP_POST_VARS;
$field = '<textarea name="' . tep_output_string($name) . '" cols="' . tep_output_string($width) . '" rows="' . tep_output_string($height) . '"';
if (tep_not_null($parameters)) $field .= ' ' . $parameters;
$field .= '>';
if ( ($reinsert_value == true) && ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) ) {
if (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) {
$field .= tep_output_string_protected(stripslashes($HTTP_GET_VARS[$name]));
} elseif (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) {
$field .= tep_output_string_protected(stripslashes($HTTP_POST_VARS[$name]));
}
} elseif (tep_not_null($text)) {
$field .= tep_output_string_protected($text);
}
$field .= '</textarea>';
return $field;
}
////
// Output a form hidden field
function tep_draw_hidden_field($name, $value = '', $parameters = '') {
global $HTTP_GET_VARS, $HTTP_POST_VARS;
$field = '<input type="hidden" name="' . tep_output_string($name) . '"';
if (tep_not_null($value)) {
$field .= ' value="' . tep_output_string($value) . '"';
} elseif ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) {
if ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) ) {
$field .= ' value="' . tep_output_string(stripslashes($HTTP_GET_VARS[$name])) . '"';
} elseif ( (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) {
$field .= ' value="' . tep_output_string(stripslashes($HTTP_POST_VARS[$name])) . '"';
}
}
if (tep_not_null($parameters)) $field .= ' ' . $parameters;
$field .= ' />';
return $field;
}
////
// Hide form elements
function tep_hide_session_id() {
global $session_started, $SID;
if (($session_started == true) && tep_not_null($SID)) {
return tep_draw_hidden_field(tep_session_name(), tep_session_id());
}
}
////
// Output a form pull down menu
function tep_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) {
global $HTTP_GET_VARS, $HTTP_POST_VARS;
$field = '<select name="' . tep_output_string($name) . '"';
if (tep_not_null($parameters)) $field .= ' ' . $parameters;
$field .= '>';
if (empty($default) && ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) ) {
if (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) {
$default = stripslashes($HTTP_GET_VARS[$name]);
} elseif (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) {
$default = stripslashes($HTTP_POST_VARS[$name]);
}
}
for ($i=0, $n=sizeof($values); $i<$n; $i++) {
$field .= '<option value="' . tep_output_string($values[$i]['id']) . '"';
if ($default == $values[$i]['id']) {
$field .= ' selected="selected"';
}
$field .= '>' . tep_output_string($values[$i]['text'], array('"' => '"', '\'' => ''', '<' => '<', '>' => '>')) . '</option>';
}
$field .= '</select>';
if ($required == true) $field .= TEXT_FIELD_REQUIRED;
return $field;
}
////
// Creates a pull-down list of countries
function tep_get_country_list($name, $selected = '', $parameters = '') {
$countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));
$countries = tep_get_countries();
for ($i=0, $n=sizeof($countries); $i<$n; $i++) {
$countries_array[] = array('id' => $countries[$i]['countries_id'], 'text' => $countries[$i]['countries_name']);
}
return tep_draw_pull_down_menu($name, $countries_array, $selected, $parameters);
}
////
// Output a jQuery UI Button
function tep_draw_button($title = null, $icon = null, $link = null, $priority = null, $params = null) {
static $button_counter = 1;
$types = array('submit', 'button', 'reset');
if ( !isset($params['type']) ) {
$params['type'] = 'submit';
}
if ( !in_array($params['type'], $types) ) {
$params['type'] = 'submit';
}
if ( ($params['type'] == 'submit') && isset($link) ) {
$params['type'] = 'button';
}
if (!isset($priority)) {
$priority = 'secondary';
}
$button ='';
$button .= '<span class="tdbLink">';
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '<a id="tdb' . $button_counter . '" href="' . $link . '"';
if ( isset($params['newwindow']) ) {
$button .= ' target="_blank"';
}
} else {
$button .= '<button id="tdb' . $button_counter . '" type="' . tep_output_string($params['type']) . '"';
}
if ( isset($params['params']) ) {
$button .= ' ' . $params['params'];
}
$button .= '>'. $title;
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '</a>';
} else {
$button .= '</button>';
}
$button .= '</span><script type="text/javascript">$("#tdb' . $button_counter . '").button(';
$args = array();
if ( isset($icon) ) {
if ( !isset($params['iconpos']) ) {
$params['iconpos'] = 'left';
}
if ( $params['iconpos'] == 'left' ) {
$args[] = 'icons:{primary:"ui-icon-' . $icon . '"}';
} else {
$args[] = 'icons:{secondary:"ui-icon-' . $icon . '"}';
}
}
if (empty($title)) {
$args[] = 'text:false';
}
if (!empty($args)) {
$button .= '{' . implode(',', $args) . '}';
}
$button .= ').addClass("ui-priority-' . $priority . '").parent().removeClass("tdbLink");</script>';
$button_counter++;
return $button;
}
?>
I've never liked the image-stretch "fix" contributions. I've always preferred using a thumbnail generator, due to the varying image sizes within different pages on the catalog side.
Try this contribution, after restoring your files to a version previous to the two add-ons you've installed. Instead of fitting an image to a specific size, a package like this will create resampled and appropriately sized copies of the original image, based on the dimensions required by the tep_image parameters.
Another benefit of a method like this that's often overlooked is that also helps to save on bandwidth and reduce page load times. If you upload a 2800px X 1400px image for a product, that file is most likely going to be a multiple MB image. Each time that image is requested on the catalog side, the full file must be downloaded to the browser before any sizing is done, based on the width and height attributes of the IMG tag. The advantage of using thumbnails is that each thumbnail is resampled for its size. Thus, if your product listing only requires a 200px X 100px image, a 200px X 100px image is crafted from the 2800px X 1400px image you uploaded. Depending on your settings, your images could be in the low-KB range.