Esempio n. 1
0
 public static function city($ip)
 {
     $url = "http://ip.taobao.com/service/getIpInfo.php?ip={$ip}";
     $data = ToolModel::getUrl($url);
     $object = json_decode($data);
     return $object->data->city;
 }
Esempio n. 2
0
 public function ad728Action()
 {
     //728*90
     $this->_layout = "empty";
     $jobsModel = new JobsModel();
     $city = LocationModel::city(ToolModel::getRealIpAddr());
     if ($city) {
         if (mb_substr($city, -1) == "市") {
             $city = mb_substr($city, 0, -1);
         }
         $jobs = $jobsModel->newJobsFromCity($city);
         if (!$jobs) {
             $jobs = $jobsModel->newJobs();
         } else {
             if (count($jobs) == 1) {
                 $addJobs = $jobsModel->newJobs();
                 shuffle($addJobs);
                 $jobs = array_merge($jobs, $addJobs);
                 $jobs = array_slice($jobs, 0, 2);
             }
         }
     } else {
         $jobs = $jobsModel->newJobs();
     }
     shuffle($jobs);
     $this->_mainContent->assign("job1", $jobs[0]);
     $this->_mainContent->assign("job2", $jobs[1]);
     $this->display();
 }
Esempio n. 3
0
 public function feedbackAction()
 {
     $data = $_POST["feedback"];
     $data = ToolModel::getRealIpAddr() . "/" . $data . "/" . time();
     $feedback = explode("/", $data);
     $db = new PlaygroundModel();
     $sql = "INSERT INTO `playground_feedback` (`ip`,`uuid`,`foursquare`,`instagram`,`feedback`,`createtime`) VALUES('{$feedback['0']}','{$feedback['1']}','{$feedback['2']}','{$feedback['3']}','{$feedback['4']}','{$feedback['5']}');";
     $db->run($sql);
     echo "done";
 }
Esempio n. 4
0
 public function sitesearch($keyword)
 {
     $data = array();
     $data["keyword"] = $keyword;
     $data["ip"] = ToolModel::getRealIpAddr();
     $userModel = new UserModel();
     $data["userid"] = $userModel->checklogin();
     $data["time"] = time();
     $this->select("sitesearch")->insert($data);
 }
Esempio n. 5
0
 function update()
 {
     $source["from"] = "拉勾网";
     $source["url"] = "http://www.lagou.com/joinNov/ex_list_ios";
     $sources[] = $source;
     foreach ($sources as $source) {
         $content = ToolModel::getUrl($source["url"]);
         $data = json_decode($content, true);
         foreach ($data["result"] as $job) {
             $job = $this->lagou2job($job);
             $this->select("jobs")->insert($job);
         }
     }
 }
Esempio n. 6
0
    public function search($q, $begin = 0, $size = 20)
    {
        $url = "http://" . SEARCHSERVER . ":9200/_search/?size={$size}&from={$begin}";
        $json = '{
  "query": {
    "multi_match": {
      "query": "' . $q . '",
      "fields": ["title","content","replysText","tags"]
    }
  },
      "highlight" : {
        "fields" : {
            "content" : {"type" : "plain"},
            "replysText" : {"type" : "plain"}
        }
    }

}';
        return ToolModel::postJSON($url, $json);
    }
Esempio n. 7
0
 public function nameAction()
 {
     $tag = urldecode($this->strVal(3));
     $page = $this->intVal(4);
     if ($page == 0) {
         $page = 1;
     }
     $threadModel = new ThreadModel();
     $threadCount = $threadModel->threadsCountByTag($tag);
     $threadPageSize = 40;
     $threads = $threadModel->threadsByTag($tag, $page, $threadPageSize);
     $pageControl = ToolModel::pageControl($page, $threadCount, $threadPageSize, "<a href='/tag/name/{$tag}/#page#/'>", 0);
     $object["threads"] = $threads;
     $object["pageControl"] = $pageControl;
     $content = $this->doTemplate("Module", "thread", $object);
     $this->_mainContent->assign("content", $content);
     $relatedTags = $threadModel->relatedTags($tag);
     $this->_mainContent->assign("relatedTags", $relatedTags);
     $this->_mainContent->assign("tag", $tag);
     $this->display();
 }
Esempio n. 8
0
 public function qAction()
 {
     $q = urldecode($this->strVal(3));
     $page = $this->intVal(4);
     if ($page == 0) {
         $page = 1;
     }
     $size = 10;
     $begin = ($page - 1) * $size;
     $searchModel = new SearchModel();
     $ret = $searchModel->search($q, $begin, $size);
     $retArray = json_decode($ret, true);
     $count = $retArray["hits"]["total"];
     $pageControl = ToolModel::pageControl($page, $count, $size, "<a href='/search/q/{$q}/#page#/'>");
     $this->_mainContent->assign("pageControl", $pageControl);
     $this->_mainContent->assign("results", $retArray);
     $this->_mainContent->assign("search", $retArray);
     $this->_view->assign("search_q", $q);
     $this->_mainContent->assign("search_q", $q);
     $this->display();
     //var_dump($retArray);
 }
Esempio n. 9
0
 private function saveAvatar()
 {
     $discuzPath = dirname(dirname(dirname(dirname(__FILE__))));
     $uploaderModel = new UploaderModel();
     $filename = $discuzPath . $_POST["fileurl"];
     $image = ToolModel::createImageFromFile($filename);
     unlink($filename);
     $imagex = imagesx($image);
     $imagey = imagesy($image);
     $cx = $_POST["cx"] * $imagex / $_POST["iw"];
     $cy = $_POST["cy"] * $imagey / $_POST["ih"];
     $cw = $_POST["cw"] * $imagex / $_POST["iw"];
     $ch = $_POST["ch"] * $imagey / $_POST["ih"];
     $image1 = $uploaderModel->crop($image, $cx, $cy, $cw, $ch, 180, 180);
     $image2 = $uploaderModel->crop($image, $cx, $cy, $cw, $ch, 80, 80);
     $image3 = $uploaderModel->crop($image, $cx, $cy, $cw, $ch, 48, 48);
     $userModel = new UserModel();
     $userid = $userModel->checklogin();
     $avpath = DiscuzModel::get_avatar_path($userid, "big");
     $path = dirname($avpath);
     ToolModel::makeDeepDir($path);
     imagejpeg($image1, $avpath, 85);
     $avpath = DiscuzModel::get_avatar_path($userid, "middle");
     imagejpeg($image2, $avpath, 85);
     $avpath = DiscuzModel::get_avatar_path($userid, "small");
     imagejpeg($image3, $avpath, 85);
 }
Esempio n. 10
0
 public function update($data)
 {
     $table = $this->_table;
     $where = $this->_where;
     if ($table == '') {
         return;
     }
     foreach ($data as $k => $v) {
         $nv = mysql_real_escape_string($v);
         $line[] = "`{$k}`='{$nv}'";
     }
     $lines = join(',', $line);
     $sql = "UPDATE {$table} SET {$lines} WHERE {$where}";
     $result = mysql_query($sql);
     if (!$result) {
         ToolModel::error_log("ERROR_IN_SQL_UPDATE {$sql}\r\n");
     }
 }
Esempio n. 11
0
 public function threadsByTag($tag, $page, $pageSize)
 {
     $start = ($page - 1) * $pageSize;
     $countSql = "SELECT count(*) FROM `threads`\n      LEFT JOIN `threadtags` ON `threads`.`id` = `threadtags`.`tid` \n      WHERE `del` = 0 AND `tagname`='{$tag}'";
     $sql = "SELECT * FROM `threads`\n      LEFT JOIN `threadtags` ON `threads`.`id` = `threadtags`.`tid` \n      WHERE `del` = 0 AND `tagname`='{$tag}'\n      ORDER BY `id` DESC  \n      limit {$start},{$pageSize};";
     $result = $this->fetchArray($sql);
     $ret = array();
     if (count($result) == 0) {
         return $ret;
     }
     foreach ($result as $item) {
         $item["createtime"] = ToolModel::countTime($item["createdate"]);
         $item["updatetime"] = ToolModel::countTime($item["updatedate"]);
         $item["image"] = DiscuzModel::get_avatar($item["createbyid"], "small");
         $item["title"] = stripslashes($item["title"]);
         $item["tagArray"] = explode(",", $item["tags"]);
         $ret[] = $item;
     }
     return $ret;
 }
Esempio n. 12
0
 public static function youkuInsert($html)
 {
     if (ToolModel::is_iPhone()) {
         $width = "200";
         $height = "200";
     } else {
         $width = "510";
         $height = "498";
     }
     $html = preg_replace("/<a href=\"http:\\/\\/v.youku.com\\/v_show\\/id_(.*)?.html\">(.*)?<\\/a>/", "\\0<div style=\"text-align:center;\"><iframe width=\"{$width}\" height=\"{$height}\" src=\"http://player.youku.com/embed/\\1\" frameborder=0 allowfullscreen></iframe></div>", $html);
     return $html;
 }
Esempio n. 13
0
 public function money_records($userid)
 {
     $records = $this->select("money")->where("userid = {$userid}")->orderby("`updatetime` DESC")->fetchAll();
     if (!$records) {
         return array();
     }
     $newRecords = array();
     foreach ($records as $money) {
         $money["time"] = ToolModel::countTime($money["updatetime"]);
         $newRecords[] = $money;
     }
     return $newRecords;
 }
Esempio n. 14
0
 public function feedbackAction()
 {
     $db = new PlaygroundModel();
     $sql = "SELECT * FROM `playground_feedback` order by `id` DESC;";
     $ret = $db->fetchArray($sql);
     $feedbacks = array();
     foreach ($ret as $line) {
         $line["feedback"] = urldecode($line["feedback"]);
         $line["feedback"] = ToolModel::toHtml($line["feedback"]);
         if ($line["createtime"] != 0) {
             $line["createtime"] = ToolModel::countTime($line["createtime"]);
         } else {
             $line["createtime"] = "";
         }
         $feedbacks[] = $line;
     }
     $this->_mainContent->assign("feedbacks", $feedbacks);
     $this->display();
 }
Esempio n. 15
0
 public function markApple($id, $apple, $mark = 1)
 {
     $sql = "UPDATE `newscenter_items` set `checked`=1,`apple`={$apple} WHERE `id` = {$id}; ";
     $this->run($sql);
     if ($mark != 1) {
         return;
     }
     $host = "http://74.207.248.39:9090";
     ToolModel::getUrl("{$host}/api/amend/?id={$id}&isTarget={$apple}");
 }
Esempio n. 16
0
 public function saveComment()
 {
     $data["newsid"] = $_POST["newsid"];
     if (empty($_POST["nonamecheck"])) {
         $data["hidename"] = 0;
     } else {
         $data["hidename"] = 1;
     }
     $data["content"] = $_POST["content"];
     $data["posterid"] = $_POST["posterid"];
     $data["poster"] = $_POST["poster"];
     if ($data["posterid"] > 0 && $data["hidename"] == 0) {
         $data["poster"] = $this->usernameById($data["posterid"]);
     }
     $data["createtime"] = time();
     $data["ip"] = ToolModel::getRealIpAddr();
     $data["useragent"] = $_SERVER['HTTP_USER_AGENT'];
     $data["referrer"] = $_SERVER['HTTP_REFERER'];
     $id = $this->select("cocoacms_comments")->insert($data);
     $akismet = new Akismet();
     $comment = $data;
     $comment["id"] = $id;
     $data = array('blog' => 'http://tiny4cocoa.org/home/', 'user_ip' => $comment["ip"], 'user_agent' => $comment["useragent"], 'referrer' => $comment["referrer"], 'permalink' => "http://tiny4cocoa.org/home/s/{$comment['newsid']}", 'comment_type' => 'comment', 'comment_author' => $comment["poster"], 'comment_author_email' => '', 'comment_author_url' => '', 'comment_content' => $comment["content"]);
     $ret = $akismet->commentCheck($data);
     if ($ret) {
         $this->markSpam($comment["id"], 1);
     }
     $this->updateCommentsCount($comment["newsid"]);
     //header("location:/home/s/$comment[newsid]/");
 }
Esempio n. 17
0
 public function __construct($pathinfo, $controller)
 {
     $this->sitename = "OurCoders (我们程序员)";
     $this->short_sitename = "OurCoders";
     $this->pathinfo = $pathinfo;
     parent::__construct($pathinfo, $controller);
     $this->begintime = microtime(true);
     $this->_layout = "index";
     $this->cas[] = array('name' => 'index', 'title' => '首页');
     $this->cas[] = array('name' => 'app', 'title' => '应用列表');
     $this->cas[] = array('name' => 'user', 'title' => '用户');
     $this->cas[] = array('name' => 'group', 'title' => '群组');
     $mainMenu = $this->createMainMenu();
     $title = $this->findTitle();
     $this->_view->assign("sitename", $this->sitename);
     $this->_view->assign("short_sitename", $this->short_sitename);
     if ($title) {
         $this->title = "{$title} - {$this->sitename}";
     } else {
         $this->title = "{$this->sitename}";
     }
     $controller = $this->_controller['name'];
     if ($controller == 'index') {
         $this->breadCrumb = '';
     } else {
         $this->breadCrumb = "<a href='/'>首页</a>-&gt;<a href='/{$controller}/'>{$title}</a>";
     }
     $this->_view->assign('mainMenu', $mainMenu);
     $this->_view->assign('title', $this->title);
     $this->_view->assign('breadCrumb', $this->breadCrumb);
     $controller = ucwords($this->_controller['name']);
     $action = $this->_controller['action'];
     $mainContentFile = "{$controller}/{$action}.html";
     if (file_exists($this->_pathinfo['views'] . '/' . $mainContentFile)) {
         $this->viewFile = $mainContentFile;
     }
     $this->_mainContent->assign("retUrl", $_SERVER['REQUEST_URI']);
     $this->_view->assign("retUrl", $_SERVER['REQUEST_URI']);
     $this->_view->assign("navsel", $controller);
     $userModel = new UserModel();
     $this->userid = $userModel->checklogin();
     if ($this->userid) {
         $this->username = $userModel->username($this->userid);
         $this->isEmailValidated = $userModel->isEmailValidated($this->userid);
         $userinfo = $userModel->userInfo($this->userid);
     }
     $toplinkadsModel = new ToplinkadsModel();
     $toplink = $toplinkadsModel->toplink();
     if ($toplink) {
         $alerttype = array();
         $alerttype[] = "alert-info";
         $alerttype[] = "alert-success";
         $alerttype[] = "";
         $toplink["alert"] = $alerttype[rand(0, 2)];
     }
     $this->_view->assign("toplink", $toplink);
     $this->_view->assign("userid", $this->userid);
     $this->_view->assign("username", $this->username);
     if (isset($this->isEmailValidated)) {
         $this->_view->assign("isEmailValidated", $this->isEmailValidated);
     }
     if (isset($userinfo)) {
         $this->_view->assign("userinfo", $userinfo);
     }
     $iPhone = ToolModel::is_iPhone();
     $this->_view->assign("iPhone", $iPhone);
     $this->_mainContent->assign("userid", $this->userid);
     $this->_mainContent->assign("iPhone", $iPhone);
 }
Esempio n. 18
0
 public function dataAction()
 {
     $id = $this->intVal(3);
     $threadModel = new ThreadModel();
     $userModel = new UserModel();
     $reputation = $userModel->reputation($this->userid);
     $thread = $threadModel->threadById($id);
     if (!$thread || $thread["del"] == 1) {
         header("HTTP/1.1 301 Moved Permanently");
         header("location: /home/");
         die;
     }
     $replys = $threadModel->replysById($id);
     $replysText = "";
     foreach ($replys as $reply) {
         $replysText .= "{$reply['name']}说道:{$reply['content']}\r\n";
     }
     $thread["replysText"] = $replysText;
     $url = "http://" . SEARCHSERVER . ":9200/ourcoders/thread/{$id}/";
     $data = ToolModel::postJSON($url, json_encode($thread));
     echo $data;
 }
Esempio n. 19
0
 public function logAction()
 {
     putenv("TZ=Asia/Shanghai");
     $data = $_POST["log"];
     $logarray = explode("|", $data);
     $logarray[0] = date("Y-m-d H:i:s");
     $line = join(",", $logarray);
     $line = ToolModel::getRealIpAddr() . "," . $line;
     $fp = fopen('/root/log/footprint-' . date("Y-m-d") . '.log', 'a');
     fwrite($fp, $line . "\r\n");
     fclose($fp);
 }