function getAvatar($small = true) { $image_id = $this->data['avatar']; if ($small) { return ImgStore::getUrl($image_id, Config::SIZES_AVATAR_SMALL); } else { return ImgStore::getUrl($image_id, Config::SIZES_AVATAR_NORMAL); } }
<pre><?php $dev_mode = 1; $core_path = 'core/'; ini_set('display_errors', $dev_mode); require_once $core_path . 'config.php'; require_once $core_path . 'include.php'; if (isset($_POST['x'])) { echo date('Y-m-d H:i:s') . "\n"; //$props = ImgStore::getImageProperties($_FILES['photo']['tmp_name'], $full = true); //dpe($props); $image_id = ImgStore::upload($_FILES['photo']['tmp_name'], array(1 => '100x100x0', 2 => '500x500x1', 3 => '250x250x1')); echo date('Y-m-d H:i:s') . "\n"; echo '<img src="' . ImgStore::getUrl($image_id, 0) . '">' . "\n"; echo '<img src="' . ImgStore::getUrl($image_id, 1) . '">' . "\n"; } ?> <form enctype="multipart/form-data" method="post"> <input type="hidden" name="x"> <input type="file" name="photo" > <input type="submit"> </form>
if ($amazon_fetch) { // fetch from amazon $fetch_url = ImgStore::getUrl($image['image_id'], $image['size_id'], 0); $real_private_path = ImgStore::getFileLocalPath($image['image_id'], $image['size_id'], $private = true); log_('fetching ' . $fetch_url . ' to ' . $real_private_path); file_put_contents($real_private_path, file_get_contents($fetch_url)); log_($image['bytes'] . '=db size,' . filesize($real_private_path) . '=real size copied'); if (filesize($real_private_path)) { $amazon_dest = str_replace(ImgStore::$server_urls[ImgStore::SERVER_AMAZONS3], '', $fetch_url); $res = Amazon::delete($amazon_dest); log_('deleted ' . $amazon_dest . ' from amazon with code:' . $res); Database::query('UPDATE `images` SET `server_id`=' . ImgStore::SERVER_PRIVATE . ', `private_real`=1 WHERE `id`=' . $image['id']); } } else { // get from local file, delete amazon copy $amazon_dest = str_replace(ImgStore::$server_urls[ImgStore::SERVER_AMAZONS3], '', ImgStore::getUrl($image['image_id'], $image['size_id'], 0)); $res = Amazon::delete($amazon_dest); log_('deleted ' . $amazon_dest . ' from amazon with code:' . $res); // $real_path = ImgStore::getFileLocalPath($image['image_id'], $image['size_id']); log_($image['id'] . ' at original server in ' . $real_path . ' ' . filesize($real_path) . ' bytes'); // change location to private folder $real_private_path = ImgStore::getFileLocalPath($image['image_id'], $image['size_id'], $private = true); log_('will be moved to ' . $real_private_path); if (copy($real_path, $real_private_path)) { log_('succesfully copied'); Database::query('UPDATE `images` SET `server_id`=' . ImgStore::SERVER_PRIVATE . ', `private_real`=1 WHERE `id`=' . $image['id']); unlink($real_path); } else { log_('cant copy'); }
function _list($opts = array()) { $has_paging = !isset($opts['no_paging']); $show_sortings = isset($opts['show_sortings']); $per_page = isset($opts['per_page']) ? $opts['per_page'] : 10; $per_page = min(100, max(1, (int) $per_page)); $cond = new Conditions(); if (isset($opts['historical']) && $opts['historical']) { $cond->setSorting(array('eventTime' => array('order' => 'desc', 'title' => 'по исторической дате')), array('eventTime' => array('order' => 'desc', 'title' => 'по исторической дате'))); } else { $cond->setSorting(array('createTime' => array('order' => 'desc', 'title' => 'по дате')), array('createTime' => array('order' => 'desc', 'title' => 'по дате'))); } $cond->setPaging(100000, $per_page); $where = array('1'); if (isset($opts['where'])) { foreach ($opts['where'] as $w) { $where[] = $w; } } $order = $cond->getSortingField() . ' ' . $cond->getSortingOrderSQL(); $limit = $cond->getLimit(); $query = 'SELECT SQL_CALC_FOUND_ROWS A.child_name as child_name,A.birthDate as birthDate,AE.*, LE.*,AE.description as description, LE.description as event_description, LE.title as event_title,AE.title as title, AE.creator_id as user_id,AE.id as id, LE.id as lib_event_id, LET.id as lib_template_id, AE.id as id FROM `album_events` AE LEFT JOIN `album` A ON A.id=AE.album_id LEFT JOIN `lib_events` LE ON LE.id=AE.event_id LEFT JOIN `lib_event_templates` LET ON LET.id=LE.template_id WHERE (' . implode(' AND ', $where) . ') ORDER BY ' . $order . ' LIMIT ' . $limit . ''; $events = Database::sql2array($query, 'id'); $uids = array(); if (count($events)) { $field_values = Database::sql2array('SELECT AEF.*,LETF.title as event_field_title,T.* FROM `album_events_fields` AEF JOIN `lib_event_templates_fields` LETF ON LETF.field_id=AEF.field_id JOIN `lib_event_templates_fields_types` T ON T.id=LETF.type WHERE `event_id` IN(' . implode(',', array_keys($events)) . ')'); } else { $field_values = array(); } foreach ($field_values as $values) { $events[$values['event_id']]['fields'][$values['field_id']] = $values; } foreach ($events as $event) { if ($event['user_id']) { $uids[$event['user_id']] = $event['user_id']; } } if (count($uids)) { $users = Users::getByIdsLoaded($uids); } else { $users = array(); } foreach ($events as &$event) { $event['user'] = isset($users[$event['user_id']]) ? $users[$event['user_id']]->data : array(); $event['template_id'] = $event['template_id'] ? $event['template_id'] : 1; $image_id = $event['picture']; $event['pic_small'] = $image_id ? ImgStore::getUrl($image_id, Config::SIZES_PICTURE_SMALL) : false; $event['pic_normal'] = $image_id ? ImgStore::getUrl($image_id, Config::SIZES_PICTURE_NORMAL) : false; $event['pic_big'] = $image_id ? ImgStore::getUrl($image_id, Config::SIZES_PICTURE_BIG) : false; $event['pic_orig'] = $image_id ? ImgStore::getUrl($image_id, 0) : false; } $cond->setPaging(Database::sql2single('SELECT FOUND_ROWS()'), $per_page); $data['events'] = $events; $data['conditions'] = $cond->getConditions(); if (!$show_sortings) { foreach ($data['conditions'] as $key => $group) { if ($group['mode'] == 'sorting') { unset($data['conditions'][$key]); } } } return $data; }
foreach ($to_export as $image) { if ($limit['uploaded_bytes'] > $day_limit_bytes) { log_('LIMIT REACHED[BYTES]:' . $limit['uploaded_bytes'] . ' FROM ' . $day_limit_bytes); exit(0); } else { log_('LIMIT [BYTES]:' . $limit['uploaded_bytes'] . ' FROM ' . $day_limit_bytes); } if ($limit['uploaded_count'] > $day_limit_count) { log_('LIMIT REACHED[COUNT]:' . $limit['uploaded_count'] . ' FROM ' . $day_limit_count); exit(0); } else { log_('LIMIT [COUNT]:' . $limit['uploaded_count'] . ' FROM ' . $day_limit_count); } $real_path = ImgStore::getFileLocalPath($image['image_id'], $image['size_id']); log_($real_path . ' ' . floor($image['bytes'] / 1024 / 1024 * 1000) / 1000 . 'Mb'); $target_path = str_replace(ImgStore::$server_urls[ImgStore::SERVER_ORIG], '', ImgStore::getUrl($image['image_id'], $image['size_id'], 0)); log_('saving to ' . $target_path); $result = Amazon::store($real_path, $target_path); if ($result) { $limit['uploaded_count']++; $limit['uploaded_bytes'] += $image['bytes']; log_('Stored at amazon at ' . ImgStore::$server_urls[ImgStore::SERVER_AMAZONS3] . $target_path); Database::query('UPDATE `images` SET `server_id`=' . ImgStore::SERVER_AMAZONS3 . ', `amazon_stored_time`=' . time() . ' WHERE `id`=' . $image['id']); } else { log_('Cant store file to amazon'); Database::query('UPDATE `images` SET `amazon_stored_time`=' . time() . ' WHERE `id`=' . $image['id']); } Database::query('REPLACE INTO `amazon_limit` SET `day`=' . $day . ', `uploaded_bytes`=' . $limit['uploaded_bytes'] . ',`uploaded_count`=' . $limit['uploaded_count']); }