CostaRico/yii2-images 404 error in the additional application - php

I can upload and see images by admin panel in back-end application without any problems and see images in the "frontend" yii2 application also, but I have an additional separate front-end application and I can't see images there. It's returns 404 error.
Take one image, for example, that has one URL in all applications, but all applications have different domain names.
My common/config/main.php :
'modules' => [
'yii2images' => [
'class' => 'rico\yii2images\Module',
//be sure, that permissions ok
//if you cant avoid permission errors you have to create "images" folder in web root manually and set 777 permissions
'imagesStorePath' => '#root/upload/store', //path to origin images
'imagesCachePath' => '#root/upload/cache', //path to resized copies
'graphicsLibrary' => 'GD', //but really its better to use 'Imagick'
'placeHolderPath' => '#root/upload/store/no-image.png', // if you want to get placeholder when image not exists, string will be processed by Yii::getAlias
'imageCompressionQuality' => 85, // Optional. Default value is 85.
]
Same code of Costa-Rico/images in all 3 models:
public $gallery;
public $gallery_url;
public function behaviors()
{
return [
'image' => [
'class' => 'rico\yii2images\behaviors\ImageBehave',
]
];
}
In the separate frontend application I trying to show image by with code:
$general_logo = General::find()->where(['index' => 'logo_social'])->one();
if($general_logo) $image = $general_logo->getImage();
if($general_logo && $image) : ?>
<meta property="og:image" content="<?= $image->getUrl(); ?>"/>
<?php endif; ?>
I was trying to use frontend\models\General and creating of own this_separate_application\models\General (ActiveRecord, same table) for this application.
How I can to solve this problem? Thank you.

If I understand correctly, you want to access an image from the back-end in the front-end. And they both have different domains. If that is indeed the case, you can just do this in the front-end, while replacing BACKEND_URL with the URL of the back-end. Let me know how it goes.
<meta property="og:image" content="<?= BACKEND_URL . $image->getUrl(); ?>"/>

I find the mistake. It was the stupid problem in the routing of my additional application. In the file separate_application/config/main.php:
'urlManager' => [
'rules' => [
[
'pattern' => '<url:.+>',
'route' => 'page/view',
],
],
]
This rule sent all URL patterns, that don't fit previous rules, to the controller PageController that is responsible for display of separated text pages. PageController also returned 404 page. In this way, it captured URL before it was processed by extension CostaRico/yii2-images and sent the script wrong way. This rule was deleted. Everything is ok with images now!

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.

How to make a custom theme using Laravel and where to store theme data?

I'm building a full website Using Laravel and this problem is facing me , I want to give the user full control to the site appearance and the ability to change website's layout without my help.
But when I'm thinking about someway to do so by database , there are several tables with tens of columns will be added beside the colors and sections that will be added to database every time the user will change something in the layout style.
Is there any other way to store the options of the theme in XML file or anything other than database?
** Note : when I checked the database of Wordpress I hadn't found any thing concerned to themes there , So where Wordpress store theme options?
For your XML-like storage you can use Laravel Config. Let's say you have the file config/templates.php. Inside you can have a lot of stuff like.
return [
'default_template' => 'layouts.templates.default',
'posts' => 'layouts.templates.post',
'footer' => 'layouts.includes.footer',
'options' => [
'full_with' => false,
'has_footer' => true,
'background_color' => '#fff',
'more_keys' => 'key_value'
]
];
Then anywhere in your app you can get the default template like
$view = config('templates.default_template'); //will get
return view($view, compact('params'));
To update a key, like has_footer, you do
config(['templates.options.has_footer' => false]); //will update
This should get you started I think
Simple Example
Let's say user changes default colour from and input and submit the form. You do
public function updateTheme(Request $request) {
if ( $request->has('background_colour') && $request->background_colour != '' ) {
config(['templates.options.background_colour' => $request->background_colour]);
}
}

Yii2 show image in backend from frontend - settting alias

In my project I used an image cropper widget. I setup the widget, that it save in frontend/web/upload. But in backend I save the images to frontend too.
This is working perfect. Then i want to show the image on the backend, if its exist. And i want to reach the frontend.
Thats why i want to set my own aliases in params-local.php file.
But I using vhosts to my webpages and I want to set Aliases to them.
In Yii2 documentation i found an article from aliases, but it wont help me. I mean i tried to use but it wont work.
I tried this:
return [
'aliases' => [
'#front' => 'http://front.mypage.dev',
'#back' => 'http://back.mypage.dev',
],
];
And I also tried this aswell:
Yii::setAlias('#front', 'http://front.mypage.dev');
Yii::setAlias('#back', 'http://back.mypage.dev');
But when i try to echo Yii::getAlias('#front'); it sais
Invalid Parameter – yii\base\InvalidParamException
Invalid path alias: #front
Maybe someone has a solution for this?
Thanks a lot.
Add in backend/config/params.php like:
return [
'front' => 'http://front.mypage.dev',
'back' => 'http://back.mypage.dev',
];
and use it from:
Yii::$app->params['front']
Yii::$app->params['back']
Let me know your thought.
Try this:
Yii::setAlias('#front', 'http://front.mypage.dev');
Yii::setAlias('#back', 'http://back.mypage.dev');
echo Yii::getAlias('#front');
echo Yii::getAlias('#back');
echo Yii::getAlias('#frontend/path/to/file');
echo Yii::getAlias('#backend/path/to/file');
Yii2 Playground
setting-aliases-in-yii2-within-the-app-config-file

Moodle, upload and store files using moodle forms

I'm having some dificulties implementing a moodle upload mechanism using moodle forms. My goal is to let the user/administrator upload images, store them and access later in a block.
Currently, I have this in the form:
$mform->addElement('filemanager', 'attachments', 'Pic:', null, array('subdirs' => 0, 'maxfiles' => 1,'accepted_types' => '*' ));
and this to save the file:
if ($draftitemid = file_get_submitted_draft_itemid('attachments')) {
file_save_draft_area_files($draftitemid, $context->id, 'mod_assignment', 'attachments', 0, array('subdirs' => false, 'maxfiles' => 1));
}
and I try to access the file like this:
file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $context->id . '/mod_assignment/attachments')
I don't receive any errors but I can't access the file either. I'm using moodle 2.0.
Thanks in advance,
Take care
It sounds like you are looking to write a custom block, in which case you should be giving block_myblock as the component name instead of mod_assignment.
Each Moodle component which serves files needs to have its own function defined within lib.php to handle file requests. In your case that function wants to be called something like block_myblock_pluginfile().
A good example of this is block_html_pluginfile() which can be found in moodle/blocks/html/lib.php and does something very similar to what you are wanting.

In CakePHP, Why using HTML->link instead of manually writing an anchor text?

Isn't it much slower concerning development time ?
What are the advantages of of HTML->link ?
Thanks !
It's just a question of whether you want to generate your own URLs and hard-code them, or if you want Cake to do the work for you. For simple urls leading to the homepage of your site using cake may seem slower, but it's actually useful for dynamic urls, for example:
Say you're printing a table of items and you have a link for each item that deletes that item. You can easily create this using:
<?php
echo $this->Html->link(
'Delete',
array('controller' => 'recipes', 'action' => 'delete', $id),
array(),
"Are you sure you wish to delete this recipe?"
);
Notice how using an array specifying the controller and action as a URL allows you to be agnostic of any custom routes. This can have its advantages.
The corresponding way to do it without the HTML helper would be:
Delete
It can also be really useful for constructing URL query strings automatically. For example, you can do this in array format:
<?php
echo $this->Html->link('View image', array(
'controller' => 'images',
'action' => 'view',
1,
'?' => array('height' => 400, 'width' => 500))
);
That then outputs this line of HTML:
View image
It could be a pain to generate that URL manually.
In summary, while it may seem awkward for simple links, the HTML helper definitely has its uses. For further uses, consult the cakePHP book on the HTML helper's link function.

Categories