1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 17:59:21 +02:00

Enhance share feature with modal dialog choices

Add Facebook / Twitter / GooglePlus external share plugins
This commit is contained in:
Afterster 2014-11-15 06:05:41 +01:00
parent 53f12cf2b2
commit 80cde0c626
23 changed files with 478 additions and 12 deletions

View file

@ -21,7 +21,16 @@
*/ */
if (!defined('NO_SESSION')) { if (!defined('NO_SESSION')) {
require_once 'lib/init.php'; if (isset($_REQUEST['ssid'])) {
define('NO_SESSION', 1);
require_once 'lib/init.php';
if (!Session::exists('stream', $_REQUEST['ssid'])) {
UI::access_denied();
exit;
}
} else {
require_once 'lib/init.php';
}
} }
ob_end_clean(); ob_end_clean();

View file

@ -36,3 +36,4 @@ should be implemented as a public method:
get_song_preview(string $track_mbid, string $artist_name, string $title) get_song_preview(string $track_mbid, string $artist_name, string $title)
stream_song_preview(string $file) stream_song_preview(string $file)
display_home() display_home()
external_share(string $url, string $text);

Binary file not shown.

After

Width:  |  Height:  |  Size: 573 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -36,6 +36,7 @@ class Share extends database_object
public $secret; public $secret;
public $public_url; public $public_url;
public $f_name;
public $f_object_link; public $f_object_link;
public $f_user; public $f_user;
public $f_allow_stream; public $f_allow_stream;
@ -199,6 +200,7 @@ class Share extends database_object
if ($details) { if ($details) {
$object = new $this->object_type($this->object_id); $object = new $this->object_type($this->object_id);
$object->format(); $object->format();
$this->f_name = $object->get_fullname();
$this->f_object_link = $object->f_link; $this->f_object_link = $object->f_link;
$user = new User($this->user); $user = new User($this->user);
$this->f_user = $user->fullname; $this->f_user = $user->fullname;
@ -305,4 +307,43 @@ class Share extends database_object
return $is_shared; return $is_shared;
} }
public static function display_ui($object_type, $object_id, $show_text = true)
{
echo "<a onclick=\"showShareDialog(event, '" . $object_type . "', " . $object_id . ");\">" . UI::get_icon('share', T_('Share'));
if ($show_text) {
echo " &nbsp;" . T_('Share');
}
echo "</a>";
}
public static function display_ui_links($object_type, $object_id)
{
echo "<ul>";
echo "<li><a href=\"". AmpConfig::get('web_path') . "/share.php?action=show_create&type=" . $object_type . "&id=" . $object_id . "\">" . UI::get_icon('share', T_('Advanced Share')) . " &nbsp;" . T_('Advanced Share') . "</a></li>";
if (AmpConfig::get('download')) {
$dllink = "";
if ($object_type == "song" || $object_type == "video") {
$dllink = AmpConfig::get('web_path') . "/play/index.php?action=download&type=" . $object_type . "&oid=" . $object_id . "&uid=-1";
} else {
if (Access::check_function('batch_download') && check_can_zip($object_type)) {
$dllink = AmpConfig::get('web_path') . "/batch.php?action=" . $object_type . "&id=" . $object_id;
}
}
if (!empty($dllink)) {
if (AmpConfig::get('require_session')) {
// Add session information to the link to avoid authentication
$dllink .= "&ssid=" . Stream::get_session();
}
echo "<li><a rel=\"nohtml\" href=\"" . $dllink . "\">" . UI::get_icon('download', T_('Temporary direct link')) . " &nbsp;" . T_('Temporary direct link') . "</a></li>";
}
}
echo "<li style='padding-top: 8px; text-align: right;'>";
$plugins = Plugin::get_plugins('external_share');
foreach ($plugins as $plugin_name) {
echo "<a href=\"" . AmpConfig::get('web_path') . "/share.php?action=external_share&plugin=" . $plugin_name . "&type=" . $object_type . "&id=" . $object_id . "\" target=\"_blank\">" . UI::get_icon('share_' . strtolower($plugin_name), $plugin_name) . "</a>&nbsp;";
}
echo "</li>";
echo "</ul>";
}
} // end of recommendation class } // end of recommendation class

View file

@ -39,7 +39,7 @@ $(function() {
$("body").delegate("a", "click", function() { $("body").delegate("a", "click", function() {
var link = $(this).attr("href"); var link = $(this).attr("href");
if (link != "" && link.indexOf("javascript:") != 0 && link != "#" && link != undefined && $(this).attr("onclick") == undefined && $(this).attr("rel") != "nohtml" && $(this).attr("target") != "_blank") { if (link !== undefined && link != "" && link.indexOf("javascript:") != 0 && link != "#" && link != undefined && $(this).attr("onclick") == undefined && $(this).attr("rel") != "nohtml" && $(this).attr("target") != "_blank") {
if ($(this).attr("rel") != "prettyPhoto") { if ($(this).attr("rel") != "prettyPhoto") {
// Ajax load Ampache pages only // Ajax load Ampache pages only
if (link.indexOf(jsWebPath) > -1) { if (link.indexOf(jsWebPath) > -1) {

View file

@ -138,6 +138,61 @@ function handleBroadcastAction(url, id) {
$("#broadcastsdialog").dialog("close"); $("#broadcastsdialog").dialog("close");
} }
/************************************************************/
/* Dialog selection to start a broadcast */
/************************************************************/
var closeshare;
function showShareDialog(e, object_type, object_id) {
$("#sharedialog").dialog("close");
var parent = this;
parent.contentUrl = jsAjaxServer + '/ajax.server.php?page=browse&action=get_share_links&object_type=' + object_type + '&object_id=' + object_id;
parent.editDialogId = '<div id="sharedialog"></div>';
$(parent.editDialogId).dialog({
modal: true,
dialogClass: 'sharedialogstyle',
resizable: false,
draggable: false,
width: 200,
height: 90,
autoOpen: false,
open: function () {
closeshare = 1;
$(document).bind('dblclick', shoverlayclickclose);
$(this).load(parent.contentUrl, function() {
$('#sharedialog').focus();
});
},
focus: function() {
closeshare = 0;
},
close: function (e) {
$(document).unbind('click');
$(this).empty();
$(this).dialog("destroy");
}
});
$("#sharedialog").dialog("option", "position", [e.clientX + 10, e.clientY]);
$("#sharedialog").dialog("open");
closeshare = 0;
}
function shoverlayclickclose(e) {
if (closeshare) {
$("#sharedialog").dialog("close");
}
closeshare = 1;
}
function handleShareAction(url, id) {
ajaxPut(url, id);
$("#sharedialog").dialog("close");
}
/***************************************************/ /***************************************************/
/* Edit modal dialog for artists, albums and songs */ /* Edit modal dialog for artists, albums and songs */
/***************************************************/ /***************************************************/

View file

@ -0,0 +1,88 @@
<?php
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
/**
*
* LICENSE: GNU General Public License, version 2 (GPLv2)
* Copyright 2001 - 2014 Ampache.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License v2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
class AmpacheFacebook {
public $name = 'Facebook';
public $categories = 'share';
public $description = 'Facebook Share';
public $url = 'https://facebook.com';
public $version = '000001';
public $min_ampache = '370027';
public $max_ampache = '999999';
/**
* Constructor
* This function does nothing...
*/
public function __construct() {
return true;
} // constructor
/**
* install
* This is a required plugin function. It inserts our preferences
* into Ampache
*/
public function install() {
return true;
} // install
/**
* uninstall
* This is a required plugin function. It removes our preferences from
* the database returning it to its original form
*/
public function uninstall() {
return true;
} // uninstall
/**
* upgrade
* This is a recommended plugin function
*/
public function upgrade() {
return true;
} // upgrade
public function external_share($url, $text)
{
$share = "https://www.facebook.com/sharer/sharer.php";
$share .= "?u=" . rawurlencode($url);
return $share;
}
/**
* load
* This loads up the data we need into this object, this stuff comes
* from the preferences.
*/
public function load($user) {
$user->set_preferences();
$data = $user->prefs;
return true;
} // load
}

View file

@ -0,0 +1,88 @@
<?php
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
/**
*
* LICENSE: GNU General Public License, version 2 (GPLv2)
* Copyright 2001 - 2014 Ampache.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License v2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
class AmpacheGooglePlus {
public $name = 'GooglePlus';
public $categories = 'share';
public $description = 'Google+ Share';
public $url = 'https://plus.google.com';
public $version = '000001';
public $min_ampache = '370027';
public $max_ampache = '999999';
/**
* Constructor
* This function does nothing...
*/
public function __construct() {
return true;
} // constructor
/**
* install
* This is a required plugin function. It inserts our preferences
* into Ampache
*/
public function install() {
return true;
} // install
/**
* uninstall
* This is a required plugin function. It removes our preferences from
* the database returning it to its original form
*/
public function uninstall() {
return true;
} // uninstall
/**
* upgrade
* This is a recommended plugin function
*/
public function upgrade() {
return true;
} // upgrade
public function external_share($url, $text)
{
$share = "https://plus.google.com/share";
$share .= "?url=" . rawurlencode($url);
return $share;
}
/**
* load
* This loads up the data we need into this object, this stuff comes
* from the preferences.
*/
public function load($user) {
$user->set_preferences();
$data = $user->prefs;
return true;
} // load
}

View file

@ -0,0 +1,91 @@
<?php
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
/**
*
* LICENSE: GNU General Public License, version 2 (GPLv2)
* Copyright 2001 - 2014 Ampache.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License v2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
class AmpacheTwitter {
public $name = 'Twitter';
public $categories = 'share';
public $description = 'Twitter Share';
public $url = 'https://twitter.com';
public $version = '000001';
public $min_ampache = '370027';
public $max_ampache = '999999';
/**
* Constructor
* This function does nothing...
*/
public function __construct() {
return true;
} // constructor
/**
* install
* This is a required plugin function. It inserts our preferences
* into Ampache
*/
public function install() {
return true;
} // install
/**
* uninstall
* This is a required plugin function. It removes our preferences from
* the database returning it to its original form
*/
public function uninstall() {
return true;
} // uninstall
/**
* upgrade
* This is a recommended plugin function
*/
public function upgrade() {
return true;
} // upgrade
public function external_share($url, $text)
{
$share = "https://twitter.com/share";
$share .= "?url=" . rawurlencode($url);
if (!empty($text)) {
$share .= "&text=" . rawurlencode($text);
}
return $share;
}
/**
* load
* This loads up the data we need into this object, this stuff comes
* from the preferences.
*/
public function load($user) {
$user->set_preferences();
$data = $user->prefs;
return true;
} // load
}

View file

@ -187,6 +187,15 @@ switch ($_REQUEST['action']) {
$browse->show_objects(); $browse->show_objects();
$results[$browse->get_content_div()] = ob_get_clean(); $results[$browse->get_content_div()] = ob_get_clean();
break; break;
case 'get_share_links':
$object_type = $_REQUEST['object_type'];
$object_id = intval($_REQUEST['object_id']);
if (Core::is_library_item($object_type) && $object_id > 0) {
Share::display_ui_links($object_type, $object_id);
exit;
}
break;
default: default:
$results['rfc3514'] = '0x1'; $results['rfc3514'] = '0x1';
break; break;

View file

@ -108,6 +108,30 @@ switch ($action) {
} }
UI::show_footer(); UI::show_footer();
exit; exit;
case 'external_share':
if (AmpConfig::get('demo_mode')) {
UI::access_denied();
exit;
}
$plugin = new Plugin($_GET['plugin']);
if (!$plugin) {
UI::access_denied('Access Denied - Unkown external share plugin.');
exit;
}
$plugin->load($GLOBALS['user']);
$type = $_REQUEST['type'];
$id = $_REQUEST['id'];
$allow_download = (($type == 'song' && Access::check_function('download')) || Access::check_function('batch_download'));
$secret = Share::generate_secret();
$share_id = Share::create_share($type, $id, true, $allow_download, AmpConfig::get('share_expire'), $secret, 0);
$share = new Share($share_id);
$share->format(true);
header("Location: " . $plugin->_plugin->external_share($share->public_url, $share->f_name));
exit;
} }
/** /**

View file

@ -255,3 +255,64 @@
.broadcastsdialogstyle.ui-dialog .ui-dialog-buttonset button:focus:active { .broadcastsdialogstyle.ui-dialog .ui-dialog-buttonset button:focus:active {
display: none; display: none;
} }
/***********************************************
jQuery share dialog
***********************************************/
.sharedialogstyle.ui-dialog {
background-color: #222;
font-size: 10px;
overflow-x: hidden;
overflow-y: auto;
padding: 0;
margin: 0;
width: 100%;
height: 100%;
border-radius: 2px;
border-color: #1d1d1d;
border: 2px solid rgba(0,0,0,0.15);
z-index: 9999;
}
.sharedialogstyle.ui-widget-content a {
background-color: #222;
color: #eee;
text-decoration: none;
text-align: left;
padding: 0.4em;
}
.sharedialogstyle.ui-widget-content a:hover {
color: #ff9d00;
cursor: pointer;
}
.sharedialogstyle.ui-dialog .ui-dialog-titlebar {
display: none;
}
.sharedialogstyle.ui-dialog .ui-dialog-title {
display: none;
}
.sharedialogstyle.ui-dialog .ui-dialog-content {
background-color: #222;
color: #999;
border: 0;
}
.sharedialogstyle.ui-dialog .ui-dialog-buttonpane {
display: none;
}
.sharedialogstyle.ui-dialog .ui-dialog-buttonset button {
display: none;
}
.sharedialogstyle.ui-dialog .ui-dialog-buttonset button:hover {
display: none;
}
.sharedialogstyle.ui-dialog .ui-dialog-buttonset button:focus:active {
display: none;
}

View file

@ -105,8 +105,7 @@ if (AmpConfig::get('show_played_times')) {
<?php } ?> <?php } ?>
<?php if (AmpConfig::get('share')) { ?> <?php if (AmpConfig::get('share')) { ?>
<li> <li>
<a href="<?php echo $web_path; ?>/share.php?action=show_create&type=album&id=<?php echo $album->id; ?>"><?php echo UI::get_icon('share', T_('Share')); ?></a> <?php Share::display_ui('album', $album->id); ?>
<a href="<?php echo $web_path; ?>/share.php?action=show_create&type=album&id=<?php echo $album->id; ?>"><?php echo T_('Share'); ?></a>
</li> </li>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>

View file

@ -125,7 +125,7 @@ if ($directplay_limit > 0) {
<a href="<?php echo AmpConfig::get('web_path'); ?>/shout.php?action=show_add_shout&type=album&id=<?php echo $c_album->id; ?>"><?php echo UI::get_icon('comment', T_('Post Shout')); ?></a> <a href="<?php echo AmpConfig::get('web_path'); ?>/shout.php?action=show_add_shout&type=album&id=<?php echo $c_album->id; ?>"><?php echo UI::get_icon('comment', T_('Post Shout')); ?></a>
<?php } ?> <?php } ?>
<?php if (AmpConfig::get('share')) { ?> <?php if (AmpConfig::get('share')) { ?>
<a href="<?php echo $web_path; ?>/share.php?action=show_create&type=album&id=<?php echo $c_album->id; ?>"><?php echo UI::get_icon('share', T_('Share')); ?></a> <?php Share::display_ui('album', $c_album->id, false); ?>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
<?php if (Access::check_function('batch_download') && check_can_zip('album')) { ?> <?php if (Access::check_function('batch_download') && check_can_zip('album')) { ?>

View file

@ -73,7 +73,7 @@ if (Art::is_enabled()) {
</a> </a>
<?php } ?> <?php } ?>
<?php if (AmpConfig::get('share') && (!$libitem->allow_group_disks || ($libitem->allow_group_disks && !count($libitem->album_suite)))) { ?> <?php if (AmpConfig::get('share') && (!$libitem->allow_group_disks || ($libitem->allow_group_disks && !count($libitem->album_suite)))) { ?>
<a href="<?php echo $web_path; ?>/share.php?action=show_create&type=album&id=<?php echo $libitem->id; ?>"><?php echo UI::get_icon('share', T_('Share')); ?></a> <?php Share::display_ui('album', $libitem->id, false); ?>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
<?php if (Access::check_function('batch_download') && check_can_zip('album')) { ?> <?php if (Access::check_function('batch_download') && check_can_zip('album')) { ?>

View file

@ -62,7 +62,7 @@
<?php } ?> <?php } ?>
<?php if (Access::check('interface', '25')) { ?> <?php if (Access::check('interface', '25')) { ?>
<?php if (AmpConfig::get('share')) { ?> <?php if (AmpConfig::get('share')) { ?>
<a href="<?php echo AmpConfig::get('web_path'); ?>/share.php?action=show_create&type=playlist&id=<?php echo $libitem->id; ?>"><?php echo UI::get_icon('share', T_('Share')); ?></a> <?php Share::display_ui('playlist', $libitem->id, false); ?>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
<?php if ($libitem->has_access()) { ?> <?php if ($libitem->has_access()) { ?>

View file

@ -62,7 +62,7 @@
<?php } ?> <?php } ?>
<?php if (Access::check('interface', '25')) { ?> <?php if (Access::check('interface', '25')) { ?>
<?php if (AmpConfig::get('share')) { ?> <?php if (AmpConfig::get('share')) { ?>
<a href="<?php echo AmpConfig::get('web_path'); ?>/share.php?action=show_create&type=song&id=<?php echo $libitem->id; ?>"><?php echo UI::get_icon('share', T_('Share')); ?></a> <?php Share::display_ui('song', $libitem->id, false); ?>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
<?php if (get_class($playlist) == "Playlist" && $playlist->has_access()) { ?> <?php if (get_class($playlist) == "Playlist" && $playlist->has_access()) { ?>

View file

@ -72,7 +72,7 @@ $button_flip_state_id = 'button_flip_state_' . $song->id;
</a> </a>
<?php } ?> <?php } ?>
<?php if (AmpConfig::get('share')) { ?> <?php if (AmpConfig::get('share')) { ?>
<a href="<?php echo AmpConfig::get('web_path'); ?>/share.php?action=show_create&type=song&id=<?php echo $song->id; ?>"><?php echo UI::get_icon('share', T_('Share')); ?></a> <?php Share::display_ui('song', $song->id, false); ?>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
<?php if (Access::check_function('download')) { ?> <?php if (Access::check_function('download')) { ?>

View file

@ -65,7 +65,7 @@
<a href="<?php echo AmpConfig::get('web_path'); ?>/shout.php?action=show_add_shout&type=song&id=<?php echo $libitem->id; ?>"><?php echo UI::get_icon('comment', T_('Post Shout')); ?></a> <a href="<?php echo AmpConfig::get('web_path'); ?>/shout.php?action=show_add_shout&type=song&id=<?php echo $libitem->id; ?>"><?php echo UI::get_icon('comment', T_('Post Shout')); ?></a>
<?php } ?> <?php } ?>
<?php if (AmpConfig::get('share')) { ?> <?php if (AmpConfig::get('share')) { ?>
<a href="<?php echo $web_path; ?>/share.php?action=show_create&type=song&id=<?php echo $libitem->id; ?>"><?php echo UI::get_icon('share', T_('Share')); ?></a> <?php Share::display_ui('song', $libitem->id, false); ?>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
<?php if (Access::check_function('download')) { ?> <?php if (Access::check_function('download')) { ?>

View file

@ -85,7 +85,7 @@ foreach ($subtitles as $subtitle) {
<a href="<?php echo AmpConfig::get('web_path'); ?>/shout.php?action=show_add_shout&type=video&id=<?php echo $video->id; ?>"><?php echo UI::get_icon('comment', T_('Post Shout')); ?></a> <a href="<?php echo AmpConfig::get('web_path'); ?>/shout.php?action=show_add_shout&type=video&id=<?php echo $video->id; ?>"><?php echo UI::get_icon('comment', T_('Post Shout')); ?></a>
<?php } ?> <?php } ?>
<?php if (AmpConfig::get('share')) { ?> <?php if (AmpConfig::get('share')) { ?>
<a href="<?php echo AmpConfig::get('web_path'); ?>/share.php?action=show_create&type=video&id=<?php echo $video->id; ?>"><?php echo UI::get_icon('share', T_('Share')); ?></a> <?php Share::display_ui('video', $video->id, false); ?>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
<?php if (Access::check_function('download')) { ?> <?php if (Access::check_function('download')) { ?>

View file

@ -77,7 +77,7 @@ if ($video_type != 'video') {
<a href="<?php echo AmpConfig::get('web_path'); ?>/shout.php?action=show_add_shout&type=video&id=<?php echo $libitem->id; ?>"><?php echo UI::get_icon('comment', T_('Post Shout')); ?></a> <a href="<?php echo AmpConfig::get('web_path'); ?>/shout.php?action=show_add_shout&type=video&id=<?php echo $libitem->id; ?>"><?php echo UI::get_icon('comment', T_('Post Shout')); ?></a>
<?php } ?> <?php } ?>
<?php if (AmpConfig::get('share')) { ?> <?php if (AmpConfig::get('share')) { ?>
<a href="<?php echo $web_path; ?>/share.php?action=show_create&type=video&id=<?php echo $libitem->id; ?>"><?php echo UI::get_icon('share', T_('Share')); ?></a> <?php Share::display_ui('video', $libitem->id, false); ?>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
<?php if (Access::check_function('download')) { ?> <?php if (Access::check_function('download')) { ?>