cash/Tidypics — Issue #4: Add new start.php elgg 1.8
Author: lianglee
Created: 2011-11-13 03:25:02+00:00
State: open

wwwroot . "pg/photos/all/");
}

// Extend CSS
elgg_extend_view('css/elgg', 'tidypics/css');

// Extend hover-over and profile menu
//elgg_extend_view('profile/menu/links','tidypics/hover_menu');

//group view ** psuedo widget view for group pages**
elgg_extend_view('groups/tool_latest','tidypics/groupprofile_albums');

// rss extensions
elgg_extend_view('extensions/xmlns', 'extensions/tidypics/xmlns');
elgg_extend_view('extensions/channel', 'extensions/tidypics/channel');

// Register a page handler, so we can have nice URLs
register_page_handler('photos','tidypics_page_handler');

// Add a new tidypics widget
add_widget_type('album_view', elgg_echo("tidypics:widget:albums"), elgg_echo("tidypics:widget:album_descr"), 'profile');
add_widget_type('latest_photos', elgg_echo("tidypics:widget:latest"), elgg_echo("tidypics:widget:latest_descr"), 'profile');

// Register a URL handler for files
register_entity_url_handler('tidypics_image_url', 'object', 'image');
register_entity_url_handler('tidypics_album_url', 'object', 'album');

// add the class files for image and album
add_subtype("object", "image", "TidypicsImage");
add_subtype("object", "album", "TidypicsAlbum");

// Register entity type
register_entity_type('object','image');
register_entity_type('object','album');

if (function_exists('add_group_tool_option'))
add_group_tool_option('photos',elgg_echo('tidypics:enablephotos'),true);

if (get_plugin_setting('grp_perm_override', 'tidypics') != "disabled")
register_plugin_hook('permissions_check', 'object', 'tidypics_permission_override');

// Register for notifications
if (is_callable('register_notification_object')) {
register_notification_object('object', 'album', elgg_echo('tidypics:newalbum'));

register_plugin_hook('notify:entity:message', 'object', 'tidypics_notify_message');
}

// slideshow plugin hook
register_plugin_hook('tp_slideshow', 'album', 'tidypics_slideshow');

// Register profile menu hook
register_plugin_hook('profile_menu', 'profile', 'tidypics_profile_menu');

// register for embed
register_plugin_hook('embed_get_sections', 'all', 'tidypics_embed_get_sections');
register_plugin_hook('embed_get_items', 'tidypics', 'tidypics_embed_get_items');
register_plugin_hook('embed_get_upload_sections', 'all', 'tidypics_embed_get_upload_sections');

// ajax handler for uploads when use_only_cookies is set
register_plugin_hook('forward', 'system', 'tidypics_ajax_session_handler');

// register a handler to check and delete a batch if its empty when an image is deleted
elgg_register_event_handler('delete', 'tp_image', 'tidypics_remove_from_batch');

elgg_register_plugin_hook_handler('register', 'menu:entity', 'tidypics_setup_entity_menu_items');
}

/**
* Sets up sidebar menus for tidypics. Triggered on pagesetup.
*/
function tidypics_submenus() {

if (elgg_in_context('tidypics:main')) {
$count_setting = get_plugin_setting('view_count', 'tidypics');

if (elgg_is_logged_in()) {
$user = elgg_get_logged_in_user_entity();

elgg_register_menu_item('page', array(
'name' => 'newalbum',
'text' => elgg_echo('photos:add'),
'href' => "photos/new/$user->username",
));
elgg_register_menu_item('page', array(
'name' => 'yourmostrecent',
'text' => elgg_echo('tidypics:yourmostrecent'),
'href' => "photos/mostrecent/$user->username",
));

if ($count_setting != 'disabled') {
elgg_register_menu_item('page', array(
'name' => 'yourmostviewed',
'text' => elgg_echo('tidypics:yourmostviewed'),
'href' => "photos/mostviewed/$user->username",
));
}
}

elgg_register_menu_item('page', array(
'name' => 'mostrecent',
'text' => elgg_echo('tidypics:mostrecent'),
'href' => "photos/mostrecent",
));
if ($count_setting != 'disabled') {
elgg_register_menu_item('page', array(
'name' => 'mostviewed',
'text' => elgg_echo('tidypics:mostviewed'),
'href' => "photos/mostviewed",
));
elgg_register_menu_item('page', array(
'name' => 'recentlyviewed',
'text' => elgg_echo('tidypics:recentlyviewed'),
'href' => "photos/recentlyviewed",
));
}
elgg_register_menu_item('page', array(
'name' => 'recentlycommented',
'text' => elgg_echo('tidypics:recentlycommented'),
'href' => "photos/recentcommented",
));

}

global $CONFIG;
return true;
$page_owner = page_owner_entity();

if ($page_owner instanceof ElggGroup) {
if (get_context() == "groups") {
if ($page_owner->photos_enable != "no") {
//add_submenu_item(	sprintf(elgg_echo('album:group'),$page_owner->name), $CONFIG->wwwroot . "pg/photos/owner/" . $page_owner->username);
}
}
}
// context is only set to photos on individual pages, not on group pages
else if (get_context() == "photos") {

$view_count = get_plugin_setting('view_count', 'tidypics');

// owner gets "your albumn", "your friends albums", "your most recent", "your most viewed"
if (get_loggedin_userid() && get_loggedin_userid() == $page_owner->guid) {
//add_submenu_item(	elgg_echo('album:create'),
//$CONFIG->wwwroot . "pg/photos/new/{$page_owner->username}/",
//'tidypics-a' );

elgg_add_submenu_item(array('text' => elgg_echo("album:yours"),
'href' => $CONFIG->wwwroot . "pg/photos/owner/{$page_owner->username}/"), 'all', 'tidypics-a');

elgg_add_submenu_item(array('text' => elgg_echo('album:yours:friends'),
'href' => $CONFIG->wwwroot . "pg/photos/friends/{$page_owner->username}/"), 'all', 'tidypics-a');

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:yourmostrecent'),
'href' => $CONFIG->wwwroot . "pg/photos/mostrecent/{$page_owner->username}/"), 'all', 'tidypics-a');

if ($view_count != 'disabled') {
elgg_add_submenu_item(array('text' => elgg_echo('tidypics:yourmostviewed'),
'href' => $CONFIG->wwwroot . "pg/photos/mostviewed/{$page_owner->username}/"), 'all', 'tidypics-a');
}

} else if (isloggedin()) {

$user = get_loggedin_user();

// logged in not owner gets "page owners albums", "page owner's friends albums", "page owner's most viewed", "page owner's most recent"
// and then "your albums", "your most recent", "your most viewed"
if ($page_owner->name) { // check to make sure the owner set their display name
elgg_add_submenu_item(array('text' => sprintf(elgg_echo("album:user"), $page_owner->name),
'href' => $CONFIG->wwwroot . "pg/photos/owner/{$page_owner->username}/"), 'all', 'tidypics-a');

elgg_add_submenu_item(array('text' => sprintf(elgg_echo('album:friends'),$page_owner->name),
'href' => $CONFIG->wwwroot . "pg/photos/friends/{$page_owner->username}/"), 'all', 'tidypics-a');

if ($view_count != 'disabled') {
elgg_add_submenu_item(array('text' => sprintf(elgg_echo('tidypics:friendmostviewed'),$page_owner->name),
'href' => $CONFIG->wwwroot . "pg/photos/mostviewed/{$page_owner->username}/"), 'all', 'tidypics-a');
}

elgg_add_submenu_item(array('text' => sprintf(elgg_echo('tidypics:friendmostrecent'),$page_owner->name),
'href' => $CONFIG->wwwroot . "pg/photos/mostrecent/{$page_owner->username}/"), 'all', 'tidypics-a');
}

elgg_add_submenu_item(array('text' => elgg_echo("album:yours"),
'href' => $CONFIG->wwwroot . "pg/photos/owner/{$user->username}/"), 'all','tidypics-b');

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:yourmostrecent'),
'href' => $CONFIG->wwwroot . "pg/photos/mostrecent/{$user->username}/"), 'all','tidypics-b');

if ($view_count != 'disabled') {
elgg_add_submenu_item(array('text' => elgg_echo('tidypics:yourmostviewed'),
'href' => $CONFIG->wwwroot . "pg/photos/mostviewed/{$page_owner->username}/"), 'all', 'tidypics-b');
}
} else if ($page_owner->guid) {
// non logged in user gets "page owners albums", "page owner's friends albums"
elgg_add_submenu_item(array('text' => sprintf(elgg_echo("album:user"), $page_owner->name),
'href' => $CONFIG->wwwroot . "pg/photos/owner/{$page_owner->username}/"), 'all', 'tidypics-a');

elgg_add_submenu_item(array('text' => sprintf(elgg_echo('album:friends'),$page_owner->name),
'href' => $CONFIG->wwwroot . "pg/photos/friends/{$page_owner->username}/"), 'all', 'tidypics-a');
}

// everyone gets world albums, most recent, most viewed, most recently viewed, recently commented
elgg_add_submenu_item(array('text' => elgg_echo('album:all'),
'href' => $CONFIG->wwwroot . "pg/photos/world/"), 'all', 'tidypics-z');

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:mostrecent'),
'href' => $CONFIG->wwwroot . "pg/photos/mostrecent/"), 'all', 'tidypics-z');

if ($view_count != 'disabled') {
elgg_add_submenu_item(array('text' => elgg_echo('tidypics:mostviewed'),
'href' => $CONFIG->wwwroot . 'pg/photos/mostviewed/'), 'all', 'tidypics-z');

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:recentlyviewed'),
'href' => $CONFIG->wwwroot . 'pg/photos/recentlyviewed/'), 'all', 'tidypics-z');

}

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:recentlycommented'),
'href' => $CONFIG->wwwroot . 'pg/photos/recentlycommented/'), 'all', 'tidypics-z');

/*
add_submenu_item(	'Flickr Integration',
$CONFIG->wwwroot . 'mod/tidypics/pages/flickr/setup.php',
'tidypics-z');
*/
}

}

/**
* Sets up tidypics admin menu. Triggered on pagesetup.
*/
function tidypics_adminmenu()
{
global $CONFIG;
if (isadminloggedin()) {
elgg_register_menu_item('page', array(
'name' => 'tidypics',
'href' => $CONFIG->url . "photos/admin/",
'text' => elgg_echo('tidypics:administration'),
'context' => 'admin',
'priority' => 200,
'section' => 'configure'
));
}
}

/**
* Sets up submenus for tidypics most viewed pages
*/
function tidypics_mostviewed_submenus() {

global $CONFIG;

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:mostvieweddashboard'),
'href' => $CONFIG->url . "mod/tidypics/mostvieweddashboard.php"));

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:mostviewedthisyear'),
'href' => $CONFIG->url . "mod/tidypics/pages/lists/mostviewedimagesthisyear.php"));

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:mostviewedthismonth'),
'href' => $CONFIG->url . "mod/tidypics/pages/lists/mostviewedimagesthismonth.php"));

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:mostviewedlastmonth'),
'href' => $CONFIG->url . "mod/tidypics/pages/lists/mostviewedimageslastmonth.php"));

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:mostviewedtoday'),
'href' => $CONFIG->url . "mod/tidypics/pages/lists/mostviewedimagestoday.php"));

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:mostcommented'),
'href' => $CONFIG->url . "mod/tidypics/pages/lists/mostcommentedimages.php"));

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:mostcommentedthismonth'),
'href' => $CONFIG->url . "mod/tidypics/pages/lists/mostcommentedimagesthismonth.php"));

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:mostcommentedtoday'),
'href' => $CONFIG->url . "mod/tidypics/pages/lists/mostcommentedimagestoday.php"));

elgg_add_submenu_item(array('text' => elgg_echo('tidypics:recentlycommented'),
'href' => $CONFIG->url . 'pg/photos/recentlycommented/'));

}

/**
* tidypics page handler
*
* @param array $page Array of page elements, forwarded by the page handling mechanism
*/
function tidypics_page_handler($page) {

global $CONFIG;

if (isset($page[0]))
{
switch($page[0])
{
case "owner": //view list of albums owned by container
if (isset($page[1])) set_input('username',$page[1]);
include($CONFIG->pluginspath . "tidypics/pages/ownedalbums.php");
break;

case "view": //view an image individually
if (isset($page[1])) set_input('guid',$page[1]);
include($CONFIG->pluginspath . "tidypics/pages/viewimage.php");
break;

case "album": //view an album individually
if (isset($page[1])) set_input('guid',$page[1]);
include($CONFIG->pluginspath . "tidypics/pages/viewalbum.php");
break;

case "new": //create new album
if (isset($page[1])) {
set_input('username', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/newalbum.php");
break;

case "upload": //upload images to album
if (isset($page[1])) {
set_input('album_guid', $page[1]);
}
if (isset($page[2])) {
set_input('uploader', 'basic');
}
include($CONFIG->pluginspath . "tidypics/pages/upload.php");
break;

case "edit": //edit image or album
if (isset($page[1])) {
set_input('guid', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/edit.php");
break;

case "batch": //update titles and descriptions
if (isset($page[1])) {
set_input('batch', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/edit_multiple.php");
break;

case "friends": // albums of friends
if (isset($page[1])) {
set_input('username', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/friends.php");
break;

case "all": // all site albums
include($CONFIG->pluginspath . "tidypics/pages/world.php");
break;

case "download": // download an image
if (isset($page[1])) {
set_input('file_guid', $page[1]);
}
if (isset($page[2])) {
set_input('type', $page[2]);
}
include($CONFIG->pluginspath . "tidypics/pages/download.php");
break;

case "thumbnail": // tidypics thumbnail
if (isset($page[1])) {
set_input('file_guid', $page[1]);
}
if (isset($page[2])) {
set_input('size', $page[2]);
}
include($CONFIG->pluginspath . "tidypics/pages/thumbnail.php");
break;

case "tagged": // all photos tagged with user
if (isset($page[1])) set_input('guid',$page[1]);
include($CONFIG->pluginspath . "tidypics/pages/tagged.php");
break;

case "mostviewed": // images with the most views
if (isset($page[1])) {
set_input('username', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/lists/mostviewedimages.php");
break;

case "mostrecent": // images uploaded most recently
if (isset($page[1])) {
set_input('username', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/lists/mostrecentimages.php");
break;

case "recentlyviewed": // images most recently viewed
include($CONFIG->pluginspath . "tidypics/pages/lists/recentlyviewed.php");
break;

case "recentlycommented": // images with the most recent comments
include($CONFIG->pluginspath . "tidypics/pages/lists/recentlycommented.php");
break;

case "highestrated": // images with the highest average rating
include($CONFIG->pluginspath . "tidypics/pages/lists/highestrated.php");
break;

case "flickr":
if (isset($page[1])) {
set_input('username',$page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/flickr/setup.php");
break;

case "admin":
include ($CONFIG->pluginspath . "tidypics/pages/admin.php");
break;
}
}
else {
// going to all site albums if something goes wrong with the page handler
include($CONFIG->pluginspath . "tidypics/pages/world.php");
}

}

/**
* Sets up the entity menu for tidypics albums and photos
*
* @param string $hook Hook name
* @param string $type Hook type
* @param array $value Array of menu items
* @param array $params Array with the entity
* @return array
*/
function tidypics_setup_entity_menu_items($hook, $type, $value, $params) {
$handler = elgg_extract('handler', $params, false);
if ($handler != 'photos') {
return $value;
}

$entity = $params['entity'];
if (elgg_instanceof($entity, 'object', 'image')) {
$options = array(
'name' => 'tag',
'text' => elgg_echo('Tag'),
'href' => "#",
'rel' => 'photo_tagging',
'priority' => 150,
);
$value[] = ElggMenuItem::factory($options);

elgg_register_js('photo:select', 'mod/tidypics/vendors/jquery.imgareaselect-0.7.js', 'footer');
elgg_load_js('photo:select');
elgg_register_js('photo:notes', 'mod/tidypics/vendors/jquery.quicksearch.js', 'footer');
elgg_load_js('photo:notes');

elgg_register_js('photo:tagging', 'js/tidypics/tagging.js', 'footer');
elgg_load_js('photo:tagging');
} else {
$slideshow_link = "javascript:PicLensLite.start({maxScale:0,feedUrl:location.href+'?view=rss'})";

$options = array(
'name' => 'slideshow',
'text' => elgg_echo('Slideshow'),
'href' => $slideshow_link,
'priority' => 150,
);
$value[] = ElggMenuItem::factory($options);

elgg_register_js('photo:slideshow', 'mod/tidypics/vendors/PicLensLite/piclens_optimized.js', 'footer');
elgg_load_js('photo:slideshow');
}

return $value;
}

/**
* Override permissions for group albums and images
*
*/
function tidypics_permission_override($hook, $entity_type, $returnvalue, $params)
{
$entity = $params['entity'];
$user = $params['user'];

if ($entity->subtype == get_subtype_id('object', 'album')) {
// test that the user can edit the container
return can_write_to_container(0, $entity->container_guid);
}

if ($entity->subtype == get_subtype_id('object', 'image')) {
// test that the user can edit the container
return can_write_to_container(0, $entity->container_guid);
}
}

/**
* Notification message handler
*/
function tidypics_notify_message($hook, $entity_type, $returnvalue, $params)
{
$entity = $params['entity'];
$to_entity = $params['to_entity'];
$method = $params['method'];
if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'album'))
{
// block notification message when the album doesn't have any photos
if ($entity->new_album == TP_NEW_ALBUM)
return false;

$descr = $entity->description;
$title = $entity->title;
$owner = $entity->getOwnerEntity();
return sprintf(elgg_echo('album:river:created'), $owner->name) . ': ' . $title . "\n\n" . $descr . "\n\n" . $entity->getURL();
}
return null;
}

/**
* Populates the ->getUrl() method for file objects
* Registered in the init function
*
* @param ElggEntity $entity album/image entity
* @return string File URL
*/
function tidypics_image_url($entity) {
global $CONFIG;
$title = $entity->title;
$title = friendly_title($title);
return $CONFIG->url . "pg/photos/view/" . $entity->getGUID() . "/" . $title;
}

function tidypics_album_url($entity) {
global $CONFIG;
$title = $entity->title;
$title = friendly_title($title);
return $CONFIG->url . "pg/photos/album/" . $entity->getGUID() . "/" . $title;
}

/**
* Catch the plugin hook and add the default album slideshow
*
* @param $hook - 'tidypics:slideshow'
* @param $entity_type - 'album'
* @param $returnvalue - if set, return because another plugin has used the hook
* @param $params - arry containing album entity
* @return unknown_type
*/
function tidypics_slideshow($hook, $entity_type, $returnvalue, $params) {

if ($returnvalue !== null) {
// someone has already added a slideshow or requested that the slideshow is not used
return $returnvalue;
}

$slideshow_link = "javascript:PicLensLite.start({maxScale:0,feedUrl:location.href+'?view=rss'})";

// add the slideshow javascript to the header
elgg_extend_view('html_head/extend', 'tidypics/js/slideshow');

return $slideshow_link;
}

function tp_mostrecentimages($max = 8, $pagination = true) {
return list_entities("object", "image", 0, $max, false, false, $pagination);
}

function tidypics_profile_menu($hook, $entity_type, $return_value, $params) {
global $CONFIG;

// Only display on group owner block if enabled
if ($params['owner'] instanceof ElggUser || $params['owner']->photos_enable == 'yes') {
$return_value[] = array(
'text' => elgg_echo('photos'),
'href' => "{$CONFIG->url}pg/photos/owner/{$params['owner']->username}"
);
}

return $return_value;
}

/**
* Register Tidypics for embed support.
* @param unknown_type $hook
* @param unknown_type $type
* @param unknown_type $value
* @param unknown_type $params
*/
function tidypics_embed_get_sections($hook, $type, $value, $params) {
$value['tidypics'] = array(
'name' => elgg_echo('photos'),
'layout' => 'list',
);

return $value;
}

/**
* Return a list of images for embedding
*
* @param unknown_type $hook
* @param unknown_type $type
* @param unknown_type $value
* @param unknown_type $params
*/
function tidypics_embed_get_items($hook, $type, $value, $params) {
$options = array(
'owner_guid' => get_loggedin_userid(),
'type_subtype_pair' => array('object' => 'image'),
'count' => TRUE
);

$count = elgg_get_entities($options);
$value['count'] += $count;

unset($options['count']);
$options['offset'] = $params['offset'];
$options['limit'] = $params['limit'];

$items = elgg_get_entities($options);

$value['items'] = array_merge($items, $value['items']);

return $value;
}

/**
* Returns the URL for the entity's icon.
*
* @param $entity
* @param $size
*/
function tidypics_get_entity_icon_url(ElggEntity $entity, $size = 'medium') {
global $CONFIG;

// only 3 possibilities
if ($size != 'small' && $size != 'large') {
$size = 'thumb';
}

// for albums, show the cover if available
if ($entity instanceof TidypicsAlbum && $entity->cover) {
$guid = $entity->cover;
} else {
$guid = $entity->guid;
}

return "{$CONFIG->wwwroot}pg/photos/thumbnail/$guid/$size";
}

/**
* Register for upload support in embed.
*
* @param unknown_type $hook
* @param unknown_type $type
* @param unknown_type $value
* @param unknown_type $params
*/
function tidypics_embed_get_upload_sections($hook, $type, $value, $params) {
$value['tidypics'] = array(
'name' => elgg_echo('photos'),
'view' => 'tidypics/forms/embed_upload'
);

return $value;
}

/**
* When an image is deleted, remove it from the batch, if the batch is empty
* delete it.
* @TODO might be a better way to handle this..
*/
function tidypics_remove_from_batch($event, $object_type, $object) {
// In case no batch metadata was save
if (!$batch = get_entity($object->batch_id)) {
// Get batch related to this image
$batches = elgg_get_entities_from_relationship(array(
'relationship' => 'belongs_to_batch',
'relationship_guid' => $object->getGUID(),
'inverse_relationship' => false,
'types' => array('object'),
'subtypes' => array('tidypics_batch'),
'limit' => 999,
'offset' => 0,
'count' => false,
));
$batch = $batches[0];
}

if ($batch) {
// Remove relationships
remove_entity_relationships($object->getGUID());

// Get images related to the batch
$images = elgg_get_entities_from_relationship(array(
'relationship' => 'belongs_to_batch',
'relationship_guid' => $batch->getGUID(),
'inverse_relationship' => true,
'types' => array('object'),
'subtypes' => array('image'),
'limit' => 999,
'offset' => 0,
'count' => false,
));

// Remove batch if empty
if (!$images) {
$batch->delete();
}
}
return true;
}

/**
* Work around for Flash/session issues
*
* @param string $hook
* @param string $entity_type
* @param string $returnvalue
* @param array $params
*/
function tidypics_ajax_session_handler($hook, $entity_type, $returnvalue, $params) {
global $CONFIG;

$url = current_page_url();
if ($url !== "{$CONFIG->wwwroot}action/tidypics/ajax_upload/") {
return;
}

if (get_loggedin_userid() != 0) {
return;
}

// action_gatekeeper rejected ajax call from Flash due to session issue

// Validate token
$token = get_input('__elgg_token');
$ts = get_input('__elgg_ts');
$session_id = get_input('Elgg');
$tidypics_token = get_input('tidypics_token');
$user_guid = get_input('user_guid');

$user = get_user($user_guid);
if (!$user) {
return;
}

if (!$token || !$ts || !$session_id || !$tidypics_token) {
return;
}

$hour = 60*60;
$now = time();
if ($ts < $now-$hour || $ts > $now+$hour) {
return;
}

$generated_token = md5($session_id . get_site_secret() . $ts . $user->salt);

if ($tidypics_token !== $generated_token) {
return;
}

// passed token test, so login and process action
login($user);
include $CONFIG->actions['tidypics/ajax_upload']['file'];

exit;
}

// Make sure tidypics_init is called on initialisation
register_elgg_event_handler('init','system','tidypics_init');
register_elgg_event_handler('pagesetup','system','tidypics_submenus');
register_elgg_event_handler('pagesetup','system','tidypics_adminmenu');

// Register actions
elgg_register_action("tidypics/settings", $CONFIG->pluginspath . "tidypics/actions/settings.php");
elgg_register_action("tidypics/upload", $CONFIG->pluginspath . "tidypics/actions/upload.php");
elgg_register_action("tidypics/ajax_upload", $CONFIG->pluginspath . "tidypics/actions/ajax_upload.php", 'public');
elgg_register_action("tidypics/ajax_upload_complete", $CONFIG->pluginspath . "tidypics/actions/ajax_upload_complete.php", 'public');
elgg_register_action("tidypics/embed_upload", $CONFIG->pluginspath . "tidypics/actions/embed_upload.php");
elgg_register_action("tidypics/addalbum", $CONFIG->pluginspath. "tidypics/actions/addalbum.php");
elgg_register_action("tidypics/edit", $CONFIG->pluginspath. "tidypics/actions/edit.php");
elgg_register_action("tidypics/delete", $CONFIG->pluginspath. "tidypics/actions/delete.php");
elgg_register_action("tidypics/edit_multi", $CONFIG->pluginspath. "tidypics/actions/edit_multi.php");
elgg_register_action("tidypics/addtag", $CONFIG->pluginspath . "tidypics/actions/addtag.php", 'public');
elgg_register_action("tidypics/deletetag", $CONFIG->pluginspath . "tidypics/actions/deletetag.php", 'public');
elgg_register_action("tidypics/flickrSetup", $CONFIG->pluginspath . "tidypics/actions/flickrSetup.php", 'public');

?>