Beispiel #1
0
 public function exec(kxEnv $environment)
 {
     $dbsize = 0;
     switch ($this->db->driver()) {
         case 'mysql':
             $twigData['dbtype'] = 'MySQL';
             $results = $this->db->query("SHOW TABLE STATUS");
             foreach ($results as $line) {
                 $dbsize += $line->data_length + $line->index_length;
             }
             break;
         case 'pgsql':
             $twigData['dbtype'] = 'PostgreSQL';
             $results = $this->db->query("SELECT pg_database_size('" . substr(kxEnv::get("kx:db:dsn"), strpos(kxEnv::get("kx:db:dsn"), "dbname=") + 7, strlen(kxEnv::get("kx:db:dsn"))) . "')");
             foreach ($results as $line) {
                 $dbsize += $line->pg_database_size;
             }
             break;
         case 'sqlite':
             $twigData['dbtype'] = 'SQLite';
             $dbsize = filesize(substr(kxEnv::get("kx:db:dsn"), strpos(kxEnv::get("kx:db:dsn"), "sqlite:") + 7, strlen(kxEnv::get("kx:db:dsn"))));
             break;
         default:
             $twigData['dbtype'] = $this->db->driver();
     }
     $twigData['dbsize'] = kxFunc::convertBytes($dbsize);
     $twigData['dbversion'] = substr($this->db->version(), 0, strrpos($this->db->version(), '-') !== FALSE ? strrpos($this->db->version(), '-') : strlen($this->db->version()));
     $twigData['stats']['numboards'] = $this->db->select("boards")->countQuery()->execute()->fetchField();
     $twigData['stats']['totalposts'] = $this->db->select("posts")->countQuery()->execute()->fetchField();
     $twigData['stats']['edahaversion'] = kxEnv::get("cache:version");
     kxTemplate::output("manage/index", $twigData);
 }
Beispiel #2
0
 private function _getMenu($savetofile = false, $option = false)
 {
     //$twigData['boardpath'] = getCLBoardPath();
     $twigData['styles'] = explode(':', kxEnv::Get('kx:css:menustyles'));
     if ($savetofile) {
         $file = 'menu.html';
     } else {
         $file = 'menu.php';
     }
     $twigData['file'] = $file;
     $sections = array();
     $boardsExist = $this->db->select("boards")->fields("boards")->countQuery()->execute()->fetchField();
     if ($boardsExist) {
         $sections = $this->db->select("sections")->fields("sections")->orderBy("section_order")->execute()->fetchAll();
         $results = $this->db->select("boards")->fields("boards", array("board_order", "board_name", "board_desc", "board_locked", "board_trial", "board_popular"))->where("section = ?")->orderBy("board_order")->orderBy("board_name")->build();
         foreach ($sections as $key => $section) {
             $results->execute(array($section['id']));
             $boards = $results->fetchAll();
             $sections[$key]['boards'] = $boards;
         }
     }
     $twigData['boards'] = $sections;
     if ($savetofile) {
         file_put_contents(KX_ROOT . '/menu.html', kxTemplate::get('menu', $twigData));
         return true;
     } else {
         return kxTemplate::get('menu', $twigData);
     }
 }
Beispiel #3
0
 public static function init($template_dir = null, $compiled_dir = null, $cache_dir = null)
 {
     if (self::$instance == null) {
         //echo "<p>init() called!</p>";
         if ($template_dir != null) {
             self::$template_dir = $template_dir;
         } else {
             self::$template_dir = KX_ROOT . kxEnv::get("kx:templates:dir");
         }
         $loader = new Twig_Loader_Filesystem(self::$template_dir);
         if ($cache_dir == null) {
             $cache_dir = KX_ROOT . kxEnv::get("kx:templates:cachedir");
         }
         self::$instance = new Twig_Environment($loader, array('cache' => $cache_dir, 'auto_reload' => true, 'debug' => true));
         // Load our extensions
         self::$instance->addExtension(new Twig_Extensions_Extension_I18n());
         self::$instance->addExtension(new Twig_Extensions_Extension_kxEnv());
         self::$instance->addExtension(new Twig_Extensions_Extension_DateFormat());
         self::$instance->addExtension(new Twig_Extensions_Extension_Text());
         self::$instance->addExtension(new Twig_Extensions_Extension_Round());
         self::$instance->addExtension(new Twig_Extensions_Extension_Strip());
         self::$instance->addExtension(new Twig_Extensions_Extension_Debug());
         self::$instance->addExtension(new Twig_Extensions_Extension_PHP());
         // Supply Twig with our GET/POST variables
         self::$data['_get'] = $_GET;
         self::$data['_post'] = $_POST;
         // Supply Twig with the default locale
         self::$data['locale'] = kxEnv::Get('kx:misc:locale');
         // Are we in manage? Load up the manage wrapper
         if (IN_MANAGE) {
             self::$data['current_app'] = "";
             if (KX_CURRENT_APP == "core") {
                 // Load up some variables for tabbing/menu purposes
                 if (isset(kxEnv::$request['app'])) {
                     self::$data['current_app'] = kxEnv::$request['app'];
                 }
             } else {
                 if (KX_CURRENT_APP == "board") {
                     if (kxEnv::$current_module == "posts") {
                         self::$data['current_app'] = "posts";
                     } else {
                         self::$data['current_app'] = "board";
                     }
                 }
             }
             $baseurl = kxEnv::Get('kx:paths:main:path') . '/manage.php?sid=' . (isset(kxEnv::$request['sid']) ? kxEnv::$request['sid'] : '') . '&';
             self::$data['base_url'] = $baseurl;
             // Get our manage username
             if (isset(kxEnv::$request['sid'])) {
                 $result = kxDB::getinstance()->select('staff', 'stf')->fields('stf', array('user_name'));
                 $result->innerJoin("manage_sessions", "ms", "ms.session_staff_id = stf.user_id");
                 self::assign('name', $result->condition('session_id', kxEnv::$request['sid'])->execute()->fetchField());
             }
         }
         // else {
         //	die('Not IN_MANAGE!');
         //}
     }
 }
Beispiel #4
0
 public function loginValidate()
 {
     // Remove old login attempts
     $this->db->delete("loginattempts")->condition("attempt_time", time() - 1200, "<")->execute();
     // Are we locked out still?
     $results = $this->db->select("loginattempts")->fields("loginattempts", array("attempt_ip"))->condition("attempt_ip", $_SERVER['REMOTE_ADDR'])->execute()->fetchAll();
     if (count($results) > 5) {
         kxFunc::showError(_gettext('System lockout'), _gettext('Sorry, because of your numerous failed logins, you have been locked out from logging in for 20 minutes. Please wait and then try again.'));
     } else {
         // Find users with the username supplied to us
         $results = $this->db->select("staff")->fields("staff", array("user_id", "user_name", "user_password", "user_salt"))->condition("user_name", $this->request['username'])->execute()->fetchAll();
         if (count($results) > 0) {
             if (md5($this->request['password'] . $results[0]->user_salt) == $results[0]->user_password) {
                 // Let's make our session
                 $session_id = md5(uniqid(microtime()));
                 $this->request['sid'] = $session_id;
                 // Delete any sessions that already exist for this user
                 $this->db->delete("manage_sessions")->condition("session_staff_id", $results[0]->user_id)->execute();
                 // Insert our new values
                 $this->db->insert("manage_sessions")->fields(array('session_id' => $session_id, 'session_ip' => $_SERVER['REMOTE_ADDR'], 'session_staff_id' => $results[0]->user_id, 'session_location' => "index", 'session_log_in_time' => time(), 'session_last_action' => time(), 'session_url' => ""))->execute();
                 // Set the cookies so ajax functions will load
                 $this->SetModerationCookies();
                 //$this->environment->get('kx:classes:core:logging:id')->manageLog(_gettext('Logged in'), 1);
                 // Let's figure out where we need to go
                 $whereto = "";
                 // Unfiltered on purpose
                 if ($_POST['qstring']) {
                     $whereto = stripslashes($_POST['qstring']);
                     $whereto = str_replace(kxEnv::Get('kx:paths:script:path'), "", $whereto);
                     $whereto = str_ireplace("?manage.php", "", $whereto);
                     $whereto = ltrim($whereto, '?');
                     $whereto = preg_replace("/sid=(\\w){32}/", "", $whereto);
                     $whereto = str_replace(array('old_&', 'old_&amp;'), "", $whereto);
                     $whereto = str_replace("module=login", "", $whereto);
                     $whereto = str_replace("do=login-validate", "", $whereto);
                     $whereto = str_replace('&amp;', '&', $whereto);
                     $whereto = preg_replace("/&{1,}/", "&", $whereto);
                 }
                 $url = kxEnv::Get('kx:paths:script:path') . kxEnv::Get('kx:paths:script:folder') . '/manage.php?sid=' . $session_id . '&' . $whereto;
                 if (!empty($_COOKIE['use_frames'])) {
                     $twigData['url'] = $url;
                     kxTemplate::output("manage/frames", $twigData);
                 } else {
                     kxFunc::doRedirect($url, true);
                 }
                 exit;
             } else {
                 $this->db->insert("loginattempts")->fields(array('attempt_name' => $this->request['username'], 'attempt_ip' => $_SERVER['REMOTE_ADDR'], 'attempt_time' => time()))->execute();
                 $this->showForm(_gettext('Incorrect username/password.'));
             }
         } else {
             $this->db->insert("loginattempts")->fields(array('attempt_name' => $this->request['username'], 'attempt_ip' => $_SERVER['REMOTE_ADDR'], 'attempt_time' => time()))->execute();
             $this->showForm(_gettext('Incorrect username/password.'));
         }
     }
 }
Beispiel #5
0
 public function recacheFiletypes()
 {
     // Get all the filetypes...
     $recache_filetypes = $this->db->select("filetypes")->fields("filetypes")->orderBy("type_id")->execute()->fetchAll();
     /*echo '<pre>';
       print_r($recache_filetypes);
       echo '</pre>';*/
     // Cache them
     kxEnv::set('cache:attachments:filetypes', $recache_filetypes);
 }
Beispiel #6
0
 public function exec(kxEnv $environment)
 {
     if (isset($this->request['p'])) {
         switch ($this->request['p']) {
             case 'faq':
                 $type = 1;
                 break;
             case 'rules':
                 $type = 2;
                 break;
         }
     } else {
         $this->request['p'] = '';
         $type = 0;
     }
     $this->twigData['styles'] = explode(':', kxEnv::Get('kx:css:menustyles'));
     $entries = $this->db->select("front")->fields("front")->condition("entry_type", $type);
     if ($this->request['p'] != '') {
         $entries->orderBy("entry_order", "ASC");
     } else {
         $entries->orderBy("entry_time", "DESC");
         if (!isset($this->request['view'])) {
             $entries->range(0, 1);
         }
     }
     $this->twigData['entries'] = $entries->execute()->fetchAll();
     $sections = $this->db->select("sections")->fields("sections")->orderBy("section_order")->execute()->fetchAll();
     $boards = $this->db->select("boards")->fields("boards", array('board_name', 'board_desc'))->where("board_section = ?")->orderBy("board_order")->build();
     // Add boards to an array within their section
     foreach ($sections as $section) {
         $boards->execute(array($section->id));
         $section->boards = $boards->fetchAll();
     }
     $this->twigData['sections'] = $sections;
     // Get recent images
     $images = $this->db->select("post_files");
     $images->innerJoin("posts", "", "post_id = file_post AND post_board = file_board");
     $images = $images->fields("post_files", array("file_name", "file_type", "file_board", "file_thumb_width", "file_thumb_height"))->fields("posts", array("post_id", "post_parent"))->condition("file_name", "", "!=")->orderBy("post_timestamp", "DESC")->range(0, 3)->execute()->fetchAll();
     $i = 0;
     if (count($images) > 0) {
         $results = $this->db->select('boards')->fields('boards', array('board_name'))->where('board_id = ?')->range(0, 1)->build();
         while ($i < count($images)) {
             $results->execute(array($images[$i]->board_id));
             $board = $results->fetchAll();
             $images[$i]->boardname = $board[0]->board_name;
             $i++;
         }
     }
     $this->twigData['images'] = $images;
     kxTemplate::output("index", $this->twigData);
 }
Beispiel #7
0
 public static function initialize($environment, $configdir)
 {
     if (self::$instance instanceof self) {
         return;
     }
     $configuration = array();
     // Load config
     foreach (self::getConfigFiles($configdir) as $configfile) {
         $configuration = array_merge_recursive(array_reduce(array_intersect_key(self::loadConfigFile($configfile), array_flip(array('all', $environment))), array('self', 'mergeWrapper')), $configuration);
     }
     // Set our instance, load kxConfig
     self::$instance = new self($environment, new kxConfig($configuration));
     // Add any classes we want added to the autoloader.
     foreach (kxEnv::get('kx:autoload:load') as $repo => $opts) {
         kxEnv::set(sprintf('kx:autoload:repository:%s:id', $repo), kxAutoload::registerRepository(sprintf('%s/%s/%s', KX_ROOT, 'application/lib', $opts['path']), array('prefix' => $opts['prefix'])));
     }
     // Set up our input, remove any magic quotes
     if (is_array($_POST) and !empty($_POST)) {
         foreach ($_POST as $BUTTER => $TOAST) {
             // Skip arrays
             if (!is_array($TOAST)) {
                 $_POST[$BUTTER] = kxFunc::strip_magic($TOAST);
             }
         }
     }
     // Clean up all of our input (cookies, get/post requests, etc)
     kxFunc::cleanInput($_GET);
     kxFunc::cleanInput($_POST);
     kxFunc::cleanInput($_COOKIE);
     kxFunc::cleanInput($_REQUEST);
     //Okay NOW let's  parse our input
     $input = kxFunc::parseInput($_GET, array());
     // Allow $_POST to overwrite $_GET
     self::$request = kxFunc::parseInput($_POST, $input) + self::$request;
     // Grab our app
     $_application = preg_replace("/[^a-zA-Z0-9\\-\\_]/", "", isset($_REQUEST['app']) && trim($_REQUEST['app']) ? $_REQUEST['app'] : "core");
     // Make sure we get (hopefully) a string
     if (is_array($_application)) {
         $_application = array_shift($_application);
     }
     define('KX_CURRENT_APP', $_application);
     kxEnv::$current_application = KX_CURRENT_APP;
     kxEnv::$current_module = isset(self::$request['module']) ? self::$request['module'] : '';
     kxEnv::$current_section = isset(self::$request['section']) ? self::$request['section'] : '';
     // Cleanup
     kxEnv::$current_module = kxFunc::alphaNum(kxEnv::$current_module);
     kxEnv::$current_section = kxFunc::alphaNum(kxEnv::$current_section);
     // Load the cache
     self::$cache = kxCache::instance();
 }
Beispiel #8
0
 /**
  * Allows adding, editing, and deleting of staff members
  */
 private function _show()
 {
     $twigData = array();
     if ($_GET['act'] == 'add' && $_POST) {
         // Adds a new staff member
         kxForm::addRule('username', 'required')->addRule('pwd1', 'required')->addRule('pwd1', 'value', true, $this->request['pwd2'])->addRule('type', 'numeric')->check();
         $results = $this->db->select("staff")->fields("staff")->condition("user_name", $this->request['username'])->countQuery()->execute()->fetchField();
         if ($results == 0) {
             $salt = substr(md5(time() . kxEnv::Get('kx:misc:randomseed')), -rand(3, 6));
             //$this->_createSalt(); TODO: Decide hashing algorithm, replace current
             $this->db->insert("staff")->fields(array('user_name' => $this->request['username'], 'user_password' => md5($this->request['pwd1'] . $salt), 'user_salt' => $salt, 'user_type' => intval($this->request['type']), 'user_add_time' => time()))->execute();
             $twigData['notice_type'] = 'success';
             $twigData['notice'] = _gettext('User added successfully');
         } else {
             // User with that username already exists
             $twigData['notice_type'] = 'error';
             $twigData['notice'] = _gettext('A user with that username already exists');
         }
     } elseif ($_GET['act'] == 'edit') {
         // Edits a user's information
         kxForm::addRule('id', 'numeric')->check();
         $user = $this->db->select("staff")->fields("staff", array("user_id", "user_name", "user_salt", "user_type"))->condition("user_id", $this->request['id'])->execute()->fetch();
         if ($_POST) {
             kxForm::addRule('pwd1', 'value', true, $this->request['pwd2'])->addRule('type', 'numeric')->check();
             $values = array('user_type' => $this->request['type']);
             if (!empty($this->request['pwd1'])) {
                 $values['user_password'] = md5($this->request['pwd1'] . $user['user_salt']);
             }
             $this->db->update("staff")->fields($values)->condition("user_id", $this->request['id'])->execute();
             $twigData['notice_type'] = 'success';
             $twigData['notice'] = _gettext('User info updated!');
         }
         $twigData['user'] = $user;
     } elseif ($_GET['act'] == 'del') {
         // Deletes a user
         kxForm::addRule('id', 'numeric')->check();
         $user_exists = $this->db->select("staff")->condition("user_id", $this->request['id'])->countQuery()->execute()->fetchField();
         if ($user_exists) {
             $this->db->delete("staff")->condition("user_id", $this->request['id'])->execute();
             $twigData['notice_type'] = 'success';
             $twigData['notice'] = _gettext('User successfully deleted!');
         } else {
             $twigData['notice_type'] = 'error';
             $twigData['notice'] = _gettext('A user with that ID does not exist');
         }
     }
     $staff = $this->db->select("staff")->fields("staff")->orderBy("user_type")->orderBy("user_add_time")->execute()->fetchAll();
     $twigData['staffmembers'] = $staff;
     kxTemplate::output("manage/staff_show", $twigData);
 }
Beispiel #9
0
 public function wordFilter(&$buffer)
 {
     $filters = kxEnv::Get("cache:filters:wordfilters");
     foreach ($filters as $filter) {
         if ((!$filter->filter_boards || in_array($this->environment->get("kx:classes:board:id"), unserialize($filter->filter_boards))) && (!$filter->filter_regex && kxMb::stripos($buffer, $filter->filter_word) !== false) || $filter->filter_regex && preg_match($filter->filter_word, $buffer)) {
             $buffer = $filter->filter_regex == 1 ? preg_replace($filter->filter_word, $filter->filter_replace, $buffer) : str_ireplace($filter->filter_word, $filter->filter_replace, $buffer);
         }
     }
 }
Beispiel #10
0
 public function kxEnvFilter($string)
 {
     return kxEnv::get('kx:' . $string);
 }
Beispiel #11
0
 public function execute($params = array())
 {
     return parent::execute($params);
     if (kxEnv::Get('kx:misc:debug')) {
         $errorinfo = parent::errorInfo();
         echo "<pre>(" . KU_DBTYPE . ") " . self::getSQL($params);
         echo "\nError (" . $errorinfo[0] . ") " . $errorinfo[2] . "\n\n</pre>";
     }
 }
Beispiel #12
0
 /**
  * Format the provided input into a reflink, which follows the Japanese locale if it is set.
  */
 public function formatReflink($post_board, $post_thread_start_id, $post_id, $locale = 'en')
 {
     $return = '	';
     $reflink_noquote = '<a href="' . kxEnv::Get('kx:paths:boards:folder') . $post_board . '/res/' . $post_thread_start_id . '.html#' . $post_id . '" onclick="return highlight(\'' . $post_id . '\');">';
     $reflink_quote = '<a href="' . kxEnv::Get('kx:paths:boards:folder') . $post_board . '/res/' . $post_thread_start_id . '.html#i' . $post_id . '" onclick="return insert(\'>>' . $post_id . '\\n\');">';
     if ($locale == 'ja') {
         $return .= $reflink_quote . kxFunc::formatJapaneseNumbers($post_id) . '</a>' . $reflink_noquote . '?</a>';
     } else {
         $return .= $reflink_noquote . 'No.&nbsp;' . '</a>' . $reflink_quote . $post_id . '</a>';
     }
     return $return . "\n";
 }
Beispiel #13
0
 public static final function openConnection($driver_options)
 {
     $driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
     try {
         $pdo = new PDO_(kxEnv::get('kx:db:dsn', 'mysql:dbname=kusabax;host=localhost'), kxEnv::get('kx:db:username', 'kusabax'), kxEnv::get('kx:db:password', 'kusabax'), $driver_options);
     } catch (PDOException $e) {
         throw new kxPDOException($e->getMessage());
     }
     return $pdo;
 }
Beispiel #14
0
 public function makePost($postData, $post, $files, $ip, $stickied, $locked, $board)
 {
     $timeStamp = time();
     $id = $this->db->insert("posts")->fields(array('post_parent' => $postData['thread_info']['parent'], 'post_board' => $board->board_id, 'post_name' => $post['name'], 'post_tripcode' => $post['tripcode'], 'post_email' => $post['email'], 'post_subject' => $post['subject'], 'post_message' => $post['message'], 'post_password' => $postData['post_fields']['postpassword'], 'post_timestamp' => $timeStamp, 'post_bumped' => $timeStamp, 'post_ip' => kxFunc::encryptMD5($ip, kxEnv::Get('kx:misc:randomseed')), 'post_ip_md5' => md5($ip), 'post_authority' => $postData['user_authority_display'], 'post_tag' => isset($post['tag']) ? $post['tag'] : '', 'post_stickied' => $stickied, 'post_locked' => $locked))->execute();
     if (!$id || kxEnv::Get('kx:db:type') == 'sqlite') {
         // Non-mysql installs don't return the insert ID after insertion, we need to manually get it.
         $id = $this->db->select("posts")->fields("posts", array("post_id"))->condition("post_board", $board->board_id)->condition("post_timestamp", $timeStamp)->condition("post_ip_md5", md5($ip))->range(0, 1)->execute()->fetchField();
     }
     if ($id == 1 && $board->board_start > 1) {
         $this->db->update("posts")->fields(array("id" => $board->board_start))->condition("post_board", $board->board_id)->execute();
         $id = $board->board_start;
     }
     if (!empty($files)) {
         foreach ($files as $file) {
             $this->db->insert("post_files")->fields(array('file_post' => $id, 'file_board' => $board->board_id, 'file_md5' => $file['file_md5'], 'file_name' => $file['file_name'], 'file_type' => substr($file['file_type'], 1), 'file_original' => mb_convert_encoding($file['original_file_name'], 'ASCII', 'UTF-8'), 'file_size' => $file['file_size'], 'file_size_formatted' => $file['file_size'], 'file_image_width' => $file['image_w'], 'file_image_height' => $file['image_h'], 'file_thumb_width' => $file['thumb_w'], 'file_thumb_height' => $file['thumb_h']))->execute();
         }
     } else {
         $this->db->insert("post_files")->fields(array('file_post' => $id, 'file_board' => $board->board_id, 'file_md5' => '', 'file_name' => '', 'file_type' => '', 'file_original' => '', 'file_size' => 0, 'file_size_formatted' => '', 'file_image_width' => 0, 'file_image_height' => 0, 'file_thumb_width' => 0, 'file_thumb_height' => 0))->execute();
     }
     return $id;
 }
Beispiel #15
0
 /**
  * Generate the postbox area
  *
  * @param integer $replythread The ID of the thread being replied to.  0 if not replying
  * @param string $postboxnotice The postbox notice
  * @return string The generated postbox
  */
 public function postBox($replythread = 0)
 {
     if (kxEnv::Get('kx:extras:blotter')) {
         $this->twigData['blotter'] = kxFunc::getBlotter();
         $this->twigData['blotter_updated'] = kxFunc::getBlotterLastUpdated();
     }
 }
Beispiel #16
0
<?php

DEFINE('KX_ROOT', realpath(dirname(__FILE__)));
DEFINE('KX_BOARD', KX_ROOT);
DEFINE('KX_SCRIPT', KX_ROOT);
DEFINE('KX_LIB', KX_ROOT . '/application/lib/kx');
// Full path to kx's library files
DEFINE('KUSABA_RUNNING', true);
require_once KX_LIB . "/../Twig/Autoloader.php";
Twig_Autoloader::register();
require_once KX_LIB . '/kxAutoload.class.php';
require_once KX_ROOT . '/application/lib/gettext/gettext.inc.php';
$repository = kxAutoload::registerRepository(KX_LIB, array('prefix' => 'kx'));
// Add the autoloader repository in kx's lib dir, listen only for classes starting with the string 'kx'
kxEnv::initialize('dev', KX_ROOT . '/config');
// Setup the main environment, make it read config files etc, the lots
kxEnv::set('kx:autoload:repository:kx:id', $repository);
// If we want to unload the kx autoloader at some point, store the id here.
// Cleanup global namespace
unset($repository);
Beispiel #17
0
 /**
  * Do execute method
  *
  * @access	protected
  * @param	object	kxCmd reference
  * @return	void
  */
 protected function exec(kxEnv $environment)
 {
     @header("Location: " . kxEnv::Get('kx:paths:main:path') . kxEnv::Get('kx:paths:main:folder'));
 }
Beispiel #18
0
 /**
  * Rebuild a cache using defined $CACHE settings in it's extensions file
  *
  * @param  string  Cache path
  * @param  string  Application
  * @return  @e void
  */
 public static function rebuildCache($path, $app = '')
 {
     $app = kxFunc::alphaNum($app);
     $caches = array();
     if ($app) {
         if ($app == 'base') {
             $caches = self::_implodeConfig(kxEnv::fetchCoreConfig('cache'));
         } else {
             if (isset(kxEnv::$applications[$app]) && !kxFunc::isAppEnabled($app)) {
                 return;
             }
             $caches = self::_implodeConfig(kxEnv::fetchAppConfig($app, 'cache'));
         }
     } else {
         $caches = self::_implodeConfig(kxEnv::fetchCoreConfig('cache'));
         foreach (array_keys($kxEnv::$applications) as $appName) {
             $appCache = self::_implodeConfig(kxEnv::fetchAppConfig($appName, 'cache'));
             if (is_array($appCache)) {
                 $caches = array_merge($caches, $appCache);
             }
         }
     }
     if (isset($caches[$path])) {
         $recacheFile = $caches[$path]['recache_file'];
         if ($recacheFile && is_file($recacheFile)) {
             // If the recache function is in the modules directory, check if we're using a module extender for this module
             if (strpos($recacheFile, '/modules') !== FALSE) {
                 $className = kxFunc::loadModule($recacheFile, $caches[$key]['recache_class']);
             } elseif ($app) {
                 $className = kxFunc::loadHelper($recacheFile, $caches[$key]['recache_class'], $app == 'global' ? 'core' : $app);
             }
             if (!$className) {
                 $className = $caches[$key]['recache_class'];
             }
             $recache = new $className(kxEnv::getInstance());
             if (method_exists($recache, 'makeRegistryShortcuts')) {
                 $recache->makeRegistryShortcuts(kxEnv::getInstance());
             }
             $recache->{$caches}[$path]['recache_function']();
         }
     }
 }
Beispiel #19
0
/**
 * gettext: Looks up message in current domain
 * faketext: same
 */
function _gettext($message)
{
    global $faketext;
    //Ugly hack, if our locale is english, remove $faketext so strings don't get translated
    if (kxEnv::Get('kx:misc:locale') == 'en' && !empty($faketext)) {
        unset($faketext);
    }
    return !empty($faketext[$message]) ? $faketext[$message] : $message;
}
Beispiel #20
0
<?php

DEFINE('IN_MANAGE', false);
include "init.php";
//Load the command resolver
kxCmdResolv::run(kxEnv::getInstance());
exit;
Beispiel #21
0
 public function exec(kxEnv $environment)
 {
     // Before we do anything, let's check if we even have any board info
     if (!$this->request['board']) {
         die;
         kxFunc::doRedirect(kxEnv::Get('kx:paths:main:webpath'));
     }
     // Grabing essential data about the board
     $boardType = $this->db->select("boards")->fields("boards", array("board_type"))->condition("board_name", $this->request['board'])->execute()->fetchField();
     // Uh oh! Someone's being naughty! Silently redirect them to the mainpage if they supply us with a non-existing board.
     if ($boardType === false) {
         kxFunc::doRedirect(kxEnv::Get('kx:paths:main:webpath'));
     }
     //Check against our built-in board types.
     if (in_array($boardType, array(0, 1, 2, 3))) {
         $types = array('image', 'text', 'oekaki', 'upload');
         $module_to_load = $types[$boardType];
     } else {
         $result = $this->db->select("modules")->fields("modules", array("module_variables", "module_directory"))->condition("module_application", 1)->execute()->fetchAll();
         foreach ($result as $line) {
             $varibles = unserialize($line->module_variables);
             if (isset($variables['board_type_id']) && $variables['board_type_id'] == $boardType) {
                 $module_to_load = $line->module_directory;
             }
         }
     }
     // Module loading time!
     $moduledir = kxFunc::getAppDir("board") . '/modules/public/' . $module_to_load . '/';
     if (file_exists($moduledir . $module_to_load . '.php')) {
         require_once $moduledir . $module_to_load . '.php';
     } else {
         kxFunc::doRedirect(kxEnv::Get('kx:paths:main:webpath'));
     }
     // Some routine checks...
     $className = "public_board_" . $module_to_load . "_" . $module_to_load;
     if (class_exists($className)) {
         $module_class = new ReflectionClass($className);
         if ($module_class->isSubClassOf(new ReflectionClass('kxCmd'))) {
             $this->_boardClass = $module_class->newInstance($this->environment);
             $this->_boardClass->execute($this->environment);
         } else {
             kxFunc::doRedirect(kxEnv::Get('kx:paths:main:webpath'));
         }
     } else {
         kxFunc::doRedirect(kxEnv::Get('kx:paths:main:webpath'));
     }
     // Include our posting class
     require_once kxFunc::getAppDir('core') . '/classes/posting.php';
     $this->_postingClass = new posting($this->environment);
     $this->environment->set('kx:classes:board:posting:id', $this->_postingClass);
     // Phew, that's over with. Let's now prepare our post for generation.
     //Are we UTF-8?
     $this->_postingClass->checkUTF8();
     // Is post valid according to our board's spec?
     if ($this->_boardClass->validPost()) {
         $this->db->startTransaction();
         // Do we have files?
         $this->postData['files'] = isset($_FILES['imagefile']) ? $_FILES['imagefile']['name'] : '';
         // Backwards compatability hack for dumpers that don't support multifile uploading
         if ($this->postData['files'] && !is_array($this->postData['files'])) {
             foreach ($_FILES['imagefile'] as $key => $value) {
                 $_FILES['imagefile'][$key] = array($value);
             }
             $this->postData['files'] = array($_FILES['imagefile']['name'][0]);
         }
         $this->postData['is_reply'] = $this->_postingClass->isReply($this->_boardClass->board->board_id);
         $this->_postingClass->checkPostingTime($this->postData['is_reply'], $this->_boardClass->board->board_id);
         $this->_postingClass->checkMessageLength($this->_boardClass->board->max_message_length);
         $this->_postingClass->checkBlacklistedText($this->_boardClass->board->board_id);
         $this->_postingClass->checkCaptcha($this->_boardClass->board, $this->postData);
         $this->_postingClass->checkBannedHash($this->_boardClass->board);
         //How many replies, is the thread locked, etc
         if ($this->postData['is_reply']) {
             $this->postData['thread_info'] = $this->_postingClass->threadInfo($this->_boardClass->board_id, $this->request['replythread']);
         } else {
             $this->postData['thread_info'] = array('replies' => 0, 'locked' => 0, 'parent' => 0);
         }
         // Subject, email, etc fields need special processing
         $this->postData['post_fields'] = $this->_postingClass->parseFields();
         $this->postData['post_fields']['postpassword'] = isset($this->request['postpassword']) ? $this->request['postpassword'] : '';
         $nextid = $this->db->select("posts")->fields("posts", array("post_id"))->condition("post_board", $this->_boardClass->board->board_id)->execute()->fetchField();
         if ($nextid) {
             $this->postData['next_id'] = $nextid + 1;
         } else {
             $this->postData['next_id'] = 1;
         }
         // Are we modposting?
         $this->postData['user_authority'] = $this->_postingClass->userAuthority();
         if (isset($this->request['displaystaffstatus'])) {
             $this->postData['flags'] .= 'D';
         }
         if (isset($this->request['lockonpost'])) {
             $this->postData['flags'] .= 'L';
         }
         if (isset($this->request['stickyonpost'])) {
             $this->postData['flags'] .= 'S';
         }
         if (isset($this->request['rawhtml'])) {
             $this->postData['flags'] .= 'RH';
         }
         if (isset($this->request['usestaffname'])) {
             $this->postData['flags'] .= 'N';
         }
         $this->postData['display_status'] = 0;
         $this->postData['lock_on_post'] = 0;
         $this->postData['sticky_on_post'] = 0;
         // If they are just a normal user, or vip...
         if ($this->postData['user_authority'] == 0 || $this->postData['user_authority'] > 2) {
             // If the thread is locked
             if ($this->postData['thread_info']['locked'] == 1) {
                 // Don't let the user post
                 kxFunc::showError(_gettext('Sorry, this thread is locked and can not be replied to.'));
             }
             $this->postData['thread_info']['message'] = $this->_boardClass->parseData($this->request['message']);
             // Or, if they are a moderator/administrator...
         } else {
             // If they checked the D checkbox, set the variable to tell the script to display their staff status (Admin/Mod) on the post during insertion
             if (isset($this->request['displaystaffstatus'])) {
                 $this->postData['display_status'] = true;
             }
             // If they checked the RH checkbox, set the variable to tell the script to insert the post as-is...
             if (isset($this->request['rawhtml'])) {
                 $this->postData['thread_info']['message'] = $this->request['message'];
                 // Otherwise, parse it as usual...
             } else {
                 $this->postData['thread_info']['message'] = $this->_boardClass->parseData($this->request['message']);
             }
             // If they checked the L checkbox, set the variable to tell the script to lock the post after insertion
             if (isset($this->request['lockonpost'])) {
                 $this->postData['lock_on_post'] = true;
             }
             // If they checked the S checkbox, set the variable to tell the script to sticky the post after insertion
             if (isset($this->request['stickyonpost'])) {
                 $this->postData['sticky_on_post'] = true;
             }
             if (isset($this->request['usestaffname'])) {
                 $_POST['name'] = kxFunc::md5_decrypt($this->request['modpassword'], kxEnv::Get('kx:misc:randomseed'));
                 $post_name = kxFunc::md5_decrypt($this->request['modpassword'], kxEnv::Get('kx:misc:randomseed'));
             }
         }
         //kxFunc::checkBadUnicode($this->postData['post_fields']);
         $this->_boardClass->processPost($this->postData);
         $url = kxEnv::Get("kx:paths:boards:path") . '/' . $this->_boardClass->board->board_name;
         if (!$this->postData['is_reply']) {
             $url .= '/' . kxEnv::Get('kx:pages:first');
         } else {
             $url .= '/res/' . intval($this->request['replythread']) . '.html';
         }
         @header('Location: ' . $url);
     }
 }
Beispiel #22
0
 public static function UpdateHtaccess()
 {
     $htaccess_contents = file_get_contents(KX_BOARD . '.htaccess');
     $htaccess_contents_preserve = substr($htaccess_contents, 0, strpos($htaccess_contents, '## !KU_BANS:') + 12) . "\n";
     $htaccess_contents_bans_iplist = '';
     $results = $kx_db->GetAll("SELECT `ip` FROM `" . kxEnv::Get('kx:db:prefix') . "banlist` WHERE `allowread` = 0 AND `type` = 0 AND (`expired` =  1) ORDER BY `ip` ASC");
     if (count($results) > 0) {
         $htaccess_contents_bans_iplist .= 'RewriteCond %{REMOTE_ADDR} (';
         foreach ($results as $line) {
             $htaccess_contents_bans_iplist .= str_replace('.', '\\.', md5_decrypt($line['ip'], kxEnv::Get('kx:misc:randomseed'))) . '|';
         }
         $htaccess_contents_bans_iplist = substr($htaccess_contents_bans_iplist, 0, -1);
         $htaccess_contents_bans_iplist .= ')$' . "\n";
     }
     if ($htaccess_contents_bans_iplist != '') {
         $htaccess_contents_bans_start = "<IfModule mod_rewrite.c>\nRewriteEngine On\n";
         $htaccess_contents_bans_end = "RewriteRule !^(banned.php|youarebanned.jpg|favicon.ico|css/site_futaba.css)\$ " . kxEnv::Get('kx:paths:boards:folder') . "banned.php [L]\n</IfModule>";
     } else {
         $htaccess_contents_bans_start = '';
         $htaccess_contents_bans_end = '';
     }
     $htaccess_contents_new = $htaccess_contents_preserve . $htaccess_contents_bans_start . $htaccess_contents_bans_iplist . $htaccess_contents_bans_end;
     file_put_contents(KX_BOARD . '.htaccess', $htaccess_contents_new);
 }