Ejemplo n.º 1
0
/**
 * API method
 * Deletes rates of an user
 * @param mixed[] $params
 *    @option int user_id
 *    @option string anonymous_id (optional)
 */
function ws_rates_delete($params, &$service)
{
    $query = '
DELETE FROM ' . RATE_TABLE . '
  WHERE user_id=' . $params['user_id'];
    if (!empty($params['anonymous_id'])) {
        $query .= ' AND anonymous_id=\'' . $params['anonymous_id'] . '\'';
    }
    if (!empty($params['image_id'])) {
        $query .= ' AND element_id=' . $params['image_id'];
    }
    $changes = pwg_db_changes(pwg_query($query));
    if ($changes) {
        include_once PHPWG_ROOT_PATH . 'include/functions_rate.inc.php';
        update_rating_score();
    }
    return $changes;
}
Ejemplo n.º 2
0
$selected_cat = array();
if (isset($_POST['set_permalink']) and $_POST['cat_id'] > 0) {
    $permalink = $_POST['permalink'];
    if (empty($permalink)) {
        delete_cat_permalink($_POST['cat_id'], isset($_POST['save']));
    } else {
        set_cat_permalink($_POST['cat_id'], $permalink, isset($_POST['save']));
    }
    $selected_cat = array($_POST['cat_id']);
} elseif (isset($_GET['delete_permanent'])) {
    $query = '
DELETE FROM ' . OLD_PERMALINKS_TABLE . '
  WHERE permalink=\'' . $_GET['delete_permanent'] . '\'
  LIMIT 1';
    $result = pwg_query($query);
    if (pwg_db_changes($result) == 0) {
        $page['errors'][] = l10n('Cannot delete the old permalink !');
    }
}
$template->set_filename('permalinks', 'permalinks.tpl');
// +-----------------------------------------------------------------------+
// | tabs                                                                  |
// +-----------------------------------------------------------------------+
$page['tab'] = 'permalinks';
include PHPWG_ROOT_PATH . 'admin/include/albums_tab.inc.php';
$query = '
SELECT
  id, permalink,
  CONCAT(id, " - ", name, IF(permalink IS NULL, "", " √") ) AS name,
  uppercats, global_rank
FROM ' . CATEGORIES_TABLE;
Ejemplo n.º 3
0
/**
 * Tries to delete a (or more) user comment.
 *    only admin can delete all comments
 *    other users can delete their own comments
 *
 * @param int|int[] $comment_id
 * @return bool false if nothing deleted
 */
function delete_user_comment($comment_id)
{
    $user_where_clause = '';
    if (!is_admin()) {
        $user_where_clause = '   AND author_id = \'' . $GLOBALS['user']['id'] . '\'';
    }
    if (is_array($comment_id)) {
        $where_clause = 'id IN(' . implode(',', $comment_id) . ')';
    } else {
        $where_clause = 'id = ' . $comment_id;
    }
    $query = '
DELETE FROM ' . COMMENTS_TABLE . '
  WHERE ' . $where_clause . $user_where_clause . '
;';
    if (pwg_db_changes(pwg_query($query))) {
        invalidate_user_cache_nb_comments();
        email_admin('delete', array('author' => $GLOBALS['user']['username'], 'comment_id' => $comment_id));
        trigger_notify('user_comment_deletion', $comment_id);
        return true;
    }
    return false;
}
Ejemplo n.º 4
0
/**
 * Execute a query
 *
 * @param string $query
 * @return mysqli_result|bool
 */
function pwg_query($query)
{
    global $mysqli, $conf, $page, $debug, $t2;
    $start = microtime(true);
    $result = $mysqli->query($query) or my_error($query, $conf['die_on_sql_error']);
    $time = microtime(true) - $start;
    if (!isset($page['count_queries'])) {
        $page['count_queries'] = 0;
        $page['queries_time'] = 0;
    }
    $page['count_queries']++;
    $page['queries_time'] += $time;
    if ($conf['show_queries']) {
        $output = '';
        $output .= '<pre>[' . $page['count_queries'] . '] ';
        $output .= "\n" . $query;
        $output .= "\n" . '(this query time : ';
        $output .= '<b>' . number_format($time, 3, '.', ' ') . ' s)</b>';
        $output .= "\n" . '(total SQL time  : ';
        $output .= number_format($page['queries_time'], 3, '.', ' ') . ' s)';
        $output .= "\n" . '(total time      : ';
        $output .= number_format($time + $start - $t2, 3, '.', ' ') . ' s)';
        if ($result != null and preg_match('/\\s*SELECT\\s+/i', $query)) {
            $output .= "\n" . '(num rows        : ';
            $output .= pwg_db_num_rows($result) . ' )';
        } elseif ($result != null and preg_match('/\\s*INSERT|UPDATE|REPLACE|DELETE\\s+/i', $query)) {
            $output .= "\n" . '(affected rows   : ';
            $output .= pwg_db_changes() . ' )';
        }
        $output .= "</pre>\n";
        $debug .= $output;
    }
    return $result;
}
Ejemplo n.º 5
0
/**
 * API method
 * Sets the level of an image
 * @param mixed[] $params
 *    @option int image_id
 *    @option int level
 */
function ws_images_setPrivacyLevel($params, $service)
{
    global $conf;
    if (!in_array($params['level'], $conf['available_permission_levels'])) {
        return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid level');
    }
    $query = '
UPDATE ' . IMAGES_TABLE . '
  SET level=' . (int) $params['level'] . '
  WHERE id IN (' . implode(',', $params['image_id']) . ')
;';
    $result = pwg_query($query);
    $affected_rows = pwg_db_changes($result);
    if ($affected_rows) {
        include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
        invalidate_user_cache();
    }
    return $affected_rows;
}