dongdong0925 发表于 2011-6-13 09:19
不好意思,之前把文件名打错了,应该是my.php
没关系,感谢您的关注!
my.php文件是有的,看看参数是否正确,如下:
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: my.php 22875 2011-05-28 06:54:37Z zhouguoqiang $
*/
define('IN_API', true);
define('CURSCRIPT', 'api');
require_once('../../source/class/class_core.php');
require_once('../../source/function/function_home.php');
$cachelist = array();
$discuz = & discuz_core::instance();
$discuz->cachelist = $cachelist;
$discuz->init_cron = false;
$discuz->init_setting = true;
$discuz->init_user = false;
$discuz->init_session = false;
$discuz->init();
require_once DISCUZ_ROOT . './api/manyou/Manyou.php';
class My extends Manyou {
function onSiteGetAllUsers($from, $userNum, $friendNum = 2000, $isExtra) {
$totalNum = getcount('common_member', '');
$sql = 'SELECT s.*
FROM %s s
ORDER BY s.uid
LIMIT %d, %d';
$sql = sprintf($sql, DB::table('common_member'), $from, $userNum);
$query = DB::query($sql);
$spaces = $uIds = array();
while($row = DB::fetch($query)) {
$spaces[$row['uid']] = $row;
$uIds[] = $row['uid'];
}
$users = $this->getUsers($uIds, $spaces, true, $isExtra, true, $friendNum, true);
$result = array('totalNum' => $totalNum,
'users' => $users
);
return $result;
}
function onSiteGetUpdatedUsers($num) {
$totalNum = getcount('common_member_log', '');
$users = array();
if ($totalNum) {
$sql = sprintf('SELECT uid, action FROM %s ORDER BY dateline LIMIT %d', DB::table('common_member_log'), $num);
$query = DB::query($sql);
$deletedUsers = $userLogs = $uIds = array();
$undeletedUserIds = array();
while($row = DB::fetch($query)) {
$uIds[] = $row['uid'];
if ($row['action'] == 'delete') {
$deletedUsers[] = array('uId' => $row['uid'],
'action' => $row['action'],
);
} else {
$undeletedUserIds[] = $row['uid'];
}
$userLogs[$row['uid']] = $row;
}
$updatedUsers = $this->getUsers($undeletedUserIds, false, true, true, false);
foreach($updatedUsers as $k => $v) {
$updatedUsers[$k]['action'] = $userLogs[$v['uId']]['action'];
$updatedUsers[$k]['updateType'] = 'all';
}
$users = array_merge($updatedUsers, $deletedUsers);
if ($uIds) {
$sql = sprintf('DELETE FROM %s WHERE uid IN (%s)', DB::table('common_member_log'), dimplode($uIds));
DB::query($sql);
}
}
$result = array('totalNum' => $totalNum, 'users' => $users);
return $result;
}
function onSiteGetUpdatedFriends($num) {
$friends = array();
$totalNum = getcount('home_friendlog', '');
if ($totalNum) {
$sql = sprintf('SELECT * FROM %s ORDER BY dateline LIMIT %d', DB::table('home_friendlog'), $num);
$query = DB::query($sql);
while ($friend = DB::fetch($query)) {
$friends[] = array('uId' => $friend['uid'],
'uId2' => $friend['fuid'],
'action' => $friend['action']
);
$sql = sprintf('DELETE FROM %s WHERE uid = %d AND fuid = %d', DB::table('home_friendlog'), $friend['uid'], $friend['fuid']);
DB::query($sql);
}
}
$result = array('totalNum' => $totalNum,
'friends' => $friends
);
return $result;
}
function onSiteGetStat($beginDate = null, $num = null, $orderType = 'ASC') {
$sql = 'SELECT * FROM ' . DB::table('common_stat');
if ($beginDate) {
$sql .= sprintf(' WHERE daytime >= %d', $beginDate);
}
$sql .= " ORDER BY daytime $orderType";
if ($num) {
$sql .= " LIMIT $num ";
}
$query = DB::query($sql);
$result = array();
$fields = array('login' => 'loginUserNum',
'doing' => 'doingNum',
'blog' => 'blogNum',
'pic' => 'photoNum',
'poll' => 'pollNum',
'event' => 'eventNum',
'share' => 'shareNum',
'thread' => 'threadNum',
'docomment' => 'doingCommentNum',
'blogcomment' => 'blogCommentNum',
'piccomment' => 'photoCommentNum',
'pollcomment' => 'pollCommentNum',
'eventcomment' => 'eventCommentNum',
'sharecomment' => 'shareCommentNum',
'pollvote' => 'pollUserNum',
'eventjoin' => 'eventUserNum',
'post' => 'postNum',
'wall' => 'wallNum',
'poke' => 'pokeNum',
'click' => 'clickNum',
);
while($row = DB::fetch($query)) {
$stat = array('date' => $row['daytime']);
foreach($row as $k => $v) {
if (array_key_exists($k, $fields)) {
$stat[$fields[$k]] = $v;
}
}
$result[] = $stat;
}
return $result;
}
function onUsersGetInfo($uIds, $fields = array(), $isExtra = false) {
$users = $this->getUsers($uIds, false, true, $isExtra, false);
$result = array();
if ($users) {
if ($fields) {
foreach($users as $key => $user) {
foreach($user as $k => $v) {
if (in_array($k, $fields)) {
$result[$key][$k] = $v;
}
}
}
}
}
if (!$result) {
$result = $users;
}
return $result;
}
function onUsersGetFriendInfo($uId, $num = MY_FRIEND_NUM_LIMIT, $isExtra = false) {
$users = $this->getUsers(array($uId), false, true, $isExtra, true, $num, false, true);
$where = array('uid' => $uId);
$totalNum = getcount('home_friend', $where);
$friends = $users[0]['friends'];
unset($users[0]['friends']);
$result = array('totalNum' => $totalNum,
'friends' => $friends,
'me' => $users[0],
);
return $result;
}
function onUsersGetExtraInfo($uIds) {
$result = $this->getExtraByUsers($uIds);
return $result;
}
function onUsersGetFormHash($uId, $userAgent) {
global $_G;
$uId = intval($uId);
if (!$uId) {
return false;
}
$sql = sprintf('SELECT * FROM %s WHERE uid = %s', DB::table('common_member'), $uId);
$member = DB::fetch_first($sql);
$_G['username'] = $member['username'];
$_G['uid'] = $member['uid'];
$_G['authkey'] = md5($_G['config']['security']['authkey'] . $userAgent);
return formhash();
}
function onFriendsGet($uIds, $friendNum = MY_FRIEND_NUM_LIMIT) {
$result = array();
if ($uIds) {
foreach($uIds as $uId) {
$result[$uId] = $this->_getFriends($uId, $friendNum);
}
}
return $result;
}
function onFriendsAreFriends($uId1, $uId2) {
$query = DB::query("SELECT uid FROM ".DB::table('home_friend')." WHERE uid='$uId1' AND fuid='$uId2'");
$result = false;
if($friend = DB::fetch($query)) {
$result = true;
}
return $result;
}
function onUserApplicationAdd($uId, $appId, $appName, $privacy, $allowSideNav, $allowFeed, $allowProfileLink, $defaultBoxType, $defaultMYML, $defaultProfileLink, $version, $displayMethod, $displayOrder = null, $userPanelArea = null, $canvasTitle = null, $isFullscreen = null , $displayUserPanel = null, $additionalStatus = null) {
global $_G;
$res = $this->getUserSpace($uId);
if (!$res) {
return new ErrorResponse('1', "User($uId) Not Exists");
}
$sql = sprintf('SELECT appid FROM %s WHERE uid = %d AND appid = %d', DB::table('home_userapp'), $uId, $appId);
$query = DB::query($sql);
$row = DB::fetch($query);
if ($row['appid']) {
$errCode = '170';
$errMessage = 'Application has been already added';
return new ErrorResponse($errCode, $errMessage);
}
switch($privacy) {
case 'public':
$privacy = 0;
break;
case 'friends':
$privacy = 1;
break;
case 'me':
$privacy = 3;
break;
case 'none':
$privacy = 5;
break;
default:
$privacy = 0;
}
$narrow = ($defaultBoxType == 'narrow') ? 1 : 0;
$setarr = array('uid' => $uId,
'appid' => $appId,
'appname' => $appName,
'privacy' => $privacy,
'allowsidenav' => $allowSideNav,
'allowfeed' => $allowFeed,
'allowprofilelink' => $allowProfileLink,
'narrow' => $narrow
);
if ($displayOrder !== null) {
$setarr['displayorder'] = $displayOrder;
}
$maxMenuOrder = DB::result_first("SELECT MAX(menuorder) FROM ".DB::table('home_userapp')." WHERE uid='$uId'");
$setarr['menuorder'] = ++$maxMenuOrder;
DB::insert('home_userapp', $setarr);
$fields = array('uid' => $uId,
'appid' => $appId,
'profilelink' => $defaultProfileLink,
'myml' => $defaultMYML
);
$result = DB::insert('home_userappfield', $fields, 1);
updatecreditbyaction('installapp', $uId, array(), $appId);
require_once libfile('function/cache');
updatecache('userapp');
DB::query("UPDATE ".DB::table('common_member_status')." SET lastactivity='$_G[timestamp]' WHERE uid='$uId'");
$displayMethod = ($displayMethod == 'iframe') ? 1 : 0;
$this->refreshApplication($appId, $appName, $version, $userPanelArea, $canvasTitle, $isFullscreen, $displayUserPanel, $displayMethod, $narrow, null, null, $additionalStatus);
return 1;
}
function onUserApplicationRemove($uId, $appIds) {
$sql = sprintf('DELETE FROM %s WHERE uid = %d AND appid IN (%s)', DB::table('home_userapp'), $uId, dimplode($appIds));
$res = DB::query($sql);
$result = DB::affected_rows();
$sql = sprintf('DELETE FROM %s WHERE uid = %d AND appid IN (%s)', DB::table('home_userappfield'), $uId, dimplode($appIds));
$res = DB::query($sql);
updatecreditbyaction('installapp', $uId, array(), $appId, -1);
require_once libfile('function/cache');
updatecache('userapp');
return $result;
}
function onUserApplicationUpdate($uId, $appIds, $appName, $privacy, $allowSideNav, $allowFeed, $allowProfileLink, $version, $displayMethod, $displayOrder = null, $userPanelArea = null, $canvasTitle = null, $isFullscreen = null, $displayUserPanel = null) {
switch($privacy) {
case 'public':
$privacy = 0;
break;
case 'friends':
$privacy = 1;
break;
case 'me':
$privacy = 3;
break;
case 'none':
$privacy = 5;
break;
default:
$privacy = 0;
}
$where = sprintf('uid = %d AND appid IN (%s)', $uId, dimplode($appIds));
$setarr = array(
'appname' => $appName,
'privacy' => $privacy,
'allowsidenav' => $allowSideNav,
'allowfeed' => $allowFeed,
'allowprofilelink' => $allowProfileLink
);
if ($displayOrder !== null) {
$setarr['displayorder'] = $displayOrder;
}
DB::update('home_userapp', $setarr, $where);
$result = DB::affected_rows();
$displayMethod = ($displayMethod == 'iframe') ? 1 : 0;
if (is_array($appIds)) {
foreach($appIds as $appId) {
$this->refreshApplication($appId, $appName, $version, $userPanelArea, $canvasTitle, $isFullscreen, $displayUserPanel, $displayMethod, null, null, null, null);
}
}
return $result;
}
function onUserApplicationGetInstalled($uId) {
$sql = sprintf('SELECT appid FROM %s WHERE uid = %d', DB::table('home_userapp'), $uId);
$query = DB::query($sql);
$result = array();
while ($userApp = DB::fetch($query)) {
$result[] = $userApp['appid'];
}
return $result;
}
function onUserApplicationGet($uId, $appIds) {
$sql = sprintf('SELECT * FROM %s WHERE uid = %d AND appid IN (%s)', DB::table('home_userapp'), $uId, dimplode($appIds));
$query = DB::query($sql);
$result = array();
while($userApp = DB::fetch($query)) {
switch($userApp['privacy']) {
case 0:
$privacy = 'public';
break;
case 1:
$privacy = 'friends';
break;
case 3:
$privacy = 'me';
break;
case 5:
$privacy = 'none';
break;
default:
$privacy = 'public';
}
$result[] = array(
'appId' => $userApp['appid'],
'privacy' => $privacy,
'allowSideNav' => $userApp['allowsidenav'],
'allowFeed' => $userApp['allowfeed'],
'allowProfileLink' => $userApp['allowprofilelink'],
'displayOrder' => $userApp['displayorder']
);
}
return $result;
}
function onFeedPublishTemplatizedAction($uId, $appId, $titleTemplate, $titleData, $bodyTemplate, $bodyData, $bodyGeneral = '', $image1 = '', $image1Link = '', $image2 = '', $image2Link = '', $image3 = '', $image3Link = '', $image4 = '', $image4Link = '', $targetIds = '', $privacy = '', $hashTemplate = '', $hashData = '', $specialAppid=0) {
$res = $this->getUserSpace($uId);
if (!$res) {
return new ErrorResponse('1', "User($uId) Not Exists");
}
$friend = ($privacy == 'public') ? 0 : ($privacy == 'friends' ? 1 : 2);
$images = array($image1, $image2, $image3, $image4);
$image_links = array($image1Link, $image2Link, $image3Link, $image4Link);
$titleTemplate = $this->_myStripslashes($titleTemplate);
$titleData = $this->_myStripslashes($titleData);
$bodyTemplate = $this->_myStripslashes($bodyTemplate);
$bodyData = $this->_myStripslashes($bodyData);
$bodyGeneral = $this->_myStripslashes($bodyGeneral);
require_once libfile('function/feed');
$result = feed_add($appId, $titleTemplate, $titleData, $bodyTemplate, $bodyData, $bodyGeneral, $images, $image_links, $targetIds, $friend, $specialAppid, 1);
return $result;
}
function onNotificationsSend($uId, $recipientIds, $appId, $notification) {
$this->getUserSpace($uId);
$result = array();
$notification = $this->_myStripslashes($notification);
foreach($recipientIds as $recipientId) {
$val = intval($recipientId);
if($val) {
if ($uId) {
$result[$val] = notification_add($val, $appId, $notification) === null;
} else {
$result[$val] = notification_add($val, $appId, $notification, array(), 1) === null;
}
} else {
$result[$recipientId] = null;
}
}
return $result;
}
function onNotificationsGet($uId) {
$notify = $result = array();
$result = array(
'message' => array(
'unread' => 0,
'mostRecent' => 0
),
'notification' => array(
'unread' => 0 ,
'mostRecent' => 0
),
'friendRequest' => array(
'uIds' => array()
)
);
$query = DB::query("SELECT * FROM ".DB::table('home_notification')." WHERE uid='$uId' AND new='1' ORDER BY id DESC");
$i = 0;
while($value = DB::fetch($query)) {
$i++;
if(!$result['notification']['mostRecent']) $result['notification']['mostRecent'] = $value['dateline'];
}
$result['notification']['unread'] = $i;
loaducenter();
$pmarr = uc_pm_list($uId, 1, 1, 'newbox', 'newpm');
if($pmarr['count']) {
$result['message']['unread'] = $pmarr['count'];
$result['message']['mostRecent'] = $pmarr['data'][0]['dateline'];
}
$query = DB::query("SELECT * FROM ".DB::table('home_friend_request')." WHERE uid='$uId' ORDER BY dateline DESC");
$fIds = array();
while($value = DB::fetch($query)) {
if(!$result['friendRequest']['mostRecent']) {
$result['friendRequest']['mostRecent'] = $value['dateline'];
}
$fIds[] = $value['uid'];
}
$result['friendRequest']['uIds'] = $fIds;
return $result;
}
function onApplicationUpdate($appId, $appName, $version, $displayMethod, $displayOrder = null, $userPanelArea = null, $canvasTitle = null, $isFullscreen = null, $displayUserPanel = null, $additionalStatus = null) {
$query = DB::query(sprintf('SELECT appname FROM %s WHERE appid=%d', DB::table('common_myapp'), $appId));
$row = DB::fetch($query);
$result = true;
if ($row['appname'] != $appName) {
$fields = array('appname' => $appName);
$where = array('appid' => $appId);
$result = DB::update('home_userapp', $fields, $where);
require_once libfile('function/cache');
updatecache('userapp');
}
$displayMethod = ($displayMethod == 'iframe') ? 1 : 0;
$this->refreshApplication($appId, $appName, $version, $userPanelArea, $canvasTitle, $isFullscreen, $displayUserPanel, $displayMethod, null, null, $displayOrder, $additionalStatus);
return $result;
}
function onApplicationRemove($appIds) {
$sql = sprintf('DELETE FROM %s WHERE appid IN (%s)', DB::table('home_userapp'), dimplode($appIds));
$result = DB::query($sql);
$sql = sprintf('DELETE FROM %s WHERE appid IN (%s)', DB::table('home_userappfield'), dimplode($appIds));
$result = DB::query($sql);
$sql = sprintf('DELETE FROM %s WHERE appid IN (%s)', DB::table('common_myapp'), dimplode($appIds));
DB::query($sql);
require_once libfile('function/cache');
updatecache(array('userapp', 'myapp'));
return $result;
}
function onApplicationSetFlag($applications, $flag) {
$flag = ($flag == 'disabled') ? -1 : ($flag == 'default' ? 1 : 0);
$appIds = array();
if ($applications && is_array($applications)) {
foreach($applications as $application) {
$this->refreshApplication($application['appId'], $application['appName'], null, null, null, null, null, null, null, $flag, null, null);
$appIds[] = $application['appId'];
}
}
if ($flag == -1) {
$sql = sprintf('DELETE FROM %s WHERE icon IN (%s)', DB::table('home_feed'), dimplode($appIds));
DB::query($sql);
$sql = sprintf('DELETE FROM %s WHERE appid IN (%s)', DB::table('home_userapp'), dimplode($appIds));
DB::query($sql);
$sql = sprintf('DELETE FROM %s WHERE appid IN (%s)', DB::table('home_userappfield'), dimplode($appIds));
DB::query($sql);
$sql = sprintf('DELETE FROM %s WHERE appid IN (%s)', DB::table('common_myinvite'), dimplode($appIds));
DB::query($sql);
$sql = sprintf('DELETE FROM %s WHERE type IN (%s)', DB::table('home_notification'), dimplode($appIds));
DB::query($sql);
}
require_once libfile('function/cache');
updatecache('userapp');
$result = true;
return $result;
}
function onProfileSetMYML($uId, $appId, $markup, $actionMarkup) {
$fields = array('myml' => $markup,
'profileLink' => $actionMarkup);
$where = array('uid' => $uId,
'appid' => $appId
);
DB::update('home_userappfield', $fields, $where);
$result = DB::affected_rows();
return $result;
}
function onProfileSetActionLink($uId, $appId, $actionMarkup) {
$fields = array('profilelink' => $actionMarkup);
$where = array('uid' => $uId,
'appid' => $appId
);
DB::update('home_userappfield', $fields, $where);
$result = DB::affected_rows();
return $result;
}
function onCreditGet($uId) {
global $_G;
$_G['setting']['myapp_credit'] = '';
if($_G['setting']['creditstransextra'][7]) {
$_G['setting']['myapp_credit'] = 'extcredits'.intval($_G['setting']['creditstransextra'][7]);
} elseif ($_G['setting']['creditstrans']) {
$_G['setting']['myapp_credit'] = 'extcredits'.intval($_G['setting']['creditstrans']);
}
if(empty($_G['setting']['myapp_credit'])) {
return 0;
}
$query = DB::query('SELECT '.$_G['setting']['myapp_credit'].' AS credit FROM '
. DB::table('common_member_count') . ' WHERE uid =' . $uId);
$row = DB::fetch($query);
return $row['credit'];
}
function onCreditUpdate($uId, $credits, $appId, $note) {
global $_G;
$_G['setting']['myapp_credit'] = '';
if($_G['setting']['creditstransextra'][7]) {
$_G['setting']['myapp_credit'] = 'extcredits'.intval($_G['setting']['creditstransextra'][7]);
} elseif ($_G['setting']['creditstrans']) {
$_G['setting']['myapp_credit'] = 'extcredits'.intval($_G['setting']['creditstrans']);
}
$errCode = 0;
$errMessage = 'No Credits Allowed';
if(empty($_G['setting']['myapp_credit'])) return new ErrorResponse($errCode, $errMessage);
$where = '';
$type = 1;
if ($credits < 0) {
$where = ' AND ' . $_G['setting']['myapp_credit'] . ' >= ' . abs($credits);
$type = 0;
}
$sql = sprintf('UPDATE %s SET %s = %s + %d WHERE uid=%d %s', DB::table('common_member_count'), $_G['setting']['myapp_credit'], $_G['setting']['myapp_credit'], $credits, $uId, $where);
$result = DB::query($sql);
if (DB::affected_rows() < 1) {
$errCode = 180;
$errMessage = 'No Credits Enough';
return new ErrorResponse($errCode, $errMessage);
}
$fields = array('uid' => $uId,
'appid' => $appId,
'type' => $type,
'credit' => abs($credits),
'note' => $note,
'dateline' => time()
);
$result = DB::insert('home_appcreditlog', $fields, 1);
$query = DB::query('SELECT '.$_G['setting']['myapp_credit'].' AS credit FROM '
. DB::table('common_member_count') . ' WHERE uid =' . $uId);
$row = DB::fetch($query);
return $row['credit'];
}
function onRequestSend($uId, $recipientIds, $appId, $requestName, $myml, $type) {
$now = time();
$result = array();
$type = ($type == 'request') ? 1 : 0;
$fields = array('typename' => $requestName,
'appid' => $appId,
'type' => $type,
'fromuid' => $uId,
'dateline' => $now
);
foreach($recipientIds as $key => $val) {
$hash = crc32($appId . $val . $now . rand(0, 1000));
$hash = sprintf('%u', $hash);
$fields['touid'] = intval($val);
$fields['hash'] = $hash;
$fields['myml'] = str_replace('{{MyReqHash}}', $hash, $myml);
$result[] = DB::insert('common_myinvite', $fields, 1);
$note = array(
'from_id' => $fields['touid'],
'from_idtype' => 'myappquery'
);
notification_add($fields['touid'], 'myapp', 'myinvite_request', $note);
}
return $result;
}
function onVideoAuthSetAuthStatus($uId, $status) {
if ($status == 'approved') {
$status = 1;
updatecreditbyaction('videophoto', $uId);
} else if($status == 'refused') {
$status = 0;
} else {
$errCode = '200';
$errMessage = 'Error arguments';
return new ErrorResponse($errCode, $errMessage);
}
DB::update('common_member', array('videophotostatus' => $status), array('uid' => $uId));
$result = DB::affected_rows();
$count = DB::result(DB::query("SELECT COUNT(*) FROM ".DB::table('common_member_verify')." WHERE uid='$uId'"), 0);
if(!$count) {
DB::insert('common_member_verify', array('uid' => $uId, 'verify7' => $status));
} else {
DB::update('common_member_verify', array('verify7' => $status), array('uid' => $uId));
}
return $result;
}
function onVideoAuthAuth($uId, $picData, $picExt = 'jpg', $isReward = false) {
global $_G;
$res = $this->getUserSpace($uId);
if (!$res) {
return new ErrorResponse('1', "User($uId) Not Exists");
}
$allowPicType = array('jpg','jpeg','gif','png');
if(in_array($picExt, $allowPicType)) {
$pic = base64_decode($picData);
if (!$pic || strlen($pic) == strlen($picData)) {
$errCode = '200';
$errMessage = 'Error argument';
return new ErrorResponse($errCode, $errMessage);
}
$secret = md5($_G['timestamp']."\t".$_G['uid']);
$picDir = DISCUZ_ROOT . './data/avatar/' . substr($secret, 0, 1);
if (!is_dir($picDir)) {
if (!mkdir($picDir, 0777)) {
$errCode = '300';
$errMessage = 'Cannot create directory';
return new ErrorResponse($errCode, $errMessage);
}
}
$picDir .= '/' . substr($secret, 1, 1);
if (!is_dir($picDir)) {
if (!@mkdir($picDir, 0777)) {
$errCode = '300';
$errMessage = 'Cannot create directory';
return new ErrorResponse($errCode, $errMessage);
}
}
$picPath = $picDir . '/' . $secret . '.' . $picExt;
$fp = @fopen($picPath, 'wb');
if ($fp) {
if (fwrite($fp, $pic) !== FALSE) {
fclose($fp);
require_once libfile('class/upload');
$upload = new discuz_upload();
if(!$upload->get_image_info($picPath)) {
@unlink($picPath);
} else {
DB::update('common_member', array('videophotostatus'=>1), array('uid' => $uId));
$count = DB::result(DB::query("SELECT COUNT(*) FROM ".DB::table('common_member_verify')." WHERE uid='$uId'"), 0);
if(!$count) {
DB::insert('common_member_verify', array('uid' => $uId, 'verify7' => 1));
} else {
DB::update('common_member_verify', array('verify7' => 1), array('uid' => $uId));
}
$fields = array('videophoto' => $secret);
DB::update('common_member_field_home', $fields, array('uid' => $uId));
$result = DB::affected_rows();
if ($isReward) {
updatecreditbyaction('videophoto', $uId);
}
return $result;
}
}
fclose($fp);
}
}
$errCode = '300';
$errMessage = 'Video Auth Error';
return new ErrorResponse($errCode, $errMessage);
}
function onMiniBlogPost($uId, $message, $clientIdentify, $ip = '') {
$fields = array('uid' => $uId,
'message' => $message,
'from' => $clientIdentify,
'dateline' => time()
);
if ($ip) {
$fields['ip'] = $ip;
}
$result = DB::insert('home_doing', $fields, 1);
return $result;
}
function onMiniBlogGet($uId, $num, $beginDate = null, $orderType = 'DESC') {
$sql = 'SELECT * FROM %s WHERE uid = %d';
$sql = sprintf($sql, DB::table('home_doing'), $uId);
if ($beginDate) {
$sql .= sprintf(' AND dateline >= %s', $beginDate);
}
$sql .= sprintf(' ORDER BY dateline %s LIMIT %d', $orderType, $num);
$query = DB::query($sql);
$result = array();
while($doing = DB::fetch($query)) {
$result[] = array('created' => $doing['dateline'],
'message' => $doing['message'],
'ip' => $doing['ip'],
'clientIdentify' => $doing['from']
);
}
return $result;
}
function onPhotoCreateAlbum($uId, $name, $privacy, $passwd = null, $friendIds = null) {
require_once libfile('function/spacecp');
$res = $this->getUserSpace($uId);
if (!$res) {
return new ErrorResponse('1', "User($uId) Not Exists");
}
$privacy = $this->_convertPrivacy($privacy);
if ($friendIds && is_array($friendIds)) {
$friends = implode(',', $friendIds);
} else {
$friends = '';
}
$fields = array(
'albumname' => $name,
'friend' => $privacy,
'password' => $passwd,
'target_ids' => $friends
);
$result = album_creat($fields);
return $result;
}
function onPhotoUpdateAlbum($uId, $aId, $name = null, $privacy = null, $passwd = null, $friendIds = null, $coverId = null) {
$aId = intval($aId);
if ($aId < 1) {
$errCode = 120;
$errMessage = 'Invalid Album Id';
return new ErrorResponse($errCode, $errMessage);
}
$fields['updatetime'] = time();
if (is_string($name) && strlen($name) > 0) {
$fields['albumname'] = $name;
}
if ($privacy !== null) {
$fields['friend'] = $this->_convertPrivacy($privacy);
}
if ($passwd !== null) {
$fields['password'] = $passwd;
}
if ($coverId) {
$query = DB::query('SELECT filepath, remote FROM ' . DB::table('home_pic') . ' WHERE picid=' . $coverId . ' AND uid=' . $uId . ' AND albumid=' . $aId);
$coverInfo = DB::fetch($query);
if ($coverInfo && is_array($coverInfo)) {
$fields['pic'] = $coverInfo['filepath'];
$fields['picflag'] = $coverInfo['remote']?2:1;
} else {
$errCode = 121;
$errMessage = 'Invalid Picture Id';
return new ErrorResponse($errCode, $errMessage);
}
}
if ($friendIds && is_array($friendIds)) {
$fields['target_ids'] = implode(', ', $friendIds);
}
DB::update('home_album', $fields, array('uid' => $uId , 'albumid' => $aId));
$result = DB::affected_rows();
return $result;
}
function onPhotoRemoveAlbum($uId, $aId, $action = null , $targetAlbumId = null) {
$res = $this->getUserSpace($uId);
if (!$res) {
return new ErrorResponse('1', "User($uId) Not Exists");
}
$aId = intval($aId);
if ($aId < 1) {
$errCode = 120;
$errMessage = 'Invalid Album Id';
return new ErrorResponse($errCode, $errMessage);
}
if ($action == 'move') {
$targetAlbumId = intval($targetAlbumId);
if ($targetAlbumId < 1) {
$errCode = 120;
$errMessage = 'Invalid Target Album Id';
return new ErrorResponse($errCode, $errMessage);
}
$sql = 'SELECT picnum FROM ' . DB::table('home_album') . ' WHERE albumid=' . $aId . ' AND uid=' . $uId;
$query = DB::query($sql);
$albumInfo = DB::fetch($query);
if (!$albumInfo) {
$errCode = 120;
$errMessage = 'Invalid Album Id';
return new ErrorResponse($errCode, $errMessage);
}
if ($albumInfo['picnum'] > 0) {
$sql = sprintf('UPDATE %s SET picnum = picnum + %d, dateline=%d WHERE albumid =%d AND uid=%d',
DB::table('home_album'), $albumInfo['picnum'], time(), $targetAlbumId , $uId);
DB::query($sql);
$existsAlbum = DB::affected_rows();
if (!$existsAlbum) {
$errCode = 120;
$errMessage = 'Invalid Target Album Id';
return new ErrorResponse($errCode, $errMessage);
}
DB::update('home_pic',array('albumid' => $targetAlbumId), array('albumid' => $aId, 'uid' => $uId));
}
}
require_once libfile('function/delete');
$res = deletealbums(array($aId));
if ($res && is_array($res)) {
return true;
} else {
$errCode = 124;
$errMessage = 'Delete Album Failure';
return new ErrorResponse($errCode, $errMessage);
}
}
function onPhotoGetAlbums($uId) {
$sql = 'SELECT * FROM ' . DB::table('home_album') . ' WHERE uid = ' . $uId;
$query = DB::query($sql);
$albums = array();
while($album = DB::fetch($query)) {
$albums[] = $this->_convertAlbum($album);
}
return $albums;
}
function onPhotoUpload($uId, $aId, $fileName, $fileType, $fileSize, $data, $caption = null) {
global $_G;
$res = $this->getUserSpace($uId);
if (!$res) {
return new ErrorResponse('1', "User($uId) Not Exists");
}
$aId = intval($aId);
if ($aId < 1) {
$errCode = 120;
$errMessage = 'Invalid Album Id';
return new ErrorResponse($errCode, $errMessage);
}
if (!is_string($data) || strlen($data) < 1) {
$errCode = 123;
$errMessage = 'Uploaded File Is Not A Valid Image';
return new ErrorResponse($errCode, $errMessage);
}
require_once libfile('function/spacecp');
global $_SC;
$attachDir = $_SC['attachdir'];
$_SC['attachdir'] = DISCUZ_ROOT . './' . $_G['setting']['attachdir'];
$stream = base64_decode($data);
$res = stream_save($stream, $aId, $fileType, $fileName, $caption);
$_SC['attachdir'] = $attachDir;
$picInfo = array();
if ($res && is_array($res)) {
$picInfo['pId'] = $res['picid'];
$picInfo['src'] = $res['filepath'];
} else if ($res == -1) {
$errCode = 122;
$errMessage = 'No Enough Space';
} else if ($res == -2) {
$errCode = 123;
$errMessage = 'Uploaded File Is Not A Valid Image';
} else {
$errCode = 1;
$errMessage = 'Unknown Error';
}
if ($picInfo) {
return $picInfo;
} else {
return new ErrorResponse($errCode, $errMessage);
}
}
function onPhotoGet($uId, $aId, $pIds = null) {
global $_G;
$aId = intval($aId);
if ($aId < 1) {
$errCode = 120;
$errMessage = 'Invalid Album Id';
return new ErrorResponse($errCode, $errMessage);
}
$sql = 'SELECT * FROM ' . DB::table('home_pic') . ' WHERE uid=' . $uId. ' AND albumid=' . $aId ;
if ($pIds && is_array($pIds)) {
$sql .= ' AND picid IN (' . implode(', ', $pIds) . ' )';
}
$query = DB::query($sql);
$result = array();
$k = 0;
$siteUrl = $this->_getUchomeUrl();
while ($picInfo = DB::fetch($query)) {
$r_src = pic_get($picInfo['filepath'], 'album', $picInfo['thumb'], $picInfo['remote'], 0);
if(!preg_match("/^(http\:\/\/|\/)/i", $r_src)) {
$r_src = $siteUrl.$r_src;
}
$result[$k]['pId'] = $picInfo['picid'];
$result[$k]['aId'] = $picInfo['albumid'];
$result[$k]['src'] = $r_src;
$result[$k]['caption'] = $picInfo['title'];
$result[$k]['created'] = $picInfo['dateline'];
$result[$k]['fileName'] = $picInfo['filename'];
$result[$k]['fileSize'] = $picInfo['size'];
$result[$k]['fileType'] = $picInfo['type'];
$k++;
}
return $result;
}
function onPhotoUpdate($uId, $pId, $aId, $fileName = null, $fileType = null, $fileSize = null, $caption = null, $data = null ) {
global $_G;
$res = $this->getUserSpace($uId);
if ($fileName !== null) {
$fields['filename'] = $fileName;
}
if (is_string($caption) && strlen($caption) > 0) {
$fields['title'] = $caption;
}
if (is_string($data) && strlen($data) > 0) {
$query = DB::query('SELECT size, title, filename FROM ' . DB::table('home_pic') . ' WHERE picid=' . $pId. ' AND albumid=' . $aId . ' AND uid=' . $uId);
$picInfo = DB::fetch($query);
if ($picInfo && is_array($picInfo)) {
require_once libfile('function/spacecp');
$attachDir = $_SC['attachdir'];
$_SC['attachdir'] = DISCUZ_ROOT . './' . $_G['setting']['attachdir'];
$title = $fields['title'] ? $caption : $picInfo['title'];
$name = $fields['filename'] ? $fileName : $picInfo['filename'];
$stream = base64_decode($data);
$pic = stream_save($stream, $aId, $fileType, $name, $title, $picInfo['size']);
$_SC['attachdir'] = $attachDir;
$newPic = array();
if ($pic && is_array($pic)) {
require_once libfile('function/delete');
deletepics(array($pId));
DB::update('home_pic', array('picid' => $pId), array('picid' => $pic['picid']));
$newPic['pId'] = $pId;
$newPic['src'] = $pic['filepat'];
return new APIResponse($newPic);
} else if ($res == -1) {
$errCode = 122;
$errMessage = 'No Enough Space';
} else if ($res == -2) {
$errCode = 123;
$errMessage = 'Uploaded File Is Not A Valid Image';
} else {
$errCode = 1;
$errMessage = 'Unknown Error';
}
} else {
$errCode = 121;
$errMessage = 'Invalid Picture Id';
}
return new ErrorResponse($errCode, $errMessage);
} else {
$where = array('uid' => $uId, 'albumid' => $aId, 'picid' => $pId);
DB::update('home_pic', $fields, $where);
$query = DB::query('SELECT * FROM ' . DB::table('home_pic') . ' WHERE picid=' . $pId . ' AND uid=' . $uId . ' AND albumid=' . $aId);
$picInfo = DB::fetch($query);
if($picInfo && is_array($picInfo)) {
$newPic['pId'] = $pId;
$newPic['src'] = pic_get($picInfo['filepath'], $picInfo['thumb'], $picInfo['remote'], 0);
if(!preg_match("/^(http\:\/\/|\/)/i", $newPic['src'])) {
$newPic['src'] = $this->_getUchomeUrl().$newPic['src'];
}
return $newPic;
} else {
$errCode = 121;
$errMessage = 'Invalid Picture Id';
return new ErrorResponse($errCode, $errMessage);
}
}
}
function onPhotoRemove($uId, $pIds) {
$result = false;
if (!$pIds && !is_array($pIds)) {
$errCode = 121;
$errMessage = 'Invalid Picture Id';
return new ErrorResponse($errCode, $errMessage);
}
require_once libfile('function/delete');
$picInfos = deletepics($pIds);
$result = array();
$deleteIds = array();
foreach ($picInfos as $picInfo) {
$deleteIds[] = $picInfo['picid'];
$result[] = array('pId' => $picInfo['picid'], 'status' => true);
}
$errorIds = array_diff($pIds, $deleteIds);
foreach($errorIds as $pId) {
$result[] = array('pId' => $pId, 'status' => false);
}
return $result;
}
function _convertAlbum($albumInfo) {
$siteUrl = $this->_getUchomeUrl();
if ($albumInfo && is_array($albumInfo)) {
$convAlbum = array();
$convAlbum['aId'] = $albumInfo['albumid'];
$convAlbum['name']= $albumInfo['albumname'];
$convAlbum['created'] = $albumInfo['dateline'];
$convAlbum['updated'] = $albumInfo['updatetime'];
$convAlbum['privacy'] = $this->_convertPrivacy($albumInfo['friend'], true);
$convAlbum['passwd'] = $albumInfo['passwd'];
$convAlbum['friendIds'] = ($albumInfo['target_ids']) ? explode(',', $albumInfo['target_ids']) : '';
if($albumInfo['pic']) {
$convAlbum['cover'] = pic_cover_get($albumInfo['pic'], $albumInfo['picflag']);
if(!preg_match("/^(http\:\/\/|\/)/i", $convAlbum['cover'])) {
$convAlbum['cover'] = $siteUrl.$struct['url'];
}
} else {
$convAlbum['cover'] = '';
}
$convAlbum['url'] = $siteUrl . 'space.php?uid=' . $albumInfo['uid'] . '&do=album&id=' . $albumInfo['albumid'];
} else {
$convAlbum = false;
}
return $convAlbum;
}
function _getUchomeUrl() {
global $_G;
return dirname(dirname($_G['siteurl'])) . '/';
}
function onNewsFeedGet($uId, $num) {
$result = array();
$query = DB::query("SELECT * FROM ".DB::table('home_feed')." WHERE uid='$uId' ORDER BY dateline DESC LIMIT 0,$num");
while($value = DB::fetch($query)) {
$result[] = array(
'appId' => $value['appid'],
'created' => $value['dateline'],
'type' => $value['icon'],
'titleTemplate' => $value['title_template'],
'titleData' => $value['title_data'],
'bodyTemplate' => $value['body_template'],
'bodyData' => $value['body_data'],
'bodyGeneral' => $value['body_general'],
'image1' => $value['image_1'],
'image1Link' => $value['image_1_link'],
'image2' => $value['image_2'],
'image2Link' => $value['image_2_link'],
'image3' => $value['image_3'],
'image3Link' => $value['image_3_link'],
'image4' => $value['image_4'],
'image4Link' => $value['image_4_link'],
'targetIds' => $value['target_ids'],
'privacy' => $value['friend']==0?'public'$value['friend']==1?'friends':'someFriends')
);
}
|