function pwg_db_get_recent_period($period, $date = 'CURRENT_DATE') { $query = ' SELECT ' . pwg_db_get_recent_period_expression($period); list($d) = pwg_db_fetch_row(pwg_query($query)); return $d; }
/** * Returns sql WHERE condition for recent photos/albums for current user. * * @param string $db_field * @return string */ function get_recent_photos_sql($db_field) { global $user; if (!isset($user['last_photo_date'])) { return '0=1'; } return $db_field . '>=LEAST(' . pwg_db_get_recent_period_expression($user['recent_period']) . ',' . pwg_db_get_recent_period_expression(1, $user['last_photo_date']) . ')'; }
/** * Get computed array of categories, that means cache data of all categories * available for the current user (count_categories, count_images, etc.). * * @param array &$userdata * @param int $filter_days number of recent days to filter on or null * @return array */ function get_computed_categories(&$userdata, $filter_days = null) { $query = 'SELECT c.id AS cat_id, id_uppercat'; $query .= ', global_rank'; // Count by date_available to avoid count null $query .= ', MAX(date_available) AS date_last, COUNT(date_available) AS nb_images FROM ' . CATEGORIES_TABLE . ' as c LEFT JOIN ' . IMAGE_CATEGORY_TABLE . ' AS ic ON ic.category_id = c.id LEFT JOIN ' . IMAGES_TABLE . ' AS i ON ic.image_id = i.id AND i.level<=' . $userdata['level']; if (isset($filter_days)) { $query .= ' AND i.date_available > ' . pwg_db_get_recent_period_expression($filter_days); } if (!empty($userdata['forbidden_categories'])) { $query .= ' WHERE c.id NOT IN (' . $userdata['forbidden_categories'] . ')'; } $query .= ' GROUP BY c.id'; $result = pwg_query($query); $userdata['last_photo_date'] = null; $cats = array(); while ($row = pwg_db_fetch_assoc($result)) { $row['user_id'] = $userdata['id']; $row['nb_categories'] = 0; $row['count_categories'] = 0; $row['count_images'] = (int) $row['nb_images']; $row['max_date_last'] = $row['date_last']; if ($row['date_last'] > $userdata['last_photo_date']) { $userdata['last_photo_date'] = $row['date_last']; } $cats[$row['cat_id']] = $row; } // it is important to logically sort the albums because some operations // (like removal) rely on this logical order. Child album doesn't always // have a bigger id than its parent (if it was moved afterwards). uasort($cats, 'global_rank_compare'); foreach ($cats as $cat) { if (!isset($cat['id_uppercat'])) { continue; } // Piwigo before 2.5.3 may have generated inconsistent permissions, ie // private album A1/A2 permitted to user U1 but private album A1 not // permitted to U1. // // TODO 2.7: add an upgrade script to repair permissions and remove this // test if (!isset($cats[$cat['id_uppercat']])) { continue; } $parent =& $cats[$cat['id_uppercat']]; $parent['nb_categories']++; do { $parent['count_images'] += $cat['nb_images']; $parent['count_categories']++; if (empty($parent['max_date_last']) or $parent['max_date_last'] < $cat['date_last']) { $parent['max_date_last'] = $cat['date_last']; } if (!isset($parent['id_uppercat'])) { break; } $parent =& $cats[$parent['id_uppercat']]; } while (true); unset($parent); } if (isset($filter_days)) { foreach ($cats as $category) { if (empty($category['max_date_last'])) { remove_computed_category($cats, $category); } } } return $cats; }
FROM ' . FAVORITES_TABLE . ' WHERE user_id = ' . $user['id'] . ' ;'; $filter_sets[] = query2array($query, null, 'image_id'); break; case 'last_import': $query = ' SELECT MAX(date_available) AS date FROM ' . IMAGES_TABLE . ' ;'; $row = pwg_db_fetch_assoc(pwg_query($query)); if (!empty($row['date'])) { $query = ' SELECT id FROM ' . IMAGES_TABLE . ' WHERE date_available BETWEEN ' . pwg_db_get_recent_period_expression(1, $row['date']) . ' AND \'' . $row['date'] . '\' ;'; $filter_sets[] = query2array($query, null, 'id'); } break; case 'no_virtual_album': // we are searching elements not linked to any virtual category $query = ' SELECT id FROM ' . IMAGES_TABLE . ' ;'; $all_elements = query2array($query, null, 'id'); $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE dir IS NULL
$filter['visible_categories'] = implode(',', array_keys($filter['categories'])); if (empty($filter['visible_categories'])) { // Must be not empty $filter['visible_categories'] = -1; } $query = ' SELECT distinct image_id FROM ' . IMAGE_CATEGORY_TABLE . ' INNER JOIN ' . IMAGES_TABLE . ' ON image_id = id WHERE '; if (!empty($filter['visible_categories'])) { $query .= ' category_id IN (' . $filter['visible_categories'] . ') and'; } $query .= ' date_available >= ' . pwg_db_get_recent_period_expression($filter['recent_period']); $filter['visible_images'] = implode(',', array_from_query($query, 'image_id')); if (empty($filter['visible_images'])) { // Must be not empty $filter['visible_images'] = -1; } // Save filter data on session pwg_set_session_var('filter_enabled', $filter['enabled']); pwg_set_session_var('filter_check_key', $filter_key); pwg_set_session_var('filter_categories', serialize($filter['categories'])); pwg_set_session_var('filter_visible_categories', $filter['visible_categories']); pwg_set_session_var('filter_visible_images', $filter['visible_images']); } else { // Read only data $filter['categories'] = unserialize(pwg_get_session_var('filter_categories', serialize(array()))); $filter['visible_categories'] = pwg_get_session_var('filter_visible_categories', '');
// if the default value is not in the expected values, we add it in the $items_number array if (!in_array($conf['comments_page_nb_comments'], $items_number)) { $items_number_new = array(); $is_inserted = false; foreach ($items_number as $number) { if ($number > $conf['comments_page_nb_comments'] or $number == 'all' and !$is_inserted) { $items_number_new[] = $conf['comments_page_nb_comments']; $is_inserted = true; } $items_number_new[] = $number; } $items_number = $items_number_new; } // since when display comments ? // $since_options = array(1 => array('label' => l10n('today'), 'clause' => 'date > ' . pwg_db_get_recent_period_expression(1)), 2 => array('label' => l10n('last %d days', 7), 'clause' => 'date > ' . pwg_db_get_recent_period_expression(7)), 3 => array('label' => l10n('last %d days', 30), 'clause' => 'date > ' . pwg_db_get_recent_period_expression(30)), 4 => array('label' => l10n('the beginning'), 'clause' => '1=1')); trigger_notify('loc_begin_comments'); if (!empty($_GET['since']) && is_numeric($_GET['since'])) { $page['since'] = $_GET['since']; } else { $page['since'] = 4; } // on which field sorting // $page['sort_by'] = 'date'; // if the form was submitted, it overloads default behaviour if (isset($_GET['sort_by']) and isset($sort_by[$_GET['sort_by']])) { $page['sort_by'] = $_GET['sort_by']; } // order to sort //
$item->guid = sprintf('%s', $dbnow); $rss->addItem($item); $query = ' UPDATE ' . USER_FEED_TABLE . ' SET last_check = \'' . $dbnow . '\' WHERE id = \'' . $feed_id . '\' ;'; pwg_query($query); } } if (!empty($feed_id) and empty($news)) { // update the last check from time to time to avoid deletion by maintenance tasks if (!isset($feed_row['last_check']) or time() - datetime_to_ts($feed_row['last_check']) > 30 * 24 * 3600) { $query = ' UPDATE ' . USER_FEED_TABLE . ' SET last_check = ' . pwg_db_get_recent_period_expression(-15, $dbnow) . ' WHERE id = \'' . $feed_id . '\' ;'; pwg_query($query); } } $dates = get_recent_post_dates_array($conf['recent_post_dates']['RSS']); foreach ($dates as $date_detail) { // for each recent post date we create a feed item $item = new FeedItem(); $date = $date_detail['date_available']; $item->title = get_title_recent_post_date($date_detail); $item->link = make_index_url(array('chronology_field' => 'posted', 'chronology_style' => 'monthly', 'chronology_view' => 'calendar', 'chronology_date' => explode('-', substr($date, 0, 10)))); $item->description .= '<a href="' . make_index_url() . '">' . $conf['gallery_title'] . '</a><br> '; $item->description .= get_html_description_recent_post_date($date_detail); $item->descriptionHtmlSyndicated = true;