コード例 #1
0
ファイル: git.php プロジェクト: gpawlik/suited-php-classes
 /**
  * get tags for a module or template
  * @param string $module
  * @param string $type 'module' or 'template'
  * @return array|false a array or false 
  */
 public static function getTagsModule($module, $type = 'module')
 {
     if ($type == 'module') {
         $path = conf::pathModules() . "/{$module}";
     }
     if ($type == 'template') {
         $path = conf::pathHtdocs() . "/templates/{$module}";
     }
     $command = "cd {$path} && git tag -l";
     exec($command, $ary, $ret);
     // ok
     if ($ret == 0) {
         $str = shell_exec($command);
         $ary = explode("\n", $str);
         $tags = array();
         foreach ($ary as $line) {
             trim($line);
             if (empty($line)) {
                 continue;
             }
             $tags[] = $line;
         }
     } else {
         return false;
     }
     return $tags;
 }
コード例 #2
0
 /**
  * returns favicon html
  * @return string $html 
  */
 public static function getFaviconHTML()
 {
     $favicon = conf::getMainIni('favicon');
     $domain = conf::getDomain();
     $rel_path = "/files/{$domain}/favicon/{$favicon}";
     $full_path = conf::pathHtdocs() . "/{$rel_path}";
     if (!is_file($full_path)) {
         $rel_path = '/favicon.ico';
     }
     $str = "<link rel=\"shortcut icon\" href=\"{$rel_path}\" type=\"image/x-icon\" />\n";
     return $str;
 }
コード例 #3
0
 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 ($type == 'mp4') {
         $full_path = conf::pathHtdocs() . $url;
         return "![{$alt_text}]({$url})";
     }
     if ($this->isImage($url)) {
         return "![{$alt_text}](" . $this->uploadImage($url) . ")";
     }
     return;
 }
コード例 #4
0
 function create($str)
 {
     $font = conf::getModuleIni('image_captcha_font');
     //'fonts/captcha.ttf';'
     $f_color = conf::getModuleIni('image_captcha_font_color');
     //'fonts/captcha.ttf';'
     if (!$f_color) {
         $f_color = 'FFFFFF';
     }
     $b_color = conf::getModuleIni('image_captcha_bg_color');
     //'fonts/captcha.ttf';'
     if (!$b_color) {
         $b_color = '000000';
     }
     $this->_capTextColor = $f_color;
     $this->_capBgColor = $b_color;
     $this->_capFont = conf::pathHtdocs() . '/' . $font;
     $this->SendHeader();
     $this->setStr($str);
     $this->MakeCaptcha();
 }
コード例 #5
0
 /**
  * check if template common.inc exists
  * @param string $template
  * @return boolean $res true if exists else false
  */
 public static function templateCommonExists($template)
 {
     if (file_exists(conf::pathHtdocs() . "/templates/{$template}/common.inc")) {
         return true;
     }
     return false;
 }
コード例 #6
0
 /**
  * returns a array of all templates found in template_dir
  * @return array $templates
  */
 public static function getAllTemplates()
 {
     return file::getFileList(conf::pathHtdocs() . "/templates", array('dir_only' => true));
 }
コード例 #7
0
 /**
  * Method for loading all module's configuration, contained in a profile 
  * @param string $profile name of the profile
  */
 public function loadProfileFiles($profile)
 {
     $profile_dir = conf::pathBase() . "/profiles/{$profile}";
     foreach ($this->profileModules as $key => $val) {
         $source = $profile_dir . "/{$val['module_name']}.ini-dist";
         $dest = conf::pathModules() . "/{$val['module_name']}/{$val['module_name']}.ini";
         $path_module = conf::pathModules() . "/{$val['module_name']}";
         if (!file_exists($path_module)) {
             continue;
         }
         if (file_exists($source)) {
             copy($source, $dest);
             $this->confirm[] = "Copy {$source} to {$dest}";
         }
         // If a PHP config.php file exists, then copy that too.
         $source = $profile_dir . "/{$val['module_name']}.php-dist";
         $dest = conf::pathModules() . "/{$val['module_name']}/config.php";
         if (file_exists($source)) {
             copy($source, $dest);
         }
     }
     foreach ($this->profileTemplates as $key => $val) {
         $source = $profile_dir . "/{$val['module_name']}.ini-dist";
         $dest = conf::pathHtdocs() . "/templates/{$val['module_name']}/{$val['module_name']}.ini";
         $path_module = conf::pathHtdocs() . "/templates/{$val['module_name']}";
         if (!file_exists($path_module)) {
             continue;
         }
         if (file_exists($source)) {
             copy($source, $dest);
             $this->confirm[] = "Copy {$source} to {$dest}";
         }
         // If a PHP config.php file exists, then copy that too.
         $source = $profile_dir . "/{$val['module_name']}.php-dist";
         $dest = conf::pathHtdocs() . "/templates/{$val['module_name']}/config.php";
         if (file_exists($source)) {
             copy($source, $dest);
         }
     }
 }
コード例 #8
0
ファイル: boot.php プロジェクト: diversen/simple-php-classes
 /**
  * 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'];
 }
コード例 #9
0
 /**
  * include template common.inc
  * @param string $template
  */
 public static function includeTemplateCommon($template)
 {
     static $included = array();
     if (!isset($included[$template])) {
         include_once conf::pathHtdocs() . "/templates/{$template}/common.php";
     }
     $included[$template] = true;
 }
コード例 #10
0
 /**
  * Method for moving uploaded file
  * @param  string $filename name of file in the html forms file field
  *                 e.g. 'file'
  * @param array  $options
  * @return boolean $res true on success or false on failure
  */
 public static function moveFile($file = null, $options = null)
 {
     if (isset($options)) {
         self::$options = $options;
     }
     // We can give both just the /htdocs/files ... path
     // then we add conf::pathBase()
     if (!strstr(self::$options['upload_dir'], conf::pathBase())) {
         self::$options['upload_dir'] = conf::pathBase() . self::$options['upload_dir'];
     }
     // check if dir exists
     if (!file_exists(self::$options['upload_dir'])) {
         $res = @mkdir(self::$options['upload_dir'], self::$mode, true);
         if (!$res) {
             echo "Could not make dir: " . self::$options['upload_dir'] . "\n";
         }
     }
     // check if an upload were performed
     if (isset($file)) {
         // check native
         $res = self::checkUploadNative($file);
         if (!$res) {
             return false;
         }
         // check mime
         if (isset(self::$options['allow_mime'])) {
             $res = self::checkAllowedMime($file);
             if (!$res) {
                 return false;
             }
         }
         // check maxsize. Note: Will overrule php ini settings
         if (isset(self::$options['maxsize'])) {
             $res = self::checkMaxSize($file);
             if (!$res) {
                 return false;
             }
         }
         // sets a new filename to save the file as or use the
         // name of the uploaded file.
         if (isset(self::$options['save_basename'])) {
             $save_basename = self::$options['save_basename'];
         } else {
             $save_basename = basename($file['name']);
         }
         self::$confirm['save_basename'] = $save_basename;
         $savefile = self::$options['upload_dir'] . '/' . $save_basename;
         // check if file exists.
         if (file_exists($savefile)) {
             if (isset(self::$options['only_unique'])) {
                 self::$errors[] = lang::translate('File already exists') . MENU_SUB_SEPARATOR_SEC . $savefile;
                 return false;
             } else {
                 // this call will also set self::$info['save_filename']
                 $savefile = self::newFileName($savefile);
             }
         } else {
             self::$saveBasename = $save_basename;
         }
         $ret = move_uploaded_file($file['tmp_name'], $savefile);
         if (!$ret) {
             self::$errors[] = lang::translate('Could not move file.');
             return false;
         }
         $savefile = str_replace(conf::pathHtdocs(), '', $savefile);
         return $savefile;
     }
     log::error('No file to move in ' . __FILE__ . ' ' . __LINE__, false);
     return false;
 }
コード例 #11
0
ファイル: view.php プロジェクト: gpawlik/suited-php-classes
 /**
  * include a set of module function used for e.g. templates. These 
  * functions can be overridden in template if they exists in a template
  * @param string $module
  * @param string $file
  * @return void
  */
 public static function includeOverrideFunctions($module, $file)
 {
     // only template who has set name will be able to override this way
     // templage_name = 'clean'
     $template = layout::getTemplateName();
     if ($template) {
         $override = conf::pathHtdocs() . "/templates/{$template}/{$module}/{$file}";
         if (is_file($override)) {
             include_once $override;
             return;
         }
     }
     include_once conf::pathModules() . "/{$module}/{$file}";
 }
コード例 #12
0
ファイル: git.php プロジェクト: gpawlik/suited-php-classes
/**
 * shell callback function for commiting a single template
 * @param array $options array ('repo')
 */
function cos_git_commit_template_single($options)
{
    $path = conf::pathHtdocs() . "/templates/{$options['repo']}";
    if (!cos_git_is_repo($path)) {
        common::abort("Template: {$options['repo']} is not a git repo. Specify installed template (e.g. 'clean') name when commiting");
    }
    $p = new profile();
    $mod = $p->getTemplate($options['repo']);
    cos_git_commit($mod, 'template');
}
コード例 #13
0
ファイル: view.php プロジェクト: diversen/simple-php-classes
 /**
  * Include a set of module function used for a module. These 
  * functions will be overridden in template if they exists in a template
  * @param string $module
  * @param string $file
  * @return void
  */
 public static function includeOverrideFunctions($module, $file)
 {
     // Check for view in template
     $template = layout::getTemplateName();
     if ($template) {
         $override = conf::pathHtdocs() . "/templates/{$template}/{$module}/{$file}";
         if (is_file($override)) {
             include_once $override;
             return;
         }
     }
     include_once conf::pathModules() . "/{$module}/{$file}";
 }
コード例 #14
0
ファイル: boot.php プロジェクト: gpawlik/suited-php-classes
 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'];
 }
コード例 #15
0
 /**
  * Get all templates from file system
  * @return array $templates
  */
 public function getTemplates()
 {
     $dir = conf::pathHtdocs() . "/templates";
     $templates = file::getFileList($dir, array('dir_only' => true));
     return $templates;
 }
コード例 #16
0
ファイル: assets.php プロジェクト: gpawlik/suited-php-classes
 /**
  * sets template css from template css ini files
  * @param string $template
  * @param string $css
  */
 public static function setTemplateCssIni($template, $css)
 {
     $ini_file = conf::pathHtdocs() . "/templates/{$template}/{$css}/{$css}.ini";
     if (file_exists($ini_file)) {
         $ary = conf::getIniFileArray($ini_file, true);
         conf::$vars['coscms_main']['module'] = array_merge_recursive(conf::$vars['coscms_main']['module'], $ary);
     }
 }
コード例 #17
0
 /**
  * installs a template
  * @return boolean $res 
  */
 public function install()
 {
     // create ini files for template
     $template = $this->installInfo['NAME'];
     $ini_file = conf::pathHtdocs() . "/templates/{$template}/{$template}.ini";
     $ini_file_php = conf::pathHtdocs() . "/templates/{$template}/{$template}.php.ini";
     $ini_file_dist = conf::pathHtdocs() . "/templates/{$template}/{$template}.ini-dist";
     $ini_file_dist_php = conf::pathHtdocs() . "/templates/{$template}/{$template}.php.ini-dist";
     if (!file_exists($ini_file)) {
         if (file_exists($ini_file_dist)) {
             if (!copy($ini_file_dist, $ini_file)) {
                 $this->error = "Error: Could not copy {$ini_file} to {$ini_file_dist}" . PHP_EOL;
                 $this->error .= "Make sure your module has an ini-dist file: {$ini_file_dist}";
                 return false;
             }
         }
     }
     // create php ini file if a php.ini-dist file exists
     if (!file_exists($ini_file_php)) {
         if (file_exists($ini_file_dist_php)) {
             copy($ini_file_dist_php, $ini_file_php);
         }
     }
     $this->confirm = "Template '" . $this->installInfo['NAME'] . "' installed" . PHP_EOL;
     $this->confirm .= "Make sure your module has an ini-dist file: {$ini_file_dist}";
 }