<commit_before><?php
/**
* Nodeattachment helper
*
* @author <NAME> <<EMAIL>>
* @copyright (c) 2010 <NAME>
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
*/
class NodeattachmentHelper extends AppHelper {
        
        /**
         * Used helpers
         *
         * @var array
         */
        public $helpers = array(
            'Html',
            'Layout',
            'Image2'
        );

        /**
         * Attachment types
         *
         * @var array
         */
        public $attachment_types = array(
            'video',
            'audio',
            'application',
            'text',
            'image'
        );

        /**
         * Nodeattachment
         *
         * @var array
         */
        public $nodeattachment = array();

        /**
         * Before render callback
         *
         * @return void
         */
        public function beforeRender() {

                $this->conf = Configure::read('Nodeattachment');
        }

        /**
         * After set node callback
         * Set all attachments by types
         *
         * @return void
         */
        public function afterSetNode() {

                foreach ($this->attachment_types as $type) {
                        $attachments[$type] = $this->extractMimeType($this->Layout->node, $type);
                }
                $this->Layout->node['Nodeattachments'] = $attachments;
        }

        /**
         * Node thumb
         *
         * @param string $field Filed of attachment to return
         * @return string Url of the thumb image
         */
        public function nodeThumb($width, $height, $method = 'resizeRatio', $options = array()) {

                $attachment = Set::extract('/Nodeattachment/.[1]', $this->Layout->node);
                $this->setNodeattachment($attachment[0]);
                if (!empty($this->nodeattachment)) {
                        return $this->Image2->resize($this->field('thumb_path'), $width, $height, $method, $options, FALSE, $this->field('server_thumb_path'));
                }
                return false;
        }

        /**
         * Set nodeattachment
         *
         * @param array $var
         * @return void
         */
        public function setNodeattachment($nodeattachment) {

                $model = 'Nodeattachment';
                if (isset($nodeattachment['id'])) {
                        $data = $nodeattachment;
                }
                if (isset($nodeattachment[$model]['id'])) {
                        $data = $nodeattachment[$model];
                }
                $this->nodeattachment[$model] = $data;
                $this->__thumb();
                $this->__flv();
        }

        /**
         * If file (video) has flv variant
         *
         * @return void
         */
        private function __flv() {

                $is_video = strpos($this->field('mime_type'), 'video');
                if ($is_video === 0) {
                        $file_name = explode('.', $this->field('slug'));

                        $flv_file = $this->conf['flvDir'] . DS . $file_name[0] . '.flv';<commit_msg>treatment data input<commit_after><?php
/**
* Nodeattachment helper
*
* @author <NAME> <<EMAIL>>
* @copyright (c) 2010 <NAME>
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
*/
class NodeattachmentHelper extends AppHelper {
        
        /**
         * Used helpers
         *
         * @var array
         */
        public $helpers = array(
            'Html',
            'Layout',
            'Image2'
        );

        /**
         * Attachment types
         *
         * @var array
         */
        public $attachment_types = array(
            'video',
            'audio',
            'application',
            'text',
            'image'
        );

        /**
         * Nodeattachment
         *
         * @var array
         */
        public $nodeattachment = array();

        /**
         * Before render callback
         *
         * @return void
         */
        public function beforeRender() {

                $this->conf = Configure::read('Nodeattachment');
        }

        /**
         * After set node callback
         * Set all attachments by types
         *
         * @return void
         */
        public function afterSetNode() {

                foreach ($this->attachment_types as $type) {
                        $attachments[$type] = $this->extractMimeType($this->Layout->node, $type);
                }
                $this->Layout->node['Nodeattachments'] = $attachments;
        }

        /**
         * Node thumb
         *
         * @param string $field Filed of attachment to return
         * @return string Url of the thumb image
         */
        public function nodeThumb($width, $height, $method = 'resizeRatio', $options = array()) {

                $attachment = Set::extract('/Nodeattachment/.[1]', $this->Layout->node);
                $this->setNodeattachment($attachment[0]);
                if (!empty($this->nodeattachment)) {
                        return $this->Image2->resize($this->field('thumb_path'), $width, $height, $method, $options, FALSE, $this->field('server_thumb_path'));
                }
                return false;
        }

        /**
         * Set nodeattachment
         *
         * @param array $var
         * @return void
         */
        public function setNodeattachment($nodeattachment) {

                $model = 'Nodeattachment';
                if (isset($nodeattachment['id'])) {
                        $data = $nodeattachment;
                }
                if (isset($nodeattachment[$model]['id'])) {
                        $data = $nodeattachment[$model];
                }
                if (isset($data)) {
                     $this->nodeattachment[$model] = $data;
                     $this->__thumb();
                     $this->__flv();
                }
        }

        /**
         * If file (video) has flv variant
         *
         * @return void
         */
        private function __flv() {

                $is_video = strpos($this->field('mime_type'), 'video');
                if ($is_video === 0) {
                        $file_name = explode('.', $this->field('slug'));

                        $flv_file = $this->conf['flvDir'] . DS . $file_name[0] . '.flv';
{'fraction_non_alphanumeric': 0.13517305893358278, 'fraction_numerical': 0.0031181789834736516, 'mean_word_length': 1.2910714285714286, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 53, 'https://': 0, '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': '1189609', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1586, 'n_words': 341}