Jump to content

ryan

Administrators
  • Posts

    16,772
  • Joined

  • Last visited

  • Days Won

    1,530

Everything posted by ryan

  1. Actually $file->basename is there too. It's the same thing as $file->name. The $file->name is mainly there for consistency with other PW objects, in that we want everything in ProcessWire to reliably have a 'name' property. But I usually use $file->basename myself.
  2. When I post code in here, I'm usually writing it in the browser. That means it's a starting point that may need testing and debugging, rather than a full working solution. Those error messages should help to get to the bottom of it, but I think we need to see the code that is actually in use. Can you post or paste the file here?
  3. I've been working on something similar recently too. Let us know how it goes and if you run into any issues.
  4. LanguageSupport is a core module and has to be upgraded with the rest of the core. So make sure you are replacing your entire /wire/ directory, and not just /wire/modules/LanguagesSupport/. Most likely you didn't see the checkboxes because they are a component of InputfieldPageName. But don't just go upgrade that module–upgrade the entire core.
  5. I haven't tried this module with languages support, but thanks for letting me know that they are not compatible. You should be able to retrieve the $languages API variable via the wire() function, i.e. wire('languages') or wire()->languages are both valid syntax. $languages is a PageArray and can be iterated. Multi-language field types implement FieldtypeLanguageInterface. If you wanted to find all multi-language fields in the system, you could do this: foreach(wire('fields') as $field) { if($field->type instanceof FieldtypeLanguageInterface) { // this is a multi-language field } } Something else to mention about multi-language fields (all of which are text-based, currently) is that their value is actually an object of type LanguagePageFieldValue, rather than a string of text. Its __toString() value is reflective of the user's current language. When outputFormatting is on (as it is on the front-end), it is converted to a string automatically. But when outputFormatting is off (as it is in the admin) the value is a LanguagesPageFieldValue object. There is also another type of multi-language field known as a Multi-language alternate field.These are quite a bit simpler in that they are just a regular field with any fieldtype. But they are recognized as multi-language by name convention. If you have a field named "myfield" and another named "myfield_es", and you have a language installed named "es", then "myfield_es" is assumed to be the Spanish version of "myfield", while "myfield" is assumed to be the default language version. On the front-end (outputFormatting on) ProcessWire knows to substitute one for the other when the user's language matches the field name. If there is a lot of code involved in configuration of an autoload module, then I prefer to put it in a separate file so that it's not taking up any memory for the non-admin requests that don't need it.
  6. I think I understand the request, but feel this probably belongs as a module since it such a specific need. My opinion has always been that the core should only have features that would be regularly used in at least 30% of installations. Otherwise we run the risk of having too much, over-configuration, etc. There are actually some modules we now have in the core that aren't used in at least 30% of installations (anyone ever used FieldtypeCache or some of the lesser known Textformatter modules we include?), so these will likely be moved out of the core in an upcoming version of PW. When it comes to meeting specific needs, I prefer to update the core to add new hooks where necessary (for modules) rather than adding new functionality or configuration. I think your case is one that does sound like a useful capability, but I'd prefer to assist you in implementing it as a module rather than adding it to the core. I'm sure some others will find it useful too, so would like to see it in the modules directory too.
  7. Whenever I run into strange errors like this, I clear the APC cache. And it usually fixes it. It sounds like that probably wasn't the issue in your case, but I have found that APC (or other PHP opcode caches) occasionally get confused and need to be cleared.
  8. JqueryWireTabs also has an associated JS and CSS file, so you'll want your template to include those: <?php $modules->get('JqueryWireTabs'); ?> <link rel='stylesheet' type='text/css' href='<?=$config->urls->JqueryWireTabs?>JqueryWireTabs.css' /> <script src='<?=$config->urls->JqueryWireTabs?>JqueryWireTabs.js'></script> Or you can do this, since JqueryWireTabs populates $config->scripts and $config->styles with the right entries (as do most PW modules that use CSS/JS): <?php $modules->get('JqueryWireTabs'); foreach($config->styles as $url) echo "<link rel='stylesheet' type='text/css' href='$url' />"; foreach($config->scripts as $url) echo "<script src='$url'></script>"; ?>
  9. Something to add to WillyC's example is checking whether the given page is active for the language. This is only necessary if you are selectively having some pages published in one language and not in another (meaning, you are using the "active" checkboxes to the right of the language-specific page names). echo "<ul>"; foreach($languages as $language) { if(!$page->viewable($language)) continue; // check if page not published for this language $class = "$language" == "$user->language" ? "active" : ""; $url = $page->localUrl($language); echo "<li class='$class'><a href='$url'>$language->title</a></li>"; } echo "</ul>"; The only change I added above was the if(!$page->viewable($language)) continue; That makes it skip over languages that aren't published for $page. If that check weren't there, then the user would just see a 404 page when attempting to view in the unpublished language.
  10. The only two of those that are PHP functions are dirname() and basename(). As far as I know, filename() and extension() are not PHP functions? So I'm not sure what you mean when you say "emulation of PHP's filename which returns the basename without the extension"? But I think I can tell you how to get the result you asked for of "basename without extension": echo basename($file->filename, '.jpg'); // substitute .jpg with extension you want to remove.
  11. It's not a bad idea to throw a 404 in that condition. Though the only way someone could access such a page is by manually editing the address bar URL. But if you want to account for it, here's how you could do it: $results = $pages->find("your selector goes here"); if($input->pageNum > 1 && !count($results)) throw new Wire404Exception();
  12. See the custom options reference on this page: http://processwire.com/api/modules/markup-pager-nav/ Though if you are just trying to wrap the pagination with a div, then you could also just wrap the output that it returns to you. The FieldtypeComments::findComments() function was added in 2.2.9.
  13. Sounds like you've got it right.
  14. Nothing will be as fast as going straight to a dedicated targeted SQL query like that. But if you wanted to use PW selectors, this is still quite fast: for($n = ord('A'); $n <= ord('Z'); $n++) { $letter = chr($n); $cnt = $pages->count("surname^=$letter"); echo "<li>$letter - $cnt people</li>"; }
  15. Global shouldn't be used with repeaters. Sorry guys, I thought I had that option disabled. I will fix.
  16. Manual sorting is intended for reasonably sized lists, like navigation. For large groups of pages that have a chronological basis, you should always use some kind of date sorting. If you need to go outside that in certain instances, then add a "sticky" or "featured" checkbox, so that the client can override what gets shown first on the front-end when they want to. For example, if we wanted to retrieve a list of all news articles by date, but with "featured" ones showing up first, we could do this: $articles = $pages->find("template=article, sort=-featured, sort=-date");
  17. Here you go: http://modules.processwire.com/modules/fieldtype-text-unique/
  18. I've looked into this, and don't think it's got anything to do with use of a language pack or admin theme. I tried executing the query manually in PhpMyAdmin and MySQL simply doesn't trigger an error when inserting duplicate values. It just skips the query. Maybe there are some conditions under which it will report an error, but not that I could find. I think the problem is that the query for inserting/updating fields looks like this: The "ON DUPLICATE KEY" part is where it's at. But we need that, otherwise we'd have to add another select to every insert/update just to see if something is already present. So it looks like any future fieldtype that supports a UNIQUE index would have to implement it's own savePageField() method with some more overhead to check things out and decide whether to insert or update. As a result, you can have a UNIQUE index right now, but it's just being enforced rather than reported. But making a new FieldtypeTextUnique or something like that would be a way to solve it pretty easily.
  19. Blowfish hashing was added to PHP in 5.3, so any version 5.3 and newer supports it. However, a security problem was found in versions of PHP 5.3 prior to 5.3.7, so they fixed it. Newer versions of PHP are still compatible with the old, but versions prior to 5.3.7 are not compatible with passwords generated on newer versions of PHP. Since your host is using PHP 5.3.3, this is likely why you ran into an issue. But a commercial hosting provider should probably not be using a PHP version earlier than 5.3.7 due to that security issue. So the workaround is probably not a good idea since it is circumventing that. I strongly recommend asking your host to upgrade the PHP version.
  20. For storing that scale of data, I think you'd want to have your module create it's own DB table(s) to store it in. Several modules do this. They create their tables via the __install() method, and drop them via the __uninstall() method.
  21. While I don't understand what WillyC is saying, his code is correct. Try "body%=grass, body%=seed" so that you are requiring both terms to be present somewhere in the target text. While that would match 'grasses' and 'seeding', it would also match 'seagrass' and 'birdseed', which you may not want. In that case, you would want to replace the %= with *=, which will use the fulltext index. Because the individual words are indexed, it would match 'grasses' and 'seeding', but not 'seagrass' and 'birdseed'. Also your raw SQL would not work because it would only find fields that begin with the word "grass" AND "seed" – an impossible condition.
  22. Soma, while I wasn't able to duplicate that here, I was able to find a bug when using just parent.title, so I'm wondering if it might also be responsible for the result you were getting. Can you try the latest dev branch and let me know if you are still experiencing the error?
  23. This is true as the requests are delivered as static HTML files. So it doesn't touch the DB unless the request isn't cached. It is a great way to let your server handle a lot more traffic. But regardless of what caching is in place, if you start to see a "too many connections" message regularly, then it's time to talk to your web host to see if the amount of traffic you are getting would benefit from a higher-end hosting plan. There are also cases with some web hosts where the resources are simply oversold and you might see those kinds of MySQL error messages even if you aren't getting a lot of traffic. In those cases, it's a good idea to find a new web host.
  24. You can get by without the symlinks option. It's there because I tend to make regular use of symlinks, and am guessing others do too. But nothing in PW actually requires it.
  25. If something triggers a fatal error, then the save can't be performed. Attempting to move a page somewhere that it's not allowed aborts the save. Also, template changes are confirmed with the user if the new template contains different fields. As a result, it has to be handled as a separate operation.
×
×
  • Create New...