GetSimple Support Forum

Full Version: ItemManager 2.0
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12
Hi Bigin,

Does the ItemManager-3 api have a way to access the thumbnail pictures ?

I get stuck at $item->path . 'thumbnail/';
how to go from there in a for each loop ?

Possible workarounds with php:

$var = GSROOTPATH . 'framework/data/uploads/1.1.1/thumbnail/';
$thumbs = array_diff(scandir($var), array('.', '..'));

Is there more information about $image->resize ? e.g. null, "adaptiveResize" ?

It looks that it auto generates thumbs in the thumbnail directory with size values you give to resize.
I am one step further with access to the thumbnail directory.

$image->resize(150, 112) creates in the thumbnail directory automatically thumbs, width=150px and height=112px
from the gallery pictures and makes them accessible at the same time. That is really neat done inside ItemManager.

So now I have:

Code:
foreach($item->images as $key => $image) {
if(!$image->name) { continue; }
echo '<div>';
echo '<h1></h1>';
echo '<a href="' . get_site_url(false) . 'framework/' . $image->url . '" rel="group_1" title="'.$image->title.'">
<img src="' . get_site_url(false) . 'framework/'.$image->resize(150, 112).'"  alt=""></a>';
echo '</div>';
}

Which works nice.
Hello Felix,

(2020-08-18, 03:10:33)Felix Wrote: [ rel="nofollow" -> ]Which works nice.

Fantastic. Here's some more information about the `FileuploadFieldValue::resize()` method. It returns a URL (string) to the image sized/cropped to the specified dimension. Width and height of the target size are the the first and second arguments. With the third parameter you can define the quality of the image (deprecated) – set it to null (instead, you can specify the quality of the image with options).

Code:
$image->resize(100, 200, null, ...

The fourth parameter $type determines the type of function to be used. By default it is 'resize', allowed also 'resizePercent', 'adaptiveResize', 'cropFromCenter', 'crop', 'rotateImage'.

The 5th parameter is an array of GD options:

Code:
$options = [
     'resizeUp'              => false,
     'jpegQuality'           => 100,
     'pngQuality'            => 1,
     'correctPermissions'    => false,
     'preserveAlpha'         => true,
     'alphaMaskColor'        => array (255, 255, 255),
     'preserveTransparency'  => true,
     'transparencyMaskColor' => array (0, 0, 0)
]
Hi Bigin,

The picture tuto example works very well.
But what I want is just a backend.php to add and delete pictures, without the login.php and the functions.php

It works as long as I have this single backend.php and the framework folder both in the root of GS.

Without the login.php and functions.php this is my working backend.php:

Code:
<?php

include 'framework/imanager.php';
$gallery = $imanager->getCategory('name=Gallery');
$timestamp = time();
$item = $gallery->getItem(1);
if(!$item) {
   $item = new \Imanager\Item($gallery->id);
}


   if($imanager->input->post->action == 'save') {
       // It is a New Item, before you can save the images you
       // should always save the item itself first, because it
       // should create the directories and the important ID's first.
       $item->save();
       $dataSent = array(
           'file' => $imanager->input->post->position_images,
           'title' => $imanager->input->post->title_images,
           'timestamp' => $imanager->input->get->timestamp
       );
       // Set input value
       if($item->set('images', $dataSent)) {
           $item->save();
       } else {
           echo 'Error: The field value could not be set';
       }
   }

?>
<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="utf-8">
   <title>Backend</title>
   <meta name="description" content="Just a simple login Form">
   <!-- Mobile-friendly viewport -->
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <link rel="stylesheet"
         href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
   <meta name="author" content="J.E">
</head>
<body>
<main role="main">
<?php
$imanager->fieldMapper->init($gallery->id, true);
$field = $gallery->getField('name=images');
$widget = new \Imanager\FieldFileupload();

echo '<form action="./test.php" method="post">';

$widget->set('url', 'framework/');
$widget->set('action', "framework/imanager/upload/server/php/index.php");
$widget->set('id', $field->name);
$widget->set('categoryid', $field->categoryid);
$widget->set('itemid', isset($item->id) ? $item->id : null);
$widget->set('timestamp', $timestamp);
$widget->set('fieldid', $field->id);
$widget->set('configs', $field->configs, false);
$widget->set('name', $field->name);

echo $widget->render();

echo '<input type="hidden" name="action" value="save">';
echo '<button type="submit">Save</button>';
echo '</form>';
?>
</main>
<footer role="contentinfo">
   <small>Copyright &copy;
       <time datetime="<?php echo date('Y'); ?>"><?php echo date('Y'); ?></time> Ehret Studio</small>
</footer>
<script src="js/jquery-1.12.4.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<?php echo $widget->renderJsBlock(); ?>
<?php echo $widget->renderJsLibs(); ?>
</body>
</html>

So far so good.

But it goes wrong when I move the backend.php out of the GS root, to the folder root/test/
So when I have the backend.php inside: /test/backend.php
in backend.php I adapt include 'framework/imanager.php'; to => include '../framework/imanager.php';
But this doesn't seem to work correctly.

When I move the folder framework also to root/test/ then it starts to work again correct.

But I want the folder framework to stay in the root and only move the backend.php
to another location inside GS.

For example I would like to create a page inside GS with the name backend and assign a template file to it with the name backend.php. This template file would hold the backend php code and the page backend would only be accessible with http://domain.com/backend/ for as long as I need to add or delete pictures.

What am I doing wrong ?
It seems that adapting include 'framework/imanager.php'; to the new location is not enough.
Ok, one step further in the proces.

Of course I have to remove backend.php from the form action, since this action is already in the backend.php template file
and not in a separate backend.php file.

So after changing this line:
echo '<form action="./backend.php" method="post">';

into this:
echo '<form action="" method="post">';

It is now working locally with Laragon. Haven't tested this yet online.
==================================================

Despite that it is working now locally, how does it find the location of the framework folder ?

include 'framework/imanager.php'; this is a relative path,
but the folder framework does not exist relative to the backend.php template file,
it is in the root of GS.

So I guess the ItemManager-3 api takes care of this ?
But how ?
Hello Felix,

let's take it from the top:

(2020-08-24, 05:51:41)Felix Wrote: [ rel="nofollow" -> ]So when I have the backend.php inside: /test/backend.php
in backend.php I adapt include 'framework/imanager.php'; to => include '../framework/imanager.php';
But this doesn't seem to work correctly.

Why? Do you get an error message that the file was not found? Or what makes you believe that the include doesn't work?
This is my test:
Code:
root/
    application/
        index.php
    framework/
        imanager.php
    ...

index.php:
PHP Code:
<?php

use Imanager\Util;

include 
'../framework/imanager.php';
Util::preformat($imanager->config);

exit; 

I get the output, so the include seems to work.

But, maybe you mean that your upload does not work?

Notice right at the start: The Upload Processor requires a login, the session 'loggedin' must be set for the upload to succeed.
Also note that an upload without registration is an extremely dangerous thing. I would never allow it, instead I would use a service (API) specialized for it, but that' s your stuff...

Ok, let's test it.
Same dir structure:
Code:
root/
    application/
        index.php
    framework/
        imanager.php
    ...

index.php: https://gist.github.com/bigin/abbebba6ae...ebecb2259a

Everything works.

FYI: The upload is using Ajax, you can see the errors in your log file under: /framework/data/logs/imlog_2020*.txt

(2020-08-24, 16:07:20)Felix Wrote: [ rel="nofollow" -> ]Despite that it is working now locally, how does it find the location of the framework folder ?

include 'framework/imanager.php'; this is a relative path,
but the folder framework does not exist relative to the backend.php template file, it is in the root of GS.

The imanager.php file is responsible for this. This file is always located one layer above the imanager/ folder ;-)
PS File upload is extremely tricky, it can cause a lot of problems.
Instead of opening the door to your server/webspace to unauthorized users, you might want to use imgur.com service to enable image upload in your application. By the way, it is free https://apidocs.imgur.com
Hi Bigin,
Ok so session (login) is hard coded in ItemManager-3 !
Real Thanks for uploading, that example code was exactly what I was missing.
Now I have ItemManager content editing work both locally and online.
=================================================
Editing my own ItemManager contents this way goes faster without login overhead.
To avoid any riscs, I simply delete the backend.php template file after editing.
I setup ItemManger Login for end users and client websites.
=================================================
My backend.php template file is in the GS theme folder, so the ItemManager-3 framework folder is 2 levels up.
My local Laragon project folder is project6, so the path to the framework folder is:
C:/laragon/www/project6/framework/
So inside my backend.php the include should be:
include ($_SERVER['DOCUMENT_ROOT'].'/project6/framework/imanager.php');
But inside my backend.php the include seems to work with:
include 'framework/imanager.php';
Quote:The imanager.php file is responsible for this. This file is always located one layer above the imanager/ folder ;-)
I am still something missing about this.

The item drag and drop position graphic (fa fa-hand-o-up) is borrowed from font-awsome.
Is it possible to replace this graphic with a custom one in the ItemManger-3 code ?
About imgur, it would be great to make an own image share with ItemManager-3
You can build your path as you like, just keep it dynamic, it might save you a lot of work later when migrating to another environment.
Let's say your "framework" directory is located in:

Code:
/var/www/project6/framework/imanager.php

And the file representing the entry point for your application is located:

Code:
/var/www/project6/GetSimple/site/theme/whatever/backend.php

PHP Code:
// PHP 7 +
var_dumpdirname(__DIR__4) );
// < PHP 7
var_dumpdirname(dirname(dirname(dirname(__DIR__)))) );
// Or
var_dumprealpath('../../../../'));
... 


Sure, with ItemManager you can set your own templates and completely customize the look of your application.
Default file upload template can be found at: "/imanager/tpls/fields/fileupload.tpl"
PHP Code:
// to build a custom template from a file use
$tpl $this->imanager->templateParser->render(
 
      file_get_contents('path/to-your/templates/fileupload.tpl'), [
 
            'YOUR_VAR' => 'Value',
 
            'YOUR_VAR_2' => 'Value-2',
 
      ]
 ); 
PHP Code:
// finally, you can pass your template to the field widget as following:
$widget->set('fileUploadTpl'$tplfalse); 

See also Scriptor CMS. Scriptor is completely based on ItemManager and does not use the Font Awesome lib anymore, so its fields look completely different: https://scriptor-cms.info/documentation/...n/content/
Pages: 1 2 3 4 5 6 7 8 9 10 11 12