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']); }
/** Laita kysymys tietokantaan * @param $question_id integer */ function put_question_to_db($question_id) { /* $title string * $body string * $tags string */ if (check_user_status()) { echo "User status pelaa"; $body = pg_escape_string($_POST['question']['body']); $title = pg_escape_string($_POST['question']['title']); $tags = $_POST['question']['tags']; if (validate_input($title, $body, $tags)) { echo "User input pelaa"; $title = $_POST['question']['title']; set_question($question_id); set_tags($question_id); header("Location: /pgCodesS/index.php?" . "question_updated" . "&" . "question_id=" . $question_id . "&" . $title); } else { header("Location: /pgCodesS/index.php?" . "&unsuccessful_new_question"); } } else { header("Location: /pgCodesS/index.php" . "&unsuccessful_new_question"); } }
} 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'])) { $_POST['represent'] = array(); } check_input_parameter('represent', $_POST, true, PATTERN_ID); $no_longer_thumbnail_for = array_diff($represented_albums, $_POST['represent']); if (count($no_longer_thumbnail_for) > 0) { set_random_representant($no_longer_thumbnail_for);
/** * Save picture form * @trigger loc_begin_picture */ function admintools_save_picture() { global $page, $conf, $MultiView, $user, $picture; if (!isset($_GET['delete']) and !isset($_POST['action']) and @$_POST['action'] != 'quick_edit') { return; } $query = 'SELECT added_by FROM ' . IMAGES_TABLE . ' WHERE id = ' . $page['image_id'] . ';'; list($added_by) = pwg_db_fetch_row(pwg_query($query)); if (!$MultiView->is_admin() and $user['id'] != $added_by) { return; } if (isset($_GET['delete']) and get_pwg_token() == @$_GET['pwg_token']) { include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; delete_elements(array($page['image_id']), true); invalidate_user_cache(); if (isset($page['rank_of'][$page['image_id']])) { redirect(duplicate_index_url(array('start' => floor($page['rank_of'][$page['image_id']] / $page['nb_image_page']) * $page['nb_image_page']))); } else { redirect(make_index_url()); } } if ($_POST['action'] == 'quick_edit') { include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; $data = array('name' => $_POST['name'], 'author' => $_POST['author']); if ($MultiView->is_admin()) { $data['level'] = $_POST['level']; } if ($conf['allow_html_descriptions']) { $data['comment'] = @$_POST['comment']; } else { $data['comment'] = strip_tags(@$_POST['comment']); } if (!empty($_POST['date_creation']) and strtotime($_POST['date_creation']) !== false) { $data['date_creation'] = $_POST['date_creation'] . ' ' . $_POST['date_creation_time']; } single_update(IMAGES_TABLE, $data, array('id' => $page['image_id'])); $tag_ids = array(); if (!empty($_POST['tags'])) { $tag_ids = get_tag_ids($_POST['tags']); } set_tags($tag_ids, $page['image_id']); } }
printv('Заканчиваем выполнение задач по дайнному файлу (режим ro)' . N); continue; } if (!$image_file && ($image = $album['image'])) { $image_file = dirname(reset($split_tracks)) . '/cover.jpg'; file_put_contents($image_file, file_get_contents($image)); } } if (isset($args['-st'])) { printv('Заканчиваем выполнение задач по дайнному файлу (режим st)' . N); continue; } $track_key = 0; $split_tracks_dirname = dirname(reset($split_tracks)) . '/'; foreach ($split_tracks as $split_track) { set_tags($split_track, $artist['title'] ? $artist['title'] : $cue_info['artist'], $album['title'] ? $album['title'] : $cue_info['album'], $cue_info['year'], $cue_info['tracks'][$track_key]['title'], $cue_info['tracks'][$track_key]['track'], $cue_info['total'], $cue_info['genre'], $cue_info['comment'], $image_file, $cue_info['disc'], $cue_info['total']); $new_split_track_name = $split_tracks_dirname . sprintf("%02d", $cue_info['tracks'][$track_key]['track']) . ' - ' . $cue_info['tracks'][$track_key]['title'] . '.flac'; rename($split_track, $new_split_track_name); $track_key++; } $artist_dirname = library . ($artist['title'] ? $artist['title'] : $cue_info['artist']); $new_split_track_dirname = $artist_dirname . '/' . $cue_info['year'] . ' - ' . ($album['title'] ? $album['title'] : $cue_info['album']) . ((isset($album['disc']) && $album['disc'] ? $album['disc'] : $cue_info['disc']) !== '' ? ' (CD' . ($album['disc'] ? $album['disc'] : $cue_info['disc']) . ')' : ''); if (!file_exists($artist_dirname)) { printv('Создаем каталог для альбомов исполнителя: ' . $artist_dirname . N); mkdir($artist_dirname); } if (file_exists($new_split_track_dirname)) { if (isset($args['-f'])) { rrmdir($new_split_track_dirname); } else { print 'Ошибка! При обработке файла: ' . $flac_file . N;
$data['comment'] = @$_POST['description-' . $row['id']]; } else { $data['comment'] = strip_tags(@$_POST['description-' . $row['id']]); } if (!empty($_POST['date_creation-' . $row['id']])) { $data['date_creation'] = $_POST['date_creation-' . $row['id']]; } else { $data['date_creation'] = null; } $datas[] = $data; // tags management $tag_ids = array(); if (!empty($_POST['tags-' . $row['id']])) { $tag_ids = get_tag_ids($_POST['tags-' . $row['id']]); } set_tags($tag_ids, $row['id']); } mass_updates(IMAGES_TABLE, array('primary' => array('id'), 'update' => array('name', 'author', 'level', 'comment', 'date_creation')), $datas); $page['infos'][] = l10n('Photo informations updated'); invalidate_user_cache(); } // +-----------------------------------------------------------------------+ // | template init | // +-----------------------------------------------------------------------+ $template->set_filenames(array('batch_manager_unit' => 'batch_manager_unit.tpl')); $base_url = PHPWG_ROOT_PATH . 'admin.php'; $template->assign(array('U_ELEMENTS_PAGE' => $base_url . get_query_string_diff(array('display', 'start')), 'F_ACTION' => $base_url . get_query_string_diff(array()), 'level_options' => get_privacy_level_options())); // +-----------------------------------------------------------------------+ // | global mode thumbnails | // +-----------------------------------------------------------------------+ // how many items to display on this page
/** * Ota uusi kysymys tietokantaan */ function receive_new_question() { /* $question_id integer * $title string * $body string * $tags string */ $body = pg_escape_string($_POST['question']['body']); $title = pg_escape_string($_POST['question']['title']); $tags = $_POST['question']['tags']; /** * Tarkasta sisaankirjaus */ if (check_user_status()) { echo "User status pelaa"; if (validate_input($title, $body, $tags)) { echo "User input pelaa"; $title = $_POST['question']['title']; set_question(); set_tags(); $question_id = get_question_id(); // question must be set before header("Location: /pgCodesS/index.php?" . "question_sent" . "&" . "question_id=" . $question_id . "&" . $title); } else { header("Location: /pgCodesS/index.php?" . "ask_question" . "&unsuccessful_new_question"); } } else { header("Location: /pgCodesS/index.php" . "ask_question" . "&unsuccessful_new_question"); } }
/** * API method * Sets details of an image * @param mixed[] $params * @option int image_id * @option string file (optional) * @option string name (optional) * @option string author (optional) * @option string date_creation (optional) * @option string comment (optional) * @option string categories (optional) - "cat_id[,rank];cat_id[,rank]" * @option string tags_ids (optional) - "tag_id,tag_id" * @option int level (optional) * @option string single_value_mode * @option string multiple_value_mode */ function ws_images_setInfo($params, $service) { include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; $query = ' SELECT * FROM ' . IMAGES_TABLE . ' WHERE id = ' . $params['image_id'] . ' ;'; $result = pwg_query($query); if (pwg_db_num_rows($result) == 0) { return new PwgError(404, 'image_id not found'); } $image_row = pwg_db_fetch_assoc($result); // database registration $update = array(); $info_columns = array('name', 'author', 'comment', 'level', 'date_creation'); foreach ($info_columns as $key) { if (isset($params[$key])) { if ('fill_if_empty' == $params['single_value_mode']) { if (empty($image_row[$key])) { $update[$key] = $params[$key]; } } elseif ('replace' == $params['single_value_mode']) { $update[$key] = $params[$key]; } else { return new PwgError(500, '[ws_images_setInfo]' . ' invalid parameter single_value_mode "' . $params['single_value_mode'] . '"' . ', possible values are {fill_if_empty, replace}.'); } } } if (isset($params['file'])) { if (!empty($image_row['storage_category_id'])) { return new PwgError(500, '[ws_images_setInfo] updating "file" is forbidden on photos added by synchronization'); } $update['file'] = $params['file']; } if (count(array_keys($update)) > 0) { $update['id'] = $params['image_id']; single_update(IMAGES_TABLE, $update, array('id' => $update['id'])); } if (isset($params['categories'])) { ws_add_image_category_relations($params['image_id'], $params['categories'], 'replace' == $params['multiple_value_mode'] ? true : false); } // and now, let's create tag associations if (isset($params['tag_ids'])) { $tag_ids = array(); foreach (explode(',', $params['tag_ids']) as $candidate) { $candidate = trim($candidate); if (preg_match(PATTERN_ID, $candidate)) { $tag_ids[] = $candidate; } } if ('replace' == $params['multiple_value_mode']) { set_tags($tag_ids, $params['image_id']); } elseif ('append' == $params['multiple_value_mode']) { add_tags($tag_ids, array($params['image_id'])); } else { return new PwgError(500, '[ws_images_setInfo]' . ' invalid parameter multiple_value_mode "' . $params['multiple_value_mode'] . '"' . ', possible values are {replace, append}.'); } } invalidate_user_cache(); }