document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2.  
  3. class PageController extends Controller
  4. {
  5.     /**
  6.      * @var string the default layout for the views. Defaults to \'//layouts/column2\', meaning
  7.      * using two-column layout. See \'protected/views/layouts/column2.php\'.
  8.      */
  9.     public $layout=\'//layouts/column2\';
  10.  
  11.     const PAGE_SIZE = 20;
  12.  
  13.     /**
  14.      * @return array action filters
  15.      */
  16.     public function filters()
  17.     {
  18.         return array(
  19.             \'accessControl\', // perform access control for CRUD operations
  20.         );
  21.     }
  22.  
  23.     /**
  24.      * Specifies the access control rules.
  25.      * This method is used by the \'accessControl\' filter.
  26.      * @return array access control rules
  27.      */
  28.     public function accessRules()
  29.     {
  30.         return array(
  31.             array(\'allow\',  // allow all users to perform \'index\' and \'view\' actions
  32.                 \'actions\'=>array(\'index\',\'view\'),
  33.                 \'users\'=>array(\'*\'),
  34.             ),
  35.             array(\'allow\', // allow authenticated user to perform \'create\' and \'update\' actions
  36.                 \'actions\'=>array(\'create\',\'update\'),
  37.                 \'users\'=>array(\'@\'),
  38.             ),
  39.             array(\'allow\', // allow admin user to perform \'admin\' and \'delete\' actions
  40.                 \'actions\'=>array(\'admin\',\'delete\'),
  41.                 \'users\'=>array(\'admin\'),
  42.             ),
  43.             array(\'deny\',  // deny all users
  44.                 \'users\'=>array(\'*\'),
  45.             ),
  46.         );
  47.     }
  48.  
  49.     /**
  50.      * Displays a particular model.
  51.      * @param integer $id the ID of the model to be displayed
  52.      */
  53.     public function actionView($title)
  54.     {
  55.         $model = Page::model()->find(
  56.                         array(
  57.                             \'condition\'     => \'title=:title\',
  58.                             \'order\'         => \'revision DESC\',
  59.                             \'params\'        => array(
  60.                                                 \':title\' => $title
  61.                             )
  62.                         )
  63.                     );
  64.  
  65.         if( $model )
  66.         {
  67.             $this->render( \'view\', array( \'model\' => $model ) );
  68.         }
  69.         else
  70.         {
  71.             throw new CHttpException( 404, \'Upsz! Hat ezt az oldalt nem talaltuk :/\' );
  72.         }
  73.     }
  74.  
  75.     /**
  76.      * Creates a new model.
  77.      * If creation is successful, the browser will be redirected to the \'view\' page.
  78.      */
  79.     public function actionCreate()
  80.     {
  81.         $model=new Page;
  82.  
  83.         // Uncomment the following line if AJAX validation is needed
  84.         // $this->performAjaxValidation($model);
  85.  
  86.         if(isset($_POST[\'Page\']))
  87.         {
  88.             $model->attributes=$_POST[\'Page\'];
  89.             if($model->save())
  90.             {
  91.                 $this->redirect(array(\'view\',\'title\'=>$model->title));
  92.             }
  93.         }
  94.  
  95.         $this->render(\'create\',array(
  96.             \'model\'=>$model,
  97.         ));
  98.     }
  99.  
  100.     /**
  101.      * Updates a particular model.
  102.      * If update is successful, the browser will be redirected to the \'view\' page.
  103.      * @param integer $id the ID of the model to be updated
  104.      */
  105.     public function actionUpdate($title)
  106.     {
  107.         $model = Page::model()->find(
  108.                         array(
  109.                             \'condition\'     => \'title=:title\',
  110.                             \'order\'         => \'revision DESC\',
  111.                             \'params\'        => array(
  112.                                                 \':title\' => $title
  113.                             )
  114.                         )
  115.                     );
  116.  
  117.         // Uncomment the following line if AJAX validation is needed
  118.         // $this->performAjaxValidation($model);
  119.  
  120.         if(isset($_POST[\'Page\']))
  121.         {
  122.             $model->attributes=$_POST[\'Page\'];
  123.             if($model->save())
  124.                 $this->redirect(array(\'view\',\'title\'=>$model->title));
  125.         }
  126.  
  127.         $this->render(\'update\',array(
  128.             \'model\'=>$model,
  129.         ));
  130.     }
  131.  
  132.     /**
  133.      * Deletes a particular model.
  134.      * If deletion is successful, the browser will be redirected to the \'admin\' page.
  135.      * @param integer $id the ID of the model to be deleted
  136.      */
  137.     public function actionDelete( $title )
  138.     {
  139.        
  140.         if(Yii::app()->request->isPostRequest)
  141.         {
  142.             // FONTOS!
  143.             // az `admin` reszt magat kiszedtuk
  144.             // ezert a delete-t funkciot kicsit atirtuk
  145.             Page::model()->deleteAll( \'title=:title\', array( \':title\' => $title ) );
  146.             $this->redirect( $this->createUrl( \'/page/index\' ) );
  147.         }
  148.         else
  149.             throw new CHttpException(400,\'Invalid request. Please do not repeat this request again.\');
  150.     }
  151.  
  152.     public function actionIndex()
  153.     {
  154.             $criteria = new CDbCriteria();
  155.             $criteria->group = \'title\';
  156.             $criteria->order = \'created DESC\';
  157.  
  158.             $dataProvider=new CActiveDataProvider(\'Page\', array(
  159.                                     \'pagination\'=>array(
  160.                                             \'pageSize\'=>self::PAGE_SIZE,
  161.                                             ),
  162.                                     \'criteria\' => $criteria,
  163.                                     ));
  164.  
  165.             $this->render(\'index\',array(
  166.                                     \'dataProvider\'=>$dataProvider,
  167.                                     ));
  168.     }
  169.  
  170.     /**
  171.      * Manages all models.
  172.      */
  173.     public function actionAdmin()
  174.     {
  175.         $model=new Page(\'search\');
  176.         $model->unsetAttributes();  // clear any default values
  177.         if(isset($_GET[\'Page\']))
  178.             $model->attributes=$_GET[\'Page\'];
  179.  
  180.         $this->render(\'admin\',array(
  181.             \'model\'=>$model,
  182.         ));
  183.     }
  184.  
  185.     /**
  186.      * Returns the data model based on the primary key given in the GET variable.
  187.      * If the data model is not found, an HTTP exception will be raised.
  188.      * @param integer the ID of the model to be loaded
  189.      */
  190.     public function loadModel($id)
  191.     {
  192.         $model=Page::model()->findByPk($id);
  193.         if($model===null)
  194.             throw new CHttpException(404,\'The requested page does not exist.\');
  195.         return $model;
  196.     }
  197.  
  198.     /**
  199.      * Performs the AJAX validation.
  200.      * @param CModel the model to be validated
  201.      */
  202.     protected function performAjaxValidation($model)
  203.     {
  204.         if(isset($_POST[\'ajax\']) && $_POST[\'ajax\']===\'page-form\')
  205.         {
  206.             echo CActiveForm::validate($model);
  207.             Yii::app()->end();
  208.         }
  209.     }
  210. }
');