function ThreadViewIndexBarReadPosting(&$_posting, $_prev_posting_id, $_next_posting_id, $_prev_thread_id, $_next_thread_id)
 {
     $this->Menu();
     if (!$_posting) {
         $this->add_separator();
         return;
     }
     $url = new FreechURL();
     $url->set_var('action', 'read');
     $url->set_var('msg_id', 1);
     $url->set_var('forum_id', $_posting->get_forum_id());
     // "Previous/Next Posting" buttons.
     if ($_prev_posting_id) {
         $url->set_var('msg_id', $_prev_posting_id);
         $url->set_label('<<');
         $this->add_link($url);
     } else {
         $this->add_text('<<');
     }
     $this->add_text(_('Message'));
     if ($_next_posting_id) {
         $url = clone $url;
         $url->set_var('msg_id', $_next_posting_id);
         $url->set_label('>>');
         $this->add_link($url);
     } else {
         $this->add_text('>>');
     }
     // "Previous Thread" button.
     $this->add_separator();
     if (cfg('thread_arrow_reverse')) {
         $prev_id = $_next_thread_id;
     } else {
         $prev_id = $_prev_thread_id;
     }
     if ($prev_id) {
         $url = clone $url;
         $url->set_var('msg_id', $prev_id);
         $url->set_label('<<');
         $this->add_link($url);
     } else {
         $this->add_text('<<');
     }
     // "Next Thread" button.
     $this->add_text(_('Thread'));
     $url = clone $url;
     if (cfg('thread_arrow_reverse')) {
         $next_id = $_prev_thread_id;
     } else {
         $next_id = $_next_thread_id;
     }
     if ($next_id) {
         $url = clone $url;
         $url->set_var('msg_id', $next_id);
         $url->set_label('>>');
         $this->add_link($url);
     } else {
         $this->add_text('>>');
     }
 }
예제 #2
0
 /**
  * 初始化,并设置是否启用自动登录
  * @param bool $auto_login
  */
 function __construct($auto_login = false)
 {
     $this->ck = new \CLib\Cookie(cfg()->get('cookie', 'encode'));
     if ($auto_login) {
         $this->auto_login();
     }
 }
예제 #3
0
파일: Db.php 프로젝트: bozhich/PHP-on-Rails
 /**
  * @param        $host
  * @param        $user
  * @param        $pass
  * @param        $name
  * @param string $driver
  */
 public function __construct($host, $user, $pass, $name, $driver = 'pgsql')
 {
     try {
         parent::__construct($driver . ':dbname=' . $name . ';host=' . $host, $user, $pass);
     } catch (Exception $e) {
         if (!cfg()->dev_mode && Core_Request::getInstance()->getRoute('module') == 'default') {
             $view = Core_View::getInstance();
             $view->setLayoutFile('$maintenance/db_connect.phtml');
             $view->displayLayout();
             die;
         } else {
             print get_class($e) . ': ' . $e->getMessage() . PHP_EOL;
             die;
         }
     }
     if (cfg()->dev_mode) {
         $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } else {
         $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
     }
     $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Core_Db_Statement', array($this)));
     if (cfg()->dev_mode) {
         //			Core_Debug::getInstance()->initPdoDebug($this);
     }
 }
예제 #4
0
 public function read()
 {
     $list = cfg('resources', 'models', $this->name);
     $rels = array('collection', 'model');
     $data = array();
     $pack = array();
     foreach ($list as $model) {
         $cname = \System\Loader::get_class_from_model($model);
         $model = \System\Loader::get_model_from_class($model);
         $schema = $cname::get_visible_schema($this->request->user);
         foreach ($schema['attrs'] as $attr) {
             if (in_array($attr['type'], $rels)) {
                 $rel_cname = \System\Loader::get_class_from_model($attr['model']);
                 $rel_model = \System\Loader::get_model_from_class($attr['model']);
                 if (!array_key_exists($rel_model, $pack)) {
                     $pack[$rel_model] = $rel_cname::get_visible_schema($this->request->user);
                 }
             }
         }
         $pack[$model] = $schema;
     }
     foreach ($pack as $name => $def) {
         $data[] = array("name" => $name, "parents" => array('model'), "static" => $def);
     }
     $this->content = json_encode(array("data" => $data));
 }
예제 #5
0
파일: show.php 프로젝트: just-paja/fudjan
 public function run()
 {
     try {
         $this->req('ident');
     } catch (\System\Error\Argument $e) {
         $this->req('id');
     }
     def($this->template, 'system/text/show');
     def($this->show_heading, true);
     $conds = array();
     if (isset($ident)) {
         $conds['ident'] = $ident;
     } else {
         $conds['id_system_text'] = $id;
     }
     if ($text = \System\Text::get_first($conds)->fetch()) {
         $this->partial($template, array("text" => $text, "show_heading" => $show_heading));
     } else {
         if (cfg('dev', 'debug', 'backend')) {
             throw new \System\Error\Config('Text was not found', isset($ident) ? $ident : $id);
         } else {
             throw new \System\Error\NotFound();
         }
     }
 }
예제 #6
0
 /**
  * @param $timestamp
  * @return bool|int|string
  */
 public static function TimestampToDate($timestamp)
 {
     if ($timestamp > 0) {
         return date(cfg()->date_format, $timestamp);
     }
     return 0;
 }
예제 #7
0
파일: module.php 프로젝트: alex-k/velotur
 function content($ret)
 {
     $tpl = gs_tpl::get_instance();
     $tpl->addTemplateDir(cfg('document_root') . DIRECTORY_SEPARATOR . 'content');
     $this->params['name'] = $this->data['gspgid_v'];
     return $this->show($ret);
 }
예제 #8
0
 private function showViewDialog()
 {
     // Only show when map name given
     if (!isset($this->url) || $this->url == '') {
         throw new NagVisException(l('No url given.'));
     }
     // Build index template
     $INDEX = new NagVisIndexView($this->CORE);
     // Need to parse the header menu?
     if (cfg('index', 'headermenu')) {
         // Parse the header menu
         $HEADER = new NagVisHeaderMenu(cfg('index', 'headertemplate'));
         // Put rotation information to header menu
         if ($this->rotation != '') {
             $HEADER->setRotationEnabled();
         }
         $INDEX->setHeaderMenu($HEADER->__toString());
     }
     // Initialize map view
     $this->VIEW = new NagVisUrlView($this->CORE, $this->url);
     // Maybe it is needed to handle the requested rotation
     if ($this->rotation != '') {
         $ROTATION = new FrontendRotation($this->rotation);
         $ROTATION->setStep('url', $this->url, $this->rotationStep);
         $this->VIEW->setRotation($ROTATION->getRotationProperties());
     }
     $INDEX->setContent($this->VIEW->parse());
     return $INDEX->parse();
 }
예제 #9
0
 /**
  *
  */
 public function indexAction()
 {
     die('todo');
     $overwrite = !is_null(Core_Request::getInstance()->getArgv(4)) ? Core_Request::getInstance()->getArgv(4) : false;
     foreach (dibi::getDatabaseInfo()->getTables() as $table_data) {
         if ($table_data->getName() == Migration_MigrationModel::getTableName()) {
             continue;
         }
         $ddl_data = dibi::query('SHOW CREATE TABLE ' . $table_data->getName())->fetch()->toArray();
         $ddl_query = $ddl_data['Create Table'];
         $migration_time = time();
         $migration_name = 'Create' . ucfirst($table_data->getName());
         $migration_name = str_replace(' ', '', $migration_name);
         $migration_name = str_replace('-', '', $migration_name);
         $migration_name = str_replace('_', '', $migration_name);
         $filename = cfg()->migration_path . $migration_name . '.php';
         if (Core_Files::fileSize($filename) && !$overwrite) {
             echo PHP_EOL . 'Migration "Create ' . ucfirst($table_data->getName()) . '" Exists' . PHP_EOL;
             continue;
         }
         $template_data = Core_Files::getContent(cfg()->migration_path . Migration_FilesHelper::TEMPLATE_FILE_NAME);
         $template_data = str_replace('Template', $migration_name, $template_data);
         $template_data = str_replace('__NAME__', $migration_name, $template_data);
         $template_data = str_replace('__CREATED_AT__', $migration_time, $template_data);
         $template_data = str_replace('__CREATED_CFG__', Core_Request::getInstance()->getArgv(1), $template_data);
         $template_data = preg_replace('#//__UP_ACTION__#', $ddl_query, $template_data);
         $down_query = 'DROP TABLE IF EXISTS `' . $table_data->getName() . '`';
         $template_data = preg_replace('#//__DOWN_ACTION__#', $down_query, $template_data);
         Core_Files::putContent($filename, $template_data);
         echo PHP_EOL . 'Migration ' . $filename . ' created' . PHP_EOL;
     }
 }
예제 #10
0
 /**
  * @param $data
  * @return bool|string
  * @throws Exception
  * @throws phpmailerException
  */
 public static function send($data)
 {
     $mail = new PHPMailer();
     if (cfg()->is_smtp) {
         $mail->IsSMTP();
         // set mailer to use SMTP
     }
     $mail->Host = cfg()->smtp_host;
     $mail->Port = cfg()->smtp_port;
     $mail->SMTPAuth = cfg()->smtp_auth;
     // turn on SMTP authentication
     $mail->Username = cfg()->mail_user;
     // SMTP username
     $mail->Password = cfg()->mail_password;
     // SMTP password
     $mail->From = $data['from_email'];
     $mail->FromName = $data['from_name'];
     $mail->AddAddress($data['to_mail']);
     $mail->SetFrom($data['from_email'], $data['from_name']);
     $mail->AddReplyTo($data['from_email'], $data['from_name']);
     //$mail->SMTPDebug = 10;
     //$mail->SMTPSecure = 'tls';
     $mail->WordWrap = cfg()->mail_world_warp;
     // set word wrap to 50 characters
     $mail->IsHTML(cfg()->is_html);
     // set email format to HTML
     $mail->Subject = $data['subject'];
     $mail->Body = $data['message_html'];
     if (!$mail->Send()) {
         return $mail->ErrorInfo;
     }
     return true;
 }
예제 #11
0
 private function showViewDialog()
 {
     // Build index template
     $INDEX = new NagVisIndexView($this->CORE);
     // Need to parse the header menu?
     if (cfg('index', 'headermenu')) {
         // Parse the header menu
         $HEADER = new NagVisHeaderMenu(cfg('index', 'headertemplate'));
         // Put rotation information to header menu
         if ($this->rotation != '') {
             $HEADER->setRotationEnabled();
         }
         $INDEX->setHeaderMenu($HEADER->__toString());
     }
     // Initialize overview view
     $this->VIEW = new NagVisOverviewView($this->CORE);
     // Maybe it is needed to handle the requested rotation
     if ($this->rotation != '') {
         $ROTATION = new FrontendRotation($this->rotation);
         $ROTATION->setStep('overview', '', $this->rotationStep);
         $this->VIEW->setRotation($ROTATION->getRotationProperties());
     }
     $INDEX->setContent($this->VIEW->parse());
     return $INDEX->parse();
 }
예제 #12
0
 function get_quoted_text($_depth = 1)
 {
     if ($this->depth + $_depth == 0) {
         return trim($this->text);
     }
     $text = '';
     $prefix .= str_repeat('> ', $this->depth + $_depth);
     $maxlen = max(45, cfg('max_linelength') - strlen($prefix));
     foreach (explode("\n", $this->text) as $paragraph) {
         $paragraph = wordwrap($paragraph, $maxlen, " \n");
         foreach (explode("\n", $paragraph) as $line) {
             if (!$line) {
                 continue;
             }
             if (strlen($line) > $maxlen + 2) {
                 $line = wordwrap($line, $maxlen, "\t\n", TRUE);
                 $lines = explode("\n", trim($line));
                 $line = implode("\n" . $prefix, $lines);
             }
             $text .= $prefix . $line . "\n";
         }
         $text = trim($text) . "\n";
     }
     return trim($text);
 }
예제 #13
0
 /**
  *
  */
 public function indexAction()
 {
     $argv = $this->getRequest()->getServer('argv');
     $test_to_run = isset($argv[3]) ? $argv[3] : Const_Tests::RUN_ALL_TESTS;
     $test_to_run = str_replace('_', '/', $test_to_run);
     foreach (Core_Files::listFiles(cfg()->tests_path) as $test) {
         if (!strstr($test, $test_to_run . '.php') && $test_to_run != Const_Tests::RUN_ALL_TESTS) {
             continue;
         }
         $class_path = str_replace(cfg()->tests_path, '', $test);
         $class_path_frag = explode('/', $class_path);
         $class_path_frag = array_map("ucfirst", $class_path_frag);
         $class_path_frag[count($class_path_frag) - 1] = str_replace('.php', '', $class_path_frag[count($class_path_frag) - 1]);
         $class = implode('_', $class_path_frag);
         $class_name = 'Tests_' . $class . 'File';
         echo '--------------------------------------' . PHP_EOL;
         echo 'Running test: ' . $class_name . PHP_EOL;
         echo '--------------------------------------' . PHP_EOL;
         $phpunit = new PHPUnit_TextUI_TestRunner();
         $phpunit->run($phpunit->getTest($class_name, $test), array('colors' => 'auto'));
         if ($test_to_run != Const_Tests::RUN_ALL_TESTS) {
             die;
         }
         echo PHP_EOL . PHP_EOL;
     }
     die;
 }
예제 #14
0
 /**
  * @param bool $return
  * @return array
  */
 public static function check($return = false)
 {
     $must_migrate = false;
     $return_data = array();
     foreach (Core_Files::listFiles(cfg()->migration_path) as $migration_file) {
         if (strstr($migration_file, self::TEMPLATE_NAME)) {
             continue;
         }
         $migration_data = explode(DS, $migration_file);
         list($migration_file_name) = array_reverse($migration_data);
         list($migration_name, $extension) = explode('.', $migration_file_name);
         $migration_class_name = self::MIGRATION_PREFIX . $migration_name . self::MIGRATION_SUFIX;
         /* @var $migration_object Core_Migration_Abstract */
         $migration_object = new $migration_class_name();
         if ($migration_object->check()) {
             $must_migrate = true;
             if ($return) {
                 $return_data[] = $migration_file_name;
             } else {
                 echo 'TO RUN: ' . $migration_file_name . PHP_EOL;
             }
         }
     }
     if (!$must_migrate) {
         if (!$return) {
             echo 'DB is UP TO DATE' . PHP_EOL;
         }
     }
     if ($return) {
         return $return_data;
     }
 }
예제 #15
0
파일: Home.php 프로젝트: ttym7993/Linger
 public function sql_error()
 {
     if (db()->status()) {
         $this->not_found();
     } else {
         $this->__view("Home/sql_error.php", ['msg' => db()->ex_message(), 'email' => cfg()->get('mail', 'From')]);
     }
 }
예제 #16
0
 /** Get default language, if settings fail, skip
  * @return string
  */
 public static function get_default_timezone()
 {
     try {
         return cfg('locales', 'timezone');
     } catch (\System\Error\Config $e) {
         return self::TZ_DEFAULT;
     }
 }
예제 #17
0
 function __construct()
 {
     parent::__construct();
     $this->info_data = cfg()->load(_RootPath_ . "/config/base_info.php");
     if (!login_class()->is_login()) {
         redirect(['Home', 'login']);
     }
 }
예제 #18
0
 /**
  * @throws Exception
  */
 protected function loadCfg()
 {
     if (PHP_SAPI != 'cli') {
         p404('only cli');
     }
     $match_id = $this->getRequest()->getArgv(1);
     cfg()->load($match_id, Core_Cfg::MATCH_TYPE_ID);
 }
예제 #19
0
 public function parse($orig_name)
 {
     global $CORE;
     ob_start();
     if (is_action()) {
         try {
             $name = post('name');
             if (!$name) {
                 throw new FieldInputError('name', l('Please provide a map name.'));
             }
             if (!preg_match(MATCH_MAP_NAME, $name)) {
                 throw new FieldInputError('name', l('This is not a valid map name (need to match [M])', array('M' => MATCH_MAP_NAME)));
             }
             if (count($CORE->getAvailableMaps('/^' . $name . '$/')) > 0) {
                 throw new FieldInputError('name', l('A map with this name already exists.'));
             }
             // Read the old config
             $MAPCFG = new GlobalMapCfg($orig_name);
             $MAPCFG->readMapConfig();
             // Create a new map config
             $NEW = new GlobalMapCfg($name);
             $NEW->createMapConfig();
             foreach ($MAPCFG->getMapObjects() as $object_id => $cfg) {
                 $NEW->addElement($cfg['type'], $cfg, $perm = true, $object_id);
             }
             success(l('The map has been created.'));
             reload(cfg('paths', 'htmlbase') . '/frontend/nagvis-js/index.php?mod=Map&show=' . $name, 1);
         } catch (FieldInputError $e) {
             form_error($e->field, $e->msg);
         } catch (NagVisException $e) {
             form_error(null, $e->message());
         } catch (Exception $e) {
             if (isset($e->msg)) {
                 form_error(null, $e->msg);
             } else {
                 throw $e;
             }
         }
     }
     echo $this->error;
     echo '<div class="simple_form">' . N;
     js_form_start('to_new_map');
     input('name');
     submit(l('Save'));
     focus('name');
     // Keep the view parameters the users has set
     $params = ltrim(req('view_params'), '&');
     if ($params) {
         $parts = explode('&', $params);
         foreach ($parts as $part) {
             list($key, $val) = explode('=', $part);
             hidden($key, $val);
         }
     }
     form_end();
     echo '</div>' . N;
     return ob_get_clean();
 }
예제 #20
0
 /**
  * 构造函数
  * @param string $path 对应的模板文件名称
  * @throws \Exception 模板有误的错误信息
  */
 public function __construct($path)
 {
     $path = cfg()->get('mail_template') . "/" . trim($path);
     if (is_file($path) && is_readable($path)) {
         $this->content = $this->get_template($path);
     } else {
         throw new \Exception(_("Template is not exists."));
     }
 }
예제 #21
0
 public function parse($e)
 {
     global $CORE;
     $INDEX = new NagVisIndexView($CORE);
     $HEADER = new NagVisHeaderMenu(cfg('index', 'headertemplate'));
     $INDEX->setHeaderMenu($HEADER->__toString());
     $INDEX->setContent($this->errorPage($e));
     return $INDEX->parse();
 }
예제 #22
0
파일: view.php 프로젝트: neoisldl/Onion
 private function __construct(array $config = null)
 {
     if (!($config = $config ?: cfg('app', 'view'))) {
         throw new Error('Invalid View config');
     }
     foreach ($config as $key => $val) {
         $this->{$key} = $val;
     }
 }
예제 #23
0
 function __construct()
 {
     c_lib()->load('sql');
     $this->driver = new Sql(cfg()->get('database'));
     if (!$this->driver->status()) {
         define('HAS_RUN_ERROR', true);
         cfg()->set('HAS_RUN_ERROR', $this->driver->ex_message());
     }
 }
예제 #24
0
파일: perm.php 프로젝트: just-paja/fudjan
 /** Get default config for this action
  * @param string $method One of permission method constants
  * @return bool
  */
 public static function get_default_for($method)
 {
     try {
         $res = cfg('api', 'allow', $method);
     } catch (\System\Error\Config $e) {
         throw new \System\Error\Argument('Unknown permission method type.', $method);
     }
     return !!$res;
 }
예제 #25
0
 /**
  * @return PDO
  */
 protected static function getDb()
 {
     if (!isset(self::$instance)) {
         self::$instance = new PDO('mysql:host=' . cfg()->db_log['host'] . ';dbname=' . cfg()->db_log['name'], cfg()->db_log['user'], cfg()->db_log['pass']);
         self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
         self::$instance->query('SET NAMES utf8');
     }
     return self::$instance;
 }
예제 #26
0
 public function __construct()
 {
     $sDomain = cfg('global', 'sesscookiedomain');
     $sPath = cfg('global', 'sesscookiepath');
     $iDuration = cfg('global', 'sesscookieduration');
     $bSecure = cfg('global', 'sesscookiesecure') == 1;
     $bHTTPOnly = cfg('global', 'sesscookiehttponly') == 1;
     // Set the session name (used in params/cookie names)
     session_name(SESSION_NAME);
     // Only add the domain when it is no simple hostname
     // This can be easily detected searching for a dot
     if (strpos($sDomain, '.') === false) {
         $sDomain = null;
     }
     // Opera has problems with ip addresses in domains. So skip them
     if (strpos($_SERVER['HTTP_USER_AGENT'], 'opera') !== false && preg_match('/\\d.\\d+.\\d+.\\d+/', $sDomain)) {
         $sDomain = null;
     }
     // Set custom params for the session cookie
     if (version_compare(PHP_VERSION, '5.2') >= 0) {
         session_set_cookie_params(0, $sPath, $sDomain, $bSecure, $bHTTPOnly);
     } else {
         session_set_cookie_params(0, $sPath, $sDomain, $bSecure);
     }
     // Start a session for the user when not started yet
     if (!isset($_SESSION)) {
         try {
             session_start();
             // Write/close to release the lock aquired by session_start().
             // Each write to the session needs to perform session_start() again
             session_write_close();
         } catch (ErrorException $e) {
             // Catch and suppress session cleanup errors. This is a problem
             // especially on current debian/ubuntu:
             //   PHP error in ajax request handler: Error: (8) session_start():
             //   ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13)
             if (strpos($e->getMessage(), 'ps_files_cleanup_dir') === false) {
                 throw $e;
             }
         }
         // Store the creation time of the session
         if (!$this->issetAndNotEmpty('sessionExpires')) {
             $this->set('sessionExpires', time() + $iDuration);
         }
     }
     // Reset the expiration time of the session cookie
     if (isset($_COOKIE[SESSION_NAME])) {
         // Don't reset the expiration time on every page load - only reset when
         // the half of the expiration time has passed
         if (time() >= $this->get('sessionExpires') - $iDuration / 2) {
             $exp = time() + $iDuration;
             setcookie(SESSION_NAME, $_COOKIE[SESSION_NAME], $exp, $sPath, $sDomain, $bSecure, $bHTTPOnly);
             // Store the update time of the session cookie
             $this->set('sessionExpires', $exp);
         }
     }
 }
예제 #27
0
 /**
  * @return string
  */
 public function checkSelfTable()
 {
     if (cfg()->db_driver == 'pgsql') {
         list($schema, $table) = explode('.', self::$table);
     } else {
         list($schema, $table) = array('.', self::$table);
     }
     return $this->checkTableExist($schema, $table);
 }
예제 #28
0
 private function setConfig()
 {
     $cfg = hook()->apply("Mail_setConfig", cfg()->get('mail'));
     foreach ($cfg as $name => $value) {
         if (isset($this->{$name})) {
             $this->{$name} = $value;
         }
     }
 }
예제 #29
0
 /**
  * 生成数据库设置信息
  */
 public function __construct()
 {
     $list = db()->select("setting", array('name', 'value'), array('auto' => 1));
     $rt = array();
     foreach ($list as $v) {
         $rt[$v['name']] = $v['value'];
     }
     cfg()->set(array('s_g'), $rt);
 }
예제 #30
0
 /**
  * PUBLIC parseJson()
  * Parses the object in json format
  */
 public function parseJson()
 {
     // Prepare the URL attribute. If it is an absolute url, leave it as it is
     // If it is a simple filename add the url to the scripts path
     $parts = parse_url($this->url);
     if (!isset($parts['scheme']) && $parts['path'][0] !== '/') {
         $this->url = cfg('paths', 'htmlbase') . '/userfiles/scripts/' . $this->url;
     }
     return parent::parseJson();
 }