Jump to content

a-ok

Members
  • Posts

    812
  • Joined

  • Last visited

Posts posted by a-ok

  1. Is it possible to run PW from an IP address before pointing the domain name at the server? The front end seems to be working okay but when I try to log in it just refreshes the page... is it possible to run it from an IP address (added to config as host too).

  2. I managed to work this out by doing the following... might be useful for others.

    function eSubmissionImageToRepeater($event) {
    
    	$page = $event->arguments(0);
    
    	if ($page->template->name == 'events-detail') { // What's On detail
    
    		if (count($page->flexible_content) <= 1 && $page->flexible_content->first()->type == 'text') {
    
    			$featuredImage = $page->featured_image->first();
    
    			$flexibleContentRepeater = $page->flexible_content->getNew();
    			$flexibleContentRepeater->of(false);
    			$flexibleContentRepeater->save();
    			$flexibleContentRepeater->repeater_matrix_type = 2; // Image(s)
    			$flexibleContentRepeater->save();
    			$flexibleContentRepeater->flexible_content_images->add($featuredImage->httpUrl);
    			$flexibleContentRepeater->save();
    
    			$flexibleContentRepeaterID = $flexibleContentRepeater->parent_id;
    			$firstItem = $event->pages->find("parent_id=$flexibleContentRepeaterID")->first();
    			$lastItem = $event->pages->find("parent_id=$flexibleContentRepeaterID")->last();
    			$event->pages->insertBefore($lastItem, $firstItem);
    
    		}
    
    	}
    
    }
    
    if ($user->hasRole('e-submission')) { // Ony required for 'e-submissions'
    	$wire->addHookAfter("Pages::save", null, "eSubmissionImageToRepeater");
    }

     

  3. Anyone got any other ideas?

    This seems to work:

    $flexibleContentRepeater->flexible_content_images->add("https://i.stack.imgur.com/bn9pu.png");

    But this doesn't (bd'ing $page->featured_image->httpUrl returns the correct full URL...)

    $flexibleContentRepeater->flexible_content_images->add($page->featured_image->httpUrl);

    EDIT

    I think it's due to the ->op(false) which makes the featured_image field an array and thus this works...

    $featuredImage = $page->featured_image->first();

     

  4. 7 hours ago, elabx said:

    Try  setting the output formatting  for the $flexibleContentRepeater repeater matrix item (which is a page!)

    
     $flexibleContentRepeater->of(false);
    

    I also think you shouldn't be saving the page inside the hook:

     

     

    Thanks! I think you're right re saving the page... I've removed that. The output formatting addition hasn't solved this though; still a blank image field.

    Hmm...

  5. Hi folks,

    I'm wanting to take an Image field and add the same image as the first row of a RepeaterMatrix field. If RepeaterField field rows already exist, it should shift it to the first row, and if the image has already been added then it shouldn't re-add it. I guess I could double check the image URL on this to prevent this?

    Anyway, I thought this would work... it's adding in a RepeaterMatrix row of the requested type but the image isn't being added.

    function eSubmissionImageToRepeater($event) {
    
        $page = $event->arguments(0);
        if ($page->template->name == 'events-detail') { // What's On detail
    
            $flexibleContentRepeater = $page->flexible_content->getNew();
            $flexibleContentRepeater->save();
            $flexibleContentRepeater->repeater_matrix_type = 2;
            $flexibleContentRepeater->save();
            $flexibleContentRepeater->flexible_content_images->add($page->featured_image->httpUrl);
            $flexibleContentRepeater->flexible_content_images->save();
            $flexibleContentRepeater->save();
    
            $page->save();
    
        }
    
    }
    $wire->addHookAfter("Pages::save", null, "eSubmissionImageToRepeater");

    Any help?

  6. Hi folks,

    I have a contributors specific role set up on PW which allows them to add and edit only their own page(s) to a parent page (Events > event) and have managed to do this by setting up specific template permissions but also include the following in my ready.php file (so they only see their own pages)

    function eSubmissionPermissions($event) {
    
    	$page = $event->object;
    	if (!$event->return) return;
    	if ($page->template->name == "events-detail" && $event->user->id !== $page->createdUser->id) {
    		$event->return = false;
    	} else {
    		$event->return = true;
    	}
    
    }
    if ($user->hasRole('e-submission')) { // Ony required for 'e-submissions'
    	$wire->addHookAfter("Page::listable", null, "eSubmissionPermissions");
    }

    This all works fine but there's one issue. I have a RepeaterMatrix set up for flexible content and the user/role can add to this fine if the content is text but when they go to add an image it states 'You don't have access to edit' when adding the image. Is there anything extra I should be doing in order to allow this? They can add an image fine that isn't in the RepeaterMatrix. I am using PW 3.0.80. It's also maybe worth noting that I am not allowing this user to publish pages (only save them) as this will be done by the admin on successful admission.

    Screen Shot 2018-03-27 at 11.16.03.png

    Screen Shot 2018-03-27 at 11.19.26.png

    Screen Shot 2018-03-27 at 11.20.00.png

  7. 3 minutes ago, elabx said:

    Don't think this is possible because Table field uses it's own schema and adds a database column per table column, so changing it in the field would change it to all fields it is instantiated.  The quickest idea I have to hack around this is to use RuntimeMarkup field and render your custom inputfield using jQuery datatables or something simliar and save it's data in a hidden text field).

    Hmm it's okay actually because I can just use the first row as the thead and then the rest can follow and I can style the first row accordingly.

    However upon adding the table to a repeater, when I try to add a row... it doesn't work. It's hashed in the URL when clicking so I'm guessing some JS isn't firing/is missing because it's in a repeater?

  8. I'm looking at using ProFields Table for a specific layout. An attached image as an example. The client should be able to add as many tables as they want, and as many table rows with the option to change the thead titles.

    My thought was to put a table in a repeater field and then use ProFields Table. This is generally okay but the only issue is that the table headers (theads) aren't fixed and need to be changed also. Any thoughts on changing the text for these?

    Thanks!

  9. 58 minutes ago, kongondo said:

    You basically have two choices

    1. Convert the PageArray into a regular array OR
    2. Convert the social media array into a WireArray (e.g. each to be a WireData which you throw into one WireArray)

    #2 will give you the advantage of easily sorting by your custom date field. I am not sure though if a WireArray can be combined with a PageArray just like that (although the latter is from a WireArray, so, yeah, maybe it is possible).

    Edit:

    Depending on your operations and size of the PageArray, since Page objects can be big, to have the best of both worlds (1 and 2), you can use explode as per @Zeka's suggestion, but convert that into a WireArray. Then, convert your social media array into a WireArray and add it to the first WireArray. You can then do your sorting by the custom date field. I don't know how much this will cost you in server resources though. Just a thought...

    Thanks for this. I didn't know you convert it into a WireArray tbh. This is what I currently have, which seems okay, but when I come to thinking about pagination... not sure how that'll work (so maybe WireArray is best if I can work it out). I haven't included my Instagram API fetch stuff here... just the variable.

    $news = $pages->find('parent=/news/, sort=-created, limit=16')->explode(['id', 'created', 'title', 'url', 'images', 'summary_text']);
    $instagrams = $instagram->getInstagramRecent();
    
    $items = array_merge($news, $instagrams['data']);
    
    bd($items);
    
    foreach ($items as $key => $item) {
    
    	if (isset($item['user']['id']) && $item['user']['id'] == '1907645821') { // Instagram post
    		$sort[$key] = $item['caption']['created_time'];
    	} else { // News article
    		$sort[$key] = $item['created'];
    	}
    }
    
    array_multisort($sort, SORT_DESC, $items);
    
    bd($items);
    
    if (isset($item['user']['id']) && $item['user']['id'] == '1907645821') { // Instagram post
    	$type = 'Instagram';
    	$title = NULL;
    	$image = $item['images']['standard_resolution']['url'];
    	$text = '<p class="instagram">' . $item['caption']['text'] . '</p>';
    	$link = $item['link'];
    
    } else { // News article
    	$type = 'News';
    	$title = $item['title'];
    	foreach($item['images'] as $img) {
    		$itemImage = $img->url;
    		break;
    	}
    	$image = $itemImage;
    	$text = $item['summary_text'];
    	$link = $item['url'];
    }
    

     

  10. Is it possible to combine a pageArray with a regular PHP array? I'm returning a list of news items from PW, which is fine, but I'm also returning Instagram and Twitter posts, from API endpoint URLs (which is JSON but I have converted to PHP arrays) and I'd like to then ultimately import them all into one big array then sort by a custom date field (that I'll build and store per loop) so you get a list of news items, Instagram posts and tweets all sorted by date.

    Any thoughts on importing a pageArray and a regular PHP array? Should I be using $a->getArray(); then combining them?

    Thanks!

  11. 7 hours ago, Robin S said:

    You can use $pageimages->add() to add images to a field.

    
    $page->image_field->add('/full/path/to/image.jpg');

    ...or...

    
    $page->image_field->add('http://domain.com/url/to/image.jpg');

    But seeing as you will probably want to replace the existing image while keeping the same name you might want to use the PW admin to drop the new image onto the existing one. Not sure if there is an equivalent for doing that via the API.

    I guess I could use 

    $image->removeVariations()

    or even https://modules.processwire.com/modules/pageimage-remove-variations/

  12. 2 hours ago, Robin S said:

    It's not sRGB.

    2018-02-27_103735.png.2b7960d7260491cb3203ec69f9e55bae.png

    Perhaps consider setting up a batch process in Photoshop to convert your supplied images to sRGB profile.

     

    Setting individual imageSizerOptions in config like that doesn't work. There are two options for overriding individual options in /site/config.php...

    
    $config->imageSizerOptions = array_merge($config->imageSizerOptions, ['upscaling' => false]);

    ...or...

    
    $config->imageSizerOptions('upscaling', false);

     

    This is all super helpful, Robin. I think that imageSizerOption setup is working now. Hero. Thank you.

    As I'd need to re-upload all these images again to get the new options... is there a good way to do this via the API?

    • Like 1
  13. If you click on these images you'll see the difference.

    I'm also using this within my template:

    $image = $images->size(1600,800, ['upscaling' => true, 'cropping' => 'center', 'quality' => 100, 'sharpening' => 'none', 'defaultGamma' => -1]); // 2:1

    I have now added the below to my config.php file instead of the above and reuploaded the image but it still shows the same quality/colour loss on the resized image.

    $config->imageSizerOptions['sharpening'] = 'none';
    $config->imageSizerOptions['quality'] = 100;
    $config->imageSizerOptions['defaultGamma'] = -1;

     

  14. 10 minutes ago, Robin S said:

    I don't think OR groups are supported at all in WireArray (therefore PageArray) methods - adding support for OR groups inside a single PageArray selector is what BitPoet's module above is all about.

    But if you are doing what I suggested with find() and add() then you don't need the OR group parentheses. It's a different approach but should result in the same thing as OR groups inside a single selector.

    Thanks again, Robin.

    I thought, based on this page, https://processwire.com/api/selectors/#or-groups, that I was just using the OR groups inside a find() Page/WireArray? Or am I getting confused? Why would it work when doing one find() and not find()->find() for example?

  15. Thanks, Robin. That makes sense!

    Now the issue I seem to be experiencing is (when only have a single modifying query) is using an OR query...

    For example...

    $events = $pages->find("template=events-detail, events_detail_dates_final_date>=today");
    $results = $events->find("(events_detail_dates_upcoming_start_date<=today)");
    OR
    $results = $events->find("(events_detail_dates_upcoming_start_date<=1517174937,events_detail_dates_upcoming_start_date<=1517097600)");

    Seems to remove all the items (itemsRemoved when using Tracey Debugger). If I remove the parenthesis from the top modifier, for example, it works fine but obviously the parenthesis is required for the OR group. Any further thoughts?

  16. 11 hours ago, Robin S said:

    You could filter the PageArray more than once and add the results together. Actually, filter() is destructive so use find() instead.

    
    $results = $pagearray->find($selector_1)->add($pagearray->find($selector_2));

     

    Thanks for this again, Robin. After looking at this I'm unsure if this is working...

    $events = $pages->find("template=events-detail, events_detail_dates_final_date>=$today");
    
    $calendar = $this->input->post->calendar;
    $query = $this->input->post->query;
    
    $results = $events->add($events->find("{$query}, {$calendar}"));

    In this above example the $query could be the following (if upcoming start date is equal to or less than today)

    events_detail_dates_upcoming_start_date<=1517171596

    What result this is returning is the 'filtered' pages to the bottom off the original $events query... this is why the filter() option was good because it was removing any items that didn't match it the filter... not adding it to the original query. Any thoughts?

×
×
  • Create New...