]> git.mxchange.org Git - friendica.git/commitdiff
ajaxify the wall poster
authorMike Macgirvin <mike@macgirvin.com>
Fri, 23 Jul 2010 05:41:45 +0000 (22:41 -0700)
committerMike Macgirvin <mike@macgirvin.com>
Fri, 23 Jul 2010 05:41:45 +0000 (22:41 -0700)
images/pen.png [new file with mode: 0644]
images/penhover.png [new file with mode: 0644]
mod/parse_url.php [new file with mode: 0644]
mod/wall_upload.php
view/jot-header.tpl
view/jot.tpl
view/style.css
view/wall_item.tpl

diff --git a/images/pen.png b/images/pen.png
new file mode 100644 (file)
index 0000000..46b4049
Binary files /dev/null and b/images/pen.png differ
diff --git a/images/penhover.png b/images/penhover.png
new file mode 100644 (file)
index 0000000..be48d77
Binary files /dev/null and b/images/penhover.png differ
diff --git a/mod/parse_url.php b/mod/parse_url.php
new file mode 100644 (file)
index 0000000..33381a0
--- /dev/null
@@ -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();
+}
\ No newline at end of file
index 769e5dcbcaa51e37b7e87cf61bbef449e3f3bb7a..d74eae3023aeec02e7cc22ffeb60cd88c8d1b52c 100644 (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'];
+       $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();
 
 }
\ No newline at end of file
index 97e30cdae79f2d3fc5e18e4bc4252fc4728c8342..3f8fe5302f59c331604148d4d454bec1dacd0eb4 100644 (file)
@@ -27,16 +27,28 @@ tinyMCE.init({
                var uploader = new window.AjaxUpload(
                        'wall-image-upload',
                        { action: 'wall_upload',
-                       name: 'userfile',
-                       onComplete: function(file,response) {
-                               tinyMCE.execCommand('mceInsertRawHTML',false,response);
-                       }                                
+                               name: 'userfile',
+                               onSubmit: function(file,ext) { $('#profile-rotator').show(); },
+                               onComplete: function(file,response) {
+                                       tinyMCE.execCommand('mceInsertRawHTML',false,response);
+                                       $('#profile-rotator').hide();
+                               }                                
                        }
                );
 
        });
 
 
+       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>
 
 <!--
index 695ac19e0ea8dc60e793a3ca4b6d40db278d1888..24b6babcb9a64354480aa5877eccd0a84cfed90c 100644 (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>
index faf1a091cbe87ad96e76b7d8194b60f50c1dc7a2..2fd5db1fb19f8faff6f78e7340062a58753b9407 100644 (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 {
index 3babc8ead376f57e72ebe56f9a516a7e74794c05..56e182761d09fae01f1b95ce09358bf6cb55bd79 100644 (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