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

I noticed that ItemManager automatically creates thumbnails inside data/uploads/imanager/x.y/thumbnail/

How can I access the thumbnail pictures url when doing a foreach ?

$imanager = imanager();
$itemMapper = $imanager->getItemMapper();
$itemMapper->init(4);   //  Category 4 holds the pictures as item with id 1
$items = $itemMapper->items;

foreach($items as $item) {
$picture = $item->fields->image->fullurl;
$description = $item->fields->image->title;
$thumb-url = ??
you can create any thumbnails you want with IM. There I showed you a function, that lets you create thumbnails in any sizes you want. Try it.

I want to select an item that holds 5 photos
Then I want to do a for each loop to store from the image field the fullurl and title in the variables $url and $title
that I can use to echo html.

Is it possible to do this with only 1 for each loop ?

The following for each loop does not put the fullurl and title in the variables:

$imanager = imanager();
$itemMapper = $imanager->getItemMapper();
$itemMapper->init(4);   //  Category 4 holds the item pictures with 5 photos
$items = $itemMapper->items;
$my_item = $itemMapper->getItem('name= pictures');

foreach ($my_item->fields->image as $picture) {
$url = $picture->fullurl;
$title = $picture->title;

echo "<a href=" . '"' . IM_SITE_URL . $url . '"' . " data-imagelightbox=" . '"g"' . " data-ilb2-caption=" . $title . ">" . "\n";
echo "<img src=" . '"' . IM_SITE_URL . $url . '"' . " width=" . '"100"' . ">" . "</a>" . "\n";


How can I do this with one for each loop ?

Do I need to use a separate for-each loop to get each field property ?
(2020-04-30, 06:08:28)Felix Wrote: [ rel="nofollow" -> ]How can I do this with one for each loop ?

Do I need to use a separate for-each loop to get each field property ?

Hmm... I see only one foreach in your example?

Like this, perhaps:

PHP Code:
foreach ($my_item->fields->image->fullurl as $key => $fullurl
   $url IM_SITE_URL.$fullurl;
   $title $my_item->fields->image->title[$key];

   echo "<a href='$url' data-imagelightbox='g' data-ilb2-caption='$title'><img src='$url' width='100'></a>";

Hi Bigin,

First of all, thanks for pointing me to the use of $key in foreach loops
I can confirm that the following code now is working:

$imanager = imanager();
$itemMapper = $imanager->getItemMapper();
$itemMapper->init(4);   //  Category 4 holds the item pictures with 5 photos
$items = $itemMapper->items;
$my_item = $itemMapper->getItem('name= pictures');
foreach ($my_item->fields->image->fullurl as $key => $fullurl) {
$url = IM_SITE_URL.$fullurl;
$title = $my_item->fields->image->title[$key];
echo "<a href='$url' data-imagelightbox='g' data-ilb2-caption='$title'>"."\n";
echo "<img src='$url' width='100'></a>"."\n";

Outputting html for galleries, sliders, banners, etc. in websites is asked for a lot
so having a foreach loop doing that in ImManager is very practical.

$my_item must be some kind of array in ImManager.
Are there other ways to loop through and output the array elements ?

This is what I have found so far:

echo "<br>";
echo key($my_item)."<br>";  // outputs: categoryid
echo key($my_item->fields)."<br>"; // outputs: text (this is a text field setup in category 4)
echo key($my_item->fields->image->title)."<br>";  // outputs: 0

your "$my_item" variable is an object of type Item, not an array. What is the point of outputting all Item object properties? Especially since they are always the same for each Item of that category type and only the values differ? Would you please explain what you're trying to accomplish so I may better help you?

If you just want to see how your item object is structured you can easily check it using the Util::preformat($my_item) function.
Quote:Would you please explain what you're trying to accomplish so I may better help you?

Your help with ImManager is very complete, thanks again for that.

But maybe a little history will be on it's place.
I come from a different cms with a powerful but over-engineered api with mysql as a database.
Since I discovered that with xml a website is much, much faster I switched to the GS cms.
Also the use of xml apps or plugins such as ImManager keeps everything modular.
You only install what is needed for a website and keep everything else out.
But I still have to get used to the differences in api usage.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Yes the use of Util::preformat($my_item);
is very good for debugging and see what is possible to accomplish
I have added it to my tool box !

In one of the items I am using a WYSIWYG field with the name description
and use this to output the contents on the front:

echo $my_item->fields->description->value;

It's working ok with only text in the WYSIWYG editor, but as soon as I insert an image
the image does not show up on the front.

The image shows up correctly inside the WYSIWYG editor with this url:

<p><img alt="" src="http://localhost/items/data/uploads/my-company.png" style="float: left; width: 243px; height: 200px;" /></p>

But on the front the url shows up like is:


Any idea why the url on the front is wrong ?
Hi Felix,

are you sure it's the URL that messed up? Did you have a look at the URL in "Source View" (not browser console!)?
As far as I remember there was a problem formatting "double quotes" from WYSIWYG.

If it is the double quotes that are causing the problems, you can solve it with the html_entity_decode():
Hi Bigin,

Thanks for your reply. You are right about the double quotes.

When I checked on View Page Source the double quotes were replaced by:

& # 3 4  (without the spaces between the characters as this post will convert it back to ")

using html_entity_decode($my_item->fields->description->value); did solve it !

Hello Bigin,

The ItemManager plugin is working perfectly when I use it only
from the GS backend under the tab Manager.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

However I seem to have a problem using ItemManager from the pages
in the GS backend.

When I select a page in the GS backend and then go to options
there is an option to select a Category. When I select a Category
I can see the fields of that Category.

Then I enter, for example, in the Text field some text
and click on Save.

Then when I go back to the Tab Manager I can see that a new item
has been added to the Catecory. The new item has been given a name
like: 3052675811

However when I try to output the text from this item
there is no output.

$itemMapper->init(6);   //  Category 6 holds the item 3052675811
$items = $itemMapper->items;
$this_item = $itemMapper->getItem('name=3052675811');

<?php echo ($this_item->fields->text->value); ?>

Also when I try to delete this item there is an error message
that says: "Item does not exist"

What am I doing wrong ?

I have no idea. I can't reproduce it. Everything works for me.

Maybe you get messed up saving it? Did you tried to select the item by its id?
PHP Code:
$item $itemMapper->getItem(3052675811); 

By the way, you can also select your item by page slugs:
PHP Code:
$item $itemMapper->getItem(
Hi Bigin,

Thanks for your reply. Yes when I use 2147483647 then it is working:

$this_item = $itemMapper->getItem('2147483647');
<?php echo html_entity_decode($this_item->fields->editor->value); ?>

- - - - - - - - - - - - - - - - - - - - - - - - - - -

However, when I go back to the page and want to add
some more text to the field and click on Save,
the following error shows up:

Error: & # 6 0 ; div & # 6 2 ;Error saving item & # 6 0 ; /div & # 6 2;.

Error: <div >Error saving item</div>.

- - - - - - - - - - - - - - - - - - - - - - - - - - -

When I go back to the tab Manager and check there the item
I see that:

pos = 2147483647
name = 3052675811

When I click on 3052675811 I see that the id = 2147483647
hmm. no idea. It may be that the ID no longer matches the page name?
When using the IM Extra Pages, you should decide on its editing method.
Quote:When using the IM Extra Pages, you should decide on its editing method.

Hi Bigin,

Thanks for your reply

What do you mean by "you should decide on it's editing method ?
I mean: prefer the editing of items inside "Extra Pages" interface instead of the editing with IM. Otherwise there is the potential to mess up something and accidentally overwrite the item name.
Hi Bigin

Good news

I reinstalled everything and this time I did choose another page and another category,
and now everything is working correctly. Not sure what the problem was.

Thanks for all the help.

Now I am ready to start building with ItemManager.
I want to build a GS theme with the content driven
by ItemManager and upload to the GS repository.
I will post back on this.
Great, have fun! ;-)

When I deactivate the plugins ItemManager and IM Extra Fields,
then logically
<?php echo html_entity_decode($home_item->fields->editor->value); ?>
does not output anything anymore

but GS page content
<?php get_page_content(); ?>
does also stop to output content

When I activate again the plugins ItemManager and IM Extra Fields,
then also
<?php get_page_content(); ?>
outputs again it's content

How is this possible ?

<?php get_page_content(); ?>
should work independent from the ItemManager plugin

When I deactivate the plugins ItemManager and IM Extra Fields,
remove this code on the template file:

$imanager = imanager();
$itemMapper = $imanager->getItemMapper();
// Loading content for the home page
$itemMapper->init(1);   //  1 is the home-category and holds the home-item
$items = $itemMapper->items;
$home_item = $itemMapper->getItem('name=home-item');

<?php get_page_content(); ?>
outputs again it's content

Is this normal behaviour ?
Hi Felix,

this has absolutely no relation to the get_page_content() function.
It's quite simple, if the ItemManager is disabled, your code above will cause an error, since you turned off error reporting in gsconfig.php you won't get it visible.

It is therefore highly recommended to enable error reporting during code development, and if you are programming procedurally, it is always preferable to use the function_exists() to wrap your ItemManager code:

PHP Code:
if(function_exists('imanager')) {
// ... your IM code 

Hi Bigin,

Yes you are right: I should have turned on DEBUG Mode !
and so I did.

Yep, an error message popped up $imanager = imanager() is undefined on line ...
wich makes sense when I have the ItemManager plugins disabled.

And so on turn when I deleted all ItemManager code in my template
so did the error message disappear and <?php get_page_content(); ?>
started to work again. I guess I created some unnecessary fuzz.
It all makes sense.
I stopped writing ItemManager code in my website page template files.
Instead I am writing ItemManager code as a php function()
in the functions.php file

Like I did for this Gallery:

function photobox() {

if (return_page_slug()=='basic') {
$imanager = imanager();
$itemMapper = $imanager->getItemMapper();
// Loading the photobox-category
$itemMapper->init(8);   //  Category 8 is the photobox-category and holds the items photobox-images and photobox-scripts
$items = $itemMapper->items;
$photobox_scripts = $itemMapper->getItem('name=photobox-scripts');
$photobox_images = $itemMapper->getItem('name=photobox-images');
// output the css for the photobox gallery
echo '<link href="' . IM_SITE_URL.($photobox_scripts->fields->files->fullurl[0]) . '" rel="stylesheet">' . "\n"; // photobox.css
echo '<link href="' . IM_SITE_URL.($photobox_scripts->fields->files->fullurl[1]) . '" rel="stylesheet">' . "\n"; // style.css for the thumbs
// set container <div> with id="gallery" class="box-thumb" before starting the foreach loop
echo '<div id="gallery" class="box-thumb">' . "\n";
// Looping through item $photobox_images with [$key] as automatic array counter;
foreach ($photobox_images->fields->files->fullurl as $key => $fullurl) {
$url = IM_SITE_URL.$fullurl;
$title = $photobox_images->fields->files->title[$key];
// output the html for the photobox gallery
echo '<a href="' . $url . '"><img src="' . $url . '" width="100" title="' . $title . '"></a>' . "\n";
// set closing container </div> after the foreach loop
echo '</div>' . "\n";
// output the necessary javascript for the photobox gallery
echo '<script src="' . IM_SITE_URL.($photobox_scripts->fields->files->fullurl[2]) . '"></script>' . "\n"; // jquery-1.7.min.js
echo '<script src="' . IM_SITE_URL.($photobox_scripts->fields->files->fullurl[3]) . '"></script>' . "\n"; // jquery.photobox.js
echo '<script src="' . IM_SITE_URL.($photobox_scripts->fields->files->fullurl[4]) . '"></script>' . "\n"; // parameters.js

Now, with a simple <?php photobox(); ?> in a page template file I can make this Gallery popup
anywhere I want - this is great Smile

Also this way contributes to better separation of code and html layout
(2020-05-13, 21:24:23)Felix Wrote: [ rel="nofollow" -> ]Also this way contributes to better separation of code and html layout

Yes, that's good idea. It was a good decision to try to separate the markup from the logic! You can even improve it by letting ItemManager render the markup, so you can focus completely on the script logic...

The only thing I notice now is that you add your CSS directly into the <body>, which might not be optimal because they should be in the <head> area.

It would be even better if you use GetSimple native functions like "get_header()", "get_page_content()" and "get_footer()" to integrate your script into the CMS.
It is also a better option to use "SimpleItem" objects instead of "Item" objects, because the execution time would be even faster. It is also recommended to physically resize the images, i.e. use the thumbnails and load the large images on demand.

Here I have written an example how you can do it (I think it should be compatible with your script):

The example above contains only 3 functions that you can add to your "functions.php" file, note that your template must contain "get_header()", "get_page_content()" and "get_footer()" methods.

1. The function "getTemplate()" retrieves your markup and can be customized. It contains variables like [[URL]], [[CONTENT]] etc, which are replaced with values.
2. The function "getResizedUrl()" takes care of creating the thumbnails.
3. And the function "photobox()" contains the logic.

The funny part is that the script works like a plugin, but is not really one.

Try it out, take it apart, maybe you'll find something useful there. Have fun! ;-)
Hi Bigin,

First of, thanks for writing the example code on github. Splitting it up in 3 functions
makes it good example code to learn better use of both ItemManager and GS.
The function "getTemplate" is very interesting.
I still don't grasp yet all possible api.

I have read in the forum about the GS methods "get_header()", "get_page_content()", "get_footer()"
but have only used so far "get_page_content()".

Yes I know that css should be called in the <head> aread and the javascript just before </body>
but not all picture galleries out there respect that. Some of them only seem to work
with the js directly called after the gallery html.

I have read about SimpleItem but not used it yet. Will update my themes with it.

Also I am glad to have found and want to start using PHPThumb:

I have seen that ItemManager automatically creates thumbnails in:
/data/uploads/imanager/x.y/thumbnail/ with size 133x100

Is there a way in ItemManager to change the 133x100 values ?

Pages: 1 2 3 4 5 6 7 8 9 10 11 12