Aptana PHP Formatter - use custom formatting rules - php

I'm using Apatana's formatting features in PHP documents, it works well except with arrays where it transform this:
$data = array(
'email' => $params['email'],
'username' => $params['username'],
);
into this:
$data = array('email' => $params['email'], 'username' => $params['username']);
is there a way to avoid this and set custom formatting rules?

Yes. There is a way.
Go to the Studio's preferences and locate the 'Formatter' item. If you are using the default formatter profile, create a new one by clicking the '+' icon.
Click to edit the PHP formatting setting (double-click the 'PHP' item, or click it and than click the 'Edit' button).
Under the 'New Lines' tab, check the option to 'Insert new line between array-creation elements'. OK the dialogs. Make sure that the profile you just created is the selected one in the formatter preferences page, and format your code.
Cheers

Related

What are the possible ways to translate in MediaWiki from "backend", without an extension?

I have a MediaWiki 1.33.0 website with only one extension → ContactPage, with which I can have a simple contact form.
Using HTMLForms template engine (in which the default form-template for ContactPage is written), I have expanded the default form to include a selection menu.
My problem
Selection list array keys and values of this selection menu are written in English inside LocalSettings.php but my site isn't primarily in the LTR English, rather, it is in the RTL Hebrew and I would like them to appear in my site's native language for end users.
My own code pattern
wfLoadExtension( 'ContactPage' );
$wgContactConfig['default'] = array(
'RecipientUser' => 'Admin', // Must be the name of a valid account which also has a verified e-mail-address added to it.
'SenderName' => 'Contact Form on ' . $wgSitename, // "Contact Form on" needs to be translated
'SenderEmail' => null, // Defaults to $wgPasswordSender, may be changed as required
'RequireDetails' => true, // Either "true" or "false" as required
'IncludeIP' => false, // Either "true" or "false" as required
'MustBeLoggedIn' => false, // Check if the user is logged in before rendering the form
'AdditionalFields' => array(
'omgaselectbox' => [
'class' => 'HTMLSelectField',
'label' => 'Select an option',
'options' => [
'X' => 'X',
'Y' => 'Y',
'Z' => 'Z',
],
],
),
// Added in MW 1.26
'DisplayFormat' => 'table', // See HTMLForm documentation for available values.
'RLModules' => array(), // Resource loader modules to add to the form display page.
'RLStyleModules' => array(), // Resource loader CSS modules to add to the form display page.
);
possible solutions
1) Writing selection list array keys and values in Hebrew (which might be a bit messy due to LTR-RTL clashings):
'options' => [
'ס' => 'ס',
'ט' => 'ט',
'ז' => 'ז',
],
2) Translating English selection list array keys and values in client side JavaScript by some similar code:
document.getElementById('select').selectedIndex = 0;
document.getElementById('select').value = 'Default';
My desire
I desire an ordinal backend way to do so, and if there is one, than without an extension
In this discussion, a MediaWiki community member recommended using system message transclution but the chapter dealing with it was very unclear to me; I didn't understand what this is about and how can this help in my situation.
My question
What are the possible ways to translate in MediaWiki from "backend", without an extension?
The localisation system is working perfectly fine in the backend (php), as well in the frontend (JavaScript) parts of MediaWiki → staying with it backend is best as it is more minimal.
Assuming you take a backend only approach:
Translation with a predefined string
If your desired translations already exist in MediaWiki (e.g. on another page of form), you can "simply" re-use the key. So, let's assume, your current additional select field definition looks like this:
'Select' => [
'type' => 'select',
'options' => [
'The english message' => 'value'
]
],
Then, you would change it to something like this:
'Select' => [
'type' => 'select',
'options-messages' => [
'the-message-key' => 'test'
]
],
Please consider the changing of options into the options-messages key.
Also: Change the key the-message-key to the message key you want to reuse.
If you know a page where the message/string is used, you can just open that page with the GET option uselang and the value qqx, in order to see the message key. Example: If the string is used on the login page, simply open the login page with https://example.com/wiki/Special:Userlogin?uselang=qqx to show all the message keys used on the page.
However, one warning when doing that: It is mostly discouraged to re-use existing message keys, especially when they're used on other pages. The keys are translated to hundreds of languages with that specific context in mind. That could also mean, that a translation in a specific language does not fit when the string/message is used on the contact page. So I would suggest to use the second option below.
Translation without a predefined string
Usually it will be done by extension which can provide a specific directory where the JSON files with the message key translations are saved. However, as you're "just" customizing an extension, you need a way to put in the translations for your keys.
So, first of all, let's take over the changes from above. Change your select field definition to be something like:
'Select' => [
'type' => 'select',
'options-messages' => [
'my-fancy-key' => 'test'
]
],
Now, two ways to get the key translated:
On-Wiki
By saving the message on-wiki, the messages can also easily being changed simply by editing the respective page in the wiki. In our example, let's translate the key to english and hebrew:
English: Edit the page MediaWiki:My-fancy-key in your wiki and add the desired text.
Hebrew: Edit the page MediaWiki:My-fancy-key/he in your wiki and add the desired text.
As part of the deployed code
We need to register a directory with JSON files for the translations of these messages. We're using the same configuration variable as extensions would use as well, $wgMessagesDirs, even given that we don't create an extension. Add the following line to your LocalSettings.php:
$wgMessagesDirs['ContactPageCustomization'] = __DIR__ . '/customContactPage';
Now, create a directory customContactPage in the root folder of your MediaWiki installation and put in the following file with the following contents:
en.json
{
"my-fancy-key": "Default"
}
If you want to translate to another language, create a new file with the language code you want to translate to. In hebrew it should be he, so let's create a new language file:
he.json
{
"my-fancy-key": "ברירת מחדל"
}
If you then open the contact page, the message key my-fancy-key should be translated to the english Default and the same (at least based on Google Translate) for hebrew. This is a more stable way of adding custom translations, however, you now also need to take care of translating the keys into the languages you want to support on your own as well. If a key is not translated into the selected language of the user, the default language, english, is used.

CKEditor not displaying data in CakePHP

I am using CKEditor plugin in CakePHP like this :
$this->element('ckeditor', array(
'name' => 'body',
'description'=>$body,
'id' => 'description',
'width' => 628,
'height' => 250
));
But I am unable to see the content on page load.
$instructionDetails['Instruction']['body'] contains html data. I tried static data also and its displaying in it but not html data.
On changing language I am able to see the content since I am using:
CKEDITOR.instances.description.setData(data);
in the JavaScript change event. Is there way to use setData in $this->element('ckeditor') with other params?
You need to tell ckeditor to open in which default mode. The mode to load at the editor startup depends on the plugins loaded. By default, the "wysiwyg" and "source" modes are available.
Use This
CKEDITOR.config.startupMode = 'source'
CKEDITOR.instances.config.startupMode = 'source'
What it will is open the data as source to you.

codeigniter destroying session after adding ckeditor latex code in cart

I am working on codeigniter project of online exams. I am creating optional question bank.
For adding multiple options i am single ck editor in which after creating option i am inserting option in codeigniter cart.
option is html of ck editor.
But when i am using latex equation in ckeditor as option, i am logging out.
its destroying my user login session. Normal html works fine.
who to overcome this problem?
<Script>
var option_html=CKEDITOR.instances['option'].getData()
$.post(base_url+"question_bank/questions/add_option",
{option_html:option_html,is_correct:is_correct}
,
function(data)
{
//code
}
);
</script>
php code
$data = array(
'id' => uniqid(),
'qty' => 1,
'price' => "1",
'name' => $is_correct,
'options' => array('type' => 'question_option',
'option_id'=>'',
'option_html' => $option_html)
);
$this->cart->insert($data);
i got answer there is no problem of cookie size. change value of product_name_rules in cart to '[:print:]'; change config to use database for session open ckedior/plugins/eqneditor/dialogs/eqneditor.js and remove statement a.setAttribute('alt')

HtmlEntities and Zend TextArea

I'm fairly new to ZF.
I've been building a website on Zend Framework.
Everything looks good.
But I can't figure out how to resolve 1 problem, that actually is essential when developing article management module.
I've got form that has ZEND_TextArea that looks like this:
$full_text = new Zend_Form_Element_TextArea('full_text');
$full_text->setLabel('Description:')
->setOptions(array('rows' => '28','cols' => '40'))
->setRequired(true)
->addValidator('NotEmpty', true)
->addFilter('HTMLEntities')
->addFilter('StringTrim');
It work great, it has filter HTMLEntities that is really essential for filtering TextArea.
When displaying the saved data on the website I'm using html_entity_decode($item['full_text']) and it's fine.
But as soon as I try to edit it, it loads encoded text into my textarea, after editing it encodes my already encoded text - and on the front page I get terrible things like:
p;quot;color: #ff0000;&amp;amp;quot;&amp;amp;gt;asdasda&amp;amp;lt;/
span&amp;amp;gt;sdas &amp;amp;lt;strong&amp;amp;gt;sdfsdf&amp;amp;
lt;/strong&amp;amp;gt;&
Maybe someone can help me figure out how to handle this problem, particularly load decoded data into Edit form of TextArea, so that my string doesn't get encoded twice, and when editing it was show in human manner and not into encoded one.
If you can provide code example - will be really AWESOME!!
thanks!!
Do not use HtmlEntities filter in edit form, if you use it in create form.
Create form :
$elements[] = $this->createElement('text','name',array(
'label' => 'test',
'filters' => array('HtmlEntities'),
));
Edit Form :
$elements[] = $this->createElement('text','name',array(
'label' => 'test',
'value' => html_entity_decode($value)
));
Your doing html_entity_decode() to set value, to show right 'name' to user..
When UPDATING data in model, you use htmlEntities filter again:
$data['name'] = $HtmlEntities->filter($data['name']);

SugarCRM - How to set the default homepage for all users

I am using SugarCRM Version 5.2.0k (Build 5837). I would like to be able to set a default home page (with dashlets I've created myself) that will be the same for all users, can anyone advice on best way to do this?
Thanks in advance for your help
I'd like to know how to do this too... see here for some ideas, but it's clear that it's not a supported feature.
I wonder if you can write a module that installs a hook for post user creation (assuming that this hook is provided) and then populate the appropriate part of the user preferences table when the hook is invoked. Of course, your module will probably break with each upgrade of SurgarCRM, so this might be more trouble than it i worth.
Edit:
I had a look at the Dash Manager module that is referenced in the thread I linked to above. It's approach is to copy the preferences of the admin user to all other users when the administrator clicks a link in the admin page. So, the admin user is used as a sort of template for other users. Rudimentary solution, but not a bad start - using a template user and treating the preferences (as stored in the DB table) as opaque seems like the way to go.
It's quite easy to do it.
I have done it in SugarCRM 6.5.23.
Here I have mentioned steps to do it:
Just copy sugarcrm_root/modules/Home/index.php and paste it in SugarCRM_root/custom/modules/Home/index.php.
Now you can customize it's behavior as you want.
You can remove default dashlets and add your own dashlets by creating one file at SugarCRM_root/custom/modules/Home/dashlets.php and add this code in it:
<?php
unset($defaultDashlets);
$defaultDashlets = array(
'CustomDashlet' => 'ModuleName',
'UpcomingAppointmentsDashlet' => 'Meetings', //Example
);
Once you do this thing still you have 3 dashlets left in your hook code you can remove it if it's needed code for that hook is like this:
$dashlets[create_guid()] = array(
'className' => 'iFrameDashlet',
'module' => 'Home',
'forceColumn' => 0,
'fileLocation' => $dashletsFiles['iFrameDashlet']['file'],
'options' => array('titleLabel' => 'LBL_DASHLET_DISCOVER_SUGAR_PRO',
'url' => '...',
'height' => 315,
));
Hope this will help you. :)

Categories