DrQuincy
Members-
Posts
293 -
Joined
-
Last visited
-
Days Won
1
Everything posted by DrQuincy
-
Fieldtype that just displays HTML, nothing else
DrQuincy replied to DrQuincy's topic in Getting Started
Ah, thanks @MarkE, l will try that. ? -
I'm trying to find an existing PW field that is simple enough for me to duplicate and adjust to suit my needs. All I'm after is the ability to create some custom HTML with a hidden field — and then hidden field is used as the database value. There is no fancy validation needed other than the value can not be empty. I have bought an icon pack for a client that is stored in a folder for the website and I simple want to be able to show the icons in a grid and when clicked the name of the icon goes into the hidden field. I've looked through some of the core modules and it's a bit overwhelming. I'm sure if I had a simple example I'd be fine with it. Thanks.
-
I searched the forum for this and couldn't find anything. Is there a module/fieldtype that doesn't store anything for the actual page in the database. It just allows you to insert any HTML you want at a given point in the template/form. Is there such a thing? Thanks.
-
Thanks Jan!
-
Thanks for your suggestion! In this case it's for something that runs on cron in the night and syncs a website property listing with third-party listing software. It takes a long time to run as it needs to copy images over HTTP and then resize some of them so when the website is accessed during the day it's a lot faster. Thanks for your suggestion though. I must admit I have never thought of doing it that way — it's a neat solution. If you run curl and then redirect via a session as you have done, does curl honour the redirect? I can't say I've never tried that but from when I have used curl in the command line I'm sure it just returns redirect headers, location, etc. I just thought maybe there was a way with the API and get a page's rendered HTML as opposed to as an object to force ProcessWire to run the task as it would if you visited it via a browser. I don't know, I thought maybe there'd be something like $pages->get('/path/to/page/')->render() that returns the page HTML. If so, from my command line script I could simply map the arguments to $_GET and also pass a path.
-
Ah, yes, thanks for that. I'll have a think about how to implement it.
-
$page->path always has trailing slash in spite of template settings
DrQuincy replied to DrQuincy's topic in General Support
Thanks for the tip. ? -
Thanks, I've seen that. I just wondered if there was a way to — rather then get a page through the API which I could do per your link — get PW to actually process it as though it were a front-end request. If I do wire('page')->get(123) it will retrieve all the data but what I want is to trigger something that is the same as accessing the page through HTTP. Is there a built-in function for this?
-
My hosting environment does not allow for PHP to run for more than 120 seconds when it is a web request. However, there is no limit via command line PHP. Is it possible take a ProcessWire URL such as http://domain.com/foo/bar/?bar=foo and run it as a PHP command line? Something like: php /path/to/pw/site/index.php route=/foo/bar/ bar=foo Is such a thing possible? Thanks.
-
$page->path always has trailing slash in spite of template settings
DrQuincy replied to DrQuincy's topic in General Support
Ah, thanks, yes, that explains it. I always assumed $page->url was the full URL but that is actually httpUrl; var_dump(wire('pages')->get('/sitemap.xml/')->path); // "/sitemap.xml/" var_dump(wire('pages')->get('/sitemap.xml/')->url); // "/sitemap.xml" var_dump(wire('pages')->get('/sitemap.xml/')->httpUrl); // "http://site.local/sitemap.xml" Thanks, I will use ->url in future. ? -
I'm not sure if I'm missing something glaringly obvious here but if you set URLs (not segments) to not have trailing slashes you will still get one at the end when accessing $page->path. So $page->path for my sitemap.xml file is /sitemap.xml/. Yes if you visit /sitemap.xml/ it redirects to /sitemap.xml — but why doesn't it just return /sitemap.xml? This will end up adding an awful lot of unnecessary requests. Is this intended behaviour? I have also noticed the API only seems to work with forward slashes too (e.g. parent=/foo/bar/, not parent=/foo/bar) — but I get that as a design decision since the the trailing slash setting is effectively abstract from that.
-
Hi, I am doing a site that does a fair bit of number crunching and decided to try PHP 8 as I read it was a fair bit faster. The front-end works fine but when I log in to /processwire/ I get: When switching back to PHP 7.4 it works as expected. I did also try it on a computer that had never accessed the back-end before and got the same error (though in hindsight I wonder if I should've cleared the cookies first). Does PW definitely work on PHP 8? I am using 3.0.184. If so, I wonder if it is a module that's the problem — or maybe the CSRF token needed clearing. I know you can disable CSRF but I am reluctant to do that. I have session fingerprinting disabled also. I just thought I'd check first to see if the core is fine to run on PHP 8. Searching the forums you find threads of people saying don't use v8 yet — but they're all about a year old. Thanks.
-
When looking at the source there are quite a few page statuses beyond those visible in the Status > Settings panel; these are marked as #pw-internal in the comments. Is it better to avoid using these as it could mess up how PW works? I just wondered as the 'flagged' status could potentially be quite useful. I can just unpublish though and if it's possible uses these statuses could cause issues I'll leave them alone.
-
Ah, yes, this is just what I want, thanks. $paths = $config->paths; $paths->set('myData', 'my-data/'); // Relative link echo $config->paths->myData; // /Absolute/path/to/PWSite/my-data/ Thanks. ?
-
Ah, interesting, thanks!
-
I've got some code that gets run from various locations and the file path is stored in PW (since it varies depending on the environment). I want to be able to store a single setting that works across all environments. The problem is sometimes it's called from init.php and other times from a template. So if my setting is ../data/, this will result in things like: /MyPWSite/site/templates/../data/ /MyPWSite/site/../data/ I.e. different locations when the data is always in the same place. What would be ideal is if I can get a file path that is always from the main index.php folder (/MyPWSite/ if you go by the above example) regardless of what point in the application it's called. I've searched for this and can't find it. Is there a variable I can use? I've not really tested it but in PHP something like this would do it: dirname($_SERVER['SCRIPT_FILENAME']) I just wondered if there was already something in the PW API. Thanks. ?
-
Add custom HTML before div#pw-mastheads if in debug mode
DrQuincy replied to DrQuincy's topic in Getting Started
That's a nice simple solution. I'd probably use that for myself but in this instance the client wanted something more obvious. -
Add custom HTML before div#pw-mastheads if in debug mode
DrQuincy replied to DrQuincy's topic in Getting Started
Wow, that is just what I needed! Thanks so much! -
I have had a client say that because the dev and live hosts are so similar they get confused between the development and production CMSs. They have asked for a way to make it clearer which environment they're in. Although it says “The site is in debug mode, suitable for sites in development” in yellow when you log in on the dev version I think they are wanting something more obvious. An easy solution would be to add a message at the top of the page in debug mode. After messing around with Inspect element it seems if I could insert custom HTML before div#pw-mastheads that would do the trick. Is there a hook for this? I could do it with custom JS but is there any way to tell from the DOM or an existing JS variable if it's in debug mode? Thanks.
-
Thanks. ? I'm going to try and implement this when I get the time. I'm thinking use your code running only on Pages::delete with status!=trash added to the selector — and then issuing a warning on Pages::restore if there are any broken references (possibly also setting the page to unpublished). I'll post something once I've had a go.
-
The above is great @Robin S, thanks. The issue I have though is if Page A references Page B, you can delete Page A. But then when you come to delete Page B it won't let you because it sees a reference between Page A, which is in the trash, and page B. I'm struggling to come up with a solution that will always work in a user-friendly way. If you only run the above just on delete (and not trash) then that fixes my initial problem but what could happen is a page could be restored while the page it references is still in the trash. What do you think would be best practice here? Run your code above on delete only and then do a similar check on restore — only on restore simply issue a warning since at that point the reference is broken. I'm just finding when thinking through all the scenarios it gets complicated and I'm wondering if you run that hook above without adding parent!=7 to the selector (to ignore trashed items) it can get messy and prevent legitimate deletes and trashes. Maybe it's just better to enforce on delete and on the edge cases where page are restored issue a warning. Hope that makes sense and I've understood it correctly!
-
Changing $config->userAuthSalt and $config->tableSalt values
DrQuincy replied to DrQuincy's topic in General Support
Great, thanks. -
I have an older site where the client wishes to add a general site search: a single search box that will search everything. I have done this before by adding a hidden text field to each searchable templates and creating a plain text version of the page when it is saved (using hooks). Then when I do a search using ~= for fulltext and if the number of characters if fewer than the minimum character limit for natural language search for that engine I switch to %= and do a LIKE search (although searches must be at least three characters). This site (which uses MyISAM), however, is based in the engineering industry and as well as the usual pages of about, news, etc they have products and manuals that they will want to be made searchable. I am wondering if a user searches Acme 123 will it only search for Acme since 123 is too short for MyISAM — rather give more weight to the specific 123 product? I guess it depends on the selector (see below). I'm wondering how to approach this. With my custom work I tend to write a query that does a MATCH AGAINST with the phrase with no quotes and then again wrapped in double-quotes, given more weight to the latter (you can do this with InnoDB without having to use BOOLEAN MODE) via the relevancy score. The problem is natural language is better for general searches but LIKE is possibly better for searching product names. I'm not sure there's an easy solution other than to add a checkbox “Exact match only (useful for product searches)” — unless there is a way to do it with fulltext selectors. I've noticed that newer versions of ProcessWire offer a wider selection of selectors. Here are the relevant ones: FULLTEXT *= Contains phrase/text Given phrase or word appears in value compared to. ~= Contains all words All given whole words appear in compared value, in any order. ~*= Contains all partial words All whole or partial words appear in value, in any order.* ~~= Contains all words live All whole words and last partial word appear in any order.* ~|= Contains any words Any given whole words appear in value, in any order.* ~|*= Contains any partial words Any given whole or partial words appear in value, in any order.* **= Contains match Any given whole words match against value.* LIKE %= Contains phrase/text like Phrase or word appears in value compared to, using like. ~%= Contain all words like All whole or partial words appear in value using like, in any order.* ~|%= Contains any words like Any given whole or partial words appear in value using like, in any order.* *Available in ProcessWire 3.0.160 or newer. I'm just a bit lost as to which selectors to use. If you use word-based fulltext selectors does it still match phrases as well and give a higher relevancy? If there's a way to search Acme 123 as an exact match first and then just Acme and 123 separately (the latter would be ignored though unless using InnoDB, which is fine) and still return results by relevancy that would be ideal. When using fulltext selectors can you combine them and have results returned by aggregate relevancy? Any advice or experiences would be appreciated. ?
-
I have created a brochureware template site that I can clone and put sites together more quickly. I have just copied it for the first time and I replaced the $config->userAuthSalt and $config->tableSalt values with a cryptographically secure hex token of the same length. I have the password reset module installed so reset the password and logged in no problem (there is only one user in the template). The site seems to work fine. I just wanted to check this was safe to do. It seems userAuthSalt is a secret salt for hashing the user passwords (in addition to the one built in to bcrypt) hence the need to change the password. Looking at the source it seems tableSalt is never used internally by PW anyway. Am I right in my assumptions? If so, I'm probably okay to change them as I have done — and actually having multiple sites with the same values is also not going to be much of an issue in most cases.