<commit_before><?php

/**
 * flexContent
 *
 * @author Team phpManufaktur <<EMAIL>>
 * @link https://kit2.phpmanufaktur.de/flexContent
 * @copyright 2013 <NAME> <<EMAIL>>
 * @license MIT License (MIT) http://www.opensource.org/licenses/MIT
 */

namespace phpManufaktur\flexContent\Control\Admin;

use Silex\Application;
use phpManufaktur\flexContent\Data\Content\Content as ContentData;
use Carbon\Carbon;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use phpManufaktur\flexContent\Data\Content\Tag;
use phpManufaktur\flexContent\Data\Content\TagType;
use phpManufaktur\flexContent\Data\Content\Category;
use phpManufaktur\flexContent\Data\Content\CategoryType;
use phpManufaktur\flexContent\Data\Import\WYSIWYG;
use phpManufaktur\Basic\Data\CMS\Page;
use phpManufaktur\flexContent\Data\Content\Event;

class ContentEdit extends Admin
{
    protected $ContentData = null;
    protected static $content_id = null;
    protected $TagData = null;
    protected $TagTypeData = null;
    protected $CategoryTypeData = null;
    protected $CategoryData = null;
    protected $WYSIWYG = null;
    protected $CMSPage = null;
    protected $EventData = null;

    protected static $language = null;

    /**
     * (non-PHPdoc)
     * @see \phpManufaktur\flexContent\Control\Backend\Backend::initialize()
     */
    protected function initialize(Application $app)
    {
        parent::initialize($app);

        self::$content_id = -1;
        $this->ContentData = new ContentData($app);
        $this->TagData = new Tag($app);
        $this->TagTypeData = new TagType($app);
        $this->CategoryData = new Category($app);
        $this->CategoryTypeData = new CategoryType($app);
        $this->WYSIWYG = new WYSIWYG($app);
        $this->CMSPage = new Page($app);
        $this->EventData = new Event($app);

        self::$language = $this->app['request']->get('form[language]', self::$config['content']['language']['default'], true);
    }

    /**
     * Create the form.factory form for flexContent
     *
     * @param array $data
     */
    protected function getContentForm($data=array())
    {
        if (isset($data['language'])) {
            // set the language property from the content data
            self::$language = $data['language'];
        }

        if (!isset($data['publish_from']) || ($data['publish_from'] == '0000-00-00 00:00:00')) {
            $dt = Carbon::create();
            $dt->addHours(self::$config['content']['field']['publish_from']['add']['hours']);
            $publish_from = $dt->toDateTimeString();
        }
        else {
            $publish_from = $data['publish_from'];
        }

        if (!isset($data['breaking_to']) || ($data['breaking_to'] == '0000-00-00 00:00:00')) {
            $dt = Carbon::createFromFormat('Y-m-d H:i:s', $publish_from);
            $dt->addHours(self::$config['content']['field']['breaking_to']['add']['hours']);
            $breaking_to = $dt->toDateTimeString();
        }
        else {
            $breaking_to = $data['breaking_to'];
        }

        if (!isset($data['archive_from']) || ($data['archive_from'] == '0000-00-00 00:00:00')) {
            $dt = Carbon::createFromFormat('Y-m-d H:i:s', $publish_from);
            $dt->endOfDay();
            $dt->addDays(self::$config['content']['field']['archive_from']['add']['days']);
            $archive_from = $dt->toDateTimeString();
        }
        else {
            $archive_from = $data['archive_from'];
        }

        if (false === ($primary_category = $this->CategoryData->selectPrimaryCategoryIDbyContentID(self::$content_id))) {
            $primary_category = null;
        }
        if (false === ($secondary_categories = $this->CategoryData->selectSecondaryCategoryIDsByContentID(self::$content_id))) {
            $secondary_categories = null;
        }

        $categories = $this->CategoryTypeData->getListForSelect(self::$language);
        if (empty($categories)) {
            $this->setAlert('No category available for the language %language%, please create a category first!',
                array('%language%' => $this->app['translator']->trans(self::$language)), self::ALERT_TYPE_WARNING);
        }

        // show the permalink URL
        $permalink_url = CMS_URL.str_ireplace('{language}', strtolower(self::$language), self::$config['content']['permalink']['directory']).'/';

        $check_kitcommand = 0;
        $category_target_url = '';
        $category_name = '';
        if (isset($data['content_id']) && ($data['content_id'] > 0) && !is_null($primary_category)) {
            // get the target_url from the primary category
            if (false !== ($category = $this->CategoryTypeData->select($primary_category))) {
                if (!empty($category['target_url'])) {
                    // check if the flexContent kitCommand exists at the target
                    $link = '/'.basename($category['target_url'], $this->CMSPage->getPageExtension());
                    if (false !== ($page_id = $this->CMSPage->getPageIDbyPageLink($link))) {
                        $check_kitcommand = (int) $this->WYSIWYG->checkPageIDforFlexContentCommand($page_id);
                        $category_target_url = $category['target_url'];
                        $category_name = $category['category_name'];
                    }
                }
            }
        }

        // category type
        $category_type = !is_null($primary_category) ? $this->CategoryTypeData->selectType($primary_category) : 'DEFAULT';

        $form = $this->app['form.factory']->createBuilder('form')
        ->add('check_kitcommand', 'hidden', array(
            'data' => $check_kitcommand
        ))
        ->add('primary_category_target_url', 'hidden', array(
            'data' => $category_target_url
        ))
        ->add('primary_category_name', 'hidden', array(
            'data' => $category_name
        ))
        ->add('category_type', 'hidden', array(
            'data' => $category_type
        ))

        // add empty fields for the optional category type EVENT
        ->add('event_date_from', 'hidden')
        ->add('event_date_to', 'hidden')
        ->add('event_organizer', 'hidden')
        ->add('event_location', 'hidden')

        ->add('content_id', 'hidden', array(
            'data' => isset($data['content_id']) ? $data['content_id'] : -1
        ))
        ->add('language', 'hidden', array(
            'data' => self::$language,
        ))
        ->add('title', 'text', array(
            'data' => isset($data['title']) ? $data['title'] : '',
            'required' => self::$config['content']['field']['title']['required'],
            'label' => 'Headline'
        ))
        ->add('page_title', 'text', array(
            'data' => isset($data['page_title']) ? $data['page_title'] : '',
            'required' => self::$config['content']['field']['page_title']['required'],
            'label' => 'SEO: Page title'
        ))
        ->add('description', 'textarea', array(
            'data' => isset($data['description']) ? $data['description'] : '',
            'required' => self::$config['content']['field']['description']['required'],
            'label' => 'SEO: Description'
        ))
        ->add('keywords', 'textarea', array(
            'data' => isset($data['keywords']) ? $data['keywords'] : '',
            'required' => self::$config['content']['field']['keywords']['required'],
            'label' => 'SEO: Keywords'
        ))
        ->add('publish_from', 'text', array(
            'required' => self::$config['content']['field']['publish_from']['required'],
            'data' => date($this->app['translator']->trans('DATETIME_FORMAT'), strtotime($publish_from)),
        ))
        ->add('breaking_to', 'text', array(
            'required' => self::$config['content']['field']['breaking_to']['required'],
            'data' => date($this->app['translator']->trans('DATETIME_FORMAT'), strtotime($breaking_to)),
        ))
        ->add('archive_from', 'text', array(
            'required' => self::$config['content']['field']['archive_from']['required'],
            'data' => date($this->app['translator']->trans('DATETIME_FORMAT'), strtotime($archive_from)),
        ))
        ->add('teaser', 'textarea', array(
            'data' => isset($data['teaser']) ? $data['teaser'] : '',
            'required' => self::$config['content']['field']['teaser']['required']<commit_msg>fix: title, page title and description are now using sanitize (was missing)<commit_after><?php

/**
 * flexContent
 *
 * @author Team phpManufaktur <<EMAIL>>
 * @link https://kit2.phpmanufaktur.de/flexContent
 * @copyright 2013 <NAME> <<EMAIL>>
 * @license MIT License (MIT) http://www.opensource.org/licenses/MIT
 */

namespace phpManufaktur\flexContent\Control\Admin;

use Silex\Application;
use phpManufaktur\flexContent\Data\Content\Content as ContentData;
use Carbon\Carbon;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use phpManufaktur\flexContent\Data\Content\Tag;
use phpManufaktur\flexContent\Data\Content\TagType;
use phpManufaktur\flexContent\Data\Content\Category;
use phpManufaktur\flexContent\Data\Content\CategoryType;
use phpManufaktur\flexContent\Data\Import\WYSIWYG;
use phpManufaktur\Basic\Data\CMS\Page;
use phpManufaktur\flexContent\Data\Content\Event;

class ContentEdit extends Admin
{
    protected $ContentData = null;
    protected static $content_id = null;
    protected $TagData = null;
    protected $TagTypeData = null;
    protected $CategoryTypeData = null;
    protected $CategoryData = null;
    protected $WYSIWYG = null;
    protected $CMSPage = null;
    protected $EventData = null;

    protected static $language = null;

    /**
     * (non-PHPdoc)
     * @see \phpManufaktur\flexContent\Control\Backend\Backend::initialize()
     */
    protected function initialize(Application $app)
    {
        parent::initialize($app);

        self::$content_id = -1;
        $this->ContentData = new ContentData($app);
        $this->TagData = new Tag($app);
        $this->TagTypeData = new TagType($app);
        $this->CategoryData = new Category($app);
        $this->CategoryTypeData = new CategoryType($app);
        $this->WYSIWYG = new WYSIWYG($app);
        $this->CMSPage = new Page($app);
        $this->EventData = new Event($app);

        self::$language = $this->app['request']->get('form[language]', self::$config['content']['language']['default'], true);
    }

    /**
     * Create the form.factory form for flexContent
     *
     * @param array $data
     */
    protected function getContentForm($data=array())
    {
        if (isset($data['language'])) {
            // set the language property from the content data
            self::$language = $data['language'];
        }

        if (!isset($data['publish_from']) || ($data['publish_from'] == '0000-00-00 00:00:00')) {
            $dt = Carbon::create();
            $dt->addHours(self::$config['content']['field']['publish_from']['add']['hours']);
            $publish_from = $dt->toDateTimeString();
        }
        else {
            $publish_from = $data['publish_from'];
        }

        if (!isset($data['breaking_to']) || ($data['breaking_to'] == '0000-00-00 00:00:00')) {
            $dt = Carbon::createFromFormat('Y-m-d H:i:s', $publish_from);
            $dt->addHours(self::$config['content']['field']['breaking_to']['add']['hours']);
            $breaking_to = $dt->toDateTimeString();
        }
        else {
            $breaking_to = $data['breaking_to'];
        }

        if (!isset($data['archive_from']) || ($data['archive_from'] == '0000-00-00 00:00:00')) {
            $dt = Carbon::createFromFormat('Y-m-d H:i:s', $publish_from);
            $dt->endOfDay();
            $dt->addDays(self::$config['content']['field']['archive_from']['add']['days']);
            $archive_from = $dt->toDateTimeString();
        }
        else {
            $archive_from = $data['archive_from'];
        }

        if (false === ($primary_category = $this->CategoryData->selectPrimaryCategoryIDbyContentID(self::$content_id))) {
            $primary_category = null;
        }
        if (false === ($secondary_categories = $this->CategoryData->selectSecondaryCategoryIDsByContentID(self::$content_id))) {
            $secondary_categories = null;
        }

        $categories = $this->CategoryTypeData->getListForSelect(self::$language);
        if (empty($categories)) {
            $this->setAlert('No category available for the language %language%, please create a category first!',
                array('%language%' => $this->app['translator']->trans(self::$language)), self::ALERT_TYPE_WARNING);
        }

        // show the permalink URL
        $permalink_url = CMS_URL.str_ireplace('{language}', strtolower(self::$language), self::$config['content']['permalink']['directory']).'/';

        $check_kitcommand = 0;
        $category_target_url = '';
        $category_name = '';
        if (isset($data['content_id']) && ($data['content_id'] > 0) && !is_null($primary_category)) {
            // get the target_url from the primary category
            if (false !== ($category = $this->CategoryTypeData->select($primary_category))) {
                if (!empty($category['target_url'])) {
                    // check if the flexContent kitCommand exists at the target
                    $link = '/'.basename($category['target_url'], $this->CMSPage->getPageExtension());
                    if (false !== ($page_id = $this->CMSPage->getPageIDbyPageLink($link))) {
                        $check_kitcommand = (int) $this->WYSIWYG->checkPageIDforFlexContentCommand($page_id);
                        $category_target_url = $category['target_url'];
                        $category_name = $category['category_name'];
                    }
                }
            }
        }

        // category type
        $category_type = !is_null($primary_category) ? $this->CategoryTypeData->selectType($primary_category) : 'DEFAULT';

        $form = $this->app['form.factory']->createBuilder('form')
        ->add('check_kitcommand', 'hidden', array(
            'data' => $check_kitcommand
        ))
        ->add('primary_category_target_url', 'hidden', array(
            'data' => $category_target_url
        ))
        ->add('primary_category_name', 'hidden', array(
            'data' => $category_name
        ))
        ->add('category_type', 'hidden', array(
            'data' => $category_type
        ))

        // add empty fields for the optional category type EVENT
        ->add('event_date_from', 'hidden')
        ->add('event_date_to', 'hidden')
        ->add('event_organizer', 'hidden')
        ->add('event_location', 'hidden')

        ->add('content_id', 'hidden', array(
            'data' => isset($data['content_id']) ? $data['content_id'] : -1
        ))
        ->add('language', 'hidden', array(
            'data' => self::$language,
        ))
        ->add('title', 'text', array(
            'data' => isset($data['title']) ? $this->app['utils']->sanitizeText($data['title']) : '',
            'required' => self::$config['content']['field']['title']['required'],
            'label' => 'Headline'
        ))
        ->add('page_title', 'text', array(
            'data' => isset($data['page_title']) ? $this->app['utils']->sanitizeText($data['page_title']) : '',
            'required' => self::$config['content']['field']['page_title']['required'],
            'label' => 'SEO: Page title'
        ))
        ->add('description', 'textarea', array(
            'data' => isset($data['description']) ? $this->app['utils']->sanitizeText($data['description']) : '',
            'required' => self::$config['content']['field']['description']['required'],
            'label' => 'SEO: Description'
        ))
        ->add('keywords', 'textarea', array(
            'data' => isset($data['keywords']) ? $data['keywords'] : '',
            'required' => self::$config['content']['field']['keywords']['required'],
            'label' => 'SEO: Keywords'
        ))
        ->add('publish_from', 'text', array(
            'required' => self::$config['content']['field']['publish_from']['required'],
            'data' => date($this->app['translator']->trans('DATETIME_FORMAT'), strtotime($publish_from)),
        ))
        ->add('breaking_to', 'text', array(
            'required' => self::$config['content']['field']['breaking_to']['required'],
            'data' => date($this->app['translator']->trans('DATETIME_FORMAT'), strtotime($breaking_to)),
        ))
        ->add('archive_from', 'text', array(
            'required' => self::$config['content']['field']['archive_from']['required'],
            'data' => date($this->app['translator']->trans('DATETIME_FORMAT'), strtotime($archive_from)),
        ))
        ->add('teaser', 'textarea', array(
            'data' => isset($data['teaser']) ? $data['teaser'] : '',
            'required' => self::$config['content']['field']['teaser']['required']
{'fraction_non_alphanumeric': 0.1839504006550857, 'fraction_numerical': 0.005965958940164941, 'mean_word_length': 2.8284818629646216, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 199, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4712381', 'n_tokens_mistral': 5002, 'n_tokens_neox': 4883, 'n_words': 818}