Skip to content

Commit

Permalink
- Added lang property which can be used for localization
Browse files Browse the repository at this point in the history
- Fixed some content escaping
  • Loading branch information
swatty007 committed Sep 30, 2020
1 parent fc7b45c commit 9181c79
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Http/InlineController.php
Expand Up @@ -2,9 +2,9 @@

namespace swatty007\LaravelInlineEditor\Http;

use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Routing\Controller as BaseController;

class InlineController extends BaseController
Expand All @@ -25,7 +25,7 @@ public function index(Request $request)

DB::table($block['table'])
->where($block['source_key'], $block['source_value'])
->update([ $block['target_key'] => $content]);
->update([$block['target_key'] => $content]);
}

return 'ok';
Expand Down
23 changes: 18 additions & 5 deletions src/InlineEditor.php
Expand Up @@ -9,7 +9,7 @@
class InlineEditor
{

protected static $models = [];
protected static $models = [];

/**
* Setup block
Expand All @@ -22,9 +22,10 @@ class InlineEditor
* @param string $options Display options for the vue editor.
* @param string $validationRules Name of the Configuration Object for some Custom Validation Rules.
* @param boolean $rawText Enables stripping of all HMTL Elements, from the input content.
* @param string $lang Language Identifier used for localization.
* @return boolean
*/
public static function setUp( $source_value, $table = null, $source_key = null, $target_key = null, $options = null, $validationRules = null, $rawText = null)
public static function setUp( $source_value, $table = null, $source_key = null, $target_key = null, $options = null, $validationRules = null, $rawText = null, $lang = null)
{
// Set default values for out items, if they are not defined
if( !isset($source_value) ) $source_value = 'key';
Expand All @@ -35,10 +36,11 @@ public static function setUp( $source_value, $table = null, $source_key = null,
if( !isset($options) ) $options = config('laravel-inline-editor.options');
if( !isset($validationRules) ) $validationRules = 'default';
if( !isset($rawText) ) $rawText = false;
if( !isset($lang) ) $lang = false;

$rawText = $rawText ? 'true':'false';

self::$models[$source_value] = [$table, $source_key, $target_key , $options, $validationRules, $rawText];
self::$models[$source_value] = [$table, $source_key, $target_key , $options, $validationRules, $rawText, $lang];

ob_start();

Expand Down Expand Up @@ -73,18 +75,29 @@ public static function tearDown()
}

if (Gate::allows('laravel-inline-editor')) {

return sprintf('<inline-content-block
source_key="'.$objectData[1].'"
source_value="'.$key.'"
target_key="'.$objectData[2].'"
validationRules="'.$objectData[4] .'"
rawText="'.$objectData[5] .'"
lang="'.$objectData[6] .'"
table="'.$objectData[0].'"
options="'. $objectData[3].'"
content="'. str_replace('"',"'",$contentBlock->{$objectData[2]}).'"
content="'. str_replace('%', '%%', e($contentBlock->{$objectData[2]}) ) .'"
>%s</inline-content-block>', $key, trim($contentBlock->{$objectData[2]}));
}

return trim($contentBlock->{$objectData[2]});
if( $objectData[6] ) {
$data = json_decode( $contentBlock->{$objectData[2]} );
if( isset($data->{$objectData[6]}) )
$data = $data->{$objectData[6]};
else
$data = '';
return $data;
}
else
return trim($contentBlock->{$objectData[2]});
}
}
3 changes: 3 additions & 0 deletions src/assets/js/laravel-inline-editor/contentBlock.vue
Expand Up @@ -14,6 +14,7 @@
validationRules : null,
table : null,
options : null,
lang : null,
source_key : null,
source_value : null,
target_key : null,
Expand All @@ -30,6 +31,8 @@
var optionsString = this.$el.attributes.options.nodeValue;
this.options = JSON.parse( optionsString.replace(/'/g, '"') );
this.lang = this.$el.attributes.lang.nodeValue;
this.medium = new MediumEditor(this.$el, this.options );
this.medium.setContent( this.$el.attributes.content.nodeValue );
Expand Down
1 change: 1 addition & 0 deletions src/assets/js/laravel-inline-editor/manager.vue
Expand Up @@ -26,6 +26,7 @@
changed.push({
rawText : block.rawText,
validationRules : block.validationRules,
lang : block.lang,
table : block.table,
source_key : block.source_key,
source_value : block.source_value,
Expand Down

0 comments on commit 9181c79

Please sign in to comment.