示例#1
0
文件: option.php 项目: flyysr/emlog
 static function get($option)
 {
     $CACHE = Cache::getInstance();
     $options_cache = $CACHE->readCache('options');
     if (isset($options_cache[$option])) {
         switch ($option) {
             case 'active_plugins':
             case 'navibar':
             case 'widget_title':
             case 'custom_widget':
             case 'widgets1':
             case 'widgets2':
             case 'widgets3':
             case 'widgets4':
             case 'custom_topimgs':
                 if (!empty($options_cache[$option])) {
                     return @unserialize($options_cache[$option]);
                 } else {
                     return array();
                 }
                 break;
             case 'blogurl':
                 if ($options_cache['detect_url'] == 'y') {
                     return realUrl();
                 } else {
                     return $options_cache['blogurl'];
                 }
                 break;
             default:
                 return $options_cache[$option];
                 break;
         }
     }
 }
示例#2
0
function getUrl($path, $url)
{
    $full = $path;
    $parse = parse_url($url);
    if ($path[0] == '/') {
        return $parse['scheme'] . '://' . $parse['host'] . $path;
    }
    if (substr($path, 0, 4) == 'http') {
        return $path;
    }
    if (substr($path, 0, 5) == 'data:') {
        return null;
    }
    $exp = explode('/', $parse['path']);
    $exp[count($exp) - 1] = $path;
    return realUrl($parse['scheme'] . '://' . $parse['host'] . implode('/', $exp));
}
function _errorlog_sendEmailAlert()
{
    if (!$GLOBALS['SETTINGS']['advanced']['phpEmailErrors']) {
        return;
    }
    // once run function once per page-view
    static $alreadySent = false;
    if ($alreadySent) {
        return;
    }
    $alreadySent = true;
    // check if email sent in last hour
    $sentInLastHour = mysql_count('_error_log', " `dateLogged` > (NOW() - INTERVAL 1 HOUR) AND email_sent = 1");
    // send hourly alert
    if (!$sentInLastHour) {
        // send email
        $secondsAgo = time() - $GLOBALS['SETTINGS']['bgtasks_lastEmail'];
        if ($secondsAgo >= 60 * 60) {
            // don't email more than once an hour
            // get date format
            if ($GLOBALS['SETTINGS']['dateFormat'] == 'dmy') {
                $dateFormat = "jS M, Y - h:i:s A";
            } elseif ($GLOBALS['SETTINGS']['dateFormat'] == 'mdy') {
                $dateFormat = "M jS, Y - h:i:s A";
            } else {
                $dateFormat = "M jS, Y - h:i:s A";
            }
            // load latest error list
            $latestErrors = mysql_select('_error_log', "`dateLogged` > (NOW() - INTERVAL 1 HOUR) ORDER BY `dateLogged` DESC LIMIT 25");
            $latestErrorsList = '';
            foreach ($latestErrors as $thisError) {
                $latestErrorsList .= date($dateFormat, strtotime($thisError['dateLogged'])) . "\n";
                $latestErrorsList .= $thisError['error'] . "\n";
                $latestErrorsList .= $thisError['filepath'] . " (line " . $thisError['line_num'] . ")\n";
                $latestErrorsList .= $thisError['url'] . "\n\n";
            }
            // set email_sent flag for ALL records
            mysql_update('_error_log', null, 'TRUE', array('email_sent' => 1));
            // send email message
            $placeholders = array('error.hostname' => parse_url($GLOBALS['SETTINGS']['adminUrl'], PHP_URL_HOST), 'error.latestErrorsList' => nl2br(htmlencode($latestErrorsList)), 'error.errorLogUrl' => realUrl("?menu=_error_log", $GLOBALS['SETTINGS']['adminUrl']));
            $errors = sendMessage(emailTemplate_loadFromDB(array('template_id' => 'CMS-ERRORLOG-ALERT', 'placeholders' => $placeholders)));
            // log/display email sending errors
            if ($errors) {
                trigger_error("Unable to send error notification email from " . __FUNCTION__ . ": {$errors}", E_USER_NOTICE);
                die(__FUNCTION__ . ": {$errors}");
            }
        }
    }
}
示例#4
0
文件: install.php 项目: Jimco/emlog
 }
 fclose($fp);
 //密码加密存储
 $PHPASS = new PasswordHash(8, true);
 $adminpw = $PHPASS->HashPassword($adminpw);
 $dbcharset = 'utf8';
 $type = 'MYISAM';
 $table_charset_sql = $DB->getMysqlVersion() > '4.1' ? 'ENGINE=' . $type . ' DEFAULT CHARSET=' . $dbcharset . ';' : 'ENGINE=' . $type . ';';
 if ($DB->getMysqlVersion() > '4.1') {
     $DB->query("ALTER DATABASE `{$db_name}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;", true);
 }
 $widgets = Option::getWidgetTitle();
 $sider_wg = Option::getDefWidget();
 $widget_title = serialize($widgets);
 $widgets = serialize($sider_wg);
 define('BLOG_URL', realUrl());
 $sql = "\nDROP TABLE IF EXISTS {$db_prefix}blog;\nCREATE TABLE {$db_prefix}blog (\n  gid int(10) unsigned NOT NULL auto_increment,\n  title varchar(255) NOT NULL default '',\n  date bigint(20) NOT NULL,\n  content longtext NOT NULL,\n  excerpt longtext NOT NULL,\n  alias VARCHAR(200) NOT NULL DEFAULT '',\n  author int(10) NOT NULL default '1',\n  sortid int(10) NOT NULL default '-1',\n  type varchar(20) NOT NULL default 'blog',\n  views int(10) unsigned NOT NULL default '0',\n  comnum int(10) unsigned NOT NULL default '0',\n  attnum int(10) unsigned NOT NULL default '0',\n  top enum('n','y') NOT NULL default 'n',\n  sortop enum('n','y') NOT NULL default 'n',\n  hide enum('n','y') NOT NULL default 'n',\n  checked enum('n','y') NOT NULL default 'y',\n  allow_remark enum('n','y') NOT NULL default 'y',\n  password varchar(255) NOT NULL default '',\n  template varchar(255) NOT NULL default '',\n  tags text,\n  PRIMARY KEY (gid),\n  KEY author (author),\n  KEY views (views),\n  KEY comnum (comnum),\n  KEY sortid (sortid),\n  KEY top (top,date)\n)" . $table_charset_sql . "\nINSERT INTO {$db_prefix}blog (gid,title,date,content,excerpt,author,views,comnum,attnum,top,sortop,hide,allow_remark,password) VALUES (1, '欢迎使用emlog', '" . time() . "', '恭喜您成功安装了emlog,这是系统自动生成的演示文章。编辑或者删除它,然后开始您的创作吧!', '', 1, 0, 0, 0, 'n', 'n', 'n', 'y', '');\nDROP TABLE IF EXISTS {$db_prefix}attachment;\nCREATE TABLE {$db_prefix}attachment (\n  aid int(10) unsigned NOT NULL auto_increment,\n  blogid int(10) unsigned NOT NULL default '0',\n  filename varchar(255) NOT NULL default '',\n  filesize int(10) NOT NULL default '0',\n  filepath varchar(255) NOT NULL default '',\n  addtime bigint(20) NOT NULL default '0',\n  width int(10) NOT NULL default '0',\n  height int(10) NOT NULL default '0',\n  mimetype varchar(40) NOT NULL default '',\n  thumfor int(10) NOT NULL default 0,\n  PRIMARY KEY  (aid),\n  KEY blogid (blogid)\n)" . $table_charset_sql . "\nDROP TABLE IF EXISTS {$db_prefix}comment;\nCREATE TABLE {$db_prefix}comment (\n  cid int(10) unsigned NOT NULL auto_increment,\n  gid int(10) unsigned NOT NULL default '0',\n  pid int(10) unsigned NOT NULL default '0',\n  date bigint(20) NOT NULL,\n  poster varchar(20) NOT NULL default '',\n  comment text NOT NULL,\n  mail varchar(60) NOT NULL default '',\n  url varchar(75) NOT NULL default '',\n  ip varchar(128) NOT NULL default '',\n  hide enum('n','y') NOT NULL default 'n',\n  PRIMARY KEY  (cid),\n  KEY gid (gid),\n  KEY date (date),\n  KEY hide (hide)\n)" . $table_charset_sql . "\nDROP TABLE IF EXISTS {$db_prefix}options;\nCREATE TABLE {$db_prefix}options (\noption_id INT( 11 ) UNSIGNED NOT NULL auto_increment,\noption_name VARCHAR( 255 ) NOT NULL ,\noption_value LONGTEXT NOT NULL ,\nPRIMARY KEY (option_id),\nKEY option_name (option_name)\n)" . $table_charset_sql . "\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('blogname','点滴记忆');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('bloginfo','使用emlog搭建的站点');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('site_title','');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('site_description','');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('site_key','emlog');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('log_title_style','0');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('blogurl','" . BLOG_URL . "');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('icp','');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('footer_info','');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('admin_perpage_num','15');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('rss_output_num','10');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('rss_output_fulltext','y');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('index_lognum','10');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('index_comnum','10');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('index_twnum','10');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('index_newtwnum','5');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('index_newlognum','5');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('index_randlognum','5');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('index_hotlognum','5');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('comment_subnum','20');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('nonce_templet','default');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('admin_style','default');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('tpl_sidenum','1');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('comment_code','n');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('comment_needchinese','y');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('comment_interval',60);\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('isgravatar','y');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('isthumbnail','y');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('att_maxsize','20480');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('att_type','rar,zip,gif,jpg,jpeg,png,txt,pdf,docx,doc,xls,xlsx');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('att_imgmaxw','420');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('att_imgmaxh','460');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('comment_paging','y');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('comment_pnum','10');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('comment_order','newer');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('login_code','n');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('reply_code','n');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('iscomment','y');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('ischkcomment','y');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('ischkreply','n');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('isurlrewrite','0');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('isalias','n');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('isalias_html','n');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('isexcerpt','n');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('excerpt_subnum','300');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('istreply','n');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('timezone','Asia/Shanghai');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('active_plugins','');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('widget_title','{$widget_title}');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('custom_widget','a:0:{}');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('widgets1','{$widgets}');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('widgets2','');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('widgets3','');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('widgets4','');\nINSERT INTO {$db_prefix}options (option_name, option_value) VALUES ('detect_url','n');\nDROP TABLE IF EXISTS {$db_prefix}link;\nCREATE TABLE {$db_prefix}link (\n  id int(10) unsigned NOT NULL auto_increment,\n  sitename varchar(30) NOT NULL default '',\n  siteurl varchar(75) NOT NULL default '',\n  description varchar(255) NOT NULL default '',\n  hide enum('n','y') NOT NULL default 'n',\n  taxis int(10) unsigned NOT NULL default '0',\n  PRIMARY KEY  (id)\n)" . $table_charset_sql . "\nINSERT INTO {$db_prefix}link (id, sitename, siteurl, description, taxis) VALUES (1, 'emlog', 'http://www.emlog.net', 'emlog官方主页', 0);\nDROP TABLE IF EXISTS {$db_prefix}navi;\nCREATE TABLE {$db_prefix}navi (\n  id int(10) unsigned NOT NULL auto_increment,\n  naviname varchar(30) NOT NULL default '',\n  url varchar(75) NOT NULL default '',\n  newtab enum('n','y') NOT NULL default 'n',\n  hide enum('n','y') NOT NULL default 'n',\n  taxis int(10) unsigned NOT NULL default '0',\n  pid int(10) unsigned NOT NULL default '0',\n  isdefault enum('n','y') NOT NULL default 'n',\n  type tinyint(3) unsigned NOT NULL default '0',\n  type_id int(10) unsigned NOT NULL default '0',\n  PRIMARY KEY  (id)\n)" . $table_charset_sql . "\nINSERT INTO {$db_prefix}navi (id, naviname, url, taxis, isdefault, type) VALUES (1, '首页', '', 1, 'y', 1);\nINSERT INTO {$db_prefix}navi (id, naviname, url, taxis, isdefault, type) VALUES (3, '登录', 'admin', 3, 'y', 3);\nDROP TABLE IF EXISTS {$db_prefix}tag;\nCREATE TABLE {$db_prefix}tag (\n  tid int(10) unsigned NOT NULL auto_increment,\n  tagname varchar(60) NOT NULL default '',\n  gid text NOT NULL,\n  PRIMARY KEY  (tid),\n  KEY tagname (tagname)\n)" . $table_charset_sql . "\nDROP TABLE IF EXISTS {$db_prefix}sort;\nCREATE TABLE {$db_prefix}sort (\n  sid int(10) unsigned NOT NULL auto_increment,\n  sortname varchar(255) NOT NULL default '',\n  alias VARCHAR(200) NOT NULL DEFAULT '',\n  taxis int(10) unsigned NOT NULL default '0',\n  pid int(10) unsigned NOT NULL default '0',\n  description text NOT NULL,\n  template varchar(255) NOT NULL default '',\n  PRIMARY KEY  (sid)\n)" . $table_charset_sql . "\nDROP TABLE IF EXISTS {$db_prefix}user;\nCREATE TABLE {$db_prefix}user (\n  uid int(10) unsigned NOT NULL auto_increment,\n  username varchar(32) NOT NULL default '',\n  password varchar(64) NOT NULL default '',\n  nickname varchar(20) NOT NULL default '',\n  role varchar(60) NOT NULL default '',\n  ischeck enum('n','y') NOT NULL default 'n',\n  photo varchar(255) NOT NULL default '',\n  email varchar(60) NOT NULL default '',\n  description varchar(255) NOT NULL default '',\nPRIMARY KEY  (uid),\nKEY username (username)\n)" . $table_charset_sql . "\nINSERT INTO {$db_prefix}user (uid, username, password, role) VALUES (1,'{$admin}','" . $adminpw . "','admin');\nDROP TABLE IF EXISTS {$db_prefix}storage;\nCREATE TABLE {$db_prefix}storage (\n  `sid` int(8) NOT NULL AUTO_INCREMENT,\n  `plugin` varchar(32) NOT NULL,\n  `name` varchar(32) NOT NULL,\n  `type` varchar(8) NOT NULL,\n  `value` text NOT NULL,\n  `createdate` int(11) NOT NULL,\n  `lastupdate` int(11) NOT NULL,\n  PRIMARY KEY (`sid`),\n  UNIQUE KEY `plugin` (`plugin`,`name`)\n)" . $table_charset_sql;
 $array_sql = preg_split("/;[\r\n]/", $sql);
 foreach ($array_sql as $sql) {
     $sql = trim($sql);
     if ($sql) {
         $DB->query($sql);
     }
 }
 //重建缓存
 $CACHE->updateCache();
 $result .= "\n        <p style=\"font-size:24px; border-bottom:1px solid #E6E6E6; padding:10px 0px;\">恭喜,安装成功!</p>\n        <p>您的emlog已经安装好了,现在可以开始您的创作了,就这么简单!</p>\n        <p><b>用户名</b>:{$admin}</p>\n        <p><b>密 码</b>:您刚才设定的密码</p>";
 if (DEL_INSTALLER === 1 && !@unlink('./install.php') || DEL_INSTALLER === 0) {
     $result .= '<p style="color:red;margin:10px 20px;">警告:请手动删除根目录下安装文件:install.php</p> ';
 }
 $result .= "<p style=\"text-align:right;\"><a href=\"./\">访问首页</a> | <a href=\"./admin/\">登录后台</a></p>";
示例#5
0
function _init_loadSettings()
{
    // get settings filenames and paths (either)
    list($hostnameWithoutPort) = explode(':', strtolower(@$_SERVER['HTTP_HOST']));
    $hostnameWithoutPort = preg_replace('/[^\\w\\-\\.]/', '', $hostnameWithoutPort);
    // security: HTTP_HOST is user defined - remove non-filename chars to prevent ../ attacks
    $hostnameWithoutPort = preg_replace('/^www\\./i', '', $hostnameWithoutPort);
    // v2.50 - usability: don't require www. prefix so www.example.com and example.com both check for settings.example.com.php
    $settings_fileName = 'settings.' . preg_replace('/[^\\w\\-\\.]/', '', $hostnameWithoutPort) . '.php';
    $settings_filePath = DATA_DIR . '/' . $settings_fileName;
    // supports host based settings files such as: /data/settings.localhost.php
    define('SETTINGS_DEV_FILENAME', $settings_fileName);
    define('SETTINGS_DEV_FILEPATH', DATA_DIR . '/' . SETTINGS_DEV_FILENAME);
    // set settings name and path for this server
    $useDev = is_file(SETTINGS_DEV_FILEPATH);
    define('SETTINGS_FILENAME', $useDev ? SETTINGS_DEV_FILENAME : 'settings.dat.php');
    define('SETTINGS_FILEPATH', $useDev ? SETTINGS_DEV_FILEPATH : DATA_DIR . '/settings.dat.php');
    // Require hostname-based settings files on development server domains (this section to be expanded)
    if (isInstalled() && isDevServer() && !is_file(SETTINGS_DEV_FILEPATH)) {
        header("Content-type: text/plain");
        die("Development server requires custom settings files.  Delete /data/isInstalled.php and re-install to create one.");
    }
    // load settings
    global $SETTINGS;
    if (!is_file(SETTINGS_FILEPATH)) {
        renameOrRemoveDefaultFiles();
    }
    // rename settings.dat.php.default to settings.dat.php
    $SETTINGS = loadStructOrINI(SETTINGS_FILEPATH);
    // legacy support
    $SETTINGS['advanced']['encryptPasswords'] = 1;
    // added in 2.08, removed in 2.62 (force on for legacy support since encryption is always required now)
    ### set defaults (if not already defined in settings file - this happens when a user upgrades)
    // NOTE: Do this here for future instead of _upgradeSettings()
    $defaults = array('language' => '', 'adminEmail' => '', 'adminUrl' => '', 'cookiePrefix' => substr(md5(mt_rand()), 0, 5) . '_', 'activePlugins' => '', 'headerImageUrl' => '', 'footerHTML' => '', 'dateFormat' => '', 'cssTheme' => 'blue.css', 'webRootDir' => @$_SERVER['DOCUMENT_ROOT'], 'wysiwyg' => array(), 'advanced' => array(), 'bgtasks_lastRun' => '0', 'bgtasks_lastEmail' => '0', 'webPrefixUrl' => '');
    $wysiwygDefaults = array('wysiwygLang' => 'en', 'includeDomainInLinks' => '0');
    $advancedDefaults = array('imageResizeQuality' => 80, 'showExpandedMenu' => 0, 'disableFlashUploader' => 0, 'codeGeneratorExpertMode' => 0, 'hideLanguageSettings' => 0, 'session_cookie_domain' => '', 'session_save_path' => '', 'useDatepicker' => 0, 'requireHTTPS' => 0, 'httpProxyServer' => '', 'allowRelatedRecordsDragSorting' => 0, 'outgoingMail' => 'sendOnly', 'languageDeveloperMode' => 0, 'login_expiry_limit' => '30', 'login_expiry_unit' => 'minutes', 'restrictByIP' => 0, 'restrictByIP_allowed' => '', 'smtp_method' => 'php', 'smtp_hostname' => '', 'smtp_port' => '', 'smtp_username' => '', 'smtp_password' => '', 'phpHideErrors' => '0', 'phpEmailErrors' => '0', 'checkReferer' => '1', 'disableAutocomplete' => '0');
    foreach ($defaults as $key => $value) {
        if (!array_key_exists($key, $SETTINGS)) {
            $SETTINGS[$key] = $value;
        }
    }
    foreach ($wysiwygDefaults as $key => $value) {
        if (!array_key_exists($key, $SETTINGS['wysiwyg'])) {
            $SETTINGS['wysiwyg'][$key] = $value;
        }
    }
    foreach ($advancedDefaults as $key => $value) {
        if (!array_key_exists($key, $SETTINGS['advanced'])) {
            $SETTINGS['advanced'][$key] = $value;
        }
    }
    ### custom defaults
    // adminUrl - update if url path has changed
    if (defined('IS_CMS_ADMIN')) {
        $hasAdminPathChanged = parse_url(thisPageUrl(), PHP_URL_PATH) != parse_url(@$SETTINGS['adminUrl'], PHP_URL_PATH);
        if ($hasAdminPathChanged) {
            // only update adminUrl when in the CMS admin
            $SETTINGS['adminUrl'] = @array_shift(explode('?', thisPageUrl()));
            // added in 2.12 - this must be set when admin.php is being access directly so we get the right URL
            saveSettings();
            alert(sprintf(t("Updating Program Url to: %s") . "<br/>\n", $SETTINGS['adminUrl']));
        }
    }
    // set default uploadDir and uploadUrl (do this here as above defaults code only runs when keys are undefined, not when they are blank)
    if (!$SETTINGS['uploadDir']) {
        $SETTINGS['uploadDir'] = 'uploads/';
        // previously: /../uploads/
    }
    if (!$SETTINGS['uploadUrl'] && !inCLI()) {
        // SCRIPT_NAME is set to filepath not web path when running in CLI, giving us incorrect values
        $SETTINGS['uploadUrl'] = dirname($_SERVER['SCRIPT_NAME']) . "/uploads/";
        // previously: /../uploads/
        $SETTINGS['uploadUrl'] = realUrl($SETTINGS['uploadUrl']);
        // remove ../ parent reference
        $SETTINGS['uploadUrl'] = parse_url($SETTINGS['uploadUrl'], PHP_URL_PATH);
        // remove scheme://hostname and leave /url/path
    }
    // remove old settings
    $removeKeys = array('vendorPoweredBy', 'timezoneOffsetAddMinus', 'timezoneOffsetHours', 'timezoneOffsetMinutes');
    $removeCount = 0;
    foreach ($removeKeys as $key) {
        if (array_key_exists($key, $SETTINGS)) {
            unset($SETTINGS[$key]);
            $removeCount++;
        }
    }
    if ($removeCount) {
        saveSettings();
    }
    // remove/convert old 'isInstalled' setting (from v2.09)
    if (array_key_exists('isInstalled', $SETTINGS)) {
        isInstalled(true);
        // set new installed status (semaphore file)
        unset($SETTINGS['isInstalled']);
        saveSettings();
    }
    // Update PHP config with SMTP values from settings (only effects users who call mail() explicitly)
    if ($GLOBALS['SETTINGS']['advanced']['smtp_hostname']) {
        ini_set('SMTP', $GLOBALS['SETTINGS']['advanced']['smtp_hostname']);
    }
    if ($GLOBALS['SETTINGS']['advanced']['smtp_port']) {
        ini_set('smtp_port', $GLOBALS['SETTINGS']['advanced']['smtp_port']);
    }
    // Note: We don't need to return $SETTINGS because we're modifying the global.
}
示例#6
0
function cron_logErrorsOnDieOrExit()
{
    if (!@$GLOBALS['CRON_JOB_LOG_NUM']) {
        return;
    }
    $summary = t("Returned errors");
    $output = ob_get_clean();
    $runtime = sprintf("%0.2f", microtime(true) - $GLOBALS['CRON_JOB_START']);
    // update job log entry
    mysql_update('_cron_log', $GLOBALS['CRON_JOB_LOG_NUM'], null, array('summary' => $summary, 'output' => $output, 'runtime' => $runtime));
    // send email
    $secondsAgo = time() - $GLOBALS['SETTINGS']['bgtasks_lastEmail'];
    if ($secondsAgo >= 60 * 60) {
        // don't email more than once an hour
        // get email placeholders
        $cronLog = mysql_get('_cron_log', $GLOBALS['CRON_JOB_LOG_NUM']);
        $placeholders = array('bgtask.date' => $cronLog['createdDate'], 'bgtask.activity' => $cronLog['activity'], 'bgtask.summary' => nl2br(htmlencode($cronLog['summary'])), 'bgtask.completed' => $cronLog['completed'], 'bgtask.function' => $cronLog['function'], 'bgtask.output' => nl2br(htmlencode($cronLog['output'])), 'bgtask.runtime' => $cronLog['runtime'], 'bgtask.function' => $cronLog['function'], 'bgtasks.logsUrl' => realUrl("?menu=_cron_log", $GLOBALS['SETTINGS']['adminUrl']), 'bgtasks.settingsUrl' => realUrl("?menu=admin&action=general#background-tasks", $GLOBALS['SETTINGS']['adminUrl']));
        // send message
        $errors = sendMessage(emailTemplate_loadFromDB(array('template_id' => 'CMS-BGTASK-ERROR', 'placeholders' => $placeholders)));
        if ($errors) {
            die("Mail Error: {$errors}");
        }
        // update last emailed time
        $GLOBALS['SETTINGS']['bgtasks_lastEmail'] = time();
        saveSettings();
    }
}
示例#7
0
function redirectBrowserToURL($url, $queryStringsOnly = false)
{
    if (!$url) {
        die(__FUNCTION__ . ": No url specified!");
    }
    // make relative urls absolute - works with /absolute/filepath.php, ?query=string, and relative/filepaths.php
    $url = realUrl($url);
    // force query string only urls (remove anything but query string and then query realUrl from that)
    if ($queryStringsOnly) {
        $url = realUrl('?' . parse_url($url, PHP_URL_QUERY));
    }
    //
    $url = str_replace(' ', '%20', $url);
    // url encoded spaces
    $htmlEncodedUrl = htmlencode($url);
    ### if content headers haven't been send yet sent http redirect and html content header
    if (!headers_sent()) {
        # Fix IIS/5.0 bug "Set-Cookie Is Ignored in CGI When Combined With Location" described here: http://support.microsoft.com/kb/q176113/
        $isIIS5 = $_SERVER['SERVER_SOFTWARE'] == 'Microsoft-IIS/5.0';
        # IIS 5.1 doesn't seem effected
        if ($isIIS5) {
            print "<meta http-equiv='refresh' content='0;URL={$htmlEncodedUrl}'>\n";
            exit;
        }
        header("Location: {$url}");
        print "<meta http-equiv='refresh' content='0;URL={$htmlEncodedUrl}'>\n";
        print "This page has moved. If you aren't automatically forwarded to the new location ";
        print "then click the following link: <a href='{$htmlEncodedUrl}'>{$url}</a>.\n";
        exit;
    }
    ### if content headers have already been sent use javascript and/or meta refresh to redirect user
    // use javascript to redirect user
    print "\n\n<script>window.location = '" . addslashes($url) . "';</script>\n";
    // use meta refresh to redirect url
    print "<meta http-equiv='refresh' content='0;URL={$htmlEncodedUrl}'>\n";
    // print redirect message with link (in case other methods fail)
    print "\n<p>Redirecting to <a href='{$htmlEncodedUrl}'>{$url}</a>.</p>\n";
    exit;
}
function getUploadDirAndUrl($fieldSchema, $settingsUploadDir = null, $settingsUploadUrl = null, $returnOnErrors = false)
{
    if ($settingsUploadDir === null) {
        $settingsUploadDir = $GLOBALS['SETTINGS']['uploadDir'];
    }
    if ($settingsUploadUrl === null) {
        $settingsUploadUrl = $GLOBALS['SETTINGS']['uploadUrl'];
    }
    // get upload dir and url
    if (@$fieldSchema['useCustomUploadDir']) {
        // if field is configured to use custom upload paths, use them
        $uploadDir = $fieldSchema['customUploadDir'];
        $uploadUrl = $fieldSchema['customUploadUrl'];
        list($baseDir, $baseUrl) = getUploadDirAndUrl(array());
        // path for resolving CUSTOM dirs/urls: Uses upload dir/url from general settings made absolute using CMS dir/url
    } else {
        // default to using global SETTINGS upload paths
        $uploadDir = $settingsUploadDir;
        $uploadUrl = $settingsUploadUrl;
        $baseDir = SCRIPT_DIR;
        // paths for resolving relative dirs and urls (CMS Script Dir)
        $baseUrl = dirname(@$GLOBALS['SETTINGS']['adminUrl']) . '/';
        // paths for resolving relative dirs and urls (CMS Script Dir URL)
    }
    $uploadDir = applyFilters('upload_uploadDir', $uploadDir, $fieldSchema);
    $uploadUrl = applyFilters('upload_uploadUrl', $uploadUrl, $fieldSchema);
    doAction('upload_dirAndUrl', $uploadDir, $uploadUrl);
    // make path absolute (and format/normalize it)
    $uploadDir = absPath($uploadDir, $baseDir);
    if (!endsWith('/', $uploadDir)) {
        $uploadDir .= '/';
    }
    // absPath doesn't return trailing slash, but we require that for user entered values and expect it in the code
    // make urls absolute, starting with either http:// or /
    if (!isAbsoluteUrl($uploadUrl) && !preg_match("|^/|", $uploadUrl)) {
        $uploadUrl = coalesce($uploadUrl, './');
        // added ./ so blank upload url gets DIR of $baseUrl, not baseurl with admin.php on the end
        $uploadUrl = realUrl($uploadUrl, $baseUrl);
        $uploadUrl = preg_replace("|^\\w+://[^/]+|", '', $uploadUrl);
        // remove scheme://hostname
    }
    if (!endsWith('/', $uploadUrl)) {
        $uploadUrl .= '/';
    }
    //
    return array($uploadDir, $uploadUrl);
}