-
Posts
103 -
Joined
-
Last visited
Everything posted by Marc
-
Copy an image from one field to another on the same page
Marc replied to Marc's topic in API & 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. -
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?
-
Multisites with same templates and different databases
Marc replied to shivrajsa's topic in General Support
Has anyone managed to overwrite the cache path and URL? It does not seem to work so all sites will be sharing the same cache, which might be problematic. Edit: looks like template cache does use the custom cache path/URL and other forms of cache use the default cache folder. -
Multisites with same templates and different databases
Marc replied to shivrajsa's topic in General Support
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. -
getting infinite loop on simple redirect module
Marc replied to Marc's topic in Module/Plugin Development
Thank you, that's it of course 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. -
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?
-
That's great @Zeka, thanks!
-
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)?
-
Thanks, gonna try this out
-
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.
-
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!
-
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: 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?
-
Looks like this can be resolved by making sure the same modules are installed on both websites. (Just like Ryan mentions in the docs...)
-
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: I'm probably missing something obvious here as I don't have much experience with namespaces yet. Any suggestions?
-
Finally set up my Vagrant testing environment (provider Virtualbox) running a Ubuntu 14.04 server with PHP 7.1 with Nginx in front of Apache. I'll mimic Soma's report: PW2.7.3 TTFB Chrome: ~28ms PW3.0.42 TTFB Chrome: ~40ms Those are new installs of intermediate profiles without modifications. I will look into the other numbers later.
-
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. 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.
-
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.
-
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.
-
I think I had this problem as well. I believe I solved it by changing the default PW 3 config.php file. There could be 2 lines in there in the database section that you can comment out or delete, one should be the db connection type.
-
Sorry I worded that incorrectly, I renamed the old wire folder first so I did not overwrite it. I'll change that sentence.
-
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.
-
New blog post: Working towards a new admin theme
Marc replied to ryan's topic in News & Announcements
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! -
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: So thank you for that
-
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.
-
change custom admin page topnav button on/active state
Marc replied to Marc's topic in API & Templates
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.