function _mythumb_story($m) { global $wpdb, $mythumb; ob_start(); $pid = intval($GLOBALS["post"]->ID); $r = mythumb_query($sql = "select * from {$wpdb->posts} where post_parent = ? and post_mime_type like 'image/%' order by menu_order", array($pid)); if (!count($r)) { return; } $size = $mythumb["story.size"]; foreach ($r as $e) { if (!($name = mythumb_build($e["guid"], $size))) { continue; } $title = htmlentities("{$e["post_title"]}"); echo "<h3>{$title}</h3>"; $link = $e["guid"]; $fname = "{$mythumb["datadir"]}/{$name}"; list($w, $h) = getimagesize($fname); $thumb = htmlentities("{$mythumb["dataurl"]}/{$name}"); echo "<a href=\"{$link}\"><img src=\"{$thumb}\" height=\"{$h}\" width=\"{$w}\" alt=\"{$title}\" title=\"{$title}\"></a>"; echo "<p>" . str_replace("\n", "<br/>", htmlentities($e["post_content"])) . "</p>"; } $r = ob_get_contents(); ob_end_clean(); return $r; }
function _mythumb_lightbox_callback($m) { global $mythumb; $src = $m[3]; $name = mythumb_build($src, "800x400"); if ($name) { $src = "{$mythumb["dataurl"]}/{$name}"; } $v = "{$m[1]}{$src}{$m[6]}"; return substr($v, 0, -1) . " rel=\"lightbox[mythumb]\">"; }
function mythumb_nav() { global $mythumb; global $wpdb; $sql = str_replace("SQL_CALC_FOUND_ROWS", "", $GLOBALS["wp_query"]->request); $sql = preg_replace("/limit.*\$/i", "", $sql); // echo $sql; $r = mythumb_query("select t2.guid src,t2.post_title title,t1.ID as pid, t2.post_parent post_id,t1.guid,t1.post_title from {$wpdb->posts} t2, ({$sql}) t1 where t2.post_parent = t1.ID and t2.post_type = 'attachment' and t2.post_mime_type like 'image/%'"); if (!count($r)) { return; } shuffle($r); global $mythumb; echo "<table>"; $cols = $mythumb["nav.cols"]; $n = 0; $size = $mythumb["nav.size"]; $posts = array(); foreach ($r as $e) { if (in_array($e["pid"], $posts)) { continue; } $posts[] = $e["pid"]; echo $n++ % $cols == 0 ? "<tr>" : ""; echo "<td align=center width={$mythumb["width"]} height={$mythumb["height"]}>"; // $link = htmlentities($e["src"]); $link = $e["guid"]; if (!($name = mythumb_build($e["src"], $size, "png"))) { continue; } $fname = "{$mythumb["datadir"]}/{$name}"; list($w, $h) = getimagesize($fname); $thumb = htmlentities("{$mythumb["dataurl"]}/{$name}"); $title = htmlentities("{$e["post_title"]} - {$e["title"]}"); echo "<a href=\"{$link}\"><img src=\"{$thumb}\" height={$h} width={$w} alt=\"{$title}\" title=\"{$title}\"></a>"; } echo "</table>"; }
function mythumb_sort() { global $mythumb, $wpdb; $pid = $GLOBALS["post_id"]; echo '<div> </div>'; if (isset($_REQUEST["order"])) { $n = 1; foreach (explode("&", $_REQUEST["order"]) as $part) { list($k, $id) = explode("=", $part); mythumb_query($sql = "update {$wpdb->posts} set menu_order = ? where ID = ? and post_parent = ?", array($n, $id, $pid)); // echo "$sql<br>"; $n += 1; } echo "<p>Order Saved!</p>"; } mythumb_query("update {$wpdb->posts} set menu_order = 1000 where menu_order = 0 and post_parent = ?", array($pid)); $r = mythumb_query("select * from {$wpdb->posts} where post_parent = ? order by menu_order", array($pid)); wp_enqueue_script('scriptaculous-dragdrop'); wp_print_scripts(); echo "<form method=post>"; echo "<ul id='mylist'>"; foreach ($r as $e) { $name = mythumb_build($e["guid"], "32x32"); $thumb = "{$mythumb["dataurl"]}/{$name}"; $title = htmlentities(strlen($e["post_title"]) ? $e["post_title"] : basename($e["guid"])); echo "<li id='mylist_{$e["ID"]}'><img src='{$thumb}' align=absmiddle> {$title}"; } echo "</ul>"; echo "<input type='hidden' size='60' name='order' id='order'>"; echo '<script type="text/javascript"> function cb (e) { document.getElementById("order").value=Sortable.serialize("mylist",{name:"x"}); } Sortable.create("mylist",{onChange:cb}); cb(0); </script>'; echo "<input type='submit' value='Save'>"; echo "</form>"; }