commit f87492d73e2b73f71285b36ee0c953ea9e826bcc Author: root Date: Sun Mar 21 14:50:44 2010 -0400 Intial revision. diff --git a/README b/README new file mode 100644 index 0000000..e0ae14c --- /dev/null +++ b/README @@ -0,0 +1,34 @@ + ___ __ _ __ ___ __ ___ __ + / | ____/ /___ ___ (_)___ / |/ /_ _______/ /_/__ \/ / + / /| |/ __ / __ `__ \/ / __ \ / /|_/ / / / / ___/ __ \/ _/ / + / ___ / /_/ / / / / / / / / / / / / / / /_/ / /__/ / / /_//_/ + /_/ |_\__,_/_/ /_/ /_/_/_/ /_/ /_/ /_/\__,_/\___/_/ /_(_)(_) + ================================================================== + +About +----- + +Admin Much?! is a bad ass PHP back-end system for quickly and easily +administering submission-based photo sites running a WordPress front-end. + +Intentions +---------- + +Hone the system and release it to the masses. + +Requirements +------------ + + * WordPress - http://www.wordpress.com + + * PICKLES - http://www.phpwithpickles.org + +Who's using it? +--------------- + +Sites currently using Admin Much?! include: + + * ParkMuch.com: + Photos of Bad Parking Jobs and other Automotive Shortcomings + + * COMING SOON - LitterMuch.com diff --git a/TODO b/TODO new file mode 100644 index 0000000..3562172 --- /dev/null +++ b/TODO @@ -0,0 +1,9 @@ + * Port system to run on the LATEST version of PICKLES. + + * Move all hardcoded / site specific values to the config file. + + * Add better spam detection to the check email script. + + * Build set up scripts possibly automatically downloading WordPress. + + * Add Geocoding support. diff --git a/config.xml b/config.xml new file mode 100644 index 0000000..a839d05 --- /dev/null +++ b/config.xml @@ -0,0 +1,19 @@ + + + localhost + ********** + ********** + parkmuch + + + Smarty + + +
index.tpl
+
+ + ********** + ******************************** + ********** + +
diff --git a/incoming/README b/incoming/README new file mode 100644 index 0000000..afe756a --- /dev/null +++ b/incoming/README @@ -0,0 +1 @@ +This is where images that are picked up by the check email script are stored before being promoted. diff --git a/modules/admin.php b/modules/admin.php new file mode 100644 index 0000000..f33175c --- /dev/null +++ b/modules/admin.php @@ -0,0 +1,12 @@ +setPublic('messages', $this->db->getArray('SELECT * FROM incoming ORDER BY received_at')); + } +} + +?> diff --git a/modules/expunge.php b/modules/expunge.php new file mode 100644 index 0000000..0a38f26 --- /dev/null +++ b/modules/expunge.php @@ -0,0 +1,26 @@ +db->execute('DELETE FROM incoming WHERE id = "' . $_REQUEST['id'] . '";'); + + $path = getcwd() . '/../incoming/' . $_REQUEST['id'] . '/'; + $files = scandir($path); + + foreach ($files as $file) + { + if ($file != '.' && $file != '..') + { + unlink($path . $file); + } + } + + rmdir($path); + + header('Location: /admin'); + } +} + +?> diff --git a/modules/file.php b/modules/file.php new file mode 100644 index 0000000..24fac1f --- /dev/null +++ b/modules/file.php @@ -0,0 +1,18 @@ + diff --git a/modules/home.php b/modules/home.php new file mode 100644 index 0000000..b20000e --- /dev/null +++ b/modules/home.php @@ -0,0 +1,11 @@ + diff --git a/modules/message.php b/modules/message.php new file mode 100644 index 0000000..0afc28d --- /dev/null +++ b/modules/message.php @@ -0,0 +1,28 @@ +db->getRow('SELECT * FROM incoming WHERE id = "' . $_REQUEST['id'] . '";'); + $path = getcwd() . '/../incoming/' . $_REQUEST['id'] . '/'; + $files = scandir($path); + + foreach ($files as $file) + { + if ($file != '.' && $file != '..') + { + $filename = $path . $file; + } + } + + $size = @getimagesize($filename); + + $message['attachment'] = $files[2]; + $message['details'] = $size; + + $this->setPublic('message', $message); + } +} + +?> diff --git a/modules/post.php b/modules/post.php new file mode 100644 index 0000000..ee9b3f4 --- /dev/null +++ b/modules/post.php @@ -0,0 +1,11 @@ + diff --git a/modules/promote.php b/modules/promote.php new file mode 100644 index 0000000..530eed4 --- /dev/null +++ b/modules/promote.php @@ -0,0 +1,61 @@ + '1', + 'post_date' => date('Y-m-d H:i:s'), + 'post_date_gmt' => gmdate('Y-m-d H:i:s'), + 'post_title' => $_REQUEST['title'], + 'post_status' => 'draft', + 'post_name' => str_replace(' ' , '-', strtolower($_REQUEST['title'])), + 'post_modified' => date('Y-m-d H:i:s'), + 'post_modified_gmt' => gmdate('Y-m-d H:i:s') + ); + + $id = $this->db->insert('wp_posts', $data); + + // Finds the image and extract the extension + $path = getcwd() . '/../incoming/' . $_REQUEST['id'] . '/'; + $files = scandir($path); + + foreach ($files as $file) + { + if ($file != '.' && $file != '..') + { + $filename = $path . $file; + $parts = explode('.', $file); + end($parts); + $extension = current($parts); + } + } + + // Creates the directory for the image and moves the original + $public_path = '/submissions/' . date('Y/m/') . $id . '/'; + $new_path = getcwd() . $public_path; + $original = $new_path . 'original' . $extension; + mkdir($new_path, 0777, true); + copy($filename, $original); + + // Scales the image down to 500px wide + $thumb = new Imagick($original); + $thumb->thumbnailImage(500, 500, true); + $thumb->writeImage($new_path . 'scaled_500.' . $extension); + + // Updates the post content and marks it as published + $data = array( + 'post_content' => '

' . $_REQUEST['content'], + 'post_status' => 'publish', + 'guid' => 'http://parkmuch.com/?p=' . $id + ); + $this->db->update('wp_posts', $data, array('ID' => $id)); + + // Expunges the data + parent::__default(); + } +} + +?> diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 0000000..413976b --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,43 @@ +# Sets up ETags +FileETag MTime Size + +# Sets up the mod_rewrite engine +RewriteEngine on + +#RewriteCond %{REQUEST_FILENAME}/$ -f [NC,OR] +#RewriteCond %{REQUEST_FILENAME}/$ -d [NC] +#RewriteRule .* - [L] + +# Sets the base path (document root) +RewriteBase / + +# Strips the trailing slash +RewriteRule ^(.+)/$ $1 [R] + +#RewriteCond %{HTTP_HOST} ^(admin).thatgirljen.com$ [NC] +#RewriteRule ^(.*)$ http://thatgirljen.com/admin [R=301,L] + +# Strips the preceeding subdomain +#RewriteCond %{HTTP_HOST} ^(.+).thatgirljen.com$ [NC] +#RewriteRule ^(.*)$ http://thatgirljen.com/$1 [R=301,L] + +# Rewrite Rules for the PICKLES Quaternity +RewriteRule ^(template/edit)/([a-z-/]+)$ index.php?module=$1&template=$2 [NC,QSA] +RewriteRule ^(weblog)/([0-9]+)$ index.php?module=$1&page=$2 [NC,QSA] +RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f +RewriteRule ^([a-z-/]+)/([0-9/]{10})/([a-z-]+)$ index.php?module=$1&date=$2&title=$3 [NC,QSA] +RewriteRule ^([a-z-/]+)/([0-9]+)$ index.php?module=$1&id=$2 [NC,QSA] +RewriteRule ^([a-z-/]+)$ index.php?module=$1 [NC,QSA] + +# Set up the error documents +ErrorDocument 400 / +ErrorDocument 401 / +ErrorDocument 403 / +ErrorDocument 404 / +ErrorDocument 500 / + +# Blocks access to .htaccess + + order allow,deny + deny from all + diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..574e615 --- /dev/null +++ b/public/index.php @@ -0,0 +1,6 @@ + diff --git a/public/submissions/README b/public/submissions/README new file mode 100644 index 0000000..a414de4 --- /dev/null +++ b/public/submissions/README @@ -0,0 +1 @@ +This is where images that are promoted from the upcoming directory are stored. diff --git a/scripts/check_mail.php b/scripts/check_mail.php new file mode 100644 index 0000000..4fdf9bb --- /dev/null +++ b/scripts/check_mail.php @@ -0,0 +1,227 @@ +date)); + $from = $header->fromaddress; + $subject = $header->subject; + + // Gets the message structure + $structure = imap_fetchstructure($mailbox, $i); + + // Pulls the plain text and HTML message body + $message = get_part($mailbox, $i, 'TEXT/PLAIN', $structure); + + // Pulls the attachment if any + $attachments = array(); + if (isset($structure->parts) && count($structure->parts)) + { + $part_count = count($structure->parts); + + for ($j = 0; $j < $part_count; $j++) + { + if ($structure->parts[$j]->ifdparameters) + { + foreach ($structure->parts[$j]->dparameters as $object) + { + if (strtolower($object->attribute) == 'filename') + { + $attachments[$j]['is_attachment'] = true; + $attachments[$j]['filename'] = $object->value; + } + } + } + + if ($structure->parts[$j]->ifparameters) + { + foreach ($structure->parts[$j]->parameters as $object) + { + if (strtolower($object->attribute) == 'name') + { + $attachments[$j]['is_attachment'] = true; + $attachments[$j]['name'] = $object->value; + } + } + } + + if ($attachments[$j]['is_attachment']) + { + $attachments[$j]['attachment'] = imap_fetchbody($mailbox, $i, $j + 1); + + // 3 = BASE64 + if ($structure->parts[$j]->encoding == 3) + { + $attachments[$j]['attachment'] = base64_decode($attachments[$j]['attachment']); + } + // 4 = QUOTED-PRINTABLE + elseif ($structure->parts[$j]->encoding == 4) + { + $attachments[$j]['attachment'] = quoted_printable_decode($attachments[$j]['attachment']); + } + } + } + } + + echo 'Time: ' . $time . "\n"; + echo 'From: ' . $from . "\n"; + echo 'Subject: ' . $subject; + echo $thin_line . 'Message: ' . $thin_line . "\n" . $message; + + if (count($attachments) > 0) + { + $displayed = false; + foreach ($attachments as $attachment) + { + if ($displayed == false) + { + echo $thin_line . 'Attachments:'; + + $displayed = true; + } + + $data = array( + 'sender' => $from, + 'subject' => $subject, + 'message' => $message, + 'received_at' => $time + ); + + $id = $db->insert('incoming', $data); + $incoming_path = $path . 'incoming/' . $id . '/'; + + if (!file_exists($incoming_path)) + { + mkdir($incoming_path, 0777, true); + } + + // Places each attachment in the appropriate location + file_put_contents($incoming_path . $attachment['filename'], $attachment['attachment']); + + //chmod($incoming_path, 0777); + chgrp($incoming_path, 'www-data'); + chown($incoming_path, 'www-data'); + + //chmod($incoming_path . $attachment['filename'], 0777); + chgrp($incoming_path . $attachment['filename'], 'www-data'); + chown($incoming_path . $attachment['filename'], 'www-data'); + + echo "\n" . $attachment['name']; + } + + // Marks the message for deletion + imap_delete($mailbox, $i); + + // Sends an alert if one hasn't been sent already + if ($alerted == false) + { + mail('8134952668@tmomail.net', 'NEW PARK MUCH?! SUBMISSION', 'Get on that shit!'); + $alerted = true; + } + } + + echo $thick_line; +} + +// Closes the mail box +imap_expunge($mailbox); +imap_close($mailbox); + +Logger::write('check_mail', 'Check mail job has completed'); + +function get_mime_type($structure) +{ + $primary_mime_type = array('TEXT', 'MULTIPART','MESSAGE', 'APPLICATION', 'AUDIO','IMAGE', 'VIDEO', 'OTHER'); + + if ($structure->subtype) + { + return $primary_mime_type[(int)$structure->type] . '/' . $structure->subtype; + } + + return 'TEXT/PLAIN'; +} + +function get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false) +{ + if (!$structure) + { + $structure = imap_fetchstructure($stream, $msg_number); + } + + if ($structure) + { + if ($mime_type == get_mime_type($structure)) + { + if(!$part_number) + { + $part_number = "1"; + } + + $text = imap_fetchbody($stream, $msg_number, $part_number); + + if ($structure->encoding == 3) + { + return imap_base64($text); + } + elseif ($structure->encoding == 4) + { + return imap_qprint($text); + } + else + { + return $text; + } + } + + // Multi-part + if($structure->type == 1) + { + while (list($index, $sub_structure) = each($structure->parts)) + { + if ($part_number) + { + $prefix = $part_number . '.'; + } + + $data = get_part($stream, $msg_number, $mime_type, $sub_structure, $prefix . ($index + 1)); + + if ($data) + { + return $data; + } + } + } + } + + return false; +} + +?> diff --git a/templates/admin.tpl b/templates/admin.tpl new file mode 100644 index 0000000..bf8a6e1 --- /dev/null +++ b/templates/admin.tpl @@ -0,0 +1,20 @@ +{foreach from=$module.messages item=message name=messages} + {if $smarty.foreach.messages.first} + + + + + + + + {/if} + + + + + + + {if $smarty.foreach.messages.last}
IDFromSubjectReceived At
{$message.id}{$message.sender|htmlentities}{$message.subject}{$message.received_at}
{/if} +{foreachelse} + No incoming submissions at this time +{/foreach} diff --git a/templates/index.tpl b/templates/index.tpl new file mode 100644 index 0000000..c834085 --- /dev/null +++ b/templates/index.tpl @@ -0,0 +1,9 @@ + + + Park Much?! Admin + + +

Park Much?! Admin

+ {include file="$template"} + + diff --git a/templates/message.tpl b/templates/message.tpl new file mode 100644 index 0000000..569d7ec --- /dev/null +++ b/templates/message.tpl @@ -0,0 +1,36 @@ +{literal}{/literal} + + + + + + + + + + + + + + + + + + + + + + + + +
Received At:{$module.message.received_at}
From:{$module.message.sender|htmlentities}
Subject:{$module.message.subject}
Message:{$module.message.message|nl2br}
Attachment: + {$module.message.attachment} + {if $module.message.details !== false} +
+ + {/if} +
+
+ + +
diff --git a/templates/post.tpl b/templates/post.tpl new file mode 100644 index 0000000..dc59651 --- /dev/null +++ b/templates/post.tpl @@ -0,0 +1,35 @@ +{literal}{/literal} +
+ + + + + + + + + + + + + + + + +
Title:
Content: + +
Attachment: + {$module.message.attachment} + {if $module.message.details !== false} +
+ + {/if} +
+
+ + +
+