|
@@ -0,0 +1,48 @@
|
|
|
|
+<?php
|
|
|
|
+//This is a function that returns the ads for this particular user by analysising his post keywords
|
|
|
|
+$keywords = '{
|
|
|
|
+ "car":["cars","car","drive","car dealer","car park","motorcycle","driving"],
|
|
|
|
+ "food":["restaurants","food","food court","sushi","rice","noodles","dim sum","cookies","icecream"],
|
|
|
|
+ "travel":["plane","travel","holiday","rest","tired","air ticket","trip","camping"],
|
|
|
|
+ "clothes":["clothes","dress","shorts","T-shirt","skirt"]
|
|
|
|
+}';
|
|
|
|
+$adsLinks = '{
|
|
|
|
+ "car":"ads/car.png",
|
|
|
|
+ "clothes":"ads/clothes.png",
|
|
|
|
+ "food":"ads/food.png",
|
|
|
|
+ "travel":"travel.png"
|
|
|
|
+}';
|
|
|
|
+$keywords = json_decode($keywords,true);
|
|
|
|
+$adsLinks = json_decode($adsLinks,true);
|
|
|
|
+include_once("requestDB.php"); //Get the sql loader from requestDB
|
|
|
|
+
|
|
|
|
+function initAds(){
|
|
|
|
+ global $keywords,$adsLinks;
|
|
|
|
+ $relatedPost = [];
|
|
|
|
+ $keys = [];
|
|
|
|
+ foreach ($keywords as $key => $value){
|
|
|
|
+ $thiskey = $key;
|
|
|
|
+ $thisKeywordList = $value;
|
|
|
|
+ $thisProb = 0;
|
|
|
|
+ foreach($thisKeywordList as $keyword){
|
|
|
|
+ $count = keywordCount($keyword);
|
|
|
|
+ $count = (int)$count[0]["pnum"];
|
|
|
|
+ $thisProb += $count;
|
|
|
|
+ }
|
|
|
|
+ array_push($keys,$thiskey);
|
|
|
|
+ array_push($relatedPost,$thisProb);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Get the highest prob which the user love this catergory.
|
|
|
|
+ $maxs = array_keys($relatedPost, max($relatedPost));
|
|
|
|
+ //The type of ads that we are going to show is:
|
|
|
|
+ //echo $keys[$maxs[0]];
|
|
|
|
+ return $adsLinks[$keys[$maxs[0]]];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function keywordCount($keyword){
|
|
|
|
+ $username = $_SESSION['login'];
|
|
|
|
+ $postData = query("select COUNT(*) as pnum from post WHERE username='" . $username ."' AND content LIKE '%$keyword%'","teabag");
|
|
|
|
+ return($postData);
|
|
|
|
+}
|
|
|
|
+?>
|