Go to the documentation of this file.00001 <?php
00002
00006 class oxTsRatings extends oxSuperCfg
00007 {
00008
00012 const CACHE_TTL = 43200;
00013
00017 const TS_RATINGS = 'TS_RATINGS';
00018
00025 protected $_aChannel = array();
00026
00032 protected $_sTsId = null;
00033
00039 public function getTsId()
00040 {
00041 return $this->_sTsId;
00042 }
00043
00049 public function setTsId($sId)
00050 {
00051 $this->_sTsId = $sId;
00052 }
00053
00061 protected function _executeCurl($sUrl)
00062 {
00063 $oCurl = oxNew('oxCurl');
00064 $oCurl->setMethod("GET");
00065 $oCurl->setUrl($sUrl);
00066 $oCurl->setOption('CURLOPT_HEADER', false);
00067 $oCurl->setOption('CURLOPT_POST', false);
00068 $sOutput = $oCurl->execute();
00069
00070 return $sOutput;
00071 }
00072
00079 public function getRatings()
00080 {
00081 if (($this->_aChannel = oxRegistry::getUtils()->fromFileCache(self::TS_RATINGS))) {
00082 return $this->_aChannel;
00083 }
00084 $sTsId = $this->getTsId();
00085
00086 $sUrl = "https://www.trustedshops.com/bewertung/show_xml.php?tsid=" . $sTsId;
00087 $sOutput = $this->_executeCurl($sUrl);
00088
00089 $this->_aChannel['empty'] = true;
00090
00091 try {
00092 $oDomFile = oxNew("oxSimpleXml");
00093 if ($oXml = $oDomFile->xmlToObject($sOutput)) {
00094 $aResult = $oXml->ratings->xpath('//result[@name="average"]');
00095
00096 $this->_aChannel['empty'] = false;
00097 $this->_aChannel['result'] = (float) $aResult[0];
00098 $this->_aChannel['max'] = "5.00";
00099 $this->_aChannel['count'] = (int) $oXml->ratings["amount"];
00100 $this->_aChannel['shopName'] = (string) $oXml->name;
00101 oxRegistry::getUtils()->toFileCache(self::TS_RATINGS, $this->_aChannel, self::CACHE_TTL);
00102 }
00103 } catch (Exception $oEx) {
00104 $oEx = oxNew("oxException");
00105 $oEx->setMessage($oEx->getMessage());
00106 $oEx->debugOut();
00107 }
00108
00109 return $this->_aChannel;
00110 }
00111 }