Example #1
0
 public function auth($username, $passowrd)
 {
     $RDb = DBService::getDB();
     $res = $RDb->fetchAll("SELECT *, auth.uid as uid FROM " . TABLE_AUTHORS . " as auth\n\t\t\t\tLEFT JOIN fanfiction_authorprefs AS ap ON ap.uid = auth.uid\n\t\t\t\tWHERE penname = '%s'", $username);
     if (count($res) == 0) {
         return false;
     } else {
         $encryptedpassword = md5($passowrd);
         $row = $res[0];
         if ($row->password != $encryptedpassword) {
             return false;
         } else {
             $name = empty($row->realname) ? $row->penname : $row->realname;
             $this->set('name', $name);
             $this->set('penname', $row->penname);
             $this->uname = $row->penname;
             $this->uid = $row->uid;
             $this->setValid();
             if (isset($_POST['cookiecheck'])) {
                 setcookie(Maple::$SITE_KEY . "_useruid", $row->uid, time() + 60 * 60 * 24 * 30, "/");
                 setcookie(Maple::$SITE_KEY . "_salt", md5($row->email + $encryptedpassword), time() + 60 * 60 * 24 * 30, "/");
             }
             if (!isset($_SESSION)) {
                 session_start();
             }
             $_SESSION[Maple::$SITE_KEY . "_useruid"] = $row->uid;
             $_SESSION[Maple::$SITE_KEY . "_salt"] = md5($row->email + $encryptedpassword);
         }
         return true;
     }
 }
Example #2
0
 /**
  * @RequestMapping(url="json/storieslist",type=json, cache=true)
  * @RequestParams(true)
  */
 public function searchStories($search = "", $order_by = "updated", $search_by = "title", $categories = array(), $language = "", $type = "", $page = 0)
 {
     $search = trim(preg_replace('/ +/', ' ', $search));
     $offset = $page * 50;
     $stories = new Stories();
     $stories->RELEVANCE = empty($search) ? 0 : 0.1;
     $stories->setCategories($categories);
     $stories->setClasses($type, $language);
     if ($search_by == 'title') {
         $stories_results = $stories->searchByTitle($search, $offset, $order_by);
     } else {
         if ($search_by == 'text') {
             $stories_results = $stories->searchByText($search, $offset, $order_by);
         } else {
             $stories_results = $stories->searchByAll($search, $offset, $order_by);
         }
     }
     if (count($stories_results)) {
         // echo "REPLACE INTO search_cache(search_text) values(".$search.")";
         $RDb = DBService::getDB();
         $res = $RDb->update("REPLACE INTO search_cache(search_text) values('" . $search . "')");
     }
     // print_r($stories->get(0));
     return $stories_results;
 }
Example #3
0
 public static function getList($sid)
 {
     $RDb = DBService::getDB();
     $qury = "SELECT chap.*, penname, chapt.chaptags as chap_tags\n\t\t\t\tFROM (fanfiction_chapters as chap, " . TABLE_AUTHORS . " as auth,fanfiction_chaptags as chapt )\n\t\t\t\tWHERE sid = '{$sid}' AND chap.chapid=chapt.chapid AND chap.uid = auth.uid \n\t\t\t\tAND chap.validated > 0 ORDER BY inorder";
     //echo $qury;
     return $RDb->fetchAll($qury);
 }
Example #4
0
 public static function addComment($sid, $chapid, $uid, $reviewer, $review, $rating)
 {
     $RDb = DBService::getDB();
     $review = TextUtils::format_story(strip_tags(TextUtils::descript($_POST['review']), Maple::$ALLOWED_TAGS));
     $RDb->update("INSERT INTO fanfiction_reviews (item, type, reviewer, review, rating, date, uid, chapid)\n\t\t\t\tVALUES ('{$sid}', 'ST', '{$reviewer}', '{$review}', '{$rating}', now(), '" . $uid . "', '{$chapid}')");
     $records = $RDb->fetchAll("SELECT chapid,count(*) as reviews, sum(rating) as ratings FROM fanfiction_reviews\n\t\t\t\tWHERE item=%d AND type='ST' GROUP BY  chapid", $sid);
     $totalReviews = 0;
     $totalRatings = 0;
     $totalRating = 0;
     $chapterReviews = 0;
     $chapterRatings = 0;
     $chapterRating = 0;
     if ($records != null && count($records)) {
         foreach ($records as $key => $record) {
             $totalReviews = +$record->reviews;
             $totalRatings = +$record->ratings;
             if ($record->chapid == $chapid) {
                 $chapterReviews = $record->reviews;
                 $chapterRatings = $record->ratings;
             }
         }
         if ($chapterReviews > 0) {
             $chapterRating = $chapterRatings / $chapterReviews;
             $RDb->update("UPDATE fanfiction_chapters SET reviews = %d, rating = %d\n\t\t\t\t        WHERE chapid=%d", $chapterReviews, $chapterRating, $chapid);
         }
         if ($totalReviews > 0) {
             $totalRating = $totalRatings / $totalReviews;
             $RDb->update("UPDATE fanfiction_stories SET reviews = %d, rating = %d\n\t\t\t\t        WHERE chapid=%d", $totalReviews, $totalRating, $sid);
         }
     }
     return array("sid" => $sid, "rating" => $totalRating, "reviews" => $totalReviews, "chapter" => array("sid" => $chapid, "rating" => $chapterRating, "reviews" => $chapterReviews));
 }
Example #5
0
 public static function getUsers($minStoryCount = 0, $offSet = 0, $limit = 20, $orderBy = "penname", $search = "")
 {
     $RDb = DBService::getDB();
     // 		printf("SELECT * FROM fanfiction_authors AS u,fanfiction_authorstats AS stats
     // 				WHERE u.uid=stats.uid AND u.stories>%d LIMIT %d, 20",$minStoryCount,$offSet);
     $users = $RDb->fetchAll("SELECT *, trim(penname) as penname FROM fanfiction_authors AS u,fanfiction_authorstats AS stats\n\t\t\t\tWHERE u.uid=stats.uid AND stats.stories>=%d AND penname like %s\n\t\t\t\tORDER BY %s LIMIT %d,%d", $minStoryCount, "'%" . $search . "%'", $orderBy, $offSet, $limit);
     return $users;
 }
Example #6
0
 public function updateCategories()
 {
     $RDb = DBService::getDB();
     $this->info = array();
     $cats = $RDb->fetchAll("SELECT * FROM fanfiction_categories WHERE parentcatid = '-1' ORDER BY displayorder");
     foreach ($cats as $cat) {
         $this->info[$cat->catid] = new Category($cat);
     }
 }
Example #7
0
 public function updateStats()
 {
     $RDb = DBService::getDB();
     $mems = $RDb->fetchAll("SELECT COUNT(uid) as members FROM " . TABLE_AUTHORS);
     $this->info['members'] = $mems[0]->members;
     $stats = $RDb->fetchAll("SELECT * FROM fanfiction_stats LIMIT 1");
     $this->info["stories"] = $stats[0]->stories;
     $this->info["authors"] = $stats[0]->authors;
     $this->info["members"] = $stats[0]->members;
     $this->info["reviews"] = $stats[0]->reviews;
     $this->info["reviewers"] = $stats[0]->reviewers;
     $this->info["wordcount"] = $stats[0]->wordcount;
     $this->info["chapters"] = $stats[0]->chapters;
     $this->info["series"] = $stats[0]->series;
 }
Example #8
0
 public function fetch()
 {
     $RDb = DBService::getDB();
     $stories = $RDb->fetchAll("SELECT penname, auth.uid as uid, story.*, UNIX_TIMESTAMP(story.date) as date,\n\t\t\t\tUNIX_TIMESTAMP(story.updated) as updated, story.validated as valid\n\t\t\t\tFROM " . TABLE_STORIES . " as story, " . TABLE_AUTHORS . " as auth\n\t\t\t\tWHERE story.sid = '" . $this->id . "' AND story.uid = auth.uid");
     $this->info = $stories[0];
     //var_dump($this->info);
     if (isset($this->info)) {
         $stats = $RDb->fetchAll("SELECT * FROM stats_stories\n\t\t\t\t\tWHERE  sid = '" . $this->id . "'");
         $this->stats = $stats[0];
         if ($this->info->coauthors) {
             $this->coauthors = CoAuthors::resolveCoauthors($this->id);
         }
         $this->chapters = Chapter::getList($this->id);
     }
 }
Example #9
0
 /**
  *
  * @RequestMapping(url="json/websiteinfo",type=json, cache=true)
  * @RequestParams(true)
  */
 public function websiteinfo($info = "NO")
 {
     if ($info == "STATS") {
         return new \app\model\WebSite();
     } else {
         if ($info == "CATEGORIES") {
             return new \app\model\Categories();
         } else {
             if ($info == "CLASSES") {
                 $RDb = DBService::getDB();
                 return $RDb->fetchAll("SELECT class_id id, class_name name, classtype_id, classtype_name,classtype_title\n                        FROM `fanfiction_classes` as c,fanfiction_classtypes as ct \n                        WHERE ct.classtype_id=c.class_type");
             }
         }
     }
     return array();
 }
Example #10
0
 public static function getByChapter($sid, $chapid)
 {
     $RDb = DBService::getDB();
     $users = $RDb->fetchAll("SELECT *, trim(charname) as charname\n\t\t\t\tFROM  charactor_chapter AS cc, charactor_user AS cu\n\t\t\t\tWHERE cc.charid=cu.charid AND sid = %d AND chapid = %d\n\t\t\t\tORDER BY charname", $sid, $chapid);
     return $users;
 }
Example #11
0
 public static function resolveCoauthors($sid)
 {
     $RDb = DBService::getDB();
     return $RDb->fetchAll("SELECT penname as penname, co.uid AS uid\n\t\t\t\t\tFROM " . TABLE_COAUTHORS . " AS co\n\t\t\t\t\tLEFT JOIN " . TABLE_AUTHORS . " AS au ON co.uid = au.uid\n\t\t\t\t\tWHERE co.sid = %s", $sid);
 }