예제 #1
0
 /**
  * gets a file pointer from a specified file
  * @param   string $filename
  * @param array $options
  * @return  mixed $res file pointer | true | false
  */
 public static function getFPFromFile($filename, $options = array())
 {
     if (isset($options)) {
         self::$options = $options;
     }
     if (!file_exists($filename)) {
         self::$errors[] = lang::translate('File does not exists') . ' : ' . $options['filename'];
         return false;
     }
     if (isset($options['maxsize'])) {
         $size = filesize($options['filename']);
         //  check the file is less than the maximum file size
         if ($size > $options['maxsize']) {
             $error = lang::translate('File is too large.');
             $error .= lang::translate('Max size is ') . bytes::bytesToGreek($options['maxsize']);
             error_log($error);
             self::$errors[] = $error;
             return false;
         }
     }
     // check for right content
     if (isset($options['allow_mime'])) {
         $type = file::getMime($options['filename']);
         if (!in_array($type, $options['allow_mime'])) {
             self::$errors[] = lang::translate('This Content type is not allowed') . MENU_SUB_SEPARATOR_SEC . $type;
             return false;
         }
     }
     $fp = fopen($filename, 'rb');
     return $fp;
 }
 protected function _doImages_inline_callback($matches)
 {
     $whole_match = $matches[1];
     $alt_text = $matches[2];
     $url = $matches[3] == '' ? $matches[4] : $matches[3];
     $title =& $matches[7];
     $alt_text = $this->encodeAttribute($alt_text);
     $url = $this->encodeAttribute($url);
     $type = $this->getType($url);
     if (!$this->isFigure($type, $url)) {
         return $str = "![{$alt_text}]({$url})";
     }
     if (empty($alt_text)) {
         $alt_text = '';
     }
     $video = lang::translate('Video');
     $figure = lang::translate('Figure');
     $id = uniqid();
     $str = "<div id =\"{$id}\">";
     $str .= '</div>';
     $str .= "![{$alt_text}]({$url})";
     if ($type == 'mp4') {
         $m = ++self::$m;
         self::$media['movie'][] = "{$video} {$m} [{$alt_text}](#{$id}).";
     } else {
         $f = ++self::$f;
         self::$media['figure'][] = "{$figure} {$f} [{$alt_text}](#{$id}).";
     }
     return $str;
 }
예제 #3
0
    public static function init()
    {
        $m = new modules();
        $m->autoloadRegister();
        // Define all system constants
        conf::defineCommon();
        // Set include path - based on config.ini
        conf::setIncludePath();
        // Load config file
        conf::load();
        // Set log level - based on config.ini
        log::setErrorLog();
        log::setLogLevel();
        // Set locales
        intl::setLocale();
        // Set default timezone
        intl::setTimezone();
        // Load language
        $l = new lang();
        $base = conf::pathBase();
        $l->setDirsInsideDir("{$base}/modules/");
        $l->setDirsInsideDir("{$base}/htdocs/templates/");
        $l->setSingleDir("{$base}/vendor/diversen/simple-php-classes");
        $l->loadLanguage(conf::getMainIni('lang'));
        // Init parent with base commands
        parent::init();
        self::$parser->description = <<<EOF
                    _ _       _     
  ___ ___  ___  ___| (_)  ___| |__  
 / __/ _ \\/ __|/ __| | | / __| '_ \\ 
| (_| (_) \\__ \\ (__| | |_\\__ \\ | | |
 \\___\\___/|___/\\___|_|_(_)___/_| |_|

    Modulized Command line program

EOF;
        self::$parser->version = '0.0.1';
        // Adding a main option for setting domain
        self::$parser->addOption('domain', array('short_name' => '-d', 'long_name' => '--domain', 'description' => 'Domain to use if using multi hosts. If not set we will use default domain', 'action' => 'StoreString', 'default' => 'default'));
        self::beforeParse();
    }
예제 #4
0
 /**
  * checks if a user if locked
  * if locked set 403 error
  * @return boolean $res true if locked else false
  */
 public static function lockedSet403($message = null)
 {
     if (self::locked()) {
         moduleloader::$status['403'] = true;
         if (!$message) {
             $message = lang::translate('You can not access this page, because your account has been locked!');
         }
         moduleloader::$message = $message;
         return true;
     }
     return false;
 }
예제 #5
0
 /**
  * method for creating a confirm form
  * @param string $legend text of the legend
  * @param string $submit text of the submit
  * @return string $form the confirm form.
  */
 public static function confirmForm($legend, $submit_value = null, $submit_name = 'submit')
 {
     $html = new html();
     $html->setAutoEncode(true);
     $html->formStart('custom_delete_form');
     $html->legend($legend);
     if (!$submit_value) {
         $submit_value = lang::translate('Submit');
     }
     $html->submit($submit_name, $submit_value);
     $html->formEnd();
     return $html->getStr();
 }
예제 #6
0
 /**
  * Get translations
  * @return array $ary array with translations
  */
 public function getTranslations()
 {
     if (class_exists('\\diversen\\lang')) {
         return array('altPrev' => \diversen\lang::translate('Previous'), 'altNext' => \diversen\lang::translate('Next page'), 'altPage' => \diversen\lang::translate('Page'));
     } else {
         return array('altPrev' => 'Previous', 'altNext' => 'Next page', 'altPage' => 'Page');
     }
 }
예제 #7
0
 /**
  * method for getting child menus to a module. 
  * @param  string   $module
  * @return array    children menus items
  */
 public static function getChildrenMenus($module)
 {
     $db = new db();
     $children = $db->selectAll('menus', null, array('parent' => $module));
     foreach ($children as $key => $val) {
         $children[$key]['title'] = lang::translate($val['title']);
     }
     return $children;
 }
예제 #8
0
 /**
  * gets  a messages attached parts
  * @param type $message
  * @return array $parts attachments
  */
 function getParts($message)
 {
     $parts = array();
     $gen_sub = false;
     try {
         $parts['subject'] = $message->subject;
     } catch (Exception $e) {
         $gen_sub = true;
     }
     $parts['plain'] = '';
     $parts['images'] = array();
     $parts['movies'] = array();
     $parts['unknown'] = array();
     $parts['date'] = $message->getHeader('Date', 'string');
     $from = $message->getHeader('From', 'string');
     $parts['from'] = trim($this->extractMailFrom($from));
     $parts['html'] = array();
     // test if it is not a multi part message
     if (!$message->isMultipart()) {
         $parts['plain'] = $this->decodePlain($message);
     }
     foreach (new RecursiveIteratorIterator($message) as $part) {
         try {
             $type = $this->getContentType($part);
             if ($type == 'text/plain') {
                 // text plain
                 $parts['plain'] = $this->decodePlain($part);
             } else {
                 if ($type == 'image/jpeg' || $type == 'image/png' || $type == 'image/jpg') {
                     // image
                     $file = base64_decode($part->getContent());
                     $human = $this->getHeadersHuman($part);
                     $parts['images'][] = array('name' => $human['content-name'], 'type' => $human['content-type'], 'file' => $file);
                 } else {
                     if ($type == 'text/html') {
                         // thtml
                         $parts['html'][] = $part->getContent();
                     } else {
                         // else unknown
                         $parts['unknown'][] = $part;
                     }
                 }
             }
         } catch (Exception $e) {
             error_log($e->getMessage());
         }
     }
     if (empty($parts['plain'])) {
         $parts['plain'] = lang::translate('No title');
     }
     if ($gen_sub) {
         $parts['subject'] = strings::substr2($parts['plain'], 20, 3, false);
     }
     return $parts;
 }
예제 #9
0
 /**
  * Run the system 
  */
 public function run()
 {
     // Register an autoloader for loading modules from mopdules dir
     $m = new modules();
     $m->autoloadRegister();
     // define HTML constants
     common::defineConstants();
     // define global constants - based on base path
     conf::defineCommon();
     // set include paths
     conf::setIncludePath();
     // load config file
     conf::load();
     if (conf::getMainIni('debug')) {
         log::enableDebug();
     }
     // set public file folder in file class
     file::$basePath = conf::getFullFilesPath();
     // utf-8
     ini_set('default_charset', 'UTF-8');
     // load config/config.ini
     // check if there exists a shared ini file
     // shared ini is used if we want to enable settings between hosts
     // which share same code base.
     // e.g. when updating all sites, it is a good idea to set the following flag
     // site_update = 1
     // this flag will send correct 503 headers, when we are updating our site.
     // if site is being updaing we send temporarily headers
     // and display an error message
     if (conf::getMainIni('site_update')) {
         http::temporarilyUnavailable();
     }
     // set a unified server_name if not set in config file.
     $server_name = conf::getMainIni('server_name');
     if (!$server_name) {
         conf::setMainIni('server_name', $_SERVER['SERVER_NAME']);
     }
     // redirect to uniform server name is set in config.ini
     // e.g. www.testsite.com => testsite.com
     $server_redirect = conf::getMainIni('server_redirect');
     if (isset($server_redirect)) {
         http::redirectHeaders($server_redirect);
     }
     // redirect to https is set in config.ini
     // force anything into ssl mode
     $server_force_ssl = conf::getMainIni('server_force_ssl');
     if (isset($server_force_ssl)) {
         http::sslHeaders();
     }
     // catch all output
     ob_start();
     // Create a db connection
     $db_conn = array('url' => conf::getMainIni('url'), 'username' => conf::getMainIni('username'), 'password' => conf::getMainIni('password'), 'db_init' => conf::getMainIni('db_init'));
     // Other options
     // db_dont_persist = 0
     // dont_die = 0 // Set to one and the connection don't die because of
     // e.g. no database etc. This will return NO_DB_CONN as string
     //$url = conf::getMainIni('url');
     connect::connect($db_conn);
     // init module loader.
     $ml = new moduleloader();
     // initiate uri
     uri::getInstance();
     // runlevel 1: merge db config
     $ml->runLevel(1);
     // select all db settings and merge them with ini file settings
     $db_Settings = [];
     if (moduleloader::moduleExists('settings')) {
         $db_settings = q::select('settings')->filter('id =', 1)->fetchSingle();
     }
     // merge db settings with config/config.ini settings
     // db settings override ini file settings
     conf::$vars['coscms_main'] = array_merge(conf::$vars['coscms_main'], $db_settings);
     // run level 2: set locales
     $ml->runLevel(2);
     // set locales
     intl::setLocale();
     // set default timezone
     intl::setTimezone();
     // runlevel 3 - init session
     $ml->runLevel(3);
     // start session
     session::initSession();
     // Se if user is logged in with SESSION
     if (!session::isUser()) {
         // If not logged in check system cookie
         // This will start the session, if an appropiate cookie exists
         session::checkSystemCookie();
     }
     // Check account
     $res = session::checkAccount();
     if (!$res) {
         // Redirect to main page if user is not allowed
         // With current SESSION or COOKIE
         http::locationHeader('/');
     }
     // set account timezone if enabled - can only be done after session
     // as user needs to be logged in
     intl::setAccountTimezone();
     // run level 4 - load language
     $ml->runLevel(4);
     // load all language files
     $l = new lang();
     $base = conf::pathBase();
     $htdocs = conf::pathHtdocs();
     $l->setDirsInsideDir("{$base}/modules/");
     $l->setDirsInsideDir("{$htdocs}/templates/");
     $l->setSingleDir("{$base}/vendor/diversen/simple-php-classes");
     $l->setSingleDir("{$base}/vendor/diversen/simple-pager");
     $l->loadLanguage(conf::getMainIni('lang'));
     // runlevel 5
     $ml->runLevel(5);
     // load routes if any
     dispatch::setDbRoutes();
     // check db routes or load defaults
     $db_route = dispatch::getMatchRoutes();
     if (!$db_route) {
         $ml->setModuleInfo();
         $ml->initModule();
     } else {
         dispatch::includeModule($db_route['method']);
     }
     // After module has been loaded.
     // You can e.g. override module ini settings
     $ml->runLevel(6);
     // Init layout. Sets template name
     // load correct CSS. St menus if any. Etc.
     $layout = new layout();
     // we first load menus here so we can se what happened when we
     // init our module. In case of a 404 not found error we don't want
     // to load module menus
     $layout->loadMenus();
     // init blocks
     $layout->initBlocks();
     // if any matching route was found we check for a method or function
     if ($db_route) {
         $str = dispatch::call($db_route['method']);
     } else {
         // or we use default module parsing
         $str = $ml->getParsedModule();
     }
     // set view vars
     $vars['content'] = $str;
     // run level 7
     $ml->runLevel(7);
     // echo module content
     echo $str = \mainTemplate::view($vars);
     conf::$vars['final_output'] = ob_get_contents();
     ob_end_clean();
     // Last divine intervention
     // e.g. Dom or Tidy
     $ml->runLevel(8);
     echo conf::$vars['final_output'];
 }
예제 #10
0
 /**
  * getting filter help from filters
  * @param array $filters
  * @return string $filters_help
  */
 public static function getFiltersHelp($filters)
 {
     if (empty($filters)) {
         return '';
     }
     $str = '<span class="small-font">';
     $i = 1;
     if (is_string($filters)) {
         $ary = array();
         $ary[] = $filters;
         $filters = $ary;
     }
     foreach ($filters as $val) {
         $t = lang::translate("filter_" . $val . "_help");
         if ($t == "NT: filter_" . $val . "_help") {
             continue;
         }
         $str .= $i . ") " . $t . "<br />";
         $i++;
     }
     $str .= '</span>';
     return $str;
 }
예제 #11
0
 /**
  * checks if if size is allowed
  * @param string $filename the name of the file
  * @param int $maxsize bytes
  * @return boolean $res
  */
 public static function checkMaxSize($file, $maxsize = null)
 {
     if (!$maxsize) {
         $maxsize = self::$options['maxsize'];
     }
     if ($file['size'] > $maxsize) {
         $error = lang::translate('File is too large.') . ' ';
         $error .= lang::translate('Max size is ') . ' ' . bytes::bytesToGreek($maxsize);
         log::error($error);
         self::$errors[] = $error;
         return false;
     }
     return true;
 }
예제 #12
0
 /**
  * sets a file field with info about max file size
  * @param string $filename 
  * @param int $max_bytes
  * @param array $options
  */
 public static function fileWithLabel($filename, $max_bytes, $options = array())
 {
     $bytes = bytes::getNativeMaxUpload();
     if ($max_bytes < $bytes) {
         $bytes = $max_bytes;
     }
     self::hidden('MAX_FILE_SIZE', $bytes);
     $label = lang::translate('Max size per file') . ". ";
     $size = bytes::bytesToGreek($bytes);
     $label .= $size;
     if (isset($options['multiple'])) {
         $max_files = ini_get('max_file_uploads');
         $label .= "<br />";
         $label .= lang::translate('Max number of files: <span class="notranslate">{MAX_FILES}</span>', array('MAX_FILES' => $max_files));
     } else {
         $label .= "<br />";
         $label .= lang::translate('Only one file at a time');
     }
     if (isset($options['allowed'])) {
         $label .= '<br />';
         $label .= lang::translate('Allowed file-types: ') . $options['allowed'];
     }
     self::label($filename, $label);
     self::file($filename, $options);
 }
예제 #13
0
 public function run()
 {
     // Register an autoloader for loading modules from mopdules dir
     $m = new modules();
     $m->autoloadRegister();
     // define HTML constants
     common::defineConstants();
     // define global constants - based on base path
     conf::defineCommon();
     // set include paths
     conf::setIncludePath();
     // load config file
     conf::load();
     // set log level - based on config.ini
     log::setLogLevel();
     // utf-8
     ini_set('default_charset', 'UTF-8');
     // load config/config.ini
     // check if there exists a shared ini file
     // shared ini is used if we want to enable settings between hosts
     // which share same code base.
     // e.g. when updating all sites, it is a good idea to set the following flag
     // site_update = 1
     // this flag will send correct 503 headers, when we are updating our site.
     // if site is being updaing we send temporarily headers
     // and display an error message
     if (conf::getMainIni('site_update')) {
         http::temporarilyUnavailable();
     }
     // set a unified server_name if not set in config file.
     $server_name = conf::getMainIni('server_name');
     if (!$server_name) {
         conf::setMainIni('server_name', $_SERVER['SERVER_NAME']);
     }
     // redirect to uniform server name is set in config.ini
     // e.g. www.testsite.com => testsite.com
     $server_redirect = conf::getMainIni('server_redirect');
     if (isset($server_redirect)) {
         http::redirectHeaders($server_redirect);
     }
     // redirect to https is set in config.ini
     // force anything into ssl mode
     $server_force_ssl = conf::getMainIni('server_force_ssl');
     if (isset($server_force_ssl)) {
         http::sslHeaders();
     }
     // catch all output
     ob_start();
     // Create a db connection
     $db = new db();
     // init module loader.
     $ml = new moduleloader();
     // initiate uri
     uri::getInstance();
     // runlevel 1: merge db config
     $ml->runLevel(1);
     // select all db settings and merge them with ini file settings
     $db_settings = $db->selectOne('settings', 'id', 1);
     // merge db settings with config/config.ini settings
     // db settings override ini file settings
     conf::$vars['coscms_main'] = array_merge(conf::$vars['coscms_main'], $db_settings);
     // run level 2: set locales
     $ml->runLevel(2);
     // set locales
     intl::setLocale();
     // set default timezone
     intl::setTimezone();
     // runlevel 3 - init session
     $ml->runLevel(3);
     // start session
     session::initSession();
     $res = session::checkAccount();
     if (!$res) {
         // To prevent
         http::locationHeader('/');
     }
     // set account timezone if enabled - can only be done after session
     // as user needs to be logged in
     intl::setAccountTimezone();
     // run level 4 - load language
     $ml->runLevel(4);
     // load all language files
     $l = new lang();
     $base = conf::pathBase();
     $htdocs = conf::pathHtdocs();
     $l->setDirsInsideDir("{$base}/modules/");
     $l->setDirsInsideDir("{$htdocs}/templates/");
     $l->setSingleDir("{$base}/vendor/diversen/simple-php-classes");
     $l->setSingleDir("{$base}/vendor/diversen/simple-pager");
     $l->loadLanguage(conf::getMainIni('language'));
     // runlevel 5
     $ml->runLevel(5);
     // load routes if any
     dispatch::setDbRoutes();
     // runlevel 6
     $ml->runLevel(6);
     // check db routes or load by defaults
     $db_route = dispatch::getMatchRoutes();
     if (!$db_route) {
         $ml->setModuleInfo();
         $ml->initModule();
     }
     // Init layout. Sets template name
     // load correct CSS. St menus if any. Etc.
     $layout = new layout();
     // we first load menus here so we can se what happened when we
     // init our module. In case of a 404 not found error we don't want
     // to load module menus
     $layout->loadMenus();
     // init blocks
     $layout->initBlocks();
     // if any matching route was found we check for a method or function
     if ($db_route) {
         $str = dispatch::call($db_route['method']);
     } else {
         // or we use default module parsing
         $str = $ml->getParsedModule();
     }
     // set view vars
     $vars['content'] = $str;
     // run level 7
     $ml->runLevel(7);
     // echo module content
     echo $str = \mainTemplate::view($vars);
     conf::$vars['final_output'] = ob_get_contents();
     ob_end_clean();
     // Last divine intervention
     // e.g. Dom or Tidy
     $ml->runLevel(8);
     echo conf::$vars['final_output'];
 }
예제 #14
0
 public function getAdminLink($id)
 {
     $str = html::createLink("/account/admin/edit/{$id}", lang::translate('(Admin) Edit profile'));
     return $str;
 }