Jump to content

davo

Members
  • Posts

    283
  • Joined

  • Last visited

Posts posted by davo

  1. I gave the upgrade to 3 a go today, but i'm hitting a couple of problems.

    I have a functions file but when it is called from in a template I get this error:

    Error: Call to undefined function wire() (line 155 of /var/www/vhosts/dudmc.com/httpdocs/site/templates/myfunctionlib.inc)

    Do I have to amend anything to make this work again?

  2. Hi,

    I have a site running PW 2.8. I moved it to a new server and (possibly foolishly) did the 2.8 upgrade at the same time.

     

    Now, all the pages are no longer using the www prefix which has screwed with search engine indexing somewhat. I don't know if it's the way the host file was created on the server or because i have over written the htaccess file.

     

    I though that on the .htaccess file I could uncomment the following two lines to prepend www but when i do this i'm getting a 500 error:

      # -----------------------------------------------------------------------------------------------
      # 13. OPTIONAL: Redirect users to the 'www.' version of the site (uncomment to enable).
      # For example: http://processwire.com/ would be redirected to http://www.processwire.com/
      # -----------------------------------------------------------------------------------------------

      # RewriteCond %{HTTP_HOST} !^www\. [NC]
      # RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

     

    Any advice please?

     

     

    Davo

  3. That's what I tried.

     

    But i get this complaint back when viewing the page:

    Error: Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column '_sort_parent_title.title' in 'order clause' (in /var/www/vhosts/dudmc.com/httpdocs/wire/core/PageFinder.php line 298)#0 [internal function]: PageFinder->___find(Object(Selectors), Array)#1 /var/www/vhosts/dudmc.com/httpdocs/wire/core/Wire.php(398): call_user_func_array(Array, Array)#2 /var/www/vhosts/dudmc.com/httpdocs/wire/core/Wire.php(333): Wire->runHooks('find', Array)#3 /var/www/vhosts/dudmc.com/httpdocs/wire/core/Pages.php(216): Wire->__call('find', Array)#4 /var/www/vhosts/dudmc.com/httpdocs/wire/core/Pages.php(216): PageFinder->find(Object(Selectors), Array)#5 [internal function]: Pages->___find('template=dmc, D...')#6 /var/www/vhosts/dudmc.com/httpdocs/wire/core/Wire.php(398): call_user_func_array(Array, Array)#7 /var/www/vhosts/dudmc.com/httpdocs/wire/core/Wire.php(333): Wire->runHooks('find', Array)#8 /var/www/vhosts/dudmc.com/httpdocs/site/templates/myfunctionlib.inc(35): Wire->__call('find', Array)#9 /var/www/vhosts/dud

     


    This error message was shown because you are logged in as a Superuser. Error has been logged.

  4. I've been using a function for some time now which sorts an array by the title of a linked page 'DMC_country_represented' title but then should reorder it by the parent page title to group the pages together.

     

    Recently the order is no longer working and a couple of the list items are out of alphabetical order. The only thing i'm aware of recently that has changed is a core upgrade to 2.7.2.

     

    Any advice welcome please.

     

    function dmc_list($names){
        
        $dmcs = wire('pages')->find("template=dmc, DMC_represented=1, sort=DMC_country_represented");
        $dmcs->sort("parent.title");
        $total = $dmcs->count();
        $items_per_column =  ceil($total / 3);
        $count = 0;    
    
    echo"<div class='row'>";
        echo "<div class='col-md-4'>"; //start the first column
            echo '<ul>'; // start your first list
            foreach($dmcs as $dmc){
                
                $region = $dmc->parent->title;
    	    $regionid = $dmc->parent->id;	
                if($region !== $new_region) echo "<li class='list-group-item list-group-item-info'><b>{$region} {$regionid} </b></li>";
    						if($names=="names") { 
    									$showname = " - " . $dmc->title;
    									}
    					$link = "<a href='$dmc->url'>{$dmc->DMC_country_represented->title} {$dmc->sub_country->title} $showname {$regionid} {$count} of {$items_per_column} in total {$total}</a>";
                                            echo "<li>{$link} </li>";
                            
                        if(++$count%$items_per_column) { // this will be false when we are on the last item in column
                            echo "";
                        } else { // this part will run when we are on the last item in the column
                            echo "</ul></div>";
                            if($count !== $total) echo "<div class='col-md-4'><ul>"; // this will start a new column unless we're on the last item.
    			
                        }
    			$new_region = $dmc->parent->title; // why the same variable?
                                                            
                    } // end foreach                                                                                
    echo "</div>"; // end row
    
    
    }

     

  5. Thanks Alxndre'

    So didn't actually do the app programming myself, but I what I did have to do know my own site structure well and then learn how that related to the real database structure behind processwire; which for a novice like me wasn't instantly obvious. I'm sure there's far more technical ways of interpreting the schema, but the way I like to think of it is processwire makes virtual tables of the real sql tables.I then had to explain all the structures to the developer who i have to admit is far more proficient at databases than I!

    The app is build for iOS and android. The iOS can be frustrating as everytime we iron out a bug it takes a while to get back into itunes.

    The nice thing about this is the client has been used to working in the back end of processwire now for a couple of years and have a very deep site. The app is read only to the db and when there is a connection it looks for live data, if you're out of signal it uses a cached copy of all the data.The good news is the client only has to work on one console ie processwire back end and the content changes are reflected on the live site, android and iOS.

    It looks like you're doing two way communication then with processwire; i thought about doing this safely using someone like url query string segments to allow pw to handle security/formatting etc. what was your approach?

  6. Thanks guys. I'll do some research into each of those methods and see what I can do. It's only for a prototype to prove the concept so authentication isn't a real issue... The model is likely to go to a bespoke developer once proved. Cheers

  7. We're doing a rapid development project as a proto type using an android app and processwire as the back end. In essense the app captures some data and then needs to send it to a server. It will be a short list of strings and integers along with an image. Both the app and the backend database have been built to show the concept but just to tidy things up we're looking at showing the data moving from one to the other.

    Does anyone have any simple ideas?

    I've thought about using the email to page module by getting the app to send the data to an email address along with the image and then allowing pw to pick it up.

    I've also thought about ways of using JS calls to the api

    Just looking for ideas to demo it working.

  8. got there in the end :)

    
    <?php
    
     
    
    
    /**
     * Search template
     *
     */
    
    $out = '';
    
    if($q = $sanitizer->selectorValue($input->get->q)) {
    
    	// Send our sanitized query 'q' variable to the whitelist where it will be
    	// picked up and echoed in the search box by the head.inc file.
    	$input->whitelist('q', $q); 
    
    	// Search the title, body and country fields for our query text.
    	// Limit the results to 50 pages. 
    	// Exclude results that use the 'admin' template. 
    
    // load my directed search results table
    
    $q = htmlentities($q);
    
    $keywords = preg_split("/[\s-]+/", $q);
    
    $selector = '';
    
    //turn the query to lowercase
    $q = strtolower($q);
    
    //load my list of specific search terms
    $dictionary_words = $pages->find("template=search_results");
    
    //loop through them to see if the query matches the any of them
    
    	foreach($dictionary_words as $word){
    
    //if it matches create the selector
    						if($word->title==$q){
    							$value = htmlentities($word->search_result); 
    							$selector = "id=" . $value . ", " ;}
    }
    
    //catch usa
    
    if ($q == "usa") {
    			$selector = "parent=1065, ";
    }
    
    //if it didnt match up break the term up 
    if($selector==""){
    
    foreach($keywords as $kw){
    
    
    
        $selector .= "Meta_keywords|DMCcontact_Country|DMCcontact_Address_2|DMC_Email~='$kw', ";
                              }
    }
    
    
    $selector .= "template=dmc, limit=50";
    
    // echo $selector;
    
    $matches = $pages->find($selector);
    
    
    
    
    
    
    
    
    
    //	$matches = $pages->find("Meta_keywords|DMCcontact_Country|DMCcontact_Address_2|DMC_Email~=$q, template=dmc, limit=50"); 
    
    	$count = count($matches); 
    
    	if($count) {
    		
                            if(!$config->ajax){$out .= "<h2>Found $count DMC matching your query:</h2>";} $out.= 
    			"<ul class='nav'>";
    
    		foreach($matches as $m) {
    			if($m->DMC_represented==1){$rep="<span class='glyphicon glyphicon-star-empty'></span>";
    			$out .= "<li  data-toggle='tooltip' data-placement='top' title='{$m->title} is a partner DMC of destinations UNLIMITED. Click the link for their full profile'><p><a href='{$m->url}'>{$rep} Full Partner -   {$m->title} - Representing {$m->DMC_country_represented->title}</a></p></li>";}else{$rep="";
    			$out .= "<li  data-toggle='tooltip' data-placement='top' title='{$m->title} are not represented by destinations UNLIMITED therefore a suggestion only' id='nonrep' ><p>{$m->title} - Representing {$m->DMC_country_represented->title} - {$m->DMC_Email} </a></p></li>";}
    		}
    
    		$out .= "</ul>";
    
    	} else {
    		$out .= "<h2>Sorry, no results were found.</h2>";
    	}
    } else {
    	$out .= "
                      ";
    }
    
    // Note that we stored our output in $out before printing it because we wanted to execute
    // the search before including the header template. This is because the header template 
    // displays the current search query in the search box (via the $input->whitelist) and 
    // we wanted to make sure we had that setup before including the header template. 
    
    if(!$config->ajax) include("./dmcheader.inc");
    
    ?>
    
     <div class="container">
    
    	<div class"row">
    
    		
    
    
    		<div class="col-md-6">
    		<?php if(!$config->ajax){ echo "<h2>Please enter a destination</h2>";} ?>
    
    	
    <form id='my_search_form' action='<?php echo $config->urls->root?>dmc-search/' method='get'>
    				<input type='text' name='q' id='my_search_query' class='form-control' value='<?php echo htmlentities($input->whitelist('q'), ENT_QUOTES, 'UTF-8'); ?>' />
    				<button type='submit' id='search_submit'>Search</button>
    			</form>
    
    			<?php echo "$out"; ?>
    		</div>
    	</div>	
    </div>
    
    <script type="text/javascript">
    
    $(document).ready(function(){
        $("[data-toggle=tooltip]").tooltip({ placement: 'right'});
    });
    
    
    
    </script>
    
    <?php
    
    
    
    if(!$config->ajax) include("./dmcfooter.inc"); 
    
                            		
    
    
  9. ok, I've worked on this and found a more hybrid solution.

    I've created a list of search terms and corresponding results.

    I test the search term to see if it matches any of the pre determined search terms and if it does it creates the selector. If it doesn't it continues with the organic search.

    The part I've got stuck with is when someone inserts an ampersand. It breaks the page resulting in this:

    Error: Exception: Unknown Selector operator: '~=&' -- was your selector value properly escaped? (in /home/content/s/o/m/somniaweb/html/dudmc/wire/core/Selectors.php line 247)

    and yet the ajax request processes it fine?

    any ideas please.

    
    <?php
    
     
    
    
    /**
     * Search template
     *
     */
    
    $out = '';
    
    if($q = $sanitizer->selectorValue($input->get->q)) {
    
    	// Send our sanitized query 'q' variable to the whitelist where it will be
    	// picked up and echoed in the search box by the head.inc file.
    	$input->whitelist('q', $q); 
    
    	// Search the title, body and country fields for our query text.
    	// Limit the results to 50 pages. 
    	// Exclude results that use the 'admin' template. 
    
    // load my directed search results table
    
    
    $keywords = preg_split("/[\s-]+/", $q);
    
    $selector = '';
    
    //turn the query to lowercase
    $q = strtolower($q);
    
    //load my list of specific search terms
    $dictionary_words = $pages->find("template=search_results");
    
    //loop through them to see if the query matches the any of them
    
    	foreach($dictionary_words as $word){
    
    //if it matches create the selector
    						if($word->title==$q){
    							$selector = "id=" . $word->search_result;}
    }
    
    //if it didnt match up break the term up 
    if($selector==""){
    
    foreach($keywords as $kw){
    
    
    
        $selector .= "Meta_keywords|DMCcontact_Country|DMCcontact_Address_2|DMC_Email~=$kw, ";
                              }
    }
    
    
    $selector .= "template=dmc, limit=50";
    
    // echo $selector;
    
    $matches = $pages->find($selector);
    
    
    
    
    
    
    
    
    
    //	$matches = $pages->find("Meta_keywords|DMCcontact_Country|DMCcontact_Address_2|DMC_Email~=$q, template=dmc, limit=50"); 
    
    	$count = count($matches); 
    
    	if($count) {
    		
                            if(!$config->ajax){$out .= "<h2>Found $count DMC matching your query:</h2>";} $out.= 
    			"<ul class='nav'>";
    
    		foreach($matches as $m) {
    			if($m->DMC_represented==1){$rep="<span class='glyphicon glyphicon-star-empty'></span>";
    			$out .= "<li  data-toggle='tooltip' data-placement='top' title='{$m->title} is a partner DMC of destinations UNLIMITED. Click the link for their full profile'><p><a href='{$m->url}'>{$rep} Full Partner -   {$m->title} - Representing {$m->DMC_country_represented->title}</a></p></li>";}else{$rep="";
    			$out .= "<li  data-toggle='tooltip' data-placement='top' title='{$m->title} are not represented by destinations UNLIMITED therefore a suggestion only' id='nonrep' ><p>{$m->title} - Representing {$m->DMC_country_represented->title} - {$m->DMC_Email} </a></p></li>";}
    		}
    
    		$out .= "</ul>";
    
    	} else {
    		$out .= "<h2>Sorry, no results were found.</h2>";
    	}
    } else {
    	$out .= "
                      ";
    }
    
    // Note that we stored our output in $out before printing it because we wanted to execute
    // the search before including the header template. This is because the header template 
    // displays the current search query in the search box (via the $input->whitelist) and 
    // we wanted to make sure we had that setup before including the header template. 
    
    if(!$config->ajax) include("./dmcheader.inc");
    
    ?>
    
     <div class="container">
    
    	<div class"row">
    
    		
    
    
    		<div class="col-md-6">
    		<?php if(!$config->ajax){ echo "<h2>Please enter a destination</h2>";} ?>
    
    	
    <form id='my_search_form' action='<?php echo $config->urls->root?>dmc-search/' method='get'>
    				<input type='text' name='q' id='my_search_query' class='form-control' value='<?php echo htmlentities($input->whitelist('q'), ENT_QUOTES, 'UTF-8'); ?>' />
    				<button type='submit' id='search_submit'>Search</button>
    			</form>
    
    			<?php echo "$out"; ?>
    		</div>
    	</div>	
    </div>
    
    <script type="text/javascript">
    
    $(document).ready(function(){
        $("[data-toggle=tooltip]").tooltip({ placement: 'right'});
    });
    
    
    
    </script>
    
    <?php
    
    
    
    if(!$config->ajax) include("./dmcfooter.inc"); 
    
                            		
    
    
  10. I have a number of pages brought back in the array and I want to test to see if each any one of the pages in the array has a certain field with content. I could probably loop through the array but seem to remember if there was a simpler method. I've tried the below which doesn't work:

    $showcases = $pages->find("template=dmc_update_link, DMC_select=$pageid, parent=1209");
    
    $countshowcases = count($showcases);
    if (($countshowcases > 0) && ($showcases->DMC_update_doc !=="")) {
    echo "					
    					<a data-toggle='collapse' data-parent='#accordion' href='#collapsefour'  class='list-group-item active'><span class='glyphicon glyphicon-collapse-down'></span> Destination Showcases <span class='badge'>{$countshowcases}</span></a>
    					<div id='collapsefour' class='panel-collapse collapse'>
    					<div class='panel-body'>";
    foreach ($showcases as $showcase)	{
    					echo "<li class='list-group-item'><a href='{$showcase->DMC_update_doc->url}' target='_blank'>Showcase {$showcase->title}</a> </li>";
    					}
    					echo "</div></div>";
    			}
    
  11. Hi Steve, just to clarify what's going on I'll explain my scenario.

    Searching normally works just fine. A while ago though I changed the search operator to ~= as %= just brought back too many irrelevant results eg Oman inside rOMANian.

    Using my lesson from Dave p I understand that even having split Sri Lanka, Sri is under the three letter limit of SQL, presumably to exclude ands and is etc.

    Although rather crass my method of the simple "if this" then force the result should actually work for me. I'll probably eventually build this into an array either kept hard in the code or a set of pages in pw. Sometimes the client wants the search results to be quite manipulated.

  12. I'm  afraid I may have cheated and taken the easy option with this due to the unwanted to results...

    
    $keywords = preg_split("/[\s-]+/", $q);
    
    $selector = '';
    
    foreach($keywords as $kw){
    
       if ($q ==  "sri lanka") {
    				$selector= "id=1330,";
    							}else{
    
        $selector .= "Meta_keywords|DMCcontact_Country|DMCcontact_Address_2|DMC_Email~=$kw, ";}
    }
    
    $selector .= "template=dmc, limit=50";
    
    // echo $selector;
    
    $matches = $pages->find($selector);
    

    Thank you for your help Pete.

    At the moment there is only one country that had this split short word issue, but if there are more I may have to build them into an array.

  13. Try this-

    $keywords = preg_split("/[\s-]+/", $q);
    
    $selector = '';
    
    foreach($keywords as $kw){
        $selector .= "Meta_keywords|DMCcontact_Country|DMCcontact_Address_2|DMC_Email~=$kw, ";
    }
    
    $selector .= "template=dmc, limit=50";
    
    //echo $selector;
    
    $matches = $pages->find($selector);
    

    You can uncomment the penultimate line for debugging (and/or understanding) purposes. That won't help with the regex, but, essentially the important bit is within the square brackets, where \s means a space (or similar) and the dash after means literally a dash. You could add others there.

    Note Written in browser, but should work. (Now where's that fingers-crossed emoticon?)

    It was almost there i think. The debug output was this:

    Meta_keywords|DMCcontact_Country|DMCcontact_Address_2|DMC_Email~=sri, Meta_keywords|DMCcontact_Country|DMCcontact_Address_2|DMC_Email~=lanka, template=dmc, limit=50
    

    and yet, it didn't return the sri lanka page?

  14. I'm using the following line to search for articles:

    $matches = $pages->find("Meta_keywords|DMCcontact_Country|DMCcontact_Address_2|DMC_Email~=$q, template=dmc, limit=50");
    

    but, where a user searches for something like 'Sri Lanka', it doesn't recognise the two words. One of the fields it searches is the keyword field, so it wouldn't be a problem if I put a hypen or something in like the 'Sri-Lanka' as long as the user could type 'sri lanka'.

    Any suggestions how i could make this happen?

  15. This module has settled in well to my live site. However, the client often presents the site 'offline'. To do this the client has made a copy of the site using httptrack.

    It's not my ideal solution but suits the client well.

    The problem is when the site tries to load a page with the map marker displayed they get this error:

    "Markup Google map error please add the maps.googleapis.com in your document head".

    Is there a possible way around this? Any suggestions welcome....

×
×
  • Create New...