/** * Process the form * * @param array $clean reference to validated $_POST */ function formProcess(&$clean) { // Captcha unset($_SESSION['captcha']); unset($clean['captcha']); $user = $this->user->getByEmail($clean['user']); if (!$user) { throw new Exception('Invalid user?!'); } elseif (@$user['banned']) { // Banned user, abort suxUser::killSession(); suxFunct::redirect(suxFunct::makeUrl('/banned')); } // Array $reset_user = array(); $reset_user['nickname'] = $user['nickname']; $reset_user['password'] = $this->user->generatePw(); $reset_user_id = $user['users_id']; // Email $subject = "{$GLOBALS['CONFIG']['TITLE']}: {$this->r->gtext['reset_mail_1']} {$reset_user['nickname']}"; $message = "{$this->r->gtext['reset_mail_2']}:\n\n{$reset_user['password']}\n\n"; $message .= "{$this->r->gtext['reset_mail_3']}: {$_SERVER['REMOTE_ADDR']}\n\n"; $message .= "---\n" . suxFunct::makeUrl('/', null, true) . "\n\n"; // Do the dirty $this->user->save($reset_user_id, $reset_user); mb_send_mail($user['email'], $subject, $message); }
/** * Constructor * */ function __construct() { parent::__construct(); // Call userRegisterOpenID if ($this->user->loginCheck()) { // Redirect to previous page if (isset($_SESSION['breadcrumbs'])) { foreach ($_SESSION['breadcrumbs'] as $val) { if (!preg_match('#^user/[login|logout|register|edit]#i', $val)) { suxFunct::redirect(suxFunct::makeUrl($val)); break; } } } // Nothing of value was found, redirect to user page suxFunct::redirect(suxFunct::makeUrl('/user/profile/' . $_SESSION['nickname'])); } else { // Too many password failures? if ($this->user->maxPasswordFailures()) { $this->r->title .= " | {$this->r->gtext['pw_failure']}"; $this->tpl->display('pw_failure.tpl'); die; } } }
/** * Constructor * */ function __construct($nickname) { // Declare objects $this->r = new userRenderer($this->module); // Renderer suxValidate::register_object('this', $this); // Register self to validator parent::__construct(); // Let the parent do the rest // Redirect if not logged in if (empty($_SESSION['users_id'])) { suxFunct::redirect(suxFunct::makeUrl('/user/register')); } // Security check. Is the user allowed to edit this? $tmp = $this->user->getByNickname($nickname, true); if (!$tmp) { suxFunct::redirect(suxFunct::getPreviousURL()); } elseif ($tmp['users_id'] != $_SESSION['users_id']) { // Check that the user is allowed to be here if (!$this->user->isRoot()) { suxFunct::redirect(suxFunct::getPreviousURL()); } } // Declare properties $this->nickname = $nickname; $this->users_id = $tmp['users_id']; $this->image = $tmp['image']; }
/** * Login */ function login() { if ($this->user->loginCheck() || !$this->user->loginCheck() && $this->user->authenticate()) { $this->log->write($_SESSION['users_id'], "sux0r::userAuthenticate() login [IP: {$_SERVER['REMOTE_ADDR']}]", 1); // Log, private // Redirect to previous page if (isset($_SESSION['breadcrumbs'])) { foreach ($_SESSION['breadcrumbs'] as $val) { if (!preg_match('#^user/[login|logout|register|edit]#i', $val)) { suxFunct::redirect(suxFunct::makeUrl($val)); break; } } } // Nothing of value was found, redirect to user page suxFunct::redirect(suxFunct::makeUrl('/user/profile/' . $_SESSION['nickname'])); } else { // Too many password failures? if ($this->user->maxPasswordFailures()) { $this->r->title .= " | {$this->r->gtext['pw_failure']}"; $this->tpl->display('pw_failure.tpl'); die; } // Note: // Threre's a conflift with the authenticate procedure and header('Location:') // The workaround is to echo some spaces and force javascript redirect echo str_repeat(' ', 40000); suxFunct::redirect(suxFunct::makeUrl('/home')); } }
/** * controller * * @author Dac Chartrand <*****@*****.**> * @license http://www.fsf.org/licensing/licenses/gpl-3.0.html */ function sux($action, $params = null) { switch ($action) { case 'access': // -------------------------------------------------------------------- // Access // -------------------------------------------------------------------- if (empty($params[0])) { suxFunct::redirect(suxFunct::makeUrl('/admin')); } $edit = new adminAccess($params[0]); if ($edit->formValidate($_POST)) { $edit->formProcess($_POST); $edit->formSuccess(); } else { $edit->formBuild($_POST); } break; case 'log': // -------------------------------------------------------------------- // Log // -------------------------------------------------------------------- $nickname = null; if (!empty($params[0])) { $nickname = $params[0]; } $admin = new adminLog($nickname); $admin->display(); break; case 'purge': // -------------------------------------------------------------------- // Purge logs // -------------------------------------------------------------------- $edit = new adminPurge(); if ($edit->formValidate($_POST)) { $edit->formProcess($_POST); $edit->formSuccess(); } else { $edit->formBuild($_POST); } break; default: // -------------------------------------------------------------------- // Default // -------------------------------------------------------------------- $admin = new admin(); if ($admin->formValidate($_POST)) { $admin->formProcess($_POST); $admin->formSuccess(); } else { $admin->formBuild($_POST); } break; } }
/** * Constructor * */ function __construct() { // Declare objects $this->rss = new suxRSS(); $this->r = new suxRenderer($this->module); // Renderer suxValidate::register_object('this', $this); // Register self to validator parent::__construct(); // Let the parent do the rest // Redirect if not logged in if (empty($_SESSION['users_id'])) { suxFunct::redirect(suxFunct::makeUrl('/user/register')); } }
/** * Constructor * */ function __construct() { // Declare objects $this->r = new adminRenderer($this->module); // Renderer suxValidate::register_object('this', $this); // Register self to validator parent::__construct(); // Let the parent do the rest // Redirect if not logged in if (empty($_SESSION['users_id'])) { suxFunct::redirect(suxFunct::makeUrl('/user/register')); } // Security check if (!$this->user->isRoot()) { suxFunct::redirect(suxFunct::makeUrl('/home')); } }
/** * Constructor * * @param string $nickname nickname */ function __construct($nickname) { // Declare objects $this->r = new userRenderer($this->module); // Renderer parent::__construct(); // Let the parent do the rest // Declare properties $this->r->bool['analytics'] = true; // Turn on analytics $this->profile = $this->user->getByNickname($nickname, true); unset($this->profile['password']); // We don't need this if (!$this->profile) { suxFunct::redirect(suxFunct::getPreviousURL()); } // Redirect for invalid profiles }
/** * Constructor * */ function __construct() { // Declare objects $this->nb = new suxUserNaiveBayesian(); $this->r = new bayesRenderer($this->module); // Renderer suxValidate::register_object('this', $this); // Register self to validator parent::__construct(); // Let the parent do the rest // If feature is turned off, then redirect if ($GLOBALS['CONFIG']['FEATURE']['bayes'] == false) { suxFunct::redirect(suxFunct::getPreviousURL()); } // Redirect if not logged in if (empty($_SESSION['users_id'])) { suxFunct::redirect(suxFunct::makeUrl('/user/register')); } }
/** * Build the form and show the template * * @param array $dirty reference to unverified $_POST */ function formBuild(&$dirty) { $photoalbum = array(); // Editing a photoalbum $tmp = $this->photo->getAlbumByID($this->id); if (!$tmp) { suxFunct::redirect(suxFunct::makeURL('/photos')); } // Invalid id $photoalbum['id'] = $tmp['id']; $photoalbum['cover'] = $tmp['thumbnail']; // Don't allow spoofing unset($dirty['id']); $this->tpl->assign($photoalbum); // -------------------------------------------------------------------- // Form logic // -------------------------------------------------------------------- if (!empty($dirty)) { $this->tpl->assign($dirty); } else { suxValidate::disconnect(); } if (!suxValidate::is_registered_form()) { suxValidate::connect($this->tpl, true); // Reset connection // Register our validators suxValidate::register_validator('integrity', 'integrity:id', 'hasIntegrity'); } // -------------------------------------------------------------------- // Templating // -------------------------------------------------------------------- // Start pager $this->pager->limit = $this->per_page; $this->pager->setStart(); $this->pager->setPages($this->photo->countPhotos($this->id)); $this->r->text['pager'] = $this->pager->pageList(suxFunct::makeUrl("/photos/album/annotate/{$this->id}")); $this->r->arr['photos'] = $this->photo->getPhotos($this->pager->limit, $this->pager->start, $this->id); $this->r->text['form_url'] = suxFunct::makeUrl('/photos/album/annotate/' . $this->id, array('page' => $_GET['page'])); $this->r->text['back_url'] = suxFunct::getPreviousURL(); $this->r->title .= " | {$this->r->gtext['annotate_2']}"; $this->tpl->display('annotate.tpl'); }
/** * controller * * @author Dac Chartrand <*****@*****.**> * @license http://www.fsf.org/licensing/licenses/gpl-3.0.html */ function sux($action, $params = null) { switch ($action) { case 'relationship': // -------------------------------------------------------------------- // Set a relationship with a user // -------------------------------------------------------------------- if (empty($params[0])) { suxFunct::redirect(suxFunct::makeUrl('/society')); } $soc = new societyEdit($params[0]); if ($soc->formValidate($_POST)) { $soc->formProcess($_POST); $soc->formSuccess(); } else { $soc->formBuild($_POST); } break; } }
/** * Constructor * */ function __construct() { // Declare objects $this->rss = new suxRSS(); $this->r = new feedsRenderer($this->module); // Renderer suxValidate::register_object('this', $this); // Register self to validator parent::__construct(); // Let the parent do the rest // Redirect if not logged in if (empty($_SESSION['users_id'])) { suxFunct::redirect(suxFunct::makeUrl('/user/register')); } // Security check if (!$this->user->isRoot()) { $access = $this->user->getAccess($this->module); if ($access < $GLOBALS['CONFIG']['ACCESS'][$this->module]['admin']) { suxFunct::redirect(suxFunct::makeUrl('/home')); } } }
/** * Constructor * * @param int $id album id */ function __construct($id = null) { if ($id) { if (!filter_var($id, FILTER_VALIDATE_INT) || $id < 1) { suxFunct::redirect(suxFunct::makeURL('/photos')); } // Invalid id } // Declare objects $this->photo = new suxPhoto(); // Photos $this->r = new photosRenderer($this->module); // Renderer suxValidate::register_object('this', $this); // Register self to validator parent::__construct(); // Let the parent do the rest // Declare properties $this->photo->setPublished(null); $this->id = $id; // Redirect if not logged in if (empty($_SESSION['users_id'])) { suxFunct::redirect(suxFunct::makeUrl('/user/register')); } // Security check if (!$this->user->isRoot()) { $access = $this->user->getAccess($this->module); if ($access < $GLOBALS['CONFIG']['ACCESS'][$this->module]['admin']) { if ($access < $GLOBALS['CONFIG']['ACCESS'][$this->module]['publisher']) { suxFunct::redirect(suxFunct::makeURL('/photos')); } elseif ($id) { if (!$this->photo->isAlbumOwner($id, $_SESSION['users_id'])) { suxFunct::redirect(suxFunct::makeURL('/photos')); } } } } }
/** * Constructor * * @param string nickname */ function __construct($nickname = null) { // Declare objects $this->r = new adminRenderer($this->module); // Renderer parent::__construct(); // Let the parent do the rest // Redirect if not logged in if (empty($_SESSION['users_id'])) { suxFunct::redirect(suxFunct::makeUrl('/user/register')); } // Security check if (!$this->user->isRoot()) { suxFunct::redirect(suxFunct::makeUrl('/home')); } // Declare properties $this->log->setPublished(null); $tmp = $this->user->getByNickname($nickname); if ($tmp) { $this->users_id = $tmp['users_id']; $this->nickname = $tmp['nickname']; } }
/** * Constructor * */ function __construct($mode = 'register', $user = null) { // Declare objects $this->r = new userRenderer($this->module); // Renderer suxValidate::register_object('this', $this); // Register self to validator parent::__construct(); // Let the parent do the rest // Give a unique form name $form_name = 'userEdit'; $this->tpl->assign('form_name', $form_name); suxValidate::set_form($form_name); // ------------------------------------------------------------------- // Edit mode // ------------------------------------------------------------------- if ($mode == 'edit') { // Redirect if invalid if ($this->user->loginCheck(suxfunct::makeUrl('/user/register'))) { $this->mode = 'edit'; } if ($user != $_SESSION['nickname']) { // Security check // Only a root user can modify other users if (!$this->user->isRoot()) { suxFunct::redirect(suxFunct::makeUrl('/home')); } } // Get user $u = $this->user->getByNickname($user); if (!$u) { suxFunct::redirect(suxFunct::getPreviousURL()); } // Invalid user $this->users_id = $u['users_id']; } }
function formSuccess() { suxFunct::redirect(suxFunct::getPreviousURL('cropper')); }
/** * The form was successfuly processed */ function formSuccess() { suxFunct::redirect(suxFunct::makeUrl("/{$this->module}/admin/")); }
/** * controller * * @author Dac Chartrand <*****@*****.**> * @license http://www.fsf.org/licensing/licenses/gpl-3.0.html */ function sux($action, $params = null) { // Alphasort $alphasort = false; if (isset($_REQUEST['sort']) && $_REQUEST['sort'] == 'alpha') { $alphasort = true; } switch ($action) { case 'admin': // -------------------------------------------------------------------- // Admin // -------------------------------------------------------------------- $admin = new bookmarksAdmin(); if ($admin->formValidate($_POST)) { $admin->formProcess($_POST); $admin->formSuccess(); } else { $admin->formBuild($_POST); } break; case 'approve': // -------------------------------------------------------------------- // Approve // -------------------------------------------------------------------- $bm = new bookmarksApprove(); if ($bm->formValidate($_POST)) { $bm->formProcess($_POST); $bm->formSuccess(); } else { $bm->formBuild($_POST); } break; case 'suggest': // -------------------------------------------------------------------- // Suggest // -------------------------------------------------------------------- $bm = new bookmarksSuggest(); if ($bm->formValidate($_POST)) { $bm->formProcess($_POST); $bm->formSuccess(); } else { $bm->formBuild($_POST); } break; case 'edit': // -------------------------------------------------------------------- // Edit // -------------------------------------------------------------------- $id = !empty($params[0]) ? $params[0] : null; $edit = new bookmarksEdit($id); if ($edit->formValidate($_POST)) { $edit->formProcess($_POST); $edit->formSuccess(); } else { $edit->formBuild($_POST); } break; case 'user': // -------------------------------------------------------------------- // User // -------------------------------------------------------------------- if (empty($params[0])) { suxFunct::redirect(suxFunct::makeUrl('/bookmarks')); } $bm = new bookmarks(); $bm->user($params[0], $alphasort); break; case 'tag': // -------------------------------------------------------------------- // Tags // -------------------------------------------------------------------- if (empty($params[0])) { suxFunct::redirect(suxFunct::makeUrl('/bookmarks')); } $bm = new bookmarks(); if ($params[0] == 'cloud') { $bm->tagcloud(); } else { $bm->tag($params[0], $alphasort); } break; case 'rss': // -------------------------------------------------------------------- // RSS // -------------------------------------------------------------------- $bm = new bookmarks(); $bm->rss(); break; default: // -------------------------------------------------------------------- // Default // -------------------------------------------------------------------- $bm = new bookmarks(); $bm->listing($alphasort); break; } }
/** * controller * * @author Dac Chartrand <*****@*****.**> * @license http://www.fsf.org/licensing/licenses/gpl-3.0.html */ function sux($action, $params = null) { switch ($action) { case 'admin': // -------------------------------------------------------------------- // Admin // -------------------------------------------------------------------- $admin = new feedsAdmin(); if ($admin->formValidate($_POST)) { $admin->formProcess($_POST); $admin->formSuccess(); } else { $admin->formBuild($_POST); } break; case 'approve': // -------------------------------------------------------------------- // Approve // -------------------------------------------------------------------- $feeds = new feedsApprove(); if ($feeds->formValidate($_POST)) { $feeds->formProcess($_POST); $feeds->formSuccess(); } else { $feeds->formBuild($_POST); } break; case 'edit': // -------------------------------------------------------------------- // Edit // -------------------------------------------------------------------- $id = !empty($params[0]) ? $params[0] : null; $edit = new feedsEdit($id); if ($edit->formValidate($_POST)) { $edit->formProcess($_POST); $edit->formSuccess(); } else { $edit->formBuild($_POST); } break; case 'suggest': // -------------------------------------------------------------------- // Suggest // -------------------------------------------------------------------- $feeds = new feedsSuggest(); if ($feeds->formValidate($_POST)) { $feeds->formProcess($_POST); $feeds->formSuccess(); } else { $feeds->formBuild($_POST); } break; case 'manage': // -------------------------------------------------------------------- // Manage // -------------------------------------------------------------------- $feeds = new feedsManage(); if ($feeds->formValidate($_POST)) { $feeds->formProcess($_POST); $feeds->formSuccess(); } else { $feeds->formBuild($_POST); } break; case 'user': // -------------------------------------------------------------------- // User // -------------------------------------------------------------------- if (empty($params[0])) { suxFunct::redirect(suxFunct::makeUrl('/feeds')); } $feeds = new feeds(); $feeds->user($params[0]); break; case 'purge': // -------------------------------------------------------------------- // Purge feeds // -------------------------------------------------------------------- $edit = new feedsPurge(); if ($edit->formValidate($_POST)) { $edit->formProcess($_POST); $edit->formSuccess(); } else { $edit->formBuild($_POST); } break; default: // -------------------------------------------------------------------- // Default // -------------------------------------------------------------------- $feeds = new feeds(); if (filter_var($action, FILTER_VALIDATE_INT) && $action > 0) { $feeds->listing($action); } else { $feeds->listing(); } break; } }
/** * Show a user if they are logged in or not */ function id_res_mode() { /* Assert truthiness of openid_identity and act accordingly */ if (!empty($_GET['openid_identity']) && $this->complete($_GET['openid_identity'])) { // Success // we have verified the identity // a maze of if/else follows... $this->destroyOpenIDSession(); $u = $this->user->getUserByOpenID($_GET['openid_identity']); if ($u) { if ($this->user->loginCheck() && $_SESSION['users_id'] != $u['users_id']) { // Wrong openid? $this->wrapHtml($this->r->gtext['error_id_conflict']); } else { // Log this user in $this->user->setSession($u['users_id']); suxFunct::redirect(suxFunct::makeUrl('/user/profile/' . $u['nickname'])); } } elseif ($this->user->loginCheck()) { if (!$this->urlDescends($_GET['openid_identity'], $this->profile['my_url'])) { // This must be this users id, attach it $this->user->attachOpenID($_GET['openid_identity']); } // Send this user to their own page suxFunct::redirect(suxFunct::makeUrl('/user/profile/' . $_SESSION['nickname'])); } else { // Forward to registration $_SESSION['openid_url_registration'] = $_GET['openid_identity']; $_SESSION['openid_url_integrity'] = md5($_GET['openid_identity'] . @$GLOBALS['CONFIG']['SALT']); // Sreg $query = null; foreach ($_REQUEST as $key => $val) { if (preg_match('/^openid_sreg_/', $key)) { $tmp = str_replace('openid_sreg_', '', $key); $query[$tmp] = $val; } } suxFunct::redirect(suxFunct::makeUrl('/user/register', $query)); } } elseif (!empty($_GET['openid_identity'])) { // Failure $this->destroyOpenIDSession(); $this->wrapHtml($this->r->gtext['error_failed'] . ': ' . $_GET['openid_identity']); } else { // Otherwise, provide useless info $this->destroyOpenIDSession(); if ($this->user->loginCheck()) { $this->wrapHtml($this->r->gtext['logged_in'] . ' ' . $_SESSION['nickname']); } else { $this->wrapHtml($this->r->gtext['not_logged_in']); } } }
/** * Process the form * * @param array $clean reference to validated $_POST */ function formProcess(&$clean) { if (!isset($_FILES['image']) || !is_uploaded_file($_FILES['image']['tmp_name'])) { throw new Exception('No file uploaded?'); } // Check that the user is allowed to upload photos / Security check #2 if (!$this->user->isRoot()) { $access = $this->user->getAccess($this->module); if ($access < $GLOBALS['CONFIG']['ACCESS'][$this->module]['admin']) { if ($access < $GLOBALS['CONFIG']['ACCESS'][$this->module]['publisher']) { suxFunct::redirect(suxFunct::makeURL('/photos')); } elseif (!$this->photo->isAlbumOwner($clean['album'], $_SESSION['users_id'])) { suxFunct::redirect(suxFunct::makeURL('/photos')); } } } // Commence collecting $photo array $photo['photoalbums_id'] = $clean['album']; // Get extension $format = explode('.', $_FILES['image']['name']); $format = strtolower(end($format)); // Set the data dir $data_dir = suxFunct::dataDir($this->module); if ($format != 'zip') { // ---------------------------------------------------------------- // Image file // ---------------------------------------------------------------- list($resize, $fullsize) = suxPhoto::renameImage($_FILES['image']['name']); $photo['image'] = $resize; // Add image to $photo array $resize = $data_dir . "/{$resize}"; $fullsize = $data_dir . "/{$fullsize}"; $md5 = md5_file($_FILES['image']['tmp_name']); if (!$this->photo->isDupe($md5, $_SESSION['users_id'], $photo['photoalbums_id'])) { suxPhoto::resizeImage($format, $_FILES['image']['tmp_name'], $resize, $this->tpl->getConfigVars('thumbnailWidth'), $this->tpl->getConfigVars('thumbnailHeight')); move_uploaded_file($_FILES['image']['tmp_name'], $fullsize); // Insert $photo into database $photo['md5'] = $md5; $this->photo->savePhoto($_SESSION['users_id'], $photo); } } else { // ---------------------------------------------------------------- // Zip file // ---------------------------------------------------------------- $tmp_dir = $GLOBALS['CONFIG']['PATH'] . '/temporary/' . md5(uniqid(mt_rand(), true)); if (!is_dir($tmp_dir) && !mkdir($tmp_dir, 0777, true)) { throw new Exception('Can\'t create temp dir ' . $tmp_dir); } if (suxFunct::unzip($_FILES['image']['tmp_name'], $tmp_dir)) { $valid_formats = array('jpg', 'jpeg', 'png', 'gif'); $files = array(); foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tmp_dir)) as $file) { if (!$file->isFile()) { continue; } if (mb_strpos($file->getPathname(), '__MACOSX') !== false) { continue; } $files[$file->getPathname()] = $file->getFilename(); } foreach ($files as $filepath => $file) { $format = explode('.', $file); $format = strtolower(end($format)); if (!in_array($format, $valid_formats)) { continue; } // Skip list($resize, $fullsize) = suxPhoto::renameImage($file); $photo['image'] = $resize; // Add image to $photo array $resize = $data_dir . "/{$resize}"; $fullsize = $data_dir . "/{$fullsize}"; $md5 = md5_file($filepath); if (!$this->photo->isDupe($md5, $_SESSION['users_id'], $photo['photoalbums_id'])) { suxPhoto::resizeImage($format, $filepath, $resize, $this->tpl->getConfigVars('thumbnailWidth'), $this->tpl->getConfigVars('thumbnailHeight')); copy($filepath, $fullsize); // Insert $photo into database $photo['md5'] = $md5; $this->photo->savePhoto($_SESSION['users_id'], $photo); } } } suxFunct::obliterateDir($tmp_dir); } $this->log->write($_SESSION['users_id'], "sux0r::photosUpload() photoalbums_id: {$photo['photoalbums_id']}", 1); // Private $this->photo->setPublished(true); $tmp = $this->photo->getAlbumByID($photo['photoalbums_id']); // Is actually published? $this->photo->setPublished(null); // Revert if ($tmp) { // Clear all caches, cheap and easy $this->tpl->clearAllCache(); // Log message $log = ''; $url = suxFunct::makeUrl("/user/profile/{$_SESSION['nickname']}", null, true); $log .= "<a href='{$url}'>{$_SESSION['nickname']}</a> "; $log .= mb_strtolower($this->r->gtext['uploaded_images']); $url = suxFunct::makeUrl("/photos/album/{$tmp['id']}", null, true); $log .= " <a href='{$url}'>{$tmp['title']}</a>"; // Log $this->log->write($_SESSION['users_id'], $log); // Clear caches, cheap and easy $tpl = new suxTemplate('user'); $tpl->clearCache(null, $_SESSION['nickname']); } }
/** * The form was successfuly processed */ function formSuccess() { $this->tpl->clearCache(null, $_SESSION['nickname']); // Clear cache suxFunct::redirect(suxFunct::makeUrl('/blog/bookmarks/' . $this->id)); // Pass this on to bookmarks for scanning }
/** * The form was successfuly processed */ function formSuccess() { suxFunct::redirect(suxFunct::makeUrl("/user/openid/{$this->nickname}")); }
/** * Tag */ function tag($tag_id, $alphasort = false) { $cache_id = null; $sort = array(); $tag = $this->tags->getByID($tag_id); if (!$tag) { suxFunct::redirect(suxFunct::makeUrl('/bookmarks')); } // Needs to be in externally accessible variable for filter() $this->tag_id = $tag_id; // Establish order if ($alphasort) { $sort['sort'] = 'alpha'; // Sort, used in makeUrl() and passed as a hidden field to insert_bayesFilters() $this->bm->setOrder('title', 'ASC'); } // Assign template variables $this->r->title .= " | {$this->r->gtext['bookmarks']} | {$this->r->gtext['tag']} | {$tag['tag']}"; $this->r->text['form_url'] = suxFunct::makeUrl('/bookmarks/tag/' . $tag_id); // Form Url $this->tpl->assign('datesort_url', suxFunct::makeUrl("/bookmarks/tag/{$tag_id}")); $this->tpl->assign('alphasort_url', suxFunct::makeUrl("/bookmarks/tag/{$tag_id}", array('sort' => 'alpha'))); $this->tpl->assign('sidetitle', $tag['tag']); $this->tpl->assign('sort', $sort); $count = $this->countTaggedItems($this->tag_id); if (list($vec_id, $cat_id, $threshold, $start, $search) = $this->nb->isValidFilter()) { // --------------------------------------------------------------- // Filtered results // --------------------------------------------------------------- $eval = '$this->getTaggedItems($this->tag_id, $this->pager->limit, $start)'; $this->r->arr['bookmarks'] = $this->filter($count, $vec_id, $cat_id, $threshold, $start, $eval, $search); // Important: $start is a reference // If $start is smaller than $count, then there are more results, we generate the approptiate pager link. if ($start < $count) { // Params if ($threshold !== false) { $params = array('threshold' => $threshold, 'filter' => $cat_id); } else { $params = array('filter' => $cat_id); } $params['search'] = $search; if ($alphasort) { $params['sort'] = 'alpha'; } // Pager link $this->r->text['pager'] = $this->pager->continueURL($start, suxFunct::makeUrl('/bookmarks/tag/' . $this->tag_id, $params)); } } else { // --------------------------------------------------------------- // Paged results, cached // --------------------------------------------------------------- // Get nickname if (isset($_SESSION['nickname'])) { $nn = $_SESSION['nickname']; } else { $nn = 'nobody'; } $this->pager->setStart(); // Start pager, variable used in cache_id // "Cache Groups" using a vertical bar | if ($alphasort) { $cache_id = "{$nn}|tags|{$this->tag_id}|alphasort|{$this->pager->start}"; } else { $cache_id = "{$nn}|tags|{$this->tag_id}|datesort|{$this->pager->start}"; } $this->tpl->caching = 1; if (!$this->tpl->isCached('scroll.tpl', $cache_id)) { $this->pager->setPages($count); $this->r->text['pager'] = $this->pager->pageList(suxFunct::makeUrl('/bookmarks/tag/' . $this->tag_id, $sort)); $this->r->arr['bookmarks'] = $this->getTaggedItems($this->tag_id, $this->pager->limit, $this->pager->start); if (!count($this->r->arr['bookmarks'])) { $this->tpl->caching = 0; } // Nothing to cache, avoid writing to disk } } $this->tpl->display('scroll.tpl', $cache_id); }
function user($nickname) { // Get users_id based on nickname $user = $this->user->getByNickname($nickname); if (!$user) { suxFunct::redirect(suxFunct::makeUrl('/feeds')); } $this->users_id = $user['users_id']; // Needs to be in externally accessible variable for filter() unset($user); // Assign stuff $this->r->text['form_url'] = suxFunct::makeUrl("/feeds/user/{$nickname}"); // Forum Url $cache_id = null; $this->r->title .= " | {$this->r->gtext['feeds']} | {$nickname}"; if (list($vec_id, $cat_id, $threshold, $start, $search) = $this->nb->isValidFilter()) { // --------------------------------------------------------------- // Filtered results // --------------------------------------------------------------- // User has subscriptions, we need special JOIN queries $max = $this->countUserItems($this->users_id); $eval = '$this->getUserItems($this->users_id, $this->pager->limit, $start)'; $this->r->arr['feeds'] = $this->filter($max, $vec_id, $cat_id, $threshold, $start, $eval, $search); // Important: $start is a reference if ($start < $max) { if ($threshold !== false) { $params = array('threshold' => $threshold, 'filter' => $cat_id); } else { $params = array('filter' => $cat_id); } $params['search'] = $search; $url = suxFunct::makeUrl("/feeds/user/{$nickname}", $params); $this->r->text['pager'] = $this->pager->continueURL($start, $url); } } else { // --------------------------------------------------------------- // Paged results, cached // --------------------------------------------------------------- // Get nickname if (isset($_SESSION['nickname'])) { $nn = $_SESSION['nickname']; } else { $nn = 'nobody'; } $this->pager->setStart(); // Start pager // "Cache Groups" using a vertical bar | $cache_id = "{$nn}|user|{$nickname}|{$this->pager->start}"; $this->tpl->caching = 1; if (!$this->tpl->isCached('scroll.tpl', $cache_id)) { // User has subscriptions, we need special JOIN queries $this->pager->setPages($this->countUserItems($this->users_id)); $this->r->arr['feeds'] = $this->getUserItems($this->users_id, $this->pager->limit, $this->pager->start); $this->r->text['pager'] = $this->pager->pageList(suxFunct::makeUrl("/feeds/user/{$nickname}")); if (!count($this->r->arr['feeds'])) { $this->tpl->caching = 0; } // Nothing to cache, avoid writing to disk } } $this->tpl->assign('users_id', $this->users_id); $this->tpl->display('scroll.tpl', $cache_id); }
/** * controller * * @author Dac Chartrand <*****@*****.**> * @license http://www.fsf.org/licensing/licenses/gpl-3.0.html */ function sux($action, $params = null) { switch ($action) { case 'admin': // -------------------------------------------------------------------- // Admin // -------------------------------------------------------------------- $admin = new photosAdmin(); if ($admin->formValidate($_POST)) { $admin->formProcess($_POST); $admin->formSuccess(); } else { $admin->formBuild($_POST); } break; case 'view': // -------------------------------------------------------------------- // View // -------------------------------------------------------------------- if (empty($params[0]) || !filter_var($params[0], FILTER_VALIDATE_INT) || $params[0] < 1) { suxFunct::redirect(suxFunct::makeUrl('/photos')); } $photos = new photos(); $photos->view($params[0]); break; case 'upload': // -------------------------------------------------------------------- // Upload // -------------------------------------------------------------------- $edit = new photosUpload(@$params[0]); if ($edit->formValidate($_POST)) { $edit->formProcess($_POST); $edit->formSuccess(); } else { $edit->formBuild($_POST); } break; case 'album': // -------------------------------------------------------------------- // Edit // -------------------------------------------------------------------- if ($params[0] == 'edit') { $id = !empty($params[1]) ? $params[1] : null; $edit = new photoalbumsEdit($id); if ($edit->formValidate($_POST)) { $edit->formProcess($_POST); $edit->formSuccess(); } else { $edit->formBuild($_POST); } break; } elseif ($params[0] == 'annotate') { if (empty($params[1]) || !filter_var($params[1], FILTER_VALIDATE_INT) || $params[1] < 1) { suxFunct::redirect(suxFunct::makeUrl('/photos')); } $edit = new photosEdit($params[1]); if ($edit->formValidate($_POST)) { $edit->formProcess($_POST); $edit->formSuccess(); } else { $edit->formBuild($_POST); } break; } else { if (empty($params[0]) || !filter_var($params[0], FILTER_VALIDATE_INT) || $params[0] < 1) { suxFunct::redirect(suxFunct::makeUrl('/photos')); } $photos = new photos(); $photos->album($params[0]); break; } case 'user': // -------------------------------------------------------------------- // User // -------------------------------------------------------------------- if (empty($params[0])) { suxFunct::redirect(suxFunct::makeUrl('/photos')); } $photos = new photos(); $photos->listing($params[0]); break; case 'rss': // -------------------------------------------------------------------- // RSS // -------------------------------------------------------------------- $photos = new photos(); $photos->rss(); break; default: $photos = new photos(); $photos->listing(); break; } }
/** * controller * * @author Dac Chartrand <*****@*****.**> * @license http://www.fsf.org/licensing/licenses/gpl-3.0.html */ function sux($action, $params = null) { switch ($action) { case 'admin': // -------------------------------------------------------------------- // Admin // -------------------------------------------------------------------- $admin = new blogAdmin(); if ($admin->formValidate($_POST)) { $admin->formProcess($_POST); $admin->formSuccess(); } else { $admin->formBuild($_POST); } break; case 'edit': // -------------------------------------------------------------------- // Edit // -------------------------------------------------------------------- $id = !empty($params[0]) ? $params[0] : null; $edit = new blogEdit($id); if ($edit->formValidate($_POST)) { $edit->formProcess($_POST); $edit->formSuccess(); } else { $edit->formBuild($_POST); } break; case 'bookmarks': // -------------------------------------------------------------------- // Scan for bookmarks // -------------------------------------------------------------------- if (empty($params[0]) || !filter_var($params[0], FILTER_VALIDATE_INT)) { suxFunct::redirect(suxFunct::makeUrl('/blog')); } $bm = new blogBookmarks($params[0]); if ($bm->formValidate($_POST)) { $bm->formProcess($_POST); $bm->formSuccess(); } else { $bm->formBuild($_POST); } break; case 'reply': // -------------------------------------------------------------------- // Reply // -------------------------------------------------------------------- if (empty($params[0]) || !filter_var($params[0], FILTER_VALIDATE_INT)) { suxFunct::redirect(suxFunct::makeUrl('/blog')); } $reply = new blogReply($params[0]); if ($reply->formValidate($_POST)) { $reply->formProcess($_POST); $reply->formSuccess(); } else { $reply->formBuild($_POST); } break; case 'view': // -------------------------------------------------------------------- // View // -------------------------------------------------------------------- if (empty($params[0]) || !filter_var($params[0], FILTER_VALIDATE_INT)) { suxFunct::redirect(suxFunct::makeUrl('/blog')); } $blog = new blog(); $blog->view($params[0]); break; case 'author': // -------------------------------------------------------------------- // Author // -------------------------------------------------------------------- if (empty($params[0])) { suxFunct::redirect(suxFunct::makeUrl('/blog')); } $blog = new blog(); $blog->author($params[0]); break; case 'tag': // -------------------------------------------------------------------- // Tag // -------------------------------------------------------------------- if (empty($params[0])) { suxFunct::redirect(suxFunct::makeUrl('/blog')); } $blog = new blog(); if ($params[0] == 'cloud') { $blog->tagcloud(); } else { $blog->tag($params[0]); } break; case 'category': // -------------------------------------------------------------------- // Category // -------------------------------------------------------------------- if (empty($params[0])) { suxFunct::redirect(suxFunct::makeUrl('/blog')); } $blog = new blog(); $blog->category($params[0]); break; case 'month': // -------------------------------------------------------------------- // Month // -------------------------------------------------------------------- $date = !empty($params[0]) ? $params[0] : date('Y-m-d'); $blog = new blog(); $blog->month($date); break; case 'rss': // -------------------------------------------------------------------- // RSS // -------------------------------------------------------------------- $blog = new blog(); $blog->rss(); break; default: // -------------------------------------------------------------------- // Default // -------------------------------------------------------------------- $blog = new blog(); $blog->listing(); break; } }
/** * The form was successfuly processed */ function formSuccess() { // clear all caches with "nickname" as the first cache_id group $this->tpl->clearCache(null, "{$_SESSION['nickname']}"); // Redirect suxFunct::redirect(suxFunct::getPreviousURL()); }
/** * Redirect to openid module * * @param array $clean reference to validated $_POST */ function formHandoff(&$clean) { $q = array('openid.mode' => 'login', 'openid_url' => $clean['url']); $url = suxFunct::makeUrl('/openid/register/openid', $q); suxFunct::redirect($url); }
/** * View photo */ function view($id) { // Get nickname if (isset($_SESSION['nickname'])) { $nn = $_SESSION['nickname']; } else { $nn = 'nobody'; } // "Cache Groups" using a vertical bar | $cache_id = "{$nn}|view|{$id}"; $this->tpl->caching = 1; if (!$this->tpl->isCached('view.tpl', $cache_id)) { $this->r->arr['photos'] = $this->photo->getPhotoByID($id); if ($this->r->arr['photos'] == false || !count($this->r->arr['photos'])) { suxFunct::redirect(suxFunct::getPreviousURL()); } else { $this->r->arr['photos']['image'] = suxPhoto::t2fImage($this->r->arr['photos']['image']); // Fullsize // Album info $this->r->arr['album'] = $this->photo->getAlbumByID($this->r->arr['photos']['photoalbums_id']); $tmp = $this->user->getByID($this->r->arr['album']['users_id']); $this->r->arr['album']['nickname'] = $tmp['nickname']; // Previous, next, and page number $prev_id = null; $next_id = null; $page = 1; $query = 'SELECT id FROM photos WHERE photoalbums_id = ? ORDER BY image '; // Same order as suxPhoto->getPhotos() $db = suxDB::get(); $st = $db->prepare($query); $st->execute(array($this->r->arr['photos']['photoalbums_id'])); $i = 0; while ($prev_next = $st->fetch(PDO::FETCH_ASSOC)) { ++$i; if ($prev_next['id'] == $id) { break; } if ($i >= $this->per_page) { $i = 0; ++$page; } $prev_id = $prev_next['id']; } $prev_next = $st->fetch(PDO::FETCH_ASSOC); $next_id = $prev_next['id']; $this->r->text['prev_id'] = $prev_id; $this->r->text['next_id'] = $next_id; $this->r->text['back_url'] = suxFunct::makeUrl('photos/album/' . $this->r->arr['photos']['photoalbums_id'], array('page' => $page)); $this->r->title .= " | {$this->r->gtext['photos']} | {$this->r->arr['album']['title']}"; } } $this->tpl->display('view.tpl', $cache_id); }