summaryrefslogtreecommitdiff
path: root/src/controllers
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2011-09-04 21:13:47 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2011-09-04 21:13:47 -0400
commitad4a7ff9159c2c64cea98d7189f46fa7d6174fc2 (patch)
tree508f971f1dbc6c6f01207426c675542b55e0333e /src/controllers
parentf3b3ea69fb46e45bf3598aa7a6bcf62aa80e4703 (diff)
Screw it, I'm tired of trying to break this into individual commits
Diffstat (limited to 'src/controllers')
-rw-r--r--src/controllers/Groups.class.php11
-rw-r--r--src/controllers/Main.class.php9
-rw-r--r--src/controllers/Messages.class.php100
-rw-r--r--src/controllers/NewMessage.class.php37
-rw-r--r--src/controllers/Plugins.class.php19
-rw-r--r--src/controllers/Users.class.php54
6 files changed, 226 insertions, 4 deletions
diff --git a/src/controllers/Groups.class.php b/src/controllers/Groups.class.php
new file mode 100644
index 0000000..9d99d99
--- /dev/null
+++ b/src/controllers/Groups.class.php
@@ -0,0 +1,11 @@
+<?php
+
+Router::register('groups/new' , 'Groups', 'new_group');
+Router::register('groups/index', 'Groups', 'index_file');
+Router::register('groups' , 'Groups', 'index_dir');
+Router::register('groups/*' , 'Groups', 'individual');
+
+class Groups extends Controller {
+ public static $illegal_names = array('', 'new', 'index');
+ // TODO
+}
diff --git a/src/controllers/Main.class.php b/src/controllers/Main.class.php
new file mode 100644
index 0000000..7651b62
--- /dev/null
+++ b/src/controllers/Main.class.php
@@ -0,0 +1,9 @@
+<?php
+
+Router::register('index', 'Main', 'index');
+
+class Main extends Controller {
+ public function index($routed, $remainder) {
+ $this->showView('index');
+ }
+}
diff --git a/src/controllers/Messages.class.php b/src/controllers/Messages.class.php
new file mode 100644
index 0000000..86403ae
--- /dev/null
+++ b/src/controllers/Messages.class.php
@@ -0,0 +1,100 @@
+<?php
+
+Router::register('messages', 'Messages', 'index');
+Router::register('messages/index', 'Messages', 'index');
+Router::register('messages/*', 'Messages', 'message');
+
+class Messages extends Controller {
+ public static $msgdir;
+
+ public function __construct() {
+ require_once('MimeMailParser.class.php');
+ $this->msgdir = BASEPATH.'/msg';
+ }
+
+ public function index($routed, $remainder) {
+ $parser = new MimeMailParser();
+ $messages = array();
+ $dh = opendir($this->msgdir);
+ while (($file = readdir($dh)) !== false) {
+ $path = $this->msgdir."/$file";
+ if (is_file($path)) {
+ $parser->setPath($path);
+
+ $date_string = $parser->getHeader('date');
+ $date = strtotime($date_string);
+ if (!isset($messages[$date])) {
+ $messages[$date] = array();
+ }
+ $messages[$date][] =
+ array('id'=>$file,
+ 'subject'=>$parser->getHeader('subject'),
+ 'from'=>$parser->getHeader('from'));
+ }
+ }
+ closedir($dh);
+
+ $this->showView('messages/index', array('messages' => $messages));
+ exit();
+ }
+
+ public function message($routed, $remainder) {
+ global $mm;
+ $uid = $mm->isLoggedIn();
+ if ($uid===false || !$mm->getAuthObj($uid)->isUser()) {
+ $this->http401($routed, $remainder);
+ return;
+ }
+
+ $msg_id = $remainder[0];// We can trust the router that this is set
+ $msg_file = $this->msgdir."/$msg_id";
+ if (!is_file($msg_file)) {
+ $this->http404($routed, $remainder);
+ return;
+ }
+
+ @$part = $remainder[1];
+ @$subpart = $remainder[2];
+ $parser = new MimeMailParser();
+ $parser->setPath($msg_file);
+
+ switch ($part) {
+ case '':
+ $this->showView('messages/frame',
+ array('msg_id'=>$msg_id,
+ 'parser'=>$parser,
+ 'msgdir'=>$this->msgdir,
+ ));
+ break;
+ case 'body':
+ require_once('Mime.class.php');
+ header('Content-type: '.Mime::ext2mime(PAGE_EXT));
+ $map = array('html'=>'html',
+ 'txt' =>'text');
+ echo $parser->getMessageBody($map[PAGE_EXT]);
+ break;
+ case 'attachment':
+ $attachment_id = $subpart;
+ $attachments = $parser->getAttachments();
+ $attachment = $attachments[$attachment_id];
+
+ $type = $attachment->getContentType();
+ $filename = $attachment->getFilename();
+
+ header('Content-Type: '.$type);
+ header('Content-Disposition: attachment; filename='.$filename );
+ while($bytes = $attachment->read()) {
+ echo $bytes;
+ }
+ break;
+ default:
+ array_push($routed, array_shift($remainder));
+ $this->http404($routed, $remainder);
+ }
+ }
+
+ public function http401($routed, $remainder) {
+ global $mm;
+ $this->showView('messages/401', array('uid'=>$mm->isLoggedIn()));
+ }
+} \ No newline at end of file
diff --git a/src/controllers/NewMessage.class.php b/src/controllers/NewMessage.class.php
new file mode 100644
index 0000000..e778385
--- /dev/null
+++ b/src/controllers/NewMessage.class.php
@@ -0,0 +1,37 @@
+<?php
+ /*
+class NewMessage extends Controller {
+$cmdline = isset($argv[0]); // called from the command line
+@$method = $_SERVER['REQUEST_METHOD']; // What HTTP method was used
+if ( ($method=='PUT') || ($method=='POST') || $cmdline ) {
+ // We're going to be uploading a new message.
+
+ // so uniqid isn't 'secure', it doesn't need to be, it's to prevent
+ // random collisions.
+ $tmpfile = "$BASE/tmp/".uniqid(getmypid().'.');
+ $infile = ($cmdline?'php://stdin':'php://input');
+ $out = fopen($tmpfile, "w");
+ $in = fopen($infile, "r");
+ while ($data = fread($in, 1024))
+ fwrite($out, $data);
+ fclose($out);
+ fclose($in);
+ //apache_request_headers()
+ require_once('MimeMailParser.class.php');
+ $parser = new MimeMailParser();
+ $parser->setPath($tmpfile);
+ $id = preg_replace('/<(.*)>/', '$1',
+ $parser->getHeader('message-id'));
+ $id = str_replace('/', '', $id); // for security reasons
+ $msg_file = "$BASE/msg/$id";
+ rename($tmpfile, $msg_file);
+
+ if (!$cmdline) {
+ $m->status('201 Created');
+ header("Location: ".$m->baseUrl().'messages/'.$id);
+ }
+ exit();
+}
+
+}
+ */ \ No newline at end of file
diff --git a/src/controllers/Plugins.class.php b/src/controllers/Plugins.class.php
new file mode 100644
index 0000000..597cd19
--- /dev/null
+++ b/src/controllers/Plugins.class.php
@@ -0,0 +1,19 @@
+<?php
+
+Router::register('plugins', 'Plugins');
+
+class Plugins extends Controller {
+ public function index($routed, $remainder) {
+ global $mm;
+ $uid = $mm->isLoggedIn();
+ if ($uid===false || !$m->getAuthObj($uid)->isAdim()) {
+ $this->http401($routed, $remainder);
+ return;
+ }
+ // TODO
+ }
+
+ public function http401($routed, $remainder) {
+ $this->showView('plugins/401');
+ }
+}
diff --git a/src/controllers/Users.class.php b/src/controllers/Users.class.php
index 617c57a..9781ab0 100644
--- a/src/controllers/Users.class.php
+++ b/src/controllers/Users.class.php
@@ -84,8 +84,14 @@ class Users extends Controller {
}
break;
}
+
+ $config_options = array();
+ $mm->pluginManager()->callHook('userConfig', &$config_options);
+
+ $vars['config_options'] = $config_options;
$vars['user'] = $user;
$vars['groups'] = $mm->listGroupNames();
+ require_once('ContactMethod.class.php');
$this->showView('users/individual', $vars);
}
}
@@ -179,10 +185,20 @@ class Users extends Controller {
}
// Change information //////////////////////////////////////////
+ global $mm;
+ $config_options = array();
+ $mm->pluginManager()->callHook('userConfig', &$config_options);
+
+ foreach ($config_options as $group=>$options) {
+ foreach ($options as $option) {
+ $this->confText($user, $option[0]);
+ }
+ }
+ /*
$this->confText($user, 'firstname');
$this->confText($user, 'lastname');
$this->confText($user, 'hsclass');
-
+ */
// Change contact info /////////////////////////////////////////
global $CONTACT_METHODS;
foreach ($CONTACT_METHODS as $method) {
@@ -213,7 +229,15 @@ class Users extends Controller {
* This will parse POST (really, PUT) data to update multiple users.
*/
private function update_users() {
- // TODO
+ $attribs = $this->getIndexAttribs();
+ foreach ($attribs as $attrib) {
+ $key = $attrib['key'];
+ if (isset($_POST[$key]) && is_array($_POST[$key])) {
+ foreach ($_POST[$key] as $uid => $value) {
+ $this->setConf($uid, $key, $value);
+ }
+ }
+ }
}
/**
@@ -264,8 +288,9 @@ class Users extends Controller {
$editable = $editable && $logged_in_user->isAdmin();
$value = $user->isAdmin();
break;
- default:
+ default:
$value = $user->getConf($key);
+ if ($value===false) $value='';
break;
}
@@ -273,6 +298,27 @@ class Users extends Controller {
'post_key'=>$post_key,
'editable'=>$editable);
}
+ private function setConf($uid, $key, $value) {
+ // So, this rocks because we don't have to check permissions,
+ // the User object does that.
+ global $mm;
+ $user = $mm->getAuthObj($uid);
+
+ switch ($key) {
+ case 'auth_name':
+ $user->setName($value);
+ break;
+ case 'auth_user':
+ $user->setUser($value=='true');
+ break;
+ case 'auth_admin':
+ $user->setAdmin($value=='true');
+ break;
+ default:
+ $user->setConf($key, $value);
+ break;
+ }
+ }
function attrib($key, $name) {
return array('key'=>$key, 'name'=>$name);
@@ -286,6 +332,6 @@ class Users extends Controller {
$this->attrib('email','Email'),
$this->attrib('auth_name', 'Username'),
);
- return $attrib;
+ return $attribs;
}
}