Ejemplo n.º 1
0
/**
 * If the recent post within a day, output format of YmdHis is "min/hours ago from now". If not within a day, it return format string.
 *
 * @param string $date Time value in format of YYYYMMDDHHIISS
 * @param string $format If gap is within a day, returns this format.
 * @return string
 */
function getTimeGap($date, $format = 'Y.m.d')
{
    $timestamp = ztime($date);
    $gap = RX_TIME - $timestamp;
    if ($gap < 60 * 60 * 24) {
        return Rhymix\Framework\DateTime::getRelativeTimestamp($gap >= 60 ? $timestamp : RX_TIME - 60);
    } else {
        return zdate($date, $format);
    }
}
Ejemplo n.º 2
0
            // XE compatible classes.
        // XE compatible classes.
        default:
            if (isset($GLOBALS['RX_AUTOLOAD_FILE_MAP'][$lc_class_name])) {
                $filename = RX_BASEDIR . $GLOBALS['RX_AUTOLOAD_FILE_MAP'][$lc_class_name];
            } elseif (preg_match('/^([a-zA-Z0-9_]+?)(Admin)?(View|Controller|Model|Api|Wap|Mobile)?$/', $class_name, $matches)) {
                $filename = RX_BASEDIR . 'modules/' . strtolower($matches[1] . '/' . $matches[1]);
                if (isset($matches[2]) && $matches[2]) {
                    $filename .= '.admin';
                }
                $filename .= isset($matches[3]) && $matches[3] ? '.' . strtolower($matches[3]) : '.class';
                $filename .= '.php';
            }
    }
    if ($filename && file_exists($filename)) {
        include $filename;
    }
});
/**
 * Also include the Composer autoloader.
 */
require_once RX_BASEDIR . 'vendor/autoload.php';
/**
 * Load system configuration.
 */
Rhymix\Framework\Config::init();
/**
 * Set the internal timezone.
 */
$internal_timezone = Rhymix\Framework\DateTime::getTimezoneNameByOffset(config('locale.internal_timezone'));
date_default_timezone_set($internal_timezone);
Ejemplo n.º 3
0
 /**
  * Display General Settings page
  * @return void
  */
 function dispAdminConfigGeneral()
 {
     // Default and enabled languages
     Context::set('supported_lang', Rhymix\Framework\Lang::getSupportedList());
     Context::set('default_lang', Rhymix\Framework\Config::get('locale.default_lang'));
     Context::set('enabled_lang', Rhymix\Framework\Config::get('locale.enabled_lang'));
     Context::set('auto_select_lang', Rhymix\Framework\Config::get('locale.auto_select_lang'));
     // Site title and HTML footer
     $oModuleModel = getModel('module');
     $config = $oModuleModel->getModuleConfig('module');
     Context::set('var_site_title', escape($config->siteTitle));
     Context::set('var_site_subtitle', escape($config->siteSubtitle));
     Context::set('all_html_footer', escape($config->htmlFooter));
     // Index module
     $columnList = array('modules.mid', 'modules.browser_title', 'sites.index_module_srl');
     $start_module = $oModuleModel->getSiteInfo(0, $columnList);
     Context::set('start_module', $start_module);
     // Default time zone
     Context::set('timezones', Rhymix\Framework\DateTime::getTimezoneList());
     Context::set('selected_timezone', Rhymix\Framework\Config::get('locale.default_timezone'));
     // Mobile view
     Context::set('use_mobile_view', config('mobile.enabled') !== null ? config('mobile.enabled') : config('use_mobile_view') ? true : false);
     Context::set('tablets_as_mobile', config('mobile.tablets') ? true : false);
     // Favicon and mobicon and site default image
     $oAdminModel = getAdminModel('admin');
     $favicon_url = $oAdminModel->getFaviconUrl(false) ?: $oAdminModel->getFaviconUrl();
     $mobicon_url = $oAdminModel->getMobileIconUrl(false) ?: $oAdminModel->getMobileIconUrl();
     $site_default_image_url = $oAdminModel->getSiteDefaultImageUrl();
     Context::set('favicon_url', $favicon_url);
     Context::set('mobicon_url', $mobicon_url);
     Context::set('site_default_image_url', $site_default_image_url);
     $this->setTemplateFile('config_general');
 }
Ejemplo n.º 4
0
 /**
  * @brief Install with received information
  */
 function procInstall($install_config = null)
 {
     // Check if it is already installed
     if (Context::isInstalled()) {
         return new Object(-1, 'msg_already_installed');
     }
     // Get install parameters.
     $config = Rhymix\Framework\Config::getDefaults();
     if ($install_config) {
         $install_config = (array) $install_config;
         $config['db']['master']['type'] = str_replace('_innodb', '', $install_config['db_type']);
         $config['db']['master']['host'] = $install_config['db_hostname'];
         $config['db']['master']['port'] = $install_config['db_port'];
         $config['db']['master']['user'] = $install_config['db_userid'];
         $config['db']['master']['pass'] = $install_config['db_password'];
         $config['db']['master']['database'] = $install_config['db_database'];
         $config['db']['master']['prefix'] = $install_config['db_table_prefix'];
         $config['db']['master']['charset'] = $install_config['db_charset'];
         $config['db']['master']['engine'] = strpos($install_config['db_type'], 'innodb') !== false ? 'innodb' : (strpos($install_config['db_type'], 'mysql') !== false ? 'myisam' : null);
         $config['use_rewrite'] = $install_config['use_rewrite'] === 'Y' ? true : false;
         $config['url']['ssl'] = $install_config['use_ssl'] ?: 'none';
         $time_zone = $install_config['time_zone'];
         $user_info = new stdClass();
         $user_info->email_address = $install_config['email_address'];
         $user_info->password = $install_config['password'];
         $user_info->nick_name = $install_config['nick_name'];
         $user_info->user_id = $install_config['user_id'];
     } else {
         $config['db']['master']['type'] = str_replace('_innodb', '', $_SESSION['db_config']->db_type);
         $config['db']['master']['host'] = $_SESSION['db_config']->db_host;
         $config['db']['master']['port'] = $_SESSION['db_config']->db_port;
         $config['db']['master']['user'] = $_SESSION['db_config']->db_user;
         $config['db']['master']['pass'] = $_SESSION['db_config']->db_pass;
         $config['db']['master']['database'] = $_SESSION['db_config']->db_database;
         $config['db']['master']['prefix'] = $_SESSION['db_config']->db_prefix;
         $config['db']['master']['charset'] = $_SESSION['db_config']->db_charset;
         $config['db']['master']['engine'] = strpos($_SESSION['db_config']->db_type, 'innodb') !== false ? 'innodb' : (strpos($_SESSION['db_config']->db_type, 'mysql') !== false ? 'myisam' : null);
         $config['use_rewrite'] = $_SESSION['use_rewrite'] === 'Y' ? true : false;
         $config['url']['ssl'] = Context::get('use_ssl') ?: 'none';
         $time_zone = Context::get('time_zone');
         $user_info = Context::gets('email_address', 'password', 'nick_name', 'user_id');
     }
     // Fix the database table prefix.
     $config['db']['master']['prefix'] = rtrim($config['db']['master']['prefix'], '_');
     if ($config['db']['master']['prefix'] !== '') {
         $config['db']['master']['prefix'] .= '_';
     }
     // Set the default language.
     $config['locale']['default_lang'] = Context::getLangType();
     $config['locale']['enabled_lang'] = array($config['locale']['default_lang']);
     // Set the default time zone.
     if (strpos($time_zone, '/') !== false) {
         $config['locale']['default_timezone'] = $time_zone;
         $user_timezone = null;
     } else {
         $user_timezone = intval(Rhymix\Framework\DateTime::getTimezoneOffsetByLegacyFormat($time_zone ?: '+0900') / 3600);
         switch ($user_timezone) {
             case 9:
                 $config['locale']['default_timezone'] = 'Asia/Seoul';
                 break;
             case 0:
                 $config['locale']['default_timezone'] = 'Etc/UTC';
                 break;
             default:
                 $config['locale']['default_timezone'] = 'Etc/GMT' . ($user_timezone > 0 ? '-' : '+') . abs($user_timezone);
         }
     }
     // Set the internal time zone.
     if ($config['locale']['default_timezone'] === 'Asia/Seoul') {
         $config['locale']['internal_timezone'] = 32400;
     } elseif ($user_timezone !== null) {
         $config['locale']['internal_timezone'] = $user_timezone * 3600;
     } else {
         $config['locale']['internal_timezone'] = 0;
     }
     // Set the default URL.
     $config['url']['default'] = Context::getRequestUri();
     // Load the new configuration.
     Rhymix\Framework\Config::setAll($config);
     Context::loadDBInfo($config);
     // Check DB.
     $oDB = DB::getInstance();
     if (!$oDB->isConnected()) {
         return $oDB->getError();
     }
     // Assign a temporary administrator while installing.
     foreach ($user_info as $key => $val) {
         Context::set($key, $val, true);
     }
     $user_info->is_admin = 'Y';
     Context::set('logged_info', $user_info);
     // Install all the modules.
     try {
         $oDB->begin();
         $this->installDownloadedModule();
         $oDB->commit();
     } catch (Exception $e) {
         $oDB->rollback();
         return new Object(-1, $e->getMessage());
     }
     // Execute the install script.
     $scripts = FileHandler::readDir(_XE_PATH_ . 'modules/install/script', '/(\\.php)$/');
     if (count($scripts)) {
         sort($scripts);
         foreach ($scripts as $script) {
             $script_path = FileHandler::getRealPath('./modules/install/script/');
             $output = (include $script_path . $script);
         }
     }
     // Apply site lock.
     if (Context::get('use_sitelock') === 'Y') {
         $user_ip_range = getView('install')->detectUserIPRange();
         Rhymix\Framework\Config::set('lock.locked', true);
         Rhymix\Framework\Config::set('lock.message', 'This site is locked.');
         Rhymix\Framework\Config::set('lock.allow', array('127.0.0.1', $user_ip_range));
     }
     // Save the new configuration.
     Rhymix\Framework\Config::save();
     // Unset temporary session variables.
     unset($_SESSION['use_rewrite']);
     unset($_SESSION['db_config']);
     // Redirect to the home page.
     $this->setMessage('msg_install_completed');
     $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : RX_BASEURL;
     $this->setRedirectUrl($returnUrl);
     return new Object();
 }
Ejemplo n.º 5
0
 /**
  * Display General Settings page
  * @return void
  */
 function dispAdminConfigGeneral()
 {
     // Default and enabled languages
     Context::set('supported_lang', Rhymix\Framework\Lang::getSupportedList());
     Context::set('default_lang', Rhymix\Framework\Config::get('locale.default_lang'));
     Context::set('enabled_lang', Rhymix\Framework\Config::get('locale.enabled_lang'));
     // Site title and HTML footer
     $oModuleModel = getModel('module');
     $config = $oModuleModel->getModuleConfig('module');
     Context::set('site_title', escape($config->siteTitle));
     Context::set('html_footer', escape($config->htmlFooter));
     // Index module
     $columnList = array('modules.mid', 'modules.browser_title', 'sites.index_module_srl');
     $start_module = $oModuleModel->getSiteInfo(0, $columnList);
     Context::set('start_module', $start_module);
     // Thumbnail settings
     $oDocumentModel = getModel('document');
     $config = $oDocumentModel->getDocumentConfig();
     Context::set('thumbnail_type', $config->thumbnail_type ?: 'crop');
     // Default time zone
     Context::set('timezones', Rhymix\Framework\DateTime::getTimezoneList());
     Context::set('selected_timezone', Rhymix\Framework\Config::get('locale.default_timezone'));
     // Mobile view
     Context::set('use_mobile_view', config('use_mobile_view') ? 'Y' : 'N');
     // Favicon and mobicon
     $oAdminModel = getAdminModel('admin');
     $favicon_url = $oAdminModel->getFaviconUrl();
     $mobicon_url = $oAdminModel->getMobileIconUrl();
     Context::set('favicon_url', $favicon_url . '?' . $_SERVER['REQUEST_TIME']);
     Context::set('mobicon_url', $mobicon_url . '?' . $_SERVER['REQUEST_TIME']);
     $this->setTemplateFile('config_general');
 }
Ejemplo n.º 6
0
 /**
  * @brief Display a screen to enter DB and administrator's information
  */
 function dispInstallOtherConfig()
 {
     // Display check_env if not installable
     if (!self::$checkEnv) {
         return $this->dispInstallCheckEnv();
     }
     // Get list of time zones.
     Context::set('timezones', Rhymix\Framework\DateTime::getTimezoneList());
     // Automatically select a time zone for the user.
     Context::set('selected_timezone', $this->detectUserTimeZone());
     // Always use SSL if installing via SSL.
     Context::set('use_ssl', RX_SSL ? 'always' : 'none');
     Context::set('sitelock_ip_range', $this->detectUserIPRange());
     $this->setTemplateFile('other_config');
 }
Ejemplo n.º 7
0
/**
 * Convert YYYYMMDDHHIISS format to user-defined format.
 * This function assumes the internal timezone.
 *
 * @param string $str Time in YYYYMMDDHHIISS format
 * @param string $format Time format for date() function
 * @param bool $conversion If true, convert automatically for the current language.
 * @return string
 */
function zdate($str, $format = 'Y-m-d H:i:s', $conversion = false)
{
    if (!$str) {
        return null;
    }
    // convert the date format according to the language
    if ($conversion) {
        static $convtable = array('en' => array('Y-m-d' => 'M j, Y', 'Y-m-d H:i:s' => 'M j, Y H:i:s', 'Y-m-d H:i' => 'M j, Y H:i'), 'es' => array('Y-m-d' => 'j M Y', 'Y-m-d H:i:s' => 'j M Y H:i:s', 'Y-m-d H:i' => 'j M Y H:i'), 'de' => 'es', 'fr' => 'es', 'vi' => array('Y-m-d' => 'd-m-Y', 'Y-m-d H:i:s' => 'H:i:s d-m-Y', 'Y-m-d H:i' => 'H:i d-m-Y'));
        $lang_type = Context::getLangType();
        if (isset($convtable[$lang_type])) {
            if (isset($convtable[$lang_type][$format])) {
                $format = $convtable[$lang_type][$format];
            } elseif (is_string($convtable[$lang_type]) && isset($convtable[$convtable[$lang_type]][$format])) {
                $format = $convtable[$convtable[$lang_type]][$format];
            }
        }
    }
    // get unixtime by using ztime() for date() function's argument.
    $result = Rhymix\Framework\DateTime::formatTimestampForCurrentUser($format, ztime($str));
    // change day and am/pm for each language
    if (preg_match('/[MFAa]/', $format)) {
        $unit_week = (array) Context::getLang('unit_week');
        $unit_meridiem = (array) Context::getLang('unit_meridiem');
        $result = str_replace(array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'), $unit_week, $result);
        $result = str_replace(array('am', 'pm', 'AM', 'PM'), $unit_meridiem, $result);
    }
    return $result;
}