Jump to content

Jan Romero

Members
  • Posts

    612
  • Joined

  • Last visited

  • Days Won

    15

Everything posted by Jan Romero

  1. Behold: http://www.microsoft.com/en-us/download/details.aspx?id=22339 How do you think I use typographic quotes in nearly all my posts
  2. There is no space because you didn’t put one there Why not do $partone . ' ' . $parttwo? Edit: Also, upvote for using a proper ellipse char.
  3. This is a feature of PHP. String literals with double quotes (") will evaluate the variables within. For clarity, you could also enclose the variable in curly brackets ({}) like so: echo "You must be the pride of {$subject_hometown}!"; Only if you use single quotes (') the string will be parsed as-is, and you must use concatenation or other string operations to change it. Note that this means that within single quotes, escape sequences will not work either, so you can’t do the following, even though there are no variables in there: echo '\r'; ---- Added by Nico: More infos: http://stackoverflow.com/questions/10512452/php-using-a-variable-inside-a-double-quotes (and I marked it as solved)
  4. An image is a already separate file from the HTML page, so it will be served independently anyways. You can keep the HTML img tag static and just swap out the image by doing something like this: <img src="/penguin/?of=d00m.jpg" /> <?php if ($input->get->of == 'd00m.jpg') { header("Content-type: image/jpeg"); readfile($page->pics->getRandom()->size(50,50)->url); die(); } Pros: – that url serves a random image every time, no matter how you access it Cons: – the url serves a random image every time, no matter how you access it I’m not really sure how this technique competes against a JS solution, but it’s an approach you can take.
  5. Put "die();" after "echo json_encode($json);"?
  6. Does your problem persist after removing the dependency, logging out and back in again? If I do that, the error is gone. It seems that the error just doesn’t get cleared properly. To fix this right now, you can hack the core. Open the file wire/modules/Process/ProcessProfile/ProcessProfile.module and change the following line: if(count($form->getErrors())) { To this: if(count($form->getErrors(true))) { The argument clears the errors that occurred during form validation. It should be safe. The errors are not used anywhere else as far as I can tell. Instead of hacking the core directly, it’s probably better to use the new multiple-modules feature. Funnily enough, Ryan uses the exact same file as an example in his blog post.
  7. Yeah, I just added a bogus display dependency to my own page field and now I’m pretty sure I’ve screwed my site up the same way as yours I’ll try to track it down tomorrow. Steps to reproduce: Add page field to user template (works) Enable it for profile editing (works) Set a dependency (Profile not saved error) To confirm what you’ve already said, removing the dependency doesn’t work. Even removing the field from the template, clearing all values doesn’t work. Neither does re-adding the field. Pretty nasty, this.
  8. “Profile not saved” usually happens when you have invalid input in one of your fields. I can assure you that adding fields to the user template as well as letting users edit them from their profiles works fine. Even with page-select fields. Unfortunately, it working well makes it hard for us to reproduce your error, and it’s hard to debug it over the internet with such a vague error message. I’m sure it will get solved in time. Can you tell us exactly what fields you added and how they’re configured? Also, perhaps looking at the current values of these fields on the database might give you a clue?
  9. You don’t have to get all pages in one go. Just keep it simple. LostKobrakai is showing a good solution where he looks at each design principle and only gets the pages that belong to it. I would like to suggest one minor improvement: Before you build the markup, you should check whether you actually found some pages. You might come across an empty category with no links, which might look awkward. Also, when you put a hyphen before the reading time, it makes it look like a negative number. Try ' &endash; ' or '&emdash;'. Those are the – much nicer looking – dashes I’m using here. To answer your follow up question, look at how LostKobrakai handles all design principles individually, by putting each one into the variable $category one after the other. What you want to find are readings that have the current $category page as their design principle, not the previous. Try this: "template=readings, design_principle=$category"
  10. If you find() a limited number of pages anyway, it probably won’t get any more performant than getTotal(), at least without venturing into hacky territory or cache-like approaches like LostKobrakai’s suggestion. In this case, the PageArray returned from find() already has the total count ready for you, because it uses MySQL’s SQL_CALC_FOUND_ROWS by default! In fact, you can influence this by passing an options array to find() that recognizes the following keys: /*@param array $options - findOne: boolean - apply optimizations for finding a single page and include pages with 'hidden' status (default: false) - getTotal: boolean - whether to set returning PageArray's "total" property (default: true except when findOne=true) - loadPages: boolean - whether to populate the returned PageArray with found pages (default: true). The only reason why you'd want to change this to false would be if you only needed the count details from the PageArray: getTotal(), getStart(), getLimit, etc. This is intended as an optimization for Pages::count(). - caller: string - optional name of calling function, for debugging purposes, i.e. pages.count*/ As you can see, if you do a find(), you get the “numTotal” property for free, and if you just want the number of pages without fetching the actual page objects, $pages->count() will do an SQL COUNT with little overhead. If you want to squeeze performance out of your site, this is probably one of the less worthwhile places to start. edit: by the way, you can see the numTotal property of your PageArrays by var_dump()ing them. It’s one of the first properties it lists.
  11. The third forum down is literally called wishlist It has been suggested before to make add the German umlauts as defaults, which won’t happen because plenty other languages use ä, ö, ü, and they use the normal trema-less characters instead of the German -e combinations. Not sure why ß isn’t in there, though.
  12. Multi-language support has been in the core for a while now. The docs are quite comprehensive on the subject. Is there anything specific that you need help with?
  13. So I thought that string trick was neat and googled it. Since this topic is solved, it might be of interest that this SO thread suggests using array_flip() and imploding the keys instead, because array_unique() sorts the array first, and thus runs a lot slower. http://stackoverflow.com/a/5134212 Array_flip() swaps the keys and values of the array, thereby eliminating duplicates. Of course this comes at the price of some legibility. Just a tidbit, but seems useful if you do this kind of stuff, especially with large n.
  14. Hmm, have you checked the settings of your frontpage? Are the language paths set and active? Could it be the frontpage has a child by the name “en” that gets precedence over the language prefix and throws a 404 (for example, if there is no template file)? edit: actually, nevermind. I tested this and it doesn’t fail the way you described. At least for me.
  15. Have you read this article on Multi-Site development with PW (I haven’t)? I also imagine you might want to check out bootstrapping. For example, you could hook into page save in your master site and then call the other ProcessWire installations and update stuff there. Or do it the other way around and have your “sub-sites” fetch content from the master site.
  16. If you want to filter content while staying on the same page, you’ll have to use Javascript. Peter posted a good approach you can use. Here is another jQuery library that can do what you want: https://mixitup.kunkalabs.com/. If you know a bit of Javascript/jQuery, it shouldn’t be too hard to build yourself, either. Basically, the idea is to tag your content with a class and then filter by that. For example: $clients = $page->children(); echo '<ul>'; foreach ($clients as $client) { //This creates a string of category-IDs. If this client has 3 categories, it may look like "1099 1350 9001". $classes = $client->categories->implode(' ', 'id'); echo "<li class='{$classes}'>{$client->title}</li>"; } echo '</ul>'; So now you have a list of clients that each belong to some classes. You make a couple of links or buttons to filter by these classes. We recognize the items by the page-ID that is in their classes, but we have to tell the button which ID it should filter, so we put the ID in the id tag. $categories = $pages->find('parent=/categories/'); foreach ($categories as $cat) { echo "<a href='#' id='{$cat->id}' class='filterbutton'>{$cat->title}</a>"; } You use jQuery to remove all elements that don’t belong to the selected class: <script type="text/javascript"> $(document).ready(function(){ //When one of the buttons was clicked, run the function $('.filterbutton').click(filter); function filter(event) { //First, hide everything. $('li').hide(); //Get class you want to show from the button’s id attribute var class = $(this).attr('id'); //Show all items that have this class $('li.' + class).show(); } } </script> This is pretty crude and not guaranteed to work or work correctly. Just use it as a base to build from.
  17. Make a template file for your categories. Inside that template file, the $page will be a category. Now you find all projects that have this category selected in the page field. Assuming the page field is called “cat” and the project template is “Project”: $projects = $pages->find("template=Project, cat={$page}");
  18. Must be a problem with your image field. Have you tried $language->icon->first->url? $language->icon can be different things depending on how you set up the field. In the field settings for icon, look under “Formatted Value”. There you can choose what you want $language->icon to return.
  19. Like everything else, languages are just pages that have their own template. Under Templates, select “show system templates”. There will be a template called “language” which you can modify like any other. Just add your field to it and it will work.
  20. It’s not Processwire that does that, though. It’s your browser. Any link without the scheme will be treated as local. Check this one: strabic.fr/Adobe-le-creatif-au-pouvoir
  21. If you compare the link on your site with the example you posted in the OP, you will see the problem. It’s missing the scheme part http://. If you add that it should work.
  22. The current page is always $page (you can assign something else to $page, but it's not a good idea). This means you can check if the page you are currently adding to the menu is the same as $page. Then you can modify the output accordingly. For example: foreach($page->menu_page as $item) { $activeclass = ($item == $page) ? 'active current' : ''; //If this is the page we are viewing, add the classes. Otherwise use ''. $out .= "<li class='top {$activeclass}'><a href='#'>{$item->title}</a>"; } If you want the parent pages to be highlighted in your multi-level menu as well, you can check if they're in $page->parents. $parents = $page->parents; foreach($page->menu_page as $item) { $parentclass = ($parents->has($item)) ? 'active' : ''; //If this is a parent of the page we are viewing, add the class. $activeclass = ($item == $page) ? 'current' : ''; //If this is the page we are viewing, add the classes. Otherwise use ''. $out .= "<li class='top {$activeclass} {$parentclass}'><a href='#'>{$item->title}</a>"; } Or something like that...
  23. WireSendFile exits unless you set 'exit' to false in the options parameter. Sorry I didn't pick up on that earlier. I never used that function... Try $opts = array('exit' => false); wireSendFile($f, $opts); It's kind of unfortunate that one has to read the code to learn a lot of PW's features, but I can only recommend it. It's well documented and well written, so it's quite easy to read.
  24. Because of the $, $download_counter is a variable here. You’re not accessing the page field “download_counter”, but a field by the name of whatever that variable contains. You should also disable output formatting before modifying a field. Use $page->setOutputFormatting(false) or $page->of(false). Lastly, it’s possible to save just the field by calling $page->save('download_counter'). Untested: wireSendFile($page->download_file_link); $page->of(false); $page->download_counter = $page->download_counter + 1; $page->save('download_counter'); $page->of(true);
×
×
  • Create New...