Jump to content

evanmcd

Members
  • Posts

    117
  • Joined

  • Last visited

Posts posted by evanmcd

  1. Hi, just tried fiddling with the dates in the ProcessTrashman table, but didn't have any luck.  Still nothing showing up.

    Think I'll just provide admin level access to the role needing to get access to the trash for now.  

    If you have any more ideas, please do let me know.  

    Thanks!

  2. Hi, timezone is correct, but the server time is 45 min ahead.  The time on the server that has the site on which Trashman is working is in synch.  

    Could this be the issue?  If so, given that I may not be able to change the server time, is there anything else you'd suggest?

    Thx.

  3. Hi again, sorry for the delay on this.  Just getting back into the sites that are using the module.  

    In the meantime, I've got the module installed and running fine on another site using 2.3, so compatibility with that version isn't the issue.

    Tried installing and re-installing, but no luck. Deleted a file, but still nothing showing in the Trashman list.

    I do see the entry in the ProcessTrashman table, though.  And, yes, I do see the Watchdog module installed.

  4. OK, so I've been battling with this for a bit, but have made some progress.  The server I'm deploying to doesn't have allow_fopen_url enabled, causing the copy function to fail.

    So, I've been trying to add a safe copy method to Pagefile.php

    Below is my attempt so far.  Unfortunately, it fails to write the file each time.  Though of course I put a workaround in place, so that the site isn't erroring, the images are getting saved where I need them to be to display them.

    protected function ___install($filename) {
    		$basename = $this->pagefiles->cleanBasename($filename, true); 
    		$pathInfo = pathinfo($basename); 
    		$basename = basename($basename, ".$pathInfo[extension]"); 
    
    		// remove any extra dots in the filename
    		$basename = str_replace(".", "_", $basename); 
    		$basenameNoExt = $basename; 
    		$basename .= ".$pathInfo[extension]"; 
    
    		// ensure filename is unique
    		$cnt = 0; 
    		while(file_exists($this->pagefiles->path() . $basename)) {
    			$cnt++;
    			$basename = "$basenameNoExt-$cnt.$pathInfo[extension]";
    		}
    
    		if(strpos($filename, ' ') !== false && strpos($filename, '://') !== false) $filename = str_replace(' ', '%20', trim($filename)); // per Pete
    		$destination = $this->pagefiles->path() . $basename;
    		
    		try {
    			$this->safe_copy_file($filename, $destination);
    		} catch(WireException $ex) {
    			echo($ex->getMessage());
    		}
    		if($this->config->chmodFile) chmod($this->pagefiles->path() . $basename, octdec($this->config->chmodFile));
    		parent::set('basename', $basename); 
    			
    	}
    
    	/**
    	 * Manages file copies in the case when copy is not available.  
    	 *
    	 * Normally this is the case because all_url_fopen is set to false in php.ini
    	 *
    	 * @param string $source Full source path and filename of file to copy
    	 * @param string $destination Full destinate path and filename of file to copy
    	 *
    	 */
    	protected function safe_copy_file($source, $destination) {
    	  $resource = curl_init();
    
    	  $source = str_replace("/var/www/vhosts/straighttalkswitch.com/httpdocs", "https://www.straighttalkswitch.com", $source);
    	 
    	  	curl_setopt($resource, CURLOPT_URL, $source);
    	  	curl_setopt($resource, CURLOPT_HEADER, 0);
    	  	curl_setopt($resource, CURLOPT_BINARYTRANSFER, 1);
    		curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
    		curl_setopt($resource, CURLOPT_CONNECTTIMEOUT, 30);
    		curl_setopt($resource, CURLOPT_SSL_VERIFYHOST, 0);
    		curl_setopt($resource, CURLOPT_SSL_VERIFYPEER, 0);
    	 
    	  $content = curl_exec($resource);
    	 
    	  curl_close($resource);
    
    	  if($content != '') {
    
    	    $fp = fopen($destination, 'wb');
    	    $fw = fwrite($fp, $content);
    	    fclose($fp);
    	 
    	    if($fw != false) {
    	      return true;
    	    } else {
    	    	throw new WireException("Error: file write failed.  Source: " .$source . "; Destination: " . $destination);	
    	    }
    	  } else {
    	  	throw new WireException("Error: curl_exec failed to gather the resource");
    	  }
    	 
    	  return false;
    	}
    

    I was able to get the file to save by just putting this code in a template and running it directly

    $resource = curl_init();
    curl_setopt($resource, CURLOPT_URL, 'https://www.straighttalkswitch.com/switch-it-to-win-it/site/assets/files/34d50563316208286b56a1564b1082ba_cute-dog-dogs-13286656-1024-768.jpg');
    curl_setopt($resource, CURLOPT_HEADER, 0);
    curl_setopt($resource, CURLOPT_BINARYTRANSFER, 1);
    curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($resource, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($resource, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($resource, CURLOPT_SSL_VERIFYPEER, 0);
    
    $content = curl_exec($resource);
    
    curl_close($resource);
    
    if($content != '') {
    	$fp = fopen($config->paths->files . 'test/34d50563316208286b56a1564b1082ba_cute-dog-dogs-13286656-1024-768.jpg', 'wb');
    	$fw = fwrite($fp, $content);
    	fclose($fp);
    	header('Content-type: image/jpeg');
    	echo($content);
    
    } else {
    	echo("failed to save");
    }
    

    Thanks to anyone who can help.

  5. Yeah, sorry, I've found that the trailing slash after the config URL doesn't matter.  Just removed it and get the same error but without the two slashes:

    Error: Exception: Unable to copy: /var/www/vhosts/straighttalkswitch.com/httpdocs/switch-it-to-win-it/site/assets/files/19feeda0a3882049c8815a9d69d7ef2d_cute-dog-dogs-13286656-1024-768.jpg => /var/www/vhosts/straighttalkswitch.com/httpdocs/switch-it-to-win-it/site/assets/files/38365/19feeda0a3882049c8815a9d69d7ef2d_cute-dog-dogs-13286656-1024-768.jpg (in /var/www/vhosts/straighttalkswitch.com/httpdocs/switch-it-to-win-it/wire/core/Pagefile.php line 109)

  6. Hi all,

    I've just discovered an error on a LIVE site.  I'm uploading images, then adding the already uploaded image to a Page

    The file gets uploaded first into the root of file, then the user submits a form with the file name in entry_photo

    $entry->entry_photo = $config->paths->files . '/' . $input->post["entry_photo"];
    $entry_result = $entry->save();
    

    Gets me this error:

    Error: Exception: Unable to copy: /var/www/vhosts/straighttalkswitch.com/httpdocs/switch-it-to-win-it/site/assets/files//19feeda0a3882049c8815a9d69d7ef2d_cute-dog-dogs-13286656-1024-768.jpg => /var/www/vhosts/straighttalkswitch.com/httpdocs/switch-it-to-win-it/site/assets/files/38361/19feeda0a3882049c8815a9d69d7ef2d_cute-dog-dogs-13286656-1024-768.jpg (in /var/www/vhosts/straighttalkswitch.com/httpdocs/switch-it-to-win-it/wire/core/Pagefile.php line 109)

    #0 [internal function]: Pagefile->___install('/var/www/vhosts...')
    #1 /var/www/vhosts/straighttalkswitch.com/httpdocs/switch-it-to-win-it/wire/core/Wire.php(271): call_user_func_array(Array, Array)
    #2 /var/www/vhosts/straighttalkswitch.com/httpdocs/switch-it-to-win-it/wire/core/Wire.php(229): Wire->runHooks('install', Array)
    #3 /var/www/vhosts/straighttalkswitch.com/httpdocs/switch-it-to-win-it/wire/core/Pagefile.php(74): Wire->__call('install', Array)
    #4 /var/www/vhosts/straighttalkswitch.com/httpdocs/switch-it-to-win-it/wire/core/Pagefile.php(74): Pageimage->inst

    I'm running php 5.2.17 if that makes a difference, and yes the Page file folders are set to 777  Thanks for any help anyone could offer ( I could REALLY use it)

  7. Hi Soma,

    Thanks so much for your detailed response.  Glad I wasn't going crazy thinking it was harder than it seems.  I'm going to try your method and will post back here with results.

    To give some context, here's the background on my use case:  the site is for a large hardware store chain for which each store manager should be able to edit the info on their store's information page.  Showing them the full page tree would unnecessarily complicate the process for what is almost surely a non-technical audience.

    While not a must have, it will cut down on support requests from the store managers who get lost in the page tree while looking for their store.

    Thanks again Soma.

  8. OK, here's the entire module.  Thanks for any suggestions.

    class HidePagesNotEditable extends WireData implements Module {
    
    	/**
    	 * getModuleInfo is a module required by all modules to tell ProcessWire about them
    	 *
    	 * @return array
    	 *
    	 */
    	public static function getModuleInfo() {
    
    		return array(
    			'title' => 'Hide Pages Not Editable',
    			'version' => 100,
    			'summary' => 'Hides Pages in the admin when the user does not have edtiable access',
    			'autoload' => true
    			);
    	}
    
    	public function init() {
    		$this->addHookAfter('Page::viewable', $this, 'showOnlyEditable');
    	}
    
    	public function showOnlyEditable(HookEvent $event) {
    		// $event->return = false; // causes redireect loop
    		// if($event->return) return; // seems to have no effect
    		// $this->message(var_dump($event->arguments)); // returns array(0) {}
    		$this->message($event->object->name);
    
    	}
    
    }
    
  9. Thanks for the tip @teppo.  I've looked into the HookEvent source, and although helpful I'm still having issues.

    Among that strange things I've noticed is this:  when I add

    $this->message($event->object->name);
    

    as the only line in the hook function, the output I get is the name of each of the top level pages in the PW admin.  So, 'page', 'page', 'setup','template','field', etc.

    While all of the examples I've seen use $event->object to get a reference to non-admin pages, mine seems to be returning only admin pages.  Maybe there's a conflict with another non-core PW module?  I've got the following other modules installed:

    • FieldtypeColorPicker
    • ProcessSelectorTest
    • HelperFieldLinks
    • ImportPagesCSV
    • MarkupSitemapXML
    • ModulesQuickFilter
    • PageReferencesTab
    • ProcessBatcher
    • ProcessRedirects

    Would really appreciate help from anyone who has an idea of what might be going on.

    Thanks!

  10. Hi Ryan,

    Thanks for the reply.  Your approach makes sense, though I'll probably flip it on it's head and show only a specific template rather than hide all the others.

    The issue I'm coming up against is that I don't seem to be able to get any information out of the event getting passed in to the function that's called when the hook is hit.

    I trace out count($event->arguments) and get 0. I'm extending the WireData class, but have also tried extending Process.  

    Trying to understand why I would get no arguments with my event and ideally how I could figure out what data should get passed with events to hook handling functions.

    Thanks again.

  11. It would be trivial for a module to hook into the PageList and avoid listing pages that the user can't edit. But it's not something that I recommend in a tree-based hierarchy because access can change at any branch. The PageList is meant to show everything the user can view. The context of the hierarchy is generally important everywhere in ProcessWire, whether the user can edit a given branch or not.

    Hi Ryan,

    While I hoped it would be trivial for me to setup a module that hides Pages in the admin that are not editable by the user, I've not been able to get it to work.

    What method specifically would be the one I'd want to hook into?  I've tried ProcessPageListRender, ProcessPageList and even Page methods.  Would be a huge help if you could point me in the right direction.

    Are there any other resources you'd recommend for Module development?  I've looked into Captain Hook, but wondering if there's anything else you think would help someone who's struggling a bit to grasp the basics (where do the event properties come from, how to get references to pages, etc.).

    Thanks a lot.

  12. Hi all,

    I'm tweaking a search engine that's built using PW selectors.  I'm wondering if there is a way to set the selector to find word fragments, for example the user searches on 'grass seed' and I want to find fields that have the words 'grasses' and 'seeding' (or 'grassy' and 'seeds' for another example).

    I know I can use the %= selector, but my options there are body%=grass seed or body%=grass|seed, neither of which return just what I want.

    I could switch to using raw SQL (body LIKE 'grass%' AND body LIKE 'seed%') but I'd rather stick with PW selectors if I can.

    Thanks!

  13. This has been super helpful on one project, but I can't seem to get it working on another.

    Using PW 2.3, I install the module, add the permissions for a role, trash a page, then go to the trashman page.  Nothing shows up.

    The other site I've got it working on is 2.2.9.2, could that make the different?

    Thanks.

  14. Hi,

    I've been using PW as the back end for a number of contest sites in which users enter a short bit of text as an answer to a question.  Each "entry" ends up as a PW Page.

    In this case, it's quite common for people to provide the same answer, which of course results in a duplicate page error (Exception: Duplicate entry).

    I'm wondering if there is a way to have PW automatically create a unique page name when it creates a new page that would have a duplicate name - like this-is-a-test becoming this-is-a-test-2.

    Any help is great appreciated!

    Thanks.

  15. Oh, whoops I left generic_text in there cause that's the actual field name I'm using.  I just used vanity_url in the example so it would be a bit more clear that the field is being used to check for an alternate (shorter) way to access the page.  So the name of a page might be 10-tips-for-a-better-lawn-this-spring while the vanity_url might be just lawn.  I want either /lawn or /10-tips-for-a-better-lawn-this-spring to redirect to /landing-pages/10-tips-for-a-better-lawn-this-spring.

    Hope that clarifies it.

  16. So it seems that the urlSegment method will work.  Here's the code:

    if($input->urlSegment1) {
    	$has_redirect = $pages->get("/landing-pages/")->find("name|vanity_url=".$input->urlSegment1)->getTotal();
    	if($has_redirect > 0) {
    		$redirect_page = $pages->get("name|generic_text=".$input->urlSegment1);
    		header("location:" . $redirect_page->url);
    	} else {
    		header("location: " . $pages->get($config->http404PageID)->url);
    	}
    }
    

    It works except for one small oddity: the or check ( | ) in the selector, to check to see if the segment is either in the name or the vanity_url fields doesn't work. if the urlSegment is only in the vanity_url field, the getTotal() call returns 0.  When urlSegment is the name of the page it works fine.

    Anyone know why that might be?

  17. Hi all,

    So, I've got a site that's being migrated from Joomla (ouch) that has a bunch of pages at the root - i.e. http://site.com/page1 http://site.com/page2, etc

    I know I could just create these in the admin below the home page, but, as I've got dozens and more being added all the time, I'd rather keep them as sub pages under a generic structure page, which I'd call something like "Landing Pages".  But, of course that would leave me with http://site.com/landing-pages/page1, etc

    I know I could add htaccess rules for each specific page, but non-devs will adding these pages, so that's not a good option.

    I've looked at Netcarver's URL Shortener module a bit, and that may be an option.  But, ideally I'd be able to have it managed all from the page itself.

    What do you all think is the best way to manage this?  

    Thanks.

    P.S. Working with Joomla has made me appreciate PW all the more.  I'm sure it's good for some people but... yuch, not for me :)

    • Like 1
×
×
  • Create New...