add categories to events

This commit is contained in:
friendica 2014-09-07 22:14:28 -07:00
parent 9d03f63511
commit ed847a91f6
4 changed files with 89 additions and 4 deletions

View File

@ -374,6 +374,26 @@ function event_store_item($arr,$event) {
intval($arr['uid']) intval($arr['uid'])
); );
$s = q("delete from term where oid = %d and otype = %d",
intval($r[0]['id']),
intval(TERM_OBJ_POST)
);
if(($arr['term']) && (is_array($arr['term']))) {
foreach($arr['term'] as $t) {
q("insert into term (uid,oid,otype,type,term,url)
values(%d,%d,%d,%d,'%s','%s') ",
intval($arr['uid']),
intval($r[0]['id']),
intval(TERM_OBJ_POST),
intval($t['type']),
dbesc($t['term']),
dbesc($t['url'])
);
}
}
$item_id = $r[0]['id']; $item_id = $r[0]['id'];
call_hooks('event_updated', $event['id']); call_hooks('event_updated', $event['id']);
return $item_id; return $item_id;
@ -424,6 +444,10 @@ function event_store_item($arr,$event) {
$item_arr['item_private'] = $private; $item_arr['item_private'] = $private;
$item_arr['verb'] = ACTIVITY_POST; $item_arr['verb'] = ACTIVITY_POST;
if(array_key_exists('term',$arr))
$item_arr['term'] = $arr['term'];
$item_arr['resource_type'] = 'event'; $item_arr['resource_type'] = 'event';
$item_arr['resource_id'] = $event['event_hash']; $item_arr['resource_id'] = $event['event_hash'];

View File

@ -33,6 +33,10 @@ function events_post(&$a) {
$adjust = intval($_POST['adjust']); $adjust = intval($_POST['adjust']);
$nofinish = intval($_POST['nofinish']); $nofinish = intval($_POST['nofinish']);
$categories = escape_tags(trim($_POST['category']));
// only allow editing your own events. // only allow editing your own events.
if(($xchan) && ($xchan !== get_observer_hash())) if(($xchan) && ($xchan !== get_observer_hash()))
@ -138,6 +142,22 @@ function events_post(&$a) {
} }
} }
$post_tags = array();
$channel = $a->get_channel();
if(strlen($categories)) {
$cats = explode(',',$categories);
foreach($cats as $cat) {
$post_tags[] = array(
'uid' => $profile_uid,
'type' => TERM_CATEGORY,
'otype' => TERM_OBJ_POST,
'term' => trim($cat),
'url' => $channel['xchan_url'] . '?f=&cat=' . urlencode(trim($cat))
);
}
}
$datarray = array(); $datarray = array();
$datarray['start'] = $start; $datarray['start'] = $start;
$datarray['finish'] = $finish; $datarray['finish'] = $finish;
@ -160,6 +180,11 @@ function events_post(&$a) {
$datarray['edited'] = $edited; $datarray['edited'] = $edited;
$event = event_store_event($datarray); $event = event_store_event($datarray);
if($post_tags)
$datarray['term'] = $post_tags;
$item_id = event_store_item($datarray,$event); $item_id = event_store_item($datarray,$event);
if($share) if($share)
@ -485,6 +510,28 @@ function events_content(&$a) {
if(! $f) if(! $f)
$f = 'ymd'; $f = 'ymd';
$catsenabled = feature_enabled(local_user(),'categories');
$category = '';
if($catsenabled && x($orig_event)){
$itm = q("select * from item where resource_type = 'event' and resource_id = '%s' and uid = %d limit 1",
dbesc($orig_event['event_hash']),
intval(local_user())
);
$itm = fetch_post_tags($itm);
if($itm) {
$cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY);
foreach ($cats as $cat) {
if(strlen($category))
$category .= ', ';
$category .= $cat['term'];
}
}
}
$dateformat = datesel_format($f); $dateformat = datesel_format($f);
$timeformat = t('hour:minute'); $timeformat = t('hour:minute');
@ -509,7 +556,9 @@ function events_content(&$a) {
'$title' => t('Event details'), '$title' => t('Event details'),
'$format_desc' => sprintf( t('Format is %s %s.'),$dateformat,$timeformat), '$format_desc' => sprintf( t('Format is %s %s.'),$dateformat,$timeformat),
'$desc' => t('Starting date and Title are required.'), '$desc' => t('Starting date and Title are required.'),
'$catsenabled' => $catsenabled,
'$placeholdercategory' => t('Categories (comma-separated list)'),
'$category' => $category,
'$s_text' => t('Event Starts:') . ' <span class="required" title="' . t('Required') . '">*</span>', '$s_text' => t('Event Starts:') . ' <span class="required" title="' . t('Required') . '">*</span>',
'$bootstrap' => 1, '$bootstrap' => 1,
'$stext' => $stext, '$stext' => $stext,

View File

@ -1,3 +1,17 @@
#event-desc-textarea, #event-location-textarea { #event-desc-textarea, #event-location-textarea {
width: 400px; width: 400px;
}
#event-summary {
width: 400px;
}
.event-cats {
margin-top: 15px;
width: 400px;
}
.required {
color: #ff0000;
font-size: 1.2rem;
} }

View File

@ -47,14 +47,12 @@
{{if $catsenabled}} {{if $catsenabled}}
<div id="event-category-wrap"> <div id="event-category-wrap">
<input name="category" id="event-category" type="text" placeholder="{{$placeholdercategory}}" value="{{$category}}" class="jothidden" style="display:none" /> <input name="category" id="event-category" type="text" placeholder="{{$placeholdercategory}}" value="{{$category}}" class="event-cats" style="display: block;" />
</div> </div>
{{/if}} {{/if}}
<div id="event-desc-text">{{$d_text}}</div> <div id="event-desc-text">{{$d_text}}</div>
<textarea id="event-desc-textarea" name="desc">{{$d_orig}}</textarea> <textarea id="event-desc-textarea" name="desc">{{$d_orig}}</textarea>