当前位置: 首页>>代码示例>>PHP>>正文


PHP single_update函数代码示例

本文整理汇总了PHP中single_update函数的典型用法代码示例。如果您正苦于以下问题:PHP single_update函数的具体用法?PHP single_update怎么用?PHP single_update使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了single_update函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ws_images_addFlickr

function ws_images_addFlickr($photo, &$service)
{
    if (!is_admin()) {
        return new PwgError(403, 'Forbidden');
    }
    global $conf;
    if (empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key'])) {
        return new PwgError(null, l10n('Please fill your API keys on the configuration tab'));
    }
    include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
    include_once PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php';
    include_once FLICKR_PATH . 'include/functions.inc.php';
    if (test_remote_download() === false) {
        return new PwgError(null, l10n('No download method available'));
    }
    // init flickr API
    include_once FLICKR_PATH . 'include/phpFlickr/phpFlickr.php';
    $flickr = new phpFlickr($conf['flickr2piwigo']['api_key'], $conf['flickr2piwigo']['secret_key']);
    $flickr->enableCache('fs', FLICKR_FS_CACHE);
    // user
    $u = $flickr->test_login();
    if ($u === false or empty($_SESSION['phpFlickr_auth_token'])) {
        return new PwgError(403, l10n('API not authenticated'));
    }
    // photos infos
    $photo_f = $flickr->photos_getInfo($photo['id']);
    $photo = array_merge($photo, $photo_f['photo']);
    $photo['url'] = $flickr->get_biggest_size($photo['id'], 'original');
    $photo['path'] = FLICKR_FS_CACHE . 'flickr-' . $u['username'] . '-' . $photo['id'] . '.' . get_extension($photo['url']);
    // copy file
    if (download_remote_file($photo['url'], $photo['path']) == false) {
        return new PwgError(null, l10n('Can\'t download file'));
    }
    // category
    if (!preg_match('#^[0-9]+$#', $photo['category'])) {
        $categories_names = explode(',', $photo['category']);
        $photo['category'] = array();
        foreach ($categories_names as $category_name) {
            $query = '
SELECT id FROM ' . CATEGORIES_TABLE . '
  WHERE LOWER(name) = "' . strtolower($category_name) . '"
;';
            $result = pwg_query($query);
            if (pwg_db_num_rows($result)) {
                list($cat_id) = pwg_db_fetch_row($result);
                $photo['category'][] = $cat_id;
            } else {
                $cat = create_virtual_category($category_name);
                $photo['category'][] = $cat['id'];
            }
        }
    } else {
        $photo['category'] = array($photo['category']);
    }
    // add photo
    $photo['image_id'] = add_uploaded_file($photo['path'], basename($photo['path']), $photo['category']);
    // do some updates
    if (!empty($photo['fills'])) {
        $photo['fills'] = rtrim($photo['fills'], ',');
        $photo['fills'] = explode(',', $photo['fills']);
        $updates = array();
        if (in_array('fill_name', $photo['fills'])) {
            $updates['name'] = pwg_db_real_escape_string($photo['title']);
        }
        if (in_array('fill_posted', $photo['fills'])) {
            $updates['date_available'] = date('Y-m-d H:i:s', $photo['dates']['posted']);
        }
        if (in_array('fill_taken', $photo['fills'])) {
            $updates['date_creation'] = $photo['dates']['taken'];
        }
        if (in_array('fill_author', $photo['fills'])) {
            $updates['author'] = pwg_db_real_escape_string($photo['owner']['username']);
        }
        if (in_array('fill_description', $photo['fills'])) {
            $updates['comment'] = pwg_db_real_escape_string(@$photo['description']);
        }
        if (in_array('fill_geotag', $photo['fills']) and !empty($photo['location'])) {
            $updates['latitude'] = pwg_db_real_escape_string($photo['location']['latitude']);
            $updates['longitude'] = pwg_db_real_escape_string($photo['location']['longitude']);
        }
        if (in_array('level', $photo['fills']) && !$photo['visibility']['ispublic']) {
            $updates['level'] = 8;
            if ($photo['visibility']['isfamily']) {
                $updates['level'] = 4;
            }
            if ($photo['visibility']['isfriend']) {
                $updates['level'] = 2;
            }
        }
        if (count($updates)) {
            single_update(IMAGES_TABLE, $updates, array('id' => $photo['image_id']));
        }
        if (!empty($photo['tags']['tag']) and in_array('fill_tags', $photo['fills'])) {
            $raw_tags = array_map(create_function('$t', 'return $t["_content"];'), $photo['tags']['tag']);
            $raw_tags = implode(',', $raw_tags);
            set_tags(get_tag_ids($raw_tags), $photo['image_id']);
        }
    }
    return l10n('Photo "%s" imported', $photo['title']);
}
开发者ID:biffhero,项目名称:Flickr2Piwigo,代码行数:100,代码来源:ws_functions.inc.php

示例2: get_nb_available_tags

/**
 * Returns the number of available tags for the connected user.
 *
 * @return int
 */
function get_nb_available_tags()
{
    global $user;
    if (!isset($user['nb_available_tags'])) {
        $user['nb_available_tags'] = count(get_available_tags());
        single_update(USER_CACHE_TABLE, array('nb_available_tags' => $user['nb_available_tags']), array('user_id' => $user['id']));
    }
    return $user['nb_available_tags'];
}
开发者ID:donseba,项目名称:Piwigo,代码行数:14,代码来源:functions_tag.inc.php

示例3: ws_extref_categories_set

function ws_extref_categories_set($params, &$service)
{
    // does the category really exist?
    $query = '
SELECT COUNT(*)
  FROM ' . CATEGORIES_TABLE . '
  WHERE id = ' . $params['category_id'] . '
;';
    list($count) = pwg_db_fetch_row(pwg_query($query));
    if ($count == 0) {
        return new PwgError(404, 'category_id not found');
    }
    single_update(CATEGORIES_TABLE, array('external_reference' => $params['external_reference']), array('id' => $params['category_id']));
    return true;
}
开发者ID:plegall,项目名称:Piwigo-external_reference,代码行数:15,代码来源:main.inc.php

示例4: update_user

function update_user($username, $id)
{
    $up = new Ldap();
    $up->load_config();
    $up->ldap_conn() or error_log("Unable to connect LDAP server : " . $up->getErrorString());
    // update user piwigo rights / access according to ldap. Only if it's webmaster / admin, so no normal !
    if ($up->ldap_status($username) != 'normal') {
        single_update(USER_INFOS_TABLE, array('status' => $up->ldap_status($username)), array('user_id' => $id));
    }
    // search groups
    $group_query = 'SELECT name, id FROM ' . GROUPS_TABLE . ';';
    $result = pwg_query($group_query);
    $inserts = array();
    while ($row = pwg_db_fetch_assoc($result)) {
        if ($up->user_membership($username, $up->ldap_group($row['name']))) {
            $inserts[] = array('user_id' => $id, 'group_id' => $row['id']);
        }
    }
    if (count($inserts) > 0) {
        mass_inserts(USER_GROUP_TABLE, array('user_id', 'group_id'), $inserts, array('ignore' => true));
    }
}
开发者ID:kvakanet,项目名称:ldap_login,代码行数:22,代码来源:main.inc.php

示例5: ws_pfemail_mailbox_save

function ws_pfemail_mailbox_save($params, &$service)
{
    $mailbox = array();
    if (isset($params['id']) and !empty($params['id'])) {
        // we are edition mode
        $query = '
SELECT *
  FROM ' . PFEMAIL_MAILBOXES_TABLE . '
  WHERE id = ' . $params['id'] . '
;';
        $mailboxes = query2array($query, 'id');
        if (!isset($mailboxes[$params['id']])) {
            return new PwgError(404, 'id not found');
        }
        $mailbox = $mailboxes[$params['id']];
    }
    $mailbox['path'] = $params['path'];
    $mailbox['login'] = $params['login'];
    $mailbox['password'] = $params['password'];
    $mailbox['category_id'] = $params['category_id'];
    $mailbox['moderated'] = $params['moderated'] ? 'true' : 'false';
    if (isset($mailbox['id'])) {
        single_update(PFEMAIL_MAILBOXES_TABLE, $mailbox, array('id' => $params['id']));
    } else {
        single_insert(PFEMAIL_MAILBOXES_TABLE, $mailbox);
        $mailbox['id'] = pwg_db_insert_id(PFEMAIL_MAILBOXES_TABLE);
    }
    return $mailbox;
}
开发者ID:plegall,项目名称:Piwigo-photo_from_email,代码行数:29,代码来源:functions.inc.php

示例6: oauth_begin_register

/**
 * register page
 */
function oauth_begin_register()
{
    global $conf, $template, $hybridauth_conf, $page, $user;
    if ($hybridauth_conf['enabled'] == 0) {
        return;
    }
    // coming from identification page
    if (pwg_get_session_var('oauth_new_user') != null) {
        list($provider, $user_identifier) = pwg_get_session_var('oauth_new_user');
        try {
            if ($provider == 'Persona') {
                $template->assign('OAUTH_USER', array('provider' => 'Persona', 'username' => $user_identifier, 'u_profile' => null, 'avatar' => null));
                oauth_assign_template_vars();
                $template->append('OAUTH', array('persona_email' => $user_identifier), true);
                $conf['oauth']['include_common_template'] = true;
            } else {
                require_once OAUTH_PATH . 'include/hybridauth/Hybrid/Auth.php';
                $hybridauth = new Hybrid_Auth($hybridauth_conf);
                $adapter = $hybridauth->authenticate($provider);
                $remote_user = $adapter->getUserProfile();
                // security, check remote identifier
                if ($remote_user->identifier != $user_identifier) {
                    pwg_unset_session_var('oauth_new_user');
                    throw new Exception('Hacking attempt!', 403);
                }
                $template->assign('OAUTH_USER', array('provider' => $hybridauth_conf['providers'][$provider]['name'], 'username' => $remote_user->displayName, 'u_profile' => $remote_user->profileURL, 'avatar' => $remote_user->photoURL));
            }
            $oauth_id = pwg_db_real_escape_string($provider . '---' . $user_identifier);
            $page['infos'][] = l10n('Your registration is almost done, please complete the registration form.');
            // register form submited
            if (isset($_POST['submit'])) {
                $user_id = register_user($_POST['login'], hash('sha1', $oauth_id . $conf['secret_key']), $_POST['mail_address'], true, $page['errors'], false);
                if ($user_id !== false) {
                    pwg_unset_session_var('oauth_new_user');
                    // update oauth field
                    single_update(USER_INFOS_TABLE, array('oauth_id' => $oauth_id), array('user_id' => $user_id));
                    // log_user and redirect
                    log_user($user_id, false);
                    redirect('profile.php');
                }
                unset($_POST['submit']);
            } else {
                if (isset($_POST['login']) && $conf['oauth']['allow_merge_accounts']) {
                    if ($conf['insensitive_case_logon'] == true) {
                        $_POST['username'] = search_case_username($_POST['username']);
                    }
                    $user_id = get_userid($_POST['username']);
                    if ($user_id === false) {
                        $page['errors'][] = l10n('Invalid username or email');
                    } else {
                        if ($user_id == $conf['webmaster_id']) {
                            $page['errors'][] = l10n('For security reason, the main webmaster account can\'t be merged with a remote account, but you can use another webmaster account.');
                        } else {
                            if (pwg_login(false, $_POST['username'], $_POST['password'], false)) {
                                // update oauth field
                                single_update(USER_INFOS_TABLE, array('oauth_id' => $oauth_id), array('user_id' => $user['id']));
                                pwg_unset_session_var('oauth_new_user');
                                redirect('profile.php');
                            } else {
                                $page['errors'][] = l10n('Invalid password!');
                            }
                        }
                    }
                }
            }
            // overwrite fields with remote datas
            if ($provider == 'Persona') {
                $_POST['login'] = '';
                $_POST['mail_address'] = $user_identifier;
            } else {
                $_POST['login'] = $remote_user->displayName;
                $_POST['mail_address'] = $remote_user->email;
            }
            // template
            $template->assign('OAUTH_PATH', OAUTH_PATH);
            if ($conf['oauth']['allow_merge_accounts']) {
                $template->assign('OAUTH_LOGIN_IN_REGISTER', true);
                $template->set_prefilter('register', 'oauth_add_login_in_register');
            } else {
                $template->set_prefilter('register', 'oauth_add_profile_prefilter');
                $template->set_prefilter('register', 'oauth_remove_password_fields_prefilter');
            }
        } catch (Exception $e) {
            $page['errors'][] = l10n('An error occured, please contact the gallery owner. <i>Error code : %s</i>', $e->getCode());
        }
    } else {
        if ($conf['oauth']['display_register']) {
            oauth_assign_template_vars(get_gallery_home_url());
            $template->set_prefilter('register', 'oauth_add_buttons_prefilter');
        }
    }
}
开发者ID:lcorbasson,项目名称:Piwigo-Social-Connect,代码行数:95,代码来源:public_events.inc.php

示例7: strip_tags

 $data['id'] = $_GET['image_id'];
 $data['name'] = $_POST['name'];
 $data['author'] = $_POST['author'];
 $data['level'] = $_POST['level'];
 if ($conf['allow_html_descriptions']) {
     $data['comment'] = @$_POST['description'];
 } else {
     $data['comment'] = strip_tags(@$_POST['description']);
 }
 if (!empty($_POST['date_creation'])) {
     $data['date_creation'] = $_POST['date_creation'];
 } else {
     $data['date_creation'] = null;
 }
 $data = trigger_change('picture_modify_before_update', $data);
 single_update(IMAGES_TABLE, $data, array('id' => $data['id']));
 // time to deal with tags
 $tag_ids = array();
 if (!empty($_POST['tags'])) {
     $tag_ids = get_tag_ids($_POST['tags']);
 }
 set_tags($tag_ids, $_GET['image_id']);
 // association to albums
 if (!isset($_POST['associate'])) {
     $_POST['associate'] = array();
 }
 check_input_parameter('associate', $_POST, true, PATTERN_ID);
 move_images_to_categories(array($_GET['image_id']), $_POST['associate']);
 invalidate_user_cache();
 // thumbnail for albums
 if (!isset($_POST['represent'])) {
开发者ID:donseba,项目名称:Piwigo,代码行数:31,代码来源:picture_modify.php

示例8: check_status

// +-----------------------------------------------------------------------+
// | Check Access and exit when user status is not ok                      |
// +-----------------------------------------------------------------------+
check_status(ACCESS_ADMINISTRATOR);
trigger_notify('loc_begin_cat_modify');
//---------------------------------------------------------------- verification
if (!isset($_GET['cat_id']) || !is_numeric($_GET['cat_id'])) {
    trigger_error('missing cat_id param', E_USER_ERROR);
}
//--------------------------------------------------------- form criteria check
if (isset($_POST['submit'])) {
    $data = array('id' => $_GET['cat_id'], 'name' => @$_POST['name'], 'comment' => $conf['allow_html_descriptions'] ? @$_POST['comment'] : strip_tags(@$_POST['comment']));
    if ($conf['activate_comments']) {
        $data['commentable'] = isset($_POST['commentable']) ? $_POST['commentable'] : 'false';
    }
    single_update(CATEGORIES_TABLE, $data, array('id' => $data['id']));
    if (isset($_POST['apply_commentable_on_sub'])) {
        $subcats = get_subcat_ids(array('id' => $data['id']));
        $query = '
UPDATE ' . CATEGORIES_TABLE . '
  SET commentable = \'' . $data['commentable'] . '\'
  WHERE id IN (' . implode(',', $subcats) . ')
;';
        pwg_query($query);
    }
    // retrieve cat infos before continuing (following updates are expensive)
    $cat_info = get_cat_info($_GET['cat_id']);
    if ($_POST['visible'] == 'true_sub') {
        set_cat_visible(array($_GET['cat_id']), true, true);
    } elseif ($cat_info['visible'] != get_boolean($_POST['visible'])) {
        set_cat_visible(array($_GET['cat_id']), $_POST['visible']);
开发者ID:HassenLin,项目名称:piwigo_utf8filename,代码行数:31,代码来源:cat_modify.php

示例9: ws_images_addRemote

function ws_images_addRemote($params, &$service)
{
    global $conf;
    if (!is_admin()) {
        return new PwgError(401, 'Access denied');
    }
    load_language('plugin.lang', URLUPLOADER_PATH);
    $params = array_map('trim', $params);
    $allowed_extensions = array('jpg', 'jpeg', 'png', 'gif');
    $allowed_mimes = array('image/jpeg', 'image/png', 'image/gif');
    // check empty url
    if (empty($params['file_url'])) {
        return new PwgError(WS_ERR_INVALID_PARAM, l10n('File URL is empty'));
    }
    // check remote url
    if (!url_is_remote($params['file_url'])) {
        return new PwgError(WS_ERR_INVALID_PARAM, l10n('Invalid file URL'));
    }
    // check file extension
    if (!in_array(strtolower(get_extension($params['file_url'])), $allowed_extensions)) {
        return new PwgError(WS_ERR_INVALID_PARAM, l10n('Invalid file type'));
    }
    // download file
    include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
    $temp_filename = $conf['data_location'] . basename($params['file_url']);
    $file = fopen($temp_filename, 'w+');
    $result = fetchRemote($params['file_url'], $file);
    fclose($file);
    // download failed ?
    if (!$result) {
        @unlink($temp_filename);
        return new PwgError(WS_ERR_INVALID_PARAM, l10n('Unable to download file'));
    }
    // check mime-type
    if (!in_array(get_mime($temp_filename, $allowed_mimes[0]), $allowed_mimes)) {
        @unlink($temp_filename);
        return new PwgError(WS_ERR_INVALID_PARAM, l10n('Invalid file type'));
    }
    // add photo
    include_once PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php';
    $image_id = add_uploaded_file($temp_filename, basename($temp_filename), array($params['category']), $params['level']);
    $updates = array();
    if (!empty($params['name'])) {
        $updates['name'] = $params['name'];
    }
    if ($params['url_in_comment'] == 'true') {
        $url = parse_url($params['file_url']);
        $url = $url['scheme'] . '://' . $url['host'];
        $updates['comment'] = '<a href="' . $url . '">' . $url . '</a>';
    }
    single_update(IMAGES_TABLE, $updates, array('id' => $image_id));
    // return infos
    $query = '
SELECT id, name, permalink
  FROM ' . CATEGORIES_TABLE . '
  WHERE id = ' . $params['category'] . '
;';
    $category = pwg_db_fetch_assoc(pwg_query($query));
    $url_params = array('image_id' => $image_id, 'section' => 'categories', 'category' => $category);
    $query = '
SELECT id, path, name
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $image_id . '
;';
    $image_infos = pwg_db_fetch_assoc(pwg_query($query));
    $query = '
SELECT
    COUNT(*) AS nb_photos
  FROM ' . IMAGE_CATEGORY_TABLE . '
  WHERE category_id = ' . $params['category'] . '
;';
    $category_infos = pwg_db_fetch_assoc(pwg_query($query));
    $category_name = get_cat_display_name_from_id($params['category'], null);
    return array('image_id' => $image_id, 'url' => make_picture_url($url_params), 'src' => DerivativeImage::thumb_url($image_infos), 'name' => $image_infos['name'], 'category' => array('id' => $params['category'], 'nb_photos' => $category_infos['nb_photos'], 'label' => $category_name));
}
开发者ID:skylogic004,项目名称:Piwigo-URL-Uploader,代码行数:75,代码来源:ws_functions.inc.php

示例10: ws_pshare_share_expire

function ws_pshare_share_expire($params, &$service)
{
    global $conf, $user;
    $query = '
SELECT *
  FROM ' . PSHARE_KEYS_TABLE . '
  WHERE pshare_key_id = ' . $params['id'] . '
;';
    $shares = query2array($query);
    if (count($shares) == 0) {
        return new PwgError(404, "not found");
    }
    $share = $shares[0];
    list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW()'));
    single_update(PSHARE_KEYS_TABLE, array('expire_on' => $dbnow), array('pshare_key_id' => $params['id']));
    return true;
}
开发者ID:plegall,项目名称:Piwigo-private_share,代码行数:17,代码来源:main.inc.php

示例11: ws_categories_setInfo

/**
 * API method
 * Sets details of a category
 * @param mixed[] $params
 *    @option int cat_id
 *    @option string name (optional)
 *    @option string comment (optional)
 */
function ws_categories_setInfo($params, &$service)
{
    $update = array('id' => $params['category_id']);
    $info_columns = array('name', 'comment');
    $perform_update = false;
    foreach ($info_columns as $key) {
        if (isset($params[$key])) {
            $perform_update = true;
            $update[$key] = $params[$key];
        }
    }
    if ($perform_update) {
        single_update(CATEGORIES_TABLE, $update, array('id' => $update['id']));
    }
}
开发者ID:HassenLin,项目名称:piwigo_utf8filename,代码行数:23,代码来源:pwg.categories.php

示例12: add_uploaded_file


//.........这里部分代码省略.........
            if (file_exists($first_file_abspath)) {
                rename($first_file_abspath, $representative_file_abspath);
            }
        }
    }
    //
    // generate pwg_representative in case of video
    //
    $ffmpeg_video_exts = array('wmv', 'mov', 'mkv', 'mp4', 'mpg', 'flv', 'asf', 'xvid', 'divx', 'mpeg', 'avi', 'rm');
    if (isset($original_extension) and in_array($original_extension, $ffmpeg_video_exts)) {
        $representative_file_path = dirname($file_path) . '/pwg_representative/';
        $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.';
        $representative_ext = 'jpg';
        $representative_file_path .= $representative_ext;
        prepare_directory(dirname($representative_file_path));
        $second = 1;
        $ffmpeg = $conf['ffmpeg_dir'] . 'ffmpeg';
        $ffmpeg .= ' -i "' . $file_path . '"';
        $ffmpeg .= ' -an -ss ' . $second;
        $ffmpeg .= ' -t 1 -r 1 -y -vcodec mjpeg -f mjpeg';
        $ffmpeg .= ' "' . $representative_file_path . '"';
        // file_put_contents('/tmp/ffmpeg.log', "\n==== ".date('c')."\n".__FUNCTION__.' : '.$ffmpeg."\n", FILE_APPEND);
        @exec($ffmpeg);
        if (!file_exists($representative_file_path)) {
            $representative_ext = null;
        }
    }
    if (isset($original_extension) and 'pdf' == $original_extension and pwg_image::get_library() == 'ext_imagick') {
        $representative_file_path = dirname($file_path) . '/pwg_representative/';
        $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.';
        $representative_ext = 'jpg';
        $representative_file_path .= $representative_ext;
        prepare_directory(dirname($representative_file_path));
        $exec = $conf['ext_imagick_dir'] . 'convert';
        $exec .= ' -quality 98';
        $exec .= ' "' . realpath($file_path) . '"[0]';
        $dest = pathinfo($representative_file_path);
        $exec .= ' "' . realpath($dest['dirname']) . '/' . $dest['basename'] . '"';
        $exec .= ' 2>&1';
        @exec($exec, $returnarray);
    }
    if (pwg_image::get_library() != 'gd') {
        if ($conf['original_resize']) {
            $need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']);
            if ($need_resize) {
                $img = new pwg_image($file_path);
                $img->pwg_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight'], $conf['original_resize_quality'], $conf['upload_form_automatic_rotation'], false);
                $img->destroy();
            }
        }
    }
    // we need to save the rotation angle in the database to compute
    // width/height of "multisizes"
    $rotation_angle = pwg_image::get_rotation_angle($file_path);
    $rotation = pwg_image::get_rotation_code_from_angle($rotation_angle);
    $file_infos = pwg_image_infos($file_path);
    if (isset($image_id)) {
        $update = array('file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)), 'filesize' => $file_infos['filesize'], 'width' => $file_infos['width'], 'height' => $file_infos['height'], 'md5sum' => $md5sum, 'added_by' => $user['id'], 'rotation' => $rotation);
        if (isset($level)) {
            $update['level'] = $level;
        }
        single_update(IMAGES_TABLE, $update, array('id' => $image_id));
    } else {
        // database registration
        $file = pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path));
        $insert = array('file' => $file, 'name' => get_name_from_file($file), 'date_available' => $dbnow, 'path' => preg_replace('#^' . preg_quote(PHPWG_ROOT_PATH) . '#', '', $file_path), 'filesize' => $file_infos['filesize'], 'width' => $file_infos['width'], 'height' => $file_infos['height'], 'md5sum' => $md5sum, 'added_by' => $user['id'], 'rotation' => $rotation);
        if (isset($level)) {
            $insert['level'] = $level;
        }
        if (isset($representative_ext)) {
            $insert['representative_ext'] = $representative_ext;
        }
        single_insert(IMAGES_TABLE, $insert);
        $image_id = pwg_db_insert_id(IMAGES_TABLE);
    }
    if (isset($categories) and count($categories) > 0) {
        associate_images_to_categories(array($image_id), $categories);
    }
    // update metadata from the uploaded file (exif/iptc)
    if ($conf['use_exif'] and !function_exists('read_exif_data')) {
        $conf['use_exif'] = false;
    }
    sync_metadata(array($image_id));
    invalidate_user_cache();
    // cache thumbnail
    $query = '
SELECT
    id,
    path
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $image_id . '
;';
    $image_infos = pwg_db_fetch_assoc(pwg_query($query));
    set_make_full_url();
    // in case we are on uploadify.php, we have to replace the false path
    $thumb_url = preg_replace('#admin/include/i#', 'i', DerivativeImage::thumb_url($image_infos));
    unset_make_full_url();
    fetchRemote($thumb_url, $dest);
    return $image_id;
}
开发者ID:lcorbasson,项目名称:Piwigo,代码行数:101,代码来源:functions_upload.inc.php

示例13: get_nb_available_comments

/**
 * returns the number of available comments for the connected user
 *
 * @return int
 */
function get_nb_available_comments()
{
    global $user;
    if (!isset($user['nb_available_comments'])) {
        $where = array();
        if (!is_admin()) {
            $where[] = 'validated=\'true\'';
        }
        $where[] = get_sql_condition_FandF(array('forbidden_categories' => 'category_id', 'forbidden_images' => 'ic.image_id'), '', true);
        $query = '
SELECT COUNT(DISTINCT(com.id))
  FROM ' . IMAGE_CATEGORY_TABLE . ' AS ic
    INNER JOIN ' . COMMENTS_TABLE . ' AS com
    ON ic.image_id = com.image_id
  WHERE ' . implode('
    AND ', $where);
        list($user['nb_available_comments']) = pwg_db_fetch_row(pwg_query($query));
        single_update(USER_CACHE_TABLE, array('nb_available_comments' => $user['nb_available_comments']), array('user_id' => $user['id']));
    }
    return $user['nb_available_comments'];
}
开发者ID:squidjam,项目名称:Piwigo,代码行数:26,代码来源:functions.inc.php

示例14: create_virtual_category

/**
 * Create a virtual category.
 *
 * @param string $category_name
 * @param int $parent_id
 * @param array $options
 *    - boolean commentable
 *    - boolean visible
 *    - string status
 *    - string comment
 *    - boolean inherit
 * @return array ('info', 'id') or ('error')
 */
function create_virtual_category($category_name, $parent_id = null, $options = array())
{
    global $conf, $user;
    // is the given category name only containing blank spaces ?
    if (preg_match('/^\\s*$/', $category_name)) {
        return array('error' => l10n('The name of an album must not be empty'));
    }
    $insert = array('name' => $category_name, 'rank' => 0, 'global_rank' => 0);
    // is the album commentable?
    if (isset($options['commentable']) and is_bool($options['commentable'])) {
        $insert['commentable'] = $options['commentable'];
    } else {
        $insert['commentable'] = $conf['newcat_default_commentable'];
    }
    $insert['commentable'] = boolean_to_string($insert['commentable']);
    // is the album temporarily locked? (only visible by administrators,
    // whatever permissions) (may be overwritten if parent album is not
    // visible)
    if (isset($options['visible']) and is_bool($options['visible'])) {
        $insert['visible'] = $options['visible'];
    } else {
        $insert['visible'] = $conf['newcat_default_visible'];
    }
    $insert['visible'] = boolean_to_string($insert['visible']);
    // is the album private? (may be overwritten if parent album is private)
    if (isset($options['status']) and 'private' == $options['status']) {
        $insert['status'] = 'private';
    } else {
        $insert['status'] = $conf['newcat_default_status'];
    }
    // any description for this album?
    if (isset($options['comment'])) {
        $insert['comment'] = $conf['allow_html_descriptions'] ? $options['comment'] : strip_tags($options['comment']);
    }
    if (!empty($parent_id) and is_numeric($parent_id)) {
        $query = '
SELECT id, uppercats, global_rank, visible, status
  FROM ' . CATEGORIES_TABLE . '
  WHERE id = ' . $parent_id . '
;';
        $parent = pwg_db_fetch_assoc(pwg_query($query));
        $insert['id_uppercat'] = $parent['id'];
        $insert['global_rank'] = $parent['global_rank'] . '.' . $insert['rank'];
        // at creation, must a category be visible or not ? Warning : if the
        // parent category is invisible, the category is automatically create
        // invisible. (invisible = locked)
        if ('false' == $parent['visible']) {
            $insert['visible'] = 'false';
        }
        // at creation, must a category be public or private ? Warning : if the
        // parent category is private, the category is automatically create
        // private.
        if ('private' == $parent['status']) {
            $insert['status'] = 'private';
        }
        $uppercats_prefix = $parent['uppercats'] . ',';
    } else {
        $uppercats_prefix = '';
    }
    // we have then to add the virtual category
    single_insert(CATEGORIES_TABLE, $insert);
    $inserted_id = pwg_db_insert_id(CATEGORIES_TABLE);
    single_update(CATEGORIES_TABLE, array('uppercats' => $uppercats_prefix . $inserted_id), array('id' => $inserted_id));
    update_global_rank();
    if ('private' == $insert['status'] and !empty($insert['id_uppercat']) and (isset($options['inherit']) and $options['inherit'] or $conf['inheritance_by_default'])) {
        $query = '
      SELECT group_id
      FROM ' . GROUP_ACCESS_TABLE . '
      WHERE cat_id = ' . $insert['id_uppercat'] . '
    ;';
        $granted_grps = query2array($query, null, 'group_id');
        $inserts = array();
        foreach ($granted_grps as $granted_grp) {
            $inserts[] = array('group_id' => $granted_grp, 'cat_id' => $inserted_id);
        }
        mass_inserts(GROUP_ACCESS_TABLE, array('group_id', 'cat_id'), $inserts);
        $query = '
      SELECT user_id
      FROM ' . USER_ACCESS_TABLE . '
      WHERE cat_id = ' . $insert['id_uppercat'] . '
    ;';
        $granted_users = query2array($query, null, 'user_id');
        add_permission_on_category($inserted_id, array_unique(array_merge(get_admins(), array($user['id']), $granted_users)));
    } elseif ('private' == $insert['status']) {
        add_permission_on_category($inserted_id, array_unique(array_merge(get_admins(), array($user['id']))));
    }
    return array('info' => l10n('Virtual album added'), 'id' => $inserted_id);
//.........这里部分代码省略.........
开发者ID:lcorbasson,项目名称:Piwigo,代码行数:101,代码来源:functions.php

示例15: ws_users_setInfo


//.........这里部分代码省略.........
        }
        // status update query is separated from the rest as not applying to the same
        // set of users (current, guest and webmaster can't be changed)
        $params['user_id_for_status'] = array_diff($params['user_id'], $protected_users);
        $update_status = $params['status'];
    }
    if (!empty($params['level']) or @$params['level'] === 0) {
        if (!in_array($params['level'], $conf['available_permission_levels'])) {
            return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid level');
        }
        $updates_infos['level'] = $params['level'];
    }
    if (!empty($params['language'])) {
        if (!in_array($params['language'], array_keys(get_languages()))) {
            return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid language');
        }
        $updates_infos['language'] = $params['language'];
    }
    if (!empty($params['theme'])) {
        if (!in_array($params['theme'], array_keys(get_pwg_themes()))) {
            return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid theme');
        }
        $updates_infos['theme'] = $params['theme'];
    }
    if (!empty($params['nb_image_page'])) {
        $updates_infos['nb_image_page'] = $params['nb_image_page'];
    }
    if (!empty($params['recent_period']) or @$params['recent_period'] === 0) {
        $updates_infos['recent_period'] = $params['recent_period'];
    }
    if (!empty($params['expand']) or @$params['expand'] === false) {
        $updates_infos['expand'] = boolean_to_string($params['expand']);
    }
    if (!empty($params['show_nb_comments']) or @$params['show_nb_comments'] === false) {
        $updates_infos['show_nb_comments'] = boolean_to_string($params['show_nb_comments']);
    }
    if (!empty($params['show_nb_hits']) or @$params['show_nb_hits'] === false) {
        $updates_infos['show_nb_hits'] = boolean_to_string($params['show_nb_hits']);
    }
    if (!empty($params['enabled_high']) or @$params['enabled_high'] === false) {
        $updates_infos['enabled_high'] = boolean_to_string($params['enabled_high']);
    }
    // perform updates
    single_update(USERS_TABLE, $updates, array($conf['user_fields']['id'] => $params['user_id'][0]));
    if (isset($update_status) and count($params['user_id_for_status']) > 0) {
        $query = '
UPDATE ' . USER_INFOS_TABLE . ' SET
    status = "' . $update_status . '"
  WHERE user_id IN(' . implode(',', $params['user_id_for_status']) . ')
;';
        pwg_query($query);
    }
    if (count($updates_infos) > 0) {
        $query = '
UPDATE ' . USER_INFOS_TABLE . ' SET ';
        $first = true;
        foreach ($updates_infos as $field => $value) {
            if (!$first) {
                $query .= ', ';
            } else {
                $first = false;
            }
            $query .= $field . ' = "' . $value . '"';
        }
        $query .= '
  WHERE user_id IN(' . implode(',', $params['user_id']) . ')
;';
        pwg_query($query);
    }
    // manage association to groups
    if (!empty($params['group_id'])) {
        $query = '
DELETE
  FROM ' . USER_GROUP_TABLE . '
  WHERE user_id IN (' . implode(',', $params['user_id']) . ')
;';
        pwg_query($query);
        // we remove all provided groups that do not really exist
        $query = '
SELECT
    id
  FROM ' . GROUPS_TABLE . '
  WHERE id IN (' . implode(',', $params['group_id']) . ')
;';
        $group_ids = array_from_query($query, 'id');
        // if only -1 (a group id that can't exist) is in the list, then no
        // group is associated
        if (count($group_ids) > 0) {
            $inserts = array();
            foreach ($group_ids as $group_id) {
                foreach ($params['user_id'] as $user_id) {
                    $inserts[] = array('user_id' => $user_id, 'group_id' => $group_id);
                }
            }
            mass_inserts(USER_GROUP_TABLE, array_keys($inserts[0]), $inserts);
        }
    }
    invalidate_user_cache();
    return $service->invoke('pwg.users.getList', array('user_id' => $params['user_id'], 'display' => 'basics,' . implode(',', array_keys($updates_infos))));
}
开发者ID:donseba,项目名称:Piwigo,代码行数:101,代码来源:pwg.users.php


注:本文中的single_update函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。