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
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 require_once(PATH_tslib."class.tslib_pibase.php");
00066
00067 class tx_ttrating extends tslib_pibase {
00068 var $enableFields ="";
00069
00070 var $config=array();
00071 var $conf=array();
00072
00073 var $rateTable = "";
00074 var $rateTableUid = "";
00075 var $rateTableTitle = "";
00076
00080 function main_rating($content,$conf) {
00081
00082
00083
00084 $this->conf=$conf;
00085
00086 $this->enableFields = $this->cObj->enableFields("tt_rating");
00087
00088 if ($this->conf["pid_list"] OR $this->conf["pid_list."]) {
00089 $this->config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this->conf["pid_list."]));
00090 $this->config["pid_list"] = $this->config["pid_list"] ? implode(t3lib_div::intExplode(",",$this->config["pid_list"]),",") : $GLOBALS["TSFE"]->page[uid];
00091 list($pid) = explode(",",$this->config["pid_list"]);
00092 }
00093
00094
00095 $this->config["code"] = $this->cObj->stdWrap($this->conf["code"],$this->conf["code."]);
00096 if (!$this->config["code"]) { $this->config["code"]=$this->conf["defaultCode"]; }
00097 if (!$this->config["code"]) { $this->config["code"]="SHOWHELP"; }
00098
00099 $this->config["maxRating"] = max ($this->conf["highestRating"],$this->conf["lowestRating"]);
00100 $this->config["minRating"] = min ($this->conf["highestRating"],$this->conf["lowestRating"]);
00101 $this->config["defaultTitle"] = $this->cObj->stdWrap($this->conf["defaultTitle"],$this->conf["defaultTitle."]);
00102 $this->config["defaultDescription"] = $this->cObj->stdWrap($this->conf["defaultDescription"],$this->conf["defaultDescription."]);
00103
00104
00105
00106
00107 $items=array();
00108 if (isset($pid) AND $this->cObj->data[CType]=="list") {
00109 $items = $this->getItemList($pid);
00110 if (!count($items) AND $this->conf["allowNew"]) {
00111 $items[] = $this->createNewItem($pid);
00112 }
00113 } elseif (isset($this->cObj->data[rating])) {
00114 $items[] = $this->cObj->data;
00115 } elseif ( $this->conf["rateTable"] ) {
00116 $this->rateTable = $this->conf["rateTable"];
00117 $this->rateTableUid = intval($this->cObj->stdWrap($this->conf["rateTableUid"],$this->conf["rateTableUid."]));
00118 if (!$this->rateTableUid) {
00119 list (,$this->rateTableUid) = explode(":",$this->cObj->currentRecord);
00120 }
00121 $item = $this->getItempollLink($this->pollTable."_".$this->pollTableUid, $this->pollTablePid);
00122 $this->rateTableTitle = $this->cObj->data["title"] ? $this->cObj->data["title"] : "";
00123 $pid = intval($this->cObj->stdWrap($this->conf["rateTablePid"],$this->conf["rateTablePid."]));
00124 $pid = $pid ? $pid : $GLOBALS["TSFE"]->id;
00125 $item = $this->getItempollLink($this->pollTable."_".$this->pollTableUid, $pid);
00126 if (is_array($item)) {
00127 $items[] = $item;
00128 } elseif ($this->conf["allowNew"]) {
00129
00130
00131 }
00132 } else {
00133
00134
00135 }
00136
00137
00138
00139
00140
00141
00142 $codes=t3lib_div::trimExplode(",", strtoupper($this->config["code"]),1);
00143
00144 $content="";
00145 reset($items);
00146 while(list(,$item)=each($items)) {
00147
00148
00149 $cookieName = "t3_tt_rating_rated_".$item["uid"];
00150 $doubleRating = (isset($GLOBALS["HTTP_COOKIE_VARS"][$cookieName]) AND isset($GLOBALS["register"]["tt_rating"][$item["uid"]]["triedRating"]));
00151 $doubleRating = $GLOBALS["TSFE"]->beUserLogin ? FALSE : $doubleRating;
00152
00153
00154
00155
00156
00157 reset($codes);
00158 while(list(,$theCode)=each($codes)) {
00159 $theCode = (string)trim($theCode);
00160 switch($theCode) {
00161 case "VOTEFORM":
00162 $lConf = $this->conf["voteform."];
00163
00164 if (is_array($lConf["dataArray."])) {
00165 reset($lConf["dataArray."]);
00166 while(list($key,$formEntry)=each($lConf["dataArray."])) {
00167 $lConf["dataArray."][$key]["type"] = str_replace ( "[EDIT]", '['.$item["uid"].']', $formEntry["type"]);
00168 }
00169
00170 $lConf["dataArray."]["9990."] = array(
00171 "type" => "data[tt_rating][".$item["uid"]."][maxRating]=hidden",
00172 "value" => $this->config["maxRating"]
00173 );
00174 $lConf["dataArray."]["9991."] = array(
00175 "type" => "data[tt_rating][".$item["uid"]."][minRating]=hidden",
00176 "value" => $this->config["minRating"]
00177 );
00178 $lConf["dataArray."]["9992."] = array(
00179 "type" => "data[tt_rating][".$item["uid"]."][ratingStatSteps]=hidden",
00180 "value" => $this->conf["ratingStatSteps"]
00181 );
00182 $lConf["dataArray."]["9993."] = array(
00183 "type" => "clearCachePid=hidden",
00184 "value" => $GLOBALS["TSFE"]->id
00185 );
00186 } else {
00187 $lConf["data"] = str_replace ( "[EDIT]", '['.$item["uid"].']', $lConf["data"]);
00188 $lConf["data"] .= " || | data[tt_rating][".$item["uid"]."][maxRating]=hidden | ".$this->config["maxRating"];
00189 $lConf["data"] .= " || | data[tt_rating][".$item["uid"]."][minRating]=hidden | ".$this->config["minRating"];
00190 $lConf["data"] .= " || | data[tt_rating][".$item["uid"]."][ratingStatSteps]=hidden | ".$this->conf["ratingStatSteps"];
00191 $lConf["data"] .= " || | clearCachePid=hidden | ".$GLOBALS["TSFE"]->id;
00192 }
00193
00194 $content .= $this->cObj->FORM($lConf);
00195
00196 break;
00197 case "RESULT":
00198 if ($item["votes"] == 0) {
00199 if (isset ($this->conf["noRatingObj."])) {
00200 $lConf = $this->conf["noRatingObj."];
00201 $content .= $this->cObj->cObjGetSingle ($this->conf["noRatingObj"], $lConf);
00202 }
00203 } else {
00204 if (isset ($this->conf["renderObj."])) {
00205 $lConf = $this->conf["renderObj."];
00206 $markContentArray = array();
00207 $markContentArray["###VOTES###"] = $item["votes"];
00208 $markContentArray["###RATING###"] = $item["rating"];
00209 $markContentArray["###HIGHEST_RATING###"] = $this->conf["highestRating"];
00210 $markContentArray["###LOWEST_RATING###"] = $this->conf["lowestRating"];
00211 $markContentArray["###RATING_OUTPUT_STEPS###"] = $this->conf["ratingOutputSteps"];
00212 $markContentArray["###RATING_MUL###"] = (string)((int)($item["rating"] * 100.0 / (double)$this->conf["highestRating"]))."/100";
00213 $markContentArray["###RATING_FULL_WIDTH###"] = $this->conf["ratingOutputWidth"];
00214 $markContentArray["###RATING_WIDTH###"] = (int)((double)$this->conf["ratingOutputWidth"]*($item["rating"] / (double)$this->conf["highestRating"]));
00215 $markContentArray["###RATING_REMAIN_WIDTH###"] = (int)$markContentArray["###RATING_FULL_WIDTH###"] - (int)$markContentArray["###RATING_WIDTH###"];
00216
00217
00218 if($doubleRating) {
00219
00220 $markContentArray["###RATING_MSG###"] = $this->conf["doubleRatingMsg"];
00221 $GLOBALS["TSFE"]->set_no_cache();
00222 } elseif ($GLOBALS["register"]["tt_rating"][$item["uid"]]["submittedRating"]) {
00223
00224 $GLOBALS["TSFE"]->set_no_cache();
00225 $markContentArray["###RATING_MSG###"] = $this->conf["submittedRatingMsg"];
00226 $markContentArray["###RATING_MSG###"] = str_replace("###SUBMITTED_RATING###", $GLOBALS["register"]["tt_rating"][$item["uid"]]["submittedRating"], $markContentArray["###RATING_MSG###"]);
00227 } else {
00228 $markContentArray["###RATING_MSG###"] = "";
00229 }
00230
00231 $this->cObj->substituteMarkerInObject ($lConf, $markContentArray);
00232 $content .= $this->cObj->cObjGetSingle ($this->conf["renderObj"], $lConf);
00233 }
00234 }
00235 break;
00236 default:
00237 $langKey = strtoupper($GLOBALS["TSFE"]->config["config"]["language"]);
00238 $helpTemplate = $this->cObj->fileResource("EXT:tt_rating/pi/rating_help.tmpl");
00239
00240
00241 $helpTemplate_lang="";
00242 if ($langKey) {$helpTemplate_lang = $this->cObj->getSubpart($helpTemplate,"###TEMPLATE_".$langKey."###");}
00243 $helpTemplate = $helpTemplate_lang ? $helpTemplate_lang : $this->cObj->getSubpart($helpTemplate,"###TEMPLATE_DEFAULT###");
00244
00245
00246 $markerArray["###CODE###"] = $theCode;
00247 $markerArray["###DEFAULTCODE###"] = $this->conf["defaultCode"];
00248 $content.=$this->cObj->substituteMarkerArray($helpTemplate,$markerArray);
00249 break;
00250 }
00251 }
00252 }
00253 return $this->cObj->wrap($content, $this->conf["wrap"]);
00254 }
00255
00256
00257
00258
00259 function getItemList($pid) {
00260 if (is_array($pid)) {
00261 $pid = implode(',',$pid);
00262 }
00263 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_rating', 'pid IN ('.$pid.')'.$this->enableFields, '', 'crdate DESC');
00264 $out = array();
00265 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00266 $out[] = $row;
00267 }
00268 return $out;
00269 }
00270
00271
00272 function getItemRatingLink($recordlink, $pid) {
00273 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_rating', 'recordlink="'.$GLOBALS['TYPO3_DB']->quoteStr($recordlink, 'tt_rating').'" AND pid='.intval($pid).$this->enableFields);
00274 return $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00275 }
00276
00277
00278
00279 function getItem($uid) {
00280 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_rating', 'uid='.intval($uid).$this->enableFields);
00281 return $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00282 }
00283
00284
00285 function createNewItem($pid=0) {
00286 $pid = $pid ? $pid : $GLOBALS["TSFE"]->id;
00287 $recordLink = "";
00288 if ($this->rateTable AND $this->rateTableUid) {
00289 $recordLink = $this->rateTable .":". $this->rateTableUid;
00290 }
00291 if (!$this->config["defaultTitle"] AND $this->rateTable AND $this->rateTableUid) {
00292 if (!$this->rateTableTitle) {
00293 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->rateTable, 'uid='.intval($this->rateTableUid));
00294 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00295 $this->rateTableTitle = $row['title'] ? $row['title'] : $recordLink;
00296 }
00297 $title = "rating: ".$this->rateTableTitle;
00298 } else {
00299 $title = $this->config["defaultTitle"] ? $this->config["defaultTitle"] : "rating: ".$GLOBALS["TSFE"]->page["title"];
00300 }
00301
00302 $insertFields = array(
00303 'pid' => $pid,
00304 'recordlink' => $recordLink,
00305 'title' => $title,
00306 'description' => $this->config['defaultDescription'],
00307 'rating' => '0',
00308 'votes' => '0',
00309 'tstamp' => time(),
00310 'crdate' => time()
00311 );
00312
00313 $GLOBALS['TYPO3_DB']->exec_INSERTquery('tt_rating', $insertFields);
00314
00315 return $this->getItem($GLOBALS['TYPO3_DB']->sql_insert_id());
00316 }
00317
00318
00319 }
00320
00321
00322
00323 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tt_rating/pi/class.tx_ttrating.php"]) {
00324 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tt_rating/pi/class.tx_ttrating.php"]);
00325 }
00326
00327 ?>