basic edit and delete for things
This commit is contained in:
		| @@ -261,11 +261,12 @@ function obj_verbs() { | |||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| function obj_verb_selector() { | function obj_verb_selector($current = '') { | ||||||
| 	$verbs = obj_verbs(); | 	$verbs = obj_verbs(); | ||||||
| 	$o .= '<select class="obj-verb-selector" name="verb" >'; | 	$o .= '<select class="obj-verb-selector" name="verb" >'; | ||||||
| 	foreach($verbs as $k => $v) { | 	foreach($verbs as $k => $v) { | ||||||
| 		$o .= '<option value="' . urlencode($k) . '">' . $v[0] . '</option>'; | 		$selected = (($k == $current) ? ' selected="selected" ' : ''); | ||||||
|  | 		$o .= '<option value="' . urlencode($k) . '"' . $selected . '>' . $v[0] . '</option>'; | ||||||
| 	} | 	} | ||||||
| 	$o .= '</select>'; | 	$o .= '</select>'; | ||||||
| 	return $o; | 	return $o; | ||||||
|   | |||||||
							
								
								
									
										121
									
								
								mod/thing.php
									
									
									
									
									
								
							
							
						
						
									
										121
									
								
								mod/thing.php
									
									
									
									
									
								
							| @@ -1,6 +1,7 @@ | |||||||
| <?php /** @file */ | <?php /** @file */ | ||||||
|  |  | ||||||
| require_once('include/items.php'); | require_once('include/items.php'); | ||||||
|  | require_once('include/contact_selectors.php'); | ||||||
|  |  | ||||||
|  |  | ||||||
| function thing_init(&$a) { | function thing_init(&$a) { | ||||||
| @@ -11,6 +12,7 @@ function thing_init(&$a) { | |||||||
| 	$account_id = $a->get_account(); | 	$account_id = $a->get_account(); | ||||||
| 	$channel    = $a->get_channel(); | 	$channel    = $a->get_channel(); | ||||||
|  |  | ||||||
|  | 	$term_hash = (($_REQUEST['term_hash']) ? $_REQUEST['term_hash'] : ''); | ||||||
|  |  | ||||||
| 	$name = escape_tags($_REQUEST['term']); | 	$name = escape_tags($_REQUEST['term']); | ||||||
| 	$verb = escape_tags($_REQUEST['verb']); | 	$verb = escape_tags($_REQUEST['verb']); | ||||||
| @@ -59,6 +61,40 @@ function thing_init(&$a) { | |||||||
| 	if((! $name) || (! $translated_verb)) | 	if((! $name) || (! $translated_verb)) | ||||||
| 		return; | 		return; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 	if($term_hash) { | ||||||
|  | 		$t = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", | ||||||
|  | 			intval(TERM_OBJ_THING), | ||||||
|  | 			dbesc($term_hash) | ||||||
|  | 		); | ||||||
|  | 		if(! $t) { | ||||||
|  | 			notice( t('Item not found.') . EOL); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 		$orig_record = $t[0]; | ||||||
|  | 		if($photo != $orig_record['imgurl']) { | ||||||
|  | 			$arr = import_profile_photo($photo,get_observer_hash(),true); | ||||||
|  | 			$local_photo = $arr[0]; | ||||||
|  | 			$local_photo_type = $arr[3]; | ||||||
|  | 		} | ||||||
|  | 		else | ||||||
|  | 			$local_photo = $orig_record['imgurl']; | ||||||
|  |  | ||||||
|  | 		$r = q("update term  set term = '%s', url = '%s', imgurl = '%s' where term_hash = '%s' and uid = %d limit 1", | ||||||
|  | 			dbesc($name), | ||||||
|  | 			dbesc(($url) ? $url : z_root() . '/thing/' . $term_hash), | ||||||
|  | 			dbesc($local_photo), | ||||||
|  | 			dbesc($term_hash), | ||||||
|  | 			intval(local_user()) | ||||||
|  | 		); | ||||||
|  |  | ||||||
|  | 		info( t('Thing updated') . EOL); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	$sql = (($profile_guid) ? " and profile_guid = '" . dbesc($profile_guid) . "' " : " and is_default = 1 "); | 	$sql = (($profile_guid) ? " and profile_guid = '" . dbesc($profile_guid) . "' " : " and is_default = 1 "); | ||||||
| 	$p = q("select profile_guid, is_default from profile where uid = %d $sql limit 1", | 	$p = q("select profile_guid, is_default from profile where uid = %d $sql limit 1", | ||||||
| 		intval(local_user()) | 		intval(local_user()) | ||||||
| @@ -118,7 +154,7 @@ function thing_init(&$a) { | |||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	info( t('thing/stuff added')); | 	info( t('Thing added')); | ||||||
|  |  | ||||||
| 	$arr = array(); | 	$arr = array(); | ||||||
| 	$links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $term['url'])); | 	$links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $term['url'])); | ||||||
| @@ -180,7 +216,7 @@ function thing_init(&$a) { | |||||||
|  |  | ||||||
| function thing_content(&$a) { | function thing_content(&$a) { | ||||||
| 	 | 	 | ||||||
| 	if(argc() > 1) { | 	if(argc() == 2) { | ||||||
|  |  | ||||||
| 		$r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", | 		$r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", | ||||||
| 			intval(TERM_OBJ_THING), | 			intval(TERM_OBJ_THING), | ||||||
| @@ -188,7 +224,12 @@ function thing_content(&$a) { | |||||||
| 		); | 		); | ||||||
|  |  | ||||||
| 		if($r) { | 		if($r) { | ||||||
| 			return replace_macros(get_markup_template('show_thing.tpl'), array( '$header' => t('Show Thing'), '$thing' => $r[0] )); | 			return replace_macros(get_markup_template('show_thing.tpl'), array( | ||||||
|  | 				'$header' => t('Show Thing'), | ||||||
|  | 				'$edit' => t('Edit'), | ||||||
|  | 				'$delete' => t('Delete'), | ||||||
|  | 				'$canedit' => ((local_user() && local_user() == $r[0]['obj_channel']) ? true : false),  | ||||||
|  | 				'$thing' => $r[0] )); | ||||||
| 		} | 		} | ||||||
| 		else { | 		else { | ||||||
| 			notice( t('item not found.') . EOL); | 			notice( t('item not found.') . EOL); | ||||||
| @@ -196,18 +237,82 @@ function thing_content(&$a) { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	require_once('include/contact_selectors.php'); | 	if(! local_user()) | ||||||
|  | 		return; | ||||||
|  |  | ||||||
|  | 	$thing_hash = ''; | ||||||
|  |  | ||||||
|  | 	if(argc() == 3 && argv(1) === 'edit') { | ||||||
|  | 		$thing_hash = argv(2); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 		$r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", | ||||||
|  | 			intval(TERM_OBJ_THING), | ||||||
|  | 			dbesc($thing_hash) | ||||||
|  | 		); | ||||||
|  |  | ||||||
|  | 		if((! $r) || ($r[0]['obj_channel'] != local_user())) { | ||||||
|  | 			notice( t('Permission denied.') . EOL); | ||||||
|  | 			return ''; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 		$o .= replace_macros(get_markup_template('thing_edit.tpl'),array( | ||||||
|  | 			'$thing_hdr' => t('Edit Thing'), | ||||||
|  | 			'$multiprof' => feature_enabled(local_user(),'multi_profiles'), | ||||||
|  | 			'$profile_lbl' => t('Select a profile'), | ||||||
|  | 			'$profile_select' => contact_profile_assign($r[0]['obj_page']), | ||||||
|  | 			'$verb_lbl' => t('Select a category of stuff. e.g. I ______ something'), | ||||||
|  | 			'$verb_select' => obj_verb_selector($r[0]['obj_verb']), | ||||||
|  | 			'$thing_hash' => $thing_hash, | ||||||
|  | 			'$thing_lbl' => t('Name of thing e.g. something'), | ||||||
|  | 			'$thething' => $r[0]['term'], | ||||||
|  | 			'$url_lbl' => t('URL of thing (optional)'), | ||||||
|  | 			'$theurl' => $r[0]['url'], | ||||||
|  | 			'$img_lbl' => t('URL for photo of thing (optional)'), | ||||||
|  | 			'$imgurl' => $r[0]['imgurl'], | ||||||
|  | 			'$submit' => t('Submit') | ||||||
|  | 		)); | ||||||
|  |  | ||||||
|  | 		return $o; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if(argc() == 3 && argv(1) === 'drop') { | ||||||
|  | 		$thing_hash = argv(2); | ||||||
|  |  | ||||||
|  | 		$r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", | ||||||
|  | 			intval(TERM_OBJ_THING), | ||||||
|  | 			dbesc($thing_hash) | ||||||
|  | 		); | ||||||
|  |  | ||||||
|  | 		if((! $r) || ($r[0]['obj_channel'] != local_user())) { | ||||||
|  | 			notice( t('Permission denied.') . EOL); | ||||||
|  | 			return ''; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 		$x = q("delete from obj where obj_obj = '%s' and obj_type = %d and obj_channel = %d limit 1", | ||||||
|  | 			dbesc($thing_hash), | ||||||
|  | 			intval(TERM_OBJ_THING), | ||||||
|  | 			intval(local_user()) | ||||||
|  | 		); | ||||||
|  | 		$x = q("delete from term where term_hash = '%s' and uid = %d limit 1", | ||||||
|  | 			dbesc($thing_hash), | ||||||
|  | 			intval(local_user()) | ||||||
|  | 		); | ||||||
|  | 		return $o; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	$o .= replace_macros(get_markup_template('thing_input.tpl'),array( | 	$o .= replace_macros(get_markup_template('thing_input.tpl'),array( | ||||||
| 		'$thing_hdr' => t('Add Stuff to your Profile'), | 		'$thing_hdr' => t('Add Thing to your Profile'), | ||||||
| 		'$multiprof' => feature_enabled(local_user(),'multi_profiles'), | 		'$multiprof' => feature_enabled(local_user(),'multi_profiles'), | ||||||
| 		'$profile_lbl' => t('Select a profile'), | 		'$profile_lbl' => t('Select a profile'), | ||||||
| 		'$profile_select' => contact_profile_assign(''), | 		'$profile_select' => contact_profile_assign(''), | ||||||
| 		'$verb_lbl' => t('Select a category of stuff. e.g. I ______ something'), | 		'$verb_lbl' => t('Select a category of stuff. e.g. I ______ something'), | ||||||
| 		'$verb_select' => obj_verb_selector(), | 		'$verb_select' => obj_verb_selector(), | ||||||
| 		'$thing_lbl' => t('Name of thing or stuff e.g. something'), | 		'$thing_lbl' => t('Name of thing e.g. something'), | ||||||
| 		'$url_lbl' => t('URL of thing or stuff (optional)'), | 		'$url_lbl' => t('URL of thing (optional)'), | ||||||
| 		'$img_lbl' => t('URL for photo of thing or stuff (optional)'), | 		'$img_lbl' => t('URL for photo of thing (optional)'), | ||||||
| 		'$submit' => t('Submit') | 		'$submit' => t('Submit') | ||||||
| 	)); | 	)); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1 +1 @@ | |||||||
| 2013-12-29.541 | 2013-12-30.542 | ||||||
|   | |||||||
| @@ -2445,3 +2445,8 @@ img.mail-list-sender-photo { | |||||||
| #sidebar-group-list ul { | #sidebar-group-list ul { | ||||||
| 	list-style-type: none; | 	list-style-type: none; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | .profile-thing-list img, .thing-show img, .thing-edit-links a { | ||||||
|  | 	margin-top: 8px; | ||||||
|  | 	margin-right: 15px; | ||||||
|  | } | ||||||
|   | |||||||
| @@ -4,5 +4,13 @@ | |||||||
| {{if $thing.imgurl}}<img src="{{$thing.imgurl}}" width="175" height="175" alt="{{$thing.term}}" />{{/if}} | {{if $thing.imgurl}}<img src="{{$thing.imgurl}}" width="175" height="175" alt="{{$thing.term}}" />{{/if}} | ||||||
| <a href="{{$thing.url}}" >{{$thing.term}}</a> | <a href="{{$thing.url}}" >{{$thing.term}}</a> | ||||||
| </div> | </div> | ||||||
|  | {{if $canedit}} | ||||||
|  | <div class="thing-edit-links"> | ||||||
|  | <a href="thing/edit/{{$thing.term_hash}}" title="{{$edit}}"><i class="icon-pencil thing-edit-icon"></i></a> | ||||||
|  | <a href="thing/drop/{{$thing.term_hash}}" onclick="return confirmDelete();" title="{{$delete}}" ><i class="icon-remove drop-icons"></i></a> | ||||||
|  | </div> | ||||||
|  | <div class="thing-edit-links-end"></div> | ||||||
|  | {{/if}} | ||||||
|  |  | ||||||
| {{/if}} | {{/if}} | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										29
									
								
								view/tpl/thing_edit.tpl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								view/tpl/thing_edit.tpl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | |||||||
|  | <h2>{{$thing_hdr}}</h2> | ||||||
|  | <form action="thing" method="post" > | ||||||
|  | <input type="hidden" name="term_hash" value="{{$thing_hash}}" /> | ||||||
|  |  | ||||||
|  | {{if $multiprof }} | ||||||
|  | <div class="thing-profile-label">{{$profile_lbl}}</div> | ||||||
|  |  | ||||||
|  | <div class="thing-profile">{{$profile_select}}</div> | ||||||
|  | {{/if}} | ||||||
|  |  | ||||||
|  | <div class="thing-verb-label">{{$verb_lbl}}</div> | ||||||
|  |  | ||||||
|  | <div class="thing-verb">{{$verb_select}}</div> | ||||||
|  |  | ||||||
|  |  | ||||||
|  | <label class="thing-label" for="thing-term">{{$thing_lbl}}</label> | ||||||
|  | <input type="text" class="thing-input" id="thing-term" name="term" value="{{$thething}}" /> | ||||||
|  | <div class="thing-field-end"></div> | ||||||
|  | <label class="thing-label" for="thing-url">{{$url_lbl}}</label> | ||||||
|  | <input type="text" class="thing-input" id="thing-url" name="url" value="{{$theurl}}" /> | ||||||
|  | <div class="thing-field-end"></div> | ||||||
|  | <label class="thing-label" for="thing-img">{{$img_lbl}}</label> | ||||||
|  | <input type="text" class="thing-input" id="thing-img" name="img" value="{{$imgurl}}" /> | ||||||
|  | <div class="thing-field-end"></div> | ||||||
|  |  | ||||||
|  | <div class="thing-end"></div>  | ||||||
|  |  | ||||||
|  | <input type="submit" class="thing-submit" name="submit" value="{{$submit}}" /> | ||||||
|  | </form> | ||||||
		Reference in New Issue
	
	Block a user