Jump to content

JoshoB

Members
  • Posts

    115
  • Joined

  • Last visited

Posts posted by JoshoB

  1. I am also trying to make this work in ready.php to compile Bootstrap on-the-fly, but I get a weird error. Here is the code, adapted from the stuff so kindly shared earlier in the thread, with some modifications to make the file modification checks work (or so I thought):

    // Define the paths
    $inputScssPath = $config->paths->templates . "scss/custom.scss";
    $bootstrapScssPath = $config->paths->templates . "bootstrap/scss";
    $outputCssPath = $config->paths->templates . "styles/bootstrap_custom.css";
    $outputMapPath = $config->paths->templates . "styles/bootstrap_custom.map";
    
    // Check if the output CSS file exists and if any SCSS file has been modified
    $recompileRequired = !file_exists($outputCssPath);
    if (!$recompileRequired) {
        $outputCssMTime = filemtime($outputCssPath);
        $recompileRequired = false;
    
        // Find all .scss files in the /scss/ folder
        $watchFiles = $files->find(
            $config->paths->templates . "scss",
            ['extensions' => 'scss']
        );
    
        foreach ($watchFiles as $watchFile) {
            if (filemtime($watchFile) > $outputCssMTime) {
                $recompileRequired = true;
                break;
            }
        }
    }
    
    // Compile SCSS if recompilation is required
    if ($recompileRequired) {
        $scss = $modules->get('Scss');
        $compiler = $modules->get('Scss')->compiler;
    
        if($compiler)
            die("Found module.");
        else
            die("Module not found!"); 
    
        $compiler->setSourceMap($compiler::SOURCE_MAP_FILE);
        $compiler->setSourceMapOptions([
            'sourceMapURL' => $outputMapPath,
            'sourceMapFilename' => $outputCssPath,
            'sourceMapBasepath' => $config->paths->root,
            'sourceRoot' => '/',
        ]);
        $compiler->addImportPath($bootstrapScssPath);
        $compiler->setOutputStyle("compressed");
    
        // Get the result
        $result = $compiler->compileString('@import "'.$inputScssPath.'";', $config->paths->templates . "scss");
    
        // Save the output in the proper files
        file_put_contents($outputMapPath, $result->getSourceMap());
        file_put_contents($outputCssPath, $result->getCss());
    }

    It kept giving me a fatal error at the line with $compiler->setSourceMap($compiler::SOURCE_MAP_FILE); (complains about NULL), so I added the check with the die statements: it cannot find the compiler for some reason. But if I change if($compiler) to if($scss) -- I added $scss for testing purposes -- it finds the latter just fine. Any idea what I am doing wrong here?

  2. I was using this to share early access to articles with Patreon users. However, Patreon now filters query strings from URLs, which is a PITA. I wanted to rework this module to use URL segments, so that any URL that ends in /preview/ becomes a preview link, but no dice: ProcessWire throws a 404 every time, regardless of what I try.

    Any suggestions or ideas? Thanks again. 🙂

  3. Still working on my CRM... I need to send emails with attachment. I am using the WireMailPHPMailer module. Everything seems to work fine, but sending an attachment doesn't work. 

    The attachments are selected on the form from pages. Each of those page features a file field (called just "file") with a file, usually a PDF. In the e-mail form, I enter the sender, the addressee, the subject, the message, and then I select, from a dropdown, the attachment I want to attach to this message. However, clicking "send" will send the e-mail, but without an attachment. 

    I think this code will make it more clear ($formAttachment is the ID that gets sent as a $_GET variable when the form is submitted, and "file" is the field that contains the selected file in question):

    $file = $pages->get("id=$formAttachment")->file; 
    $mail->addAttachment($file->path, $file->name);

    Going step by step through the code, the error ProcessWire throws up is "Could not access file". 

    I have been banging my head against this now for a week, so I am hoping that someone here can have a look and say, "Oh hey, you need to do this and it's fine." I am pretty sure it has to do with either permissions in the file structure (this is a file that gets upload to /assets/ for the page in question), or that my understanding of ProcessWire's "path" is completely off. Either way, any help would be greatly appreciated! 

  4. Oh, cheers! I think I managed to solve it thanks to that thread.

    For posterity/future reference, this is what I wrote in the parent template:

    // Populate history_repeater with history from underlying pages, too
    foreach($page->children() as $child) {
        $page->history_repeater->add($child->history_repeater);
    }
    $page->history_repeater = $page->history_repeater->find("sort=-datetime");
    • Like 1
  5. I am building a website that serves as a client management system. I have organisations (each a page) and they are parent pages to contacts (i.e. people). Both the organisations and the contacts beneath them have a repeater field, "history_repeater", that is used to store comments in. The repeaters consist of a date/time field ("datetime") and a comment field ("comment"). An organisation page should show the complete history for that organisation, i.e. add the "history_repeater" data from the underlying pages (contacts) to the main "history_repeater" field in the organisation page, and then reverse sort the results by "datetime".

    I cannot seem to figure out how to do this in a neat way without taking recourse to building an array. I think it should be doable with a simple selector and sort, but how escapes me at present. Does anyone have a solution for this? Thank you so much in advance.

  6. Oh yeah, I am familiar with the database structure.

    I should have added that I want people to be signed in before they're allowed to post comments, so the website would see an influx of users. Currently, all "users" on the website are authors who write articles, and I would like to keep this list as small as possible. (I know I can use roles to manage the lists, but I would prefer a simpler solution.)

    There's also the issue of security: I don't want there to be any risk that a user is able to mess anything up, and I'd prefer to keep them out of the main database.

  7. Hello everyone,

    I manage a large site and would like to add the ability for visitors to add comments to articles. However, I also want to keep the core website database relatively "clean". So my idea was to install a fresh copy of ProcessWire to a subdomain (say, account.ancientworldmagazine.com), where users can register, sign in, and edit their profile. I could also sign in and manage comments.

    My idea is to load the new database into the website, so that a page can check if there's any pages with comments in the new database. So, for example, article X on my original website gets loaded, there's an if-statement that checks if there's a page in the new database with the field awm_page_id = $page->id (where $page is the article on the original website). If yes, it proceeds to load the comments from that database; if no, it creates a new page with the field awm_page_id = $page->id and people who are signed in can then start posting comments.

    So, is this feasible? Does it pose any security risks? Will it create unnecessary overhead and slow everything down? Am I better off just sacrificing the cleanliness of my website's database and enabling comments on there directly from the backend? I'd love to hear your thoughts.

  8. I'm testing it by putting the code in init.php (which gets loaded first), then going to the page in question via another browser with ?preview=true, and I get a 404 page instead of the article I want to preview.

    But maybe forcing the 404 page to reload would be an idea. (Even though I cannot get that to work either.)

  9. So I'm the editor of a large website and it's useful for me if my authors can check their articles before they are published on the web. I'd prefer to do this without needing them to sign in (with either their own account or a preview account). I figured the easiest way to do this is with a GET variable, so if someone goes to e.g. this URL:

    https://www.examples.com/articles/test?preview=true

    They would be able to see the specific article in question. But building the override eludes me; I tried to stick it in the template, but it's not working (using $pages->find or $pages->get with check_access=0).

    I feel like this ought to be simple, but I cannot figure it out. Does anyone have a suggestion on how to solve this?

    Many thanks in advance, as always!

  10. 26 minutes ago, Autofahrn said:

    Shouldn't this work with:

    
    $selector = "template=product, limit=10, categories={$page}|{$page->children}, sort=$sort_results";

    Given that $page is either a category or subcategory then $page->children is either the list of subcategory pages or empty.

    Maybe the or operator must only exist when children exist (not tested).

    This looks like it ought to work! Sadly, it doesn't. $page->children doesn't seem to do anything (the results get dropped).

  11. 8 minutes ago, Tom. said:

    Trying my hardest to understand this - from what I can tell, `$page` is category.php template?

    Ah yeah, sorry. That is correct: $page in this instance has a category.php template.

    Your solution sadly generated an error. I edited it to read:

    "template=product, limit=10, categories=[has_parent|id=".$page->id."], sort=categories.sort, sort=$sort_results"

    But then it doesn't list any products. I think that's because it now specifies it has to either have a parent or the ID needs to be specifically that of the page.

    What I'd like to do is to specify that the categories field includes either the current $page or one of the current page's children (i.e. the subcategories). So I was hoping something like this might work:

    categories.parent=$page|$page->children

    But no dice.

×
×
  • Create New...