function get_like_display($user_id) { $favorite_post_ids = get_user_favorites($user_id); if (isset($favorite_post_ids[0]['posts'])) { return; } $post_ids = implode(',', $favorite_post_ids); the_widget('music_post_widget', array('count' => -1, 'include' => $post_ids, 'display' => 'list'), array()); }
die; } $title = esc_html(sprintf(__('%1$s » Topic: %2$s'), bb_get_option('name'), get_topic_title())); $link = get_topic_link($feed_id); $link_self = get_topic_rss_link($feed_id); break; case 'profile': if (bb_get_option('mod_rewrite') === 'slugs') { $user = bb_get_user_by_nicename($feed_id); } else { $user = bb_get_user($feed_id); } if (!$user) { die; } if (!($posts = get_user_favorites($user->ID))) { die; } $title = esc_html(sprintf(__('%1$s » User Favorites: %2$s'), bb_get_option('name'), $user->user_login)); $link = bb_get_profile_link($feed_id); $link_self = get_favorites_rss_link($feed_id); break; case 'tag-topics': if (!($tag = bb_get_tag($feed_id))) { die; } if (!($topics = get_tagged_topics(array('tag_id' => $tag->tag_id, 'page' => 0)))) { die; } $posts = array(); foreach ($topics as $topic) {
/** * Get all user favourites * * @param string $shortname shortname of the favourites * @return array An array describing favourites */ public static function get_all_favourites($shortname) { global $WEBSERVICE_INSTITUTION, $WEBSERVICE_OAUTH_USER; $params = self::validate_parameters(self::get_all_favourites_parameters(), array('shortname' => $shortname)); $dbfavourites = get_records_sql_array('SELECT * from {favorite} WHERE shortname = ? AND institution = ?', array($shortname, $WEBSERVICE_INSTITUTION)); if (empty($dbfavourites)) { throw new WebserviceInvalidParameterException('get_favourites | ' . get_string('invalidfavourite', 'auth.webservice', $shortname . '/' . $WEBSERVICE_INSTITUTION)); } $result = array(); foreach ($dbfavourites as $dbfavourite) { $dbuser = get_record('usr', 'id', $dbfavourite->owner, 'deleted', 0); if (empty($dbuser)) { continue; } $favourites = get_user_favorites($dbuser->id, 100); $favs = array(); if (!empty($favourites)) { foreach ($favourites as $fav) { $dbfavuser = get_record('usr', 'id', $fav->id, 'deleted', 0); $favs[] = array('id' => $fav->id, 'username' => $dbfavuser->username); } } $result[] = array('id' => $dbuser->id, 'username' => $dbuser->username, 'shortname' => $dbfavourite->shortname, 'institution' => $dbfavourite->institution, 'favourites' => $favs); } return $result; }
$link_self = get_topic_rss_link($feed_id); break; case 'profile': if (bb_get_option('mod_rewrite') === 'slugs') { if (!($user = bb_get_user_by_nicename($feed_id))) { $user = bb_get_user($feed_id); } } else { if (!($user = bb_get_user($feed_id))) { $user = bb_get_user_by_nicename($feed_id); } } if (!$user) { die; } $posts = get_user_favorites($user->ID); $title = sprintf(__('%1$s » User Favorites: %2$s'), bb_get_option('name'), $user->user_nicename); $link = get_user_profile_link($feed_id); $link_self = get_favorites_rss_link($feed_id); break; case 'tag-topics': if (!($tag = bb_get_tag($feed_id))) { die; } $topics = get_tagged_topics(array('tag_id' => $tag->tag_id, 'page' => 0)); $posts = array(); foreach ((array) $topics as $topic) { $posts[] = bb_get_first_post($topic->topic_id); } $title = sprintf(__('%1$s » Tag: %2$s - Recent Topics'), bb_get_option('name'), bb_get_tag_name()); $link = bb_get_tag_link($feed_id);
function mahara_user_update_favourites($client) { //Set test data $dbuser1 = $this->create_user1_for_update(); $dbuser2 = $this->create_user2_for_update(); //update the test data $user1 = new stdClass(); $user1->id = $dbuser1->id; $user1->shortname = 'testshortname1'; $user1->institution = 'mahara'; $user1->favourites = array(array('id' => 1), array('username' => $dbuser2->username)); $user2 = new stdClass(); $user2->username = $dbuser2->username; $user2->shortname = 'testshortname1'; $user2->institution = 'mahara'; $user2->favourites = array(array('id' => 1), array('username' => $dbuser1->username)); $users = array($user1, $user2); //update the users by web service $function = 'mahara_user_update_favourites'; $params = array('users' => $users); $client->call($function, $params); // check the new favourites lists $fav1 = self::prune_nasty_zero(get_user_favorites($dbuser1->id, 100, 0)); $fav2 = self::prune_nasty_zero(get_user_favorites($dbuser2->id, 100, 0)); $this->assertEquals(count($fav1), count($user1->favourites)); $this->assertEquals($dbuser2->id, self::find_new_fav($fav1)); $this->assertEquals(count($fav2), count($user2->favourites)); $this->assertEquals($dbuser1->id, self::find_new_fav($fav2)); $function = 'mahara_user_get_favourites'; $params = array('users' => array(array('shortname' => 'testshortname1', 'userid' => $dbuser1->id), array('shortname' => 'testshortname1', 'userid' => $dbuser2->id))); $users = $client->call($function, $params); foreach ($users as $user) { $favs = self::prune_nasty_zero($user['favourites']); $this->assertEquals(count($favs), count($user1->favourites)); $this->assertEquals($user['shortname'], $user1->shortname); $this->assertEquals($user['institution'], $user1->institution); } // get all favourites $function = 'mahara_user_get_all_favourites'; $params = array('shortname' => 'testshortname1'); $users = $client->call($function, $params); $this->assertTrue(count($users) >= 2); foreach ($users as $user) { // skip users that we don't know if ($user['id'] != $dbuser1->id && $user['id'] != $dbuser2->id) { continue; } $favs = self::prune_nasty_zero($user['favourites']); $this->assertEquals(count($favs), count($user1->favourites)); $this->assertEquals($user['shortname'], $user1->shortname); $this->assertEquals($user['institution'], $user1->institution); } }
/** * Provides an element to manage a view ACL * * @param array $element The element to render * @param Pieform $form The form to render the element for * @return string The HTML for the element */ function pieform_element_viewacl(Pieform $form, $element) { global $USER, $SESSION, $LANGDIRECTION; $strlen = function_exists('mb_strlen') ? 'mb_strlen' : 'strlen'; $smarty = smarty_core(); $smarty->left_delimiter = '{{'; $smarty->right_delimiter = '}}'; $value = $form->get_value($element); // Look for the presets and split them into two groups require_once get_config('libroot') . 'antispam.php'; $public = false; if (is_probationary_user()) { $public = false; } else { if (get_config('allowpublicviews') && $USER->institution_allows_public_views()) { $public = true; } else { if (get_config('allowpublicprofiles') && $element['viewtype'] == 'profile') { $public = true; } } } $allpresets = array('public', 'loggedin', 'friends'); $allowedpresets = array(); $loggedinindex = 0; if ($public) { $allowedpresets[] = 'public'; $loggedinindex = 1; } $allowedpresets[] = 'loggedin'; if ($form->get_property('userview')) { $allowedpresets[] = 'friends'; } $accesslist = array(); if ($value) { foreach ($value as $item) { if (is_array($item)) { if ($item['type'] == 'public') { $item['publicallowed'] = (int) $public; } if (in_array($item['type'], $allpresets)) { $item['name'] = get_string($item['type'] == 'loggedin' ? 'registeredusers' : $item['type'], 'view'); $item['preset'] = true; } else { $item['name'] = pieform_render_viewacl_getvaluebytype($item['type'], $item['id']); } if ($strlen($item['name']) > 30) { $item['shortname'] = str_shorten_text($item['name'], 30, true); } // only show access that is still current. Expired access will be deleted if the form is saved if ($form->is_submitted() || empty($item['stopdate']) || time() <= strtotime($item['stopdate'])) { $accesslist[] = $item; } } } } $defaultaccesslist = $accesslist ? 0 : 1; $myinstitutions = array(); foreach ($USER->get('institutions') as $i) { $myinstitutions[] = array('type' => 'institution', 'id' => $i->institution, 'start' => null, 'end' => null, 'name' => hsc($i->displayname), 'preset' => false); } foreach ($allowedpresets as &$preset) { $preset = array('type' => $preset, 'id' => $preset, 'start' => null, 'end' => null, 'name' => get_string($preset == 'loggedin' ? 'registeredusers' : $preset, 'view'), 'preset' => true); } $allgroups = array('type' => 'allgroups', 'id' => 'allgroups', 'start' => null, 'end' => null, 'name' => get_string('allmygroups', 'group'), 'preset' => true); $mygroups = array(); foreach (group_get_user_groups($USER->get('id')) as $g) { $group = array('type' => 'group', 'id' => $g->id, 'start' => null, 'end' => null, 'name' => $g->name, 'preset' => false); if ($strlen($g->name) > 30) { $group['shortname'] = str_shorten_text($g->name, 30, true); } $mygroups[] = $group; } $faves = array(); foreach (get_user_favorites($USER->get('id')) as $u) { $fave = array('type' => 'user', 'id' => $u->id, 'start' => null, 'end' => null, 'name' => $u->name, 'preset' => false); if ($strlen($u->name) > 30) { $fave['shortname'] = str_shorten_text($u->name, 30, true); } $faves[] = $fave; } require_once get_config('libroot') . 'pieforms/pieform/elements/calendar.php'; $options = array('dateFormat' => get_string('calendar_dateFormat', 'langconfig'), 'timeFormat' => get_string('calendar_timeFormat', 'langconfig'), 'stepHour' => 1, 'stepMinute' => 5); $options = pieform_element_calendar_get_lang_strings($options, $LANGDIRECTION); $datepickeroptionstr = ''; foreach ($options as $key => $option) { if (is_numeric($option)) { $datepickeroptionstr .= $key . ': ' . $option . ','; } else { if (is_array($option)) { foreach ($option as $k => $v) { if (!is_numeric($v)) { if (preg_match('/^\'(.*)\'$/', $v, $match)) { $v = $match[1]; } $option[$k] = json_encode($v); } } $option = '[' . implode(',', $option) . ']'; $datepickeroptionstr .= $key . ': ' . $option . ','; } else { $datepickeroptionstr .= $key . ': ' . json_encode($option) . ','; } } } $smarty->assign('datepickeroptions', $datepickeroptionstr); $smarty->assign('viewtype', $element['viewtype']); $smarty->assign('potentialpresets', json_encode($allowedpresets)); $smarty->assign('loggedinindex', $loggedinindex); $smarty->assign('accesslist', json_encode($accesslist)); $smarty->assign('defaultaccesslist', $defaultaccesslist); $smarty->assign('viewid', $form->get_property('viewid')); $smarty->assign('formname', $form->get_property('name')); $smarty->assign('myinstitutions', json_encode($myinstitutions)); $smarty->assign('allowcomments', $element['allowcomments']); $smarty->assign('allgroups', json_encode($allgroups)); $smarty->assign('mygroups', json_encode($mygroups)); $smarty->assign('faves', json_encode($faves)); return $smarty->fetch('form/viewacl.tpl'); }
require 'modules/user/favorite_' . $submodule . '.php'; } else { session_write_close(); header('Location: ' . $config['BASE_URL'] . '/error/invalid_module'); die; } } else { $template = 'user_' . $module; require 'modules/user/' . $module . '.php'; } } else { $prefs = get_user_prefs($uid); $is_friend = is_friend($uid); $friends = get_user_friends($uid, $prefs['show_friends'], $is_friend); $playlist = get_user_playlist($uid, $prefs['show_playlist'], $is_friend); $favorites = get_user_favorites($uid, $prefs['show_favorites'], $is_friend); $subscriptions = get_user_subscriptions($uid, $prefs['show_subscriptions'], $is_friend); $subscribers = get_user_subscribers($uid, $prefs['show_subscribers'], $is_friend); $albums = get_user_albums($uid); $photos = get_user_favorite_photos($uid, $prefs['show_favorites'], $is_friend); $games = get_user_favorite_games($uid, $prefs['show_favorites'], $is_friend); $show_wall = false; $wall_public = $prefs['wall_public']; $walls = array(); $walls_total = 0; if ($wall_public == '1') { $show_wall = true; } else { if ($is_friend) { $show_wall = true; } elseif (isset($_SESSION['uid']) && $_SESSION['uid'] == $uid) {
} $fav = (int) $_GET['fav']; $topic_id = (int) $_GET['topic_id']; bb_check_admin_referer('toggle-favorite_' . $topic_id); $topic = get_topic($topic_id); if (!$topic || 0 != $topic->topic_status) { exit; } if ($fav) { bb_add_user_favorite($user_id, $topic_id); } else { bb_remove_user_favorite($user_id, $topic_id); } $ref = wp_get_referer(); if (false !== strpos($ref, bb_get_uri(null, null, BB_URI_CONTEXT_TEXT))) { bb_safe_redirect($ref); } else { wp_redirect(get_topic_link($topic_id)); } exit; } if (!bb_is_profile()) { $sendto = get_profile_tab_link($user->ID, 'favorites'); wp_redirect($sendto); exit; } if ($topics = get_user_favorites($user->ID, true)) { bb_cache_last_posts($topics); } $favorites_total = isset($user->favorites) ? count(explode(',', $user->favorites)) : 0; bb_load_template('favorites.php', array('favorites_total', 'self'));
/** * Get an array of User Favorites * @param $user_id int, defaults to current user * @param $site_id int, defaults to current blog/site * @param $filters array of post types/taxonomies * @param $html boolean, whether to output html (important for AJAX updates). If false, an integer is returned * @return int */ function get_user_favorites_count($user_id = null, $site_id = null, $filters = null, $html = false) { $favorites = get_user_favorites($user_id, $site_id, $filters); $posttypes = isset($filters['post_type']) ? implode(',', $filters['post_type']) : 'all'; $out = ""; if (!$site_id) { $site_id = 1; } if ($html) { $out .= '<span class="simplefavorites-user-count" data-posttypes="' . $posttypes . '" data-siteid="' . $site_id . '">'; } $out .= count($favorites); if ($html) { $out .= '</span>'; } return $out; }