Example #1
0
 public function actionViewXml()
 {
     Controller::disableProfiler();
     $this->isXml = true;
     $map = $this->generateMap($this->isXml);
     if (is_array($map) && count($map) > 0) {
         header('Content-type: text/xml');
         header('Pragma: public');
         header('Cache-control: private');
         header('Expires: -1');
         $xmlWriter = new XMLWriter();
         $xmlWriter->openMemory();
         $xmlWriter->setIndent(true);
         $xmlWriter->startDocument('1.0', 'UTF-8');
         $xmlWriter->startElement('urlset');
         $xmlWriter->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
         foreach ($map as $item) {
             if (isset($item['url'])) {
                 $this->prepareItem($item, $xmlWriter, $this->isXml);
             }
             if (isset($item['subsection']) && count($item['subsection']) > 0) {
                 foreach ($item['subsection'] as $value) {
                     if (isset($value['url'])) {
                         $this->prepareItem($value, $xmlWriter, $this->isXml);
                     }
                     if (isset($value['apartments']) && count($value['apartments']) > 0) {
                         foreach ($value['apartments'] as $apartment) {
                             if (isset($apartment['url'])) {
                                 $this->prepareItem($apartment, $xmlWriter, $this->isXml);
                             }
                         }
                     }
                 }
             }
         }
         $xmlWriter->endElement();
         // end xmlns
         echo $xmlWriter->outputMemory();
     } else {
         echo 'no elements';
     }
 }
Example #2
0
 public function actionViewFeed()
 {
     $oldLang = Yii::app()->language;
     Controller::disableProfiler();
     $defaultLangs = Lang::getDefaultLang();
     Yii::app()->language = $defaultLangs;
     // если есть русский или украинский языки, но они не дефолтные. установим на время их.
     if ($defaultLangs != 'ru' || $defaultLangs != 'uk') {
         $allLangs = Lang::getActiveLangs();
         if (array_key_exists('ru', $allLangs)) {
             Yii::app()->language = 'ru';
         } elseif (array_key_exists('uk', $allLangs)) {
             Yii::app()->language = 'uk';
         }
     }
     $items = $this->generateFeed();
     if (is_array($items) && count($items) > 0) {
         header('Content-type: text/xml');
         header('Pragma: public');
         header('Cache-control: private');
         header('Expires: -1');
         $xmlWriter = new XMLWriter();
         $xmlWriter->openMemory();
         $xmlWriter->setIndent(true);
         $xmlWriter->startDocument('1.0', 'UTF-8');
         $xmlWriter->startElement('realty-feed');
         $xmlWriter->writeAttribute('xmlns', 'http://webmaster.yandex.ru/schemas/feed/realty/2010-06');
         $xmlWriter->writeElement('generation-date', $this->generationDate);
         foreach ($items as $item) {
             if (isset($item['id'])) {
                 $this->prepareItem($item, $xmlWriter);
             }
         }
         $xmlWriter->endElement();
         // end realty-feed (xmlns)
         echo $xmlWriter->outputMemory();
     } else {
         echo 'no elements';
     }
     // установим обратно пользовательский язык
     Yii::app()->language = $oldLang;
 }
Example #3
0
 public function actionUploadImage()
 {
     $allowExtension = array('png', 'jpg', 'gif', 'jpeg');
     if (Yii::app()->user->checkAccess('upload_from_wysiwyg')) {
         $type = Yii::app()->request->getQuery('type');
         Controller::disableProfiler();
         // yii-debug-toolbar disabler
         if ($type == 'imageUpload') {
             if (!empty($_FILES['upload']['name']) && !Yii::app()->user->isGuest) {
                 //$dir = Yii::getPathOfAlias('webroot.upload') . '/' . Yii::app()->user->id . '/';
                 $dir = Yii::getPathOfAlias('webroot.uploads.editor') . '/';
                 if (!is_dir($dir)) {
                     @mkdir($dir, '0777', true);
                 }
                 $file = CUploadedFile::getInstanceByName('upload');
                 if ($file) {
                     $newName = md5(time()) . '.' . $file->extensionName;
                     $error = '';
                     $callback = $_GET['CKEditorFuncNum'];
                     if (in_array($file->extensionName, $allowExtension)) {
                         if ($file->saveAs($dir . $newName)) {
                             $httpPath = Yii::app()->getBaseUrl(true) . '/uploads/editor/' . $newName;
                         } else {
                             $error = 'Some error occured please try again later';
                             $httpPath = '';
                         }
                     } else {
                         $error = 'The file is not the image';
                         $httpPath = '';
                     }
                     echo "<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction(" . $callback . ",  \"" . $httpPath . "\", \"" . $error . "\" );</script>";
                 }
             }
         }
     }
 }
 public function actionDownloadFile($fileId = null)
 {
     $this->setActiveMenu('my_mailbox');
     if ($fileId) {
         $sql = 'SELECT id_message, orig_file_path, file_path FROM {{messages_files}} WHERE file_id = "' . (int) $fileId . '"';
         $result = Yii::app()->db->createCommand($sql)->queryRow();
         if ($result) {
             if (!Yii::app()->user->checkAccess('backend_access')) {
                 $sqlOwner = 'SELECT id_userTo, id_userFrom FROM {{messages}} WHERE id = "' . $result['id_message'] . '"';
                 $resultOwner = Yii::app()->db->createCommand($sqlOwner)->queryRow();
                 if ($resultOwner['id_userTo'] != Yii::app()->user->id && $resultOwner['id_userFrom'] != Yii::app()->user->id) {
                     throw404();
                 }
             }
             $message = new Messages();
             Controller::disableProfiler();
             Yii::app()->request->sendFile($result['orig_file_path'], file_get_contents($message->uploadPath . '/' . $result['file_path']));
         } else {
             throw404();
         }
     }
 }
Example #5
0
 public function actionConfig()
 {
     Controller::disableProfiler();
     $model = new InstallForm();
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'install-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     $this->checkRequirements();
     $this->checkRightFile();
     if (isset($_POST['InstallForm'])) {
         $model->attributes = $_POST['InstallForm'];
         if ($model->validate()) {
             // form inputs are valid, do something here
             try {
                 $ds = DIRECTORY_SEPARATOR;
                 $dbConfFile = Yii::app()->basePath . "{$ds}config{$ds}db.php";
                 /*if(isFree()) {
                 			$sqlFile = $this->module->basePath . "{$ds}data{$ds}open-re.sql";
                 		} else {
                 			$sqlFile = $this->module->basePath . "{$ds}data{$ds}open-re-full.sql";
                 		}*/
                 $connectionString = "mysql:host={$model->dbHost};dbname={$model->dbName};port={$model->dbPort}";
                 $connection = new CDbConnection($connectionString, $model->dbUser, $model->dbPass);
                 $connection->connectionString = $connectionString;
                 $connection->username = $model->dbUser;
                 $connection->password = $model->dbPass;
                 $connection->emulatePrepare = true;
                 $connection->charset = 'utf8';
                 $connection->tablePrefix = $model->dbPrefix;
                 $connection->active = true;
                 Yii::app()->setComponent('db', $connection);
                 $params = array('components' => array('db' => array('class' => 'CDbConnection', 'connectionString' => $connectionString, 'username' => $model->dbUser, 'password' => $model->dbPass, 'emulatePrepare' => true, 'charset' => 'utf8', 'enableParamLogging' => false, 'enableProfiling' => false, 'schemaCachingDuration' => 7200, 'tablePrefix' => $model->dbPrefix)), 'language' => $model->language);
                 $dbConfString = "<?php\n return " . var_export($params, true) . " ;\n?>";
                 $fh = fopen($dbConfFile, 'w+');
                 if (!$fh) {
                     $model->addError('', tFile::getT('module_install', 'Can not open config/db.php file for record!'));
                 } else {
                     fwrite($fh, $dbConfString);
                     fclose($fh);
                     @chmod($dbConfFile, 0666);
                     $adminSalt = User::generateSalt();
                     $adminPass = User::hashPassword($model->adminPass, $adminSalt);
                     Yii::app()->user->setState('adminName', $model->adminName);
                     Yii::app()->user->setState('adminPass', $adminPass);
                     Yii::app()->user->setState('adminSalt', $adminSalt);
                     Yii::app()->user->setState('adminEmail', $model->adminEmail);
                     Yii::app()->user->setState('dbPrefix', $model->dbPrefix);
                     Yii::app()->user->setState('siteName', $model->siteName);
                     Yii::app()->user->setState('siteKeywords', $model->siteKeywords);
                     Yii::app()->user->setState('siteDescription', $model->siteDescription);
                     if (!isFree()) {
                         Yii::app()->user->setState('installLang', $model->language);
                     }
                     $this->redirect(array('/install/main/install'));
                 }
             } catch (Exception $e) {
                 $model->addError('', $e->getMessage());
             }
         }
     }
     if (Yii::app()->request->cookies['ore_is_first'] && Yii::app()->request->cookies['ore_is_first']->value == 1) {
         $is_first = 0;
     } else {
         $is_first = 1;
         $cookie = new CHttpCookie('ore_is_first', 1);
         $cookie->expire = time() + 24 * 60 * 60;
         Yii::app()->request->cookies['ore_is_first'] = $cookie;
     }
     $this->render('install', array('model' => $model, 'is_first' => $is_first));
 }