本文整理汇总了PHP中mass_inserts函数 的典型用法代码示例。如果您正苦于以下问题:PHP mass_inserts函数的具体用法?PHP mass_inserts怎么用?PHP mass_inserts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mass_inserts函数 的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: NBMS_Save_Profile
function NBMS_Save_Profile()
{
global $conf, $user;
include_once PHPWG_ROOT_PATH . 'admin/include/functions_notification_by_mail.inc.php';
$query = '
SELECT *
FROM ' . USER_MAIL_NOTIFICATION_TABLE . '
WHERE user_id = \'' . $user['id'] . '\'
';
$count = pwg_db_num_rows(pwg_query($query));
if ($count == 0) {
$inserts = array();
$check_key_list = array();
// Calculate key
$nbm_user['check_key'] = find_available_check_key();
// Save key
array_push($check_key_list, $nbm_user['check_key']);
// Insert new nbm_users
array_push($inserts, array('user_id' => $user['id'], 'check_key' => $nbm_user['check_key'], 'enabled' => $_POST['NBM_Subscription']));
mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts);
} elseif ($count != 0 and !empty($_POST['NBM_Subscription']) && in_array($_POST['NBM_Subscription'], array('true', 'false'))) {
$query = '
UPDATE ' . USER_MAIL_NOTIFICATION_TABLE . '
SET enabled = \'' . $_POST['NBM_Subscription'] . '\'
WHERE user_id = \'' . $user['id'] . '\';';
pwg_query($query);
}
}
开发者ID:Eric-Piwigo, 项目名称:NBM_Subscriber, 代码行数:28, 代码来源:main.inc.php
示例2: 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
示例3: array
}
$insert = array('id' => $next_element_id++, 'file' => $filename, 'name' => get_name_from_file($filename), 'date_available' => CURRENT_DATE, 'path' => $path, 'representative_ext' => $fs[$path]['representative_ext'], 'storage_category_id' => $db_fulldirs[$dirname], 'added_by' => $user['id']);
if ($_POST['privacy_level'] != 0) {
$insert['level'] = $_POST['privacy_level'];
}
$inserts[] = $insert;
$insert_links[] = array('image_id' => $insert['id'], 'category_id' => $insert['storage_category_id']);
$infos[] = array('path' => $insert['path'], 'info' => l10n('added'));
$caddiables[] = $insert['id'];
}
if (count($inserts) > 0) {
if (!$simulate) {
// inserts all new elements
mass_inserts(IMAGES_TABLE, array_keys($inserts[0]), $inserts);
// inserts all links between new elements and their storage category
mass_inserts(IMAGE_CATEGORY_TABLE, array_keys($insert_links[0]), $insert_links);
// add new photos to caddie
if (isset($_POST['add_to_caddie']) and $_POST['add_to_caddie'] == 1) {
fill_caddie($caddiables);
}
}
$counts['new_elements'] = count($inserts);
}
// delete elements that are in database but not in the filesystem
$to_delete_elements = array();
foreach (array_diff($db_elements, array_keys($fs)) as $path) {
$to_delete_elements[] = array_search($path, $db_elements);
$infos[] = array('path' => $path, 'info' => l10n('deleted'));
}
if (count($to_delete_elements) > 0) {
if (!$simulate) {
开发者ID:squidjam, 项目名称:Piwigo, 代码行数:31, 代码来源:site_update.php
示例4: unset
if (isset($need_update[$key])) {
$row['nb_pages'] += $need_update[$key];
$updates[] = $row;
unset($need_update[$key]);
}
}
}
foreach ($need_update as $time_key => $nb_pages) {
$time_tokens = explode('-', $time_key);
$inserts[] = array('year' => $time_tokens[0], 'month' => @$time_tokens[1], 'day' => @$time_tokens[2], 'hour' => @$time_tokens[3], 'nb_pages' => $nb_pages);
}
if (count($updates) > 0) {
mass_updates(HISTORY_SUMMARY_TABLE, array('primary' => array('year', 'month', 'day', 'hour'), 'update' => array('nb_pages')), $updates);
}
if (count($inserts) > 0) {
mass_inserts(HISTORY_SUMMARY_TABLE, array_keys($inserts[0]), $inserts);
}
if ($max_id != 0) {
$query = '
UPDATE ' . HISTORY_TABLE . '
SET summarized = \'true\'
WHERE summarized = \'false\'
AND id <= ' . $max_id . '
;';
pwg_query($query);
}
// +-----------------------------------------------------------------------+
// | Page parameters check |
// +-----------------------------------------------------------------------+
foreach (array('day', 'month', 'year') as $key) {
if (isset($_GET[$key])) {
开发者ID:lcorbasson, 项目名称:Piwigo, 代码行数:31, 代码来源:stats.php
示例5: create_user_infos
/**
* Creates user informations based on default values.
*
* @param int|int[] $user_ids
* @param array $override_values values used to override default user values
*/
function create_user_infos($user_ids, $override_values = null)
{
global $conf;
if (!is_array($user_ids)) {
$user_ids = array($user_ids);
}
if (!empty($user_ids)) {
$inserts = array();
list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
$default_user = get_default_user_info(false);
if ($default_user === false) {
// Default on structure are used
$default_user = array();
}
if (!is_null($override_values)) {
$default_user = array_merge($default_user, $override_values);
}
foreach ($user_ids as $user_id) {
$level = isset($default_user['level']) ? $default_user['level'] : 0;
if ($user_id == $conf['webmaster_id']) {
$status = 'webmaster';
$level = max($conf['available_permission_levels']);
} elseif ($user_id == $conf['guest_id'] or $user_id == $conf['default_user_id']) {
$status = 'guest';
} else {
$status = 'normal';
}
$insert = array_merge($default_user, array('user_id' => $user_id, 'status' => $status, 'registration_date' => $dbnow, 'level' => $level));
$inserts[] = $insert;
}
mass_inserts(USER_INFOS_TABLE, array_keys($inserts[0]), $inserts);
}
}
开发者ID:lcorbasson, 项目名称:Piwigo, 代码行数:39, 代码来源:functions_user.inc.php
示例6: pwg_query
$res = pwg_query($query);
while ($row = pwg_db_fetch_assoc($res)) {
$grp_access[] = array('cat_id' => $row['cat_id'], 'group_id' => $groupid);
}
mass_inserts(GROUP_ACCESS_TABLE, array('group_id', 'cat_id'), $grp_access);
$query = '
SELECT *
FROM ' . USER_GROUP_TABLE . '
WHERE group_id = ' . $group . '
;';
$usr_grp = array();
$res = pwg_query($query);
while ($row = pwg_db_fetch_assoc($res)) {
$usr_grp[] = array('user_id' => $row['user_id'], 'group_id' => $groupid);
}
mass_inserts(USER_GROUP_TABLE, array('user_id', 'group_id'), $usr_grp);
$page['infos'][] = l10n('group "%s" added', $_POST['duplicate_' . $group . '']);
}
}
// +
// | toggle_default
// +
if ($action == "toggle_default") {
foreach ($groups as $group) {
$query = '
SELECT name, is_default
FROM ' . GROUPS_TABLE . '
WHERE id = ' . $group . '
;';
list($groupname, $is_default) = pwg_db_fetch_row(pwg_query($query));
// update of the group
开发者ID:donseba, 项目名称:Piwigo, 代码行数:31, 代码来源:group_list.php
示例7: ws_caddie_add
/**
* API method
* Adds images to the caddie
* @param mixed[] $params
* @option int[] image_id
*/
function ws_caddie_add($params, &$service)
{
global $user;
$query = '
SELECT id
FROM ' . IMAGES_TABLE . '
LEFT JOIN ' . CADDIE_TABLE . '
ON id=element_id AND user_id=' . $user['id'] . '
WHERE id IN (' . implode(',', $params['image_id']) . ')
AND element_id IS NULL
;';
$result = array_from_query($query, 'id');
$datas = array();
foreach ($result as $id) {
$datas[] = array('element_id' => $id, 'user_id' => $user['id']);
}
if (count($datas)) {
mass_inserts(CADDIE_TABLE, array('element_id', 'user_id'), $datas);
}
return count($datas);
}
开发者ID:donseba, 项目名称:Piwigo, 代码行数:27, 代码来源:pwg.php
示例8: fill_caddie
/**
* fill the current user caddie with given elements, if not already in caddie
*
* @param int[] $elements_id
*/
function fill_caddie($elements_id)
{
global $user;
$query = '
SELECT element_id
FROM ' . CADDIE_TABLE . '
WHERE user_id = ' . $user['id'] . '
;';
$in_caddie = query2array($query, null, 'element_id');
$caddiables = array_diff($elements_id, $in_caddie);
$datas = array();
foreach ($caddiables as $caddiable) {
$datas[] = array('element_id' => $caddiable, 'user_id' => $user['id']);
}
if (count($caddiables) > 0) {
mass_inserts(CADDIE_TABLE, array('element_id', 'user_id'), $datas);
}
}
开发者ID:squidjam, 项目名称:Piwigo, 代码行数:23, 代码来源:functions.inc.php
示例9: ws_permissions_add
/**
* API method
* Add permissions
* @param mixed[] $params
* @option int[] cat_id
* @option int[] group_id (optional)
* @option int[] user_id (optional)
* @option bool recursive
*/
function ws_permissions_add($params, &$service)
{
if (get_pwg_token() != $params['pwg_token']) {
return new PwgError(403, 'Invalid security token');
}
include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
if (!empty($params['group_id'])) {
$cat_ids = get_uppercat_ids($params['cat_id']);
if ($params['recursive']) {
$cat_ids = array_merge($cat_ids, get_subcat_ids($params['cat_id']));
}
$query = '
SELECT id
FROM ' . CATEGORIES_TABLE . '
WHERE id IN (' . implode(',', $cat_ids) . ')
AND status = \'private\'
;';
$private_cats = array_from_query($query, 'id');
$inserts = array();
foreach ($private_cats as $cat_id) {
foreach ($params['group_id'] as $group_id) {
$inserts[] = array('group_id' => $group_id, 'cat_id' => $cat_id);
}
}
mass_inserts(GROUP_ACCESS_TABLE, array('group_id', 'cat_id'), $inserts, array('ignore' => true));
}
if (!empty($params['user_id'])) {
if ($params['recursive']) {
$_POST['apply_on_sub'] = true;
}
add_permission_on_category($params['cat_id'], $params['user_id']);
}
return $service->invoke('pwg.permissions.getList', array('cat_id' => $params['cat_id']));
}
开发者ID:squidjam, 项目名称:Piwigo, 代码行数:43, 代码来源:pwg.permissions.php
示例10: insert_new_data_user_mail_notification
function insert_new_data_user_mail_notification()
{
global $conf, $page, $env_nbm;
// Set null mail_address empty
$query = '
update
' . USERS_TABLE . '
set
' . $conf['user_fields']['email'] . ' = null
where
trim(' . $conf['user_fields']['email'] . ') = \'\';';
pwg_query($query);
// null mail_address are not selected in the list
$query = '
select
u.' . $conf['user_fields']['id'] . ' as user_id,
u.' . $conf['user_fields']['username'] . ' as username,
u.' . $conf['user_fields']['email'] . ' as mail_address
from
' . USERS_TABLE . ' as u left join ' . USER_MAIL_NOTIFICATION_TABLE . ' as m on u.' . $conf['user_fields']['id'] . ' = m.user_id
where
u.' . $conf['user_fields']['email'] . ' is not null and
m.user_id is null
order by
user_id;';
$result = pwg_query($query);
if (pwg_db_num_rows($result) > 0) {
$inserts = array();
$check_key_list = array();
while ($nbm_user = pwg_db_fetch_assoc($result)) {
// Calculate key
$nbm_user['check_key'] = find_available_check_key();
// Save key
$check_key_list[] = $nbm_user['check_key'];
// Insert new nbm_users
$inserts[] = array('user_id' => $nbm_user['user_id'], 'check_key' => $nbm_user['check_key'], 'enabled' => 'false');
$page['infos'][] = l10n('User %s [%s] added.', stripslashes($nbm_user['username']), $nbm_user['mail_address']);
}
// Insert new nbm_users
mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts);
// Update field enabled with specific function
$check_key_treated = do_subscribe_unsubscribe_notification_by_mail(true, $conf['nbm_default_value_user_enabled'], $check_key_list);
// On timeout simulate like tabsheet send
if ($env_nbm['is_sendmail_timeout']) {
$quoted_check_key_list = quote_check_key_list(array_diff($check_key_list, $check_key_treated));
if (count($quoted_check_key_list) != 0) {
$query = 'delete from ' . USER_MAIL_NOTIFICATION_TABLE . ' where check_key in (' . implode(",", $quoted_check_key_list) . ');';
$result = pwg_query($query);
redirect($base_url . get_query_string_diff(array(), false), l10n('Operation in progress') . "\n" . l10n('Please wait...'));
}
}
}
}
开发者ID:donseba, 项目名称:Piwigo, 代码行数:53, 代码来源:notification_by_mail.php
示例11: die
// | USA. |
// +-----------------------------------------------------------------------+
if (!defined('PHOTOS_ADD_BASE_URL')) {
die("Hacking attempt!");
}
// +-----------------------------------------------------------------------+
// | batch management request |
// +-----------------------------------------------------------------------+
if (isset($_GET['batch'])) {
check_input_parameter('batch', $_GET, false, '/^\\d+(,\\d+)*$/');
$query = '
DELETE FROM ' . CADDIE_TABLE . '
WHERE user_id = ' . $user['id'] . '
;';
pwg_query($query);
$inserts = array();
foreach (explode(',', $_GET['batch']) as $image_id) {
$inserts[] = array('user_id' => $user['id'], 'element_id' => $image_id);
}
mass_inserts(CADDIE_TABLE, array_keys($inserts[0]), $inserts);
redirect(get_root_url() . 'admin.php?page=batch_manager&filter=prefilter-caddie');
}
// +-----------------------------------------------------------------------+
// | prepare form |
// +-----------------------------------------------------------------------+
include_once PHPWG_ROOT_PATH . 'admin/include/photos_add_direct_prepare.inc.php';
// +-----------------------------------------------------------------------+
// | sending html code |
// +-----------------------------------------------------------------------+
trigger_notify('loc_end_photo_add_direct');
$template->assign_var_from_handle('ADMIN_CONTENT', 'photos_add');
开发者ID:donseba, 项目名称:Piwigo, 代码行数:31, 代码来源:photos_add_direct.php
示例12: ws_groups_addUser
/**
* API method
* Adds user(s) to a group
* @param mixed[] $params
* @option int group_id
* @option int[] user_id
*/
function ws_groups_addUser($params, &$service)
{
if (get_pwg_token() != $params['pwg_token']) {
return new PwgError(403, 'Invalid security token');
}
// does the group exist ?
$query = '
SELECT COUNT(*)
FROM ' . GROUPS_TABLE . '
WHERE id = ' . $params['group_id'] . '
;';
list($count) = pwg_db_fetch_row(pwg_query($query));
if ($count == 0) {
return new PwgError(WS_ERR_INVALID_PARAM, 'This group does not exist.');
}
$inserts = array();
foreach ($params['user_id'] as $user_id) {
$inserts[] = array('group_id' => $params['group_id'], 'user_id' => $user_id);
}
mass_inserts(USER_GROUP_TABLE, array('group_id', 'user_id'), $inserts, array('ignore' => true));
include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
invalidate_user_cache();
return $service->invoke('pwg.groups.getList', array('group_id' => $params['group_id']));
}
开发者ID:lcorbasson, 项目名称:Piwigo, 代码行数:31, 代码来源:pwg.groups.php
示例13: foreach
}
foreach ($indexes_of[$table] as $index_name => $index) {
if (!in_array($index_name, $existing_indexes)) {
$query = '
ALTER TABLE ' . PREFIX_TABLE . $table . '
ADD ' . ($index['unique'] ? 'UNIQUE' : 'INDEX') . ' ' . $index_name . ' (' . implode(',', $index['columns']) . ')
;';
pwg_query($query);
}
}
}
//
// insert params in new configuration table
//
$params = array(array('param' => 'prefix_thumbnail', 'value' => $save['prefix_thumbnail'], 'comment' => 'thumbnails filename prefix'), array('param' => 'mail_webmaster', 'value' => $save['mail_webmaster'], 'comment' => 'webmaster mail'), array('param' => 'default_language', 'value' => 'en_UK.iso-8859-1', 'comment' => 'Default gallery language'), array('param' => 'default_template', 'value' => 'default', 'comment' => 'Default gallery style'), array('param' => 'default_maxwidth', 'value' => '', 'comment' => 'maximum width authorized for displaying images'), array('param' => 'default_maxheight', 'value' => '', 'comment' => 'maximum height authorized for the displaying images'), array('param' => 'nb_comment_page', 'value' => '10', 'comment' => 'number of comments to display on each page'), array('param' => 'upload_maxfilesize', 'value' => '150', 'comment' => 'maximum filesize for the uploaded pictures'), array('param' => 'upload_maxwidth', 'value' => '800', 'comment' => 'maximum width authorized for the uploaded images'), array('param' => 'upload_maxheight', 'value' => '600', 'comment' => 'maximum height authorized for the uploaded images'), array('param' => 'upload_maxwidth_thumbnail', 'value' => '150', 'comment' => 'maximum width authorized for the uploaded thumbnails'), array('param' => 'upload_maxheight_thumbnail', 'value' => '100', 'comment' => 'maximum height authorized for the uploaded thumbnails'), array('param' => 'log', 'value' => 'false', 'comment' => 'keep an history of visits on your website'), array('param' => 'comments_validation', 'value' => 'false', 'comment' => 'administrators validate users comments before becoming visible'), array('param' => 'comments_forall', 'value' => 'false', 'comment' => 'even guest not registered can post comments'), array('param' => 'mail_notification', 'value' => 'false', 'comment' => 'automated mail notification for adminsitrators'), array('param' => 'nb_image_line', 'value' => '5', 'comment' => 'Number of images displayed per row'), array('param' => 'nb_line_page', 'value' => '3', 'comment' => 'Number of rows displayed per page'), array('param' => 'recent_period', 'value' => '7', 'comment' => 'Period within which pictures are displayed as new (in days)'), array('param' => 'auto_expand', 'value' => 'false', 'comment' => 'Auto expand of the category tree'), array('param' => 'show_nb_comments', 'value' => 'false', 'comment' => 'Show the number of comments under the thumbnails'), array('param' => 'use_iptc', 'value' => 'false', 'comment' => 'Use IPTC data during database synchronization with files metadata'), array('param' => 'use_exif', 'value' => 'false', 'comment' => 'Use EXIF data during database synchronization with files metadata'), array('param' => 'show_iptc', 'value' => 'false', 'comment' => 'Show IPTC metadata on picture.php if asked by user'), array('param' => 'show_exif', 'value' => 'true', 'comment' => 'Show EXIF metadata on picture.php if asked by user'), array('param' => 'authorize_remembering', 'value' => 'true', 'comment' => 'Authorize users to be remembered, see $conf{remember_me_length}'), array('param' => 'gallery_locked', 'value' => 'false', 'comment' => 'Lock your gallery temporary for non admin users'));
mass_inserts(CONFIG_TABLE, array_keys($params[0]), $params);
// refresh calculated datas
update_global_rank();
update_category();
// update calculated field "images.path"
$cat_ids = array();
$query = '
SELECT DISTINCT(storage_category_id) AS unique_storage_category_id
FROM ' . IMAGES_TABLE . '
;';
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result)) {
array_push($cat_ids, $row['unique_storage_category_id']);
}
$fulldirs = get_fulldirs($cat_ids);
foreach ($cat_ids as $cat_id) {
开发者ID:squidjam, 项目名称:Piwigo, 代码行数:31, 代码来源:upgrade_1.3.1.php
示例14: hash_from_query
<?php
$show_form = true;
if (isset($_POST['image_id'])) {
if (!preg_match('#^[0-9]+$#', $_POST['image_id'])) {
echo '<h3>Incorrect image Id</h3><br>';
} else {
$query = '
SELECT * FROM ' . COMMENTS_TABLE . '
WHERE image_id = ' . $_POST['image_id'] . '
;';
$comms = hash_from_query($query, 'id');
if (!count($comms)) {
echo '<h3>No comments for this picture</h3><br>';
} else {
mass_inserts(GUESTBOOK_TABLE, array('date', 'author', 'author_id', 'anonymous_id', 'email', 'website', 'content', 'rate', 'validated', 'validation_date'), $comms);
echo '<h3>' . count($comms) . ' comments imported into the Guestbook</h3><br>';
$show_form = false;
}
}
}
if ($show_form) {
?>
Just enter the ID of your old guestbook picture (the ID can be found a the picture edition page, near the thumbnail) and click the <b>import</b> button.
<form action="" method="post">
<label>Image ID : <input type="text" size="5" name="image_id"></label><br>
<input type="submit" value="import">
</form>
<?php
}
开发者ID:plegall, 项目名称:Piwigo-Guest-Book, 代码行数:30, 代码来源:import_tool.php
示例15: array_from_query
$image_ids = array_from_query($query, 'image_id');
delete_tags($tag_ids_to_delete);
$query = '
SELECT
image_id
FROM ' . IMAGE_TAG_TABLE . '
WHERE tag_id = ' . $destination_tag_id . '
;';
$destination_tag_image_ids = array_from_query($query, 'image_id');
$image_ids_to_link = array_diff($image_ids, $destination_tag_image_ids);
$inserts = array();
foreach ($image_ids_to_link as $image_id) {
$inserts[] = array('tag_id' => $destination_tag_id, 'image_id' => $image_id);
}
if (count($inserts) > 0) {
mass_inserts(IMAGE_TAG_TABLE, array_keys($inserts[0]), $inserts);
}
$tags_deleted = array();
foreach ($tag_ids_to_delete as $tag_id) {
$tags_deleted[] = $name_of_tag[$tag_id];
}
$page['infos'][] = l10n('Tags <em>%s</em> merged into tag <em>%s</em>', implode(', ', $tags_deleted), $name_of_tag[$destination_tag_id]);
}
}
}
// +-----------------------------------------------------------------------+
// | delete tags |
// +-----------------------------------------------------------------------+
if (isset($_POST['delete']) and isset($_POST['tags'])) {
$query = '
SELECT name
开发者ID:donseba, 项目名称:Piwigo, 代码行数:31, 代码来源:tags.php
示例16: ws_add_image_category_relations
/**
* Sets associations of an image
* @param int $image_id
* @param string $categories_string - "cat_id[,rank];cat_id[,rank]"
* @param bool $replace_mode - removes old associations
*/
function ws_add_image_category_relations($image_id, $categories_string, $replace_mode = false)
{
// let's add links between the image and the categories
//
// $params['categories'] should look like 123,12;456,auto;789 which means:
//
// 1. associate with category 123 on rank 12
// 2. associate with category 456 on automatic rank
// 3. associate with category 789 on automatic rank
$cat_ids = array();
$rank_on_category = array();
$search_current_ranks = false;
$tokens = explode(';', $categories_string);
foreach ($tokens as $token) {
@(list($cat_id, $rank) = explode(',', $token));
if (!preg_match('/^\\d+$/', $cat_id)) {
continue;
}
$cat_ids[] = $cat_id;
if (!isset($rank)) {
$rank = 'auto';
}
$rank_on_category[$cat_id] = $rank;
if ($rank == 'auto') {
$search_current_ranks = true;
}
}
$cat_ids = array_unique($cat_ids);
if (count($cat_ids) == 0) {
return new PwgError(500, '[ws_add_image_category_relations] there is no category defined in "' . $categories_string . '"');
}
$query = '
SELECT id
FROM ' . CATEGORIES_TABLE . '
WHERE id IN (' . implode(',', $cat_ids) . ')
;';
$db_cat_ids = query2array($query, null, 'id');
$unknown_cat_ids = array_diff($cat_ids, $db_cat_ids);
if (count($unknown_cat_ids) != 0) {
return new PwgError(500, '[ws_add_image_category_relations] the following categories are unknown: ' . implode(', ', $unknown_cat_ids));
}
$to_update_cat_ids = array();
// in case of replace mode, we first check the existing associations
$query = '
SELECT category_id
FROM ' . IMAGE_CATEGORY_TABLE . '
WHERE image_id = ' . $image_id . '
;';
$existing_cat_ids = query2array($query, null, 'category_id');
if ($replace_mode) {
$to_remove_cat_ids = array_diff($existing_cat_ids, $cat_ids);
if (count($to_remove_cat_ids) > 0) {
$query = '
DELETE
FROM ' . IMAGE_CATEGORY_TABLE . '
WHERE image_id = ' . $image_id . '
AND category_id IN (' . implode(', ', $to_remove_cat_ids) . ')
;';
pwg_query($query);
update_category($to_remove_cat_ids);
}
}
$new_cat_ids = array_diff($cat_ids, $existing_cat_ids);
if (count($new_cat_ids) == 0) {
return true;
}
if ($search_current_ranks) {
$query = '
SELECT category_id, MAX(rank) AS max_rank
FROM ' . IMAGE_CATEGORY_TABLE . '
WHERE rank IS NOT NULL
AND category_id IN (' . implode(',', $new_cat_ids) . ')
GROUP BY category_id
;';
$current_rank_of = query2array($query, 'category_id', 'max_rank');
foreach ($new_cat_ids as $cat_id) {
if (!isset($current_rank_of[$cat_id])) {
$current_rank_of[$cat_id] = 0;
}
if ('auto' == $rank_on_category[$cat_id]) {
$rank_on_category[$cat_id] = $current_rank_of[$cat_id] + 1;
}
}
}
$inserts = array();
foreach ($new_cat_ids as $cat_id) {
$inserts[] = array('image_id' => $image_id, 'category_id' => $cat_id, 'rank' => $rank_on_category[$cat_id]);
}
mass_inserts(IMAGE_CATEGORY_TABLE, array_keys($inserts[0]), $inserts);
include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
update_category($new_cat_ids);
}
开发者ID:nikrou, 项目名称:Piwigo, 代码行数:98, 代码来源:pwg.images.php
示例17: tag_replace_keywords
/**
* replace old style #images.keywords by #tags. Requires a big data
* migration.
*
* @return void
*/
function tag_replace_keywords()
{
// code taken from upgrades 19 and 22
$query = '
CREATE TABLE ' . PREFIX_TABLE . 'tags (
id smallint(5) UNSIGNED NOT NULL auto_increment,
name varchar(255) BINARY NOT NULL,
url_name varchar(255) BINARY NOT NULL,
PRIMARY KEY (id)
)
;';
pwg_query($query);
$query = '
CREATE TABLE ' . PREFIX_TABLE . 'image_tag (
image_id mediumint(8) UNSIGNED NOT NULL,
tag_id smallint(5) UNSIGNED NOT NULL,
PRIMARY KEY (image_id,tag_id)
)
;';
pwg_query($query);
//
// Move keywords to tags
//
// each tag label is associated to a numeric identifier
$tag_id = array();
// to each tag id (key) a list of image ids (value) is associated
$tag_images = array();
$current_id = 1;
$query = '
SELECT id, keywords
FROM ' . PREFIX_TABLE . 'images
WHERE keywords IS NOT NULL
;';
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result)) {
foreach (preg_split('/[,]+/', $row['keywords']) as $keyword) {
if (!isset($tag_id[$keyword])) {
$tag_id[$keyword] = $current_id++;
}
if (!isset($tag_images[$tag_id[$keyword]])) {
$tag_images[$tag_id[$keyword]] = array();
}
array_push($tag_images[$tag_id[$keyword]], $row['id']);
}
}
$datas = array();
foreach ($tag_id as $tag_name => $tag_id) {
array_push($datas, array('id' => $tag_id, 'name' => $tag_name, 'url_name' => str2url($tag_name)));
}
if (!empty($datas)) {
mass_inserts(PREFIX_TABLE . 'tags', array_keys($datas[0]), $datas);
}
$datas = array();
foreach ($tag_images as $tag_id => $images) {
foreach (array_unique($images) as $image_id) {
array_push($datas, array('tag_id' => $tag_id, 'image_id' => $image_id));
}
}
if (!empty($datas)) {
mass_inserts(PREFIX_TABLE . 'image_tag', array_keys($datas[0]), $datas);
}
//
// Delete images.keywords
//
$query = '
ALTER TABLE ' . PREFIX_TABLE . 'images DROP COLUMN keywords
;';
pwg_query($query);
//
// Add useful indexes
//
$query = '
ALTER TABLE ' . PREFIX_TABLE . 'tags
ADD INDEX tags_i1(url_name)
;';
pwg_query($query);
$query = '
ALTER TABLE ' . PREFIX_TABLE . 'image_tag
ADD INDEX image_tag_i1(tag_id)
;';
pwg_query($query);
// print_time('tags have replaced keywords');
}
开发者ID:squidjam, 项目名称:Piwigo, 代码行数:89, 代码来源:upgrade_1.5.0.php
示例18: 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
示例19: mass_updates
/**
* updates multiple lines in a table
*
* @param string table_name
* @param array dbfields
* @param array datas
* @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones
* @return void
*/
function mass_updates($tablename, $dbfields, $datas, $flags = 0)
{
if (count($datas) == 0) {
return;
}
// depending on the MySQL version, we use the multi table update or N update queries
if (count($datas) < 10) {
foreach ($datas as $data) {
$query = '
UPDATE ' . $tablename . '
SET ';
$is_first = true;
foreach ($dbfields['update'] as $key) {
$separator = $is_first ? '' : ",\n ";
if (isset($data[$key]) and $data[$key] != '') {
$query .= $separator . $key . ' = \'' . $data[$key] . '\'';
} else {
if ($flags & MASS_UPDATES_SKIP_EMPTY) {
continue;
}
// next field
$query .= "{$separator}{$key} = NULL";
}
$is_first = false;
}
if (!$is_first) {
// only if one field at least updated
$query .= '
WHERE ';
$is_first = true;
foreach ($dbfields['primary'] as $key) {
if (!$is_first) {
$query .= ' AND ';
}
if (isset($data[$key])) {
$query .= $key . ' = \'' . $data[$key] . '\'';
} else {
$query .= $key . ' IS NULL';
}
$is_first = false;
}
pwg_query($query);
}
}
// foreach update
} else {
// creation of the temporary table
$query = '
SHOW FULL COLUMNS FROM ' . $tablename;
$result = pwg_query($query);
$columns = array();
$all_fields = array_merge($dbfields['primary'], $dbfields['update']);
while ($row = pwg_db_fetch_assoc($result)) {
if (in_array($row['Field'], $all_fields)) {
$column = $row['Field'];
$column .= ' ' . $row['Type'];
$nullable = true;
if (!isset($row['Null']) or $row['Null'] == '' or $row['Null'] == 'NO') {
$column .= ' NOT NULL';
$nullable = false;
}
if (isset($row['Default'])) {
$column .= " default '" . $row['Default'] . "'";
} elseif ($nullable) {
$column .= " default NULL";
}
if (isset($row['Collation']) and $row['Collation'] != 'NULL') {
$column .= " collate '" . $row['Collation'] . "'";
}
$columns[] = $column;
}
}
$temporary_tablename = $tablename . '_' . micro_seconds();
$query = '
CREATE TABLE ' . $temporary_tablename . '
(
' . implode(",\n ", $columns) . ',
UNIQUE KEY the_key (' . implode(',', $dbfields['primary']) . ')
)';
pwg_query($query);
mass_inserts($temporary_tablename, $all_fields, $datas);
if ($flags & MASS_UPDATES_SKIP_EMPTY) {
$func_set = create_function('$s', 'return "t1.$s = IFNULL(t2.$s, t1.$s)";');
} else {
$func_set = create_function('$s', 'return "t1.$s = t2.$s";');
}
// update of images table by joining with temporary table
$query = '
UPDATE ' . $tablename . ' AS t1, ' . $temporary_tablename . ' AS t2
SET ' . implode("\n , ", array_map($func_set, $dbfields['update'])) . '
WHERE ' . implode("\n AND ", array_map(create_function('$s', 'return "t1.$s = t2.$s";'), $dbfields['primary']));
//.........这里部分代码省略.........
开发者ID:squidjam, 项目名称:Piwigo, 代码行数:101, 代码来源:functions_mysql.inc.php
示例20: c13y_correction_user
GaloyMoney/galoy-mobile
阅读:743| 2022-08-30
LibraryBox-Dev/LibraryBox-core: PirateBox Core scripts modification and build st
阅读:630| 2022-08-15
swcarpentry/matlab-novice-inflammation: Programming with MATLAB
阅读:656| 2022-08-17
三一学院是美国最古老的院校之一,建于1823年,是康涅迪格州的第二所大学,也是经过新
阅读:897| 2022-11-06
Twzy/MarkWord: a markdown editer
阅读:588| 2022-08-18
A missing permission check in Jenkins OpenShift Deployer Plugin 1.2.0 and earlie
阅读:789| 2022-07-29
hidjou/classsed-react-localization
阅读:358| 2022-08-15
出去游玩,遇到马蜂是很司空见惯的事情,很多人都有被马蜂蛰过的经历,被马蜂蜇可大可
阅读:224| 2022-11-06
sunxu/mastodon
阅读:638| 2022-08-18
In libtirpc before 1.3.3rc1, remote attackers could exhaust the file descriptors
阅读:581| 2022-07-29
请发表评论