justb3a

Module: Image Extra

109 posts in this topic

10 hours ago, justb3a said:

One opportunity would be to use a `label` element if it isn't a multilingual site and a `strong` tag if it is one.  What do you think?

Sounds good, thanks.

10 hours ago, justb3a said:

The idea behind this was that some textformatter like "NewLineToBreak" or "NewLineToListItem" doesn't make that much sense applied to an one liner input element.

True, but the textformatter that I'm thinking of is HTML Entity Encoder, which is important for any text field to avoid ambiguous ampersands or other invalid HTML. The string could be manually encoded in the template but more convenient to set-and-forget with a textformatter. :)

Share this post


Link to post
Share on other sites

Hi,

Thanks so much - that makes sense... I've tried to combine the below in a lot of different ways but keep getting an error...

Any ideas?

Thanks

<?php
if ($image->caption){
    //Output markup 1
}
else {
    //Output markup 2
}
?>

<?foreach($page->images as $image) {
 $thumb = $image->width(1040); 
echo "<li><img src='$thumb->url' alt='$image->description'><p class='caption'><strong>{$image->imagetitle}</strong> <em>{$image->imagetext}</em> <span><br>{$image->role}</span></p></li>";}
?>

 

Edited by kongondo
Mod Note: Moved your question to this module's support forum

Share this post


Link to post
Share on other sites

hi!
thanks for this great module!

today I experienced a strange issue when using this module with the Video Fieldtype Module
I get the following error when uploading a video, when the image extra module is installed:

<br />
<b>Notice</b>:  Trying to get property of non-object in <b>/www/htdocs/w00dd152/projekte/jp-relaunch/site/modules/ImageExtra/ImageExtra.module</b> on line <b>722</b><br />
[{"error":false,"message":"Added file: portfolio_screencap_02.mp4","file":"\/jp-relaunch\/site\/assets\/files\/1162\/portfolio_screencap_02.mp4","size":3214711,"markup":"<li id='file_c17b44756649023a42ba014c5b29202c' class='InputfieldFile InputfieldImage InputfieldVideo ui-widget'>\n\t\t<p class='InputfieldFileInfo ui-widget ui-widget-header'>\n\t\t\t<span class='ui-icon ui-icon-arrowthick-2-n-s'><\/span>\n\t\t\t<span class='InputfieldFileName'>portfolio_screencap_02.mp4<\/span> \n\t\t\t<span class='InputfieldFileStats'>• 3,139 kB • <\/span> \n\t\t\t<label class='InputfieldFileDelete'><input type='checkbox' name='delete_video_repeater1162_c17b44756649023a42ba014c5b29202c' value='1' \/><span class='ui-icon ui-icon-trash'>Delete<\/span><\/label>\n\t\t\t<a class='InputfieldFileMove InputfieldFileMoveBottom' href='#'><span class='ui-icon ui-icon-arrowthickstop-1-s'><\/span><\/a> \n\t\t\t<a class='InputfieldFileMove InputfieldFileMoveTop' href='#'><span class='ui-icon ui-icon-arrowthickstop-1-n'><\/span><\/a> \n\t\t<\/p>\n\t\t\t<div class='InputfieldFileDescription'><label for='description_video_repeater1162_c17b44756649023a42ba014c5b29202c' class='detail'>Description<\/label><input type='text' name='description_video_repeater1162_c17b44756649023a42ba014c5b29202c' id='description_video_repeater1162_c17b44756649023a42ba014c5b29202c' value='' \/><\/div>\n\t\t<br \/><label class='InputfieldFileDescription'><span class='detail'>Subtitles<\/span>\n\t\t<br \/><br \/>In templates, you can access this subtitles file (portfolio_screencap_02.srt) using: <code>$page->video->eq(0)->subtitles<\/code><br \/>In templates you can access a formatted transcript (converted from subtitles entered in SRT format), by using: <code>$page->video->eq(0)->transcript<\/code>\n\t\t<br \/><br \/><textarea rows='10' name='subtitles_video_repeater1162_c17b44756649023a42ba014c5b29202c' \/><\/textarea>\n\t\t\t<input class='InputfieldFileSort' type='text' name='sort_video_repeater1162_c17b44756649023a42ba014c5b29202c' value='0' \/>\n\t\t<\/p><\/li>","replace":false,"overwrite":0}]

I testes this in PW 3.0 with the newest versions of both modules installed.
Not sure why its even interfering with the video field..
When I disable the image extra module, everything works fine.

Share this post


Link to post
Share on other sites

@jploch - I'd like to see a dump of $event after line 718 because $field is not an object and it should be.

That said, a quick fix might be to change the hook on line 97 to:

InputfieldImage::processInputFile

 

1 person likes this

Share this post


Link to post
Share on other sites
20 hours ago, adrian said:

@jploch - I'd like to see a dump of $event after line 718 because $field is not an object and it should be.

That said, a quick fix might be to change the hook on line 97 to:


InputfieldImage::processInputFile

 

Thx! this fixed it for me

1 person likes this

Share this post


Link to post
Share on other sites

@Jon E 

Just use the comparison inside the foreach loop:

foreach ($page->images as $image) {
  $caption = '';
  if ($image->imagetitle) {
    $caption = "<p class='caption'>{$image->imagetitle}</p>";
  }

  echo "<li><img src='{$image->width(1040)->url}' alt='{$image->description}'>$caption</li>";
}

Or if you want to combine multiple parts: you can check every extra field individually and concatenate the caption before outputting it.

foreach ($page->images as $image) {
  $caption = '';
  if ($image->imagetitle) $caption .= "<strong>{$image->imagetitle}</strong>";
  if ($image->imagetext) $caption .= "<em>{$image->imagetext}</em>";
  if ($image->role) $caption .= "<span>{$image->role}</span>";
  if ($caption) $caption = "<p class='caption'>$caption</p>";

  echo "<li><img src='{$image->width(1040)->url}' alt='{$image->description}'>$caption</li>";
}

 

1 person likes this

Share this post


Link to post
Share on other sites

New Version 1.0.4:

@Robin S  use label tag if it isn't a multilangual site

@jploch, @adrian changed hook InputfieldFile::processInputFile to InputfieldImage::processInputFile

5 people like this

Share this post


Link to post
Share on other sites

Hi there! And, as always, thanks for a perfect product!

Would like to discuss an interesting case. Let's suppose we have some images attached to different pages, each image having some extra fields including uid field which is unique. We have to build an api page which should receive requests like /api?uid=efv97yg and it should return some JSON about the image with that uid.

Is there any possibility to find an image by its extrafield value (e.g. uid)? Well, i know that we can do something like this:

$pages_ = $pages->find('template=page_with_fotos');
foreach($pages_ as $page_)
	{
	$images = $page_->images;
	foreach($images as $image)
		{
		if($image->uid !== $uid) continue;
		$json = json_encode($image);
		break;
		}
	}
echo $json;

But its not very elegant.

And even worse:

$sql = "select * from field_foto where uid=$uid";
$query = $database->prepare($sql);
$query->execute();
...

What is on my wishlist:

//pseudocode, will NOT work for sure!

$foto = $field_fotos->get("uid=$uid");
...

Will appreciate any advice. Thanks!

Share this post


Link to post
Share on other sites

Just used this module for adding a video link to images. There was a glitch that there was no indication on the thumbnails whether there is a link added or not, so I put together a small js/css combo to add an icon:

has-video.thumb.gif.6e88144313e59ece60e44535eb9dda44.gif

Here is the corresponding code - dirty but works :)

Spoiler

var fieldname = 'video_url_project_images';

function updateVideoItems() {

    $('.gridImage__hover.has-video').removeClass('has-video');

    $('input[id*="video_url_project_images"][value!=""]').each(function() {

        var $item = $(this),
            seekId = $item.attr('id').replace(fieldname, 'file'),
            $target = $('#' + seekId);

        if($target.length) {
            $target.find('.gridImage__hover').addClass('has-video');
        }
    });
}

$(document).ready(function() {
    updateVideoItems();
});

$(document).on('keyup change', 'input[id*="' + fieldname + '"]', function() {
    updateVideoItems();
});

.gridImage__hover.has-video .gridImage__inner::after {
    content: "";
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 30px;
    height: 30px;
    background: #333 url('/site/templates/images/icons/play-circle.svg') center center no-repeat;
    background-size: 30px;
    border-radius: 100%;
    border: 2px solid white;
    background-clip: content-box;
}

 

 

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bernhard
      Hi,
      just stumbled over a little module that i built for my last project. it helped me to test performance of my rockdatatables module to generate 3000 random json datasets and i want to share it with you. maybe it saves some time for someone.
      https://gitlab.com/baumrock/RockDummyData/
      easy example:
      $rdd = $modules->get('RockDummyData'); for($i=0; $i<15; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); echo date("d.m.Y H:i:s", $dummy->timestamp) . "<br>"; } more advanced:
      $json = new stdClass(); $json->data = array(); $rdd = $modules->get('RockDummyData'); for($i=0; $i<3000; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); $obj = new stdClass(); $obj->name = $dummy->forename . ' ' . $dummy->surname; $obj->position = $dummy->job; $obj->office = $dummy->city; $obj->color = $dummy->color; $obj->start_date = new stdClass(); $obj->start_date->display = date('d.m.Y',$dummy->timestamp); $obj->start_date->sort = $dummy->timestamp; $obj->salary = rand(0,10000); $json->data[] = $obj; } echo json_encode($json); you have to store your random datasets on your own into the /data folder. there are several services for creating all kinds of random data on the web - if you know one service that allows sharing those datasets let me know and i can include common needed data into the module
    • By AndySh
      Hello!
      I need your assistance please. I purchased the module FormBuilder. Unfortunately, the module discontinued delivering customer submissions to e-mail box specified in the module settings. Direct mailing to the e-mail box works OK. The module settings stays the same and are correct, like "Send e-mail to administrator(s) is checked. The last version of FormBuilder 3.0 has been installed. Please advise how to resolve the issue becase I cannot get orders from customers anymore (((
    • By kixe
      As described in this post (https://processwire.com/talk/topic/8551-custom-urls-for-pages/?p=82742) the option 'Name Format Children' under the tab 'Family' in template settings doesn't work properly and also not as expected. I had a look inside the code and made some changes which are working properly, which offers much more options, more consistency and less code too.

      The result is the following. You have 3 Options for generating name and title, which could be combined in endless variations.
      Name is always derived from title, same like creating pages manually.
      type date: if function detects # character anywhere in the string, conversion will be: deletion of # and string will be used as format parameter for PHP date() function type field: if string is a fieldname of the parent page the value of this field will be used type string: if string doesn't fit to the 2 preceeding it will be taken as it is All parts (separated by comma) will be composed in the order of setting. You can use unlimited numbers of parts

      I made a pull request on github: https://github.com/ryancramerdesign/ProcessWire/pull/831

      Example screenshots

      Setting ...


      will result in


       
    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
       
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend