NAME

Slovo::Controller::Role::Stranica - common methods for Stranici and Celini

METHODS

In this role are implemented the following shared methods.

around execute

Wrapper around methods "execute" in Slovo::Controller::Stranici and "execute" in Slovo::Controller::Celini. Most of the work for constructing the page is done here so for Slovo::Controller::Stranici is left only to render everything put by this wrapper into stash. Slovo::Controller::Celini in addition has to find the specific celina to render.

To the wrapped methods are passed the parameters $page, $user, $language, $preview. $page is the current page with the заглавѥ celina in the current $ѩꙁыкъ. $user is the current user. $language is the current $ѩꙁыкъ. $preview is a boolean value - true if the current request is just a preview. In preview mode permissions and published columns of the records in the database are not respected.

Beside constructing the page, if there is a cached page or celina with the requested url path, it is simply slurped and rendered, but only for non autheticated users.

After the rendering is done by the consuming classes, the constructed response body is cached and saved on disk. On the next request by a guest user it is simply rendered, as mentioned above.

Returns the result of $c->render().

around remove

around update

In case a celina or a stranica is updated or removed, all cached pages on disk are deleted. This may feell like small slowdown if you have thousands of cached pages.

b64_images_to_files

$c->b64_images_to_files('foo');

Cleans up a parameter from base64 images and updates it with path to extracted images.

Expects that the value of the form parameter with name 'foo' is a HTML string. Scans it for img tags wich contain base64 encoded image in their src attribute. Decodes the encoded values and saves them in files in the specific domain public directory. The files are named after the alias of the record + count. Example (Second image in the body of a celina record with alias 'hello'): hello-01.png. Puts the URL path to the newly created file into the src attribute (e.g. /img/hello-01.png). The <src> attributes of the images are replaced with the paths to the newly created files.

is_item_editable

Checks the ownership and permissions of a content item. Returns true if this page or content is editable by the current user.

% if ($c->is_item_editable($p)) {
<li>
    <%= link_to
    url_for(edit_stranici => {id => $p->{id}})
    ->query([language=>$p->{language}]) => (title => 'Промѣна'),
    begin %><i class="fas fa-edit"></i> Промѣна<% end %>
</li>
% }

SEE ALSO

Slovo::Controller::Celini, Slovo::Controller::Stranici