public static function ActionSaveMessage($chatId) { ChatModel::saveMessage($chatId, 1, $_POST['message']); exit('ok'); if (UserModel::isUserLoggedIn() and ChatModel::isUserInChat($chatId, UserModel::getUserId())) { } }
public static function addMessage($chatId, $message) { $db = Mdb::GetConnection(); $collection = $db->selectCollection(Mdb::$dbname, 'chat'); $message = ['senderId' => UserModel::getUserId(), 'date' => UserModel::getDateString(), 'text' => $message, 'timestamp' => time()]; $collection->update(['_id' => intval($chatId)], ['$push' => ['messages' => $message]]); return $message; }
public static function ActionChangeAvatar() { $path = root . '/application/data/users/' . UserModel::getUserId() . '/'; if (file_exists($path . 'avatar.png')) { unlink($path . 'avatar.png'); } $image = self::fileUpload($path); exit('/application/data/users/' . UserModel::getUserId() . '/' . $image); }
public static function addComment($postId, $text) { $db = Db::connect(); $query = "INSERT INTO comments(author, post, text, date) VALUES(:author, :post, :text, :date)"; $stmt = $db->prepare($query); $stmt->bindParam(':author', UserModel::getUserId()); $stmt->bindParam(':post', $postId); $stmt->bindParam(':text', $text); $stmt->bindParam(':date', date('jS \\of F Y h:i:s A')); $stmt->execute(); }
public static function ActionRules() { $id = UserModel::getUserId(); $dictionary = UserModel::getLangArray(); $menuClass = [0 => 'active', 1 => '', 2 => '', 3 => '', 4 => '', 5 => '']; $view = 'templates/userProfile.php'; $profile_content = 'templates/rules.php'; $links = ['userProfile.css', 'webcam.css', 'rules.css']; $scripts = ['dragAndDropDownload.js', 'addPost.js', 'MediaAPI.js']; $user = UserModel::getInfo($id); include_once view . '/templates/template.php'; }
<div class="panel-body"> <ul class="chat"> <?php foreach ($messages as $message) { ?> <?php if ($message['senderId'] == intval(UserModel::getUserId())) { ?> <?php include view . 'templates/message/messageRight.php'; ?> <?php } else { ?> <?php include view . 'templates/message/messageLeft.php'; ?> <?php } ?> <?php } ?> </ul> <div class="row"> <form method='post' role="form" id="chatForm" action="/addMessage/<?php echo $chatId; ?> " timestamp="<?php echo $timestamp;
public static function addPostLike($userId, $postId) { $db = Mdb::GetConnection(); $collection = $db->selectCollection(Mdb::$dbname, 'user'); $result = $collection->findOne(['_id' => intval($userId)], ['wall' => true]); $nLikes = 0; for ($i = 0; $i < count($result['wall']); $i++) { if ($result['wall'][$i]['id'] == $postId) { if (in_array(UserModel::getUserId(), $result['wall'][$i]['like'])) { return false; } else { $result['wall'][$i]['like'][] = UserModel::getUserId(); $nLikes = count($result['wall'][$i]['like']); $collection->update(['_id' => intval($userId)], ['$set' => ['wall' => $result['wall']]]); } } } return $nLikes; }
</div> <?php foreach ($user['information'] as $item) { ?> <div class="info profile-property col-md-3"> <?php echo key($item); ?> </div> <div class="val col-md-9"> <?php echo current($item); ?> <?php if ($id == UserModel::getUserId()) { ?> <i class="pull-right dell-info fa fa-minus-square-o"></i> <?php } ?> </div> <?php } ?> <div class="add-information"> <div class="col-md-3"> <input name="info" placeholder="<?php echo $dictionary['information']; ?>
public static function ActionDellPhotos() { $data = file_get_contents('php://input'); $data = json_decode($data, true); unlink(root . '/application/data/users/' . UserModel::getUserId() . '/photos/' . $data); if (UserModel::delletePhoto($data)) { exit('ok'); } exit('failed'); }
*/ // ///////////////////////// // CONTROLLER checkin.php // //////////////////////////// // Page de vérification du login et du mot de passe ///////////////////////////////////////////////////////////////////////////////////////// // Appel aux classes de Model pour récupérer les données include_once "account/model/UserModel.php"; session_start(); ///////////////////////////////////////////////////////////////////////////////////////// // Traitement des données et des informations diverses // Récupération du USER via le login saisi $login = $_POST['login']; $password = $_POST['password']; $crypted_password = md5($password); $user = new UserModel(); // Renvoi l'utilisateur s'il existe; renvoi null sinon $usercheck = $user->checkUserByLogin($login); if (!$usercheck) { echo "Aucun utilisateur ne correspond a votre login"; } else { // vérification du mot de passe $checkpassword = $user->checkUserPassword($login, $crypted_password); if (!$checkpassword) { echo "Mot de passe incorrect"; } else { $user->init($login, $crypted_password); $_SESSION['userid'] = $user->getUserId(); header('Location: index.php'); } }
function searchSchool($keyword, $ssotoken) { $tblLog = new DB_Udo_SearchLog(); $userModel = new UserModel(); $uid = $userModel->getUserId($ssotoken); //print_r($keyword); //先进行结果查询,将查询出来的id记录下来 $tblEntrance = new DB_Sso_Entrance(); //记录结果id的数组 $result = []; $resultIds = []; //关键字搜索的长度限制 //获取输入的关键字的字符串长度 /* $length = strlen($keyword); for($i = $length;$i >=1 ;$i--){ //对关键词进行拆分 $split_array = str_split($keyword,$i); foreach ($split_array as $k=>$value){ //对于每一个截断后的结果进行搜索 $name = $tblEntrance->fetchAll("id","where customer_name like '%{$value}%' or customer_title like '%{$value}%' "); $result = array_merge($result,$name); } } $resultIds = $tblEntrance->columnRow($result,"id"); print_r(array_unique($resultIds)); print_r(str_split("外语")); print_r(preg_split("/[\s,]+/","外语 教学,研究")); $tempaddtext="php对UTF8字体串进行单字分割返回数组"; //$cind代表的是字符位移 $cind = 0; $arr_cont = array(); for ($i = 0; $i < strlen($tempaddtext); $i++) { if (strlen(substr($tempaddtext, $cind, 1)) > 0) { if (ord(substr($tempaddtext, $cind, 1)) < 192) { if (substr($tempaddtext, $cind, 1) != " ") { array_push($arr_cont, substr($tempaddtext, $cind, 1));} $cind++;} elseif(ord(substr($tempaddtext, $cind, 1)) < 224) { array_push($arr_cont, substr($tempaddtext, $cind, 2)); $cind+=2;} else {array_push($arr_cont, substr($tempaddtext, $cind, 3));$cind+=3;}}} print_r($arr_cont);*/ $result = $tblEntrance->fetchAll("id", "where customer_name like '%{$keyword}%' or customer_title like '%{$keyword}%' "); $resultIds = $tblEntrance->columnRow($result, 'id'); if (!$resultIds) { $tblLog->insert(array("userId" => $uid, "keyword" => $keyword, "result" => -1, "createTime" => time())); return -1; } //print_r($resultIds); $result_array = []; //从sso获取所有频道 $url = Common_Config::SSO_SCHOOL_URL; $post_data = array("ssotoken" => $ssotoken); $cl = new Common_Curl(); $array = $cl->request($url, $post_data); $array['entrances'] = $this->schoolOrder($array); //针对搜索结果,返回频道的基础信息 foreach ($resultIds as $l) { foreach ($array['entrances'] as $k => $val) { if ($val['id'] == $l) { $price = $this->getSchoolPrice($l, $uid); $val = array_merge($val, array("isSubscribed" => $this->getIfSub($val['id'], $uid) ? 1 : 0), $price); $index = 0; //过滤掉apiBaseUrl项目 while ($key = key($val)) { if ($key == "apiBaseUrl") { array_splice($val, $index, 1); break; } $index++; next($val); } array_push($result_array, $val); } } if (count($result_array) == count($resultIds)) { break; } } if (!$result_array) { $tblLog->insert(array("userId" => $uid, "keyword" => $keyword, "result" => -1, "createTime" => time())); return -1; } $tblLog->insert(array("userId" => $uid, "keyword" => $keyword, "result" => count($result_array), "resultString" => implode(',', $resultIds), "createTime" => time())); //print_r($result_array); return $result_array; }
function searchSchoolAction() { $request = $this->getRequest(); if ('POST' == $request->getMethod()) { $ssotoken = $this->post()->get("ssotoken"); $keyword = $this->post()->get("keyword"); } else { $ssotoken = $this->get("ssotoken"); $keyword = $this->get("keyword"); } if (!$ssotoken || !$keyword) { $this->displayJsonUdo(Common_Error::ERROR_PARAM); } //获取用户id $userModel = new UserModel(); $uid = $userModel->getUserId($ssotoken); if (is_array($uid)) { $this->displayJsonUdo(Common_Error::INVALID_TOKEN, "", $uid['msg']); } $schoolModel = new SchoolModel(); $result = $schoolModel->searchSchool($keyword, $ssotoken); if ($result == -1) { $this->displayJsonUdo(Common_Error::ERROR_NO_SEARCH_RESULT, "", "搜索结果为空"); } $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, $result); }
/** * 用户是否存在 */ public function getAdAction() { //广告接口首先拿客户端传来的ssotoken 在SSO进行验证获取用户信息 $request = $this->getRequest(); $userModel = new UserModel(); $userModel->logout(); if ('POST' == $request->getMethod()) { $token = trim($this->post()->get("ssotoken")); } else { $token = $this->get("ssotoken"); } //$token = "1"; if (!$token) { $this->displayJsonUdo(Common_Error::ERROR_PARAM); } //获取到用户信息 $url = Common_Config::SSO_SCHOOL_URL; $post_data = array("ssotoken" => $token); //print_r($post_data); $cl = new Common_Curl(); $result = $cl->request($url, $post_data); /* $result = array("id"=>8 , "grade"=>11,"province"=>3,"city"=>4,"area"=>5, "entrances"=>array(0=>array("id"=>1,"name"=>"双十","title"=>"双十网校","grade"=>11,"baseUrl"=>"1", "udoUrl"=>"2","city_id"=>4), 1=>array("id"=>2,"name"=>"华英","title"=>"华英网校","grade"=>14,"baseUrl"=>"1", "udoUrl"=>"2","city_id"=>6), 2=>array("id"=>3,"name"=>"三明","title"=>"三明网校","grade"=>15,"baseUrl"=>"1", "udoUrl"=>"2","city_id"=>4)));*/ //print_r($result); if (array_key_exists('code', $result) && $result['code'] == 0) { $this->displayJsonUdo(Common_Error::ERROR_FAIL, null, "SSO没有返回正确的用户信息哦~"); } //$result = array ("id"=> 2779,"province"=>3,"grade"=>11); //$result = array ("id"=> 2779,"province"=> 0,"grade"=>11); //sso返回成功,开始进行广告过滤 //print_r($result); //过滤出和用户所在地区和年级一致的广告 $ad = new AdModel(); $adlist = $ad->getAd($result); $uid = $userModel->getUserId($token); /*$kaixin = $ad->filterPrimary($uid); if(is_array($kaixin)) $adlist = $kaixin;*/ //计算总竞价值 $price_sum = 0; $temp_arr = array(); foreach ($adlist as $i => $val) { $price_sum += $val['price']; } //生成随机数 $arr = array(); $arr[] = rand(1, 100); $arr = array_unique($arr); $rand = implode(" ", $arr); //获得随机url $url = []; $rate = 0; foreach ($adlist as $i => $val) { $temp_arr[$i] = $val['price'] / $price_sum * 100 + ($i - 1 >= 0 ? $temp_arr[$i - 1] : 0); //print_r($i." ".$temp_arr[$i]); if ($rand <= $temp_arr[$i] && $rand >= ($i - 1 >= 0 ? $temp_arr[$i - 1] : 0)) { $url = $val; $rate = $val['price'] / $price_sum; } } //将推送的广告写入广告推送表 $ad->adLog($url['id'], 0, $rate); $ad->adPushSum($url['id']); $ad->adStatistics($url['id']); $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, $url); }
function payAction() { $request = $this->getRequest(); if ('POST' == $request->getMethod()) { $ssotoken = $this->post()->get("ssotoken"); $payType = $this->post()->get("payType"); $resource = $this->post()->get("resource"); $amt = $this->post()->get("amt"); $coinId = $this->post()->get("coinId"); $platform = $this->post()->get("channel"); $schoolId = $this->post()->get("schoolId"); } else { $ssotoken = $this->get("ssotoken"); $payType = $this->get("payType"); $resource = $this->get("resource"); $amt = $this->get("amt"); $coinId = $this->get("coinId"); $platform = $this->get("channel"); $schoolId = $this->get("schoolId"); } //此处为测试数据 //$resource = []; $resource = json_decode($resource, true); //接收参数判断 if (!$ssotoken || !$payType || !$amt) { $this->displayJsonUdo(Common_Error::ERROR_PARAM, "", "缺少必选参数"); } $courseCount = 0; $schoolModel = new SchoolModel(); //余额支付时,需对resource参数进行判断 if ($payType == Common_Config::UDO_PAYTYPE_COIN || $payType == Common_Config::UDO_PAYTYPE_CREDIT) { if (!is_array($resource) || !$schoolId) { $this->displayJsonUdo(Common_Error::ERROR_PARAM, "", "缺少resource或schoolId参数"); } //从客户端传过来的resource是所有选中的资源 //此处根据resource生成交易的信息 //$resourceType = 0; $resourceInfo = ""; $courseName = ""; foreach ($resource as $k => $value) { if ($value['resourceType'] == Common_Config::UDO_RESOURCE_COURSE) { $courseCount++; //$resourceType = Common_Config::UDO_RESOURCE_SCHOOL; $resourceInfo = "频道"; $courseName = $courseName ? $courseName : $schoolModel->getSingleCourse($value['resourceId']); } } $resourceInfo = $courseName['name'] . "'等" . $courseCount . "个课程"; } elseif ($payType == Common_Config::UDO_PAYTYPE_RECHARGE) { if (!$coinId || !$platform) { $this->displayJsonUdo(Common_Error::ERROR_PARAM, "", "缺少channel或coinId参数"); } } $accountModel = new AccountModel(); $tradeModel = new TradeModel(); $userModel = new UserModel(); //在校验过参数完整性后,生成订单 $uid = $userModel->getUserId($ssotoken); if (is_array($uid)) { $this->displayJsonUdo(Common_Error::INVALID_TOKEN, "", $uid['msg']); } $order = $accountModel->newOrder($ssotoken, $uid, $schoolId, $courseCount, $payType, $resource, $coinId, $amt, $platform); //对生成订单的结果进行判断 if ($order < 0) { $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, array("result" => $order)); } //生成订单后,将支付参数传向公共云 //根据支付类型不同,在调用公共云的支付服务时,传相应的值处理 /* * @param payType * 1:U币支付 * 2:U币充值 * 3.学分支付 */ switch ($payType) { case Common_Config::UDO_PAYTYPE_COIN: $type = Common_Config::PUBLIC_PAYTYPE_AMOUNT; $subject = "U币购买'" . $resourceInfo; $score = 0; $balanceAmt = $amt; $channel = 0; $chargeAmt = 0; break; case Common_Config::UDO_PAYTYPE_RECHARGE: //客户端提交的amt均为 $type = $type = Common_Config::PUBLIC_PAYTYPE_CHANNEL; $coinMoney = $tradeModel->getCoinMoney($coinId); //实际 $chargeAmt = $amt; $amt = $coinMoney['price']; $subject = "U币充值"; $score = 0; $balanceAmt = 0; $channel = $platform; break; case Common_Config::UDO_PAYTYPE_CREDIT: $type = Common_Config::PUBLIC_PAYTYPE_AMOUNT; $subject = "学分购买'" . $resourceInfo; $score = $amt; $amt = 0; $balanceAmt = 0; $channel = 0; $chargeAmt = 0; break; } //notifyUrl:需腰写在配置文件里 $notifyUrl = Common_Config::PAY_NOTIFY_URL; $remark = "支付"; //公共云传回预下单信息 $result = $accountModel->pay($ssotoken, $type, $subject, $amt, $chargeAmt, $score, $balanceAmt, $channel, $notifyUrl, $remark); switch ($payType) { case Common_Config::UDO_PAYTYPE_COIN: case Common_Config::UDO_PAYTYPE_CREDIT: if ($result) { //支付成功,写入购买关系表,U币和学分变动表 $insertBought = $accountModel->insertBought($uid, $schoolId, $resource, $order, $result['transNo']); $accountModel->insertTransLog($uid, 0 - ($payType == Common_Config::UDO_PAYTYPE_CREDIT ? $score : $amt), $subject, $payType == Common_Config::UDO_PAYTYPE_CREDIT ? Common_Config::CREDIT_LOG : Common_Config::COIN_LOG, $ssotoken, $schoolId); if ($insertBought < 0) { $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, array("result" => $insertBought)); } } //print_r($result); $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, array_merge(array("result" => Common_Error::ERROR_ORDER_SUCCESS), $result)); break; case 2: if (array_key_exists("invoke", $result) && array_key_exists("transNo", $result) && $result['transNo'] && $result['invoke']) { $accountModel->updateOrder($order, $result['transNo'], Common_Config::ORDER_NOT_PAY); $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, array_merge(array("result" => Common_Error::ERROR_ORDER_SUCCESS), array("transNo" => $result['transNo'], "invoke" => $result['invoke']))); } break; } $this->displayJsonUdo(Common_Error::ERROR_FAIL); }
<div class="profile-usertitle"> <div class="profile-usertitle-name"> <?php echo $user['name'] . ' ' . $user['surname']; ?> </div> <div class="profile-usertitle-job"> Developer </div> </div> <div class="profile-userbuttons"> <?php if (UserModel::getUserId() != $id) { ?> <?php if (!in_array($id, UserModel::getFollowers(UserModel::getUserId()))) { ?> <a href="" value="<?php echo $id; ?> " id="follow" type="submit" class="btn btn-success btn-sm"><?php echo $dictionary['follow']; ?> </a> <?php } ?> <a href="/createChat/<?php echo $id; ?> " value="<?php
public static function getMainVariables() { return ['scripts' => ['authorization.js'], 'dict' => PageModel::getDictionary(UserModel::getUserLanguage()), 'user' => ['isAdmin' => AdminModel::isAdmin(), 'isModerator' => ModeratorModel::isModerator(), 'isLoggedIn' => UserModel::isUserLoggedIn(), 'name' => UserModel::getUserLogin(), 'id' => UserModel::getUserId(), 'theme' => UserModel::getUserThemeFromDb()], 'theme' => PageModel::getStandartTheme()]; }