Ejemplo n.º 1
0
 /**
  * 写log
  *
  * @param string $logfile        	
  * @param array $data        	
  * @param boolean $additional        	
  */
 public static function writeInstallLog($logfile, $data, $additional = false)
 {
     if ($additional) {
         $_data = self::readInstallLog($logfile);
         if ($_data) {
             $data = array_merge($_data, $data);
         }
     }
     return WindFile::savePhpData($logfile, $data);
 }
Ejemplo n.º 2
0
 /**
  * step 6 : 数据库更新操作
  *
  * 先执行update.sql,再跳转到update.php
  */
 public function dbAction()
 {
     $step = (int) Wekit::cache()->get('system_upgrade_db_step');
     $step || $this->installService->after($this->localFileList, Wekit::cache()->get('system_upgrade_ftp'), $this->fileList);
     $sqlFile = Wind::getRealPath('PUBLIC:update.sql', true);
     $success = 1;
     if (!file_exists($sqlFile)) {
         Wekit::cache()->set('system_upgrade_step', 6);
         PwSystemHelper::log('no db update', $this->version);
         $this->forwardRedirect(WindUrlHelper::createUrl('appcenter/upgrade/php'));
     }
     $lang = Wind::getComponent('i18n');
     try {
         /* @var $db WindConnection */
         $db = Wind::getComponent('db');
         if (!$step) {
             $sqlArray = PwSystemHelper::sqlParser(WindFile::read($sqlFile), $db->getConfig('charset', '', 'utf8'), $db->getTablePrefix(), $db->getConfig('engine', '', 'MYISAM'));
             WindFile::savePhpData(DATA_PATH . 'upgrade/sql.tmp', $sqlArray);
         } else {
             $sqlArray = (include DATA_PATH . 'upgrade/sql.tmp');
         }
         end($sqlArray);
         if ($step > key($sqlArray)) {
             Wekit::cache()->set('system_upgrade_step', 6);
             PwSystemHelper::log('db update success', $this->version);
             $this->forwardRedirect(WindUrlHelper::createUrl('appcenter/upgrade/php'));
         }
         $sql = $sqlArray[$step];
         if ($sql) {
             foreach ($sql as $v) {
                 if (empty($v)) {
                     continue;
                 }
                 if (preg_match('/^ALTER\\s+TABLE\\s+`?(\\w+)`?\\s+(DROP|ADD)\\s+(KEY|INDEX|UNIQUE)\\s+([\\w\\(\\),`]+)?/i', $v, $matches)) {
                     list($key, $fields) = explode('(', $matches[4]);
                     $fields = trim($fields, '),');
                     list($matches[3]) = explode(' ', $matches[3]);
                     $matches[3] = trim(strtoupper($matches[3]));
                     PwSystemHelper::log($matches[1] . ' ' . str_replace('`', '', $key) . ' ' . ($fields ? str_replace('`', '', $fields) : '') . ' ' . $matches[3], $this->version);
                     PwSystemHelper::alterIndex(array($matches[1], str_replace('`', '', $key), $fields ? str_replace('`', '', $fields) : '', $matches[3], $matches[2]), $db);
                 } elseif (preg_match('/^ALTER\\s+TABLE\\s+`?(\\w+)`?\\s+(CHANGE|DROP|ADD)\\s+`?(\\w+)`?/i', $v, $matches)) {
                     PwSystemHelper::log($matches[1] . ' ' . $matches[3], $this->version);
                     PwSystemHelper::alterField(array($matches[1], $matches[3], $v), $db);
                 } else {
                     PwSystemHelper::log('execute sql ' . $v, $this->version);
                     $db->execute($v);
                 }
             }
         }
     } catch (Exception $e) {
         if ($e instanceof WindForwardException) {
             throw $e;
         }
         $success = 0;
         $this->setOutput(1, 'error');
         PwSystemHelper::log('execute sql failed' . $e->getMessage(), $this->version);
         $this->setOutput($lang->getMessage('APPCENTER:upgrade.db.error', array(implode(';', $sql))), 'msg');
     }
     if ($success) {
         $this->setOutput($lang->getMessage('APPCENTER:upgrade.db.update', array($step, key($sqlArray))), 'msg');
     }
     Wekit::cache()->set('system_upgrade_db_step', ++$step);
 }
Ejemplo n.º 3
0
 /**
  * 更新缓存
  * 
  * @return boolean
  */
 public function updateCache()
 {
     $data = $this->_getWindidAreaDs()->fetchAll();
     $file = Wind::getRealPath('DATA:area.area.php', true);
     WindFolder::mk(dirname($file));
     WindFile::savePhpData($file, $data, true);
     return $data;
 }
Ejemplo n.º 4
0
 protected function buildThreeArea()
 {
     $fileTmp = WindSecurity::escapePath(Wind::getRealDir('DATA:') . 'tmp/' . 'area.php');
     file_exists($fileTmp) && (self::$_map = (include $fileTmp));
     if (!self::$_map) {
         $area = $this->_getAreaDs()->fetchAll();
         foreach ($area as $key => $value) {
             if ($value['parentid'] < 100) {
                 continue;
             }
             self::$_map[] = $value['areaid'];
         }
         WindFile::savePhpData($fileTmp, self::$_map);
     }
     return self::$_map;
 }
Ejemplo n.º 5
0
            $pic_ids = explode("|", $pic_link_ups);
            foreach ($pic_ids as $k => $v) {
                if ($v) {
                    if ($_FILES['up_pic_' . $v]['error'] == 0) {
                        $rand = date("YmdHis") . random(3, $numeric = 1);
                        $filetype = array("jpg", "JPG", "jpeg", "JPEG", "gif", "GIF", "png", "PNG");
                        $arr = explode(".", $_FILES['up_pic_' . $v]["name"]);
                        $hz = $arr[count($arr) - 1];
                        $filepath = "source/plugin/dz55625_haodian/upimg/" . date("Ymd") . "/";
                        $randname = date("Y") . date("m") . date("d") . date("H") . date("i") . date("s") . rand(100, 999) . "." . $hz;
                        if (!file_exists($filepath)) {
                            mkdir($filepath);
                        }
                        if (@copy($_FILES['up_pic_' . $v]['tmp_name'], $filepath . $randname) || function_exists('move_uploaded_file') && @move_uploaded_file($_FILES['up_pic_' . $v]['tmp_name'], $filepath . $randname)) {
                            @unlink($_FILES['up_pic_' . $v]['tmp_name']);
                        }
                        $pic = "source/plugin/dz55625_haodian/upimg/" . date("Ymd") . "/" . $randname . "";
                        new myThumbClass($pic, 308, 180, $pic, 0, 0);
                        $conf['magic_lantern'][$v]['pic'] = $pic;
                    } else {
                        unset($conf['magic_lantern'][$v]['link']);
                    }
                }
            }
        }
        WindFile::savePhpData($file, $conf);
        cpmsg($php_lang['lbianjiok'], $appurl);
    } else {
        cpmsg($php_lang['czerror'], $appurl);
    }
}
Ejemplo n.º 6
0
 /**
  * 应用的设置提交
  *
  */
 public function doRunAction()
 {
     $conf = $this->getInput('conf', 'post');
     WindFile::savePhpData($this->file, $conf);
     $this->showMessage('success');
 }
Ejemplo n.º 7
0
 /**
  * windid更新
  * 
  * @return boolean
  */
 private function _writeWindid()
 {
     $baseUrl = Wind::getApp()->getRequest()->getBaseUrl(true);
     $key = md5(WindUtility::generateRandStr(10));
     $charset = Wind::getApp()->getResponse()->getCharset();
     $charset = str_replace('-', '', strtolower($charset));
     if (!in_array($charset, array('gbk', 'utf8', 'big5'))) {
         $charset = 'utf8';
     }
     Wind::import('WINDID:service.app.dm.WindidAppDm');
     $dm = new WindidAppDm();
     $dm->setApiFile('windid.php')->setIsNotify('1')->setIsSyn('1')->setAppName('phpwind9.0')->setSecretkey($key)->setAppUrl($baseUrl)->setCharset($charset)->setAppIp('');
     $result = Windid::load('app.WindidApp')->addApp($dm);
     if ($result instanceof WindidError) {
         $this->showError('INSTALL:windid.init.fail');
     }
     $config = array('windid' => 'local', 'serverUrl' => $baseUrl, 'clientId' => (int) $result, 'clientKey' => $key, 'clientDb' => 'mysql', 'clientCharser' => $charset);
     WindFile::savePhpData(Wind::getRealPath('ROOT:conf.windidconfig.php', true), $config);
     return true;
 }
Ejemplo n.º 8
0
 protected function deleteValue($key)
 {
     return WindFile::savePhpData($key, '', 'w');
 }
Ejemplo n.º 9
0
 /**
  * 创建创始人
  *
  * @param string $manager
  * @param string $manager_pwd
  * @param string $manager_email
  * @return PwError
  */
 private function _writeFounder($manager, $manager_pwd, $manager_email)
 {
     Wekit::C()->reload('windid');
     Wind::import('SRV:user.dm.PwUserInfoDm');
     $data = array($manager => md5($manager_pwd));
     WindFile::savePhpData($this->_getFounderFile(), $data);
     //TODO 创始人添加:用户的配置信息先更新。添加完之后再更新回 开始
     $config = new PwConfigSet('register');
     $config->set('security.username.max', 15)->set('security.ban.username', '')->set('security.username.min', 1)->set('security.password.max', 25)->set('security.password.min', 1)->flush();
     Wind::import('WINDID:service.config.srv.WindidConfigSet');
     $windidConfig = new WindidConfigSet('reg');
     $windidConfig->set('security.ban.username', '')->set('security.password.max', 25)->set('security.password.min', 1)->set('security.username.max', 15)->set('security.username.min', 1)->flush();
     Wekit::C()->reload('register');
     WindidApi::C()->reload('reg');
     //TODO结束
     $userDm = new PwUserInfoDm();
     $userDm->setUsername($manager)->setPassword($manager_pwd)->setEmail($manager_email)->setGroupid(3)->setRegdate(Pw::getTime())->setLastvisit(Pw::getTime())->setRegip(Wind::getApp()->getRequest()->getClientIp())->setGroups(array('3' => '0'));
     //特殊操作  gao.wanggao
     if (true !== ($result = $userDm->beforeAdd())) {
         $this->showError($result->getError());
     }
     if (($uid = Wekit::load('WSRV:user.WindidUser')->addUser($userDm->dm)) < 1) {
         $this->showError('WINDID:code.' . $uid);
     }
     $userDm->setUid($uid);
     Wind::import('SRV:user.PwUser');
     $daoMap = array();
     $daoMap[PwUser::FETCH_MAIN] = 'user.dao.PwUserDao';
     $daoMap[PwUser::FETCH_DATA] = 'user.dao.PwUserDataDao';
     $daoMap[PwUser::FETCH_INFO] = 'user.dao.PwUserInfoDao';
     Wekit::loadDaoFromMap(PwUser::FETCH_ALL, $daoMap, 'PwUser')->addUser($userDm->getSetData());
     //特殊操作
     //$uid = Wekit::load('user.PwUser')->addUser($userDm);
     //TODO 创始人添加完成:恢复默认数据:开始
     $config = new PwConfigSet('register');
     $config->set('security.username.max', 15)->set('security.ban.username', '创始人,管理员,版主,斑竹,admin')->set('security.username.min', 3)->set('security.password.max', 15)->set('security.password.min', 6)->flush();
     $windidConfig = new WindidConfigSet('reg');
     $windidConfig->set('security.ban.username', '创始人,管理员,版主,斑竹,admin')->set('security.password.max', 15)->set('security.password.min', 6)->set('security.username.max', 15)->set('security.username.min', 3)->flush();
     //TODO 结束
     if ($uid instanceof PwError) {
         $this->showError($uid->getError());
     }
     Wekit::load('user.PwUserBelong')->update($uid, array(3 => 0));
     //特殊操作  gao.wanggao
     $this->_defaultAvatar($uid);
     $this->_defaultAvatar(0);
     //特殊操作
     //Wekit::load('user.srv.PwUserService')->restoreDefualtAvatar($uid);//用户的默认头像需要设置
     //Wekit::load('user.srv.PwUserService')->restoreDefualtAvatar(0);//游客的默认头像需要设置
     //站点统计信息
     Wind::import('SRV:site.dm.PwBbsinfoDm');
     $dm = new PwBbsinfoDm();
     $dm->setNewmember($manager)->addTotalmember(1);
     Wekit::load('site.PwBbsinfo')->updateInfo($dm);
     return $uid;
 }
Ejemplo n.º 10
0
 /**
  * 更新创始人信息
  * 
  * @return boolean PwError
  */
 private function updateFounder()
 {
     $r = WindFile::savePhpData($this->getFounderFilePath(), $this->_founder);
     return $r ? $r : new PwError('ADMIN:founder.file.write.fail');
 }
Ejemplo n.º 11
0
 /**
  * 备份
  * 
  * @return void
  */
 public function dobackAction()
 {
     @set_time_limit(500);
     list($sizelimit, $compress, $start, $tableid, $step, $dirname) = $this->getInput(array('sizelimit', 'compress', 'start', 'tableid', 'step', 'dirname'));
     list($tabledb, $insertmethod, $tabledbname) = $this->getInput(array('tabledb', 'insertmethod', 'tabledbname'));
     //关闭站点
     $backupService = $this->_getBackupService();
     $tabledbTmpSaveDir = $backupService->getDataDir() . 'tmp/';
     $backupService->createFolder($tabledbTmpSaveDir);
     $tableid = intval($tableid);
     $tableid = $tableid ? $tableid : 0;
     $insertmethod = $insertmethod == 'extend' ? 'extend' : 'common';
     $sizelimit = $sizelimit ? $sizelimit : 2048;
     (!is_array($tabledb) || !$tabledb) && !$step && $this->showError('BACKUP:name.empty');
     // 读取保存的需要操作的表
     if (!$tabledb && $step) {
         $cachedTable = WindFile::read(WindSecurity::escapePath($tabledbTmpSaveDir . $tabledbname . '.tmp'));
         $tabledb = explode("|", $cachedTable);
     }
     !$dirname && ($dirname = $backupService->getDirectoryName());
     // 第一次临时保存需要操作的表
     if (!$step) {
         $config = new PwConfigSet('site');
         $siteState = Wekit::load('config.PwConfig')->getValues('site');
         WindFile::savePhpData(WindSecurity::escapePath($tabledbTmpSaveDir . tempSite . '.php'), $siteState['visit.state']);
         $config->set('visit.state', 2)->flush();
         $specialTables = array_intersect($backupService->getSpecialTables(), $tabledb);
         $tabledb = array_values(array_diff($tabledb, $backupService->getSpecialTables()));
         // 备份数据表结构
         // 备份特殊表结构和数据
         if ($specialTables) {
             $backupService->backupSpecialTable($specialTables, $dirname, $compress, $insertmethod);
         }
         if ($tabledb) {
             $backupService->backupTable($tabledb, $dirname, $compress);
             $tabledbname = 'cached_table_buckup';
             WindFile::write(WindSecurity::escapePath($tabledbTmpSaveDir . $tabledbname . '.tmp'), implode("|", $tabledb), 'wb');
         }
     }
     if (!$tabledb) {
         $this->showMessage(array('BACKUP:bakup_success', array('{path}' => $backupService->getSavePath() . $dirname)), 'admin/backup/backup/run');
     }
     // 保存数据
     $step = (!$step ? 1 : $step) + 1;
     $filename = $dirname . '/' . $dirname . '_' . ($step - 1) . '.sql';
     list($backupData, $tableid, $start, $totalRows) = $backupService->backupData($tabledb, $tableid, $start, $sizelimit, $insertmethod, $filename);
     $continue = $tableid < count($tabledb) ? true : false;
     $backupService->saveData($filename, $backupData, $compress);
     // 循环执行
     if ($continue) {
         $currentTableName = $tabledb[$tableid];
         $currentPos = $start + 1;
         $createdFileNum = $step - 1;
         $referer = 'admin/backup/backup/doback?' . "start={$start}&tableid={$tableid}&sizelimit={$sizelimit}&step={$step}&insertmethod={$insertmethod}&compress={$compress}&tabledbname={$tabledbname}&dirname={$dirname}";
         $this->showMessage(array('BACKUP:bakup_step', array('{currentTableName}' => $currentTableName, '{totalRows}' => $totalRows, '{currentPos}' => $currentPos, '{createdFileNum}' => $createdFileNum)), $referer, true);
     } else {
         //还原站点
         $siteState = (require_once WindSecurity::escapePath($tabledbTmpSaveDir . tempSite . '.php'));
         $config = new PwConfigSet('site');
         $config->set('visit.state', $siteState)->flush();
         unlink(WindSecurity::escapePath($tabledbTmpSaveDir . $tabledbname . '.tmp'));
         $this->showMessage(array('BACKUP:bakup_success', array('{path}' => $backupService->getSavePath() . $dirname)), 'admin/backup/backup/run');
     }
 }