493, 'dispmaxheight' => 370, 'css' => 'inject', 'cssblock' => $CSS ); function blogphoto_activate() { // the 'write_page_' prefix below is based on the parent file (set below to post.php) // and prepended to the plugin filename to arrive at the hook for the admin page. // The admin page can be displayed from 'admin.php?page=xxx' where xxx is the plugin // filename $pagehook = 'write_page_' . basename(__FILE__, '.php'); add_action($pagehook, 'blogphoto_admin_page'); add_action('admin_menu', 'blogphoto_admin_menu'); add_action('wp_head', 'blogphoto_include_js'); if (blogphoto_getoption('css') == 'inject') { add_action('wp_head', 'blogphoto_include_css'); } wfplugin_set_parent_file('post.php'); } function blogphoto_include_js($ret) { $url = get_settings('siteurl') . '/wp-content/plugins/' . basename(__FILE__) . '?mode=clientscript&x=.js'; ?> "gif", 2 => "jpeg", 3 => "png" ); // Get image information and do a quick check to make sure the // image type is supported $file = $_FILES['imagefile']; $extension = strtolower(array_pop($extension = explode('.', $file['name']))); if ($extension = 'jpg') $extension = 'jpeg'; if ( !in_array($extension, $extlist) ) { die("Sorry, $extension extensions are not supported"); } else if ( !function_exists('image' . $extension) ) { die("Sorry, $extension support could not be found"); } // check for upload errors (such as exceeding max size) $fileattr = wp_handle_upload($file); if (!empty($fileattr['error'])) { die($fileattr['error']); } // move the file to the new location // first to the fullquality folder (created if necessary) // then we will downsample from that folder to the regular folder $dispimgpath = $fileattr['file']; $filename = basename($dispimgpath); $uploaddir = dirname($dispimgpath); $fullqualdir = trailingslashit($uploaddir) . 'fullquality'; if (!file_exists($fullqualdir)) { mkdir($fullqualdir); } // move the original file to the 'fullquality' directory $file = trailingslashit($fullqualdir) . $filename; rename($dispimgpath, $file); // Get image size and type information $image_attr = getimagesize($file); // read options $dispmaxwidth = blogphoto_getoption('dispmaxwidth'); $dispmaxheight = blogphoto_getoption('dispmaxheight'); $maxratio = (double)$dispmaxwidth / (double)$dispmaxheight; $imgratio = (double)$image_attr[0] / (double)$image_attr[1]; $ratio = 1; if ($imgratio >= $maxratio) { $ratio = (double)$dispmaxwidth / (double)$image_attr[0]; } else { $ratio = (double)$dispmaxheight / (double)$image_attr[1]; } // if the resulting image is smaller, then downsample // else leave it. $newwidth = $image_attr[0]; $newheight = $image_attr[1]; if ($ratio < 1) { // calculate new dimensions $newwidth = floor($image_attr[0] * $ratio); $newheight = floor($image_attr[1] * $ratio); //printf("Width: %d => %d, Height: %d => %d\n", $image_attr[0], $newwidth, $image_attr[1], $newheight); // create the in-memory copy from the original file if ($image_attr[2] == 1) { $image = imagecreatefromgif($file); } elseif ($image_attr[2] == 2) { $image = imagecreatefromjpeg($file); } elseif ($image_attr[2] == 3) { $image = imagecreatefrompng($file); } if (function_exists('imageantialias')) imageantialias($image, TRUE); // initialize new image $dispimg = imagecreatetruecolor($newwidth, $newheight); // downsample @ imagecopyresampled($dispimg, $image, 0, 0, 0, 0, $newwidth, $newheight, $image_attr[0], $image_attr[1]); // save the display image to it's final destination $format = $extlist[$image_attr[2]]; if (!call_user_func('image' . $format, $dispimg, $dispimgpath)) { die('Error saving ' . $format . ' format'); } } else { // go ahead and just move the image from the full quality folder to display folder rename($file, $dispimgpath); } // create the new post $post = array( 'post_status' => 'draft', 'to_ping' => '', 'post_author' => (int)$user_ID, 'post_title' => $_POST['post_title'] ); $imgdata = array( 'origsize' => sprintf("%d x %d", $image_attr[0], $image_attr[1]), 'guid' => $fileattr['url'] ); if ($format == 'jpeg' && function_exists('exif_read_data')) { $exif = exif_read_data($file, 'EXIF', true); if (isset($exif['EXIF']['DateTimeOriginal']) && ($exif['EXIF']['DateTimeOriginal'] != '')) { $imgdata['date'] = $exif['EXIF']['DateTimeOriginal']; } } if ($ratio < 1) { $imgdata['origurl'] = wf_urldirname($fileattr['url']) . '/fullquality/' . basename($fileattr['file']); $imgdata['downloadurl'] = get_settings('siteurl') . '/wp-content/plugins/' . basename(__FILE__) . '?mode=downloadimg&type=' . urlencode($format) . '&guid=' . urlencode($imgdata['guid']) . '&x=.' . $format; } $jscode = "return blogphoto_toggleImgMenu(this, " . htmlspecialchars(wf_json($imgdata, "'")) . ");"; $post['post_content'] = addslashes(sprintf('
', $jscode, $fileattr['url'], $newwidth, $newheight)); $post['post_content'] .= $_POST['post_text']; $post['post_excerpt'] = ''; // store the draft post $newpostid = wp_insert_post($post); // store the image attachment // create the new post $imgpost = array( 'post_status' => 'attachment', 'to_ping' => '', 'post_author' => (int)$user_ID, 'post_title' => $_POST['post_title'] . ' - Image', 'post_mime_type' => 'image/' . $format, 'guid' => $imgdata['guid'] ); $imgpostid = wp_insert_attachment($imgpost, $dispimgpath, $newpostid); $thumb = wp_create_thumbnail($dispimgpath, 128); $imgmeta = array( 'width' => $newwidth, 'height' => $newheight, 'hwstring_small' => "height='$uheight' width='$uwidth'", 'file' => $dispimgpath, 'thumb' => basename($thumb), 'full' => trailingslashit('fullquality') . basename($dispimgpath) ); add_post_meta($imgpostid, '_wp_attachment_metadata', $imgmeta, true); header('Location: ' . get_settings('siteurl') . '/wp-admin/post.php?action=edit&post=' . $newpostid); } function wf_json($a, $q = "'") { $isassoc = false; switch (gettype($a)) { case 'array': foreach(array_keys($a) as $key) { if (gettype($key) != 'integer') { $isassoc = true; break; } } $rval = ''; if ($isassoc) { foreach($a as $key => $val) { $rval .= (($rval != '') ? (',') : ('')) . $q . str_replace($q, "\\" . $q, $key) . $q . ':' . wf_json($val, $q); } $rval = '{' . $rval . '}'; } else { foreach($a as $val) { $rval .= (($rval != '') ? (',') : ('')) . wf_json($val, $q); } $rval = '[' . $rval . ']'; } return $rval; case 'string': return $q . str_replace($q, "\\" . $q, $a) . $q; default: return "" . $a; } } function wf_print_options($sel, $opts) { foreach($opts as $val => $txt) { printf("%s\n", ($sel == $val ? ' selected="true"' : ''), htmlspecialchars($val), htmlspecialchars($txt)); } } function wf_urldirname($url) { $a = parse_url($url); if (!empty($a['pass'])) $a['pass'] = ':' . $a['pass']; if (!empty($a['user'])) $a['user'] = $a['user'] . $a['pass'] . '@'; return $a['scheme'] . '://' . $a['user'] . $a['host'] . dirname($a['path']); } function blogphoto_admin_menu_debug() { global $submenu; echo ""; } if (!function_exists('wfplugin_set_parent_file')) { function wfplugin_set_parent_file($pf) { // hack to set $parent_file at appropriate time // because it isn't clear if there's a correct way to do this global $parent_file; if (basename($_SERVER['PHP_SELF']) == 'admin.php') $parent_file = 'post.php'; } } function wf_dumpvar($lvl, $key, $val) { if (gettype($val) == 'array') { echo str_repeat(' ', $lvl * 2) . $key . " = {\n"; foreach ($val as $newkey => $newval) { wf_dumpvar($lvl + 1, $newkey, $newval); } echo str_repeat(' ', $lvl * 2) . " }\n"; } else { echo str_repeat(' ', $lvl * 2) . $key . " = \"" . $val . "\"\n"; } } function wf_tobytes($val) { $val = trim($val); $last = strtolower($val{strlen($val)-1}); switch($last) { // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } return $val; } function blogphoto_getoption($name) { global $blogphoto_defval; $val = get_option('blogphoto_' . $name); if (false === $val) { $val = $blogphoto_defval[$name]; } return $val; } function blogphoto_print_options() { ?>

Photo Blogger Options

PhotoBlogger plugin by: Warren Falk
Photo Blogger
Display Image Max Width:
Display Image Max Height:
Img Info Box Style:
Custom CSS:

You can also e-mail the admin to ask for a promotion.
When you’re promoted, just reload this page and you’ll be able to blog. :)'), get_settings('admin_email')); ?>

Photo Blogger

PhotoBlogger plugin by: Warren Falk
Upload

You will be able to change this title and post text after uploading the image


function el(s) { return document.createElement(s); } function addel(p,s) { return p.appendChild(document.createElement(s)); } function addtxt(p,s) { if (!p) { return; } return p.appendChild(document.createTextNode(s)); } var infomap = { 'origsize': 'Full Size', 'origurl': null, 'downloadurl': null, 'date': 'Date Taken' }; function blogphoto_toggleImgMenu(d, info) { if (d.showingMenu) { d.infoDiv.style.display = "none"; d.showingMenu = false; } else { d.showingMenu = true; d.style.position = "relative"; d.style.pixelTop = d.style.pixelTop = 0; if (!d.infoDiv) { d.infoDiv = el("div"); d.infoDiv.className = "imginfo"; var s = d.infoDiv.style; s.left = "5px"; s.top = "5px"; s.position = "absolute"; var t = addel(d.infoDiv, 'table'); t = addel(t, 'tbody'); t.valcells = new Object(); for (var k in info) { if (infomap[k]) { var tr = addel(t, 'tr'); var tdn = addel(tr, 'th'); tdn.className = 'name ' + k; var tx = addtxt(addel(tdn, 'p'), infomap[k] + ': '); var tdv = addel(tr, 'td'); tdv.className = 'value ' + k; t.valcells[k] = addel(tdv, 'p'); } } addtxt(t.valcells['origsize'], ' (' + info['origsize'] + ') ['); var adnld = addel(t.valcells['origsize'], 'a'); addtxt(t.valcells['origsize'], '|'); var aview = addel(t.valcells['origsize'], 'a'); addtxt(t.valcells['origsize'], ']'); aview.target = "_blank"; adnld.href = info['downloadurl']; aview.href = info['origurl']; addtxt(adnld, 'download'); addtxt(aview, 'view') addtxt(t.valcells['date'], info['date']); d.appendChild(d.infoDiv); } d.infoDiv.style.display = "block"; } } get_var("SELECT `ID` FROM $wpdb->posts WHERE guid = '$guid'"); $postmeta = get_post_meta($imgid, '_wp_attachment_metadata', true); $filepath = trailingslashit(dirname($postmeta['file'])) . $postmeta['full']; header('Content-disposition: attachment; filename=' .str_replace(" ", "_", basename($filepath))); //df: changed to use the actual name of the file. readfile($filepath, false); break; default: if (basename(__FILE__) == basename($_SERVER['SCRIPT_NAME'])) { // if this page was called directly, just redirect to photo uploader header('Location: ../../wp-admin/admin.php?page=' . basename(__FILE__) . '.php'); } else { blogphoto_activate(); } break; } ?>