public static function simpleAdd($logid, $type) { $attr = array('logid' => $logid, 'classify' => $type); $model = new Favorites(); $model->attributes = $attr; if ($model->save()) { return true; } else { return false; } }
public function testgetCurrentUserSidebarFavorites() { $favorites = new Favorites(); //test with empty string parameter $result = $favorites->getCurrentUserSidebarFavorites(); $this->assertTrue(is_array($result)); //test with string $result = $favorites->getCurrentUserSidebarFavorites('1'); $this->assertTrue(is_array($result)); }
public function actionSetFavorites($id) { $model = Favorites::model()->find(" user_id='" . Yii::app()->user->id . "' and obj_id='" . $id . "' and obj_type='0'"); if ($model) { $model->delete(); echo 'false'; } else { $model = New Favorites(); $model->user_id = Yii::app()->user->id; $model->obj_id = $id; $model->obj_type = 0; $model->save(); echo 'true'; } }
public function removeFavoriteBy(Users $user) { if ($user->hasFavoredThis($this)) { Favorites::query()->where('user_id = :user:'******'user' => $user->id])->andWhere('favoritable_type = :type:', ['type' => get_class($this)])->andWhere('favoritable_id = :id:', ['id' => $this->id])->execute()->delete(); } return $this; }
public function favorites() { if (null == $this->favorites) { $this->favorites = Favorites::query()->where('user_id = :user:'******'user' => $this->id])->leftJoin('Movies', 'Movies.id = Favorites.favoritable_id AND favoritable_type = "Movies"')->orderBy('created_at DESC')->columns(['Favorites.id', 'Favorites.user_id', 'Favorites.favoritable_id AS movie_id', 'Favorites.created_at AS created_at', 'Movies.title AS movie_title'])->execute(); } return $this->favorites; }
public static function sendUpdate($personId, $message) { // error_reporting(E_ALL); // ini_set('display_errors', '1'); $person = Person::getById($personId); $person = recast("Person", $person); $list = Favorites::getFavoritesByPerson($person->id); unset($to); foreach ($list as $individual) { $user = User::getUserById($individual->user_id); if (!empty($user->email) && $user->rights == "medium") { if (isset($to)) { $to .= ", " . $user->email; } else { $to = $user->email; } } # code... } $subject = "Update message for " . $person->displayName(); $from = "*****@*****.**"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From:" . $from; mail($to, $subject, $message, $headers); }
public function actionView() { $id = zmf::val('id', 2); if (!$id) { throw new CHttpException(404, 'The requested page does not exist.'); } $info = $this->loadModel($id); $pageSize = 30; $comments = Comments::getCommentsByPage($id, 'posts', 1, $pageSize); $tags = Tags::getByIds($info['tagids']); $relatePosts = Posts::getRelations($id, 5); if (!zmf::actionLimit('visit-Posts', $id, 5, 60)) { Posts::updateCount($id, 'Posts', 1, 'hits'); } $size = '600'; if ($this->isMobile) { $size = '640'; } $info['content'] = zmf::text(array(), $info['content'], true, $size); $data = array('info' => $info, 'comments' => $comments, 'tags' => $tags, 'relatePosts' => $relatePosts, 'loadMore' => count($comments) == $pageSize ? 1 : 0); $this->favorited = Favorites::checkFavored($id, 'post'); $this->pageTitle = $info['title']; $this->selectNav = 'posts'; $this->render('view', $data); }
function init() { parent::init(); $this->layout = '/layouts/user'; $this->currentModule = 'user'; if ($this->isMobile == 'yes') { $this->message(0, '感谢你的支持!本页面暂还在拼命制作中...'); } $this->uid = zmf::filterInput($_GET['id']); if (!$this->uid) { $this->uid = zmf::uid(); } if (!$this->uid) { $this->redirect(array('site/login')); } if ($this->uid == zmf::uid()) { $this->mySelf = 'yes'; } if ($this->mySelf != 'yes') { if (zmf::uid()) { $_favorinfo = Favorites::checkFavored($this->uid, 'user'); if ($_favorinfo) { $this->favored = true; } } } $this->userInfo = Users::getUserInfo($this->uid); if ($this->userInfo['tagids'] != '') { $this->userTags = Tags::getByIds($this->userInfo['tagids']); } $this->pageTitle = $this->userInfo['truename'] . ' - ' . zmf::config('sitename'); $this->pageDescription = $this->userInfo['truename'] . '的【' . zmf::config('sitename') . '】的个人主页,包括TA的原创文章、精美图片及各类悉心收藏,快来看看吧!'; }
public function __create($bookmarkurl, $title, $tokenval) { global $CFG, $DB; $response = new CliniqueServiceResponce(); $token_val = array('token' => $tokenval); $userId = array_values($DB->get_records_sql('SELECT userid FROM {external_tokens} et WHERE et.token=?', $token_val)); if ($userId) { $user_id = array('id' => $userId[0]->userid); //if(confirm_sesskey()){ $user = array_values($DB->get_records_sql('SELECT * FROM {user} u WHERE u.id=?', $user_id)); Favorites::__fav_user_login($user['0']); if (get_user_preferences('user_bookmarks')) { $bookmarks = explode(',', get_user_preferences('user_bookmarks')); if (in_array($bookmarkurl . ";" . $title, $bookmarks)) { $response->response(true, 'You have already bookmarked'); die; } } else { $bookmarks = array(); } //adds the bookmark at end of array $bookmarks[] = $bookmarkurl . ";" . $title; $bookmarks = implode(',', $bookmarks); //adds to preferences table set_user_preference('user_bookmarks', $bookmarks); global $CFG; //header("Location: " . $CFG->wwwroot . "/"); //print "Added Favourite Successfully"; $response->response(false, 'Added Favourite Successfully'); die; } else { $response->response(false, 'Invalid user'); die; } }
public function loadModel($id) { $model = Favorites::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested user does not exist.'); } return $model; }
public function proccess() { Phalanx::loadClasses('Favorites', 'Notification'); switch ($this->post->action) { case 'favorite': $n = new Notification(Notification::FAVORITED_A_POST, $this->session->user->id, $this->post->post_id); $status = Favorites::add($this->session->user->id, $this->post->post_id); break; case 'unfavorite': $status = Favorites::remove($this->session->user->id, $this->post->post_id); break; } header("Content-type: text/html; charset=utf-8"); $o = new stdClass(); $o->status = $status; die(json_encode($o)); }
public function __remove($bookmarkurl, $title, $tokenval) { global $CFG, $DB; $bookmarkurl = htmlspecialchars_decode($bookmarkurl); $title = htmlspecialchars_decode($title); $response = new CliniqueServiceResponce(); $token_val = array('token' => $tokenval); // Get user token /** * @get user id from external_tokens table * */ $userId = array_values($DB->get_records_sql('SELECT userid FROM {external_tokens} et WHERE et.token=?', $token_val)); if ($userId) { $user_id = array('id' => $userId[0]->userid); //if(confirm_sesskey()){ $user = array_values($DB->get_records_sql('SELECT * FROM {user} u WHERE u.id=?', $user_id)); Favorites::__fav_user_login($user['0']); $bookmarks = explode(',', get_user_preferences('user_bookmarks')); $bookmarkremoved = false; foreach ($bookmarks as $bookmark) { // check the bookmarkurl and title given values to delete from preference $tempBookmark = explode(';', $bookmark); if ($tempBookmark[0] == $bookmarkurl && $tempBookmark[1] == $title) { $keyToRemove = array_search($bookmark, $bookmarks); unset($bookmarks[$keyToRemove]); $bookmarkremoved = true; } } if ($bookmarkremoved == false) { $response->response(true, 'The bookmark you requested does not exist'); die; } $bookmarks = implode(',', $bookmarks); set_user_preference('user_bookmarks', $bookmarks); global $CFG; //header("Location: " . $CFG->wwwroot . $bookmarkurl); $response->response(false, 'Removed Favorite Successfully'); die; } else { $response->response(true, 'Invalid user'); die; } }
/** * Find all tasks in project, and prepare them for objects list * * @param Project $project * @param User $user * @param int $state * @return array */ static function findForObjectsList(Project $project, User $user, $state = STATE_VISIBLE) { $result = array(); $today = strtotime(date('Y-m-d')); $tasks = DB::execute("SELECT o.id, o.name,\r\n\t\t\t\t\t\to.category_id,\r\n\t\t\t\t\t\to.milestone_id,\r\n\t\t\t\t\t\to.completed_on,\r\n\t\t\t\t\t\to.integer_field_1 as task_id,\r\n\t\t\t\t\t\to.label_id,\r\n\t\t\t\t\t\to.assignee_id,\r\n\t\t\t\t\t\to.priority,\r\n\t\t\t\t\t\to.delegated_by_id,\r\n\t\t\t\t\t\to.state,\r\n\t\t\t\t\t\to.visibility,\r\n\t\t\t\t\t\to.created_on,\r\n\t\t\t\t\t\to.updated_on,\r\n\t\t\t\t\t\to.due_on,\r\n\t\t\t\t\t\trec.tracked_time\r\n\t\t\t\t\tFROM " . TABLE_PREFIX . "project_objects o \r\n\t\t\t\t\tLEFT JOIN (SELECT parent_id, sum(value) tracked_time FROM " . TABLE_PREFIX . "time_records WHERE state = ? GROUP BY(parent_id)) rec ON(o.id=rec.parent_id)\r\n\t\t\t\t\tWHERE o.type = 'Task' AND o.project_id = ? AND o.state = ? AND o.visibility >= ? ORDER BY o.id DESC", $state, $project->getId(), $state, $user->getMinVisibility()); if (is_foreachable($tasks)) { $task_url = Router::assemble('project_task', array('project_slug' => $project->getSlug(), 'task_id' => '--TASKID--')); $project_id = $project->getId(); $labels = Labels::getIdDetailsMap('AssignmentLabel'); foreach ($tasks as $task) { list($total_subtasks, $open_subtasks) = ProjectProgress::getObjectProgress(array('project_id' => $project_id, 'object_type' => 'Task', 'object_id' => $task['id'])); $taskObj = new Task($task['id']); $result[] = array('id' => $task['id'], 'name' => $task['name'], 'project_id' => $project_id, 'category_id' => $task['category_id'], 'milestone_id' => $task['milestone_id'], 'task_id' => $task['task_id'], 'is_completed' => $task['completed_on'] ? 1 : 0, 'permalink' => str_replace('--TASKID--', $task['task_id'], $task_url), 'label_id' => $task['label_id'], 'label' => $task['label_id'] ? $labels[$task['label_id']] : null, 'assignee_id' => $task['assignee_id'], 'priority' => $task['priority'], 'delegated_by_id' => $task['delegated_by_id'], 'total_subtasks' => $total_subtasks, 'open_subtasks' => $open_subtasks, 'estimated_time' => $taskObj->tracking()->canAdd($user) && $taskObj->tracking()->getEstimate() ? $taskObj->tracking()->getEstimate()->getValue() : 0, 'tracked_time' => $taskObj->tracking()->canAdd($user) ? $task['tracked_time'] : 0, 'is_favorite' => Favorites::isFavorite(array('Task', $task['id']), $user), 'is_archived' => $task['state'] == STATE_ARCHIVED ? 1 : 0, 'visibility' => $task['visibility'], 'created_on' => $task['created_on'] ? $task['created_on'] : $task['updated_on'], 'updated_on' => $task['updated_on'], 'has_attachments' => $taskObj->attachments()->has() ? true : false, 'due_on' => $task['due_on'] ? $task['due_on'] : lang('No due date set')); } // foreach } // if return $result; }
/** * @param $id */ public function allUserData($id, $mode = 'show') { if (!($user = User::find($id))) { abort(404); } $name = $user->full_name; if (!($fullProfile = Profile::where('user_id', '=', $id)->first())) { $fullProfile = new Profile(); } $cityLiving = $this->placeLiving($fullProfile->place_living_id); $cityFrom = $this->placeFrom($fullProfile->place_from_id); $languages_high = Language::where('profile_id', '=', $fullProfile->id)->where('level', '=', 'advanced')->get(); $languages_med = Language::where('profile_id', '=', $fullProfile->id)->where('level', '=', 'intermediate')->get(); $languages_low = Language::where('profile_id', '=', $fullProfile->id)->where('level', '=', 'basic')->get(); //Avatar is optional if ($user->avatar) { $avatar = $user->avatar; } if ($mode == 'show' || $mode == 'references') { $references = Reference::where('profile_user_id', '=', $id)->with(['user'])->orderBy('updated_at', 'DES')->get(); $age = $user->age; $owner = \Auth::id() == $id; $gender = $user->gender; $places = $user->placesWanted; $placesVisited = $user->placesVisited; $avg = Reference::where('profile_user_id', '=', $id)->avg('grade'); $ref = false; $fav = boolval(Favorites::where('owner_id', \Auth::id())->where('user_id', $id)->first()); if ($mode == 'references') { $ref = true; } return compact('fullProfile', 'references', 'name', 'avatar', 'ref', 'avg', 'cityFrom', 'cityLiving', 'age', 'gender', 'id', 'owner', 'fav', 'languages_high', 'languages_med', 'languages_low', 'places', 'placesVisited'); } else { if ($mode == 'edit') { return compact('fullProfile', 'cityFrom', 'cityLiving', 'name', 'avatar', 'id', 'languages_high', 'languages_med', 'languages_low'); } else { return abort(404); } } }
public function __favorites($tokenval) { global $CFG, $DB; $response = new CliniqueServiceResponce(); //$username = "******"; //$password = "******"; $token_val = array('token' => $tokenval); //$token_val = array('token'=>"64217bb7eea6f343a19f3af17104c49b"); $userId = array_values($DB->get_records_sql('SELECT userid FROM {external_tokens} et WHERE et.token=?', $token_val)); if ($userId) { $user_id = array('id' => $userId[0]->userid); //if(confirm_sesskey()){ $user = array_values($DB->get_records_sql('SELECT * FROM {user} u WHERE u.id=?', $user_id)); Favorites::__fav_user_login($user['0']); $favourites_user = get_user_preferences('user_bookmarks'); $favourites_user = explode(',', get_user_preferences('user_bookmarks')); /// Accessibility: markup as a list. $favBookmark = array(); $incr = 0; //print_r($favourites_user); foreach ($favourites_user as $favourite_bookmark) { //$favBookmark = explode(';', $favourite_bookmark); //echo json_encode($favBookmark); // return json format //$response->response(false, $favBookmark); $data = explode(';', $favourite_bookmark); $id = $data[0] ? $data[0] : null; $fileDetails = explode("@", $data[1]); $res[$incr]['url'] = $data[0]; $res[$incr]['id'] = $fileDetails[0] ? $fileDetails[0] : null; $res[$incr]['course_type'] = $fileDetails[1] ? $fileDetails[1] : null; $res[$incr]['file_name'] = $fileDetails[2] ? $fileDetails[2] : null; $res[$incr]['file_type'] = $fileDetails[3] ? $fileDetails[3] : null; $res[$incr]['fname_upload'] = $fileDetails[4] ? $fileDetails[4] : null; $incr++; } $response->response(false, 'success', $res); } else { $response->response(true, 'Invalid user'); } }
private static function getFavouties($userid) { global $DB; $user = $DB->get_record('user', array('id' => $userid)); Favorites::__fav_user_login($user); $favourites_user = get_user_preferences('user_bookmarks'); $favourites_user = explode(',', get_user_preferences('user_bookmarks')); $favBookmark = array(); $incr = 0; foreach ($favourites_user as $favourite_bookmark) { $data = explode(';', $favourite_bookmark); $id = $data[0] ? $data[0] : null; $fileDetails = explode("@", $data[1]); if ($fileDetails[0]) { $getModInfo = $DB->get_record('course_modules', array('id' => $fileDetails[0])); } else { $getModInfo = ''; } if ($getModInfo) { $res[$incr]['url'] = $data[0]; $res[$incr]['id'] = $fileDetails[0] ? $fileDetails[0] : null; $res[$incr]['course_type'] = $fileDetails[1] ? $fileDetails[1] : null; $res[$incr]['file_name'] = $fileDetails[2] ? $fileDetails[2] : null; $res[$incr]['file_type'] = $fileDetails[3] ? $fileDetails[3] : null; $res[$incr]['fname_upload'] = $fileDetails[4] ? $fileDetails[4] : null; $incr++; } } if ($incr == 0) { $res[$incr]['url'] = ""; $res[$incr]['id'] = null; $res[$incr]['course_type'] = null; $res[$incr]['file_name'] = null; $res[$incr]['file_type'] = null; $res[$incr]['fname_upload'] = null; } return $res; }
private function MyFavorites(stdClass $config) { Phalanx::loadClasses('Favorites'); return Favorites::from_user($this->session->user->id, $config); }
<?php $favorited = false; if (Favorites::checkFavored($keyid, $type)) { $css = "favorited"; $title = zmf::t('cancelFavorite'); $favorited = true; } else { $css = ""; $title = zmf::t('favorite'); } echo CHtml::link('<span class="icon-thumbs-up"></span> 赞', 'javascript:;', array('class' => 'btn btn-xs btn-' . ($_favored ? 'success' : 'default'), 'action' => 'favor', 'action-data' => $keyid, 'action-type' => 'posts', 'id' => 'favor-posts-' . $keyid)); echo CHtml::link('<span class="icon-heart"></span> 收藏', 'javascript:;', array('class' => 'btn btn-xs btn-' . ($favorited ? 'danger' : 'default'), 'action' => 'favorite', 'action-data' => $keyid, 'action-type' => 'posts'));
/** * 统计用户的内容数 */ public static function getCounts($uid, $info = '') { if (!$uid) { return array(); } if ($info) { if (zmf::now() - $info['last_update'] <= 3600) { $data = array('posts' => $info['posts'], 'answers' => $info['answers'], 'tips' => $info['tips']); return $data; } } $data = array('posts' => Posts::model()->count('uid=:uid AND status=' . Posts::STATUS_PASSED, array(':uid' => $uid)), 'answers' => Answer::model()->count('uid=:uid AND status=' . Posts::STATUS_PASSED, array(':uid' => $uid)), 'tips' => PoiPost::model()->count('uid=:uid AND status=' . Posts::STATUS_PASSED, array(':uid' => $uid)), 'favors' => Favorites::model()->count('uid=:uid AND classify="user"', array(':uid' => $uid)), 'fans' => Favorites::model()->count('logid=:uid AND classify="user"', array(':uid' => $uid))); //将统计数据更新到用户统计表 $data['last_update'] = zmf::now(); Users::model()->updateByPk($uid, $data); return $data; }
if ($action == 'family') { $id = getRequest("id"); if ($id) { $session->save("indvidual_id", $id); $session->save("content", "people/family/familychart.php"); include_page('home.php'); } exit; } if ($action == 'add_to_favorites') { $user = User::current_user(); $user = recast('User', $user); $id = getRequest('id'); $check = Favorites::getFavorites($user->id, $id); if (!$check) { $temp = new Favorites(); $temp->id = null; $temp->user_id = $user->id; $temp->person_id = $id; $result = $temp->save(); if ($result) { echo "Success"; exit; } else { echo "Failure"; exit; } } else { echo "That person was already favorited"; } exit;
function to_favorites() { $id = get_post_value('id'); $m = new Favorites(); $data = $m->cartToFavorites($id); $this->assign('message', '1'); $this->setReturnType('message'); }
function saveTags($tag, $table, $id, $group, $personId, $type, $link) { $database = cbSQLConnect::connect('object'); if (isset($database)) { $fields = array(); $fields['name'] = $tag; $fields['ftable'] = $table; $fields['fid'] = $id; $fields['category'] = $group; $fields['personid'] = $personId > 0 ? $personId : -1; $fields['type'] = $type; // return data // return $fields; $insert = $database->SQLInsert($fields, "tags"); // return true if sucess or false if ($insert && $personId > 0) { $person = Person::getById($personId); $person = recast("Person", $person); $message = ' <html> <head> <title>Recent upload to a person on your watch list.</title> </head> <body> <p>Something has been uploaded for ' . $person->displayName() . '</p> <p>Click <a href="' . $link . '">HERE</a> to view the new document, or go to their page to view new content <a href="/?controller=individual&action=homepage&id=' . $person->id . '">HERE</a></p> <br/> <p>Thank you for your continued membership!</p> <br/> <p>Sincerely</p> <p>-The Familyhistorydatabase crew</p> </body> </html> '; Favorites::sendUpdate($personId, $message); return $insert; } else { return "Insert didn't compute"; } } }
public static function build_from_list($uid, $list_id, stdClass $config) { Phalanx::loadClasses('Friendship'); $friends_ids = Friendship::get_friend_array($uid); $friends_ids = implode(', ', $friends_ids); $where = ""; if (property_exists($config, 'min')) { $where .= " AND p.id < '{$config->min}'"; } if (property_exists($config, 'max')) { $where .= " AND p.id < '{$config->max}'"; } Phalanx::loadClasses('Lists', 'SocialNetwork', 'Facebook', 'Twitter', 'twitteroauth', 'Instagram', 'PostCategory', 'Favorites', 'Profile'); $list = Lists::from_user($uid, $list_id); $categories = array(); foreach ($list->categories as $category) { $categories[] = $category->id; } if (sizeof($categories) > 0) { Phalanx::loadClasses('Posts', 'PostComments'); $categories_ids = implode("', '", $categories); $custom_tl = array(); $m = Model::Factory('posts p', false, 0); $m->fields('DISTINCT p.id AS id', 'p.original_posts_id AS original_id', 'p.user_id AS user_id', 'p.content AS content', 'p.date AS date', 'p.title AS title', 'p.promoted AS promoted', 'u.name AS name', 'u.login AS user', 'ud.avatar AS avatar', 'p.like_count AS likes', 'p.dislike_count AS dislikes', 'p.comment_count AS comments', 'p.reblog_count AS reblogs', 'p.reply_count AS replies'); $m->innerJoin('user u', 'u.id = p.user_id'); $m->innerJoin('user_data ud', 'ud.user_id = p.user_id'); $m->innerJoin('posts_has_category phc', 'p.id = phc.posts_id'); $m->where("p.user_id IN({$friends_ids}) AND phc.category_id IN ('{$categories_ids}') {$where} AND u.banned IS NULL AND p.status=1 AND p.date > DATE_SUB(NOW(), INTERVAL 1 MONTH)"); # $m->group("p.original_posts_id"); $m->order('p.id DESC'); $m->limit(NUMBER_OF_POSTS_LOADED_PER_TIME); $skynerd_posts = $m->all(); foreach ($skynerd_posts as $each) { $o = new stdClass(); $o->date = Date::RelativeTime($each->date); $o->id = $each->id; $o->user = $each->user; $o->name = $each->name; $o->title = $each->title; $o->avatar = $each->avatar; $o->user_id = $each->user_id; $o->rating = new stdClass(); $o->rating->megaboga = $each->likes; $o->rating->whatever = $each->dislikes; $o->my_rating = Posts::userRating($uid, $each->id); $o->content = trim($each->content); $o->comments = $v->comments; $o->replies = $v->replies; $o->categories = PostCategory::from_post($each->id); $o->is_reblogged = Posts::userHasReblogged($each->id, $uid); $o->is_favorite = Favorites::is_favorite($uid, $each->id); $o->user_points = Profile::experience($v->user_id); $o->promoted = (bool) $each->promoted; if (!empty($o->original_id)) { //Se o post for um reblog, então o conteúdo dele deve ser o do reblogado, mostrando as ações $originalPost = Posts::from_user(false, $o->original_id); $originalPost = reset($originalPost); $o->content = $originalPost->content; $o->title = $originalPost->title; $o->reblogged_from = $originalPost->user; $o->original_date = $originalPost->date; $o->rating->reblog_count = $originalPost->rating->reblog_count; $o->is_reblogged = Posts::userHasReblogged($originalPost->id, $uid); } $custom_tl[] = $o; } } return $custom_tl; }
public function actionAdd_favorites() { $request = Yii::app()->request; if ($request->isAjaxRequest && !Yii::app()->user->isGuest) { $model = new Favorites(); $model->mid = (int) $_POST['id']; $model->mtitle = $_POST['title']; $model->murl = $_POST['url']; $model->module = $_POST['module']; $model->user_id = Yii::app()->user->getId(); $model->save(); $this->widget('ext.favorites.FavoritesWidget', array('id' => (int) $_POST['id'], 'url' => $_POST['url'], 'title' => $_POST['title'], 'module' => $module, 'view' => false)); } }
private function __favorites() { require_once 'favorites.php'; $tokenval = required_param('token', PARAM_RAW_TRIMMED); Favorites::__favorites($tokenval); }
/** * Displays the header on section of the page; basically everything before the content */ public function displayHeader($retModTabs = false) { global $theme; global $max_tabs; global $app_strings; global $current_user; global $sugar_config; global $app_list_strings; global $mod_strings; global $current_language; $GLOBALS['app']->headerDisplayed = true; $themeObject = SugarThemeRegistry::current(); $theme = $themeObject->__toString(); $ss = new Sugar_Smarty(); $ss->assign("APP", $app_strings); $ss->assign("THEME", $theme); $ss->assign("THEME_CONFIG", $themeObject->getConfig()); $ss->assign("THEME_IE6COMPAT", $themeObject->ie6compat ? 'true' : 'false'); $ss->assign("MODULE_NAME", $this->module); $ss->assign("langHeader", get_language_header()); // set ab testing if exists $testing = isset($_REQUEST["testing"]) ? $_REQUEST['testing'] : "a"; $ss->assign("ABTESTING", $testing); // get browser title $ss->assign("SYSTEM_NAME", $this->getBrowserTitle()); // get css $css = $themeObject->getCSS(); if ($this->_getOption('view_print')) { $css .= '<link rel="stylesheet" type="text/css" href="' . $themeObject->getCSSURL('print.css') . '" media="all" />'; } $ss->assign("SUGAR_CSS", $css); // get javascript ob_start(); $this->renderJavascript(); $ss->assign("SUGAR_JS", ob_get_contents() . $themeObject->getJS()); ob_end_clean(); // get favicon if (isset($GLOBALS['sugar_config']['default_module_favicon'])) { $module_favicon = $GLOBALS['sugar_config']['default_module_favicon']; } else { $module_favicon = false; } $favicon = $this->getFavicon(); $ss->assign('FAVICON_URL', $favicon['url']); // build the shortcut menu $shortcut_menu = array(); foreach ($this->getMenu() as $key => $menu_item) { $shortcut_menu[$key] = array("URL" => $menu_item[0], "LABEL" => $menu_item[1], "MODULE_NAME" => $menu_item[2], "IMAGE" => $themeObject->getImage($menu_item[2], "border='0' align='absmiddle'", null, null, '.gif', $menu_item[1])); } $ss->assign("SHORTCUT_MENU", $shortcut_menu); // handle rtl text direction if (isset($_REQUEST['RTL']) && $_REQUEST['RTL'] == 'RTL') { $_SESSION['RTL'] = true; } if (isset($_REQUEST['LTR']) && $_REQUEST['LTR'] == 'LTR') { unset($_SESSION['RTL']); } if (isset($_SESSION['RTL']) && $_SESSION['RTL']) { $ss->assign("DIR", 'dir="RTL"'); } // handle resizing of the company logo correctly on the fly $companyLogoURL = $themeObject->getImageURL('company_logo.png'); $companyLogoURL_arr = explode('?', $companyLogoURL); $companyLogoURL = $companyLogoURL_arr[0]; $company_logo_attributes = sugar_cache_retrieve('company_logo_attributes'); if (!empty($company_logo_attributes)) { $ss->assign("COMPANY_LOGO_MD5", $company_logo_attributes[0]); $ss->assign("COMPANY_LOGO_WIDTH", $company_logo_attributes[1]); $ss->assign("COMPANY_LOGO_HEIGHT", $company_logo_attributes[2]); } else { // Always need to md5 the file $ss->assign("COMPANY_LOGO_MD5", md5_file($companyLogoURL)); list($width, $height) = getimagesize($companyLogoURL); if ($width > 212 || $height > 40) { $resizePctWidth = ($width - 212) / 212; $resizePctHeight = ($height - 40) / 40; if ($resizePctWidth > $resizePctHeight) { $resizeAmount = $width / 212; } else { $resizeAmount = $height / 40; } $ss->assign("COMPANY_LOGO_WIDTH", round($width * (1 / $resizeAmount))); $ss->assign("COMPANY_LOGO_HEIGHT", round($height * (1 / $resizeAmount))); } else { $ss->assign("COMPANY_LOGO_WIDTH", $width); $ss->assign("COMPANY_LOGO_HEIGHT", $height); } // Let's cache the results sugar_cache_put('company_logo_attributes', array($ss->get_template_vars("COMPANY_LOGO_MD5"), $ss->get_template_vars("COMPANY_LOGO_WIDTH"), $ss->get_template_vars("COMPANY_LOGO_HEIGHT"))); } $ss->assign("COMPANY_LOGO_URL", getJSPath($companyLogoURL) . "&logo_md5=" . $ss->get_template_vars("COMPANY_LOGO_MD5")); // get the global links $gcls = array(); $global_control_links = array(); require "include/globalControlLinks.php"; foreach ($global_control_links as $key => $value) { if ($key == 'users') { //represents logout link. $ss->assign("LOGOUT_LINK", $value['linkinfo'][key($value['linkinfo'])]); $ss->assign("LOGOUT_LABEL", key($value['linkinfo'])); //key value for first element. continue; } foreach ($value as $linkattribute => $attributevalue) { // get the main link info if ($linkattribute == 'linkinfo') { $gcls[$key] = array("LABEL" => key($attributevalue), "URL" => current($attributevalue), "SUBMENU" => array()); if (substr($gcls[$key]["URL"], 0, 11) == "javascript:") { $gcls[$key]["ONCLICK"] = substr($gcls[$key]["URL"], 11); $gcls[$key]["URL"] = "javascript:void(0)"; } } // and now the sublinks if ($linkattribute == 'submenu' && is_array($attributevalue)) { foreach ($attributevalue as $submenulinkkey => $submenulinkinfo) { $gcls[$key]['SUBMENU'][$submenulinkkey] = array("LABEL" => key($submenulinkinfo), "URL" => current($submenulinkinfo)); } if (substr($gcls[$key]['SUBMENU'][$submenulinkkey]["URL"], 0, 11) == "javascript:") { $gcls[$key]['SUBMENU'][$submenulinkkey]["ONCLICK"] = substr($gcls[$key]['SUBMENU'][$submenulinkkey]["URL"], 11); $gcls[$key]['SUBMENU'][$submenulinkkey]["URL"] = "javascript:void(0)"; } } } } $ss->assign("GCLS", $gcls); $ss->assign("SEARCH", isset($_REQUEST['query_string']) ? $_REQUEST['query_string'] : ''); if ($this->action == "EditView" || $this->action == "Login") { $ss->assign("ONLOAD", 'onload="set_focus()"'); } $ss->assign("AUTHENTICATED", isset($_SESSION["authenticated_user_id"])); // get other things needed for page style popup if (isset($_SESSION["authenticated_user_id"])) { // get the current user name and id $ss->assign("CURRENT_USER", $current_user->full_name == '' || !showFullName() ? $current_user->user_name : $current_user->full_name); $ss->assign("CURRENT_USER_ID", $current_user->id); // get the last viewed records require_once "modules/Favorites/Favorites.php"; $favorites = new Favorites(); $favorite_records = $favorites->getCurrentUserSidebarFavorites(); $ss->assign("favoriteRecords", $favorite_records); $tracker = new Tracker(); $history = $tracker->get_recently_viewed($current_user->id); $ss->assign("recentRecords", $this->processRecentRecords($history)); } $bakModStrings = $mod_strings; if (isset($_SESSION["authenticated_user_id"])) { // get the module list $moduleTopMenu = array(); $max_tabs = $current_user->getPreference('max_tabs'); // Attempt to correct if max tabs count is extremely high. if (!isset($max_tabs) || $max_tabs <= 0 || $max_tabs > 10) { $max_tabs = $GLOBALS['sugar_config']['default_max_tabs']; $current_user->setPreference('max_tabs', $max_tabs, 0, 'global'); } $moduleTab = $this->_getModuleTab(); $ss->assign('MODULE_TAB', $moduleTab); // See if they are using grouped tabs or not (removed in 6.0, returned in 6.1) $user_navigation_paradigm = $current_user->getPreference('navigation_paradigm'); if (!isset($user_navigation_paradigm)) { $user_navigation_paradigm = $GLOBALS['sugar_config']['default_navigation_paradigm']; } // Get the full module list for later use foreach (query_module_access_list($current_user) as $module) { // Bug 25948 - Check for the module being in the moduleList if (isset($app_list_strings['moduleList'][$module])) { $fullModuleList[$module] = $app_list_strings['moduleList'][$module]; } } if (!should_hide_iframes()) { $iFrame = new iFrame(); $frames = $iFrame->lookup_frames('tab'); foreach ($frames as $key => $values) { $fullModuleList[$key] = $values; } } elseif (isset($fullModuleList['iFrames'])) { unset($fullModuleList['iFrames']); } if ($user_navigation_paradigm == 'gm' && isset($themeObject->group_tabs) && $themeObject->group_tabs) { // We are using grouped tabs require_once 'include/GroupedTabs/GroupedTabStructure.php'; $groupedTabsClass = new GroupedTabStructure(); $modules = query_module_access_list($current_user); //handle with submoremodules $max_tabs = $current_user->getPreference('max_tabs'); // If the max_tabs isn't set incorrectly, set it within the range, to the default max sub tabs size if (!isset($max_tabs) || $max_tabs <= 0 || $max_tabs > 10) { // We have a default value. Use it if (isset($GLOBALS['sugar_config']['default_max_tabs'])) { $max_tabs = $GLOBALS['sugar_config']['default_max_tabs']; } else { $max_tabs = 8; } } $subMoreModules = false; $groupTabs = $groupedTabsClass->get_tab_structure(get_val_array($modules)); // We need to put this here, so the "All" group is valid for the user's preference. $groupTabs[$app_strings['LBL_TABGROUP_ALL']]['modules'] = $fullModuleList; // Setup the default group tab. $allGroup = $app_strings['LBL_TABGROUP_ALL']; $ss->assign('currentGroupTab', $allGroup); $currentGroupTab = $allGroup; $usersGroup = $current_user->getPreference('theme_current_group'); // Figure out which tab they currently have selected (stored as a user preference) if (!empty($usersGroup) && isset($groupTabs[$usersGroup])) { $currentGroupTab = $usersGroup; } else { $current_user->setPreference('theme_current_group', $currentGroupTab); } $ss->assign('currentGroupTab', $currentGroupTab); $usingGroupTabs = true; } else { // Setup the default group tab. $ss->assign('currentGroupTab', $app_strings['LBL_TABGROUP_ALL']); $usingGroupTabs = false; $groupTabs[$app_strings['LBL_TABGROUP_ALL']]['modules'] = $fullModuleList; } $topTabList = array(); // Now time to go through each of the tab sets and fix them up. foreach ($groupTabs as $tabIdx => $tabData) { $topTabs = $tabData['modules']; if (!is_array($topTabs)) { $topTabs = array(); } $extraTabs = array(); // Split it in to the tabs that go across the top, and the ones that are on the extra menu. if (count($topTabs) > $max_tabs) { $extraTabs = array_splice($topTabs, $max_tabs); } // Make sure the current module is accessable through one of the top tabs if (!isset($topTabs[$moduleTab])) { // Nope, we need to add it. // First, take it out of the extra menu, if it's there if (isset($extraTabs[$moduleTab])) { unset($extraTabs[$moduleTab]); } if (count($topTabs) >= $max_tabs - 1) { // We already have the maximum number of tabs, so we need to shuffle the last one // from the top to the first one of the extras $lastElem = array_splice($topTabs, $max_tabs - 1); $extraTabs = $lastElem + $extraTabs; } if (!empty($moduleTab)) { $topTabs[$moduleTab] = $app_list_strings['moduleList'][$moduleTab]; } } /* // This was removed, but I like the idea, so I left the code in here in case we decide to turn it back on // If we are using group tabs, add all the "hidden" tabs to the end of the extra menu if ( $usingGroupTabs ) { foreach($fullModuleList as $moduleKey => $module ) { if ( !isset($topTabs[$moduleKey]) && !isset($extraTabs[$moduleKey]) ) { $extraTabs[$moduleKey] = $module; } } } */ // Get a unique list of the top tabs so we can build the popup menus for them foreach ($topTabs as $moduleKey => $module) { $topTabList[$moduleKey] = $module; } $groupTabs[$tabIdx]['modules'] = $topTabs; $groupTabs[$tabIdx]['extra'] = $extraTabs; } } if (isset($topTabList) && is_array($topTabList)) { // Adding shortcuts array to menu array for displaying shortcuts associated with each module $shortcutTopMenu = array(); foreach ($topTabList as $module_key => $label) { global $mod_strings; $mod_strings = return_module_language($current_language, $module_key); foreach ($this->getMenu($module_key) as $key => $menu_item) { $shortcutTopMenu[$module_key][$key] = array("URL" => $menu_item[0], "LABEL" => $menu_item[1], "MODULE_NAME" => $menu_item[2], "IMAGE" => $themeObject->getImage($menu_item[2], "border='0' align='absmiddle'", null, null, '.gif', $menu_item[1]), "ID" => $menu_item[2] . "_link"); } } if (!empty($sugar_config['lock_homepage']) && $sugar_config['lock_homepage'] == true) { $ss->assign('lock_homepage', true); } $ss->assign("groupTabs", $groupTabs); $ss->assign("shortcutTopMenu", $shortcutTopMenu); $ss->assign('USE_GROUP_TABS', $usingGroupTabs); // This is here for backwards compatibility, someday, somewhere, it will be able to be removed $ss->assign("moduleTopMenu", $groupTabs[$app_strings['LBL_TABGROUP_ALL']]['modules']); $ss->assign("moduleExtraMenu", $groupTabs[$app_strings['LBL_TABGROUP_ALL']]['extra']); } if (isset($extraTabs) && is_array($extraTabs)) { // Adding shortcuts array to extra menu array for displaying shortcuts associated with each module $shortcutExtraMenu = array(); foreach ($extraTabs as $module_key => $label) { global $mod_strings; $mod_strings = return_module_language($current_language, $module_key); foreach ($this->getMenu($module_key) as $key => $menu_item) { $shortcutExtraMenu[$module_key][$key] = array("URL" => $menu_item[0], "LABEL" => $menu_item[1], "MODULE_NAME" => $menu_item[2], "IMAGE" => $themeObject->getImage($menu_item[2], "border='0' align='absmiddle'", null, null, '.gif', $menu_item[1]), "ID" => $menu_item[2] . "_link"); } } $ss->assign("shortcutExtraMenu", $shortcutExtraMenu); } if (!empty($current_user)) { $ss->assign("max_tabs", $current_user->getPreference("max_tabs")); } $imageURL = SugarThemeRegistry::current()->getImageURL("dashboard.png"); $homeImage = "<img src='{$imageURL}'>"; $ss->assign("homeImage", $homeImage); global $mod_strings; $mod_strings = $bakModStrings; $headerTpl = $themeObject->getTemplate('header.tpl'); if (inDeveloperMode()) { $ss->clear_compiled_tpl($headerTpl); } if ($retModTabs) { return $ss->fetch($themeObject->getTemplate('_headerModuleList.tpl')); } else { $ss->display($headerTpl); $this->includeClassicFile('modules/Administration/DisplayWarnings.php'); $errorMessages = SugarApplication::getErrorMessages(); if (!empty($errorMessages)) { foreach ($errorMessages as $error_message) { echo '<p class="error">' . $error_message . '</p>'; } } } }
public function action_get_sidebar_elements() { $favourite_class = new Favorites(); $return = $favourite_class->getCurrentUserSidebarFavorites($_REQUEST['record_id']); echo json_encode($return); }
public static function favorite($code, $type, $from = 'web', $uid = '') { if (!$code || !$type) { return array('status' => 0, 'msg' => '数据不全,请核实'); } if (!in_array($type, array('post'))) { return array('status' => 0, 'msg' => '暂不允许的分类'); } if (is_numeric($code)) { $id = $code; } else { $codeArr = Posts::decode($code); if ($codeArr['type'] != $type || !is_numeric($codeArr['id']) || $codeArr['id'] < 1) { $this->jsonOutPut(0, '您所查看的内容不存在'); } $id = $codeArr['id']; } if (!$uid) { $uid = zmf::uid(); } if ($uid) { if (zmf::actionLimit('favorite-' . $type, $id)) { return array('status' => 0, 'msg' => '操作太频繁,请稍后再试'); } } else { //没有登录的访客点收藏时判断是否已收藏过 if (zmf::actionLimit('favorite-' . $type, $id, 1, 86400, true)) { return array('status' => 1, 'msg' => '已点赞', 'state' => 1); } $uid = 0; } $postInfo = Posts::model()->findByPk($id); if (!$postInfo || $postInfo['status'] != Posts::STATUS_PASSED) { return array('status' => 0, 'msg' => '文章不存在'); } $attr = array('uid' => $uid, 'logid' => $id, 'classify' => $type); $info = false; if ($uid) { $info = Favorites::model()->findByAttributes($attr); } if ($info) { if (Favorites::model()->deleteByPk($info['id'])) { if ($type == 'post') { Posts::updateCount($id, 'Posts', -1, 'favorite'); } return array('status' => 1, 'msg' => '取消点赞', 'state' => 3); } else { return array('status' => 0, 'msg' => '取消点赞失败', 'state' => 4); } } else { $attr['cTime'] = zmf::now(); $model = new Favorites(); $model->attributes = $attr; if ($model->save()) { if ($type == 'post') { Posts::updateCount($id, 'Posts', 1, 'favorite'); } //点赞后给对方发提醒 $_noticedata = array('uid' => $postInfo['uid'], 'authorid' => $uid, 'content' => "您的文章【{$postInfo['title']}】有了新的赞", 'new' => 1, 'type' => 'favorite', 'cTime' => zmf::now(), 'from_id' => $model->id, 'from_num' => 1); Notification::add($_noticedata); return array('status' => 1, 'msg' => '点赞成功', 'state' => 1); } else { return array('status' => 0, 'msg' => '点赞失败', 'state' => 2); } } }
public function __favorites($tokenval) { global $CFG, $DB; $response = new CliniqueServiceResponce(); //$username = "******"; //$password = "******"; $token_val = array('token' => $tokenval); //$token_val = array('token'=>"64217bb7eea6f343a19f3af17104c49b"); $userId = array_values($DB->get_records_sql('SELECT userid FROM {external_tokens} et WHERE et.token=?', $token_val)); if ($userId) { $user_id = array('id' => $userId[0]->userid); //if(confirm_sesskey()){ $user = array_values($DB->get_records_sql('SELECT * FROM {user} u WHERE u.id=?', $user_id)); Favorites::__fav_user_login($user['0']); $favourites_user = get_user_preferences('user_bookmarks'); $favourites_user = explode(',', get_user_preferences('user_bookmarks')); /// Accessibility: markup as a list. $favBookmark = array(); $incr = 0; //print_r($favourites_user); foreach ($favourites_user as $favourite_bookmark) { //$favBookmark = explode(';', $favourite_bookmark); //echo json_encode($favBookmark); // return json format //$response->response(false, $favBookmark); $data = explode(';', $favourite_bookmark); $id = $data[0] ? $data[0] : null; $fileDetails = explode("@", $data[1]); if ($fileDetails[0]) { $getModInfo = $DB->get_record('course_modules', array('id' => $fileDetails[0])); } else { $getModInfo = ''; } if ($getModInfo) { $res[$incr]['url'] = $data[0]; $res[$incr]['id'] = $fileDetails[0] ? $fileDetails[0] : null; $res[$incr]['course_type'] = $fileDetails[1] ? $fileDetails[1] : null; $res[$incr]['file_name'] = $fileDetails[2] ? $fileDetails[2] : null; $res[$incr]['file_type'] = $fileDetails[3] ? $fileDetails[3] : null; $res[$incr]['fname_upload'] = $fileDetails[4] ? $fileDetails[4] : null; $incr++; } } if ($incr == 0) { $res[$incr]['url'] = ""; $res[$incr]['id'] = null; $res[$incr]['course_type'] = null; $res[$incr]['file_name'] = null; $res[$incr]['file_type'] = null; $res[$incr]['fname_upload'] = null; } $fav_comment_count_sql = 'SELECT COUNT(urc.id) AS comment_count FROM mdl_user_resource_comments urc JOIN mdl_course_modules cm ON cm.id = urc.coursemoduleid JOIN mdl_course c ON cm.course = c.id JOIN mdl_resource r ON cm.instance = r.id WHERE urc.userid = ' . $user_id['id']; $comments_count = current($DB->get_records_sql($fav_comment_count_sql)); $res['resource_comment_count'] = $comments_count->comment_count; $response->response(false, 'success', $res); } else { $response->response(true, 'Invalid user'); } }
public function remove_favorite($bean) { $favorites_class = new Favorites(); $favorite_id = $favorites_class->getFavoriteID($bean->module_dir, $bean->id); if ($favorite_id) { $deleted = $favorites_class->deleteFavorite($favorite_id); return $deleted; } else { return false; } }