mirror of
https://github.com/friendica/friendica
synced 2024-11-18 16:23:41 +00:00
open friendica photos from the stream with colorbox
This commit is contained in:
parent
deaaeec047
commit
eb1e882d7c
2 changed files with 70 additions and 0 deletions
28
js/theme.js
28
js/theme.js
|
@ -73,6 +73,34 @@ $(document).ready(function(){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add Colorbox for viewing Network page images
|
||||||
|
//var cBoxClasses = new Array();
|
||||||
|
$(".wall-item-body a img").each(function(){
|
||||||
|
var aElem = $(this).parent();
|
||||||
|
var imgHref = aElem.attr("href");
|
||||||
|
|
||||||
|
// We need to make sure we only put a Colorbox on links to Friendica images
|
||||||
|
// We'll try to do this by looking for links of the form
|
||||||
|
// .../photo/ab803d8eg08daf85023adfec08 (with nothing more following), in hopes
|
||||||
|
// that that will be unique enough
|
||||||
|
if(imgHref.match(/\/photo\/[a-fA-F0-9]+(-[0-9]\.[\w]+?)?$/)) {
|
||||||
|
|
||||||
|
// Add a unique class to all the images of a certain post, to allow scrolling through
|
||||||
|
var cBoxClass = $(this).closest(".wall-item-body").attr("id") + "-lightbox";
|
||||||
|
$(this).addClass(cBoxClass);
|
||||||
|
|
||||||
|
// if( $.inArray(cBoxClass, cBoxClasses) < 0 ) {
|
||||||
|
// cBoxClasses.push(cBoxClass);
|
||||||
|
// }
|
||||||
|
|
||||||
|
aElem.colorbox({
|
||||||
|
maxHeight: '90%',
|
||||||
|
photo: true, // Colorbox doesn't recognize a URL that don't end in .jpg, etc. as a photo
|
||||||
|
rel: cBoxClass //$(this).attr("class").match(/wall-item-body-[\d]+-lightbox/)[0]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// overwrite Dialog.show from main js to load the filebrowser into a bs modal
|
// overwrite Dialog.show from main js to load the filebrowser into a bs modal
|
||||||
Dialog.show = function(url) {
|
Dialog.show = function(url) {
|
||||||
var modal = $('#modal').modal();
|
var modal = $('#modal').modal();
|
||||||
|
|
42
theme.php
42
theme.php
|
@ -83,11 +83,53 @@ EOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
function frio_install() {
|
function frio_install() {
|
||||||
|
register_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
|
||||||
|
|
||||||
logger("installed theme frio");
|
logger("installed theme frio");
|
||||||
}
|
}
|
||||||
|
|
||||||
function frio_uninstall() {
|
function frio_uninstall() {
|
||||||
|
unregister_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
|
||||||
|
|
||||||
logger("uninstalled theme frio");
|
logger("uninstalled theme frio");
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @brief Replace friendica photo links
|
||||||
|
*
|
||||||
|
* This function does replace the links to photos
|
||||||
|
* of other friendica users. Original the photos are
|
||||||
|
* linked to the photo page. Now they will linked directly
|
||||||
|
* to the photo file. This function is nessesary to use colorbox
|
||||||
|
* in the network stream
|
||||||
|
*
|
||||||
|
* @param App $a
|
||||||
|
* @param array $body_info The item and its html output
|
||||||
|
*/
|
||||||
|
function frio_item_photo_links(&$a, &$body_info) {
|
||||||
|
require_once('include/Photo.php');
|
||||||
|
|
||||||
|
$phototypes = Photo::supportedTypes();
|
||||||
|
$occurence = 1;
|
||||||
|
$p = bb_find_open_close($body_info['html'], "<a", ">");
|
||||||
|
|
||||||
|
while($p !== false && ($occurence++ < 500)) {
|
||||||
|
$link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
|
||||||
|
$matches = array();
|
||||||
|
|
||||||
|
preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches);
|
||||||
|
if($matches) {
|
||||||
|
// Replace the link for the photo's page with a direct link to the photo itself
|
||||||
|
$newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
|
||||||
|
|
||||||
|
// Add a "quiet" parameter to any redir links to prevent the "XX welcomes YY" info boxes
|
||||||
|
$newlink = preg_replace("/href=\"([^\"]+)\/redir\/([^\"]+)&url=([^\"]+)\"/", 'href="$1/redir/$2&quiet=1&url=$3"', $newlink);
|
||||||
|
|
||||||
|
// Having any arguments to the link for Colorbox causes it to fetch base64 code instead of the image
|
||||||
|
$newlink = preg_replace("/\/[?&]zrl=([^&\"]+)/", '', $newlink);
|
||||||
|
|
||||||
|
$body_info['html'] = str_replace($link, $newlink, $body_info['html']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$p = bb_find_open_close($body_info['html'], "<a", ">", $occurence);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue