ajaxify the wall poster

This commit is contained in:
Mike Macgirvin 2010-07-22 22:41:45 -07:00
parent 88bfe21bea
commit 36b66dccb6
8 changed files with 148 additions and 12 deletions

BIN
images/pen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

BIN
images/penhover.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

32
mod/parse_url.php Normal file
View File

@ -0,0 +1,32 @@
<?php
require_once('library/HTML5/Parser.php');
function parse_url_content(&$a) {
$url = trim($_GET['url']);
$template = "<a href=\"%s\" >%s</a>";
if($url)
$s = fetch_url($url);
if(! $s) {
echo sprintf($template,$url,$url);
killme();
}
$dom = HTML5_Parser::parse($s);
if(! $dom)
return $ret;
$items = $dom->getElementsByTagName('title');
foreach($items as $item) {
$title = $item->textContent;
break;
}
echo sprintf($template,$url,$title);
killme();
}

View File

@ -1,16 +1,98 @@
<?php
require_once('Photo.php');
function wall_upload_post(&$a) {
if(! local_user()) {
notice ( "Permission denied." . EOL );
return;
}
$src = $_FILES['userfile']['tmp_name'];
$filename = basename($_FILES['userfile']['name']);
$filesize = intval($_FILES['userfile']['size']);
$imagedata = @file_get_contents($src);
$ph = new Photo($imagedata);
unlink($src);
if(! ($image = $ph->getImage())) {
notice("Unable to process image." . EOL);
@unlink($src);
return;
}
@unlink($src);
echo "<img src=\"".$a->get_baseurl(). "/images/default-profile.jpg\" alt=\"default\" />";
$width = $ph->getWidth();
$height = $ph->getHeight();
$hash = hash('md5',uniqid(mt_rand(),true));
$str_image = $ph->imageString();
$smallest = 0;
$r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
`height`, `width`, `data`, `scale` )
VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 0 )",
intval($_SESSION['uid']),
dbesc($hash),
datetime_convert(),
datetime_convert(),
dbesc(basename($filename)),
intval($height),
intval($width),
dbesc($str_image));
if($r)
notice("Image uploaded successfully." . EOL);
else
notice("Image upload failed." . EOL);
if($width > 640 || $height > 640) {
$ph->scaleImage(640);
$r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
`height`, `width`, `data`, `scale` )
VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 1 )",
intval($_SESSION['uid']),
dbesc($hash),
datetime_convert(),
datetime_convert(),
dbesc(basename($filename)),
intval($ph->getHeight()),
intval($ph->getWidth()),
dbesc($ph->imageString())
);
if($r === false)
notice("Image size reduction (640) failed." . EOL );
else
$smallest = 1;
}
if($width > 320 || $height > 320) {
$ph->scaleImage(320);
$r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
`height`, `width`, `data`, `scale` )
VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 2 )",
intval($_SESSION['uid']),
dbesc($hash),
datetime_convert(),
datetime_convert(),
dbesc(basename($filename)),
intval($ph->getHeight()),
intval($ph->getWidth()),
dbesc($ph->imageString())
);
if($r === false)
notice("Image size reduction (320) failed." . EOL );
else
$smallest = 2;
}
$basename = basename($filename);
echo "<img src=\"".$a->get_baseurl(). "/photo/{$hash}-{$smallest}.jpg\" alt=\"$basename\" />";
killme();
}

View File

@ -28,8 +28,10 @@ tinyMCE.init({
'wall-image-upload',
{ action: 'wall_upload',
name: 'userfile',
onSubmit: function(file,ext) { $('#profile-rotator').show(); },
onComplete: function(file,response) {
tinyMCE.execCommand('mceInsertRawHTML',false,response);
$('#profile-rotator').hide();
}
}
);
@ -37,6 +39,16 @@ tinyMCE.init({
});
function jotGetLink() {
reply = prompt("Please enter a link URL:");
$('#profile-rotator').show();
$.get('parse_url?url=' + reply, function(data) {
tinyMCE.execCommand('mceInsertRawHTML',false,data);
$('#profile-rotator').hide();
});
}
</script>
<!--

View File

@ -17,9 +17,11 @@ What's on your mind?
<div id="wall-image-upload-div" ><img id="wall-image-upload" src="images/camera-icon.gif" alt="Upload Photo" title="Upload Photo" /></div>
</div>
<div id="profile-link-wrapper" style="display: $visitor;" >
<img id="profile-link" src="images/link-icon.gif" alt="Insert web link" title="Insert web link" />
<img id="profile-link" src="images/link-icon.gif" alt="Insert web link" title="Insert web link" onclick="jotGetLink();" />
</div>
<div id="profile-rotator-wrapper" style="display: $visitor;" >
<img id="profile-rotator" src="images/rotator.gif" alt="Please wait" title="Please wait" style="display: none;" />
</div>
<div id="profile-jot-perms" class="profile-jot-perms" style="display: $visitor;" ><img src="images/$lockstate_icon.gif" alt="Permission Settings" title="Permission Settings" onClick="openClose('profile-jot-acl-wrapper');" /></div>
<div id="profile-jot-perms-end"></div>
<div id="profile-jot-acl-wrapper" style="display: none;" >$acl</div>

View File

@ -493,6 +493,11 @@ input#dfrn-url {
.wall-item-photo {
border: none;
}
.wall-item-body {
float: left;
margin-top: 30px;
margin-left: 10px;
}
.comment-edit-wrapper {
margin-top: 15px;
@ -517,6 +522,10 @@ input#dfrn-url {
margin-left: 50px;
}
#profile-rotator {
float: left;
margin-left: 50px;
}
#profile-link-wrapper {
float: left;
margin-left: 20px;
@ -524,7 +533,7 @@ input#dfrn-url {
#profile-jot-perms {
float: left;
margin-left: 280px;
margin-left: 250px;
}
#profile-jot-perms-end {

View File

@ -5,10 +5,9 @@
</div>
<div class="wall-item-wrapper" id="wall-item-wrapper-$id" >
<a href="$profile_url" title="View $name's profile" class="wall-item-name-link"><span class="wall-item-name" id="wall-item-name-$id" >$name</span></a>
<span class="wall-item-body" id="wall-item-body-$id" >$body</span>
<div class="wall-item-ago" id="wall-item-ago-$id">$ago</div>
</div>
<span class="wall-item-body" id="wall-item-body-$id" >$body</span>
<div class="wall-item-wrapper-end"></div>
<div class="wall-item-comment-separator"></div>
$comment