Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

26 Excellent

About johnstephens

  • Rank
    Jr. Member

Recent Profile Visitors

4,955 profile views
  1. Thanks! I feel very foggy on how to do that. Could you direct me to an appropriate code example? I'll look into that! I'm used to dealing with the DOM in JavaScript, but with PHP I'm not so savvy. DOMDocument looks like a great fit! Thank you!
  2. I'm working on a script for importing very old static HTML files into ProcessWire so they are searchable on the new site. What I have so far works, but I wonder if there are ways I can make the work of cleaning up the imported content easier, by doing more useful cleanup during the import. For this demo, suppose all the files exist in one directory, called "public", and suppose we're importing them all into the basic-page template. At this point, the basic-page template has been modified from the blank profile to include one additional textarea field called "body", which uses the CKEditor. <?php include './path/to/processwire/index.php'; // Use FileSystemIterator to save all the files in the 'public' directory // https://www.php.net/manual/en/class.filesystemiterator.php $files = new FileSystemIterator('./public'); // This is a callback function for the CallbackFilterIterator below $is_html_file = function($file) { return strpos($file->getFilename(), '.htm'); }; // Use CallbackFilterIterator to winnow the files down to only HTML files // https://www.php.net/manual/en/class.callbackfilteriterator.php $html_files = new CallbackFilterIterator($files, $is_html_file); // Input a regular expression and a string -> output an array of matches $preg_matches = function($regex, $string) { preg_match($regex, $string, $array); return $array; }; // Iterate over the directory objects stored in $html_files foreach($html_files as $file) { // Turn this file into a SplFileObject so we can read its contents // https://www.php.net/manual/en/class.splfileobject.php#splfileobject.constants.drop-new-line $_file = new SplFileObject($file); $contents = $_file->fread($_file->getSize()); $h1_content = $preg_matches('/\<h1\>(.*?)\<\/h1\>/i', $contents)[1] | false; // Create a new ProcessWire page and save the content into it $article = new \ProcessWire\Page(); $article->parent = $pages->get('/'); $article->template = 'basic-page'; $article->title = preg_match('/\<h1\>(.*?)\<\/h1\>/i', $contents) ? $preg_matches('/\<h1\>(.*?)\<\/h1\>/i', $contents)[1] : $preg_matches('/\<title\>(.*?)\<\/title\>/i', $contents)[1]; $article->body = $contents; $article->save(); } This successfully titles all the pages that have at least one h1 tag. (I know this is making a big assumption of proper markup, but it appears to be broadly correct in this one case.) The rest of the content is dumped into the page's body field. If this helps anyone else solve a similar problem, have the code! (WTFPL) But when one is dealing with archaic HTML using font tags and tables for layout (yeek!), this leaves much room for improvement. Something I'd like to do is get rid of all the layout tables and site furniture, like branding markup, navigation, and footer text. Of course, that is not marked up in a consistent way across all the documents. 😉 I wonder if anyone has guidance for something like this? Do you know of any best practices for automating the cleanup old HTML? Thank you! Edit: When searching for HTML tags, matches should be case insensitive (using the i flag after the delimiter). Also, use the content of the title element when there is no h1 tag on the page. This is all fixed in the code above.
  3. I have a site operating on Textpattern CMS. I still love Texptattern, which has served us well for many years—but the needs of this site have steadily grown beyond the limits of what Textpattern can do comfortably. I'd like to transition the site to ProcessWire, but the project doesn't have a budget for a full redesign right now. I'm wondering if it's feasible to install ProcessWire now, and create a limited number of pages managed by ProcessWire; then seamlessly redirect all requests for pages not managed by ProcessWire to Textpattern. Then, over time, I'd like to migrate the remaining templates and content to ProcessWire so that more and more of the site is being managed by ProcessWire, until the Textpattern site is no longer needed. Has anyone else done something like this? What steps did you take to minimize any possible disruption? How would you recommend setting something like this up? Thanks in advance for any guidance you can offer!
  4. That appears to have fixed the issue! I can log in after uncommenting the RewriteRule and the RewriteBase / line. Thank you! The installation was the latest stable version as of yesterday, ProcessWire 3.0.123. And the server runs PHP 7.2.17. I appreciate the help! Is there anything else I should look out for when running ProcessWire on a subdomain with this PHP version? Thank you again!
  5. I see the following message in my Apache error log file—I think it's associated with the attempts to load a page with the password reset code: [Mon Apr 29 11:10:13.761290 2019] [core:error] [pid 12889:tid 4057058112] [host opm.beardedbaby.net] [client] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
  6. Hi! I just created a fresh installation of ProcessWire on a subdomain. After commenting out the following rule in my .htaccess file, I was able to access the admin panel: RewriteRule ^(.*)$ index.php?it=$1 [L,QSA] But then I hit a dead end. When I attempt to log in, the same login screen reloads without any error display. I attempted to reset the password following the method here, but when I load the page with the password reset code, I get an error saying "Superuser has never logged in", and I still can't log in via the admin panel. I expect this is a known issue do to some quirk of my hosting that I never noticed before. Can anyone suggest steps I could take to troubleshoot this? Thank you!
  7. I'd like to understand this too. I too made sure that the editor role had user-admin permissions enabled, before coming across this problem.
  8. I can confirm that this fixed the problem for me, when I typed check_access=0 by hand into the selector field instead of copying and pasting it from Adrian's message. Thank you @adrian, for identifying the solution! And thank you, @Robin S for figuring out where I went wrong!
  9. Thank you, @adrian! That seems to cause ProcessWire to choke when loading a page in the editor. If I set the selector to this: template=user, roles=managing_editor It works perfectly for a superuser. The above selector throws no error when loading the editor using my managing_editor role—it simply doesn't populate the options. But if I set the selector to this: template=user, roles=managing_editor, check_access=0 ProcessWire throws this error, no matter what role I log in with: Unknown Selector operator: '' -- was your selector value properly escaped? Thanks again! I appreciate any insight someone might offer. Cheers!
  10. Hi! I created a page reference field linked to ProcessWire's "Users" page array. I do not have "create new pages" enabled for the field, and I don't want to use this field to create new users. When I am logged in as the superuser, it works as intended: I can select one or more registered users and associate them with the current page. But when I log in under a different role, the page reference field is empty, and does not allow me to select any users. I've checked the permissions for the role that I want to authorize to use the this field, and the permissions under the "Access" tab on the field itself. I don't see any role-based permissions I could add to the role that seem pertinent to this issue. Under the field's "Access" tab, I have added "View" and "Edit" privileges for the given role, but that does not seem to change the behavior at all. Can anyone offer some guidance in troubleshooting this? I know there must be some privileges I have not considered, but I don't know where to look. Thank you all in advance!
  11. Hi! I'm setting up a site search form and results page. Something I wanted to include in the search results was an excerpt of the content showing the highlighted search term plus some surrounding text—like the search_result_excerpt tag in Textpattern (function definition). I searched the forum and couldn't find an example of this. I suppose I'm just not hitting the right keywords relative to ProcessWire's API. Can anyone suggest examples or documentation that might help me with this? Thank you!
  12. I'm seeing this error and the site doesn't use jQuery at all on the front-end. It does have caching enabled on some templates (the type of caching offered natively by ProcessWire, not ProCache). Do I have to conditionally load ckeditor's jQuery on the front-end when edit-access users log in?
  13. You're wrapping up a design project for a new or substantially redesigned website. What are the not-so-obvious things on your list that you don't want to forget before you work on something else for a while? I realize that what counts as not-so-obvious in one project might be completely obvious and the first thing you do on another. Still, I'd love to hear what are the little things you do to tighten the screws and clean up before moving on to other work?
  14. So one of my requirements is that the shell script that must access the secret content is executed on the editor's personal machine, not on the server. After scouring ProcessWire's API, I think I've stumbled upon a way to do the main thing I use smd_access_keys for: function showSecretContent() { return "<pre>Secret content</pre>"; } /** * Generate a key unique to this user and for this day only. */ $segment = sha1($user->name . $datetime->date('Y-m-d') . $this->config->userAuthSalt); /** * Add the key to the URL for this page to use in links. */ $urlkey = $page->url . '?key=' . $segment; /** * If there is a key in the URL request, save it. */ $key = $input->get('key'); /** * To authenticate the key for certified users only, save all users to an array. */ $allusers = $users->find('id>0'); /** * If the current session is logged in to ProcessWire, show the URL key and the secret content. */ if (!$user->isGuest()) { echo '<pre><a href="' . $urlkey . '">'. $urlkey . '</a>' .'</pre>'; echo '<pre>This is what you will see:</pre>'; echo showSecretContent(); } else { /** * If the page is accessed without a ProcessWire login, check if the key is set. */ if (isset($key)) { /** * If the key is set, check all the users for a user who matches the key. */ foreach ($allusers as $thatuser) { if ( $thatuser !== $users->getGuestUser() && $key == sha1( $thatuser->name . $datetime->date('Y-m-d') . $this->config->userAuthSalt ) ) { /** * If there is a user who matches the key, who isn't a "guest", show the secret content, * But only if the session isn't logged in. */ if ($user->isGuest()) echo showSecretContent(); } } } else { /** * Don't show the secret content if the session isn't logged in or when the request doesn't include a key. */ echo '<pre>Go away</pre>'; } } Compared to smd_access_keys, this script does not allow keys to include custom expiration windows or expiration after a given number of requests—a "key" expires at midnight regardless of whether it was created at 00:01 or 11:59. This script also does not save keys to a database or allow keys to be voided in the ProcessWire admin. It also doesn't offer file protection. (smd_access_keys can be used to generate keyed links to download assets that you want to limit, like if you offer a MP3 or PDF download only to someone who signs up for your newsletter.) But I didn't need those features for this implementation. Can you see any problems with this approach? Are there security issues that I have overlooked? Are there any obvious improvements I should make? Thanks for any guidance you can offer! I appreciate your comments and support.
  15. Howdy, I have a document created and served by ProcessWire. I want to make it visible only to someone who is logged in to ProcessWire OR to an external shell script being run by an authorized user. I see how to designate authorized roles for access in the template's "Access" panel, and I see how to devise what content visitors can see in a page's template file using the API. Those cover the first scenario perfectly. However, if I exclude "guests" (or any other roles) from accessing a page via the template's Access menu or via the API, that also prevents someone from getting the URL via a shell script. I've solved this problem on other sites that use the Textpattern CMS, by adding the smd_access_keys plugin. The solution is twofold: The template or template section first detects whether an authentic user has privileges to view the page. If a privileged user is logged in, the template displays a special access URL that the user can use with their shell script. The URL access key has a built-in expiration, which prevents unauthorized access if someone somehow "guesses" the hash and salt at a later time. One of my uses for this feature is to allow a managing editor to generate documents that can be converted to PDF using Prince XML. I have also used it to provide temporary access to web forms and other content. I might use it to give someone temporary access to a file hosted on the site, as per the plugin's documentation. I'm not convinced that temporary access URLs is the only way or the best way to solve this problem, but I'm not sure how to do it at all using ProcessWire's API. Do you know a way to allow temporary access to resources managed by ProcessWire to designated external services (like a shell script), without giving access to anyone who goes to the URL? Thanks in advance!
  • Create New...