используя изображение для кнопки на php - PullRequest
0 голосов
/ 30 марта 2012

У меня есть скрипт php, который создает собственную кнопку, так как я использую фреймворк с открытым исходным кодом. Я хочу использовать изображение для создания кнопки вместо ссылки, которая создается. Вот строка, для которой мне нужна кнопка:

<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>

Это скрипт, который я использую для создания кнопки обзора, но я бы хотел вставить в нее изображение. Любые идеи будут наиболее благодарны.

Это код для функции tep_draw_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 = '<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;
}
?>

Ответы [ 2 ]

1 голос
/ 30 марта 2012

Вы, вероятно, можете переопределить стиль, используя несколько CSS:

#your_button_id{ background: url(); height: x; width: x; etc...  }
.your_button_class{ background: url(); height: x; width: x; etc...  }
0 голосов
/ 30 марта 2012

Попробуйте:

Для вызова кнопки используйте функцию с параметрами, указанными ниже:

$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);

Затем измените функцию tep_draw_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;
}
?>

Дайте мне знать, если это работает, или вам нужно настроить его вообще,Мне сложно тестировать, так как на моей машине нет экземпляра oscommerce для тестирования.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...