public function __construct(CustomField &$field, $data = null)
 {
     if ($field === null) {
         Core::throwError('First parameter is null.');
     }
     $this->field = $field;
     $this->setData($data);
 }
 public function __construct($position, $baseUri, array $mainFields)
 {
     if (count($mainFields) == 0) {
         Core::throwError('Please provide fields to show.', INTERNAL_ERROR);
     }
     $this->position = Core::constructObject($position);
     $this->baseUri = $baseUri;
     $this->mainFields = $mainFields;
 }
 public function load($file)
 {
     $file = $this->getFilePath($file);
     if (file_exists($file)) {
         return new TemplateBit($file);
     } else {
         Core::throwError("Template not found: '{$file}'");
         return null;
     }
 }
 protected function loadMenu()
 {
     require self::MENU_FILE;
     $this->menu = $config;
     if (empty($this->menu['Pages'])) {
         Core::throwError("No pages in admin menu table found.", INTERNAL_ERROR);
     }
     foreach ($this->menu['Pages'] as $key => $menuClass) {
         $this->menu['Pages'][$key] = Core::constructObject($menuClass);
     }
 }
 public static function checkACL($gid, $right)
 {
     $cache = Core::getObject('Core.Cache.CacheServer');
     $p = $cache->load('permissions');
     $acl = $p->getPermissions($gid);
     if (isset($acl[$right])) {
         return $acl[$right] == 1;
     } else {
         Core::throwError('No permission with name "' . $right . '" found.', INTERNAL_NOTICE);
         return false;
     }
 }
 public function formatDataForDb($data)
 {
     if ($data !== null) {
         $dt = DT::createFromFormat(Config::get('intl.date_format'), $data);
         if ($dt !== null) {
             $data = $dt->dbDate();
         } else {
             Core::throwError('Could not convert DateTime-data for database.');
         }
     }
     return $data;
 }
/**
 * Loads the required classes automatically from ClassManager (only indexed classes).
 *
 * @param string Class Name
 */
function __autoload($className)
{
    if ($className === 'parent') {
        // Avoid calling parent when using callback function.
        // See: http://www.php.net/manual/de/function.call-user-func.php#106391
        return;
    }
    $classManager = Core::getObject('Core.System.ClassManager');
    if (Config::get('core.debug')) {
        Core::throwError("Autoloaded class with name '{$className}'", INTERNAL_DEBUG);
    }
    $file = $classManager->loadFile($className);
    if ($file == null) {
        Core::throwError('Class "{$className}" not found', INTERNAL_ERROR);
    }
}
Exemplo n.º 8
0
 /**
  * Attempts to open a connection to the MySQL Server.
  *
  * The host can be either a host name or an IP address. Passing the null value or the
  * string "localhost" to this parameter, the local host is assumed. If successful,
  * the the function will return an object representing the connection to the database,
  * or null on failure. The port and socket parameters are used in conjunction with the
  * host parameter to further control how to connect to the database server. The port
  * parameter specifies the port number to attempt to connect to the MySQL server on,
  * while the socket parameter specifies the socket or named pipe that should be used.
  * If all values are null, the data from the configuration file will be read and used.
  * If one value is not null, the data specified will be used. Default values are in this
  * case:<br>
  * Host: localhost<br>
  * Username: root<br>
  * Password: <empty> (An warning will occur)<br>
  * Port: 3306<br>
  * Socket: null<br>
  *
  * @param string Host
  * @param string Username
  * @param string Password
  * @param int Port
  * @param string Socket or null
  **/
 public function connect($username = null, $password = null, $host = null, $port = null, $socket = null)
 {
     if (false == ($username == null && $password == null && $host == null && $port == null && $socket == null)) {
         $this->username = empty($username) ? 'root' : $username;
         $this->password = $password;
         if (empty($this->password) == true) {
             Core::throwError("Password for SQL-Connection is empty. It is highly recommended to set a password for your Database.");
         }
         $this->host = empty($host) ? 'localhost' : $host;
         $this->port = empty($port) ? '3306' : $port;
         $this->socket = $socket;
     }
     $host = $this->host . iif(is_id($port), ":{$this->port}") . iif(!empty($this->socket), ":{$this->socket}");
     $this->connection = mysqli_connect($host, $this->username, $this->password);
     if ($this->hasConnection() == false) {
         Core::throwError('Could not connect to database! Pleasy try again later or check the database settings!', INTERNAL_ERROR);
     }
 }
 /**
  * Loads the class with the given class name from the index.
  *
  * @param	string	Class Name
  * @return	mixed	Filename or null on failure
  * @access	public
  */
 public function loadFile($className)
 {
     if (isset($this->index[$className]) == true) {
         if (file_exists($this->index[$className]) == true) {
             $filename = $this->index[$className];
             include_once $filename;
         } else {
             $this->deleteIndex();
             Core::throwError('ClassManager index seems to be outdated. File for class ' . $className . ' not found: ' . $this->index[$className] . '. New index scan scheduled. Please refresh this page.', INTERNAL_ERROR);
             $filename = null;
         }
     } else {
         $this->deleteIndex();
         Core::throwError('ClassManager has no class with name ' . $className . ' indexed. New index scan scheduled. Please refresh this page.', INTERNAL_ERROR);
         $filename = null;
     }
     return $filename;
 }
 public static function findNearestStep($value, $min = 0, $max = 5, $step = 0.5)
 {
     if ($step <= 0) {
         Core::throwError("Step has to be > 0, given {$step}.", INTERNAL_ERROR);
     }
     if ($value <= $min) {
         return $min;
     } else {
         if ($value >= $max) {
             return $max;
         } else {
             $margin = $step / 2;
             for ($i = $min; $i < $max; $i += $step) {
                 if ($value > $i - $margin && $value <= $i + $margin) {
                     return $i;
                 }
             }
             return $max;
         }
     }
 }
 /**
  * Looks for class names in a PHP code
  *
  * @param string File to scan for class name.
  * @todo Reine PHP Alternative um Klassen zu erkennen (RegExp)
  */
 private function parse($filepath)
 {
     $file = new File($filepath);
     if ($file->exists() == true) {
         $code = $file->read();
         $tokens = @token_get_all($code);
         foreach ($tokens as $token) {
             if (!isset($token[0])) {
                 continue;
             }
             // next token after this one is our desired class name
             if ($token[0] == T_CLASS) {
                 $this->next = true;
             }
             if ($token[0] == T_STRING && $this->next === true) {
                 if (isset($this->data[$token[1]]) == true) {
                     Core::throwError('Class with name "' . $token[1] . '" was found more than once. Only file "' . $file->absPath() . '" has been indexed!', INTERNAL_NOTICE);
                 }
                 $this->data[$token[1]] = $file->relPath();
                 $this->next = false;
             }
         }
     }
 }
Exemplo n.º 12
0
 /**
  * Reads a file (in three different ways).
  *
  * If the parameter is -1 (FILE_COMPLETE) or if no parameter is given, the complete file will be returned at once.<br />
  *
  * If the parameter is -2 (FILE_LINES) or -3 (FILE_LINES_TRIM), the function returns the file in an array.
  * Each element of the array corresponds to a line in the file.
  * If the parameter is -2 (FILE_LINES) the newline/carriage return will be still attached, -3 (FILE_LINES_TRIM) removes them at the end.<br />
  *
  * If the parameter is > 0, the function reads up to the specified amount of bytes from the file pointer.
  * When the end of file (EOF) is reached the function returns null.
  * If the file does not exist or an error occurs, null will be returned.
  *
  * Example:
  * <code>
  *	$f = new File('file.txt');
  *	while ($data = $f->read(1024)) {
  *		echo $data;
  *	}
  * </code>
  *
  * @param	int	Type to read the file. Standard: -1 (FILE_COMPLETE)
  * @return	mixed	Requested content (as array or string) or null
  * @todo Better trim for FILE_LINES_TRIM (replace foreach with ...?)
  */
 public function read($type = FILE_COMPLETE)
 {
     if ($this->readable() == false) {
         return null;
     }
     if ($type == FILE_COMPLETE) {
         $contents = file_get_contents($this->path);
         if ($contents != false) {
             return $contents;
         } else {
             return null;
         }
     } elseif ($type == FILE_LINES || $type == FILE_LINES_TRIM) {
         // When files are bigger than 8 MB then use another method to read file into array.
         if ($this->size() <= 8 * 1024 * 1024) {
             $array = file($this->path);
         } else {
             $array = array();
             $this->handle = fopen($this->path, 'rb');
             if (is_resource($this->handle) == false) {
                 return null;
             }
             while (feof($this->handle) == false) {
                 $array[] = fgets($this->handle);
             }
             fclose($this->handle);
         }
         if ($array != false) {
             if ($type == FILE_LINES_TRIM) {
                 foreach ($array as $key => $value) {
                     $array[$key] = rtrim($value, "\r\n");
                 }
             }
             return $array;
         } else {
             return null;
         }
     } elseif ($type > 0) {
         if (is_resource($this->handle) == false) {
             $this->handle = fopen($this->path, 'rb');
             if (is_resource($this->handle) == false) {
                 return null;
             }
         }
         if (feof($this->handle) == false) {
             $part = fread($this->handle, $type);
             if ($part != false) {
                 return $part;
             } else {
                 return null;
             }
         } else {
             fclose($this->handle);
             return null;
         }
     } else {
         Core::throwError('The specified type (' . $type . ') to read the file "' . $this->path . '" is not supported.');
         return null;
     }
 }
Exemplo n.º 13
0
 /**
  * 显示控制器对应的模板输出内容
  * @param string $name
  */
 public function display($name = '')
 {
     $engine = isset($GLOBALS['_template_engine']) ? $GLOBALS['_template_engine'] : 'php';
     if (is_file($name)) {
         $themeFile = $name;
     } else {
         $themeFile = $this->getThemeFile($name);
     }
     if (!is_file($themeFile)) {
         if (APP_DEBUG) {
             $filestr = ' [' . $themeFile . ']';
         } else {
             $filestr = '';
         }
         $args = array('{template_file}' => $filestr);
         Core::throwError('template_file_not_exist', __FILE__, __LINE__, $args);
     }
     // 需要获取缓存冲区内容
     if (!empty($_GET['ob_html'])) {
         ob_start();
     }
     if ($engine == 'php') {
         include $themeFile;
     } else {
         if ($engine == 'dophin') {
             $suffix = isset($GLOBALS['_suffix']) ? $GLOBALS['_suffix'] : '';
             $left = isset($GLOBALS['_tpl_delimiter_left']) ? $GLOBALS['_tpl_delimiter_left'] : '';
             $right = isset($GLOBALS['_tpl_delimiter_right']) ? $GLOBALS['_tpl_delimiter_right'] : '';
             $tpl = new Template($themeFile, $this->themePath, $suffix, $left, $right);
             $tpl->load($this->_vars);
         } else {
             echo 'unknow template engine!';
         }
     }
     // 输出内容到html静态文件
     if (!empty($_GET['make_html'])) {
         if (!empty($_GET['html_file'])) {
             $htmlFile = HTML_PATH . $_GET['html_file'];
         } else {
             if (isset($GLOBALS['html_file'])) {
                 $htmlFile = HTML_PATH . $GLOBALS['html_file'];
             } else {
                 if ($this->html_cache_file) {
                     $htmlFile = HTML_PATH . $this->html_cache_file;
                 } else {
                     if (!empty($_GET['id']) && !ctype_digit($_GET['id'])) {
                         $htmlFile = HTML_PATH . $this->co . '_' . $this->do . '_' . $_GET['id'] . '.html';
                     } else {
                         $htmlFile = HTML_PATH . $this->co . '_' . $this->do . '.html';
                     }
                 }
             }
         }
         $dir = dirname($_GET['html_file']);
         if (!is_dir($dir)) {
             mkdir($dir, 0775, true);
         }
         $html = ob_get_contents();
         file_put_contents($_GET['html_file'], $html);
         if ($_GET['html_display']) {
             ob_end_flush();
         } else {
             ob_end_clean();
             return true;
         }
     }
     if ($GLOBALS['_output_process_time']) {
         echo microtime(1) - APP_BEGIN_TIME;
     }
     // 显示完页面不执行后面代码
     exit;
 }
 /**
  * This method loads a cache item and adds it to the cache manager.
  *
  * If the cache class file is not found or the cache file is corrupt a new
  * CacheItem will be constructed. An USER_NOTICE will be thrown.
  *
  * @param string Name of the cache file (class.cache_ will be added before the name and .php will be added after the name)
  * @param string Path to the folder with the cache files or null for default source directory.
  * @return object
  **/
 public function load($name, $sourcedir = null)
 {
     $this->loadClass($name, $sourcedir);
     $className = "cache_{$name}";
     if (class_exists($className)) {
         $object = new $className($name, $this->cachedir);
     } elseif (class_exists($name)) {
         $object = new $name($name, $this->cachedir);
     } else {
         Core::throwError('Cache Class of type "' . $name . '" could not be loaded.', INTERNAL_NOTICE);
         $object = new CacheItem($name, $this->cachedir);
     }
     $this->data[$name] = $object;
     return $object;
 }
Exemplo n.º 15
0
 /**
  * Magic call for FTP functions using
  * this class resource
  *
  * This allows usage like this:
  *
  * $ftp = new ftp('ftp://example.com');
  * $ftp->ftp_login('username', 'password');
  * $ftp->ftp_put('source', 'destination');
  *
  * @param   string      $func       - The function name
  * @param   mixed       $a          - The function parameters
  * @return  mixed
  */
 public function __call($func, $a)
 {
     if (strstr($func, 'ftp_') !== false && function_exists($func)) {
         array_unshift($a, $this->conn);
         return call_user_func_array($func, $a);
     } else {
         Core::throwError('Internal Invalid call: ' . $func);
     }
 }
Exemplo n.º 16
0
 /**
  * Checks that the value of the specified CHMOD is correct.
  *
  * If the parameter is FALSE (default), this method will abort the script if the CHMOD is incorrect.
  * If the parameter is TRUE, this method will return false if the CHMOD is incorrect. If it is correct TRUE will be returned.
  *
  * @param boolean Set this parameter to TRUE to return the result of the check. FALSE will abort the script when an error occurs.
  * @return boolean If the parameter is true a boolean will be returned.
  */
 private function checkMode($disableError = false)
 {
     if ($this->chmod == null) {
         if (!$disableError) {
             Core::throwError('You have not set a value for CHMOD.', INTERNAL_ERROR);
         }
         return false;
     } else {
         $decimal = $this->getDecimal();
         if ($decimal < 0 || $decimal > 511) {
             if (!$disableError) {
                 Core::throwError('Specified CHMOD is invalid.', INTERNAL_ERROR);
             }
             return false;
         } else {
             return true;
         }
     }
 }
Exemplo n.º 17
0
 /**
  * Updates the value for the configuration key specified as parameter.
  *
  * If the third parameter is null (it is the default value) the script tries to get
  * the value by name (without group!) from the input data (query string). If no data is found
  * the default value from Variables::get() for the specified type will be used.
  *
  * This function throws a notice if the key is not found.
  *
  * The data won't be saved by this function! You have to call Config::save() for this!
  *
  * @see Variables::get()
  * @see Config::save()
  * @param string Config key in the format Group.Key
  * @param int Type of variable (one of the standard types that are accepted by Request::get().
  * @param mixed Value to change to specified config key.
  **/
 public static function set($key, $type = VAR_NONE, $value = null)
 {
     if (self::$data == null) {
         self::baseConfig();
     }
     list($sgroup, $name) = explode('.', $key, 2);
     if ($value == null) {
         $value = Request::get($name, $type);
     }
     if (isset(self::$data[$key]) == true) {
         self::$data[$key] = $value;
         if ($type == VAR_INT || $type == VAR_ARR_INT) {
             $value = Sanitize::saveInt($value);
         }
         self::$changes[$key] = array('key' => $key, 'value' => $value, 'type' => $type);
     } else {
         Core::throwError("Config::set() - Specified key does not exist.");
     }
 }
Exemplo n.º 18
0
 protected function transformPathToModule($modules, $package, &$query, $uriToUse = '!')
 {
     foreach ($modules as $uri => $className) {
         if (count($query) > 0) {
             if (strcasecmp($uri, $query[0]) == 0) {
                 array_shift($query);
                 if (is_array($className)) {
                     // we are skipping this level
                     return $this->transformPathToModule($modules[$uri], $package, $query, $uriToUse);
                 } else {
                     $uriToUse = $uri;
                 }
             }
         }
     }
     // Not found, try the default page if it has levels beneath
     if (is_array($modules['!'])) {
         $r = $this->transformPathToModule($modules['!'], $package, $query, null);
         if ($r !== null) {
             return;
             // we are skipping this level
         }
     }
     if (!empty($modules[$uriToUse]) && !is_array($modules[$uriToUse])) {
         $class = $this->convertModuleToClass($package, $modules[$uriToUse]);
         if (Core::classExists($class)) {
             $this->requestedClass = $class;
             $this->originalModule = $uriToUse;
         } else {
             Core::throwError("Routed class '{$class}' not found.");
         }
     }
     return $uriToUse;
 }
Exemplo n.º 19
0
 /**
  * Gets a new instance of an object with the class name passed as parameter.
  *
  * To create a new instance the class is loaded from the source folder.
  * Null will be returned on failure.
  *
  * Example names of classes:<br />
  * - Core.Core is this class<br />
  * - Core.System.ClassManager is the ClassManager class in Viscacha/System/class.ClassManager.php<br />
  * The package names are case sensitive!
  *
  * @param string $objectName Name of package
  * @param mixed First parameter for the constructor of the object. (Optional)
  * @param mixed Second parameter for the constructor of the object. (Optional)
  * @param mixed Third parameter for the constructor of the object. (Optional)
  * @param mixed n-th parameter for the constructor of the object. (Optional)
  * @return object Returns the object or null on failure
  * @todo Replace eval variant with call_user_func_array().
  */
 public static function constructObject()
 {
     $numArgs = func_num_args();
     if ($numArgs == 0) {
         Core::throwError("Missing argument 1 for Core::constructObject()");
     }
     $objectName = func_get_arg(0);
     $parts = explode('.', $objectName);
     $className = array_pop($parts);
     self::loadClass($objectName);
     if (class_exists($className) == true) {
         if ($numArgs == 1) {
             return new $className();
         } elseif ($numArgs == 2) {
             // Just a bit faster then the eval shit...
             return new $className(func_get_arg(1));
         } else {
             $argString = array();
             $argList = func_get_args();
             for ($x = 1; $x < $numArgs; $x++) {
                 $argString[] = '$argList[' . $x . ']';
             }
             $argString = implode(',', $argString);
             return eval("return new {$className}({$argString});");
         }
     } else {
         self::throwError("Can not find class with name '{$className}'");
         return null;
     }
 }
Exemplo n.º 20
0
 public function isAllowed($right)
 {
     $this->loadACL();
     if (isset($this->acl[$right])) {
         return $this->acl[$right] == 1;
     } else {
         Core::throwError('No permission with name "' . $right . '" found.', INTERNAL_NOTICE);
         return false;
     }
 }
Exemplo n.º 21
0
 /**
  * Finished Benchmarks and log texts will be added to the logfile.
  *
  * Each benchmark is one row in the file.
  * After calling this function successfully, the finished benchmarks array and the log data array are empty.
  * It is not recommended to use this function directly.
  * If an error occurs while writing the file a warning will be thrown.
  */
 public function saveFile()
 {
     $benchmarks = array();
     //add new line if file is not empty
     $text = iif($this->file->size() != 0 && $this->file->size() != false, "\r\n");
     $benchmarks = $this->getBenchmarkStringArray();
     $text .= implode("\r\n", array_merge($this->logs, $benchmarks));
     if ($this->file->write($text, true) === false) {
         Core::throwError('Could not write log file in method Debug::saveFile().');
     } else {
         $this->clear();
     }
 }
 protected function parseInt($var)
 {
     if (!is_string($var) && !is_numeric($var)) {
         Core::throwError('Database::parseInt() can only convert strings and numerical data to integers.');
     }
     if (is_string($var)) {
         $var = trim($var);
     }
     return intval($var);
 }