add categories to events
This commit is contained in:
parent
9d03f63511
commit
ed847a91f6
@ -374,6 +374,26 @@ function event_store_item($arr,$event) {
|
||||
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'];
|
||||
call_hooks('event_updated', $event['id']);
|
||||
return $item_id;
|
||||
@ -424,6 +444,10 @@ function event_store_item($arr,$event) {
|
||||
$item_arr['item_private'] = $private;
|
||||
$item_arr['verb'] = ACTIVITY_POST;
|
||||
|
||||
|
||||
if(array_key_exists('term',$arr))
|
||||
$item_arr['term'] = $arr['term'];
|
||||
|
||||
$item_arr['resource_type'] = 'event';
|
||||
$item_arr['resource_id'] = $event['event_hash'];
|
||||
|
||||
|
@ -33,6 +33,10 @@ function events_post(&$a) {
|
||||
$adjust = intval($_POST['adjust']);
|
||||
$nofinish = intval($_POST['nofinish']);
|
||||
|
||||
$categories = escape_tags(trim($_POST['category']));
|
||||
|
||||
|
||||
|
||||
// only allow editing your own events.
|
||||
|
||||
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['start'] = $start;
|
||||
$datarray['finish'] = $finish;
|
||||
@ -160,6 +180,11 @@ function events_post(&$a) {
|
||||
$datarray['edited'] = $edited;
|
||||
|
||||
$event = event_store_event($datarray);
|
||||
|
||||
|
||||
if($post_tags)
|
||||
$datarray['term'] = $post_tags;
|
||||
|
||||
$item_id = event_store_item($datarray,$event);
|
||||
|
||||
if($share)
|
||||
@ -485,6 +510,28 @@ function events_content(&$a) {
|
||||
if(! $f)
|
||||
$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);
|
||||
$timeformat = t('hour:minute');
|
||||
|
||||
@ -509,7 +556,9 @@ function events_content(&$a) {
|
||||
'$title' => t('Event details'),
|
||||
'$format_desc' => sprintf( t('Format is %s %s.'),$dateformat,$timeformat),
|
||||
'$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>',
|
||||
'$bootstrap' => 1,
|
||||
'$stext' => $stext,
|
||||
|
@ -1,3 +1,17 @@
|
||||
#event-desc-textarea, #event-location-textarea {
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
#event-summary {
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
.event-cats {
|
||||
margin-top: 15px;
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
.required {
|
||||
color: #ff0000;
|
||||
font-size: 1.2rem;
|
||||
}
|
@ -47,14 +47,12 @@
|
||||
|
||||
{{if $catsenabled}}
|
||||
<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>
|
||||
{{/if}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div id="event-desc-text">{{$d_text}}</div>
|
||||
<textarea id="event-desc-textarea" name="desc">{{$d_orig}}</textarea>
|
||||
|
||||
|
Reference in New Issue
Block a user