<commit_before><?php

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

namespace phpManufaktur\Basic\Control\kitCommand;

use phpManufaktur\Basic\Control\kitCommand\Basic as kitCommand;

class Help extends kitCommand {

    const USERAGENT = 'kitFramework:Basic';

    /**
     * Get the content of the specified help file from Gist
     *
     * @param string $info_path to the command.xxx.json file
     */
    public function getContent($info_path)
    {
        $info = $this->app['utils']->readConfiguration($info_path);
        $locale = $this->app['request']->query->get('locale', $this->getCMSlocale());
        if (isset($info['help'][$locale]['gist_id'])) {
            $gist_id = $info['help'][$locale]['gist_id'];
            $gist_link = (isset($info['help'][$locale]['link'])) ? $info['help'][$locale]['link'] : '';
        }
        elseif (isset($info['help']['en']['gist_id'])) {
            $gist_id = $info['help']['en']['gist_id'];
            $gist_link = (isset($info['help']['en']['link'])) ? $info['help']['en']['link'] : '';
        }
        else {
            return $this->app['twig']->render($this->app['utils']->templateFile('@phpManufaktur/Basic/Template', 'kitcommand.help.unavailable.twig'),
                array('command' => $info['command']));
        }
        $ch = curl_init("https://api.github.com/gists/$gist_id");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, self::USERAGENT);
        $result = curl_exec($ch);
        if (!curl_errno($ch)) {
            $curl_info = curl_getinfo($ch);
        }
        curl_close($ch);
        if (isset($curl_info) && isset($curl_info['http_code']) && ($curl_info['http_code'] == '200')) {
            $result = json_decode($result, true);
            if (isset($result['files'])) {
                foreach ($result['files'] as $file) {
                    if (isset($file['content'])) {
                        $help = array(
                            'command' => $info['command'],
                            'content' => $file['content'],
                            'link' => $gist_link,
                            'help' => FRAMEWORK_URL.'/help/command/help?pid='.$this->getParameterID()
                        );
                        return $this->app['twig']->render($this->app['utils']->templateFile('@phpManufaktur/Basic/Template', 'kitcommand.help.content.twig'),
                            array('help' => $help));
                    }
                }
            }
        }
        else {
            return $this->app['twig']->render($this->app['utils']->templateFile('@phpManufaktur/Basic/Template', 'kitcommand.help.unavailable.twig'),
                array(
                    'command' => $info['command'],
                    'curl_info' => $curl_info
            ));
        }
    }

    /**
     * Get the help page for the specified kitCommand from Github Gist
     *
     * @param string $command
     */<commit_msg>fixed route for help command<commit_after><?php

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

namespace phpManufaktur\Basic\Control\kitCommand;

use phpManufaktur\Basic\Control\kitCommand\Basic as kitCommand;

class Help extends kitCommand {

    const USERAGENT = 'kitFramework:Basic';

    /**
     * Get the content of the specified help file from Gist
     *
     * @param string $info_path to the command.xxx.json file
     */
    public function getContent($info_path)
    {
        $info = $this->app['utils']->readConfiguration($info_path);
        $locale = $this->app['request']->query->get('locale', $this->getCMSlocale());
        if (isset($info['help'][$locale]['gist_id'])) {
            $gist_id = $info['help'][$locale]['gist_id'];
            $gist_link = (isset($info['help'][$locale]['link'])) ? $info['help'][$locale]['link'] : '';
        }
        elseif (isset($info['help']['en']['gist_id'])) {
            $gist_id = $info['help']['en']['gist_id'];
            $gist_link = (isset($info['help']['en']['link'])) ? $info['help']['en']['link'] : '';
        }
        else {
            return $this->app['twig']->render($this->app['utils']->templateFile('@phpManufaktur/Basic/Template', 'kitcommand.help.unavailable.twig'),
                array('command' => $info['command']));
        }
        $ch = curl_init("https://api.github.com/gists/$gist_id");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, self::USERAGENT);
        $result = curl_exec($ch);
        if (!curl_errno($ch)) {
            $curl_info = curl_getinfo($ch);
        }
        curl_close($ch);
        if (isset($curl_info) && isset($curl_info['http_code']) && ($curl_info['http_code'] == '200')) {
            $result = json_decode($result, true);
            if (isset($result['files'])) {
                foreach ($result['files'] as $file) {
                    if (isset($file['content'])) {
                        $help = array(
                            'command' => $info['command'],
                            'content' => $file['content'],
                            'link' => $gist_link,
                            'help' => FRAMEWORK_URL.'/command/help?pid='.$this->getParameterID()
                        );
                        return $this->app['twig']->render($this->app['utils']->templateFile('@phpManufaktur/Basic/Template', 'kitcommand.help.content.twig'),
                            array('help' => $help));
                    }
                }
            }
        }
        else {
            return $this->app['twig']->render($this->app['utils']->templateFile('@phpManufaktur/Basic/Template', 'kitcommand.help.unavailable.twig'),
                array(
                    'command' => $info['command'],
                    'curl_info' => $curl_info
            ));
        }
    }

    /**
     * Get the help page for the specified kitCommand from Github Gist
     *
     * @param string $command
     */
{'fraction_non_alphanumeric': 0.18280414963847846, 'fraction_numerical': 0.0022005658597925182, 'mean_word_length': 2.168824701195219, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 67, 'https://': 4, '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': '5033180', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1874, 'n_words': 292}