YiiBooster - Custom ckeditorrow - php

Good Morning Guys!
I have a problem to solve. I trying all possibilities thought on the net but nothing work.
Use a YiiBooster, and the problem is to use the ckEditorRow. When I trying custon this widget to showing some options, according the manual of CkEditor, I can change the property 'toolbar', but I try configure in several ways but doesn't work!
my last test is:
$ckeditor = "[
{ name: 'document', items : [ 'NewPage','Preview' ] },
{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
{ name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','Scayt' ] },
{ name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'
,'Iframe' ] },
'/',
{ name: 'styles', items : [ 'Styles','Format' ] },
{ name: 'basicstyles', items : [ 'Bold','Italic','Strike','-','RemoveFormat' ] },
{ name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote' ] },
{ name: 'links', items : [ 'Link','Unlink','Anchor' ] },
{ name: 'tools', items : [ 'Maximize','-','About' ] }
];";
<?php echo $form->ckEditorRow($model, 'ds_nick_usr', array('options'=>array('language'=>'pt','disableNativeSpellChecker'=>false,'scayt_autoStartup'=>true, 'toolbar_Basic'=>$ckeditor, 'toolbar'=>'Basic', 'fullpage'=>'js:true', 'width'=>'640', 'resize_maxWidth'=>'640','resize_minWidth'=>'320')));?>
In this test, on my ckEditorRow should appear only options, Source, Bold and Italic. But in the case, nothing showing!
Other test show a full editor.
Any Ideas to solve my problem?
Thanks in advance!
PS: I trying too edit config.js but no sucess;
Best Regards,
Marcos.

Yii will escape your JS code so all the ' will become \'.
All you need to do is: $ckeditor="js:[the configuration you have]"

Just an answer, perhaps it may help someone:
<?php echo $form->ckEditorGroup($model,'ds_nick_usr',
array(
'widgetOptions' => array(
'editorOptions' => array(
'toolbar'=>array(
array( '-', 'Bold', 'Italic', 'Strike' ),
array( 'Image', 'Link', 'Unlink', '-', 'Source'),
),
),
))); ?>
works for me.

Related

MongoDb fetch document subset using PHP

I have a MongoDB document structure like this:
[
{
"locale":"en",
"translations":[
{
"name":"translation1",
"value":"enValue"
},
{
"name":"translation2",
"value":"enValue"
},
{
"name":"translation3",
"value":"enValue"
}
]
},
{
"locale":"ru",
"translations":[
{
"name":"translation1",
"value":"ruValue"
},
{
"name":"translation2",
"value":"ruValue"
},
{
"name":"translation3",
"value":"ruValue"
}
]
}
]
and I need to get the translation with name translation1 for locale en.
The expected result I want is:
{
"_id" : ObjectId("5e845ba1005e625a6237d2e0"),
"translations" : [
{
"name" : "translation1",
"value" : "enValue"
}
]
}
I know how to do this with pure mongo, it should be like this:
db.translations.find({"locale" : "en"},
{ translations: { $elemMatch: { name: "translation1" } } } )
Here is the proof https://gyazo.com/fb9b1a505a898c7137ece5304d715171
but I can't make it work with PHP. I tried code like:
$collection = $this->database->{$group};
$collection->find(
[
'locale' => 'en',
'translations' => ['$elemMatch' => ['name' => 'translation1']
]
);
And Im getting all translations for en instead of only tranlsation1 as a result:
{
"_id" : ObjectId("5e845ba1005e625a6237d2e0"),
"locale" : "en",
"translations" : [
{
"name" : "translation1",
"value" : "enValue"
},
{
"name":"translation2",
"value":"enValue"
},
{
"name":"translation3",
"value":"enValue"
}
]
}
I tried as:
$collection = $this->database->{$group};
$collection->find(
['locale' => 'en'],
[
'translations' => ['$elemMatch' => ['name' => 'translation1']
]
);
also result is the same as above.
Tried like:
$collection = $this->database->{$group};
$collection->find(
[
'locale' => 'en',
[
'translations' => ['$elemMatch' => ['name' => 'translation1']
]
]
);
result is null
As a workaround, for now, I filter result on PHP side, but it extra work
This appears to be a bug in the driver.
This database command should be equivalent to the find you were running, but the command works as expected while the find does not.
$this->$database->command([
'find'=>'CollectionName',
'filter'=>['locale' => 'en'],
'projection'=>['translations' => ['$elemMatch' => ['name' => 'translation1']]]
])

Symfony YAML : Formatting the Output

I am using the Symfony YAML Component to model and output a yml file.
What I want to achieve is the following:
id: my-page
name: My Page
fields:
pageTitle: My Page Title
placeholders:
project-main:
- component: MyComponent
fields:
imageSmall:
src: /path/to/image.jpg
imageMed:
src: /path/to/image.jpg
I am almost managing that, just need help to understand how I need to form the line from componentName onwards. The result I'm getting at the moment is the following:
id: my-page
name: My Page
fields:
pageTitle: 'My Page Title'
placeholders:
project-main: { component: MyComponent, 0: { fields: { imageSmall: 'src: /path/to/image.jpg', imageMed: 'src: /path/to/image.jpg' } } }
Whilst this is the PHP Code I'm using to obtain this, is the following:
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Yaml\Exception\ParseException;
$array = array(
"id" => "my-page",
"name" => "My Page",
"fields" => ["pageTitle" => "My Page Title"],
"placeholders" => ["project-main" => array("component" => "MyComponent", array("fields"=>array("imageSmall" => "src: /path/to/image.jpg","imageMed" => "src: /path/to/image.jpg")))]);
$yaml = Yaml::dump($array);
file_put_contents('file.yaml', $yaml);
Anyone can help put me on the right track :) ?
**
UPDATE
**
I have followed the tip in the comments and updated the PHP as follows:
$array = array(
"id" => "my-page",
"name" => "My Page",
"fields" => ["pageTitle" => "My Page Title"],
"placeholders" => ["project-main" => ["component" => "MyComponent", "fields"=>array("imageSmall" => "src: /path/to/image.jpg","imageMed" => "src: /path/to/image.jpg")]]);
$yaml = Yaml::dump($array,4);
file_put_contents('file.yaml', $yaml);
After this, my output is as follows:
id: my-page
name: My Page
fields:
pageTitle: My Page Title
placeholders:
project-main:
component: MyComponent
fields:
imageSmall:
src: /path/to/image.jpg
imageMed:
src: /path/to/image.jpg
So I have moved a bit, but still getting "component: MyComponent" instead of "- component: My Component". Any tips on solving this one last issue :) ?
To control the level at which the dumper switches to using the inline notation you have to pass the desired level as the second argument to the dump() method (the default value is 2).
To get the expected structure while dumping you need to adjust the input array which currently does not represent what you expect it to be:
use Symfony\Component\Yaml\Yaml;
$array = [
'id' => 'my-page',
'name' => 'My Page',
'fields' => ['pageTitle' => 'My Page Title'],
'placeholders' => [
'project-main' => [
[
'component' => 'MyComponent',
'fields' => [
'imageSmall' => [
'src' => '/path/to/image.jpg',
],
'imageMed' => [
'src' => '/path/to/image.jpg',
],
],
],
],
],
];
$yaml = Yaml::dump($array, 6);

Elasticsearch in php doesn't recognize dash

I'm working on a project and try to make a search with elasticsearch but my field can contain dash and when I search with it I can't find the result I'm looking for, so I tried to change the mapping but the index doesn't work at all. I don't have any error message but I can't find what I indexed even using a different field. So what I did was :
$params = [
'index' => 'arc',
'type' => 'purchase',
'id' => $purchase['id'],
'body' => $purchase
];
It worked great with that except for the field with the dash. My $purchase looks like that :
array:34 [
"id" => 163160
"distant" => "MOR-938BBM28147090"
[...]
]
so when I search for "MOR" I find the result but when I do "MOR-" nothing. I tried to change the mapping by doing that :
$params = [
'index' => 'arc',
'type' => 'purchase',
'id' => $purchase['id'],
'body' => [
'mappings' => [
'_default_' => [
'properties' => [
'distant' => [
'type' => 'string',
'index' => 'not_analyzed'
]
]
]
],
$purchase
]
];
But with that even if I try to search "163160" I can't find any result.
Whitespace analyzer could be the right solution in this case. It takes into account only whitespaces while breaking text into tokens, and characters like "-" or "_" are still treated as a part of a term.
But if you need to do a partial matching, for example with "MOR-" token, then it requires a bit more complicated mapping.
As I don't know php, I'll be using Elasticsearch syntax. First, create a proper mapping:
PUT http://127.0.0.1:9200/arc
{
"settings": {
"analysis": {
"analyzer": {
"edge_ngram_analyzer": {
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "edge_ngram",
"min_gram": 3,
"max_gram": 18,
"token_chars": [
"letter",
"digit",
"punctuation"
]
}
}
}
},
"mappings": {
"purchase": {
"properties": {
"distant": {
"type": "string",
"analyzer": "edge_ngram_analyzer"
}
}
}
}
}
As you can see, I use EdgeNGram tokenizer here. When you index a document with MOR-938BBM28147090 in distant field, it will create following tokens:
[MOR, MOR-, MOR-9, MOR-93, MOR-938, MOR-938B, MOR-938BB, ...]
The core point here is punctuation character class in token_chars list, that tells elasticsearch, that dash character (and some others like ! or ") should be included in a token and not treated as a "split char".
Now when I index the document:
PUT http://127.0.0.1:9200/arc/purchase/163160
{
"distant": "MOR-938BBM28147090"
}
and run a term search query:
POST http://127.0.0.1:9200/arc/purchase/_search
{
"query": {
"bool" : {
"must" : {
"term" : {
"distant": "MOR-93"
}
}
}
}
}
I get in response:
"hits": {
"total": 1,
"max_score": 0.6337049,
"hits": [
{
"_index": "arc",
"_type": "purchase",
"_id": "163160",
"_score": 0.6337049,
"_source": {
"distant": "MOR-938BBM28147090"
}
}
]
}

Elasticsearch MLT query with Elastica for PHP

Wondering if this from the Elasticsearch official doc:
{
"more_like_this" : {
"fields" : ["name.first", "tweet"],
"like" : [
{
"_index" : "marvel",
"_type" : "quotes",
"doc" : {
"name": {
"first": "Ben",
"last": "Grimm"
},
"tweet": "You got no idea what I'd... what I'd give to be invisible."
}
},
],
"min_term_freq" : 1,
"max_query_terms" : 1
}
}
is yet implemented within the latest release of Elastica?
The bit I am struggling with is the "doc" section of the "like".
My code is as follow:
$moreLikeThis = (new Query\MoreLikeThis())
->setFields([
'name.first',
'tweet'
])
->setLike((new Document())
->setIndex('myIndexName')
->setType('myTypeName')
->setData([
'tweet' => 'Foo',
'name' => [
'first' => 'Bar',
'last' => 'Test'
]
])
)
->setMinTermFrequency(1)
->setMinDocFrequency(1);
But it looks like the query is not generated properly. Here is what I get when I var_dump() Request::toString():
string(398)
"{"path":"myIndexName/myTypeName/_search","method":"GET","data":{"query":{"more_like_this":{"fields":["name.first","tweet"],"like":{"_id":"","_type":"myTypeName","_index":"myIndexName"},"min_term_freq":1,"min_doc_freq":1}}},"query":{"search_type":"count"},"connection":{"config":[],"host":"localhost","port":9200,"enabled":true}}"
The "doc" section if definitely missing? Am I not using it properly?
If anyone is wondering, the feature was actually not fully implemented within Elastica.
It's fixed now.

Delete some features from CKEditor text editor [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
How can I delete some features from CKEditor text editor? I only need basic features like bold an so on.
To remove features from the editor, you should adjust config.plugins in your config like:
config.plugins = 'usefulPlugin, anotherUsefulPlugin, ...'
Another possibility is to remove undesired plugins from current configuration:
config.removePlugins = 'unwantedPlugin, anotherUnwantedPlugin, ...'
Additionally, you can use the official CKEditor builder and create own editor package by selecting things that you find useful in the GUI.
After all, you can adjust the toolbar. Please note that changing toolbar doesn't affect features running in your editor instance - they're still loaded, and working but not accessible via toolbar. This might be a troublemaker if you don't control it.
below are some basic setting of CKEditor
config.toolbar = 'Full';
config.toolbar_Full =
[
{ name: 'document', items : [ 'Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates' ] },
{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
{ name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] },
{ name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton',
'HiddenField' ] },
'/',
{ name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },
{ name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv',
'-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] },
{ name: 'links', items : [ 'Link','Unlink','Anchor' ] },
{ name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe' ] },
'/',
{ name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] },
{ name: 'colors', items : [ 'TextColor','BGColor' ] },
{ name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] }
];
config.toolbar_Basic =
[
['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink','-','About']
];

Categories