<commit_before><?php

class ContentController extends CiiDashboardController
{
    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * @return array access control rules
     */
    public function accessRules()
    {
        return array(
            array('allow',  // allow authenticated admins to perform any action
                'users'=>array('@'),
                'expression'=>'Yii::app()->user->role>=7'
            ),
            array('deny',   // Prevent Editors from deleting content
                'actions' => array('delete', 'deleteMany'),
                'expression' => 'Yii::app()->user->role==7'
            ),
            array('deny',  // deny all users
                'users'=>array('*'),
            ),
        );
    }

  /**
   * Default management page
     * Display all items in a CListView for easy editing
   */
  public function actionIndex()
  {
        $preview = NULL;

        $model=new Content('search');
        $model->unsetAttributes();  // clear any default values
        if(Cii::get($_GET, 'Content') !== NULL)
            $model->attributes=$_GET['Content'];

        // Only show posts that belong to that user if they are not an editor or an admin
        if (($role =Yii::app()->user->role))
        {
            if ($role != 7 && $role != 9)
                $model->author_id = Yii::app()->user->id;
        }

        if (Cii::get($_GET, 'id') !== NULL)
            $preview = Content::model()->findByPk(Cii::get($_GET, 'id'));


        $model->pageSize = 20;

        if (!isset(Yii::app()->session['admin_perspective']))
            Yii::app()->session['admin_perspective'] = 1;
        
        if (Cii::get($_GET, 'perspective') !== NULL)
        {
            if (in_array((int)Cii::get($_GET, 'perspective'), array(1, 2)))
                Yii::app()->session['admin_perspective'] = Cii::get($_GET, 'perspective');
        }

        if (Yii::app()->session['admin_perspective'] == 2)
            $model->pageSize = 15;

        $viewFile = 'index_' . Yii::app()->session['admin_perspective'];
        $this->render($viewFile, array(
            'model' => $model,
            'preview' => $preview
        ));
    }

    /**
     * Handles the creation and editing of Content models.
     * If no id is provided, a new model will be created. Otherwise attempt to edit
     * @param int $id   The ContentId of the model we want to manipulate
     */
    public function actionSave($id=NULL)
    {
        $version   = 0;
        $theme     = Cii::getConfig('theme', 'default');
        $viewFiles = $this->getViewFiles($theme);
        $layouts   = $this->getLayouts($theme);
          
        // Editor Preferences
        $preferMarkdown = Cii::getConfig('preferMarkdown',false);

        if ($preferMarkdown == NULL)
            $preferMarkdown = false;
        else
            $preferMarkdown = (bool)$preferMarkdown;
          
        // Determine what we're doing, new model or existing one
        if ($id == NULL)
        {
            $model = new Content;
            $model->savePrototype();
            $this->redirect($this->createUrl('/dashboard/content/save/id/' . $model->id));
        }
        else
        {
            $model = Content::model()->findByPk($id);
              
            if ($model == NULL)
                throw new CHttpException(400,'We were unable to retrieve a post with that id. Please do not repeat this request again.');
              
            // Determine the version number based upon the count of existing rows
            // We do this manually to make sure we have the correct data
            $version = Content::model()->countByAttributes(array('id' => $id));
        }

        if(Cii::get($_POST, 'Content'))
        {
            $model2 = new Content;
            $model2->attributes = Cii::get($_POST, 'Content', array());
            if ($_POST['Content']['password'] != "")
                $model2->password = Cii::encrypt($_POST['Content']['password']);

            // For some reason this isn't setting with the other data
            $model2->extract    = $_POST['Content']['extract'];
            $model2->id         = $id;
            $model2->vid        = $model->vid+1;
            $model2->viewFile   = $_POST['Content']['view'];
            $model2->layoutFile = $_POST['Content']['layout'];
            $model2->created    = $_POST['Content']['created'];

            if($model2->save()) 
            {
                Yii::app()->user->setFlash('success', 'Content has been updated');
                $this->redirect(array('save','id'=>$model2->id));
            }
            else
            {
                foreach ($model2->attributes as $k=>$v)
                    $model->$k = $v;

                $model->vid = $model2->vid-1;
                $model->addErrors($model2->getErrors());

                Yii::app()->user->setFlash('error', 'There was an error saving your content. Please try again');
            }
        }

        $this->render('save',array(
            'model'          =>  $model,
            'id'             =>  $id,
            'version'        =>  $version,
            'preferMarkdown' =>  $preferMarkdown,
            'views'          =>  $viewFiles,
            'layouts'        =>  $layouts 
        ));
    }

    /**
     * Handles file uploading for the controller<commit_msg>Change publish date. Color looks awful<commit_after><?php

class ContentController extends CiiDashboardController
{
    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * @return array access control rules
     */
    public function accessRules()
    {
        return array(
            array('allow',  // allow authenticated admins to perform any action
                'users'=>array('@'),
                'expression'=>'Yii::app()->user->role>=7'
            ),
            array('deny',   // Prevent Editors from deleting content
                'actions' => array('delete', 'deleteMany'),
                'expression' => 'Yii::app()->user->role==7'
            ),
            array('deny',  // deny all users
                'users'=>array('*'),
            ),
        );
    }

  /**
   * Default management page
     * Display all items in a CListView for easy editing
   */
  public function actionIndex()
  {
        $preview = NULL;

        $model=new Content('search');
        $model->unsetAttributes();  // clear any default values
        if(Cii::get($_GET, 'Content') !== NULL)
            $model->attributes=$_GET['Content'];

        // Only show posts that belong to that user if they are not an editor or an admin
        if (($role =Yii::app()->user->role))
        {
            if ($role != 7 && $role != 9)
                $model->author_id = Yii::app()->user->id;
        }

        if (Cii::get($_GET, 'id') !== NULL)
            $preview = Content::model()->findByPk(Cii::get($_GET, 'id'));


        $model->pageSize = 20;

        if (!isset(Yii::app()->session['admin_perspective']))
            Yii::app()->session['admin_perspective'] = 1;
        
        if (Cii::get($_GET, 'perspective') !== NULL)
        {
            if (in_array((int)Cii::get($_GET, 'perspective'), array(1, 2)))
                Yii::app()->session['admin_perspective'] = Cii::get($_GET, 'perspective');
        }

        if (Yii::app()->session['admin_perspective'] == 2)
            $model->pageSize = 15;

        $viewFile = 'index_' . Yii::app()->session['admin_perspective'];
        $this->render($viewFile, array(
            'model' => $model,
            'preview' => $preview
        ));
    }

    /**
     * Handles the creation and editing of Content models.
     * If no id is provided, a new model will be created. Otherwise attempt to edit
     * @param int $id   The ContentId of the model we want to manipulate
     */
    public function actionSave($id=NULL)
    {
        $version   = 0;
        $theme     = Cii::getConfig('theme', 'default');
        $viewFiles = $this->getViewFiles($theme);
        $layouts   = $this->getLayouts($theme);
          
        // Editor Preferences
        $preferMarkdown = Cii::getConfig('preferMarkdown',false);

        if ($preferMarkdown == NULL)
            $preferMarkdown = false;
        else
            $preferMarkdown = (bool)$preferMarkdown;
          
        // Determine what we're doing, new model or existing one
        if ($id == NULL)
        {
            $model = new Content;
            $model->savePrototype();
            $this->redirect($this->createUrl('/dashboard/content/save/id/' . $model->id));
        }
        else
        {
            $model = Content::model()->findByPk($id);
              
            if ($model == NULL)
                throw new CHttpException(400,'We were unable to retrieve a post with that id. Please do not repeat this request again.');
              
            // Determine the version number based upon the count of existing rows
            // We do this manually to make sure we have the correct data
            $version = Content::model()->countByAttributes(array('id' => $id));
        }

        if(Cii::get($_POST, 'Content'))
        {
            $model2 = new Content;
            $model2->attributes = Cii::get($_POST, 'Content', array());
            if ($_POST['Content']['password'] != "")
                $model2->password = Cii::encrypt($_POST['Content']['password']);

            // For some reason this isn't setting with the other data
            $model2->extract    = $_POST['Content']['extract'];
            $model2->id         = $id;
            $model2->vid        = $model->vid+1;
            $model2->viewFile   = $_POST['Content']['view'];
            $model2->layoutFile = $_POST['Content']['layout'];
            $model2->created    = $_POST['Content']['created'];
            $model2->published  = $_POST['Content']['published'];
            
            if($model2->save()) 
            {
                Yii::app()->user->setFlash('success', 'Content has been updated');
                $this->redirect(array('save','id'=>$model2->id));
            }
            else
            {
                foreach ($model2->attributes as $k=>$v)
                    $model->$k = $v;

                $model->vid = $model2->vid-1;
                $model->addErrors($model2->getErrors());

                Yii::app()->user->setFlash('error', 'There was an error saving your content. Please try again');
            }
        }

        $this->render('save',array(
            'model'          =>  $model,
            'id'             =>  $id,
            'version'        =>  $version,
            'preferMarkdown' =>  $preferMarkdown,
            'views'          =>  $viewFiles,
            'layouts'        =>  $layouts 
        ));
    }

    /**
     * Handles file uploading for the controller
{'fraction_non_alphanumeric': 0.1541487512578904, 'fraction_numerical': 0.0059463909980788585, 'mean_word_length': 1.76200101061142, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 140, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '255931', 'n_tokens_mistral': 3034, 'n_tokens_neox': 2928, 'n_words': 722}