private function onExit($status, $msg = '') { MyTool::setVar($this, MyConst::FIELD_STATUS, $status); MyTool::setVar($this, MyConst::FIELD_MESSAGE, $msg); MyTool::simpleView(); return true; }
private function getUserInfo($account) { $userId = null; if (MyTool::isEmail($account)) { $userId = sprintf("%s='%s'", MyConst::FIELD_EMAIL, $account); } else { $userId = sprintf("%s='%s'", MyConst::FIELD_PHONE, $account); } return MaUser::findFirst($userId); }
public static function addMember($tid, $uid) { $member = new MaTeamMember(); $member->ctime = MyTool::now(); $member->mtime = $member->ctime; $member->flag = 0; $member->deleted = 0; $member->tid = $tid; $member->uid = $uid; return $member; }
public static function getUser($account) { $userId = null; if (MyTool::isEmail($account)) { $userId = sprintf("%s='%s'", MyConst::FIELD_EMAIL, $account); } else { if (MyTool::isPhone($account)) { $userId = sprintf("%s='%s'", MyConst::FIELD_PHONE, $account); } else { $userId = sprintf("id=%s", $account); } } return MaUser::findFirst($userId); }
public function deleteAction() { // 使用默认视图 MyTool: simpleView(); // 验证登录状态 if (!MyTool::loginAuth($this)) { return $this->onExit(MyConst::STATUS_NOT_LOGIN, 'must login first'); } $targetId = @intval($targetId); $uid = @intval(MyTool::getCookie($this, MyConst::COOKIE_UID)); // 获取团队信息 $team = TeamLogic::getTeam($targetId); if (empty($team)) { return MyTool::onExit($this, MyConst::STATUS_INVALID_TEAM, 'invalid team id'); } if (TeamLogic::isOwner($uid, $targetId)) { return MyTool::onExit($this, MyConst::STATUS_ERROR, 'owner of team'); } // 团队成员 $member = MaTeamMember::getMember($targetId, $uid); if (empty($member)) { return MyTool::onExit($this, MyConst::STATUS_NOT_EXISTS, 'not a member of team'); } // 删除成员 try { if (true !== $member->delete()) { return MyTool::onExit($this, MyConst::STATUS_DB, 'delete team fail'); } } catch (Exception $e) { return MyTool::onExit($this, MyConst::STATUS_ERROR, $e->getMessage()); } // 返回 MyTool::setVar($this, MyConst::FIELD_STATUS, MyConst::STATUS_OK); return true; }
/** * add channel * * @param string $xmlUrl String corresponding to the XML URL * * @return true|false True if add is success, false otherwise */ public function addChannel($xmlUrl) { $feedHash = MyTool::smallHash($xmlUrl); $error = ''; if (!isset($this->_data['feeds'][$feedHash])) { $output = $this->loadRss($xmlUrl); if (empty($output['feed']['error'])) { $output['feed']['xmlUrl'] = $xmlUrl; $output['feed']['nbUnread'] = count($output['items']); $output['feed']['nbAll'] = count($output['items']); $this->_data['feeds'][$feedHash] = $output['feed']; $this->_data['needSort'] = true; $items = $output['items']; foreach (array_keys($items) as $itemHash) { if (empty($items[$itemHash]['via'])) { $items[$itemHash]['via'] = $output['feed']['htmlUrl']; } if (empty($items[$itemHash]['author'])) { $items[$itemHash]['author'] = $output['feed']['title']; } else { $items[$itemHash]['author'] = $output['feed']['title'] . ' (' . $items[$itemHash]['author'] . ')'; } $items[$itemHash]['xmlUrl'] = $xmlUrl; $this->_data['newItems'][$feedHash . $itemHash] = array($items[$itemHash]['time'], 0); $items[$feedHash . $itemHash] = $items[$itemHash]; unset($items[$itemHash]); } $this->writeFeed($feedHash, $items); } else { $error = $output['feed']['error']; } } else { $error = Intl::msg('Duplicated feed'); } return array('error' => $error); }
/** * Convert opml array into more convenient array with xmlUrl as key * * @param array $array Array obtained from Opml file * @param array $listFolders List of current folders * * @return array New formated array */ public static function convertOpmlArray($array, $listFolders = array()) { $newArray = array(); for ($i = 0, $len = count($array); $i < $len; $i++) { if (isset($array[$i]['outline']) && (isset($array[$i]['text']) || isset($array[$i]['title']))) { // here is a folder if (isset($array[$i]['text'])) { $listFolders[] = $array[$i]['text']; } else { $listFolders[] = $array[$i]['title']; } $newArray = array_merge($newArray, Opml::convertOpmlArray($array[$i]['outline'], $listFolders)); array_pop($listFolders); } else { if (isset($array[$i]['xmlUrl'])) { // here is a feed $xmlUrl = MyTool::smallHash($array[$i]['xmlUrl']); if (isset($newArray[$xmlUrl])) { //feed already exists foreach ($listFolders as $val) { // add folder to the feed if (!in_array($val, $newArray[$xmlUrl]['folders'])) { $newArray[$xmlUrl]['folders'][] = $val; } } } else { // here is a new feed foreach ($array[$i] as $attr => $val) { $newArray[$xmlUrl][$attr] = $val; } $newArray[$xmlUrl]['folders'] = $listFolders; } } } } return $newArray; }
$hashView = 'Folder (' . $kf->getFolderTitle($currentHash) . '): <span id="nb-unread">' . $unread . '</span><span class="hidden-phone"> ' . Intl::msg('unread items') . '</span>'; break; default: $hashView = '<span id="nb-unread">' . $unread . '</span><span class="hidden-phone"> ' . Intl::msg('unread items') . '</span>'; break; } $menu = $kfc->getMenu(); $paging = $kfc->getPaging(); $pb->assign('menu', $menu); $pb->assign('paging', $paging); $pb->assign('currentHashType', $currentHashType); $pb->assign('currentHashView', $hashView); $pb->assign('currentPage', (int) $currentPage); $pb->assign('maxPage', (int) $maxPage); $pb->assign('currentItemHash', $currentItemHash); $pb->assign('nbItems', $nbItems); $pb->assign('items', $listItems); if ($listFeeds == 'show') { $pb->assign('feedsView', $kf->getFeedsView()); } $pb->assign('pagetitle', strip_tags($kfc->title)); $pb->renderPage('index'); } else { $pb->assign('pagetitle', Intl::msg('Sign in') . ' - ' . strip_tags($kfc->title)); if (!empty($_SERVER['QUERY_STRING'])) { $pb->assign('referer', MyTool::getUrl() . '?' . $_SERVER['QUERY_STRING']); } $pb->assign('token', Session::getToken()); $pb->renderPage('login'); } }
public static function convertJsonToLeader($json) { $leader = new MaTeamLeader(); if (!self::fill($json, $leader, MyConst::FIELD_NAME)) { return false; } if (!self::fill($json, $leader, MyConst::FIELD_PIC)) { return false; } if (!self::fill($json, $leader, MyConst::FIELD_ROLE)) { return false; } if (!self::fill($json, $team, MyConst::FIELD_INTRO)) { return false; } $team->mtime = MyTool::now(); $team->ctime = $team->mtime; $team->deleted = 0; return $team; }
public function updateLeaderAction($teamId, $leaderId) { MyTool::simpleView($this); if (!MyTool::loginAuth($this)) { return $this->onError(MyConst::STATUS_NOT_LOGIN, 'must login first'); } $teamId = @intval($teamId); $team = TeamLogic::getTeam($teamId); if (empty($team)) { return MyTool::onExit($this, MyConst::STATUS_INVALID_TEAM, 'unknown team id'); } $uid = MyTool::getCookie($this, MyConst::COOKIE_UID); if ($team->owner != $uid) { return MyTool::onExit($this, MyConst::STATUS_NO_PERMISSION, 'no premission'); } if (empty($leader)) { return MyTool::onExit($this, MyConst::STATUS_INVALID_PARAM, 'invalid input'); } $leader = TeamLogic::getLeader($id); if (empty($leader)) { return MyTool::onExit($this, MyConst::STATUS_UNKNOWN_LEADER, 'unknown leader'); } if ($leader->tid != $teamId) { return MyTool::onExit($this, MyConst::STATUS_NO_PERMISSION, 'no permission'); } $body = $this->request->getJsonRawBody(); if (empty($body)) { return MyTool::onExit($this, MyConst::STATUS_INVALID_PARAM, 'mal-json input data'); } $leader2 = TeamLogic::convertJsonToLeader($body); if (empty($leader2)) { return MyTool::onExit($this, MyConst::STATUS_INVALID_PARAM, 'invalid input'); } if (MyTool::eq($leader->name, $leader2->name)) { $leader->name = $leader2->name; } if (MyTool::eq($leader->pic, $leader2->pic)) { $leader->pic = $leader2->pic; } if (MyTool::eq($leader->role, $leader2->role)) { $leader->role = $leader2->role; } if (MyTool::eq($leader->intro, $leader2->intro)) { $leader->intro = $leader2->intro; } $leader->mtime = $leader2->ctime; try { if (true !== $leader->update()) { return MyTool::onExit($this, MyConst::STATUS_ERROR, "update team leader failed"); } } catch (Exception $e) { return MyTool::onExit($this, MyConst::STATUS_ERROR, $e->getMessage()); } MyTool::setVar($this, MyConst::FIELD_STATUS, MyConst::STATUS_OK); return true; }
public static function convert($json) { $user = new MaUser(); // user name, required if (!isset($json->name)) { return false; } $user->name = @trim($json->name); if (empty($user->name)) { return false; } // user password, required if (!isset($json->password)) { return false; } $user->password = @trim($json->password); if (empty($user->password)) { return false; } // user phone number, required if (!isset($json->phone)) { return false; } $user->phone = @trim($json->phone); if (empty($user->phone)) { return false; } // user email, required if (!isset($json->email)) { return false; } $user->email = @trim($json->email); if (empty($user->email)) { return false; } // user company or school or institude, required if (!isset($json->email)) { return false; } $user->company = @trim($json->company); if (empty($user->company)) { return false; } // user job position or title, required if (!isset($json->job)) { return false; } $user->job = @trim($json->job); if (empty($user->job)) { return false; } // searchable or not $user->open = 0; if (isset($json->open)) { $user->open = @intval(@trim($json->open)); if ($user->open != 0) { $user->open = 1; } } else { $user->open = 0; } // user weibo account or uri, optional if (isset($json->weibo)) { $user->weibo = @trim($json->weibo); } // user weixin account or uri, required if (!isset($json->weixin)) { return false; } $user->weixin = @trim($json->weixin); if (empty($user->weixin)) { return false; } // user linkedin account or uri, required if (!isset($json->linkedin)) { return false; } $user->linkedin = @trim($json->linkedin); if (empty($user->linkedin)) { return false; } // user github account or uri, required if (isset($json->github)) { $user->github = @trim($json->github); } // user head pic uri, optional if (isset($json->pic)) { $user->pic = @trim($json->pic); } $user->mtime = MyTool::now(); $user->ctime = MyTool::now(); $user->status = 0; $user->deleted = 0; return $user; }
/** * Installation of the configuration file */ private function _install() { if (!empty($_POST['setlogin']) && !empty($_POST['setpassword'])) { $this->setSalt(sha1(uniqid('', true) . '_' . mt_rand())); $this->setLogin($_POST['setlogin']); $this->setHash($_POST['setpassword']); $this->write(); FeedPage::$pb->assign('pagetitle', 'KrISS feed installation'); FeedPage::$pb->assign('class', 'text-success'); FeedPage::$pb->assign('message', Intl::msg('Your simple and smart (or stupid) feed reader is now configured.')); FeedPage::$pb->assign('referer', MyTool::getUrl() . '?import'); FeedPage::$pb->assign('button', Intl::msg('Continue')); FeedPage::$pb->renderPage('message'); } else { FeedPage::$pb->assign('pagetitle', Intl::msg('KrISS feed installation')); FeedPage::$pb->assign('token', Session::getToken()); FeedPage::$pb->renderPage('install'); } exit; }
public static function onExit($controller, $status, $msg) { MyTool::setVar($controller, MyConst::FIELD_STATUS, $status); MyTool::setVar($controller, MyConst::FIELD_MESSAGE, $msg); return true; }
/** * Redirect depending on returnurl form or REFERER * * @param string $rurl Url to be redirected to */ public static function redirect($rurl = '') { if ($rurl === '') { // if (!empty($_SERVER['HTTP_REFERER']) && strcmp(parse_url($_SERVER['HTTP_REFERER'],PHP_URL_HOST),$_SERVER['SERVER_NAME'])==0) $rurl = empty($_SERVER['HTTP_REFERER']) ? '?' : $_SERVER['HTTP_REFERER']; if (isset($_POST['returnurl'])) { $rurl = $_POST['returnurl']; } } // prevent loop if (empty($rurl) || parse_url($rurl, PHP_URL_QUERY) === $_SERVER['QUERY_STRING']) { $rurl = MyTool::getUrl(); } if (substr($rurl, 0, 1) !== '?') { $ref = MyTool::getUrl(); if (substr($rurl, 0, strlen($ref)) !== $ref) { $rurl = $ref; } } header('Location: ' . $rurl); exit; }