Jump to content


Ben

Member Since 22 Mar 2012
Offline Last Active Feb 22 2013 02:38 PM
-----

#26517 ProcessWire Error Notification

Posted by Ben on 04 February 2013 - 01:53 PM

I've seen a couple of these myself happen due to malformed markdown links, it's reproducible. To cause it - you take any page above the homepage, and add a special character (!@#$%^&*()) followed by a backslash. It'll throw the rootparent error.

 

For example, http://www.example.com/news/*/ seems to throw it consistenly in LAMP, though not in a Windows environment for some reason.

 

Not sure of the etiquette, perhaps I should've created a new thread rather than reanimate one that's over a year old?




#19046 limiting image size upload in the admin

Posted by Ben on 26 October 2012 - 08:53 AM

Nevermind, I must be blind. The setting is in the images field setup on the input tab - the last field in the fieldset, "Max Image Dimensions".


#12913 Calendar: recurring events?

Posted by Ben on 22 June 2012 - 09:28 AM

I'm working with a events calendar myself, though I elected to take a more service oriented approach using google calendar and outlook generated *.ics feeds. If your calendar is going to be as simple as you describe, you might be able to get away with the following approach.
  • Set up three datetime fields - event_start, event_end, and recurrence_end.
  • Set up a text field, recurrence_rule (rrule).
  • Add the PHP When library to your project.
  • For recurring events, set your rrule based on byweekday, bymonthday, etc. You can generate rrules with a google calendar (add a recurring event and look at the ical feed) if you're new to them.
  • For the range to be displayed (e.g. today + 3 months) you can use the api to get all events that have start/end OR start/end-recurrence overlap with the displayed range.
  • Set up an array and loop the events, using PHP When to generate a list of occurences if an rrule exists, push rule occurences and non-rrule events in as as siblings, sort by event_start/occurence_start.
  • Render the list of occurences.
That's the basic formula anyways.. If you are avoiding google only because of the look of thier embeded calendars, you might consider rendering your own calendar of events with PHP When and the raw icalendar (*.ics) feed they provide.

Edit: grammar.


#10162 adding images to a page via the api

Posted by Ben on 05 April 2012 - 01:43 PM

My suspicions were correct, there's no need to do anything crazy. The API handles it fine - $page->images->add() was what I was looking for. Part of the frustration was that I mislabeled the switch case, it should have been 'FieldtypeImage' as opposed to 'ImageFieldtype'.

Now if I could only control the name of the phpRANDOM.tmp filename being created, but that's a different matter.

For anyone looking for a solution, here's an updated snippet:

foreach($page->template->fields as $template_field){
	
	$field_name = $template_field->name;
	$field_class = $template_field->type->className;
	$update_value = $this->input->post($field_name);

	switch($field_class){
		case 'TitleFieldtype':
		case 'TextareaFieldtype':
			$page->{$field_name} = $update_value;
			break;
	  
		case 'FieldtypeImage':
			
		    if (array_key_exists($field_name,$_FILES)){
			
				$img_path = $_FILES[$field_name]['tmp_name'];
				$img_name = $_FILES[$field_name]['name'];
				
				// $_FILES array singular vs. multiple
				// normalize by converting single to array prior to looping.
				// http://php.net/manual/en/reserved.variables.files.php  
				
				if (!(is_array($img_path))){
					$img_path = array($img_path);
					$img_name = array($img_name);
				}
				
				for($i=0; $i < count($img_path); $i++){
					$page->images->add($img_path[$i]);
					// TODO, change image name from phpXYZ.tmp
				}
			
			}
			
			break;			
		...
	}	
	...
}



#10157 Is there a way to run PW without json?

Posted by Ben on 05 April 2012 - 11:56 AM

Coming from another angle, maybe you could include a replacement json_encode in the application? Just make sure it gets loaded in before it is called.

Here are a couple alternatives for older PHP: