예제 #1
0
파일: user.php 프로젝트: revcozmo/dating
 public static function list_users($page_number, $per_page, $query_string)
 {
     parse_str($query_string, $parsed_query_string);
     $where = $values = array();
     foreach ($parsed_query_string as $column => $query) {
         if (strpos($query, '[') === 0) {
             // range
             $range = explode(',', str_replace(array('[', ']'), '', $query));
             if (count($range) != 2) {
                 \lib\log::error("range formatted incorrectly: {$query}");
                 return false;
             }
             $where[] = "`{$column}` >= %s AND `{$column}` <= %s";
             $values[] = $range[0];
             $values[] = $range[1];
         } else {
             // checkbox
             $where[] = "`{$column}` IN (%s)";
             $values[] = explode(',', $query);
         }
     }
     $limit_array = array(($page_number - 1) * $per_page, $per_page);
     $values = array_merge($values, $limit_array);
     $where = implode(' AND ', $where);
     $conn = self::get_database();
     $res = database::vqueryf($conn, "SELECT SQL_CALC_FOUND_ROWS * FROM `users` WHERE {$where} LIMIT %d, %d", $values);
     $users = array();
     while ($row = mysql_fetch_assoc($res)) {
         $users[] = $row;
     }
     $total_rows = mysql_fetch_row(database::queryf($conn, 'SELECT FOUND_ROWS()'));
     $total_rows = reset($total_rows);
     return array('page' => $page_number, 'perPage' => $per_page, 'total' => $total_rows, 'models' => $users);
 }
예제 #2
0
파일: actions.php 프로젝트: revcozmo/dating
 public static function run()
 {
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $class = get_called_class();
     $return_value = '';
     if (method_exists($class, $request_method)) {
         $path_info = !empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
         $return_value = $class::$request_method($path_info);
     } else {
         \lib\log::error("request method invalid: class: {$class}, request_method: {$request_method}");
     }
     if (self::$return_json) {
         echo json_encode($return_value);
     } else {
         echo $return_value;
     }
 }
예제 #3
0
파일: image.php 프로젝트: revcozmo/dating
<?php

include_once $_SERVER['DATING_ROOT'] . '/lib/init-global.php';
if (!isset($_SESSION['user_id'])) {
    \lib\log::error('image upload attempted by user not logged in');
    echo '';
    exit;
}
abstract class image extends \lib\actions
{
    public static function get()
    {
        $vars = self::get_path_variables();
        if (count($vars) == 1) {
            $image = \lib\image::get(reset($vars));
            header("Content-type: image/{$image['type']}");
            self::$return_json = false;
            return $image['image'];
        } else {
            if (count($vars) == 2 && $vars[0] == 'user') {
                $images = \lib\image::get_user_images($vars[1]);
                return $images;
            }
        }
    }
    public static function post()
    {
        $user_id = $_SESSION['user_id'];
        $image_data = $_FILES['image'];
        // bad image
        if (strpos($image_data['type'], 'image/') === false) {