diff options
author | friendica <info@friendica.com> | 2014-09-07 22:14:28 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2014-09-07 22:14:28 -0700 |
commit | ed847a91f6f8221bc13523574baf4ab7b3cf430a (patch) | |
tree | a47f8aaad6f4bcbb20dfc751e68003d9580dbbfb | |
parent | 9d03f635119b69c9ed1865b77ae397488d1dd599 (diff) | |
download | volse-hubzilla-ed847a91f6f8221bc13523574baf4ab7b3cf430a.tar.gz volse-hubzilla-ed847a91f6f8221bc13523574baf4ab7b3cf430a.tar.bz2 volse-hubzilla-ed847a91f6f8221bc13523574baf4ab7b3cf430a.zip |
add categories to events
-rw-r--r-- | include/event.php | 24 | ||||
-rwxr-xr-x | mod/events.php | 51 | ||||
-rw-r--r-- | view/css/mod_events.css | 14 | ||||
-rwxr-xr-x | view/tpl/event_form.tpl | 4 |
4 files changed, 89 insertions, 4 deletions
diff --git a/include/event.php b/include/event.php index 0c29d26f6..1fe6e6f7f 100644 --- a/include/event.php +++ b/include/event.php @@ -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']; diff --git a/mod/events.php b/mod/events.php index e5250e8f8..195dcb0ff 100755 --- a/mod/events.php +++ b/mod/events.php @@ -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, diff --git a/view/css/mod_events.css b/view/css/mod_events.css index 657eff082..0aef13aa6 100644 --- a/view/css/mod_events.css +++ b/view/css/mod_events.css @@ -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; }
\ No newline at end of file diff --git a/view/tpl/event_form.tpl b/view/tpl/event_form.tpl index 95ebe0351..af10e6c73 100755 --- a/view/tpl/event_form.tpl +++ b/view/tpl/event_form.tpl @@ -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> |