diff options
author | cash <cash.costello@gmail.com> | 2011-11-20 18:41:34 -0500 |
---|---|---|
committer | cash <cash.costello@gmail.com> | 2011-11-20 18:41:34 -0500 |
commit | 9b814dd2124a8c71dec3a8d510d288f040b03b9e (patch) | |
tree | 63a53f0445df06963de1537af58faba38213b587 | |
parent | c51b483f24936c8d04a54a6999412937ec21c49a (diff) | |
download | elgg-9b814dd2124a8c71dec3a8d510d288f040b03b9e.tar.gz elgg-9b814dd2124a8c71dec3a8d510d288f040b03b9e.tar.bz2 |
working on settings
-rw-r--r-- | actions/photos/admin/settings.php (renamed from actions/admin/settings.php) | 26 | ||||
-rw-r--r-- | activate.php | 32 | ||||
-rw-r--r-- | classes/TidypicsAlbum.php | 41 | ||||
-rw-r--r-- | deactivate.php | 10 | ||||
-rw-r--r-- | languages/en.php | 3 | ||||
-rw-r--r-- | pages/photos/image/view.php | 52 | ||||
-rw-r--r-- | pages/photos/owner.php | 15 | ||||
-rw-r--r-- | pages/viewimage.php | 62 | ||||
-rw-r--r-- | start.php | 59 | ||||
-rw-r--r-- | views/default/admin/settings/tidypics.php | 11 | ||||
-rw-r--r-- | views/default/forms/photos/admin/settings.php | 80 | ||||
-rw-r--r-- | views/default/object/album/full.php | 10 | ||||
-rw-r--r-- | views/default/object/image/full.php | 66 |
13 files changed, 348 insertions, 119 deletions
diff --git a/actions/admin/settings.php b/actions/photos/admin/settings.php index d3801f655..a401d9bf3 100644 --- a/actions/admin/settings.php +++ b/actions/photos/admin/settings.php @@ -1,25 +1,24 @@ <?php /** - * Save settings of Tidypics + * Save Tidypics plugin settings * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 */ -global $CONFIG; +$plugin = elgg_get_plugin_from_id('tidypics'); -admin_gatekeeper(); -action_gatekeeper(); - - -// Params array (text boxes and drop downs) $params = get_input('params'); -$result = false; foreach ($params as $k => $v) { - if (!set_plugin_setting($k, $v, 'tidypics')) { - register_error(sprintf(elgg_echo('plugins:settings:save:fail'), 'tidypics')); - forward($_SERVER['HTTP_REFERER']); + if (!$plugin->setSetting($k, $v)) { + register_error(elgg_echo('plugins:settings:save:fail', array('tidypics'))); + forward(REFERER); } } +system_message(elgg_echo('tidypics:settings:save:ok')); +forward(REFERER); + // check boxes if (is_array(get_input('download_link'))) { // this can be done due to way Elgg uses checkboxes set_plugin_setting('download_link', 'enabled', 'tidypics'); @@ -76,8 +75,3 @@ $image_sizes['thumb_image_width'] = get_input('thumb_width'); $image_sizes['thumb_image_height'] = get_input('thumb_width'); set_plugin_setting('image_sizes', serialize($image_sizes), 'tidypics'); - - -system_message(elgg_echo('tidypics:settings:save:ok')); - -forward($_SERVER['HTTP_REFERER']); diff --git a/activate.php b/activate.php new file mode 100644 index 000000000..ca74c6119 --- /dev/null +++ b/activate.php @@ -0,0 +1,32 @@ +<?php +/** + * Activate Tidypics + * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 + */ + +// register classes +if (get_subtype_id('object', 'album')) { + update_subtype('object', 'album', 'TidypicsAlbum'); +} else { + add_subtype('object', 'album', 'TidypicsAlbum'); +} +if (get_subtype_id('object', 'image')) { + update_subtype('object', 'image', 'TidypicsImage'); +} else { + add_subtype('object', 'image', 'TidypicsImage'); +} + +// set default settings +$plugin = elgg_get_plugin_from_id('tidypics'); + +$defaults = array( + 'tagging' => true, +); + +foreach ($defaults as $name => $value) { + if ($plugin->getSetting($name) === null) { + $plugin->setSetting($name, $value); + } +} diff --git a/classes/TidypicsAlbum.php b/classes/TidypicsAlbum.php index 18fa556e3..f1fd20669 100644 --- a/classes/TidypicsAlbum.php +++ b/classes/TidypicsAlbum.php @@ -9,12 +9,20 @@ class TidypicsAlbum extends ElggObject { - protected function initialise_attributes() { - parent::initialise_attributes(); + + /** + * Sets the internal attributes + */ + protected function initializeAttributes() { + parent::initializeAttributes(); $this->attributes['subtype'] = "album"; } + /** + * Constructor + * @param mixed $guid + */ public function __construct($guid = null) { parent::__construct($guid); } @@ -36,6 +44,8 @@ class TidypicsAlbum extends ElggObject { mkdir(tp_get_img_dir() . $this->guid, 0755, true); + elgg_trigger_event('create', 'album', $this); + return true; } @@ -68,7 +78,7 @@ class TidypicsAlbum extends ElggObject { * @param int $offset * @return array */ - public function getImages($limit, $offset=0) { + public function getImages($limit, $offset = 0) { $imageList = $this->getImageList(); if ($offset > count($imageList)) { return array(); @@ -90,7 +100,7 @@ class TidypicsAlbum extends ElggObject { * @param int $offset * @return string */ - public function viewImages($limit, $offset=0) { + public function viewImages($limit, $offset = 0) { $images = $this->getImages($limit, $offset); if (count($images) == 0) { return ''; @@ -101,9 +111,16 @@ class TidypicsAlbum extends ElggObject { return elgg_view_entity_list($images, $count, $offset, $limit, false, false, true); } + /** + * Get the URL for the album cover image + * + * @param string $size + * @return string + */ public function getCoverImageURL($size = 'small') { - if ($this->cover) { - $url = "pg/photos/thumbnail/$this->cover/$size/"; + $coverGuid = $this->getCoverImageGuid(); + if ($coverGuid) { + $url = "pg/photos/thumbnail/$coverGuid/$size/"; } else { $url = "mod/tidypics/graphics/empty_album.png"; } @@ -237,16 +254,19 @@ class TidypicsAlbum extends ElggObject { public function removeImage($imageGuid) { $imageList = $this->getImageList(); $key = array_search($imageGuid, $imageList); - if ($key === FALSE) { - return FALSE; + if ($key === false) { + return false; } unset($imageList[$key]); $this->setImageList($imageList); - return TRUE; + return true; } + /** + * Delete all the images in this album + */ protected function deleteImages() { // get all the images from this album as long as less than 999 images $images = elgg_get_entities(array( @@ -264,6 +284,9 @@ class TidypicsAlbum extends ElggObject { } } + /** + * Delete the album directory on disk + */ protected function deleteAlbumDir() { $tmpfile = new ElggFile(); $tmpfile->setFilename('image/' . $this->guid . '/._tmp_del_tidypics_album_'); diff --git a/deactivate.php b/deactivate.php new file mode 100644 index 000000000..55191a9e4 --- /dev/null +++ b/deactivate.php @@ -0,0 +1,10 @@ +<?php +/** + * Deactive Tidypics + * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 + */ + +update_subtype('object', 'album'); +update_subtype('object', 'image'); diff --git a/languages/en.php b/languages/en.php index 63d4632c6..e93ee3197 100644 --- a/languages/en.php +++ b/languages/en.php @@ -11,6 +11,7 @@ $english = array( 'photos' => "Photos", 'album' => "Photo Album", 'albums' => "Photo Albums", + 'admin:settings:tidypics' => 'Tidypics', 'photos:add' => "Create album", 'images:upload' => "Upload photos", @@ -21,7 +22,7 @@ $english = array( 'album:user' => "%s's photo albums", 'album:friends' => "Friends' photo albums", 'album:all' => "All site photo albums", - 'album:group' => "Group albums", + 'photos:group' => "Group photos", 'item:object:image' => "Photos", 'item:object:album' => "Albums", 'tidypics:uploading:images' => "Please wait. Uploading images.", diff --git a/pages/photos/image/view.php b/pages/photos/image/view.php new file mode 100644 index 000000000..d9231eb08 --- /dev/null +++ b/pages/photos/image/view.php @@ -0,0 +1,52 @@ +<?php +/** + * View an image + * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 + */ + +group_gatekeeper(); + +// get the photo entity +$photo_guid = (int) get_input('guid'); +$photo = get_entity($photo_guid); + +// set page owner based on owner of photo album +$album = $photo->getContainerEntity(); +if ($album) { + elgg_set_page_owner_guid($album->getContainerGUID()); +} +$owner = elgg_get_page_owner_entity(); + +// set up breadcrumbs +elgg_push_breadcrumb(elgg_echo('photos'), 'photos/all'); +if (elgg_instanceof($page_owner, 'group')) { + elgg_push_breadcrumb($owner->name, "photos/group/$owner->guid/all"); +} else { + elgg_push_breadcrumb($owner->name, "photos/owner/$owner->username"); +} +elgg_push_breadcrumb($album->title, $album->getURL()); +elgg_push_breadcrumb($photo->title); + +// add download button to title menu +elgg_register_menu_item('title', array( + 'name' => 'download', + 'href' => 'photos/download', + 'text' => elgg_echo('image:download'), + 'link_class' => 'elgg-button elgg-button-action', +)); + +$content = elgg_view_entity($photo, array('full_view' => true)); + +$body = elgg_view_layout('content', array( + 'filter' => false, + 'content' => $content, + 'title' => $photo->title, + 'sidebar' => elgg_view('tidypics/sidebar', array( + 'page' => 'view', + 'image' => $photo, + )), +)); + +echo elgg_view_page($photo->title, $body); diff --git a/pages/photos/owner.php b/pages/photos/owner.php index f6582e326..214cd2e37 100644 --- a/pages/photos/owner.php +++ b/pages/photos/owner.php @@ -35,11 +35,22 @@ elgg_pop_context(); elgg_register_title_button(); -$body = elgg_view_layout('content', array( +$params = array( 'filter_context' => 'mine', 'content' => $content, 'title' => $title, 'sidebar' => elgg_view('tidypics/sidebar', array('page' => 'owner')), -)); +); + +// don't show filter if out of filter context +if ($owner instanceof ElggGroup) { + $params['filter'] = false; +} + +if ($owner->getGUID() != elgg_get_logged_in_user_guid()) { + $params['filter_context'] = ''; +} + +$body = elgg_view_layout('content', $params); echo elgg_view_page($title, $body); diff --git a/pages/viewimage.php b/pages/viewimage.php deleted file mode 100644 index 890f7e8c4..000000000 --- a/pages/viewimage.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php - -/** - * Tidypics image view - * - * Display a view of a single image - */ - -// Load Elgg engine -include_once dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php"; - -// if this page belongs to a closed group, prevent anyone outside group from seeing -if (is_callable('group_gatekeeper')) { - group_gatekeeper(); -} - -// get the album entity -$photo_guid = (int) get_input('guid'); -$photo = get_entity($photo_guid); - -// panic if we can't get it -if (!$photo) { - forward(); -} - -// set page owner based on owner of photo album -set_page_owner($photo->owner_guid); -$album = get_entity($photo->container_guid); -if ($album) { - $owner_guid = $album->container_guid; - if ($owner_guid) { - set_page_owner($owner_guid); - } -} - - -$page_owner = page_owner_entity(); -if ($page_owner instanceof ElggGroup) { - add_submenu_item( sprintf(elgg_echo('album:group'),$page_owner->name), - $CONFIG->wwwroot . "pg/photos/owned/" . $page_owner->username); -} - -if (can_write_to_container(0, $album->container_guid)) { - add_submenu_item( elgg_echo('image:edit'), - $CONFIG->wwwroot . 'pg/photos/edit/' . $photo_guid, - 'photos'); - $ts = time(); - $token = generate_action_token($ts); - add_submenu_item( elgg_echo('image:delete'), - $CONFIG->wwwroot . 'action/tidypics/delete?guid=' . $photo_guid . '&__elgg_token=' . $token . '&__elgg_ts=' . $ts, - 'photos', - true); -} - - -$title = $photo->title; -$area2 = elgg_view_title($title); -$area2 .= elgg_view_entity($photo, true); - -$body = elgg_view_layout('two_column_left_sidebar', '', $area2); - -page_draw($title, $body); @@ -12,9 +12,8 @@ elgg_register_event_handler('init', 'system', 'tidypics_init'); * Tidypics plugin initialization */ function tidypics_init() { - global $CONFIG; - // include core libraries + // Include core libraries require dirname(__FILE__) . "/lib/tidypics.php"; // Set up site menu @@ -27,6 +26,13 @@ function tidypics_init() { // Extend CSS elgg_extend_view('css/elgg', 'tidypics/css'); + // Add photos link to owner block/hover menus + elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'tidypics_owner_block_menu'); + + // Add admin menu item + elgg_register_admin_menu_item('configure', 'tidypics', 'settings'); + +/* // Extend hover-over and profile menu elgg_extend_view('profile/menu/links','tidypics/hover_menu'); @@ -75,9 +81,9 @@ function tidypics_init() { // ajax handler for uploads when use_only_cookies is set register_plugin_hook('forward', 'system', 'tidypics_ajax_session_handler'); - +*/ // Register actions - $base_dir = $CONFIG->pluginspath . "tidypics/actions/photos"; + $base_dir = elgg_get_plugins_path() . 'tidypics/actions/photos'; elgg_register_action("photos/album/save", "$base_dir/album/save.php"); elgg_register_action("photos/delete", "$base_dir/delete.php"); elgg_register_action("photos/image/upload", "$base_dir/image/upload.php"); @@ -89,11 +95,13 @@ function tidypics_init() { register_action("tidypics/addtag", false, "$base_dir/addtag.php"); register_action("tidypics/deletetag", false, "$base_dir/deletetag.php"); - register_action("tidypics/admin/settings", false, "$base_dir/admin/settings.php", true); + elgg_register_action("photos/admin/settings", "$base_dir/admin/settings.php", 'admin'); register_action("tidypics/admin/upgrade", false, "$base_dir/admin/upgrade.php", true); - elgg_register_library('tidypics:upload', $CONFIG->pluginspath . 'tidypics/lib/upload.php'); - elgg_register_library('tidypics:resize', $CONFIG->pluginspath . 'tidypics/lib/resize.php'); + // Register libraries + $base_dir = elgg_get_plugins_path() . 'tidypics/lib'; + elgg_register_library('tidypics:upload', "$base/upload.php"); + elgg_register_library('tidypics:resize', "$base/resize.php"); } /** @@ -263,31 +271,25 @@ function tidypics_page_handler($page) { case "owned": // albums owned by container entity case "owner": - if (isset($page[1])) { - set_input('username', $page[1]); - } require "$base/owner.php"; break; case "friends": // albums of friends - if (isset($page[1])) { - set_input('username', $page[1]); - } require "$base/friends.php"; break; + case "group": // albums of a group + require "$base/owner.php"; + break; + case "album": // view an album individually - if (isset($page[1])) { - set_input('guid', $page[1]); - } + set_input('guid', $page[1]); require "$base/album/view.php"; break; case "new": // create new album case "add": - if (isset($page[1])) { - set_input('guid', $page[1]); - } + set_input('guid', $page[1]); require "$base/album/add.php"; break; @@ -393,6 +395,25 @@ function tidypics_page_handler($page) { } /** + * Add a menu item to an ownerblock + */ +function tidypics_owner_block_menu($hook, $type, $return, $params) { + if (elgg_instanceof($params['entity'], 'user')) { + $url = "photos/owner/{$params['entity']->username}"; + $item = new ElggMenuItem('photos', elgg_echo('photos'), $url); + $return[] = $item; + } else { + if ($params['entity']->blog_enable != "no") { + $url = "photos/group/{$params['entity']->guid}/all"; + $item = new ElggMenuItem('photos', elgg_echo('photos:group'), $url); + $return[] = $item; + } + } + + return $return; +} + +/** * Override permissions for group albums and images * * @param string $hook diff --git a/views/default/admin/settings/tidypics.php b/views/default/admin/settings/tidypics.php new file mode 100644 index 000000000..aaaebd371 --- /dev/null +++ b/views/default/admin/settings/tidypics.php @@ -0,0 +1,11 @@ +<?php +/** + * Admin page + * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 + */ + +echo elgg_view('output/longtext', array('value' => elgg_echo('tidypics:admin:instructions'))); + +echo elgg_view_form('photos/admin/settings'); diff --git a/views/default/forms/photos/admin/settings.php b/views/default/forms/photos/admin/settings.php index 06b3f4cb9..ea1e12de8 100644 --- a/views/default/forms/photos/admin/settings.php +++ b/views/default/forms/photos/admin/settings.php @@ -3,18 +3,84 @@ * Tidypics admin settings form body */ -$plugin = find_plugin_settings('tidypics'); +$plugin = elgg_get_plugin_from_id('tidypics'); + +echo '<div>'; +$checked = $plugin->tagging ? 'checked' : false; +echo elgg_view('input/checkbox', array( + 'name' => 'params[tagging]', + 'value' => true, + 'checked' => (bool)$plugin->tagging, +)); +echo ' ' . elgg_echo('tidypics:settings:tagging'); +echo '</div>'; + +// Thumbnail sizes +echo '<div>'; +echo '<h3>' . elgg_echo('tidypics:settings:heading:sizes') . '</h3>'; +echo "<h6>You must edit the css if you change the default sizes</h6>"; +$image_sizes = unserialize($plugin->image_sizes); + +/* +if(!$image_sizes) { + $image_sizes = array(); // set default values + $image_sizes['large_image_width'] = $image_sizes['large_image_height'] = 600; + $image_sizes['small_image_width'] = $image_sizes['small_image_height'] = 153; + $image_sizes['thumb_image_width'] = $image_sizes['thumb_image_height'] = 60; +} else { + $image_sizes = unserialize($image_sizes); +} + * + */ + +$sizes = array('large', 'small', 'tiny'); +foreach ($sizes as $size) { + echo elgg_echo("tidypics:settings:{$size}size"); + echo ' width: '; + echo elgg_view('input/text', array( + 'name' => "{$size}_thumb_width", + 'value' => $image_sizes["{$size}_image_width"], + 'style' => 'width: 150px;' + )); + echo ' height: '; + echo elgg_view('input/text', array( + 'name' => "{$size}_thumb_height", + 'value' => $image_sizes["{$size}_image_height"], + 'style' => 'width: 150px;' + )); +} + +$form_body .= 'width: <input style="width: 20%;" type="text" name="large_thumb_width" value=' . "\"{$image_sizes['large_image_width']}\"" . ' class="input-text" /> '; +$form_body .= 'height: <input style="width: 20%;" type="text" name="large_thumb_height" value=' . "\"{$image_sizes['large_image_height']}\"" . ' class="input-text" /></p>'; + +$form_body .= "<p>" . elgg_echo('tidypics:settings:smallsize') . "<br />"; +$form_body .= 'width and height: <input style="width: 20%;" type="text" name="small_thumb_width" value=' . "\"{$image_sizes['small_image_width']}\"" . ' class="input-text" /> '; +//$form_body .= 'height: <input style="width: 20%;" type="text" name="small_thumb_height" value=' . "\"{$image_sizes['small_image_height']}\"" . ' class="input-text" /></p>'; + +$form_body .= "<p>" . elgg_echo('tidypics:settings:thumbsize') . "<br />"; +$form_body .= 'width and height: <input style="width: 20%;" type="text" name="thumb_width" value=' . "\"{$image_sizes['thumb_image_width']}\"" . ' class="input-text" /> '; +//$form_body .= 'height: <input style="width: 20%;" type="text" name="thumb_height" value=' . "\"{$image_sizes['thumb_image_height']}\"" . ' class="input-text" /></p>'; +echo '</div>'; + +echo elgg_view('input/submit', array('value' => elgg_echo("save"))); + +return true; // Main settings -$form_body = '<h3>' . elgg_echo('tidypics:settings:heading:main') . '</h3>'; +echo '<h3>' . elgg_echo('tidypics:settings:heading:main') . '</h3>'; // Tagging -$tagging = $plugin->tagging; -if (!$tagging) { - $tagging = "enabled"; -} -$form_body .= '<p class="admin_debug">' . elgg_view("input/checkboxes", array('options' => array(elgg_echo('tidypics:settings:tagging') => 'enabled'), 'internalname' => 'tagging', 'value' => $tagging )) . "</p>"; +$tagging = $plugin->tagging ? $plugin->tagging : 'enabled'; +echo '<div>'; +echo elgg_view("input/checkboxes", array( + 'name' => 'tagging', + 'value' => $tagging, + 'options' => array( + elgg_echo('tidypics:settings:tagging') => 'enabled' + ), +)); +echo "</div>"; // Download Link $download_link = $plugin->download_link; diff --git a/views/default/object/album/full.php b/views/default/object/album/full.php index 4d2d8c88b..e350d2327 100644 --- a/views/default/object/album/full.php +++ b/views/default/object/album/full.php @@ -41,9 +41,13 @@ $params = array( $params = $params + $vars; $summary = elgg_view('object/elements/summary', $params); -$body = elgg_view('output/longtext', array( - 'value' => $album->description, -)); +$body = ''; +if ($album->description) { + $body = elgg_view('output/longtext', array( + 'value' => $album->description, + 'class' => 'mbm', + )); +} $body .= elgg_list_entities(array( 'type' => 'object', 'subtype' => 'image', diff --git a/views/default/object/image/full.php b/views/default/object/image/full.php index a4abe2daf..d08c03f9c 100644 --- a/views/default/object/image/full.php +++ b/views/default/object/image/full.php @@ -1,2 +1,68 @@ <?php +/** + * Full view of an image + * + * @uses $vars['entity'] TidypicsImage + * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 + */ +$image = $photo = $vars['entity']; + +$img = elgg_view('output/img', array( + 'src' => $image->getSrcURL('large'), + 'alt' => $image->getTitle(), + 'class' => 'elgg-photo', +)); + +$content = elgg_view('output/url', array( + 'text' => $img, + 'href' => $image->getURL(), +)); + +$owner_link = elgg_view('output/url', array( + 'href' => "photos/owner/" . $photo->getOwnerEntity()->username, + 'text' => $photo->getOwnerEntity()->name, +)); +$author_text = elgg_echo('byline', array($owner_link)); + +$owner_icon = elgg_view_entity_icon($photo->getOwnerEntity(), 'tiny'); + +$metadata = elgg_view_menu('entity', array( + 'entity' => $vars['entity'], + 'handler' => 'photos', + 'sort_by' => 'priority', + 'class' => 'elgg-menu-hz', +)); + +$subtitle = "$author_text $date $categories $comments_link"; + +$params = array( + 'entity' => $photo, + 'title' => false, + 'metadata' => $metadata, + 'subtitle' => $subtitle, + 'tags' => $tags, +); +$list_body = elgg_view('object/elements/summary', $params); + +$params = array('class' => 'mbl'); +$summary = elgg_view_image_block($owner_icon, $list_body, $params); + +echo $summary; + +if ($photo->description) { + echo elgg_view('output/longtext', array( + 'value' => $photo->description, + 'class' => 'mbl', + )); +} + +echo '<div class="tidypics-wrapper-photo">'; +echo elgg_view('tidypics/tagging/help'); +echo elgg_view('tidypics/tagging/select', array('photo' => $photo)); +echo $content; +echo '</div>'; + + echo elgg_view_comments($photo);
\ No newline at end of file |