public function loadClass($class_name)
 {
     $debug = $this->getSandbox()->isDebug();
     $class_name = us($class_name);
     $class_paths = self::$class_paths;
     // フレームワークのクラスではない場合はFALSEを返却
     if (!isset($class_paths[$class_name])) {
         //            log_info( "system,debug,class_loader", "class_loader", "[FrameworkClassLoader] Can not load class: [$class_name]" );
         if ($debug) {
             echo "Class NOT found in framework class loader: {$class_name}" . eol();
         }
         return FALSE;
     }
     // クラス名からクラスパスを取得
     $file_name = $class_name . '.class.php';
     $pos = strpos($file_name, 'Charcoal_');
     if ($pos !== FALSE) {
         $file_name = substr($file_name, $pos + 9);
     }
     $class_path = CHARCOAL_HOME . '/src/' . $class_paths[$class_name] . '/' . $file_name;
     //        log_info( "system,debug,class_loader", "class_loader", "[FrameworkClassLoader] class_path=[$class_path] class_name=[$class_name]" );
     // ソース読み込み
     Charcoal_Framework::loadSourceFile($class_path);
     if ($debug) {
         echo "Class found in framework class loader: {$class_name}" . eol();
     }
     return TRUE;
 }
 /**
  *  load config
  *
  * @param  string|Charcoal_String $key                  config key
  *
  * @return mixed   configure data
  */
 public function loadConfig($key)
 {
     //        Charcoal_ParamTrait::validateString( 1, $key );
     $source = $key . '.ini';
     $is_debug = b($this->debug)->isTrue();
     $result = NULL;
     if (!is_file($source)) {
         if ($is_debug) {
             print "ini file[{$source}] does not exist." . eol();
             log_warning("system, debug, config", "config", "ini file[{$source}] does not exist.");
         }
     } else {
         // read ini file
         $result = @parse_ini_file($source, TRUE);
         if ($is_debug) {
             print "[{$source}] parse_ini_file({$source})=" . eol();
             ad($result);
             if ($result === FALSE) {
                 print "parse_ini_file failed: [{$source}]" . eol();
                 log_warning("system, debug, config", "config", "parse_ini_file failed: [{$source}]");
             } else {
                 log_debug("system, debug, config", "config", "read ini file[{$source}]:" . print_r($result, true));
             }
         }
     }
     return $result;
 }
Exemplo n.º 3
0
 protected function _element($data = '', $tab = '', $start = 0)
 {
     static $start;
     $eof = eol();
     $output = '';
     $attrs = '';
     $tab = str_repeat("\t", $start);
     if (!is_array($data)) {
         return $data . $eof;
     } else {
         foreach ($data as $k => $v) {
             if (is_numeric($k)) {
                 $k = 'li';
             }
             $end = "/" . Arrays::getFirst(explode(' ', $k));
             if (!is_array($v)) {
                 $output .= "{$tab}<{$k}>{$v}<{$end}>{$eof}";
             } else {
                 $output .= $tab . "<{$k}>{$eof}" . $this->_element($v, $tab, $start++) . $tab . "<{$end}>" . $tab . $eof;
                 $start--;
             }
         }
     }
     return $output;
 }
Exemplo n.º 4
0
 /**
  * execute tests
  */
 public function test($action, $context)
 {
     $request = $context->getRequest();
     $action = us($action);
     // Qdmail
     $qdmail = $context->getComponent('qdmail@:qdmail');
     $config = new Charcoal_Config($this->getSandbox()->getEnvironment());
     $config->set('qdsmtp.host', 'localhost');
     $config->set('qdsmtp.port', '25');
     $config->set('qdsmtp.from', '*****@*****.**');
     $config->set('qdsmtp.protocol', 'SMTP');
     $config->set('qdsmtp.user', '');
     $config->set('qdsmtp.pass', '');
     $qdmail->configure($config);
     switch ($action) {
         // Send mail
         case "send_mail":
             $to = $request->get("to");
             $from = "*****@*****.**";
             $subject = "test";
             $body = "test!!!";
             echo "to:" . $to . eol();
             $qdmail->sendMail($from, $to, $subject, $body);
             break;
     }
 }
Exemplo n.º 5
0
 public function data($string = '', $data = array())
 {
     // Parametre konrolleri sağlanıyor.
     if (!is_string($string)) {
         return Error::set('Error', 'stringParameter', 'string');
     }
     $eol = eol();
     // Veri dizisi boş değilse işlemleri gerçekleştir.
     if (!empty($data)) {
         $space = '\\s*';
         $all = '.*';
         foreach ($data as $key => $val) {
             // Eleman dizi değilse değiştirme işlemi gerçekleştir.
             if (!is_array($val)) {
                 $key = $this->ldel . $space . $key . $space . $this->rdel;
                 $string = preg_replace('/' . $key . '/', $val, $string);
             } else {
                 $allString = '';
                 $newResult = '';
                 if (!empty($val)) {
                     $kstart = $this->ldel . $space . $key . $space . $this->rdel;
                     $kend = $this->ldel . $space . '\\/' . $space . $key . $space . $this->rdel;
                     preg_match('/' . $kstart . $all . $kend . '/s', $string, $result);
                     if (!empty($result)) {
                         // Bloğu değiştirme ve çoğalatma
                         // işlemi gerçekleştir.
                         foreach ($result as $res) {
                             // Değiştirme işlemlerini gerçekleştir.
                             foreach ($data[$key] as $item) {
                                 $newResult = preg_replace('/' . $kstart . '/', '', $res);
                                 $newResult = preg_replace('/' . $kend . '/', '', $newResult);
                                 $allString .= $this->data($newResult, $item) . $eol;
                             }
                             $string = str_replace($res, $allString, $string);
                         }
                     }
                 }
             }
         }
     }
     $regexChar = '(([^@]|(\'|\\").*?(\'|\\"))*)';
     $htmlRegexChar = '.*?';
     $pattern = array('/\\s*\\#end(\\w+)/i' => '</$1>', '/\\#\\#(\\!*\\w+)\\s*\\((' . $htmlRegexChar . ')\\)/i' => '<$1 $2>', '/\\s*\\#\\#(\\w+)/i' => '</$1>', '/\\#(\\!*\\w+)\\s*\\((' . $htmlRegexChar . ')(\\s*\\,\\s*(' . $htmlRegexChar . '))*\\)/i' => '<$1 $4>$2</$1>', '/\\#(\\!*\\w+)\\s*(\\[(' . $htmlRegexChar . ')\\])*\\s*/i' => '<$1 $3>', '/\\<(\\!*\\w+)\\s+\\>/i' => '<$1>', '/\\$\\(\'\\s*\\<(.*?)\\>\\s*\'\\)/i' => '$(\'#$1\')', '/\\$\\(\\"\\s*\\<(.*?)\\>\\s*\\"\\)/i' => '$("#$1")', '/@(if)\\s*(\\(' . $htmlRegexChar . '\\))' . $eol . '\\s*/' => '<?php $1$2: ?>', '/\\s*@(elseif)\\s*(\\(' . $htmlRegexChar . '\\))' . $eol . '\\s*/' => '<?php $1$2: ?>', '/\\s*@(endif)/' => '<?php $1 ?>', '/@(foreach)\\s*(\\(' . $htmlRegexChar . '\\))' . $eol . '\\s*/' => '<?php $1$2: ?>', '/\\s*@(endforeach)/' => '<?php $1 ?>', '/@(for)\\s*(\\(' . $htmlRegexChar . '\\))' . $eol . '\\s*/' => '<?php $1$2: ?>', '/\\s*@(endfor)/' => '<?php $1 ?>', '/@(while)\\s*(\\(' . $htmlRegexChar . '\\))' . $eol . '\\s*/' => '<?php $1$2: ?>', '/\\s*@(endswhile)/' => '<?php $1 ?>', '/@(break)/' => '<?php $1 ?>', '/@(continue)/' => '<?php $1 ?>', '/@(default)/' => '<?php $1: ?>', '/@@((\\w+|\\$|::|\\s*\\-\\>\\s*)*\\s*\\(' . $regexChar . '\\))/' => '<?php echo $1 ?>', '/@((\\w+|\\$|::|\\s*\\-\\>\\s*)*\\s*\\(' . $regexChar . '\\))/' => '<?php $1 ?>', '/@(\\$\\w+(\\$|::|\\s*\\-\\>\\s*|\\(' . $regexChar . '\\))*)/' => '<?php echo $1 ?>', '/\\{\\-\\-\\s*(' . $htmlRegexChar . ')\\s*\\-\\-\\}/' => '<!--$1-->', '/\\{\\{\\{\\s*(' . $htmlRegexChar . ')\\s*\\}\\}\\}/' => '<?php echo htmlentities($1) ?>', '/\\{\\{(\\s*' . $htmlRegexChar . ')\\s*\\}\\}/' => '<?php echo $1 ?>', '/\\{\\[\\s*(' . $htmlRegexChar . ')\\s*\\]\\}/' => '<?php $1 ?>');
     $string = preg_replace(array_keys($pattern), array_values($pattern), $string);
     if (is_array($data)) {
         extract($data, EXTR_OVERWRITE);
     }
     ob_start();
     @eval("?>{$string}");
     $content = ob_get_contents();
     ob_end_clean();
     if ($lastError = Error::last()) {
         Exceptions::table('', $lastError['message'], '', $lastError['line']);
     } else {
         return $content;
     }
 }
Exemplo n.º 6
0
 protected function _transform($data)
 {
     $str = '';
     $str .= $this->selector . "{" . eol();
     foreach ($this->browsers as $val) {
         $str .= $val . "transform:{$data};" . eol();
     }
     $str .= "}" . eol();
     return $str;
 }
Exemplo n.º 7
0
 /**
  *    Describe object/array structure. If an object is specified, this method will return or output it's own
  *    method names or properties.
  *
  * @param ReflectionClass $ref_class        target class
  * @param integer $indent                   indent count
  */
 public static function describeParentClass(ReflectionClass $ref_class, $indent)
 {
     $result = '';
     $result .= space($indent * 4) . $ref_class->getName() . eol();
     $ref_parent = $ref_class->getParentClass();
     if ($ref_parent) {
         $result .= self::describeParentClass($ref_parent, $indent++);
     }
     return $result;
 }
Exemplo n.º 8
0
 public function attr($attr = array())
 {
     if (!is_array($attr)) {
         return Error::set('Error', 'arrayParameter', 'attr');
     }
     $str = $this->selector . "{" . eol();
     $str .= $this->_attr($attr) . eol();
     $str .= "}" . eol();
     $this->_defaultVariable();
     return $str;
 }
Exemplo n.º 9
0
 public function load($debug_mode, $profile_name)
 {
     $config_file = "{$profile_name}.profile.ini";
     try {
         // get profile directory path
         $profile_dir = Charcoal_ResourceLocator::getApplicationFile('config/profile');
         // make config file object
         $config_file = new Charcoal_File($config_file, $profile_dir);
         // check if profile directory exists
         if (!$profile_dir->exists()) {
             if ($debug_mode) {
                 echo "profile directory not exists: [{$profile_dir}]" . eol();
             }
             log_error("debug,config,profile", "profile directory not exists: [{$profile_dir}]");
             _throw(new Charcoal_ProfileDirectoryNotFoundException($profile_dir));
         }
         // throw exception when config file is not found
         if (!$config_file->isFile() || !$config_file->canRead()) {
             if ($debug_mode) {
                 echo "profile config file not exists or not readable: [{$config_file}]" . eol();
             }
             log_error("debug,config,profile", "profile config file not exists or not readable: [{$config_file}]");
             _throw(new Charcoal_ProfileConfigFileNotFoundException($config_file));
         }
         // parse config file
         //            log_debug( "debug,config,profile", "profile", "parsing config file: [$config_file]" );
         $config_file = $config_file->getAbsolutePath();
         if ($debug_mode) {
             echo "executing parse_ini_file: [{$config_file}]" . eol();
         }
         $config = @parse_ini_file($config_file, FALSE);
         if ($config === FALSE) {
             if ($debug_mode) {
                 echo "profile config file format error: [{$config_file}]" . eol();
             }
             log_error("debug,config,profile", "profile config file format error: [{$config_file}]");
             _throw(new Charcoal_ProfileConfigFileFormatException($config_file));
         }
         if ($debug_mode) {
             echo "executed parse_ini_file: " . ad($config) . eol();
         }
         //            log_debug( "profile", "profile", "parse_ini_file: " . print_r($config,TRUE) );
         // 設定を保存
         parent::mergeArray($config);
         //            log_debug( "debug,config,profile", "profile", "marged profile:" . print_r($config,TRUE) );
     } catch (Exception $ex) {
         //            log_debug( "system,error,debug", "catch $e" );
         _catch($ex);
         _throw(new Charcoal_ProfileLoadingException($config_file, $profile_name, $ex));
     }
 }
Exemplo n.º 10
0
 /**
  * process event
  *
  * @param Charcoal_IEventContext $context   event context
  *
  * @return boolean|Charcoal_Boolean
  *
  * @throws DivisionByZeroException
  */
 public function processEvent($context)
 {
     $request = $context->getRequest();
     // Get parameter from request
     $a = $request->getInteger('a', 0);
     $b = $request->getInteger('b', 0);
     $op = $request->getString('op', '+');
     $a = ui($a);
     $b = ui($b);
     $op = us($op);
     $result = NULL;
     switch ($op) {
         case 'add':
             $result = $a + $b;
             break;
         case 'sub':
             $result = $a - $b;
             break;
         case 'mul':
             $result = $a * $b;
             break;
         case 'div':
             if ($b == 0) {
                 throw new DivisionByZeroException();
             }
             $result = $a / $b;
             break;
     }
     // show message
     if ($result) {
         echo "result:" . $result . eol();
     } else {
         echo "<pre>USAGE:" . PHP_EOL;
         echo "http://" . $_SERVER['SERVER_NAME'] . "/calc/value1/value2/[add/sub/mul/div]" . PHP_EOL;
         echo "value1, value2: number" . eol();
         echo "add: shows result of 'value1 + value2'" . PHP_EOL;
         echo "sub: shows result of 'value1 - value2'" . PHP_EOL;
         echo "mul: shows result of 'value1 * value2'" . PHP_EOL;
         echo "div: shows result of 'value1 / value2'" . PHP_EOL;
         echo "</pre>" . eol();
     }
     // return TRUE if processing the procedure success.
     return TRUE;
 }
Exemplo n.º 11
0
 public function __construct()
 {
     // Ayarlar alınıyor...
     $this->config = Config::get('Record');
     // Ana dizin belirleniyor...
     $this->znrDir = STORAGE_DIR . 'ZNRecords/';
     // Güvenlik eki olşturuluyor...
     $this->secureFix .= eol();
     $recordName = $this->config['record'];
     $recordDir = $this->_recordName($recordName);
     // Config/Record.php dosyasıda yer alan
     // record parametresi ayarlanmışsa
     // oluşturma ve seçme işlemini otomatik yap.
     if (!empty($recordName)) {
         if (!is_dir($recordDir)) {
             $this->createRecord($recordName);
         }
         if (is_dir($recordDir)) {
             $this->selectRecord($recordName);
         }
     }
 }
Exemplo n.º 12
0
 public function backup($tables = '*', $fileName = '', $path = FILES_DIR)
 {
     if ($this->db->backup($fileName) !== false) {
         return $this->db->backup($fileName);
     }
     if ($tables === '*') {
         $tables = array();
         $this->db->query('SHOW TABLES');
         while ($row = $this->db->fetchRow()) {
             $tables[] = $row[0];
         }
     } else {
         $tables = is_array($tables) ? $tables : explode(',', $tables);
     }
     $return = NULL;
     foreach ($tables as $table) {
         if (!empty($this->prefix) && !strstr($table, $this->prefix)) {
             $table = $this->prefix . $table;
         }
         $this->db->query('SELECT * FROM ' . $table);
         $numFields = $this->db->numFields();
         $return .= 'DROP TABLE ' . $table . ';';
         $this->db->query('SHOW CREATE TABLE ' . $table);
         $row2 = $this->db->fetchRow();
         $return .= eol(2) . $row2[1] . ";" . eol(2);
         for ($i = 0; $i < $numFields; $i++) {
             while ($row = $this->db->fetchRow()) {
                 $return .= 'INSERT INTO ' . $table . ' VALUES(';
                 for ($j = 0; $j < $numFields; $j++) {
                     $row[$j] = addslashes($row[$j]);
                     $row[$j] = preg_replace("/\n/", "\\n", $row[$j]);
                     if (isset($row[$j])) {
                         $return .= '"' . $row[$j] . '"';
                     } else {
                         $return .= '""';
                     }
                     if ($j < $numFields - 1) {
                         $return .= ',';
                     }
                 }
                 $return .= ");" . eol();
             }
         }
         $return .= eol(3);
     }
     if (empty($fileName)) {
         $fileName = 'db-backup-' . time() . '-' . md5(implode(',', $tables)) . '.sql';
     }
     $handle = fopen($path . $fileName, 'w+');
     fwrite($handle, $return);
     fclose($handle);
     return getMessage('Database', 'backupTablesSuccess');
 }
Exemplo n.º 13
0
 /**
  *    run bootstrap
  *
  * @param boolean $debug
  */
 public static function run($debug = FALSE)
 {
     self::$debug = $debug;
     // register bootstrap clas loader
     if (!spl_autoload_register('Charcoal_Bootstrap::loadClass', false)) {
         echo "registering bootstrap class loader failed." . eol();
         exit;
     }
     // register system handlers
     register_shutdown_function('Charcoal_Bootstrap::onShutdown');
     set_error_handler("Charcoal_Bootstrap::onUnhandledError");
     set_exception_handler("Charcoal_Bootstrap::onUnhandledException");
 }
Exemplo n.º 14
0
 public function close()
 {
     $script = '</style>' . eol();
     return $script;
 }
Exemplo n.º 15
0
 protected function _package($packages = "", $recursive = false, $getContents = false)
 {
     if (!is_string($packages)) {
         Error::set('Error', 'stringParameter', 'packages');
         return false;
     }
     if (!empty($this->parameters['usable'])) {
         $getContents = $this->parameters['usable'];
     }
     if (!empty($this->parameters['recursive'])) {
         $recursive = $this->parameters['recursive'];
     }
     $this->parameters = array();
     $eol = eol();
     $return = '';
     if (is_dir($packages)) {
         $packageFiles = Folder::allFiles(suffix($packages), $recursive);
         if (!empty($packageFiles)) {
             foreach ($packageFiles as $val) {
                 $val = restorationPath($val);
                 if ($getContents === true) {
                     $return .= $this->something($val, '', true);
                 } else {
                     $this->something($val);
                 }
             }
             return $return;
         } else {
             return false;
         }
     } elseif (is_file($packages)) {
         return $this->something($packages, '', $getContents);
     }
 }
Exemplo n.º 16
0
 public function create()
 {
     $combineFunction = func_get_args();
     $complete = eol() . JQ::selector($this->selector);
     $complete .= $this->complete();
     if (!empty($combineFunction)) {
         foreach ($combineFunction as $function) {
             $complete .= $function;
         }
     }
     $complete .= ";";
     return $complete;
 }
Exemplo n.º 17
0
function createHtaccessFile()
{
    // Cache.php ayar dosyasından ayarlar çekiliyor.
    $config = Config::get('Cache');
    //-----------------------GZIP-------------------------------------------------------------
    // mod_gzip = true ayarı yapılmışsa aşağıdaki kodları ekler.
    // Gzip ile ön bellekleme başlatılmış olur.
    if ($config['modGzip']['status'] === true) {
        $modGzip = '<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(' . $config['modGzip']['includedFileExtension'] . ')$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>' . eol(2);
    } else {
        $modGzip = '';
    }
    //-----------------------GZIP-------------------------------------------------------------
    //-----------------------EXPIRES----------------------------------------------------------
    // mod_expires = true ayarı yapılmışsa aşağıdaki kodları ekler.
    // Tarayıcı ile ön bellekleme başlatılmış olur.
    if ($config['modExpires']['status'] === true) {
        $exp = '';
        foreach ($config['modExpires']['fileTypeTime'] as $type => $value) {
            $exp .= 'ExpiresByType ' . $type . ' "access plus ' . $value . ' seconds"' . eol();
        }
        $modExpires = '<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus ' . $config['modExpires']['defaultTime'] . ' seconds"
' . $exp . '
</ifModule>' . eol(2);
    } else {
        $modExpires = '';
    }
    //-----------------------EXPIRES----------------------------------------------------------
    //-----------------------HEADERS----------------------------------------------------------
    // mod_headers = true ayarı yapılmışsa aşağıdaki kodları ekler.
    // Header ile ön bellekleme başlatılmış olur.
    if ($config['modHeaders']['status'] === true) {
        $fmatch = '';
        foreach ($config['modHeaders']['fileExtensionTimeAccess'] as $type => $value) {
            $fmatch .= '<filesMatch "\\.(' . $type . ')$">
Header set Cache-Control "max-age=' . $value['time'] . ', ' . $value['access'] . '"
</filesMatch>' . eol();
        }
        $modHeaders = '<ifModule mod_headers.c>
' . $fmatch . '
</ifModule>
' . eol(2);
    } else {
        $modHeaders = '';
    }
    //-----------------------HEADERS----------------------------------------------------------
    //-----------------------HEADER SET-------------------------------------------------------
    $headerSet = Config::get("Headers");
    if (!empty($headerSet['setHtaccessFile'])) {
        $headersIniSet = "<ifModule mod_expires.c>" . eol();
        foreach ($headerSet['iniSet'] as $val) {
            $headersIniSet .= "{$val}" . eol();
        }
        $headersIniSet .= "</ifModule>" . eol(2);
    } else {
        $headersIniSet = '';
    }
    //-----------------------HEADER SET-------------------------------------------------------
    //-----------------------HTACCESS SET-----------------------------------------------------
    $htaccessSettings = Config::get("Htaccess");
    if (!empty($htaccessSettings['setFile'])) {
        $htaccessSettingsStr = '';
        foreach ($htaccessSettings['settings'] as $key => $val) {
            $htaccessSettingsStr .= "<{$key}>" . eol();
            foreach ($val as $v) {
                $htaccessSettingsStr .= $v;
            }
            $keyex = explode(" ", $key);
            $htaccessSettingsStr .= eol() . "</{$keyex['0']}>" . eol(2);
        }
    } else {
        $htaccessSettingsStr = '';
    }
    //-----------------------HTACCESS SET-----------------------------------------------------
    // Htaccess dosyasına eklenecek veriler birleştiriliyor...
    $htaccess = $modGzip . $modExpires . $modHeaders . $headersIniSet . $htaccessSettingsStr;
    //-----------------------URI INDEX PHP----------------------------------------------------
    if (!Config::get('Uri', 'index.php')) {
        $htaccess .= "<IfModule mod_rewrite.c>" . eol();
        $htaccess .= "RewriteEngine On" . eol();
        $htaccess .= "RewriteBase /" . eol();
        $htaccess .= "RewriteCond %{REQUEST_FILENAME} !-f" . eol();
        $htaccess .= "RewriteCond %{REQUEST_FILENAME} !-d" . eol();
        $htaccess .= 'RewriteRule ^(.*)$  ' . server('scriptName') . Config::get('Uri', 'indexSuffix') . '/$1 [L]' . eol();
        $htaccess .= "</IfModule>";
    }
    //-----------------------URI INDEX PHP----------------------------------------------------
    //-----------------------UPLOAD SETTINGS--------------------------------------------------
    $uploadSet = Config::get('Upload');
    if (!empty($uploadSet['setHtaccessFile'])) {
        $uploadSettings = $uploadSet['settings'];
    } else {
        $uploadSettings = array();
    }
    //-----------------------UPLOAD SETTINGS--------------------------------------------------
    //-----------------------SESSION SETTINGS-------------------------------------------------
    $sessionSet = Config::get('Session');
    if (!empty($sessionSet['setHtaccessFile'])) {
        $sessionSettings = $sessionSet['settings'];
    } else {
        $sessionSettings = array();
    }
    //-----------------------SESSION SETTINGS-------------------------------------------------
    //-----------------------INI SETTINGS-----------------------------------------------------
    $iniSet = Config::get('Ini');
    if (!empty($iniSet['setHtaccessFile'])) {
        $iniSettings = $iniSet['settings'];
    } else {
        $iniSettings = array();
    }
    //-----------------------INI SETTINGS-----------------------------------------------------
    // Ayarlar birleştiriliyor.
    $allSettings = array_merge($iniSettings, $uploadSettings, $sessionSettings);
    if (!empty($allSettings)) {
        $sets = '';
        foreach ($allSettings as $k => $v) {
            if ($v !== '') {
                $sets .= "php_value {$k} {$v}" . eol();
            }
        }
        if (!empty($sets)) {
            $htaccess .= eol() . "<IfModule mod_php5.c>" . eol();
            $htaccess .= $sets;
            $htaccess .= "</IfModule>";
        }
    }
    // .htaccess dosyası varsa içeriği al yok ise içeriği boş geç
    if (file_exists('.htaccess')) {
        $getContents = file_get_contents('.htaccess');
    } else {
        $getContents = '';
    }
    // $htaccess değişkenin tuttuğu değer ile dosya içeri eşitse tekrar oluşturma
    if (trim($htaccess) === trim($getContents)) {
        return false;
    }
    //echo $getContents."<br>";
    //echo $htaccess;
    // .htaccess dosyasını oluştur.
    $fileOpen = fopen('.htaccess', 'w');
    $fileWrite = fwrite($fileOpen, trim($htaccess));
    fclose($fileOpen);
    // $htaccess değişkenini kaldır.
    unset($htaccess);
}
Exemplo n.º 18
0
 protected function _mediaContent($src, $content, $_attributes, $type)
 {
     if (!is_string($src)) {
         $src = '';
     }
     if (!isValue($content)) {
         $content = '';
     }
     return '<' . $type . 'src="' . $src . '"' . Html::attributes($_attributes) . '>' . $content . "</{$type}>" . eol();
 }
Exemplo n.º 19
0
 public function create($name = '', $ver = 0)
 {
     if ($version = $this->_version($ver)) {
         $dir = $this->path . $name . $this->versionDir;
         if (!is_dir($dir)) {
             Folder::create($dir);
         }
         $file = $dir . suffix($version, '.php');
         $name = $name . $version;
     } else {
         $file = $this->path . suffix($name, '.php');
     }
     if (!is_file($file)) {
         $eol = eol();
         $str = '<?php' . $eol;
         $str .= 'class ' . $this->classFix . $name . ' extends ' . $this->extendsFix . $eol;
         $str .= '{' . $eol;
         $str .= "\t" . '//----------------------------------------------------------------------------------------------------' . $eol;
         $str .= "\t" . '// Call Undefined Method' . $eol;
         $str .= "\t" . '//----------------------------------------------------------------------------------------------------' . $eol;
         $str .= "\t" . 'use CallUndefinedMethodTrait;' . $eol . $eol;
         $str .= "\t" . '//----------------------------------------------------------------------------------------------------' . $eol;
         $str .= "\t" . '// Class/Table Name' . $eol;
         $str .= "\t" . '//----------------------------------------------------------------------------------------------------' . $eol;
         $str .= "\t" . 'protected static $table = __CLASS__;' . $eol . $eol;
         $str .= "\t" . '//----------------------------------------------------------------------------------------------------' . $eol;
         $str .= "\t" . '// Up' . $eol;
         $str .= "\t" . '//----------------------------------------------------------------------------------------------------' . $eol;
         $str .= "\t" . 'public function up()' . $eol;
         $str .= "\t" . '{' . $eol;
         $str .= "\t\t" . '// Queries' . $eol;
         $str .= "\t" . '}' . $eol . $eol;
         $str .= "\t" . '//----------------------------------------------------------------------------------------------------' . $eol;
         $str .= "\t" . '// Down' . $eol;
         $str .= "\t" . '//----------------------------------------------------------------------------------------------------' . $eol;
         $str .= "\t" . 'public function down()' . $eol;
         $str .= "\t" . '{' . $eol;
         $str .= "\t\t" . '// Queries' . $eol;
         $str .= "\t\t" . '$this->dropTable(); // Varsayılan işlem.' . $eol;
         $str .= "\t" . '}' . $eol;
         $str .= '}';
         return File::write($file, $str);
     } else {
         return Error::set('File', 'alreadyFileError', $file);
     }
 }
 /**
  * テスト
  *
  * @param string $action
  * @param Charcoal_IEventContext $context
  *
  * @return boolean
  */
 public function test($action, $context)
 {
     $action = us($action);
     /** @var Charcoal_SmartGateway $gw */
     $gw = $context->getComponent('smart_gateway@:charcoal:db');
     $gw->reset();
     switch ($action) {
         case "commit":
             // トランザクション開始
             $gw->beginTrans();
             $gw->autoCommit(FALSE);
             // 初期データの確認
             $result = $gw->query(NULL, "SELECT * FROM posts WHERE post_id=1");
             $this->assertEquals('stk2k', $result[0]['post_user'], true);
             // 更新
             $gw->execute(NULL, "UPDATE posts set post_user = '******' where post_id = 1");
             // コミット
             $gw->commitTrans();
             // 検索
             $result = $gw->query(NULL, "SELECT * FROM posts WHERE post_id=1");
             $this->assertEquals('hoge', $result[0]['post_user']);
             return TRUE;
         case "query":
             $sql = "SELECT * FROM blogs WHERE blog_id = 1";
             $result = $gw->query("query #1", $sql);
             $blog_name = '';
             foreach ($result as $row) {
                 $blog_name = $row['blog_name'];
                 echo "blog_name:{$blog_name}" . eol();
             }
             $this->assertEquals(1, count($result));
             $this->assertEquals("my blog", $blog_name);
             return TRUE;
         case "select":
             $where = "blog_id = ?";
             $criteria = new Charcoal_SQLCriteria($where, array(1));
             $result = $gw->findAll("select #1", 'blogs', $criteria);
             $blog_name = '';
             foreach ($result as $row) {
                 $blog_name = $row['blog_name'];
                 echo "blog_name:{$blog_name}" . eol();
             }
             $this->assertEquals(1, count($result));
             $this->assertEquals("my blog", $blog_name);
             return TRUE;
         case "select_alias":
             $where = "b.blog_id = ?";
             $criteria = new Charcoal_SQLCriteria($where, array(1));
             $result = $gw->findAll("select_alias #1", 'blogs as b', $criteria);
             $blog_name = '';
             foreach ($result as $row) {
                 $blog_name = $row['blog_name'];
                 echo "blog_name:{$blog_name}" . eol();
             }
             $this->assertEquals(1, count($result));
             $this->assertEquals("my blog", $blog_name);
             return TRUE;
         case "select_alias_forupdate":
             $where = "blog_name like ?";
             $criteria = new Charcoal_SQLCriteria($where, array("My First Blog"));
             $result = $gw->findAllForUpdate("select_alias_forupdate #1", 'blogs as b', $criteria);
             foreach ($result as $row) {
                 print print_r($row, true) . PHP_EOL;
             }
             return TRUE;
         case "inner_join":
             $where = "blogs.blog_id = ?";
             $criteria = new Charcoal_SQLCriteria($where, array(1));
             $result = $gw->findAll("inner_join #1", 'blogs + posts on "blogs.blog_id = posts.blog_id" + comments on "posts.post_id = comments.post_id"', $criteria);
             $blog_name = '';
             foreach ($result as $row) {
                 $blog_name = $row['blog_name'];
                 echo "blog_name:{$blog_name}" . eol();
             }
             $this->assertEquals(3, count($result));
             $this->assertEquals("my blog", $blog_name);
             return TRUE;
         case "left_join":
             $where = "blogs.blog_id = ?";
             $criteria = new Charcoal_SQLCriteria($where, array(1));
             $result = $gw->findAll("left_join #1", 'blogs (+ posts on "blogs.blog_id = posts.blog_id"', $criteria);
             $blog_name = '';
             foreach ($result as $row) {
                 $blog_name = $row['blog_name'];
                 echo "blog_name:{$blog_name}" . eol();
             }
             $this->assertEquals(2, count($result));
             $this->assertEquals("my blog", $blog_name);
             return TRUE;
         case "right_join":
             $where = "blogs.blog_id = ?";
             $criteria = new Charcoal_SQLCriteria($where, array(1));
             $result = $gw->findAll("right_join #1", 'blogs +) posts on "blogs.blog_id = posts.blog_id"', $criteria);
             $blog_name = '';
             foreach ($result as $row) {
                 $blog_name = $row['blog_name'];
                 echo "blog_name:{$blog_name}" . eol();
             }
             // 評価
             $this->assertEquals(2, count($result));
             $this->assertEquals("my blog", $blog_name);
             return TRUE;
         case "inner_join_alias":
             $where = "b.blog_id = ?";
             $criteria = new Charcoal_SQLCriteria($where, array(1));
             $result = $gw->findAll("inner_join_alias #1", 'blogs as b + posts as p on "b.blog_id = p.blog_id"', $criteria);
             $blog_name = '';
             foreach ($result as $row) {
                 $blog_name = $row['blog_name'];
                 echo "blog_name:{$blog_name}" . eol();
             }
             $this->assertEquals(2, count($result));
             $this->assertEquals("my blog", $blog_name);
             return TRUE;
         case "inner_join_multi":
             $where = "blogs.blog_id = ?";
             $criteria = new Charcoal_SQLCriteria($where, array(1));
             $result = $gw->findAll("inner_join_multi #1", 'blogs  + posts on "blogs.blog_id = posts.blog_id" + comments on "posts.post_id = comments.post_id"', $criteria);
             $blog_name = '';
             foreach ($result as $row) {
                 $blog_name = $row['blog_name'];
                 echo "blog_name:{$blog_name}" . eol();
             }
             $this->assertEquals(3, count($result));
             $this->assertEquals("my blog", $blog_name);
             return TRUE;
         case "inner_join_multi_alias":
             $where = "b.blog_id = ?";
             $criteria = new Charcoal_SQLCriteria($where, array(1));
             $result = $gw->findAll("inner_join_multi_alias #1", 'blogs as b + posts as p on "b.blog_id = p.blog_id" + comments as c on "p.post_id = c.post_id"', $criteria);
             $blog_name = '';
             foreach ($result as $row) {
                 $blog_name = $row['blog_name'];
                 echo "blog_name:{$blog_name}" . eol();
             }
             $this->assertEquals(3, count($result));
             $this->assertEquals("my blog", $blog_name);
             return TRUE;
         case "count":
             $criteria = new Charcoal_SQLCriteria();
             $result = $gw->count("count #1", 'posts', $criteria, '*');
             echo "result:" . $result . eol();
             // 評価
             $this->assertEquals(3, $result);
             return TRUE;
         case "max":
             $criteria = new Charcoal_SQLCriteria();
             $result = $gw->max("max #1", 'posts', $criteria, 'favorite');
             echo "result:" . $result . eol();
             $this->assertEquals(11, $result);
             return TRUE;
         case "min":
             $criteria = new Charcoal_SQLCriteria();
             $result = $gw->min("min #1", 'posts', $criteria, 'favorite');
             echo "result:" . $result . eol();
             // 評価
             $this->assertEquals(5, $result);
             return TRUE;
         case "avg":
             $criteria = new Charcoal_SQLCriteria();
             $result = $gw->avg("avg #1", 'posts', $criteria, 'favorite');
             echo "result:" . $result . eol();
             $this->assertEquals(8, $result);
             return TRUE;
         case "count_alias":
             $criteria = new Charcoal_SQLCriteria();
             $result = $gw->count("count_alias #1", 'posts as p', $criteria, '*');
             echo "result:" . $result . eol();
             $this->assertEquals(3, $result);
             return TRUE;
         case "max_alias":
             $criteria = new Charcoal_SQLCriteria();
             $result = $gw->max("max_alias #1", 'posts as p + comments as c on "p.post_id = c.post_id"', $criteria, 'favorite');
             echo "result:" . $result . eol();
             $this->assertEquals(11, $result);
             return TRUE;
         case "find_first":
             $criteria = new Charcoal_SQLCriteria();
             $criteria->setOrderBy('favorite');
             $result = $gw->findFirst("find_first #1", 'posts', $criteria);
             echo "result:" . $result['post_title'] . eol();
             $this->assertEquals('How does it work?', $result['post_title']);
             return TRUE;
         case "find_by_id":
             $result = $gw->findAll("find_by_id #1", 'posts', new Charcoal_SQLCriteria());
             foreach ($result as $row) {
                 $blog_id = $row['blog_id'];
                 $blog = $gw->findById("find_by_id #2", 'blogs', $blog_id);
                 $this->assertEquals($this->blog_name_expected[$blog_id], $blog['blog_name']);
                 $blog_category_id = $blog['blog_category_id'];
                 $category = $gw->findById("find_by_id #3", 'blog_category', $blog_category_id);
                 $this->assertEquals($this->category_name_expected[$blog_category_id], $category['blog_category_name']);
             }
             return TRUE;
         case "save":
             // save by INSERT
             $dto = new PostTableDTO();
             $dto->post_title = 'New Post';
             $dto->post_body = 'New Post Body';
             $dto->post_user = '******';
             $count = $gw->count(NULL, 'posts', new Charcoal_SQLCriteria(), NULL);
             //echo $gw->popSQLHistory() . PHP_EOL;
             //echo "count(before save):" . $count . eol();
             $this->assertEquals(3, $count);
             $new_id = $gw->save(NULL, "posts", $dto);
             //echo $gw->popSQLHistory() . PHP_EOL;
             $criteria = new Charcoal_SQLCriteria();
             $criteria->setWhere("post_id = ?");
             $criteria->setParams(array($new_id));
             $new_record = $gw->findFirst(NULL, 'posts', $criteria);
             //echo $gw->popSQLHistory() . PHP_EOL;
             $count = $gw->count(NULL, 'posts', new Charcoal_SQLCriteria());
             //echo $gw->popSQLHistory() . PHP_EOL;
             //echo "count(after save):" . $count . eol();
             $this->assertEquals(4, $count);
             $this->assertEquals(4, $new_record['post_id']);
             $this->assertEquals('New Post', $new_record['post_title']);
             $this->assertEquals('New Post Body', $new_record['post_body']);
             $this->assertEquals('Ichiro', $new_record['post_user']);
             // save by UPDATE
             $dto->post_id = $new_id;
             $dto->post_date = array('function', 'now');
             $dto->post_user = array('value', 'null');
             $dto->post_body = array(1, 2, "apple", array('name' => 'stk2k'), array('sex' => 'male'));
             $time_before_update = time();
             sleep(1);
             $gw->save(NULL, "posts", $dto);
             sleep(1);
             $time_after_update = time();
             $criteria = new Charcoal_SQLCriteria();
             $criteria->setWhere("post_id = ?");
             $criteria->setParams(array($dto->post_id));
             $the_record = $gw->findFirst(NULL, 'posts', $criteria);
             // check post date
             $this->assertGreaterThan($time_before_update, strtotime($the_record['post_date']));
             $this->assertLessThan($time_after_update, strtotime($the_record['post_date']));
             // check post user
             $this->assertEquals(NULL, $the_record['post_user']);
             // check post body(JSON)
             $post_body = json_decode($the_record['post_body'], true);
             $expeced = array(1, 2, "apple", array('name' => 'stk2k'), array('sex' => 'male'));
             $this->assertEquals($expeced, $post_body);
             return TRUE;
         case "fluent_api":
             $gw->select("b.blog_name, b.post_total, p.post_user, p.post_title")->from(s("blogs"), s("b"))->leftJoin(s("posts"), s("p"))->on("b.blog_id = p.blog_id")->where()->gt(s("b.post_total"), i(1))->orderBy(s("b.post_total DESC"))->limit(i(5))->offset(i(0))->prepareExecute()->findFirst("fluent_api #1")->result();
             echo $gw->popSQLHistory() . PHP_EOL;
             //            echo print_r($rs,true) . eol();
             //            echo "last SQL:" . $gw->getLastSQL() . eol();
             //            echo "last params:" . $gw->getLastParams() . eol();
             return TRUE;
         case "recordset_query":
             $rsfactory1 = $gw->createRecordsetFactory();
             // fetch mode: FETCHMODE_BOTH
             $sql = "SELECT * FROM blogs WHERE blog_id = 1";
             $result = $gw->query("recordset_query #1", $sql, NULL, $rsfactory1, NULL);
             echo $gw->popSQLHistory() . PHP_EOL;
             foreach ($result as $row) {
                 $this->assertEquals($this->blog_name_expected[$row['blog_id']], $row['blog_name']);
             }
             $rsfactory2 = $gw->createRecordsetFactory(Charcoal_IRecordset::FETCHMODE_ASSOC);
             $sql = "SELECT * FROM blogs WHERE blog_id = 1";
             $result = $gw->query("recordset_query #2", $sql, NULL, $rsfactory2, NULL);
             echo $gw->popSQLHistory() . PHP_EOL;
             foreach ($result as $row) {
                 $this->assertEquals($this->blog_name_expected[$row['blog_id']], $row['blog_name']);
             }
             $rsfactory3 = $gw->createRecordsetFactory(Charcoal_IRecordset::FETCHMODE_NUM);
             $sql = "SELECT blog_id, blog_name, post_total FROM blogs WHERE blog_id = 1";
             $result = $gw->query("recordset_query #3", $sql, NULL, $rsfactory3, NULL);
             echo $gw->popSQLHistory() . PHP_EOL;
             foreach ($result as $row) {
                 $this->assertEquals($this->blog_name_expected[$row[0]], $row[1]);
             }
             return TRUE;
         case "recordset_find":
             $rsfactory1 = $gw->createRecordsetFactory();
             // fetch mode: FETCHMODE_ASSOC
             $sql = "SELECT * FROM blogs WHERE blog_id = 1";
             $result = $gw->query("recordset_find #1", $sql, NULL, $rsfactory1, NULL);
             echo $gw->popSQLHistory() . PHP_EOL;
             foreach ($result as $row) {
                 $this->assertEquals($this->blog_name_expected[$row['blog_id']], $row['blog_name']);
             }
             $rsfactory2 = $gw->createRecordsetFactory(Charcoal_IRecordset::FETCHMODE_ASSOC);
             $sql = "SELECT * FROM blogs WHERE blog_id = 1";
             $result = $gw->query("recordset_find #2", $sql, NULL, $rsfactory2, NULL);
             echo $gw->popSQLHistory() . PHP_EOL;
             foreach ($result as $row) {
                 $this->assertEquals($this->blog_name_expected[$row['blog_id']], $row['blog_name']);
             }
             $rsfactory3 = $gw->createRecordsetFactory(Charcoal_IRecordset::FETCHMODE_NUM);
             $sql = "SELECT blog_id, blog_name, post_total FROM blogs WHERE blog_id = 1";
             $result = $gw->query("recordset_find #3", $sql, NULL, $rsfactory3, NULL);
             echo $gw->popSQLHistory() . PHP_EOL;
             foreach ($result as $row) {
                 $this->assertEquals($this->blog_name_expected[$row[0]], $row[1]);
             }
             return TRUE;
         case "nested_recordset_query":
             $rsfactory1 = $gw->createRecordsetFactory();
             // fetch mode: FETCHMODE_BOTH
             $sql = "SELECT * FROM blogs WHERE blog_id = 1";
             $result = $gw->query(NULL, $sql, NULL, $rsfactory1);
             foreach ($result as $row) {
                 $this->assertEquals(1, $row['blog_id']);
                 $this->assertEquals($this->blog_name_expected[1], $row['blog_name']);
                 $blog_category_id = $row['blog_category_id'];
                 $sql = "SELECT * FROM blog_category WHERE blog_category_id = ?";
                 $result2 = $gw->query(NULL, $sql, array($blog_category_id), $rsfactory1);
                 foreach ($result2 as $row2) {
                     $this->assertEquals($blog_category_id, $row2['blog_category_id']);
                     $this->assertEquals($this->category_name_expected[$blog_category_id], $row2['blog_category_name']);
                 }
             }
             /*
                         $rsfactory2 = $gw->createRecordsetFactory( Charcoal_IRecordset::FETCHMODE_ASSOC );
             
                         $sql = "SELECT * FROM blogs WHERE blog_id = 1";
                         $result = $gw->query( $sql, NULL, $rsfactory2 );
             
                         foreach( $result as $row ){
                             $this->assertEquals( 1, $row['blog_id'] );
                             $this->assertEquals( $this->blog_name_expected[1], $row['blog_name'] );
             
                             $blog_category_id = $row['blog_category_id'];
             
                             $sql = "SELECT * FROM blog_category WHERE blog_category_id = ?";
                             $result2 = $gw->query( $sql, array($blog_category_id), $rsfactory2 );
             
                             foreach( $result2 as $row ){
                                 $this->assertEquals( $blog_category_id, $row['blog_category_id'] );
                                 $this->assertEquals( $this->category_name_expected[$blog_category_id], $row['blog_category_name'] );
                             }
                         }
             
                         $rsfactory3 = $gw->createRecordsetFactory( Charcoal_IRecordset::FETCHMODE_NUM );
             
                         $sql = "SELECT blog_id, blog_name, post_total, blog_category_id FROM blogs WHERE blog_id = 1";
                         $result = $gw->query( $sql, NULL, $rsfactory3 );
             
                         foreach( $result as $row ){
                             $this->assertEquals( 1, $row[0] );
                             $this->assertEquals( $this->blog_name_expected[1], $row[1] );
             
                             $blog_category_id = $row[3];
             
                             $sql = "SELECT blog_category_id, blog_category_name FROM blog_category WHERE blog_category_id = ?";
                             $result2 = $gw->query( $sql, array($blog_category_id), $rsfactory3 );
             
                             foreach( $result2 as $row ){
                                 $this->assertEquals( $blog_category_id, $row[0] );
                                 $this->assertEquals( $this->category_name_expected[$blog_category_id], $row[1] );
                             }
                         }
             */
             $another_ds = $context->createObject('PDO', 'data_source');
             $default_ds_config = $gw->getDataSource()->getConfig();
             //ad($default_ds_config);
             $config = $context->createConfig($default_ds_config->getAll());
             $GLOBALS['hoge'] = true;
             ad($config);
             $config->set('token_key', 'foo');
             $another_ds->configure($config);
             return TRUE;
         case "nested_recordset_find":
             return TRUE;
         case "delete_by_id":
             $gw->deleteById("delete_by_id #1", 'blog_category', 1);
             echo $gw->popSQLHistory() . PHP_EOL;
             $criteria = new Charcoal_SQLCriteria('');
             $cnt = $gw->count("delete_by_id #2", 'blog_category', $criteria);
             echo 'cnt:' . $cnt . PHP_EOL;
             echo $gw->popSQLHistory() . PHP_EOL;
             return TRUE;
         case "delete_by_ids":
             $gw->deleteByIds("delete_by_ids #1", 'blog_category', array(1, 3));
             echo $gw->popSQLHistory() . PHP_EOL;
             $criteria = new Charcoal_SQLCriteria('');
             $cnt = $gw->count("delete_by_ids #2", 'blog_category', $criteria);
             echo 'cnt:' . $cnt . PHP_EOL;
             echo $gw->popSQLHistory() . PHP_EOL;
             return TRUE;
             /* ------------------------------
                    increment/decrement test
                */
         /* ------------------------------
                increment/decrement test
            */
         case "increment_field":
             // increment post_toal by 1
             $gw->incrementField("increment_field #1", 'blogs', 1, 'post_total');
             //echo $gw->popSQLHistory() . PHP_EOL;
             // post_total must be 2 => 3
             $pdo = new DuplicatedPdo($gw);
             $post_total = $pdo->queryValue("SELECT post_total FROM blogs WHERE blog_id = ?", [1]);
             //var_dump($post_total);
             $this->assertEquals(3, $post_total);
             // increment post_toal by 2
             $gw->incrementField("increment_field #1", 'blogs', 1, 'post_total', 2);
             //echo $gw->popSQLHistory() . PHP_EOL;
             // post_total must be 3 => 5
             $pdo = new DuplicatedPdo($gw);
             $post_total = $pdo->queryValue("SELECT post_total FROM blogs WHERE blog_id = ?", [1]);
             //var_dump($post_total);
             $this->assertEquals(5, $post_total);
             // increment post_toal by -5
             $gw->incrementField("increment_field #1", 'blogs', 1, 'post_total', -5);
             //echo $gw->popSQLHistory() . PHP_EOL;
             // post_total must be 5 => 0
             $pdo = new DuplicatedPdo($gw);
             $post_total = $pdo->queryValue("SELECT post_total FROM blogs WHERE blog_id = ?", [1]);
             //var_dump($post_total);
             $this->assertEquals(0, $post_total);
             return TRUE;
         case "increment_field_by":
             // increment post_toal by 1
             $gw->incrementFieldBy("increment_field_by #1", 'blogs', 'post_total', 'blog_name', 'my blog');
             //echo $gw->popSQLHistory() . PHP_EOL;
             // post_total must be 2 => 3
             $pdo = new DuplicatedPdo($gw);
             $post_total = $pdo->queryValue("SELECT post_total FROM blogs WHERE blog_id = ?", [1]);
             //var_dump($post_total);
             $this->assertEquals(3, $post_total);
             // increment post_toal by 2
             $gw->incrementFieldBy("increment_field_by #2", 'blogs', 'post_total', 'blog_name', 'my blog', 2);
             //echo $gw->popSQLHistory() . PHP_EOL;
             // post_total must be 3 => 5
             $pdo = new DuplicatedPdo($gw);
             $post_total = $pdo->queryValue("SELECT post_total FROM blogs WHERE blog_id = ?", [1]);
             //var_dump($post_total);
             $this->assertEquals(5, $post_total);
             // increment post_toal by -5
             $gw->incrementFieldBy("increment_field_by #3", 'blogs', 'post_total', 'blog_name', 'my blog', -5);
             //echo $gw->popSQLHistory() . PHP_EOL;
             // post_total must be 5 => 0
             $pdo = new DuplicatedPdo($gw);
             $post_total = $pdo->queryValue("SELECT post_total FROM blogs WHERE blog_id = ?", [1]);
             //var_dump($post_total);
             $this->assertEquals(0, $post_total);
             return TRUE;
         case "decrement_field":
             // decrement post_toal by 1
             $gw->decrementField("decrement_field #1", 'blogs', 1, 'post_total');
             //echo $gw->popSQLHistory() . PHP_EOL;
             // post_total must be 2 => 1
             $pdo = new DuplicatedPdo($gw);
             $post_total = $pdo->queryValue("SELECT post_total FROM blogs WHERE blog_id = ?", [1]);
             //var_dump($post_total);
             $this->assertEquals(1, $post_total);
             // decrement post_toal by 2
             $gw->decrementField("decrement_field #2", 'blogs', 1, 'post_total', 2);
             //echo $gw->popSQLHistory() . PHP_EOL;
             // post_total must be 1 => -1
             $pdo = new DuplicatedPdo($gw);
             $post_total = $pdo->queryValue("SELECT post_total FROM blogs WHERE blog_id = ?", [1]);
             var_dump($post_total);
             $this->assertEquals(-1, $post_total);
             // decrement post_toal by -5
             $gw->decrementField("decrement_field #3", 'blogs', 1, 'post_total', -5);
             //echo $gw->popSQLHistory() . PHP_EOL;
             // post_total must be -1 => 4
             $pdo = new DuplicatedPdo($gw);
             $post_total = $pdo->queryValue("SELECT post_total FROM blogs WHERE blog_id = ?", [1]);
             //var_dump($post_total);
             $this->assertEquals(4, $post_total);
             return TRUE;
         case "decrement_field_by":
             // decrement post_toal by 1
             $gw->decrementFieldBy("decrement_field_by #1", 'blogs', 'post_total', 'blog_name', 'my blog');
             //echo $gw->popSQLHistory() . PHP_EOL;
             // post_total must be 2 => 1
             $pdo = new DuplicatedPdo($gw);
             $post_total = $pdo->queryValue("SELECT post_total FROM blogs WHERE blog_id = ?", [1]);
             //var_dump($post_total);
             $this->assertEquals(1, $post_total);
             // decrement post_toal by 2
             $gw->decrementFieldBy("decrement_field_by #2", 'blogs', 'post_total', 'blog_name', 'my blog', 2);
             //echo $gw->popSQLHistory() . PHP_EOL;
             // post_total must be 1 => -1
             $pdo = new DuplicatedPdo($gw);
             $post_total = $pdo->queryValue("SELECT post_total FROM blogs WHERE blog_id = ?", [1]);
             //ar_dump($post_total);
             $this->assertEquals(-1, $post_total);
             // decrement post_toal by -5
             $gw->decrementFieldBy("decrement_field_by #3", 'blogs', 'post_total', 'blog_name', 'my blog', -5);
             //echo $gw->popSQLHistory() . PHP_EOL;
             // post_total must be -1 => 4
             $pdo = new DuplicatedPdo($gw);
             $post_total = $pdo->queryValue("SELECT post_total FROM blogs WHERE blog_id = ?", [1]);
             //var_dump($post_total);
             $this->assertEquals(4, $post_total);
             return TRUE;
             /* ------------------------------
                    insert test
                */
         /* ------------------------------
                insert test
            */
         case "insert":
             // INSERT
             $blog = new BlogTableDTO();
             $blog->blog_name = 'my new blog';
             $blog->post_total = 123;
             $blog->created_date = array('function', 'now');
             $blog->modified_date = array('function', 'now');
             $time_insert_before = time();
             sleep(1);
             $gw->insert(NULL, 'blogs', $blog);
             sleep(1);
             $time_insert_after = time();
             $blog_id = $gw->getLastInsertId();
             $this->assertEquals(3, $blog_id);
             // INSERTの確認
             $where = "blog_id = ?";
             $criteria = new Charcoal_SQLCriteria($where, array($blog_id));
             $blog = $gw->findFirst("insert #1", 'blogs', $criteria);
             $this->assertEquals(3, $blog['blog_id']);
             $this->assertEquals('my new blog', $blog['blog_name']);
             $this->assertEquals(123, $blog['post_total']);
             $this->assertGreaterThan($time_insert_before, strtotime($blog['created_date']));
             $this->assertLessThan($time_insert_after, strtotime($blog['created_date']));
             return TRUE;
         case "bulk_insert":
             // BULK INSERT
             $blogs = array();
             $blog = new BlogTableDTO();
             $blog->blog_name = 'my new blog';
             $blog->post_total = 123;
             $blog->created_date = array('function', 'now');
             $blog->modified_date = array('function', 'now');
             $blogs[] = $blog;
             $blog = new BlogTableDTO();
             $blog->blog_name = 'my new blog2';
             $blog->post_total = 44;
             $blog->created_date = array('function', 'now');
             $blog->modified_date = array('function', 'now');
             $blogs[] = $blog;
             $time_insert_before = time();
             sleep(1);
             $inserted_rows = $gw->insertAll(NULL, 'blogs', $blogs);
             $this->assertEquals(2, $inserted_rows);
             sleep(1);
             $time_insert_after = time();
             // INSERTの確認
             $where = "blog_name like 'my new blog%'";
             $criteria = new Charcoal_SQLCriteria($where, NULL, 'blog_id');
             $result = $gw->findAll(NULL, 'blogs', $criteria);
             $blog = array_shift($result);
             $this->assertEquals(3, $blog['blog_id']);
             $this->assertEquals('my new blog', $blog['blog_name']);
             $this->assertEquals(123, $blog['post_total']);
             $this->assertGreaterThan($time_insert_before, strtotime($blog['created_date']));
             $this->assertLessThan($time_insert_after, strtotime($blog['created_date']));
             $blog = array_shift($result);
             $this->assertEquals(4, $blog['blog_id']);
             $this->assertEquals('my new blog2', $blog['blog_name']);
             $this->assertEquals(44, $blog['post_total']);
             $this->assertGreaterThan($time_insert_before, strtotime($blog['created_date']));
             $this->assertLessThan($time_insert_after, strtotime($blog['created_date']));
             return TRUE;
             /* ------------------------------
                    update test
                */
         /* ------------------------------
                update test
            */
         case "update_field":
             echo "selected database:" . $gw->getSelectedDatabase() . PHP_EOL;
             // update a field
             $gw->updateField('update_field #1', 'blogs', 1, 'post_total', 5);
             echo $gw->popSQLHistory() . PHP_EOL;
             // confirm result
             $pdo = new DuplicatedPdo($gw);
             $rows = $pdo->queryRows("SELECT * FROM blogs");
             //var_dump($rows);
             foreach ($rows as $row) {
                 switch ($row['blog_id']) {
                     case 1:
                         $this->assertEquals(1, $row['blog_category_id']);
                         $this->assertEquals('my blog', $row['blog_name']);
                         $this->assertEquals(5, $row['post_total']);
                         break;
                     case 2:
                         $this->assertEquals(2, $row['blog_category_id']);
                         $this->assertEquals('another blog', $row['blog_name']);
                         $this->assertEquals(1, $row['post_total']);
                         break;
                 }
             }
             return TRUE;
         case "update_fields":
             // update fields
             $fields = array('post_total' => 999, 'blog_name' => 'super popular blog');
             $gw->updateFields('update_fields #1', 'blogs', 1, $fields);
             echo $gw->popSQLHistory() . PHP_EOL;
             // confirm result
             $pdo = new DuplicatedPdo($gw);
             $rows = $pdo->queryRows("SELECT * FROM blogs");
             //var_dump($rows);
             foreach ($rows as $row) {
                 switch ($row['blog_id']) {
                     case 1:
                         $this->assertEquals(1, $row['blog_category_id']);
                         $this->assertEquals('super popular blog', $row['blog_name']);
                         $this->assertEquals(999, $row['post_total']);
                         break;
                     case 2:
                         $this->assertEquals(2, $row['blog_category_id']);
                         $this->assertEquals('another blog', $row['blog_name']);
                         $this->assertEquals(1, $row['post_total']);
                         break;
                 }
             }
             return TRUE;
         case "update_field_by":
             // update fields in a row
             $rows = $gw->updateFieldBy('update_field_by #1', 'blogs', 'blog_name', 'another blog', 'blog_id', 1);
             echo $gw->popSQLHistory() . PHP_EOL;
             $this->assertEquals(1, $rows);
             // confirm result
             $pdo = new DuplicatedPdo($gw);
             $rows = $pdo->queryRows("SELECT * FROM blogs");
             //var_dump($rows);
             foreach ($rows as $row) {
                 switch ($row['blog_id']) {
                     case 1:
                         $this->assertEquals(1, $row['blog_category_id']);
                         $this->assertEquals('another blog', $row['blog_name']);
                         $this->assertEquals(2, $row['post_total']);
                         break;
                     case 2:
                         $this->assertEquals(2, $row['blog_category_id']);
                         $this->assertEquals('another blog', $row['blog_name']);
                         $this->assertEquals(1, $row['post_total']);
                         break;
                 }
             }
             // update fields in multiple rows
             $rows = $gw->updateFieldBy('update_field_by #1', 'blogs', 'post_total', 3, 'blog_name', 'another blog');
             echo $gw->popSQLHistory() . PHP_EOL;
             $this->assertEquals(2, $rows);
             // confirm result
             $pdo = new DuplicatedPdo($gw);
             $rows = $pdo->queryRows("SELECT * FROM blogs");
             //var_dump($rows);
             foreach ($rows as $row) {
                 switch ($row['blog_id']) {
                     case 1:
                         $this->assertEquals(1, $row['blog_category_id']);
                         $this->assertEquals('another blog', $row['blog_name']);
                         $this->assertEquals(3, $row['post_total']);
                         break;
                     case 2:
                         $this->assertEquals(2, $row['blog_category_id']);
                         $this->assertEquals('another blog', $row['blog_name']);
                         $this->assertEquals(3, $row['post_total']);
                         break;
                 }
             }
             return TRUE;
         case "update_field_now":
             $start_time = time();
             // update field to current time
             $gw->updateFieldNow('update_field_now #1', 'blogs', 1, 'modified_date');
             echo $gw->popSQLHistory() . PHP_EOL;
             // confirm result
             $pdo = new DuplicatedPdo($gw);
             $rows = $pdo->queryRows("SELECT * FROM blogs");
             //var_dump($rows);
             foreach ($rows as $row) {
                 switch ($row['blog_id']) {
                     case 1:
                         $this->assertEquals(1, $row['blog_category_id']);
                         $this->assertEquals('my blog', $row['blog_name']);
                         $this->assertEquals(2, $row['post_total']);
                         $this->assertEquals('2010-01-02 12:56:12', $row['created_date']);
                         $this->assertLessThanOrEqual($start_time, strtotime($row['modified_date']));
                         $this->assertGreaterThanOrEqual(time(), strtotime($row['modified_date']));
                         break;
                     case 2:
                         $this->assertEquals(2, $row['blog_category_id']);
                         $this->assertEquals('another blog', $row['blog_name']);
                         $this->assertEquals(1, $row['post_total']);
                         $this->assertEquals('2010-01-12 02:12:32', $row['created_date']);
                         $this->assertEquals('2010-01-15 11:42:02', $row['modified_date']);
                         break;
                 }
             }
             return TRUE;
         case "update_field_null":
             // update fields in a row
             $gw->updateFieldNull('update_field_null #1', 'blogs', 1, 'blog_name');
             echo $gw->popSQLHistory() . PHP_EOL;
             // confirm result
             $pdo = new DuplicatedPdo($gw);
             $rows = $pdo->queryRows("SELECT * FROM blogs");
             //var_dump($rows);
             foreach ($rows as $row) {
                 switch ($row['blog_id']) {
                     case 1:
                         $this->assertEquals(1, $row['blog_category_id']);
                         $this->assertEquals(null, $row['blog_name']);
                         $this->assertEquals(2, $row['post_total']);
                         break;
                     case 2:
                         $this->assertEquals(2, $row['blog_category_id']);
                         $this->assertEquals('another blog', $row['blog_name']);
                         $this->assertEquals(1, $row['post_total']);
                         break;
                 }
             }
             return TRUE;
             /* ------------------------------
                    select db test
                */
         /* ------------------------------
                select db test
            */
         case "select_db":
             echo "selected database:" . $gw->getSelectedDatabase() . PHP_EOL;
             $exists = $gw->existsTable('item');
             $this->assertEquals(true, $exists);
             $exists = $gw->existsTable('item2');
             $this->assertEquals(false, $exists);
             $gw->selectDatabase('test2');
             echo "selected database:" . $gw->getSelectedDatabase() . PHP_EOL;
             $exists = $gw->existsTable('item');
             $this->assertEquals(false, $exists);
             $exists = $gw->existsTable('item2');
             $this->assertEquals(true, $exists);
             return TRUE;
             /* ------------------------------
                    list models test
                */
         /* ------------------------------
                list models test
            */
         case "list_models_all":
             $models = $gw->listModels();
             $this->assertEquals(7, count($models));
             $bundled_models = array('Charcoal_SessionTableModel', 'BlogCategoryTableModel', 'BlogTableModel', 'CommentTableModel', 'ItemTableModel', 'Item2TableModel', 'PostTableModel', 'TestTableModel');
             foreach ($models as $model) {
                 $this->assertTrue($model instanceof Charcoal_ITableModel);
                 $clazz = get_class($model);
                 echo $clazz . PHP_EOL;
                 $this->assertTrue(in_array($clazz, $bundled_models));
             }
             return TRUE;
         case "list_models_framework":
             $models = $gw->listModels(Charcoal_EnumFindPath::FIND_PATH_FRAMEWORK);
             $this->assertEquals(1, count($models));
             $bundled_models = array('Charcoal_SessionTableModel');
             foreach ($models as $model) {
                 $this->assertTrue($model instanceof Charcoal_ITableModel);
                 $clazz = get_class($model);
                 echo $clazz . PHP_EOL;
                 $this->assertTrue(in_array($clazz, $bundled_models));
             }
             return TRUE;
         case "list_models_project":
             $models = $gw->listModels(Charcoal_EnumFindPath::FIND_PATH_PROJECT);
             $this->assertEquals(6, count($models));
             $bundled_models = array('BlogCategoryTableModel', 'BlogTableModel', 'CommentTableModel', 'ItemTableModel', 'Item2TableModel', 'PostTableModel', 'TestTableModel');
             foreach ($models as $model) {
                 $this->assertTrue($model instanceof Charcoal_ITableModel);
                 $clazz = get_class($model);
                 echo $clazz . PHP_EOL;
                 $this->assertTrue(in_array($clazz, $bundled_models));
             }
             return TRUE;
         case "list_models_application":
             $models = $gw->listModels(Charcoal_EnumFindPath::FIND_PATH_APPLICATION);
             $this->assertEquals(0, count($models));
             return TRUE;
         default:
             break;
     }
     return FALSE;
 }
Exemplo n.º 21
0
 public function close()
 {
     $script = "";
     if ($this->ready === true) {
         $script .= eol() . '});' . eol();
     }
     $script .= '</script>' . eol();
     return $script;
 }
Exemplo n.º 22
0
 protected static function searchClassMap($directory = '', $baseDirectory = '')
 {
     static $classes;
     // Dizin parametreleri / eki içermiyorsa
     // dizin bilgisinin sonuna / ekini ekle.
     $directory = suffix($directory);
     $baseDirectory = suffix($baseDirectory);
     $configClassMap = Config::get('ClassMap');
     $files = glob($directory . '*');
     $files = array_diff($files, isset($configClassMap['classes']) ? $configClassMap['classes'] : array());
     $staticAccessDirectory = SYSTEM_DIR . 'StaticAccess/';
     $eol = eol();
     if (!empty($files)) {
         foreach ($files as $v) {
             // Sadece .php uzantılı dosyalar için işlem yap.
             if (is_file($v)) {
                 $classEx = explode('/', $v);
                 // Sınıf isimleri ve yolları oluşturuluyor...
                 $classInfo = self::tokenClassFileInfo($v);
                 if (isset($classInfo['class'])) {
                     $class = strtolower($classInfo['class']);
                     // İsim alanı varsa oluşturuluyor...
                     if (isset($classInfo['namespace'])) {
                         // İsim alanını oluştur.
                         $className = strtolower($classInfo['namespace']) . '\\' . $class;
                         $classes['namespaces'][$className] = $class;
                     } else {
                         $className = $class;
                     }
                     $classes['classes'][$className] = $v;
                     $useStaticAccess = strtolower(STATIC_ACCESS);
                     // Statik erişim sağlanmak istenen
                     // Statik olmayan sınıfların
                     // sınıf adına Static ön eki getirilerek
                     // bu sınıfların statik kullanımlarının oluşturulması
                     // sağlanabilir.
                     if (strpos($class, $useStaticAccess) === 0) {
                         // Yeni sınıf ismi oluşturuluyor...
                         $newClassName = str_ireplace($useStaticAccess, '', $classInfo['class']);
                         // Yeni sınıf dizini oluşturuluyor...
                         $newPath = str_ireplace($baseDirectory, '', $v);
                         // Yeni StaticAccess/ dizin yolu oluşturuluyor...
                         $pathEx = explode('/', $newPath);
                         array_pop($pathEx);
                         $newDir = implode('/', $pathEx);
                         $dir = $staticAccessDirectory;
                         $newDir = $dir . $newDir;
                         if (!is_dir($dir)) {
                             mkdir($dir, 0777, true);
                         }
                         // Oluşturulacak dizinin var olup olmadığı
                         // kontrol ediliyor...
                         if (!is_dir($newDir)) {
                             // StaticAccess/ dizini içi sınıf dizini oluşturuluyor...
                             mkdir($newDir, 0777, true);
                         }
                         $path = suffix($newDir) . $classInfo['class'] . '.php';
                         // Oluşturulacak dosyanın var olup olmadığı
                         // kontrol ediliyor...
                         if (!file_exists($path)) {
                             // Statik sınıf içeriği oluşturuluyor....
                             $classContent = '<?php' . $eol;
                             $classContent .= 'class ' . $newClassName . ' extends StaticAccess' . $eol;
                             $classContent .= '{' . $eol;
                             $classContent .= "\t" . 'public static function getClassName()' . $eol;
                             $classContent .= "\t" . '{' . $eol;
                             $classContent .= "\t\t" . 'return __CLASS__;' . $eol;
                             $classContent .= "\t" . '}' . $eol;
                             $classContent .= '}';
                             if (!file_put_contents($path, $classContent)) {
                             }
                             die(getErrorMessage('Error', 'fileNotWrite', $path));
                         }
                         $classes['classes'][strtolower($newClassName)] = $path;
                     }
                 }
             } elseif (is_dir($v)) {
                 // Yol bir dizini ifade ediyorsa taramaya devam et.
                 self::searchClassMap($v, $baseDirectory);
             }
         }
     }
     return $classes;
 }
Exemplo n.º 23
0
 public function select($name = '', $options = array(), $selected = '', $_attributes = '', $multiple = false)
 {
     if (!is_string($name)) {
         $name = '';
     }
     if (!isValue($selected)) {
         $selected = '';
     }
     // Herhangi bir id değeri tanımlanmamışsa
     // Id değeri olarak isim bilgisini kullan.
     $id = isset($_attributes["id"]) ? $_attributes["id"] : $name;
     // Id değer tanımlanmışsa
     // Id değeri olarak tanımalanan değeri kullan.
     $id_txt = isset($_attributes["id"]) ? '' : "id=\"{$id}\"";
     // Son parametrenin durumuna multiple olması belirleniyor.
     // Ancak bu parametrenin kullanımı gerekmez.
     // Bunun için multiple() yöntemi oluşturulmuştur.
     if ($multiple === true) {
         $multiple = 'multiple="multiple"';
     } else {
         $multiple = '';
     }
     $selectbox = '<select ' . $multiple . ' name="' . $name . '" ' . $id_txt . Html::attributes($_attributes) . '>';
     if (is_array($options)) {
         foreach ($options as $key => $value) {
             if ($selected == $key) {
                 $select = 'selected="selected"';
             } else {
                 $select = "";
             }
             $selectbox .= '<option value="' . $key . '" ' . $select . '>' . $value . '</option>' . eol();
         }
     }
     $selectbox .= '</select>' . eol();
     return $selectbox;
 }
Exemplo n.º 24
0
 protected function _document($xml = '', $tab = '', $start = 0)
 {
     static $start;
     $eof = eol();
     $output = '';
     $tab = str_repeat("\t", $start);
     if (!isset($xml[0])) {
         $xml = array($xml);
         $start = 0;
     }
     foreach ($xml as $data) {
         $name = isset($data['name']) ? $data['name'] : '';
         $attr = isset($data['attr']) ? $data['attr'] : '';
         $content = isset($data['content']) ? $data['content'] : '';
         $child = isset($data['child']) ? $data['child'] : '';
         $output .= "{$tab}<{$name}" . Html::attributes($attr) . ">";
         if (!empty($content)) {
             $output .= $content;
         } else {
             if (!empty($child)) {
                 $output .= $eof . $this->_document($child, $tab, $start++) . $tab;
             } else {
                 $output .= $content;
             }
         }
         $output .= "</" . $name . ">" . $eof;
     }
     return $output;
 }
Exemplo n.º 25
0
 public static function onUnhandledError($errno, $errstr, $errfile, $errline)
 {
     $flags_handled = error_reporting();
     if (Charcoal_System::isBitSet($errno, $flags_handled, Charcoal_System::BITTEST_MODE_ANY)) {
         $errno_disp = Charcoal_System::phpErrorString($errno);
         echo "smarty error [errno]{$errno}({$errno_disp}) [errstr]{$errstr} [errfile]{$errfile} [errline]{$errline}" . eol();
     }
     return TRUE;
     // Otherwise, ignore all errors
 }
Exemplo n.º 26
0
 public function create()
 {
     $combineAnimation = func_get_args();
     $animate = eol() . "\t" . JQ::selector($this->selector);
     $animate .= $this->complete();
     if (!empty($combineAnimation)) {
         foreach ($combineAnimation as $animation) {
             $animate .= $animation;
         }
     }
     $animate .= ";" . eol();
     return $this->_tag($animate);
 }
Exemplo n.º 27
0
 protected function _object($array)
 {
     $object = '';
     if (is_array($array)) {
         $object = '';
         $object .= "{";
         if (!empty($array)) {
             foreach ($array as $k => $v) {
                 $object .= $k . ":" . $this->_isCode($v) . ", ";
             }
         }
         $object = substr($object, 0, -2);
         $object .= "}";
     } else {
         $object = eol() . "\"{$array}\"";
     }
     return $object;
 }
Exemplo n.º 28
0
 public function content()
 {
     $colNo = 1;
     $rowNo = 1;
     $table = '';
     $eol = eol();
     $elements = func_get_args();
     foreach ($elements as $key => $element) {
         $table .= $eol . "\t" . '<tr>' . $eol;
         if (is_array($element)) {
             foreach ($element as $k => $v) {
                 $val = $v;
                 $attr = "";
                 if (is_array($v)) {
                     $attr = Html::attributes($v);
                     $val = $k;
                 }
                 $table .= "\t\t" . '<td' . $attr . '>' . $val . '</td>' . $eol;
                 $colNo++;
             }
         }
         $table .= "\t" . '</tr>' . $eol;
         $rowNo++;
     }
     $this->table = $table;
     return $this;
 }
Exemplo n.º 29
0
/**
 * method to update username and password passed via POST
 * @global object $_files
 * @return string HTML success message or empty when there was no update
 */
function update_user_settings()
{
    global $_files;
    $ret = '';
    if (!array_key_exists('vpn_provider', $_POST)) {
        throw new Exception('FATAL ERROR: vpn_provider not set');
    }
    //get name of login file
    $login_file = VPN_get_loginfile($_POST['vpn_provider']);
    $tmp = explode('/', $login_file);
    $session = $tmp[1];
    //session requires no path
    $username = array_key_exists('username', $_POST) ? $_POST['username'] : '';
    $password = array_key_exists('password', $_POST) ? $_POST['password'] : '';
    //create an empty file and set permissions
    if (!file_exists($login_file)) {
        file_put_contents($login_file, ' ');
        chmod($login_file, 0660);
        //r+w for owner and group
        @chown($login_file, 'root');
        //this line should not work due to security restrictions
        chgrp($login_file, 'vpnvm');
    }
    //can not handle empty values right now ... but there is a reset command
    if ($username != '') {
        if (file_exists($login_file)) {
            $c = $_files->readfile($login_file);
            $ct = explode("\n", eol($c));
            if ($username !== $ct[0]) {
                $content = "{$username}\n{$ct['1']}";
                //write new username with old password
                $_files->writefile($login_file, $content);
                //back to login-pia.conf
                $ret .= "<div id=\"feedback\" class=\"feedback\">Username updated</div>\n";
                unset($_SESSION[$session]);
                unset($_SESSION[$login_file]);
            }
        }
    }
    if ($password != '') {
        if (file_exists($login_file)) {
            $c = $_files->readfile($login_file);
            $ct = explode("\n", eol($c));
            if ($password !== $ct[1]) {
                $content = "{$ct['0']}\n{$password}";
                //write old username with new password
                $_files->writefile($login_file, $content);
                //back to login-pia.conf
                $ret .= "<div id=\"feedback\" class=\"feedback\">Password updated</div>\n";
                unset($_SESSION[$session]);
                unset($_SESSION[$login_file]);
            }
        }
    }
    return $ret;
}
Exemplo n.º 30
0
 protected function _input($name = "", $value = "", $_attributes = array(), $type = '')
 {
     if ($name !== '') {
         $_attributes['name'] = $name;
     }
     if ($value !== '') {
         $_attributes['value'] = $value;
     }
     if (isset($this->settings['attr'])) {
         $_attributes = array_merge($this->settings['attr'], (array) $_attributes);
     }
     $this->settings = array();
     return '<input type="' . $type . '"' . Html::attributes($_attributes) . '>' . eol();
 }