00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Page_Block_Html_Toplinks extends Mage_Core_Block_Template
00035 {
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 protected $_toplinks = array();
00054
00055 function __construct()
00056 {
00057 parent::__construct();
00058 $this->setTemplate('page/html/top.links.phtml');
00059 }
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 public function addLink($liParams, $aParams, $innerText, $position='', $beforeText='', $afterText='')
00073 {
00074 $params = '';
00075 if (!empty($liParams) && is_array($liParams)) {
00076 foreach ($liParams as $key=>$value) {
00077 $params .= ' ' . $key . '="' . addslashes($value) . '"';
00078 }
00079 } elseif (is_string($liParams)) {
00080 $params .= ' ' . $liParams;
00081 }
00082 $toplinkInfo['liParams'] = $params;
00083 $params = '';
00084 if (!empty($aParams) && is_array($aParams)) {
00085 foreach ($aParams as $key=>$value) {
00086 $params .= ' ' . $key . '="' . addslashes($value) . '"';
00087 }
00088 } elseif (is_string($aParams)) {
00089 $params .= ' ' . $aParams;
00090 }
00091 $toplinkInfo['aParams'] = $params;
00092 $toplinkInfo['innerText'] = $innerText;
00093 $toplinkInfo['beforeText'] = $beforeText;
00094 $toplinkInfo['afterText'] = $afterText;
00095 $this->_prepareArray($toplinkInfo, array('liParams', 'aParams', 'innerText', 'beforeText', 'afterText', 'first', 'last'));
00096 if (is_numeric($position)) {
00097 array_splice($this->_toplinks, $position, 0, array($toplinkInfo));
00098 } else {
00099 $this->_toplinks[] = $toplinkInfo;
00100 }
00101 return $this;
00102 }
00103
00104 protected function _toHtml()
00105 {
00106 if (is_array($this->_toplinks) && $this->_toplinks) {
00107 reset($this->_toplinks);
00108 $this->_toplinks[key($this->_toplinks)]['first'] = true;
00109 end($this->_toplinks);
00110 $this->_toplinks[key($this->_toplinks)]['last'] = true;
00111 }
00112 $this->assign('toplinks', $this->_toplinks);
00113 return parent::_toHtml();
00114 }
00115 }