Beispiel #1
0
    error_404();
}
$history_url = "user/{$fsq_id}/places/{$woeid}/";
login_ensure_loggedin($history_url);
$fsq_user = foursquare_users_get_by_foursquare_id($fsq_id);
if (!$fsq_user) {
    error_404();
}
$owner = users_get_by_id($fsq_user['user_id']);
$is_own = $owner['id'] == $GLOBALS['cfg']['user']['id'] ? 1 : 0;
# for now...
if (!$is_own) {
    error_403();
}
$more = array('locality' => $woeid);
if ($page = get_int32("page")) {
    $more['page'] = $page;
}
$rsp = privatesquare_checkins_venues_for_user($owner, $more);
$GLOBALS['smarty']->assign_by_ref("venues", $rsp['rows']);
$geo_stats = privatesquare_checkins_utils_geo_stats($rsp['rows']);
$GLOBALS['smarty']->assign_by_ref("geo_stats", $geo_stats);
$locality = reverse_geoplanet_get_by_woeid($woeid, 'locality');
$GLOBALS['smarty']->assign_by_ref("locality", $locality);
$GLOBALS['smarty']->assign_by_ref("owner", $owner);
$pagination_url = urls_places_for_user($owner) . "{$woeid}/";
$GLOBALS['smarty']->assign("pagination_url", $pagination_url);
$export_formats = privatesquare_export_valid_formats();
$GLOBALS['smarty']->assign("export_formats", array_keys($export_formats));
$GLOBALS['smarty']->display("page_user_place.txt");
exit;
function privatesquare_checkins_localities_for_user(&$user, $more = array())
{
    $defaults = array('page' => 1, 'per_page' => 10);
    $more = array_merge($defaults, $more);
    $cluster_id = $user['cluster_id'];
    $enc_user = AddSlashes($user['id']);
    # TO DO: indexes
    # Note: we do pagination in memory because we're going to
    # sort the results by count; this all happens below.
    $sql = "SELECT locality, COUNT(id) AS count FROM PrivatesquareCheckins WHERE user_id='{$enc_user}' GROUP BY locality";
    $rsp = db_fetch_users($cluster_id, $sql);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $tmp = array();
    foreach ($rsp['rows'] as $row) {
        if (!$row['locality']) {
            continue;
        }
        $tmp[$row['locality']] = $row['count'];
    }
    arsort($tmp);
    $woeids = array_keys($tmp);
    $total_count = count($woeids);
    #
    $page_count = ceil($total_count / $more['per_page']);
    $last_page_count = $total_count - ($page_count - 1) * $more['per_page'];
    $pagination = array('total_count' => $total_count, 'page' => $more['page'], 'per_page' => $more['per_page'], 'page_count' => $page_count);
    if ($GLOBALS['cfg']['pagination_assign_smarty_variable']) {
        $GLOBALS['smarty']->assign('pagination', $pagination);
    }
    #
    $offset = $more['per_page'] * ($more['page'] - 1);
    $woeids = array_slice($woeids, $offset, $more['per_page']);
    $localities = array();
    foreach ($woeids as $woeid) {
        $count = $tmp[$woeid];
        $row = reverse_geoplanet_get_by_woeid($woeid, 'locality');
        # what if ! $row? should never happen but...
        $row['count'] = $count;
        # Maybe always get this? Filtering may just be a
        # pointless optimization (20120229/straup)
        if ($count > 1) {
            $venues_more = array('locality' => $woeid, 'stats_mode' => 1);
            $venues_rsp = privatesquare_checkins_venues_for_user($user, $venues_more);
            $row['venues'] = $venues_rsp['rows'];
        }
        $localities[] = $row;
    }
    return okay(array('rows' => $localities, 'pagination' => $pagination));
}