Jump to content

rash

Members
  • Posts

    112
  • Joined

  • Last visited

Posts posted by rash

  1. Hi guys,

    I’m writing on a brief editor’s manual what reminds me of a topic I repeatedly stumble upon: What are the exact differences between unpublished, hidden and locked pages? Just to make it clear: There is no problem with checking or setting the status and using the result for whatever. The only thing I don’t really understand is the editor’s view: What is happening with the states beside their usage in my templates? Surprisingly, the otherwise excellent PW docs don’t reveal too much about.

    • Like 1
  2. 3 hours ago, Mike Rockett said:

    I've bumped to 0.4.0 RC3 on the repo.

    @Mike Rockett Fine, thank you. Just a question for future generations: As I presume that there are (or will be) several different images field types, wouldn’t it be better to keep the check more generic? The way I’ve suggested is working for me, but has the big drawback that every single field type must be explicitely listed – and you might never catch all of them. So is there a syntax for (in plain words) find('type=fields that are somehow managing images')?

  3. @Mike Rockett Thanks for your fast reply. It looks as if we’re getting closer: my images are of fieldtype CroppableImage3, resulting from the popular module with the same name. Do you think I could just change the field type where the check happens? Or extend the range of possible field types? I’m no big fan of module hacks, but in this case I could live with it. Would you mind to reveal the exact check location?

    Update: I’ve got the job done now – much easier than expected. Just in case somebody faces the same problem: in /site/modules/MarkupSitemap/MarkupSitemapConfig.php in line 90 I changed

    if ($imageFields = $this->fields->find('type=FieldtypeImage') and $imageFields->count) {

    to

    if ($imageFields = $this->fields->find('type=FieldtypeImage|FieldtypeCroppableImage3') and $imageFields->count) {

    to extend the range of considered field types. The option select appeared and everything works perfectly now. Another thanks for your help.

    • Thanks 1
  4. @Mike Rockett This is the way I would have assumed to go, unfortunately I can't find an option like the one you describe. On the module’s config page there are the following sections:

    Module information
    Templates with sitemap options
    Templates without sitemap options
    ISO code for default languages
    Stylesheet
    Support Development
    Deinstall

    Either I’m suffering from vision defects, or the mentioned option is missing.  (Or carefully hidden.)


     

  5. @Mike Rockett It seems as if I'm unable to include images in the sitemap. Besides that, the module is working just fine. I can find the option to exclude images (page-based) but neither the one to include them, nor do they get included automatically. I'm using only one images field in my template and the page is multilingual. Any hints what I'm doing wrong?

    Thanks.

  6. 9 hours ago, Sergio said:

    Found something different: my string-php.json file has two hyphens instead of 3 on the textdomain line, look:

    @Sergio A late Bingo! After a few hours of sleep I picked up your hint once more, although I still don’t understand what's going on with the hyphens. So I simply deleted the _strings.php of the translater and re-imported it. The number of hyphens appeared reduced and everything works now as expected. Another big thank you – the day is suddenly showing a much sunnier face as this little evil is defeated.

    • Like 1
  7. @Robin S Thanks for your recommendation. I installed TracyDebugger and spontaneously I'm a bit overwhelmed (it's long after midnight here and the fights did weaken me). Anyway, it's definitely a highly interesting tool that I will examine in detail soon.

    @Sergio You do lot of work to help me, that’s very friendly. Your secont hint could lead into the near of a solution, as I assume a problem with paths. Unfortunately I don’t understand the relation of the path in the function and the  number of hyphens the translator produces. Regarding my settings: before I tried the _strings.php method, I travelled the exhausting road of translating with __('term') file by file. That worked just fine, I only found it a bit too exhausting on the long run and started looking for a faster way (haha). So there might be something wrong with the settings, but it must be very subtile then.

  8. Hi guys,

    after hours of trying and reading several threads I suppose tears will start running soon.  I work with the widely spread and documented method of a _strings.php file and a t() function. Everything seeems to run fine, the translator finds the _strings file, all phrases are translated properly and no error messages are showing up. Except that no translatiions are shown at all, no matter what I do:  It's like a hopeless struggle with deceitful demons.

    My _init.php:

    include_once("./_func.php");
    include_once("./_strings.php");

    (in this order). Then in _func.php:

    function _t($text, $context, $textdomain = "/site/templates/_strings.php") {
        return _x($text, $context, $textdomain);
    }

    and in _strings.php:

    <?php namespace ProcessWire;
    /*
    _x('Home', 'generic');
    _x('/en/', 'generic');
    _x('Contact', 'footer');
    _x('/en/contact/', 'footer');
    _x('Other projects', 'footer');
    */
    ?>

    Trying to call the translations for example in the footer template like this:

    <li><a href='<?php echo _t('/en/contact/', 'footer'); ?>'><?php echo _t('Contact', 'footer'); ?></a></li>

    leads to this result , no matter what language is active.

    <li><a href='/en/contact/'>Contact</a></li>

    The translator has everything it needs:

    {
        "file": "site\/\/templates\/_strings.php",
        "textdomain": "site----templates--_strings-php",
        "translations": {
            "33fa1c21648d73e1ac14e0db66b4fa9e": {
                "text": "Start"
            },
            "2f73c44cbb8a98616f8aeca67192aec6": {
                "text": "\/de\/"
            },
            "77eb6543a21ba5c45f9c11f899136eee": {
                "text": "Kontakt"
            },
            "68780987fca9c3f52fb511f87cd43262": {
                "text": "\/de\/kontakt\/"
            },
            "184cf75de619c2e3a02a40f163c81c5e": {
                "text": "Weitere Projekte"
            }
        }
    }

    Obviously there seems to be a connection problem between the _func and the _strings file. Instead of $textdomain = '/site/templates/_strings.php' I can fill in whatever I want without any recognizable difference. Any hints what else I could try?

    Cheers
    Ralf

     

     

  9. Hi guys,

    I’m struggling with an annoying problem which I guess where it comes from, but can‘t find a way to get rid of it. When I try to preview hidden oder unpublished posts in the /kompendium/ category, I'll receive a 404 error, when I do the same thing with posts of other catgegories, everything works as expected. The only difference is an url thing I’ve bulit to shorten urls like /kompendium/entry to /entry/, while others are formed completely like /category/entry/.

    To enable this, I use the following code in my home template:

    <?php
    if (strlen($input->urlSegment2)) {
        // 2 segments => 404
        throw new Wire404Exception();
    }
    else if (strlen($input->urlSegment1)) {
        // 1 segment, check whether it exists in /kompendium/
        $name = $sanitizer->pageName($input->urlSegment1);
        $post = $pages->get("/kompendium/")->child("name=$name");
        // if so render /kompendium/name/
        if($post->id) {
            echo $post->render();
          }
          // else 404
          else {
              throw new Wire404Exception();
          }
          $render_homepage = "no";
    }
    
    if ($render_homepage != "no") {
    
    // render normal home content
    
    }
    ?>

    and in _init.php there is the following hook to ensure lists are generated in the wanted manner (all entries in /kompendium/ and only those work with template pg_entry)

    <?php
    ProcessWire\wire()->addHookBefore('Page::path', function($event) {
    	$page = $event->object;
    	if($page->template == 'pg_entry') {
    		$event->replace = true;
    		$event->return = "/$page->name/";
    	}
    });
    ?>

    So everything is fine beside the preview/404 problem with hidden/unpublished posts. As some of them show quite complex content, the preview funtion is important. Any hints, why it doesn’t work?

    Thanks
    Ralf

     

  10. 31 minutes ago, horst said:

    You definetly have to check the user rights. If you prviously used apache module, and afterwards changed to cgi mode, I bet that this are different users on the server. Common usage on shared hosts is, that php as apache module is a user something like wwwrun. As cgi version, mostly it is identical with your own ftp user. So, after you switched to cgi, all messages that say you don't have the access rights to the assets directory totally make sence!

    Thanks Horst for pointing to the right direction – after inspecting how to solve the problem concretely, I found a provider’s ReadMe telling me bascially the same. The offered options are exactly two: owner is either 'User' (Me) or 'PHP-User', named '33'. When I set the owner of /site/assets/ to 'User' (recursively), nobody will see not even a single image. Chosing the second option 'PHP-User', I receive the completety irritating require_once error (and nobody will see anything else at all). As there is no third option available I don’t see the right method to get it done.

  11. Hi guys,

    bad day today. I first updated PW to 3.0.42, everything went fine without any problem. Then I changed the PHP version of my (shared) server and the weirdness started:

    1. I switched from PHP 5.5 (Apache module) to 7.1 in CGI mode. There were a few minor issues with too less function parameters that I got fixed in minutes. The only real strange thing was that no images were shown anymore, neither in frontend nor in backend. Trying to call an image directly by it’s URL led to a 403 message, telling me  I don’t have access to the site/assets directory.

    2. To find out whether the problem is specific to PHP 7.1, I »downgraded« to 7.0 and 5.6 in CGI mode, both didn’t change anything.

    3. I finally »reset« everything to the 5.5 version as Apache mode again, now everything seems to be broken. In frontend I get

    Compile Error: require_once(): Failed opening required '~/site/modules/TextformatterTextile/src/Parser.php' (include_path='~/wire/modules/Markup/MarkupHTMLPurifier/htmlpurifier/standalone:.:/usr/share/php:..') (line 39 of ~/site/modules/TextformatterTextile/TextformatterTextileField.module)

    (The file is definitely there). In the backend I receive

    DirectoryIterator::__construct(~ /site/assets/files/1148/): failed to open dir: Permission denied The process returned no content.

    when I try to edit a page.

    There seems to be a serious permission problem, but I don’t know where to start. If nothing helps, I will ask my provider for a yesterday’s server backup, but I would prefer to understand at least the basics of what is going on.

    UPDATE: Meanwhile I returned to the PHP 7.1. update. At least this situation hasn’t changed: all is working well except the images are still missing, in frond- and backend as described above. The require_once errors are gone, so my ideal solution would be to stay with PHP 7.1. but with correctly displayed images.

  12. Okay, the job is done now. The final solution might not be too elegant, but it works exactly the way I want as I described it in the opening post. My search form has two additional selects: scope for setting the fields to search and mode for setting the search mode.

    kongondo and Robin S: I want to thank you once more – I wouldn't be where I am without your kind help.

    <?php
    
    if ($input->get->search_terms) {
        
        // ---- sanitizing text input -------------------------------------------------------
        $search_terms = $sanitizer->text($input->get->search_terms);
    
        // ---- getting desired search scope, default = title + body ------------------------
        if ($input->get->scope) {
            $scope = $input->get->scope;
        }
        else $scope = "t_body";
    
        // ---- getting desired search mode, default = AND ----------------------------------
        if ($input->get->mode) {
            $mode = $input->get->mode;
        }
        else $mode = "and";
    
        // ---- template and limit settings --------------------------------------------------
        $template = "pg_entry";
        $limit = 50;
        $selector_complete = ", template=".$template.", limit=".$limit;
            
        // ---- replace multiple spaces with single space
        $search_terms = preg_replace("/\s+/", " ", $search_terms);
        $terms = explode(" ", $search_terms);
    
        // ---- both scope options: search title ----------------------------------------
        // ---- mode: AND search
        if ($mode == "and") {
            $selector_1 = "(";
            foreach($terms as $term) {
                $selector_1 .= "title%=".$term.", ";
            }
            $selector_1 = substr($selector_1, 0, -2); // delete trailing comma and space                    
            $selector_1 .= ")";
        }
        // ---- mode: OR search
        else {
            $selector_1 = "title%=";
            foreach($terms as $term) {
                $selector_1 .= $term."|";
            }
            $selector_1 = substr($selector_1, 0, -1); // delete trailing pipe
            
        }
        // ---- adding template and limit values
        $selector_1 .= $selector_complete;
        
        // ---- scope: t_body, adding 2nd selector for body -----------------------------
        if ($scope == "t_body") {
        
            // ---- mode: AND search
            if ($mode == "and") {
                $selector_2 = "(";
                foreach($terms as $term) {
                    $selector_2 .= "body%=".$term.", ";
                    
                }
                // ---- delete trailing comma and space
                $selector_2 = substr($selector_2, 0, -2);                
                $selector_2 .= ")";
            }
            // ---- mode: OR search
            else {
                $selector_2 = "body%=";
                foreach($terms as $term) {
                    $selector_2 .= $term."|";
                }
                // ---- delete trailing pipe
                $selector_2 = substr($selector_2, 0, -1);
            }
            // ---- adding template and limit values
            $selector_2 .= $selector_complete;    
        }
        
        // ++++ matches for selector 1 (title) ++++++++++++++++++++++++++++++++++++++++++
        $matches = $pages->find($selector_1);
        
        // ++++ scope t_body && limit not reached yet: matches for selector 2 (body) ++++
        if ($matches->count < $limit && $scope == "t_body") {
            $body_matches = $pages->find($selector_2);
        } else {
            $body_matches = "";
        }
    
        // --- matches found in body
        if ($body_matches) {
            // ---- remove duplicates already in title matches
            $body_matches->removeItems($matches);
            // ---- add body_matches to matches
            $matches->import($body_matches);
        }
    
        // ++++ Output search result ++++++++++++++++++++++++++++++++++++++++++++++++++++
        if ($matches->count) {
    
            foreach($matches as $match) {
                // Output matches
            }
        }
        else {
             // Output no matches
        }
    }
    else {
         // Output no search term(s)
    }
    
    ?>

     

    • Like 1
  13. Hi guys,

    I would like to realize a search function on my site that follows some clear rules:

    1 – Search is performed in the two fields 'tite' and 'body'.
    2 – If a user searches for 'foo' and 'bar' he can select whether both terms have to be in at least one of the fields (AND) or at least one of the terms has to be in at least one of the fields (OR).
    3 – 'foo' should match words like 'food' or 'foolish' as well as 'foo' (LIKE).
    4 – Search results where 'foo' or 'bar' are found in the title should be displayed first, followed by the results found in 'body' only.

    This is what I have:

    <?php
    
    if($input->get->q) {
        $q = $sanitizer->text($input->get->q);
        if($q) {
            $input->whitelist('q', $q);
            $qs = explode(" ", $q);
            
            foreach($qs as $key => $q) :
                  $qs[$key] = $sanitizer->selectorValue($q);
            endforeach;
            
            $selector1 = "title%=".implode("|", $qs).", template=entry, limit=50";
            $selector2 = "body%=".implode("|", $qs).", template=entry, limit=50";
            
            // Trying to separate 'important' title matches from 'less important' body matches
            $matches = $pages->find($selector1);
            if ($matches->count) < $limit)) $matches->import($pages->find($selector2));
    
            if ($matches->count) {        
                foreach($matches as $m) :
                    
                    // Output matches title & body excerpt
    
                endforeach;
            }
            else {
                // Output no matches
            }
        }
    }
    else {
        // Output no search term(s)
    }
    
    ?>

    First problem is regarding rule 2: I don’t know how to do an AND search. As far as I can see, it’s always an OR.

    Second problem is the order of the search results (rule 4): I split the queries to separate them nicely, but they appear mixed up. Output starts with a few title matches as I would expect, followed by some body matches, then some further title matches appears. I don’t understand how this happens:

    $matches->import

    adds array 2 to array 1 without mixing them, isn’t that true?

    And just in case I will get the job done someday: how could I avoid doubled matches? Matches in body aren’t that interesting anymore, when the terms was already found in the title field.

    I will appreciate any helping hand – thanks.
    Ralf

  14. blynx,

    your solution is definitely ingenious – in total and detail! I played around with all parts and everything was working immediately without any issues. Standing ovations!

    What I like the most is the relation of maximum result with minimum effort – this reveals true masters. To get the synonym and sync problem solved with a few lines of code in very short time is more than I dared to dream of.  So another giant thank you!

    • Like 2
  15. Okay, I’m nearly convinced now. The steps you outlined in your last paragraph seem to be the most plausible way to get where I want to. Sadly, I found another stumbling stone in the meantime: the tags. There will hardly be the need to list all database entries, the most frequent rendered lists will be search results and entries matching tag X. Approximately I will exclude synonym pages from the search, so the main problem will be the tags. If 'plane' is tagged with 'traffic' and 'transport', the synonyms 'ufo' and 'flying saucer' should be tagged with both tags too. So I should better not only give the synonym page a parent field, but a tags field too. Which leads me to hopefully my last questions:

    Is it possible to sync the content of the tag field like the following?

    • Creating a new synonym creates the according synonym page and copies the content of the root entry’s tags field to the synonym’s tag field.
    • When editing the tags field content of the root entry, all connected synonym tag fields get updated too.

    You mentioned the option to create links to parent pages automatically via hook. How do I do this? In case of the tags I work with the 'page' field type and unfotunately I don’t know how to run automated tasks when filling a field with content. Where should the hook function reside?

    Edit – a few hours later

    Meanwhile I’ve read (nearly) everything about hooks and where to place them. I think I will get the autolinks done as well as the tag syncs, so both questions are answered. I want to thank you again, blynx – you showed a lot of patience and helped me a whole piece further, that was very friendly.

    • Like 1
  16. 2 hours ago, blynx said:
    
    <?php
    $pages->find("synonyms*=requested_synonym") // or ->get()

    It'll basically just be like tagging and one doesn't have to think much about those tag / synonym pages. They can be hidden somewhere. Finding correlating pages would work like above. (Not sure about the *= though, works with just = on a setup I have). This might also prevent you from some errors since every synonym is an actual entity in the system.

    Thank you very much bIynx,

    'tags' is a very good keyword, as I work with them already in the way you described. Indeed I could organize the synonyms with a field that actually creates pages. The result would be the load of additional pages I wanted to avoid, but they get built automatically and always stay 'connected' with their root page. Means: I’ll seldomly see them and so they don’t have to bother me, beside the fact they are there. You’re sure there is no downside keeping thousands of extra pages?

    Another question regarding the list structure of my opening post: My list selector would be posts of types 'entries' and 'synonyms' in alphabetical order. Depending on the type, the list item would either be a direct link or a reference link synonym → entry page. But how does the synonym page know where to link as I never touched it? In other words: I don’t fully understand what your code line exactly does.

  17. Hi Guys,

    I’m working on kind of an encyclopedic website and there is a problem, I’m trying to find an intelligent way to solve it. Until now, I can only think of a less intelligent way and would be glad to hear your ideas, whether and how it could be done.

    It’s about listing pages. Each encyclopedic term is represented by a page, so basic listing of term entries is easy. What I would like to get managed is also listing synonyms or similarities to terms. Let’s say we have the main terms 'car', 'ship' and 'plane' and a page for each of them. For 'car' let’s take 'automobile' and 'vehicle' as synonyms and for 'plane' we have 'jet' and 'aircraft'. Differently to terms, synonyms don’t have pages but only references to terms/pages. The alphatbetic list would be:

    Of course I could manage it with a page type 'synonym'. Pages of that type would exist without content and just do redirects or similar. That would be the less intelligent way I mentioned above. As there will be several thousand of main terms/pages, there might soon be three oder four times more pages, just for handling synonyms of minor importance. At least to me this seems to be a bit confused.

    I’m dreaming of solving it with a field 'synonyms' that contains a synonym array of arbitrary length. The alphabtetic list would be a mixture of pages and fields showing to their parent page. Sadly I have no idea if this is doable and where to start, if so.

    Any hints anybody?

    Thanks for your time and help,
    Ralf

  18. @LostKobrakai: No, I don’t use $page-> viewable – there must be another issue.

    @Robin S & diogo: I filled in the line you suggested and now everything works the way I was searching for. (Okay, I don’t have a clue what the line actually does, but as a newbie there must be some learning potential left.)

    So big thanks to all of you for your kind answers, you were enormously helpful.

    Ralf

    • Like 2
  19. Hi guys,

    I'm a Processwire-Newbie and new to this forum. Happily I have to struggle with very few difficulties, thanks to the clear and pleasing concept and structure of PW. Currently there is only one thing that makes me brood:

    I have a main category 'posts' that contains the majority of all pages. So the regular url would be 'domain/posts/post-one' etc. As I prefer the url scheme 'domain/post-one' I followed the instructions discussed in this topic.

    This hook is in my 'init.php':

    wire()->addHookBefore('Page::path', function($event) {
      $page = $event->object;
      if($page->template == 'post') {
        $event->replace = true;
        $event->return = "/$page->name/";
      }
    });

    And this is in my 'home' template:

    if(strlen($input->urlSegment2)) {
        throw new Wire404Exception();
    }
    else if(strlen($input->urlSegment1)) {
        $input->urlSegment1;
        $name = $sanitizer->pageName($input->urlSegment1);
        $post = $pages->get("/posts/")->child("name=$name");      
        if($post->id) echo $post->render();
        else throw new Wire404Exception();
          $renderMain = false;
    } else {
      // regular homepage output
      $posts = $pages->find("parent=/posts/, limit=$limit, sort=-date");
      $body = renderPosts($posts);
    }

    Both templates 'home' and 'post' have 'url segments' option activated.

    On the first sight everything is working fine. $page-name outputs '/domain/post-one' and the page '/domain/post-one' ist getting displayed. What's frighening me is the fact, that 'domain/posts/post-one' is working as well. This means 'post-one' can be adressed with two different urls, and I’m not sure how to rate that.

    On one hand, nobody will ever notice the '/domain/posts/page-one' option, as it's listed nowhere. So I could just ignore it. On the other hand, I don't know for sure if this presumption is correct. Maybe there are unknown channels where the 'wrong' urls will be spreaded, then there will be 'doubled content' which is bad, as far as  I know.

    So what I'm asking for: Is there an easy way to avoid the double url-scheme option and output a 404 error, when 'domain/posts/page-one' is called? Or should I just don't care, as it doesn't matter a all? Unfortunately, I don’t fully understand every line of the second code, so I would be very grateful if someone could light it up for me a bit.

    Thanks + regards
    Ralf

×
×
  • Create New...