Jump to content

Leftfield

Members
  • Content Count

    31
  • Joined

  • Last visited

Community Reputation

9 Neutral

About Leftfield

  • Rank
    Jr. Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hi @All, When I turn on cache, the map is blank. What variable should I exclude or...!?
  2. Attached files are updated. Keep in mind that home.php and one search.php are in views/ folder. Hi @All. I am making real estate website with map leaflet module. Please keep in mind that I do SEO and SEM and I am NOT an expert in PHP, so if you find anything that could be better or pit-a-pat, please, please fix and comment. Many tricks learned throw @OLSA coding so thank You my great friend. Explanation: I am using template/view folder for logic = separate code and design. Calls for my fields are included in files attached to the post. Hope you'll get the idea. what I have done All of this is preliminary code which will be speeded up but it is working. Not finished but must have: search button on the home if ajax is not working. _main.php file has: include('views/' . $page->template->name . '.php'); but it doesnt have any influence on this code. Just saying if I update this. So, here are parts views/home.php <?php $izdvojene = wire('pages')->find('template=property, state=featured|new, sort=-date, limit=6'); ?> <div id="sadrzaj"> <div id="rezultati"> <?php foreach($izdvojene as $item) : ?> <div class="trecina nekretnina" data-link="<?= $item->url ?>"> <div class="slika"> <img src="<?= $item->images->eq(0)->size(346,220)->url; ?>" alt="<?= $item->images->eq(0)->description ?>" /> <div class="stanje"> <?php $state = $item->state; if ($state->has("name=sold") == 1) { ?><div class="prodato"><?= $state->sold->title ?></div><?php } else { if ($state->has("name=featured") == 1) : ?><div class="izdvojeno"><?= $state->featured->title ?></div><?php endif; if ($state->has("name=new") == 1) : ?><div class="novo"><?= $state->new->title ?></div><?php endif; // if ($state->has("name=hot") == 1) : // endif; if ($state->has("name=gorgeus") == 1) : ?><div class="prelijepo"><?= $state->gorgeus->title ?></div><?php endif; }; ?> </div> <div class="lokacija"><i class="fa fa-map-marker"></i><?php $json = json_decode($item->map->raw); if (isset($json->address->village)) : echo $json->address->village; else : echo $json->address->county; endif; echo ", "; echo $json->address->country; ?> </div> <div class="displeji"><?= $item->images->count(); ?><i class="fa fa-picture-o"></i></div> </div> <h2 class="naslov"><a href="<?= $item->url ?>"><?= $item->title; ?></a></h2> <p class="cijena"><?php if($item->price) : ?><?php echo number_format($item->price,2,",",".");?> &euro;<?php else : ?><?php echo __('Call for price');?><?php endif; ?></p> <p class="uvod"><?= wordLimiter(ripTags($item->body), 120); ?> <?php echo __('Read More');?></p> <p class="sadrzaj"> <?php if($item->surface) : ?><i class="fa fa-th"></i><?= $item->surface ?><?php endif; ?> m<sup>2</sup> <?php if($item->bedrooms) : ?><i class="fa fa-bed"></i><?= $item->bedrooms ?><?php endif; ?> <?php if($item->bathrooms) : ?><i class="fa fa-bath"></i><?= $item->bathrooms ?><?php endif; ?> </p> </div> <?php endforeach; ?> </div> </div> main-search.php which is called by ajax: <?php namespace ProcessWire; ?> <div id="rezultati"> <?php foreach($items as $item) : ?> <div class="trecina nekretnina" data-link="<?= $item->url ?>"> <div class="slika"> <img src="<?= $item->images->eq(0)->size(346,220)->url; ?>" alt="<?= $item->images->eq(0)->description ?>" /> <div class="stanje"> <?php $state = $item->state; if ($state->has("name=sold") == 1) { ?><div class="prodato"><?= $state->sold->title ?></div><?php } else { if ($state->has("name=featured") == 1) : ?><div class="izdvojeno"><?= $state->featured->title ?></div><?php endif; if ($state->has("name=new") == 1) : ?><div class="novo"><?= $state->new->title ?></div><?php endif; // if ($state->has("name=hot") == 1) : // endif; if ($state->has("name=gorgeus") == 1) : ?><div class="prelijepo"><?= $state->gorgeus->title ?></div><?php endif; }; ?> </div> <div class="lokacija"><i class="fa fa-map-marker"></i><?php $json = json_decode($item->map->raw); if (isset($json->address->village)) : echo $json->address->village; else : echo $json->address->county; endif; echo ", "; echo $json->address->country; ?> </div> <div class="displeji"><?= $item->images->count(); ?><i class="fa fa-picture-o"></i></div> </div> <h2 class="naslov"><a href="<?= $item->url ?>"><?= $item->title; ?></a></h2> <p class="cijena"><?php if($item->price) : ?><?php echo number_format($item->price,2,",",".");?> €<?php else : ?><?php echo __('Call for price');?><?php endif; ?></p> <p class="uvod"><?= wordLimiter(ripTags($item->body), 120); ?> <?php echo __('Read More');?></p> <p class="sadrzaj"> <?php if($item->surface) : ?><i class="fa fa-th"></i><?= $item->surface ?><?php endif; ?> m<sup>2</sup> <?php if($item->bedrooms) : ?><i class="fa fa-bed"></i><?= $item->bedrooms ?><?php endif; ?> <?php if($item->bathrooms) : ?><i class="fa fa-bath"></i><?= $item->bathrooms ?><?php endif; ?> </p> </div> <?php endforeach; ?> </div> main.js // Ajax search and scrolling to the form function goToByScroll() { $('html,body').animate({ scrollTop: $("#glavna-pretraga").offset().top-200 }, 'slow'); } function ajaxLoaderClass(){ var container = document.getElementById( "sadrzaj" ); container.classList.toggle("loading"); } function ajaxSearch(){ goToByScroll; ajaxLoaderClass(); $.ajax({ type: "GET", url: 'search\/', data: $('#glavna-pretraga').serialize(), success: function(data){ goToByScroll(); $("#sadrzaj").empty().append(data); ajaxLoaderClass(); } }); } search.php <?php namespace ProcessWire; // other params $property_type = $sanitizer->text($input->get->property_type); $bedrooms_min = $sanitizer->int($input->get->bedrooms_min); $bedrooms_max = $sanitizer->int($input->get->bedrooms_max); $price_min = $sanitizer->int($input->get->price_min); $price_max = $sanitizer->int($input->get->price_max); $sq_min = $sanitizer->int($input->get->sq_min); $sq_max = $sanitizer->int($input->get->sq_max); $pid = $sanitizer->text($input->get->pid); $selector = array(); if($property_type){ $input->whitelist('property_type', $property_type); $property_type = $sanitizer->selectorValue($property_type); $selector[]= "parent=$property_type"; } if($bedrooms_min){ $input->whitelist('bedrooms_min', $bedrooms_min); $sq_min = $sanitizer->selectorValue($bedrooms_min); $selector[]= "bedrooms>=$bedrooms_min"; } if($bedrooms_max){ $input->whitelist('bedrooms_max', $bedrooms_max); $rooms = $sanitizer->selectorValue($bedrooms_max); $selector[]= "bedrooms<=$bedrooms_max"; } if($price_min){ $input->whitelist('price_min', $price_min); $price_min = $sanitizer->selectorValue($price_min); $selector[] = "price>=$price_min"; } if($price_max){ $input->whitelist('price_max', $price_max); $price_max = $sanitizer->selectorValue($price_max); $selector[] = "price<=$price_max"; } if($sq_min){ $input->whitelist('sq_min', $sq_min); $sq_min = $sanitizer->selectorValue($sq_min); $selector[]= "surface>=$sq_min"; } if($sq_max){ $input->whitelist('sq_max', $sq_max); $rooms = $sanitizer->selectorValue($sq_max); $selector[]= "surface<=$sq_max"; } if( $pid ){ $selector = array(); // reset selector $input->whitelist('pid', $pid); $pid = $sanitizer->selectorValue($pid); $selector[] = "pid=$pid"; } // search inside property items $selector[] = "template=property"; // search processing if( $config->ajax ){ // Ajax call $query = implode(',', $selector); $items = $pages->find( $query ); $items_count = $items->count; include('./main-search.php');?> <?php exit(0); } else { // is not Ajax call $selector[] = "sort=price"; $selector[] = "limit=10"; $query = implode(',', $selector); $items = $pages->find( $query ); $pagination = $items->renderPager(array( 'nextItemLabel' => "<span aria-hidden='true'>»</span>", 'previousItemLabel' => "<span aria-hidden='true'>«</span>", 'listMarkup' => "<ul class='pagination pagination-lg'>{out}</ul>", 'itemMarkup' => "<li>{out}</li>", 'linkMarkup' => "<a href='{url}' class='btn btn-raised ripple-effect btn-default'>{out}</a>", 'currentItemClass' => "active" )); // did we find any matches? if( $items->count ){ $message = __("Showing results"); } } ?> Complete files attached with function.php were some functions are. All this files are in root folder (except js) of template. home.php main-search.php search.php main.js _func.php search.php
  3. Here is final solution for the link: /samsung-s10-mobile-phone/pr/f980fd84/ I got tree like this: Products/product articles/details NOTE: template articles has name/URL: "pr" NOTE 2: Product is the main name of the article/articles but all other fields are going in the template details. It was made in case of duplicate name so the hash would be The only difference but the product page would keep children with hash name. See the URLs and picture bellow /samsung-s10-mobile-phone/pr/f980fd84/ /samsung-s10-mobile-phone/pr/d8h3jk1n/ NOTE 3: I am using hidden hash_field as text field on the template details for recording hash URL segmentation enabled on all templates. In product template there is: Profields: Page Table (with the same name as template "Details") with action on product page. Module for making hash: <?php namespace ProcessWire; class AddHashField extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Add Hash Field', 'summary' => 'Populate hash field of product template', 'href' => '', 'version' => 001, 'permanent' => false, 'autoload' => true, 'singular' => true, ); } public function init() { $this->pages->addHookBefore('saveReady', $this, 'AddHashField'); } public function AddHashField($event) { $page = $event->arguments[0]; if($page->template != 'details') return; if(!$page->title){ $hash = hash('CRC32', microtime()); $page->set('title', $hash); $page->set('name', $hash); $page->set('hash_field', $hash); $this->message("Hash is set " . $page->hash_field); } } } In my (probably yours home.php) _main.php file, on the top: <?php namespace ProcessWire; if ($input->urlSegment1 && $input->urlSegment2 == 'pr' && $input->urlSegment3) : $pagename = $input->urlSegment1; $hash = $input->urlSegment3; $match = $page->find("template=details, name={$hash}"); include('views/' . $match->template . 'details.php'); return $this->halt(); endif; On details template: <?php namespace ProcessWire; $parent_name = $input->urlSegment1; $name = $input->urlSegment3; $parent_page = $page->findOne("template=product, name={$parent_name}"); $page = $page->findOne("template=details, name={$name}"); include("./head.inc"); include('./nav.php'); ?> <h1><?= $parent_page->title ?></h1> Function detailsUrl in function.php: function detailsUrl($item){ $out = ''; foreach($item->details as $c){ $out .= '<a href="' .$item->name .'/'. $item->parent->name .'/'. $c->name . '">' . $c->headline . '</a>'; } $out.= '<br />'; return $out; } Listing on the home template: <?php $pages = $pages->find("template=product, sort=date, limit=10"); foreach($pages as $item) : echo detailsUrl($item); endforeach; ?> Now, this is not finished code in home.php, it doesn't list on all products... But I leave your imagination how to handle further. IF anyone needs this rare solution I am here to help. Thanks to motherf.... @OLSA (we are friends) who doesn't let me give him cup.
  4. One of the easiest solutions in my head is: to exclude "/" from regex when creating page->name. Or to query page->title after save, remove number and copy database page_paths path to pages name after save. Hash is unique and that's what makes the page unique.
  5. Hi @All 🙂 I made custom URLs I have unique hash at the end of the every URL of template=product: /nike-air-max-man-running-trainers/pr/832a2805/ Now, I don't need PW to check is there a duplicate page name because it will add to URLs numbers like this (-1, -2, -3...): /nike-air-max-man-running-trainers/pr/832a2805/ /nike-air-max-man-running-trainers-1/pr/9876j536/ /nike-air-max-man-running-trainers-2/pr/54b5221/ /nike-air-max-man-running-trainers-3/pr/0o542761/ etc. How to stop PW from doing this?
  6. OK. Here it is. ProcessWire 3.0.123 PHP 7.2.18 1. In "product" template turned on "Allow URL segments". 2. Made text field: "hash_field" and added it to product.php template. Set visibility to: Open when populated + closed when blanked + Locked (not editable) In site/ready.php <?php namespace ProcessWire; //* conf segments of URL of template product *// wire()->addHook("Page(template=product)::path", function($e) { $page = $e->object; $e->return = "/{$page->name}/pr/{$page->hash_field}/"; }); Made a module "AddHashField" with simple hash CRC32 to populate "hash_field" so the URL will be as short as possible. <?php namespace ProcessWire; class AddHashField extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Add Hash Field', 'summary' => 'Populate hash field of product template', 'href' => '', 'version' => 001, 'permanent' => false, 'autoload' => true, 'singular' => true, ); } public function init() { $this->pages->addHookBefore('saveReady', $this, 'AddHashField'); } public function AddHashField($event) { $page = $event->arguments[0]; if($page->template != 'product') return; if(!$page->hash_field){ date_default_timezone_set('Europe/Podgorica'); $new_date = new \DateTime(date('Y/m/d 00:00')); $formated_date = $new_date->format(YmdHi); $hash = hash('CRC32', $formated_date); $page->set('hash_field', $hash); $this->message("Hesh is set " . $page->hash_field); } } } Now, I am using 'views/' folder for templating so, instead of using home.php I am placing this on the top of the _main.php file. <?php namespace ProcessWire; if ($input->urlSegment1 && $input->urlSegment2 == 'pr' && $input->urlSegment3) : $pagename = $input->urlSegment1; $hash = $input->urlSegment3; $match = $page->findOne("template=product, name={$pagename}, hash_field={$hash}"); if (!$match->id || !$match->hash_field) throw new Wire404Exception(); include("./head.inc"); include('./nav.php'); include('views/' . $match->template->name . '.php'); include("./foot.inc"); // echo $match->render(); // problem with looping page endlessly + fatal error return $this->halt(); endif; NOTE: echo $match->render is causing massive looping until Fatal Error. I don't have idea what is causing that. Tried to turn off xdebug etc. Special THANKS to @Zeka
  7. OK. I think I am resolving this. Will post everything
  8. I placed the URL segmentation code in _main.php. While natural PW URL is still working, I am getting error: Fatal error: Uncaught Error: Maximum function nesting level of '50' reached, aborting! I have turned off xdebug, tried with ini_set('xdebug.max_nesting_level', 10000); in config.php but it loads forever.
  9. @Zeka First part of the code I placed in ready.php file. The second part is in template product.php URL segmentation is enabled in backend. When saving article, I got message with desired URL. But still get 404. I am using latest PW and WAMP. $input->urlSegment1 is empty (var_dump): (length=0)
  10. @Zeka Thank You! I will try and give feedback what I have done. I need the URL to be recorded in the database on Page Save, not alternated on the fly. @wbmnfktr I am making website similar to yellow pages and I need SEO. Main reason - hash will be kind of ID of the page. I am not alternating real ID because of pagination (I am OK with PW but not that good)
  11. Thank you @psy, I think don't need that. To explain my problem a little bit better: 1rst: I need to build URL before page save and add hash after forward slash. IT doesn't matter is it JS or PHP: $new_name = $page->title . '/' . $hash; The problem is: The core is converting forward slash "/" to "-". Probably something with $sanitizer->pageName but I am stuck here. 2nd problem is to move parent name after the child's name or to remove it completely - probably easiest way "Name format for children".
  12. Hi @All 🙂 I have template product in category products And have URLs like this: example.com/pr/salomon-gtx-3d-1930649707/ The last numbers, the hash, is added by a module before save page. What I need is this: example.com/salomon-gtx-3d/pr/1930649707 Is there a way to do this on the fly in the backend and record URL to database? A hint please
  13. Hi @All, @Wanze thanks for the module! Please mates, is there a way to add pdf button/link to backend template? I need to print particular template from backend.
×
×
  • Create New...