Jump to content

Jan Romero

Members
  • Posts

    680
  • Joined

  • Last visited

  • Days Won

    18

Everything posted by Jan Romero

  1. 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?
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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}");
  7. 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.
  8. 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.
  9. 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
  10. 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.
  11. 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...
  12. 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.
  13. 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);
  14. I take it you don’t want to show the date the page was created? That would be $page->created. $page->sort gives you the zero-based sort index, but it’s only unique in relation to the parent. This might be the closest to your requirement. $page->id is not necessarily consecutive and starts at 1000, but it’s unique site wide. I believe ProcessWire doesn’t reuse deleted IDs, so they should reflect the order of page creation. However, every new admin page and repeater item will increase this number. Do with that what you will.
  15. I assume you have a special template for /functions/ and you have set up your config.php to auto-append _main.php. You can exclude templates from auto-appending and auto-prepending in the “files” tab of the template settings. If auto-append is active, there will be a checkbox called “Disable automatic append of file: _main.php”. Regardless, it’s always a good idea to die() as soon as possible. In your case, I would advocate putting a die() at the end of each if ($command ...) block, unless there’s something you need to do afterwards. Probably a good idea to use a switch, too, then.
  16. Sure, just link to the page without the GET parameters, check if they’re in $input->get or not, and build (or omit) your selector strings accordingly. I’m sure you can figure it out By the way, you should read up on sanitizers and use them with $input, because you’re essentially letting anyone modify the variables in your PHP script now.
  17. Oh, nah, $city is just a page object and weather is a field. The sample was taken out of a foreach loop. To set the city id via API, you can do $page->weather = 12345 and save the page/field.
  18. Ooooh, I didn't know about $input->it. That's awesome. Where does it come from, though?! I've never seen it anywhere. Where in the core is it prepared?
  19. Your code looks very mixed up. We’ll assume that we’re working on the parent page of Bassisten, Fluitisten, and Trombonisten. Thus, those three pages are in $page->children. We’ll refer to them as $categories. Each category has a number of artists as its children (grandchildren of $page). Each category should have one <ul> element containing the artists. We’ll call an artist page $muzikant and create an <li> element. First of all, let’s get the categories. Create a $categories variable and fill it with the children of $page. $categories = $page->children(); Now loop over these categories and create a <ul> for each one. foreach($categories as $category) { echo "<h3>$category->title</h3>"; echo '<ul>'; echo '</ul>'; } Inside the foreach we now have the variable $category, which refers to a single category. Let’s get its children and call them $muzikanten. Then loop over $muzikanten the same way and echo <li>s. Our complete code now looks like this: $categories = $page->children(); foreach($categories as $category) { echo "<h3>$category->title</h3>"; echo '<ul>'; $muzikanten = $category->children(); foreach($muzikanten as $muzikant) { echo "<li>$muzikant->title</li>"; } echo '</ul>'; } This should just give us all the categories and all the artists in whatever order they come in. To get only one specific category, we need a selector. If you’re unfamiliar with selector strings, take a quick look at the docs. We’re going to use the "sort=" selector to order our $muzikanten, and the "name=" selector to filter the $categories. For example, to get only Bassisten, the selector would be "name=bassisten" (provided that’s the actual name of the page). Let’s put that between the parentheses of $page->children(): $categories = $page->children("name=bassisten"); Now the page shows only Bassisten, but there’s still no order (probably). To sort, we have to know by which field to sort. We’ll use the title field. The selector for that is "sort=title". To sort Z-A instead of A-Z, it would be "sort=-title", with a minus/hyphen symbol. So we have: $categories = $page->children("name=bassisten"); foreach($categories as $category) { echo "<h3>$category->title</h3>"; echo '<ul>'; $muzikanten = $category->children("sort=title"); foreach($muzikanten as $muzikant) { echo "<li>$muzikant->title</li>"; } echo '</ul>'; } The next step would be to use $input->get to determine what goes into our selectors. Let’s assume our address should look like this at the end: ?selectedcategory=bassisten&sortby=-title (You will want to do this differently in reality, but let’s roll with it for now) As soon as you add that part to the address in your browser, $input->get will have two new properties: selectedcategory and sortby. Store them in some variables. $selectedCategory = $input->get->selectedcategory; $sortby = $input->get->sortby; Now we can use these variables inside our selector strings. Our finished code: $selectedCategory = $input->get->selectedcategory; $sortby = $input->get->sortby; $categories = $page->children("name=$selectedCategory"); foreach($categories as $category) { echo "<h3>$category->title</h3>"; echo '<ul>'; $muzikanten = $category->children("sort=$sortby"); foreach($muzikanten as $muzikant) { echo "<li>$muzikant->title</li>"; } echo '</ul>'; }
  20. It’s only visible to accounts that have a license and if I recall correctly, you have to renew your license to get access (i. e. support) annually. Renewal is not required to use the module itself, only for continual support 1 year after the purchase. If you didn’t buy it, you should probably talk to Ryan and the person who did, in order to transfer the license?
  21. I just tested it and I think this is what you want. Here’s a complete demo module: class NotFoundIntercept extends Wire implements Module { public static function getModuleInfo() { return array( 'title' => 'Not Found Intercept ', 'version' => 001, 'summary' => 'Hooks into pageNotFound so you can handle URLs that don’t belong to any page.', 'href' => 'https://processwire.com/talk/topic/8510-module-intercept-ajax-call/', 'autoload' => true, ); } public function init() { wire()->addHook('ProcessPageView::pageNotFound', $this, 'intercept404'); } protected function intercept404($event) { $url = $event->arguments('url'); if ($url != '/my_pseudo_page/') return; //Let pageNotFound() handle it header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK', true, 200); $name = $_GET['name']; if ($name) die("Hola $name! Como estas?"); else die("Sup, guest?"); } } Now you can open ejemplo.es/my_pseudo_page/?name=Manol and – provided that page doesn’t exist in PW – it will greet you. Of course, if the front page has urlSegments enabled, it will just accept that instead, and your module won’t be triggered...
  22. I like GET because it’s associative and order independent and doesn’t care about missing values. They’re different tools for different jobs ¯\(ツ)/¯
  23. (On mobile, haven’t tested) Maybe try hooking into ___PageNotFound() in ProcessPageView. It gives you the requested URL, so you can check if that’s what your module expects and process it. That way your module could remain self-contained. If $input isn’t populated at that point, you should always be able to go through $_POST.
  24. Whoops, sorry, I’m embarrassed. I only skimmed the code samples. @Manol: if I understand correctly, you want to create this “pseudo page” (web-accessible, but not any distinct file or PW page) from within your module?
×
×
  • Create New...