Jump to content

Marc

Members
  • Posts

    103
  • Joined

  • Last visited

Posts posted by Marc

  1. 1 hour ago, dragan said:

    May I ask why you want to clone an image in the first place?

    If you need thumbnails, just use 

    
    $image->size($width, $height, $options)

    in your templates.

    I understand I can generate different sizes and that is exactly what I'm doing right now. I do some checks to see if the uploaded thumbnail is of high enough quality by checking its dimensions and if it is not, I fallback to the image_front field which is always of higher quality and I resize on the fly to the correct dimensions. I want to get rid of these checks so I want to do a one time replacement of a bunch of thumbnails by cloning the image_front image to the thumbnail field.

  2. I want to use the API to duplicate an image from one field to another (on the same page). The duplicated image should be a new file so both fields should not point to the same physical file. The field that holds the image that I want to duplicate is called 'image_front' and the duplicated image should go to a field called 'image_thumb'. Any image that is already attached to image_thumb should be removed because it should hold only one file. The same goes for image_front, it should have only one image. Here's what I have so far:

    $original = $page->image_front;
    $file = $original->getFile($original);
    $new = $original->clone($file);
    $page->save();
    
    $page->image_thumb = $new;
    $page->save('image_thumb');

    This works in the sense that the image is successfully cloned but it is attached to both fields so both fields end up have their original image plus the cloned image. 'Image_thumb' should only have the cloned image and 'image_front' should only have the original image. What would be the best way to remove those images and am I even approaching this correctly?

  3. I really like what you guys came up with here, I think I'm going to implement this on a bunch of websites. 

    One thing to note is that when you are using multi-instance like I do, and you connect from a PW site that is not part of your 'multisite' setup, the $_SERVER['HTTP_HOST'] condition in config.php won't trigger and you will not get the data you are after. One way to get around this is to create the instance like this:

    $site = new ProcessWire('/srv/users/me/apps/website/public/', 'http://website.dev/');

    Adding the domain as the second parameter will set a variable called $httpHost (to 'website.dev' in my example) in wire\core\ProcessWire.php which is available to config.php. Therefore, if you alter the condition in config.php to this, multi-instance should work:

    if ($_SERVER['HTTP_HOST'] == 'website.dev' || $httpHost == 'website.dev') {
        $config->dbName = 'name';
        $config->dbUser = 'user';
        $config->dbPass = 'pass';
        //etc
    }

    I have not tested this extensively but it seems to work fine.

  4. 14 hours ago, Soma said:

    How about redirect to the url page->url not the page object which would be the id.

    Thank you, that's it of course :-[

    14 hours ago, Soma said:

    Also i would use $this->wire ('pages')->... not $event->pages...

    I was using the wire way at first but searching the forums I noticed someone using $event object for this so I decided to give it a try, not really understanding the differences.

  5. I am trying to make a simple wiredata module that lets me select a page I want all visitors to be redirected to. I have this working in ready.php but then I decided on putting it in a module and I can't get it to work. Here's the relevant bits:

        public function ready()
        {
            $this->addHookBefore('Page::render', $this, 'redirectUsers');
        }
    
        public function redirectUsers(HookEvent $e)
        {
            $page = $e->object;
    
            // The page we want to redirect to.
            $redirect = $e->pages->get($this->redirectPage);
    
            if ($page->id == $redirect->id) return; // Prevent infinite loop.
    
        	if (!$e->user->isLoggedin()) {
            	$e->session->redirect($redirect, false); // 'false' indicates 302 temp redirect.
        	}
        }

    I left some checks out for simplification. Whenever I'm not on the page that I want to redirect to, an infinite redirect loop starts. Could anybody explain why that is?

  6. I have setup two websites, A and B. A can read pages from B using the multi-instance API. But how do I get A to save a new page to B? I have this simple test setup:

    $path = "C:/Users/Marc/Documents/development/www/siteB/";
    $url = "/siteB/";
    
    $siteB = new ProcessWire($path, $url);
    
    $np = new Page();
    $np->template = "my-template";
    $np->parent = $siteB->pages->get('/forms/');
    $np->title = 'test multi-instance form';
    $np->save();

    The page is saved to site A instead of B, with no parent. Is this a case of saving it to the wrong instance? If so, how do I save it to the correct instance (site B)?

    • Like 1
  7. Is it possible to temporarily overwrite the smtp host and smtp user defined in settings with the API? I would like to send some emails using a different smtp server with different credentials from the one I entered in the module settings.

  8. On 8-4-2017 at 9:49 AM, horst said:

    You need to manually install pim2 under site/modules/, and UN-install pim. Than you can use pim2load.

    You can read about it in the very first post of this thread: https://processwire.com/talk/topic/4264-page-image-manipulator-1/  right at the top of that post.

     

    I read that post but I was confused by it. But now understand: I need to open the site/modules/PageImageManipulator folder that was downloaded by PW and remove the module files that are not PageImageManipulator02 and then install it. Thanks for the module!

  9. This module is not working for me on PW 3.0.58. I'm trying to convert PNG to JPG. When I do 

    $img->pim2Load('template')->setOptions($options)->width($img->width())->pimSave()

    I get a fatal error: 

    Quote

    Exception: Method Pageimage::pim2Load does not exist or is not callable in this context

    When I use pimLoad instead of pim2Load, there's no error and JPG's are generated. But since I'm on PW 3, I should use pim2Load. I'm calling the function in one of my templates. Any idea as to why pim2Load would not be working?

  10. I'm working on a process module that connects to another ProcessWire 3.0.54 installation on the same (local) server (both sites running 3.0.54). I'm trying to use multi-instance for this, so:

    namespace ProcessWire;
    
    $path = "C:/Users/Me/Documents/development/www/pw3/";
    $url = "http://www.test.me";
    $site = new ProcessWire($path, $url);

    Those simple three lines generate the following error:

    Quote

     

    Fatal error: Cannot declare class ProcessWire\LanguagesPageFieldValue, because the name is already in use in C:\Users\Me\Documents\development\www\pw3\wire\modules\LanguageSupport\LanguagesPageFieldValue.php on line 11

    Fatal error: Cannot declare class ProcessWire\AdminThemeReno, because the name is already in use in C:\Users\Me\Documents\development\www\pw3\wire\modules\AdminTheme\AdminThemeReno\AdminThemeReno.module on line 3

     

    I'm probably missing something obvious here as I don't have much experience with namespaces yet. Any suggestions?

  11. Thank you Ryan for the detailed response. Given all of the optimizations you mention it is indeed quite strange myself and a few others are seeing this behavior.

    22 hours ago, ryan said:

    I'm measuring here with Chrome dev tools, ProfilerPro and my own timers using the Debug class. What tool are you guys using to measure times, and in what quantity?

    I'm using the most basic way of testing which is Chrome dev tools and repeatedly refreshing the page to inspect the load times. Doing this with unmodified and brand new intermediate profile installations of Processwire 2.7.3 and 3.0.42 I see the 30% difference in load times. By unmodified I mean I haven't changed a single template or page that is installed by default. I only modified config.php to connect to my database, everything else is untouched (no extra modules). This is on a Windows machine with Xampp running PHP 7.0 on an SSD drive and a remote database connection (which is surely slowing things down but it should be slowing both the PW 2 and 3 database connections equally I imagine). 

    I will setup a different development environment at home later today or tomorrow that is Vagrant/Ubuntu-based and repeat the test. To be honest I'm expecting no difference as I've already seen similar degradation on my production server where I uploaded a site that I upgraded to PW 3 (which has load time differences of up to 100%, ouch). 

    I should note that adding $config->moduleCompile = false to the PW 3 site makes no difference.

  12.  

    2 minutes ago, kongondo said:

    Hmm. That's an interesting observation. I am curios that no one else (as far as I can tell) has had/reported a similar experience. I wonder if it has to do with your setup? 

     

    I agree, that is suspicious and maybe I am jumping to conclusions. However in trying to rule out my local setup I uploaded my upgraded website to my server and saw the exact same degradation in speed. Which disappointed me greatly because I was really hoping it was just my local XAMPP setup causing this.

  13. After testing vanilla installations of the intermediate profiles of both PW 2.7.3 and PW 3.0.42, it seems PW 3 is just slower in general than PW 2. I'm seeing differences in load times of 30+ percent on identical pages. I suppose that's a price to pay for all the new stuff that is possible with version 3. The upside is, maybe this means the longer load times of the website I upgraded are to be expected. 

  14. 4 minutes ago, flydev said:

    In before complete answer, the first thing I see is :

    What the doc say:

    When you put in the new /wire/ directory, make sure that you remove or rename the old one first. If you just copy or FTP changed files into the existing /wire/ directory, you will end up with both old and new files, which will cause an error.

    Sorry I worded that incorrectly, I renamed the old wire folder first so I did not overwrite it. I'll change that sentence. 

  15. I have upgraded a pretty large ProcessWire 2.7.2 website to version 3.0.25, and the site became much slower. On simple pages load times on average went from 555 ms to 780 ms, which is bad enough, but the more complex pages which gather info from other pages and add some custom queries went from 2.3 seconds to 5 seconds, twice as slow. A few facts:

    • This is without template caching, which I cannot use on these particular pages.
    • This is on localhost. I have not upgraded the live site yet (fortunately).
    • Load times are on the slow side regardless because my local database server is on a NAS.
    • There are no errors.
    • By upgrading to PW 3 I mean I did the standard upgrade path by replacing the wire folder, overwriting index and htaccess files and letting the admin upgrade the db. I also added the ProcessWire namespace to all my custom template files and scripts.
    • I'm not using any PW3-specific config options or features yet.
    • I use very few plugins.

    I'll be needing version 3 features for this particular website soon so I will have to do the upgrade either way. But I'm not sure how to troubleshoot these poor load times. Where do I start? Any pointers would be greatly appreciated!

    Edit: I did some test with simple pages that use template cache: load times went up from 287 ms to 470 ms on avarage. I should also add these times are for the document to load, before scripts like CSS and images are loaded. So I'm measuring only the time it takes for ProcessWire to do its thing.

  16. I'm super excited by this announcement. I've always felt the default admin theme looks a little too utilitarian. The screenshots already look lovely, can't wait to try this out!

    I started using Uikit again with the release of the latest PW site profile, after abandoning Uikit 2 years ago in favor of something smaller and more customized, but using Uikit 3 has been a pleasure so I'm glad to see it become available in the admin as well. Exciting times for Processwire developers! 

    • Like 1
  17. On 1/15/2017 at 10:32 PM, Robin S said:

    The inputfield value is not saved correctly because config you are trying creates an error:

    
    PHP Notice: Object of class ProcessWire\Page could not be converted to int in ...\modules\Process\ProcessModule\ProcessModule.module:1287

     

    Where does this error show up? I have debug mode activated but this error is not in my logs and it is not displayed on screen.

    I arrived at the same conclusion of creating the options for the field manually and have basically the exact same code as you posted above, however I like your alternative approach much better and it is what I was after in the first place:

    Quote
    
    // My custom test field
    array(
        'name' => 'myTest',
        'type' => 'PageListSelect',
        'label' => $this->_('Test')
    )

    So thank you for that :)

  18. I'm messing around with the ProcessHello example module and I'm trying to add a page selector the the module's configuration page. I have added the input field but the value is not saved to the database and I'm trying to find out why that is. Here's my ProcessHello.config.php:

    class ProcessHelloConfig extends ModuleConfig {
    
    	public function __construct() {
    
    		$this->add(array(
    
    			// Text field: greeting
    			array(
    				'name' => 'greeting', // name of field
    				'type' => 'text', // type of field (any Inputfield module name)
    				'label' => $this->_('Hello Greeting'), // field label
    				'description' => $this->_('What would you like to say to people using this module?'),
    				'required' => true,
    				'value' => $this->_('A very happy hello world to you.'), // default value
    			),
    
    			// Radio buttons: greetingType
    			array(
    				'name' => 'greetingType',
    				'type' => 'radios',
    				'label' => $this->_('Greeting Type'),
    				'options' => array(
    					// options array of value => label
    					'message' => $this->_('Message'),
    					'warning' => $this->_('Warning'),
    					'error' => $this->_('Error'),
    					),
    				'value' => 'warning', // default value
    				'optionColumns' => 1, // make options display on one line
    				'notes' => $this->_('Choose wisely'), // like description but appears under field
    			),
    
    			// My custom test field
    			array(
    				'name' => 'myTest',
    				'type' => 'page',
    				'label' => $this->_('Test'),
    				'labelFieldName' => 'title',
    				'inputfield' => 'InputfieldSelect',
    				'parent_id' => 1
    			)
    		));
    	}
    }

    I am probably missing something obvious here. The custom field is displayed but it won't save anything. Other field types like 'text' do save their value.

  19. 13 hours ago, tpr said:

    Is there a unique class on the body element that you could use to style the element? Eg. "ProcessPageEdit-id-1005" or similar?

    Indeed there is :) In fact, the button I want to style has almost the same class, so I suppose I could use javascript as mentioned by @BitPoet and match the body class with the element in the topnav and act accordingly. Good suggestion! So here's what I came up with, a working example:

    ready.php

    if ($page->template == "admin" && $page->name == "settings-appearance")
    {
        $input->get->id = $pages->get("/settings-appearance/")->id;
        $config->scripts->append($config->urls->templates."scripts/admin.topnav.js"); // Give nav button active state.
    }

    admin.topnav.js

    $(function() {
        /* Make the topnav navigation button active that points to the current page that
        was added to the topnav manually.
        Search for a class on the body element that starts with 'id-' and add the 'on' class
        to the button if the button has a similar class. */
        var bodyClasses = $('body').attr('class');
        var pageClass = bodyClasses.split(" ").filter(getPageClass);
    
        function getPageClass(value) {
            return value.indexOf("id-") === 0;
        }
    
        // The navigation button in the topnav element should have a class name like 'page-id-1058-'.
        var btnClass = '.page-' + pageClass + '-';
        $('#topnav').find(btnClass).attr('class', 'on');
    });

    The javascript should work for any page you add to the top navigation bar since it matches page ID's from the body element's class attribute to the page ID in the navigation button's class attribute. So you don't have to set any page ID's manually in the javascript.

    Note that this only applies to the default admin theme. On Reno theme it is not necessary.

    • Like 2
×
×
  • Create New...