예제 #1
0
파일: history.php 프로젝트: donseba/Piwigo
    if (isset($page['search']['fields']['user'])) {
        $form['user'] = $page['search']['fields']['user'];
    } else {
        $form['user'] = null;
    }
    $form['image_id'] = @$page['search']['fields']['image_id'];
    $form['filename'] = @$page['search']['fields']['filename'];
    $form['ip'] = @$page['search']['fields']['ip'];
    $form['display_thumbnail'] = @$page['search']['fields']['display_thumbnail'];
} else {
    // by default, at page load, we want the selected date to be the current
    // date
    $form['start'] = $form['end'] = date('Y-m-d');
    $form['types'] = $types;
    // Hoverbox by default
    $form['display_thumbnail'] = pwg_get_cookie_var('display_thumbnail', 'no_display_thumbnail');
}
$template->assign(array('IMAGE_ID' => @$form['image_id'], 'FILENAME' => @$form['filename'], 'IP' => @$form['ip'], 'START' => @$form['start'], 'END' => @$form['end']));
$template->assign(array('type_option_values' => $types, 'type_option_selected' => $form['types']));
$query = '
SELECT
    ' . $conf['user_fields']['id'] . ' AS id,
    ' . $conf['user_fields']['username'] . ' AS username
  FROM ' . USERS_TABLE . '
  ORDER BY username ASC
;';
$template->assign(array('user_options' => query2array($query, 'id', 'username'), 'user_options_selected' => array(@$form['user'])));
$template->assign('display_thumbnails', $display_thumbnails);
$template->assign('display_thumbnail_selected', $form['display_thumbnail']);
// +-----------------------------------------------------------------------+
// |                           html code display                           |
예제 #2
0
/**
 * Rate a picture by the current user.
 *
 * @param int $image_id
 * @param float $rate
 * @return array as return by update_rating_score()
 */
function rate_picture($image_id, $rate)
{
    global $conf, $user;
    if (!isset($rate) or !$conf['rate'] or !preg_match('/^[0-9]+$/', $rate) or !in_array($rate, $conf['rate_items'])) {
        return false;
    }
    $user_anonymous = is_autorize_status(ACCESS_CLASSIC) ? false : true;
    if ($user_anonymous and !$conf['rate_anonymous']) {
        return false;
    }
    $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]);
    if (count($ip_components) > 3) {
        array_pop($ip_components);
    }
    $anonymous_id = implode('.', $ip_components);
    if ($user_anonymous) {
        $save_anonymous_id = pwg_get_cookie_var('anonymous_rater', $anonymous_id);
        if ($anonymous_id != $save_anonymous_id) {
            // client has changed his IP adress or he's trying to fool us
            $query = '
SELECT element_id
  FROM ' . RATE_TABLE . '
  WHERE user_id = ' . $user['id'] . '
    AND anonymous_id = \'' . $anonymous_id . '\'
;';
            $already_there = array_from_query($query, 'element_id');
            if (count($already_there) > 0) {
                $query = '
DELETE
  FROM ' . RATE_TABLE . '
  WHERE user_id = ' . $user['id'] . '
    AND anonymous_id = \'' . $save_anonymous_id . '\'
    AND element_id IN (' . implode(',', $already_there) . ')
;';
                pwg_query($query);
            }
            $query = '
UPDATE ' . RATE_TABLE . '
  SET anonymous_id = \'' . $anonymous_id . '\'
  WHERE user_id = ' . $user['id'] . '
    AND anonymous_id = \'' . $save_anonymous_id . '\'
;';
            pwg_query($query);
        }
        // end client changed ip
        pwg_set_cookie_var('anonymous_rater', $anonymous_id);
    }
    // end anonymous user
    $query = '
DELETE
  FROM ' . RATE_TABLE . '
  WHERE element_id = ' . $image_id . '
    AND user_id = ' . $user['id'] . '
';
    if ($user_anonymous) {
        $query .= ' AND anonymous_id = \'' . $anonymous_id . '\'';
    }
    pwg_query($query);
    $query = '
INSERT
  INTO ' . RATE_TABLE . '
  (user_id,anonymous_id,element_id,rate,date)
  VALUES
  (' . $user['id'] . ',' . '\'' . $anonymous_id . '\',' . $image_id . ',' . $rate . ',NOW())
;';
    pwg_query($query);
    return update_rating_score($image_id);
}