Example #1
0
 public function parse($block)
 {
     $p = $this->document->createElement('p');
     $inline = new Inline($this->document);
     $inline->inject($p, str_replace("\n", ' ', $block));
     $this->document->documentElement->appendChild($p);
     return Block::MATCH;
 }
Example #2
0
 public function parse($block)
 {
     $lines = explode("\n", $block);
     if (count($lines) == 2 && $lines[1][0] == $this->char) {
         $element = $this->document->createElement($this->tag);
         $inline = new Inline($this->document);
         $inline->inject($element, $lines[0]);
         $this->document->documentElement->appendChild($element);
         return Block::MATCH;
     }
 }
Example #3
0
 /**
  * Dumps a PHP value to YAML.
  *
  * @param mixed $input  The PHP value
  * @param int   $inline The level where you switch to inline YAML
  * @param int   $indent The level of indentation (used internally)
  * @param int   $flags  A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
  *
  * @return string The YAML representation of the PHP value
  */
 public function dump($input, $inline = 0, $indent = 0, $flags = 0)
 {
     if (is_bool($flags)) {
         @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
         if ($flags) {
             $flags = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE;
         } else {
             $flags = 0;
         }
     }
     if (func_num_args() >= 5) {
         @trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
         if (func_get_arg(4)) {
             $flags |= Yaml::DUMP_OBJECT;
         }
     }
     $output = '';
     $prefix = $indent ? str_repeat(' ', $indent) : '';
     if ($inline <= 0 || !is_array($input) || empty($input)) {
         $output .= $prefix . Inline::dump($input, $flags);
     } else {
         $isAHash = array_keys($input) !== range(0, count($input) - 1);
         foreach ($input as $key => $value) {
             $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
             $output .= sprintf('%s%s%s%s', $prefix, $isAHash ? Inline::dump($key, $flags) . ':' : '-', $willBeInlined ? ' ' : "\n", $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $flags)) . ($willBeInlined ? "\n" : '');
         }
     }
     return $output;
 }
Example #4
0
 /**
  * Dumps a PHP value to YAML.
  *
  * @param  mixed   $input  The PHP value
  * @param  integer $inline The level where you switch to inline YAML
  * @param  integer $indent The level o indentation indentation (used internally)
  *
  * @return string  The YAML representation of the PHP value
  */
 public function dump($input, $inline = 0, $indent = 0)
 {
     $output = '';
     $prefix = $indent ? str_repeat(' ', $indent) : '';
     if ($inline <= 0 || !is_array($input) || empty($input)) {
         $output .= $prefix . Inline::dump($input);
     } else {
         $isAHash = array_keys($input) !== range(0, count($input) - 1);
         foreach ($input as $key => $value) {
             $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
             $output .= sprintf('%s%s%s%s', $prefix, $isAHash ? Inline::dump($key) . ':' : '-', $willBeInlined ? ' ' : "\n", $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + 2)) . ($willBeInlined ? "\n" : '');
         }
     }
     return $output;
 }
 /**
  * Dumps a PHP value to YAML.
  *
  * @param mixed $input                  The PHP value
  * @param int   $inline                 The level where you switch to inline YAML
  * @param int   $indent                 The level of indentation (used internally)
  * @param bool  $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
  * @param bool  $objectSupport          true if object support is enabled, false otherwise
  *
  * @return string The YAML representation of the PHP value
  */
 public function dump($input, $inline = 0, $indent = 0, $exceptionOnInvalidType = false, $objectSupport = false)
 {
     $output = '';
     $prefix = $indent ? str_repeat(' ', $indent) : '';
     if ($inline <= 0 || !is_array($input) || empty($input)) {
         $output .= $prefix . Inline::dump($input, $exceptionOnInvalidType, $objectSupport);
     } else {
         $isAHash = Inline::isHash($input);
         foreach ($input as $key => $value) {
             $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
             $output .= sprintf('%s%s%s%s', $prefix, $isAHash ? Inline::dump($key, $exceptionOnInvalidType, $objectSupport) . ':' : '-', $willBeInlined ? ' ' : "\n", $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $exceptionOnInvalidType, $objectSupport)) . ($willBeInlined ? "\n" : '');
         }
     }
     return $output;
 }
 /**
  * Parses a YAML value.
  *
  * @param  string $value A YAML value
  *
  * @return mixed  A PHP value
  *
  * @throws ParserException When reference does not exist
  */
 protected function parseValue($value)
 {
     if ('*' === substr($value, 0, 1)) {
         if (false !== ($pos = strpos($value, '#'))) {
             $value = substr($value, 1, $pos - 2);
         } else {
             $value = substr($value, 1);
         }
         if (!array_key_exists($value, $this->refs)) {
             throw new ParserException(sprintf('Reference "%s" does not exist (%s).', $value, $this->currentLine));
         }
         return $this->refs[$value];
     }
     if (preg_match('/^(?P<separator>\\||>)(?P<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?P<comments> +#.*)?$/', $value, $matches)) {
         $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
         return $this->parseFoldedScalar($matches['separator'], preg_replace('#\\d+#', '', $modifiers), intval(abs($modifiers)));
     } else {
         return Inline::load($value);
     }
 }
Example #7
0
 function inline_handler($params, $node)
 {
     global $CTX, $FUNCS, $AUTH;
     if ($AUTH->user->access_level < K_ACCESS_LEVEL_ADMIN || $CTX->get('k_disable_edit')) {
         return;
     }
     extract($FUNCS->get_named_vars(array('fields' => '', 'link_text' => 'Edit', 'prompt_text' => '', 'toolbar' => '', 'custom_toolbar' => '', 'custom_styles' => '', 'class' => '', 'url_only' => '0'), $params));
     // sanitize params
     $fields = trim($fields);
     if (!$fields) {
         die("ERROR: Tag \"" . $node->name . "\": no fields specified");
     }
     $link_text = trim($link_text);
     // can be set to empty
     $prompt_text = trim($prompt_text);
     $prompt_text = strlen($prompt_text) ? str_replace("'", "\\'", $prompt_text) : 'Please save the inline-edit changes first';
     $toolbar = strtolower(trim($toolbar));
     if (!in_array($toolbar, array('small', 'basic', 'medium', 'full', 'custom'))) {
         $toolbar = 'default';
     }
     $custom_toolbar = trim($custom_toolbar);
     $custom_styles = trim($custom_styles);
     $class = trim($class);
     if (strlen($class)) {
         $class = ' ' . $class;
     }
     $url_only = trim($url_only) == 1 ? 1 : 0;
     // get page_id (return if used in context of list_view)
     if ($CTX->get('k_is_page')) {
         $page_id = $CTX->get('k_page_id');
     } elseif ($CTX->get('k_is_list_page')) {
         // non-clonable template
         $page_id = 0;
     } else {
         return;
     }
     // happens in list_view
     // template_id
     $tpl_id = $CTX->get('k_template_id');
     $obj_id = $page_id ? $page_id : $tpl_id;
     $nonce = $FUNCS->create_nonce('edit_page_' . $obj_id);
     // create link
     $url = K_ADMIN_URL . "addons/inline/index.php?act=edit&tpl=" . $tpl_id . "&p=" . $page_id . "&nonce=" . $nonce . "&flist=" . $fields;
     $onclick = "TINY.box.show({iframe:'" . $url . "',animate:false,width:795,height:535,boxid:'k_inline',modal:1});";
     if (!$CTX->get('k_disable_inline_edit')) {
         $onclick = "if(window.CKEDITOR && window.CKEDITOR.k_regions){for(var i=0;i<window.CKEDITOR.k_regions.length;i++){if(window.CKEDITOR.k_regions[i].checkDirty()){alert( '" . $prompt_text . "' );window.CKEDITOR.k_regions[i].focus();return false;}}}" . $onclick;
     }
     if ($node->name == 'inline_link') {
         $html = $url_only ? $url : $onclick;
     } elseif ($node->name == 'inline_edit') {
         if ($CTX->get('k_disable_inline_edit')) {
             return;
         }
         $url = $url . '&ajax=1';
         $html = ' data-k-inline="' . $url . '" data-k-toolbar="' . $toolbar . '" contenteditable="true" ';
         if ($toolbar == 'custom') {
             $custom_toolbar = Inline::_toolbar($custom_toolbar);
             $html .= "data-k-custom-toolbar='{$custom_toolbar}' ";
         }
         if (strlen($custom_styles)) {
             list($custom_style_name, $custom_style_file) = array_map("trim", explode('=', $custom_styles));
             if (strpos($custom_style_file, '://') === false) {
                 $custom_style_file = K_SITE_URL . ($custom_style_file[0] == '/' ? substr($custom_style_file, 1) : $custom_style_file);
             }
             $custom_styles = $custom_style_name . ':' . $custom_style_file;
             $html .= "data-k-custom-styles='{$custom_styles}' ";
         }
     } else {
         //popup_edit
         $html = "<a href=\"#\" class=\"k_inline" . $class . "\" onclick=\"" . $onclick . "return false;\">" . $link_text . "</a>";
     }
     return $html;
 }
Example #8
0
 /**
  * @param mixed $content
  * @param string $title
  * @param bool $initialism
  */
 public function __construct($content = null, $title = null, $initialism = false)
 {
     $this->setInitialism($initialism)->setTitle($title);
     parent::__construct($content);
 }
Example #9
0
<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}
/**
 * Inline SVG Plugin
 *
 * @category    Plugin
 */
$plugin_info = array('pi_name' => 'Inline SVG', 'pi_version' => '1.0', 'pi_author' => 'Jamie Blacker', 'pi_author_url' => 'http://amitywebsolutions.co.uk', 'pi_description' => 'Inline an svg file', 'pi_usage' => Inline::usage());
class Inline
{
    // PREPARE VARS
    public $return_data;
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->EE =& get_instance();
        // Get folder from config
        $folder = $this->EE->config->item('svg_folder');
        // Only proceed if folder is set
        if ($folder !== FALSE) {
            $filename = trim($this->EE->TMPL->fetch_param('file'));
            // Fail silently with @
            $svg_file = @file_get_contents($folder . $filename);
            return $svg_file;
        } else {
            // Log error and do nothing
Example #10
0
 public function crop()
 {
     $this->inline = Inline::find($this->params()->id);
     $image = $this->inline->inline_images->toArray();
     $this->image = array_shift($image);
     if (!$this->image) {
         throw new Rails\ActiveRecord\Exception\RecordNotFoundException("Inline images set #" . $this->inline->id . " doesn't have inline images");
     }
     if (!current_user()->has_permission($this->inline)) {
         $this->access_denied();
         return;
     }
     if ($this->request()->isPost()) {
         if ($this->inline->crop($this->params()->toArray())) {
             $this->redirectTo(['#edit', 'id' => $this->inline->id]);
         } else {
             $this->respond_to_error($this->inline, ['#edit', 'id' => $this->inline->id]);
         }
     }
 }
Example #11
0
 /**
  * Dumps a PHP value to YAML.
  *
  * @param mixed $input  The PHP value
  * @param int   $inline The level where you switch to inline YAML
  * @param int   $indent The level of indentation (used internally)
  * @param int   $flags  A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
  *
  * @return string The YAML representation of the PHP value
  */
 public function dump($input, $inline = 0, $indent = 0, $flags = 0)
 {
     if (is_bool($flags)) {
         @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
         if ($flags) {
             $flags = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE;
         } else {
             $flags = 0;
         }
     }
     if (func_num_args() >= 5) {
         @trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
         if (func_get_arg(4)) {
             $flags |= Yaml::DUMP_OBJECT;
         }
     }
     $output = '';
     $prefix = $indent ? str_repeat(' ', $indent) : '';
     if ($inline <= 0 || !is_array($input) || empty($input)) {
         $output .= $prefix . Inline::dump($input, $flags);
     } else {
         $isAHash = Inline::isHash($input);
         foreach ($input as $key => $value) {
             if ($inline > 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n")) {
                 $output .= sprintf("%s%s%s |\n", $prefix, $isAHash ? Inline::dump($key, $flags) . ':' : '-', '');
                 foreach (preg_split('/\\n|\\r\\n/', $value) as $row) {
                     $output .= sprintf("%s%s%s\n", $prefix, str_repeat(' ', $this->indentation), $row);
                 }
                 continue;
             }
             $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
             $output .= sprintf('%s%s%s%s', $prefix, $isAHash ? Inline::dump($key, $flags) . ':' : '-', $willBeInlined ? ' ' : "\n", $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $flags)) . ($willBeInlined ? "\n" : '');
         }
     }
     return $output;
 }
Example #12
0
 /**
  * @param $scope
  * @param $body
  * @param $expected
  * @dataProvider processResponseBodyGetInlineScriptDataProvider
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function testProcessResponseBodyGetInlineScript($scope, $body, $expected)
 {
     $isJson = true;
     $this->prepareIsAllowed(true, true, true, $scope);
     $jsonCall = is_array($body) ? 2 * (count($body) + 1) : 2;
     $this->parserMock->expects($this->exactly($jsonCall))->method('setIsJson')->will($this->returnValueMap([[$isJson, $this->returnSelf()], [!$isJson, $this->returnSelf()]]));
     $this->parserMock->expects($this->exactly(1))->method('processResponseBodyString')->with(is_array($body) ? reset($body) : $body);
     $this->parserMock->expects($this->exactly(2))->method('getContent')->will($this->returnValue(is_array($body) ? reset($body) : $body));
     $model = new Inline($this->scopeResolverMock, $this->urlMock, $this->layoutMock, $this->configMock, $this->parserMock, $this->stateMock, '', '', $scope);
     $model->processResponseBody($body, $isJson);
     $this->assertEquals($body, $expected);
 }
Example #13
0
 public function format_inlines($text, $id)
 {
     $num = 0;
     $list = [];
     $text = preg_replace_callback('/image #(\\d+)/i', function ($m) use(&$list, &$num, $id) {
         $i = Inline::where(['id' => (int) $m[1]])->first();
         if ($i) {
             list($block, $script) = $this->format_inline($i, $num, $id);
             $list[] = $script;
             $num++;
             return $block;
         } else {
             return $m[0];
         }
     }, $text);
     if ($num > 0) {
         $text .= '<script type="text/javascript">' . implode("\n", $list) . '</script>';
     }
     return $text;
 }