Example #1
0
    function displayBody()
    {
        $html = NULL;
        if (!isset($this->get['pid']) || strlen($this->get['pid']) != 8) {
            parent::addError("Invalid ID");
            return $html;
        }
        $conn = parent::getPDOConn();
        if ($conn != NULL) {
            $stmt = $conn->prepare("SELECT raw, formatted, hash FROM `pastes` WHERE `hash` = :hash");
            $stmt->bindParam(":hash", $this->get['pid']);
            if ($stmt->execute()) {
                $res = $stmt->fetch();
                $html .= '<h3>View Paste</h3>
        		<div id="formatted">' . $res['formatted'] . '</div>        
        		<textarea id="preview">' . $res['raw'] . '</textarea>
				<form method="post" action="download.php">
				<input type="hidden" name="pid" value="' . $res['hash'] . '" />
				<input style="margin-left: 5%;" type="submit" value="Download as ' . $res['hash'] . '.txt" />';
            } else {
                parent::addError("Invalid ID");
            }
        } else {
            parent::addError("Server error - Could not connect to the database.");
        }
        return $html;
    }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return void
  *
  * @throws CDbException
  */
 public function actionCreate()
 {
     $model = new Page();
     $menuId = null;
     $menuParentId = 0;
     if (($data = Yii::app()->getRequest()->getPost('Page')) !== null) {
         $model->setAttributes($data);
         $transaction = Yii::app()->db->beginTransaction();
         try {
             if ($model->save()) {
                 // если активен модуль "Меню" - сохраним в меню
                 if (Yii::app()->hasModule('menu')) {
                     $menuId = (int) Yii::app()->getRequest()->getPost('menu_id');
                     $parentId = (int) Yii::app()->getRequest()->getPost('parent_id');
                     $menu = Menu::model()->findByPk($menuId);
                     if ($menu) {
                         if (!$menu->addItem($model->title, $model->getUrl(), $parentId, true)) {
                             throw new CDbException(Yii::t('PageModule.page', 'There is an error when connecting page to menu...'));
                         }
                     }
                 }
                 Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('PageModule.page', 'Page was created'));
                 $transaction->commit();
                 $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['create']));
             }
         } catch (Exception $e) {
             $transaction->rollback();
             $model->addError(false, $e->getMessage());
         }
     }
     $languages = $this->yupe->getLanguagesList();
     //если добавляем перевод
     $id = (int) Yii::app()->getRequest()->getQuery('id');
     $lang = Yii::app()->getRequest()->getQuery('lang');
     if (!empty($id) && !empty($lang)) {
         $page = Page::model()->findByPk($id);
         if (null === $page) {
             Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('PageModule.page', 'Targeting page was not found!'));
             $this->redirect(['index']);
         }
         if (!array_key_exists($lang, $languages)) {
             Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('PageModule.page', 'Language was not found!'));
             $this->redirect(['index']);
         }
         Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('PageModule.page', 'You add translation for {lang}', ['{lang}' => $languages[$lang]]));
         $model->lang = $lang;
         $model->slug = $page->slug;
         $model->category_id = $page->category_id;
         $model->title = $page->title;
         $model->title_short = $page->title_short;
         $model->parent_id = $page->parent_id;
         $model->order = $page->order;
         $model->layout = $page->layout;
     } else {
         $model->lang = Yii::app()->getLanguage();
     }
     $this->render('create', ['model' => $model, 'pages' => Page::model()->getFormattedList(), 'languages' => $languages, 'menuId' => $menuId, 'menuParentId' => $menuParentId]);
 }
Example #3
0
 function displayLanguages()
 {
     $html = NULL;
     $conn = parent::GetPDOConn();
     if (conn != null) {
         $stmt = $conn->prepare("SELECT lang FROM `langs` ORDER BY `lang` ASC");
         if ($stmt->execute()) {
             while ($res = $stmt->fetch()) {
                 $html .= "<option>" . $res['lang'] . "</option>";
             }
         }
     } else {
         parent::addError("Server error - Could not connect to the database");
     }
     return $html;
 }
 function addEntry()
 {
     require_once 'inc/geshi.php';
     $code = $this->post['code'];
     $lang = $this->post['lang'];
     $poster = $this->post['poster'];
     $conn = parent::getPDOConn();
     if ($conn == NULL) {
         parent::addError("Server error - Could not connect to the database");
         return false;
     }
     if (empty($code) || empty($lang)) {
         parent::addError("You haven't pasted anything!");
         return false;
     }
     if (empty($poster)) {
         $poster = "Anonymous";
     }
     $stmt = $conn->prepare("SELECT * FROM `langs` WHERE `lang` = :lang");
     $stmt->bindParam(":lang", $lang);
     if ($stmt->execute()) {
         $res = $stmt->fetch(PDO::FETCH_ASSOC);
         if (empty($res)) {
             parent::addError("Invalid language");
             return false;
         }
     }
     $geshi = new GeSHi($code, $lang);
     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     if ($lang !== "None") {
         $formatted = $geshi->parse_code();
     } else {
         $formatted = "<pre>" . htmlentities($code) . "</pre>";
     }
     $hash = $this->makeHash($this->post['code'], $formatted, $this->post['lang']);
     $stmt = $conn->prepare("INSERT INTO `pastes` VALUES('', ?, ?, ?, ?, ?, ?)");
     if ($stmt->execute(array(htmlentities($code), $formatted, $res['filename'], $hash, $poster, time()))) {
         parent::addMessage("Paste has been added!  Click <a href=\"view.php?pid=" . $hash . "\">here</a> to view.<br /><input type=\"text\" value=\"http://pb.pwnds.info/view.php?pid=" . $hash . "\" readonly />");
         return $hash;
     } else {
         parent::addError("Server error - Couldn't add paste.  " . $this->post['lang'] . " " . print_r($stmt->errorInfo(), true));
         return false;
     }
 }
Example #5
0
 public function actionCreate()
 {
     $page = new Page();
     if (isset($_POST['Page'])) {
         try {
             if ($page->save()) {
                 if (Settings::get('SEO', 'slugs_enabled') && isset($_POST['Page']['slug'])) {
                     $page->slug = Slug::create($_POST['Page']['slug'], array('view', 'id' => $page->id));
                     $page->save();
                 }
                 $this->redirect(array('view', 'id' => $page->id));
             }
         } catch (Exception $e) {
             $page->addError('', $e->getMessage());
         }
     } elseif (isset($_GET['Page'])) {
         $page->attributes = $_GET['Page'];
     }
     //        if (!isset($_POST['Page']['user']))
     //            $page->user = Yii::app()->user->id;
     $this->render('create', array('page' => $page));
 }