Beispiel #1
0
 function save()
 {
     $this->success = false;
     if ($this->get('value')) {
         if (!$this->saved()) {
             $this->set('date', 'now()');
         }
         parent::save();
     } else {
         $this->throwError("No value!");
         $this->error_code = 500;
     }
     return $this;
 }
Beispiel #2
0
 function save()
 {
     $this->success = null;
     if (!$this->POD->isAuthenticated()) {
         $this->success = false;
         $this->throwError("No current user! Can't save group!");
         $this->error_code = 500;
         return null;
     }
     if ($this->get('id')) {
         // if we are updating this group, make sure this user has permission to do so!
         $membership = $this->isMember($this->POD->currentUser());
         if ($membership != 'owner' && $membership != 'manager' && !$this->POD->currentUser()->get('adminUser')) {
             $this->success = false;
             $this->throwError("Access denied!  Only group owner or manager can create group!");
             $this->error_code = 401;
             return null;
         }
     } else {
         $this->set('userId', $this->POD->currentUser()->get('id'));
     }
     if ($this->get('groupname') && $this->get('description') && $this->get('userId')) {
         $this->set('groupname', stripslashes(strip_tags($this->get('groupname'))));
         $this->set('description', stripslashes(strip_tags($this->get('description'))));
         if (!$this->get('stub')) {
             $stub = $this->get('groupname');
             $stub = preg_replace("/\\s+/", "-", $stub);
             $stub = preg_replace("/[^a-zA-Z0-9\\-]/", "", $stub);
             $stub = strtolower($stub);
             $this->set('stub', $stub);
         }
         $stub = $this->get('stub');
         $newstub = $stub;
         // check and see if any documents already use this stub.
         $stubcheck = $this->POD->getGroup(array('stub' => $stub));
         $counter = 2;
         while ($stubcheck->success() && $stubcheck->get('id') != $this->get('id')) {
             $newstub = $stub . "_" . $counter++;
             $stubcheck = $this->POD->getGroup(array('stub' => $newstub));
         }
         $stub = $newstub;
         $this->set('stub', $stub);
         if (!$this->saved()) {
             $this->set('date', 'now()');
             $this->set('changeDate', 'now()');
         } else {
             $this->set('changeDate', 'now()');
         }
         parent::save();
         $this->generatePermalink();
         $this->DOCUMENTS = new Stack($this->POD, 'content', array('d.groupId' => $this->get('id')));
         $this->MEMBERS = new Stack($this->POD, 'user', array('mem.groupId' => $this->get('id')), 'mem.date DESC', 20, 0);
         $this->addMember($this->POD->getPerson(array('id' => $this->get('userId'))), 'owner');
         $this->POD->cachestore($this);
         $this->success = true;
         return $this;
     } else {
         $this->success = null;
         $this->throwError("Missing required field");
         $this->error_code = 500;
         return null;
     }
 }
Beispiel #3
0
 function save($local_ok = false)
 {
     $this->success = false;
     if (!$this->POD->isAuthenticated()) {
         $this->throwError("Permission Denied");
         return null;
     }
     if (!$this->get('file_name')) {
         $this->throwError("Could not save file. Required field file_name missing.");
         return;
     }
     if (!$this->get('original_name')) {
         $this->throwError("Could not save new file. Required field original_name missing.");
         return;
     }
     $this->set('original_name', basename($this->get('original_name')));
     $this->set('extension', strtolower(array_pop(explode('.', $this->get('original_name')))));
     if ($this->get('extension') == "jpeg") {
         $this->set('extension', 'jpg');
     }
     $this->set('mime_type', $this->mime_content_type($this->get('original_name')));
     if (!$this->get('mime_type')) {
         $this->throwError("Could not save file. Required field mime_type missing.");
         return;
     }
     if (!$this->get('id')) {
         if (!$this->get('tmp_name')) {
             $this->throwError("Could not save new file. Required field tmp_name missing.");
             return;
         }
     }
     if (!$this->get('userId')) {
         $this->set('userId', $this->POD->currentUser()->get('id'));
     }
     if (!$this->saved()) {
         $this->set('date', 'now()');
         $this->set('changeDate', 'now()');
     } else {
         $this->set('changeDate', 'now()');
     }
     parent::save();
     if ($this->get('tmp_name')) {
         // do file operations
         $this->isImage = false;
         // is this an image or some other sort of file?
         if (preg_match("/^image/", $this->get('mime_type'))) {
             $fileDir = $this->POD->libOptions('imgDir');
             $this->isImage = true;
             $this->POD->tolog("file->save() isImage!");
         } else {
             $fileDir = $this->POD->libOptions('docDir');
         }
         $new_name = "{$fileDir}/" . $this->get('id') . ".original." . $this->get('extension');
         $this->POD->tolog("file->save() New file name: {$new_name}");
         // clean up old versions
         $this->cleanup();
         // is it an uploaded file?
         if (is_uploaded_file($this->get('tmp_name'))) {
             // move uploaded file
             if (!move_uploaded_file($this->get('tmp_name'), $new_name)) {
                 $this->delete();
                 $this->success = false;
                 $this->throwError("file->save() Could not move uploaded file to {$new_name}");
                 return null;
             }
         } else {
             if ($local_ok) {
                 // is it a local file?
                 // move normal file
                 if (!copy($this->get('tmp_name'), $new_name)) {
                     $this->delete();
                     $this->success = false;
                     $this->throwError("file->save() Could not move local file to {$new_name}!");
                     return null;
                 }
             } else {
                 $this->delete();
                 $this->success = false;
                 $this->throwError("file->save() Could not handle local file (local_ok = false)!");
                 return null;
             }
         }
         // is it an image?
         if ($this->isImage) {
             // crop and resize image
             $this->POD->tolog("file->save() Time to crop an image!");
             $this->createThumbs($new_name, $this->get('type'));
             if (!$this->success()) {
                 $error = $this->error();
                 $this->delete();
                 $this->throwError($error);
                 $this->success = false;
                 return null;
             }
         }
         // did we succeed?
         // if not, undo db stuff
     } else {
         $this->POD->tolog("file->save() Updated file info without changing file");
     }
     $this->generatePermalink();
     $this->clearCaches();
     $this->POD->cachestore($this);
     $this->success = true;
 }
Beispiel #4
0
 function save($nomail = false)
 {
     $profilePath = $this->POD->libOptions('profilePath');
     $this->success = false;
     $this->POD->tolog("user->save() " . $this->get('nick'));
     // clean up input
     $this->set('nick', stripslashes(strip_tags($this->get('nick'))));
     $this->set('email', stripslashes(strip_tags($this->get('email'))));
     if ($this->get('nick') == "") {
         $this->throwError("Missing required field nick.");
         $this->error_code = 201;
         return null;
     }
     if ($this->get('email') == "") {
         $this->throwError("Missing required field email.");
         $this->error_code = 202;
         return null;
     }
     if (!$this->get('stub')) {
         $stub = $this->get('nick');
         $stub = preg_replace("/\\s+/", "-", $stub);
         $stub = preg_replace("/[^a-zA-Z0-9\\-]/", "", $stub);
         $stub = strtolower($stub);
     } else {
         $stub = $this->get('stub');
     }
     $newstub = $stub;
     $this->POD->tolog("Begin Checking stub...");
     // check and see if any users already use this stub.
     $stubcheck = $this->POD->getPerson(array('stub' => $stub));
     $counter = 2;
     while ($stubcheck->success() && $stubcheck->get('id') != $this->get('id')) {
         $newstub = $stub . "_" . $counter++;
         $stubcheck = $this->POD->getPerson(array('stub' => $newstub));
     }
     $this->POD->tolog("End Checking stub...");
     $stub = $newstub;
     $this->set('stub', $stub);
     $stub = mysql_real_escape_string($stub);
     // Do I need to create a user or update a user?
     if (!$this->saved()) {
         // CREATE NEW USER!
         $this->set('memberSince', 'now()');
         // new users must specify a password, though we will not store it in the db
         if ($this->get('password') == "") {
             $this->throwError("Missing required field password.");
             $this->error_code = 203;
             return null;
         }
         $error = $this->checkUsernames($this->get('nick'), $this->get('email'), '');
         if ($error == "nick_taken") {
             $this->throwError("Oops!  The name you specified is already being used by someone else on the site.  Please pick a new one.");
             $this->error_code = 204;
             return;
         } else {
             if ($error == "email_taken") {
                 $this->throwError("Ooops! The email address you specified is already registered on the site.");
                 $this->error_code = 205;
                 return;
             }
         }
         // FIX THIS
         // Should use an oop method for handling invites.
         if ($this->get('invite_code') != '') {
             $this->POD->tolog('user->save() Looking for invite.');
             $sql = "SELECT * FROM invites WHERE code='" . $this->get('invite_code') . "';";
             $this->POD->tolog($sql, 2);
             $res = mysql_query($sql, $this->POD->DATABASE);
             $num = mysql_num_rows($res);
             if ($num > 0) {
                 $this->POD->tolog("user->save() INVITE FOUND");
                 $invite = mysql_fetch_assoc($res);
                 $sql = "DELETE FROM invites WHERE id=" . $invite['id'];
                 $this->POD->tolog($sql, 2);
                 mysql_query($sql, $this->POD->DATABASE);
             }
         }
         $authSecret = md5($this->get('email') . $this->get('password'));
         $this->set('authSecret', $authSecret);
         // now that we've generated the authSecret, we can clear the password
         $this->set('password', null);
         $this->generatePermalink();
         if (isset($invite)) {
             $this->POD->tolog('user->save() Invite found, processing...');
             $invitedBy = $invite['userId'];
             $this->set('invitedBy', $invitedBy);
             // members who are invited by other members do not need to confirm their emails
             $this->set('verificationKey', null);
             parent::save();
             if (!$this->success()) {
                 $this->POD->cacheclear($this);
                 return null;
             }
             $this->POD->changeActor(array('id' => $this->get('id')));
             if (isset($invite['groupId'])) {
                 $this->POD->tolog('user->save() Adding user to group');
                 $group = $this->POD->getGroup(array('id' => $invite['groupId']));
                 $group->addMember($this, 'member', true);
             }
             $inviter = $this->POD->getPerson(array('id' => $invitedBy));
             // add the person who invited me as a friend, and send an email
             $this->addFriend($inviter);
             // cause the friend who invited me to add me as a friend, but do not send email
             $inviter->addFriend($this, false);
         } else {
             // new members have to confirm their email address
             $this->set('verificationKey', md5($this->get('password') . $this->get('email')));
             parent::save();
             if (!$this->success()) {
                 $this->POD->cacheclear($this);
                 return null;
             }
         }
         $this->success = true;
         if (!$nomail) {
             $this->POD->tolog("user->save() user created, sending welcome email");
             $this->welcomeEmail();
         }
     } else {
         // UPDATE USER
         $this->POD->tolog("user->save() Updating user " . $this->get('nick'));
         $error = $this->checkUsernames($this->get('nick'), $this->get('email'), $this->get('id'));
         if ($error == "nick_taken") {
             $this->throwError("Oops!  The name you specified is already being used by someone else on the site.  Please pick a new one.");
             $this->error_code = 208;
             $this->POD->cacheclear($this);
             return;
         } else {
             if ($error == "email_taken") {
                 $this->throwError("Oops! The email address you specified is already registered on the site.  You might need to <a href=\"" . $this->POD->siteRoot(false) . "/login.php\">log in</a>.");
                 $this->error_code = 209;
                 $this->POD->cacheclear($this);
                 return;
             }
         }
         if ($this->get('password')) {
             $this->set('authSecret', md5($this->get('email') . $this->get('password')));
             $this->set('password', null);
         }
         parent::save();
         if (!$this->success()) {
             $this->POD->cacheclear($this);
             return null;
         }
     }
     $this->stuffUser();
     $this->success = true;
     $this->POD->cachestore($this);
     return $this;
 }
Beispiel #5
0
 function save($strip_html = true)
 {
     // set up some options
     $this->success = false;
     $this->POD->tolog("content->save()");
     if (!$this->POD->isAuthenticated()) {
         $this->throwError("No current user! Can't save content!");
         return null;
     }
     if (!$this->isEditable()) {
         $this->throwError("Access Denied");
         $this->error_code = 401;
         return null;
     }
     if ($strip_html) {
         $this->set('body', $this->POD->sanitizeInput($this->get('body')));
     }
     $this->set('body', stripslashes($this->get('body')));
     $this->set('headline', stripslashes(strip_tags($this->get('headline'))));
     $this->set('link', stripslashes(strip_tags($this->get('link'))));
     if (!$this->saved()) {
         $this->set('date', 'now()');
         $this->set('editDate', 'now()');
         $this->set('minutes', '0');
         $this->set('changeDate', 'now()');
         $this->set('yes_votes', '0');
         $this->set('no_votes', '0');
         $this->set('hidden', '0');
     } else {
         $this->set('editDate', 'now()');
         $this->set('changeDate', 'now()');
     }
     if ($this->get('privacy') == '') {
         $this->set('privacy', 'public');
     }
     // do this down here instead of at the top to catch cases where the headline is blank after stripping html
     if ($this->get('headline') == '') {
         $this->success = false;
         $this->throwError("Missing required fields");
         $this->error_code = 500;
         return null;
     }
     if (!$this->get('type')) {
         $this->set('type', 'document');
     }
     if (!$this->get('status')) {
         $this->set('status', 'new');
     }
     if ($this->get('createdBy') == '') {
         $this->set('createdBy', $this->POD->currentUser()->get('id'));
     }
     if ($this->get('userId') == '') {
         $this->set('userId', $this->get('createdBy'));
     }
     if (!$this->get('stub')) {
         $stub = $this->get('headline');
         $stub = preg_replace("/\\s+/", "-", $stub);
         $stub = preg_replace("/[^a-zA-Z0-9\\-]/", "", $stub);
         $stub = strtolower($stub);
     } else {
         $stub = $this->get('stub');
     }
     $newstub = $stub;
     // check and see if any content already use this stub.
     $stubcheck = $this->POD->getContent(array('stub' => $stub));
     $counter = 2;
     while ($stubcheck->success() && $stubcheck->get('id') != $this->get('id')) {
         $newstub = $stub . "_" . $counter++;
         $stubcheck = $this->POD->getContent(array('stub' => $newstub));
     }
     $this->set('stub', $newstub);
     parent::save();
     if (!$this->success()) {
         $this->POD->cacheclear($this);
         return null;
     }
     $this->stuffDoc();
     $this->POD->cachestore($this);
     $this->POD->tolog("content->save() ADD WATCH");
     $this->POD->currentUser()->addWatch($this);
     $this->success = true;
     $this->POD->tolog("content->save(): Content saved!");
 }
Beispiel #6
0
 function save()
 {
     $this->success = false;
     if (!$this->get('contentId') && !$this->get('profileId')) {
         $this->throwError("Could not save comment. Required field contentId or profileId missing.");
         $this->error_code = 500;
         return;
     }
     if (!$this->get('comment')) {
         $this->throwError("Could not save comment. Required field comment missing.");
         $this->error_code = 500;
         return;
     }
     if (!$this->get('userId')) {
         $this->throwError("Could not save comment. Required field userId missing.");
         $this->error_code = 500;
         return;
     }
     $this->clearCaches();
     // strip everything but basic tags out of the comment field.
     $this->set('comment', strip_tags(stripslashes($this->get('comment')), '<p><em><strong><a><b><i><br>'));
     if (!$this->saved()) {
         $this->set('date', 'now()');
         $this->set('minutes', 0);
     }
     parent::save();
     $this->generatePermalink();
     $this->POD->cachestore($this);
     return $this;
 }