public static function getUrlFor($controller, $data, $full = false, $append_session = 0)
{
global $prefs;
$rewrite = isset($GLOBALS['conf']['urls']['pretty']) && $GLOBALS['conf']['urls']['pretty'] == 'rewrite';
switch ($controller) {
case 'view':
if ($rewrite && empty($data['special'])) {
$url = '';
// Viewing a List
if ($data['view'] == 'List') {
$groupby = isset($data['groupby']) ? $data['groupby'] : $prefs->getValue('groupby');
if ($groupby == 'owner' && !empty($data['owner'])) {
$url = 'user/' . urlencode($data['owner']) . '/';
} elseif ($groupby == 'owner') {
$url = 'user/';
} elseif ($groupby == 'none') {
$url = 'all/';
}
$url = Horde::url($url, $full, $append_session);
// don't append the page number if it's zero
if (!empty($data['page'])) {
$url->add('page', $data['page']);
}
return $url;
}
// Viewing a Gallery or Image
if ($data['view'] == 'Gallery' || $data['view'] == 'Image') {
// @TODO: This is needed to correctly generate URLs in
// places that are not specifically requested by the user,
// for instance, in a gallery block. Otherwise, the proper
// date variables would not be attached to the url, since we
// don't know them ahead of time. This is a slight hack and
// needs to be corrected, probably by delegating at least
// some of the URL generation to the gallery/image/view
// object...most likely when we move to PHP5.
if (empty($data['year']) && $data['view'] == 'Image') {
// Getting these objects is not ideal, but at this point
// they should already be locally cached so the cost
// is minimized.
$i = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($data['image']);
$g = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($data['gallery']);
if ($g->get('view_mode') == 'Date') {
$imgDate = new Horde_Date($i->originalDate);
$data['year'] = $imgDate->year;
$data['month'] = $imgDate->month;
$data['day'] = $imgDate->mday;
}
}
$url = 'gallery/' . (!empty($data['slug']) ? $data['slug'] : 'id/' . (int) $data['gallery']) . '/';
// See comments below about lightbox
if ($data['view'] == 'Image' && (empty($data['gallery_view']) || !empty($data['gallery_view']) && $data['gallery_view'] != 'GalleryLightbox')) {
$url .= (int) $data['image'] . '/';
}
$extras = array();
// We may have a value of zero here, but it's the default,
// so ignore it if it's empty.
if (!empty($data['havesearch'])) {
$extras['havesearch'] = $data['havesearch'];
}
// Block any auto navigation (for date views)
if (!empty($data['force_grouping'])) {
$extras['force_grouping'] = $data['force_grouping'];
}
$url = new Horde_Url($url);
if (count($extras)) {
$url->add($extras);
}
//Slight hack until we delegate at least some of the url
// generation to the gallery/image/view object.
if ($data['view'] == 'Image' && !empty($data['gallery_view']) && $data['gallery_view'] == 'GalleryLightbox') {
$url->setAnchor($data['image']);
}
} elseif ($data['view'] == 'Results') {
$url = new Horde_Url('tag/' . (!empty($data['tag']) ? urlencode($data['tag']) . '/' : ''));
if (!empty($data['actionID'])) {
$url->add(array('actionID' => $data['actionID']));
}
if (!empty($data['owner'])) {
$url->add('owner', $data['owner']);
}
}
// Keep the URL as clean as possible - don't append the page
// number if it's zero, which would be the default.
if (!empty($data['page'])) {
$url->add('page', $data['page']);
}
if (!empty($data['year'])) {
$url->add(array('year' => $data['year'], 'month' => empty($data['month']) ? 0 : $data['month'], 'day' => empty($data['day']) ? 0 : $data['day']));
}
return Horde::url($url, $full, $append_session);
} else {
$url = Horde::url('view.php', $full, $append_session);
// See note above about delegating url generation to gallery/view
if ($data['view'] == 'Image' && !empty($data['gallery_view']) && $data['gallery_view'] == 'GalleryLightbox') {
$data['view'] = 'Gallery';
$url->setAnchor($data['image']);
}
return $url->add($data)->setRaw(true);
}
case 'group':
if ($rewrite) {
if (empty($data['groupby'])) {
$data['groupby'] = $prefs->getValue('groupby');
}
if ($data['groupby'] == 'owner') {
$url = 'user/';
} elseif ($data['groupby'] == 'none') {
$url = 'all/';
}
unset($data['groupby']);
$url = Horde::url($url, $full, $append_session);
if (count($data)) {
$url->add($data);
}
return $url;
} else {
return Horde::url('group.php', $full, $append_session)->add($data);
}
case 'rss_user':
if ($rewrite) {
return Horde::url('user/' . urlencode($data['owner']) . '/rss', $full, $append_session);
} else {
$url = Horde::url(new Horde_Url('rss.php'), $full, $append_session);
return $url->add(array('stream_type' => 'user', 'id' => $data['owner']));
}
case 'rss_gallery':
if ($rewrite) {
$id = !empty($data['slug']) ? $data['slug'] : 'id/' . (int) $data['gallery'];
return Horde::url('gallery/' . $id . '/rss', $full, $append_session);
} else {
return Horde::url('rss.php', $full, $append_session)->add(array('stream_type' => 'gallery', 'id' => (int) $data['gallery']));
}
case 'default_view':
switch ($prefs->getValue('defaultview')) {
case 'browse':
return Horde::url(new Horde_Url('browse.php'), $full, $append_session);
case 'galleries':
$url = Ansel::getUrlFor('view', array('view' => 'List'), true);
break;
case 'mygalleries':
default:
$url = Ansel::getUrlFor('view', array('view' => 'List', 'owner' => $GLOBALS['registry']->getAuth(), 'groupby' => 'owner'), true);
break;
}
return $url;
}
}