/** * Allows a user to edit post if conditions are right * * @version 2.0 * @since 1.0.0 * @author xLink * * @param int $id */ public function editPost($id) { //grab the post were reffering to $post = $this->objSQL->getLine('SELECT * FROM `$Pforum_posts` WHERE id ="%s" LIMIT 1;', array($id)); if (!is_array($post)) { hmsgDie('FAIL', 'Failed to retreive post information'); } $thread = $this->objSQL->getLine('SELECT t.*, COUNT(DISTINCT p.id) as replies FROM `$Pforum_threads` t LEFT JOIN `$Pforum_posts` p ON p.thread_id = t.id WHERE t.id ="%s" GROUP BY t.id', array($post['thread_id'])); if (!is_array($thread)) { hmsgDie('FAIL', 'Failed to retreive thread information'); } $category = $this->getForumInfo($thread['cat_id']); $category = $category[0]; $catAuth = $this->auth[$category['id']]; $writeTest = false; //see if the user has write permissions if (User::$IS_MOD || $catAuth['auth_mod'] || $catAuth['auth_edit'] && $this->objUser->grab('id') == $post['author'] && ($thread['replies'] == 1 || time() - $post['posted'] < $this->config('forum', 'post_edit_time'))) { $writeTest = true; } if ($writeTest != true) { $this->objTPL->set_filenames(array('body' => 'modules/forum/template/forum_category.tpl')); $this->objTPL->assign_block_vars('threads', array()); $this->objTPL->assign_block_vars('threads.error', array('ERROR' => $msg)); $this->objTPL->parse('body', false); return; } //if we get this far then they have permissions, so start the page output $this->objPage->addPagecrumb(array(array('url' => $this->config('global', 'url'), 'name' => langVar('B_EDIT_POST', $thread['subject'])))); //okay so test to see which part of the page we should see.. if (!HTTP_POST) { $this->objPage->addJSFile('/' . root() . 'scripts/editor.js'); $this->objTPL->set_filenames(array('body' => 'modules/forum/template/forum_post.tpl')); $_SESSION['site']['forum'][$id]['id'] = $id; $_SESSION['site']['forum'][$id]['sessid'] = $sessid = $this->objUser->mkPassword($this->objUser->grab('username') . $id); $first_post = false; if ($id == $thread['first_post_id']) { $first_post = true; } // //-- BBCode Buttons // $button[] = array('text_heading_1.png', 'Heading 1', 'h1', '[h1]|[/h1]'); $button[] = array('text_heading_2.png', 'Heading 2', 'h2', '[h2]|[/h2]'); $button[] = array('text_heading_3.png', 'Heading 3', 'h3', '[h3]|[/h3]'); $button[] = '---'; $button[] = array('text_bold.png', 'Bold', 'bold', '[b]|[/b]'); $button[] = array('text_italic.png', 'Italics', 'italics', '[i]|[/i]'); $button[] = array('text_underline.png', 'Underlined', 'underlined', '[u]|[/u]'); $button[] = array('text_strikethrough.png', 'Strikethrough', 'strikethrough', '[s]|[/s]'); $button[] = $this->genSelects('color'); $button[] = '---'; $button[] = array('link.png', 'Link', 'links', "[url]|[/url]"); $button[] = array('email.png', 'Email Link', 'email', "[email]|[/email]"); $button[] = array('photo_delete.png', 'Image', 'image', "[img]|[/img]"); $button[] = array('comment.png', 'Add Quote', 'quote', "[quote]\n|\n[/quote]"); $button[] = '---'; $button[] = array('script_code.png', 'Code Block', 'code', "[code]\n|\n[/code]"); $button[] = array('php.png', 'PHP Code Block', 'phpcode', "[code=php]\n|\n[/code]"); $button[] = $this->genSelects('code'); $button[] = '---'; $button[] = array('text_columns.png', 'Add Table Columns', 'columns', "[columns]|[/columns]"); $button[] = array('text_list_bullets.png', 'Add Bullet Points', 'ul', "[list]\n[*]|[/list]"); $button[] = array('text_list_numbers.png', 'Add Numbered Points', 'ol', "[list=ol]\n[*]|\n[/list]"); $button[] = array('text_superscript.png', 'Add Superscript Text', 'sup', "[sup]|[/sup]"); $button[] = array('text_subscript.png', 'Add Subscript Text', 'sub', "[sub]|[/sub]"); $this->objPlugins->hook('MODForum_post_buttons', $buttons); $buttons = NULL; foreach ($button as $b) { if (!is_array($b) && strlen($b) > 3) { $buttons .= $b; continue; } if (!is_array($b) && $b == '---') { $buttons .= ' '; continue; } $buttons .= sprintf('<input type="image" src="%s" class="bbButton" title="%s" data-code="%s" />', '/' . root() . 'images/icons/' . $b[0], $b[1], $b[3]); } $postMode = null; $title = null; if ($first_post && (User::$IS_MOD || $catAuth['auth_mod'])) { $postVals = array(1 => str_replace(array(':', ' '), '', strip_tags(langVar('L_ANNOUNCEMENT', ''))), 2 => str_replace(array(':', ' '), '', strip_tags(langVar('L_STICKY', ''))), 0 => str_replace(array(':', ' '), '', strip_tags(langVar('L_POST', '')))); $postMode = $this->objForm->radio('type', $postVals, 0, array('br' => true)) . '<br />'; $this->objTPL->assign_block_vars('title', array()); $this->objTPL->assign_block_vars('new_post', array()); } //yada yada, the general tpl crap.. $this->objTPL->assign_vars(array('F_START' => $this->objForm->start('edit', array('method' => 'POST', 'action' => '?mode=edit&postid=' . $id)), 'F_END' => $this->objForm->finish(), 'SMILIES' => $this->generateSmilies(), 'BUTTONS' => $buttons, 'ID' => $this->objForm->inputbox('id', 'hidden', $id) . $this->objForm->inputbox('sessid', 'hidden', $sessid), 'L_TITLE' => langVar('L_TITLE') . ':', 'F_TITLE' => $this->objForm->inputbox('title', 'input', $thread['subject'], array('extra' => 'tabindex="1"', 'style' => 'width:99%')), 'L_POST_BODY' => langVar('L_POST_BODY') . ':', 'F_POST' => $this->objForm->textarea('post', $post['post'], array('extra' => 'tabindex="2" rows="3"', 'style' => 'height:350px;width:99%;')), 'POST_MODE' => $postMode, 'SUBMIT' => $this->objForm->button('submit', 'Submit', array('extra' => ' tabindex="3"')), 'RESET' => $this->objForm->button('preview', 'Preview', array('extra' => ' tabindex="4" onclick="doPreview();"')))); $this->objTPL->parse('body', false); return; } else { //check to make sure we have a cat id if (!doArgs('id', false, $_POST)) { hmsgDie('FAIL', 'Error: I cannot remember where your posting to.'); } //content checks if (!doArgs('post', false, $_POST)) { unset($_SESSION['site']['forum']); hmsgDie('FAIL', 'Post Failed - Post either missing or not long enough.'); } if (!doArgs('id', false, $_SESSION['site']['forum'][$id]) || $_SESSION['site']['forum'][$id]['id'] != $_POST['id']) { hmsgdie('FAIL', 'Post Failed - I cannot remember where your posting to.'); } if (!doArgs('sessid', false, $_SESSION['site']['forum'][$id]) || $_SESSION['site']['forum'][$id]['sessid'] != $_POST['sessid']) { hmsgdie('FAIL', 'Post Failed - Security Check failed. Please make sure your posting directly from the page.'); } // //--insert the post info into the db // $uid = $this->objUser->grab('id'); unset($update); $update['post'] = secureMe($_POST['post']); $update['edited'] = $thread['edited'] + 1; $update['edited_uid'] = $uid; $post_update = $this->objSQL->updateRow('forum_posts', $update, array('id ="%s"', $id)); if (!$post_update) { hmsgDie('FAIL', 'Error: This is not your post, or there was a problem with saving the post. Error 0x02;'); } $this->objPage->redirect('/' . root() . 'modules/forum/thread/' . seo($thread['subject']) . '-' . $thread['id'] . '.html'); hmsgDie('INFO', 'Thread successfully posted. Redirecting you to it.'); } }
/** * Loads in a instance of the requested module * * @version 2.0 * @since 0.8.0 * @author xLink * * @param string $module Module name * @param var $returnVar Variable you want the module to be loaded into * @param string $mode class, admin, mod, user */ function autoLoadModule($module, &$returnVar, $mode = 'class') { global $objCore; $objCore->objSQL->recordMessage('Loading Module: ' . $module, 'INFO'); if (!is_dir(cmsROOT . 'modules/' . $module . '/')) { hmsgDie('FAIL', 'Error loading module file "' . $module . '"'); return; } $file = cmsROOT . 'modules/' . $module . '/' . $mode . '.' . $module . '.php'; if (!is_readable($file)) { hmsgDie('FAIL', 'Error loading module file "' . $module . '"'); return; } $fileData = file_get_contents($file); $newModule = $module . '_' . substr(md5(microtime()), 0, 6); $fileData = preg_replace("/(class[\\s]){$module}([\\s]extends[\\s]module{)/i", '\\1' . $newModule . '\\2', $fileData); $success = eval('?>' . $fileData . '<?php '); if ($success === false) { hmsgdie('FAIL', 'Error: There was a syntax error in the class."' . $module . '".php file. Loading Halted.'); return; } $returnVar = new $newModule($objCore); }