<commit_before><?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://getfrapi.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @license   New BSD
 * @copyright echolibre ltd.
 * @package   frapi-admin
 */
class ActionController extends Lupin_Controller_Base
{
    /**
     * Main Initializer
     *
     * This is the public method that will be used by the controller base
     * using the tyles in the init.
     *
     * @param array $styles an array of stylesheets (CSS)
     */
    public function init($styles = array())
    {
        $actions = array('index', 'add', 'edit', 'delete', 'sync', 'test', 'code', 'error');
        $this->_helper->_acl->allow('admin', $actions);
        parent::init($styles);
    }

    /**
     * Empty error action
     *
     * This is only the action for errors
     *
     * @return void
     */
    public function errorAction() {}

    /**
     * The index
     *
     * This is the index action where we check if the localConfigPath
     * is writeable by the user. If it isn't then we set a warning message.
     *
     * @uses   Default_Model_Action
     * @return void
     */
    public function indexAction()
    {
        $model = new Default_Model_Action;
        $dir = Zend_Registry::get('localConfigPath');
        $dir = $dir . 'actions.xml';

        $dir = Zend_Registry::get('localConfigPath');
        $translate = Zend_Registry::get('tr');

        if (!is_writable($dir)) {

            $actionPathMessage = sprintf($translate->_('ACTION_DIR_PROBLEM'), $dir);
            $setupHelpMessage  = $translate->_('SETUP_HELP_MESSAGE');

            $this->addMessage(
                $actionPathMessage .' <br /><br />' . $setupHelpMessage
            );

            $this->_redirect('/action/error');
        }

        $data = $model->getAll();

        if ($data == false) {
            $data = array();
        }

        $this->view->data = $data;
    }

    /**
     * Add an action
     *
     * This is the add action method. It literally does what it say.
     * It adds an action.
     *
     * This method has a different output whether or not some data is posted
     * to it.
     *
     * @uses Default_Form_Action
     * @uses Default_Model_Action
     *
     * @return void
     */
    public function addAction()
    {
        $form  = new Default_Form_Action;
        $model = new Default_Model_Action;

        $request = $this->getRequest();
        if ($request->isPost()) {
            if ($form->isValid($request->getPost())) {

                // Save data
                try {
                    $model->save($request->getParams());
                    $this->addMessage('Action ' . $request->getParam('name') . ' added.');
                    $this->_redirect('/action');
                } catch (RuntimeException $e) {
                    $this->addErrorMessage('Error adding action ' . $request->getParam('name') .
                        '. ' . $e->getMessage());
                }
            }
        }

        $this->view->form = $form;
    }

    /**
     * This is the code action
     *
     * This method is not in use right now but was mostly used
     * for the code editor (In browser FRAPI code editor)
     */
    public function codeAction()
    {
        $translate = Zend_Registry::get('tr');

        $request = $this->getRequest();
        $this->view->id = $id = $request->getParam('id');
        if ($id === null) {
            $this->addErrorMessage('ID parameter is missing.');
            return;
        }

        $model = new Default_Model_Action;

        $data       = $request->getParams();
        $actionData = $model->get($id);
        $name       = $actionData['name'];
        $file       = $name . '.php';

        $dir = ROOT_PATH . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR . 'Action';
        $file = $dir . DIRECTORY_SEPARATOR . $file;

        if ($this->_request->isPost()) {
            $content = $this->_request->getParam('code');
            if (!is_writable($file)) {<commit_msg>- Made sure the code-editor's file is loadable on case-sensitive filesystems.<commit_after><?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://getfrapi.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @license   New BSD
 * @copyright echolibre ltd.
 * @package   frapi-admin
 */
class ActionController extends Lupin_Controller_Base
{
    /**
     * Main Initializer
     *
     * This is the public method that will be used by the controller base
     * using the tyles in the init.
     *
     * @param array $styles an array of stylesheets (CSS)
     */
    public function init($styles = array())
    {
        $actions = array('index', 'add', 'edit', 'delete', 'sync', 'test', 'code', 'error');
        $this->_helper->_acl->allow('admin', $actions);
        parent::init($styles);
    }

    /**
     * Empty error action
     *
     * This is only the action for errors
     *
     * @return void
     */
    public function errorAction() {}

    /**
     * The index
     *
     * This is the index action where we check if the localConfigPath
     * is writeable by the user. If it isn't then we set a warning message.
     *
     * @uses   Default_Model_Action
     * @return void
     */
    public function indexAction()
    {
        $model = new Default_Model_Action;
        $dir = Zend_Registry::get('localConfigPath');
        $dir = $dir . 'actions.xml';

        $dir = Zend_Registry::get('localConfigPath');
        $translate = Zend_Registry::get('tr');

        if (!is_writable($dir)) {

            $actionPathMessage = sprintf($translate->_('ACTION_DIR_PROBLEM'), $dir);
            $setupHelpMessage  = $translate->_('SETUP_HELP_MESSAGE');

            $this->addMessage(
                $actionPathMessage .' <br /><br />' . $setupHelpMessage
            );

            $this->_redirect('/action/error');
        }

        $data = $model->getAll();

        if ($data == false) {
            $data = array();
        }

        $this->view->data = $data;
    }

    /**
     * Add an action
     *
     * This is the add action method. It literally does what it say.
     * It adds an action.
     *
     * This method has a different output whether or not some data is posted
     * to it.
     *
     * @uses Default_Form_Action
     * @uses Default_Model_Action
     *
     * @return void
     */
    public function addAction()
    {
        $form  = new Default_Form_Action;
        $model = new Default_Model_Action;

        $request = $this->getRequest();
        if ($request->isPost()) {
            if ($form->isValid($request->getPost())) {

                // Save data
                try {
                    $model->save($request->getParams());
                    $this->addMessage('Action ' . $request->getParam('name') . ' added.');
                    $this->_redirect('/action');
                } catch (RuntimeException $e) {
                    $this->addErrorMessage('Error adding action ' . $request->getParam('name') .
                        '. ' . $e->getMessage());
                }
            }
        }

        $this->view->form = $form;
    }

    /**
     * This is the code action
     *
     * This method is not in use right now but was mostly used
     * for the code editor (In browser FRAPI code editor)
     */
    public function codeAction()
    {
        $translate = Zend_Registry::get('tr');

        $request = $this->getRequest();
        $this->view->id = $id = $request->getParam('id');
        if ($id === null) {
            $this->addErrorMessage('ID parameter is missing.');
            return;
        }

        $model = new Default_Model_Action;

        $data       = $request->getParams();
        $actionData = $model->get($id);
        $name       = $actionData['name'];
        $file       = strtolower($name) . '.php';

        $dir = ROOT_PATH . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR . 'Action';
        $file = $dir . DIRECTORY_SEPARATOR . ucfirst($file);

        if ($this->_request->isPost()) {
            $content = $this->_request->getParam('code');
            if (!is_writable($file)) {
{'fraction_non_alphanumeric': 0.13262629718325922, 'fraction_numerical': 0.0, 'mean_word_length': 1.912653603454002, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3837914', 'n_tokens_mistral': 2522, 'n_tokens_neox': 2444, 'n_words': 712}