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 title celina in the current language. $user is the current user. $language is $c-language>. $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 containing HTML from base64 images and updates it with paths to extracted images' sources.

Expects that the value of the form parameter with name 'foo' is a HTML string. Scans it for img tags which contain base64 encoded image in their src attribute. Decodes the encoded values and saves them in files in the specific domain public directory.

To ensure unique filenames, the files are named after the following algorithm: first 6 symbols of the sha1_sum of the base64 string, current gmtime in format %Y%m%d%H%M%S and count of the image in the HTML string with dashes in between. Example (Second image in the body of a celina record): 7e556c-20211115225521-02.gif. Puts the URL path to the newly created file into the src attribute (e.g. /img/7e556c-20211115225521-02.gif). The src attributes of the images are replaced with the paths to the newly created files.

Returns void.

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