]> git.mxchange.org Git - friendica.git/commitdiff
moods
authorfriendica <info@friendica.com>
Thu, 23 Aug 2012 04:36:55 +0000 (21:36 -0700)
committerfriendica <info@friendica.com>
Thu, 23 Aug 2012 04:36:55 +0000 (21:36 -0700)
boot.php
include/conversation.php
include/text.php
mod/mood.php [new file with mode: 0644]
mod/poke.php
view/mood_content.tpl [new file with mode: 0644]

index 0c05afd1978c20c9e74b27d1ff0f9c030f9f54f5..b49c92bf05f470b64910f2cd512cba6c6aae73bb 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -253,6 +253,7 @@ define ( 'ACTIVITY_TAG',         NAMESPACE_ACTIVITY_SCHEMA . 'tag' );
 define ( 'ACTIVITY_FAVORITE',    NAMESPACE_ACTIVITY_SCHEMA . 'favorite' );
 
 define ( 'ACTIVITY_POKE',        NAMESPACE_ZOT . '/activity/poke' );
+define ( 'ACTIVITY_MOOD',        NAMESPACE_ZOT . '/activity/mood' );
 
 define ( 'ACTIVITY_OBJ_COMMENT', NAMESPACE_ACTIVITY_SCHEMA . 'comment' );
 define ( 'ACTIVITY_OBJ_NOTE',    NAMESPACE_ACTIVITY_SCHEMA . 'note' );
index f7d0298124044deb3eac8253321584880eb7e779..0b091571f1cc6f25ffdd154b6fccf285d9f161db 100644 (file)
@@ -205,6 +205,20 @@ function localize_item(&$item){
                $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
 
        }
+       if (stristr($item['verb'],ACTIVITY_MOOD)) {
+               $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
+               if(! $verb)
+                       return;
+
+               $Aname = $item['author-name'];
+               $Alink = $item['author-link'];
+               $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
+               
+               $txt = t('%1$s is currently %2$s');
+
+               $item['body'] = sprintf($txt, $A, t($verb));
+       }
+
     if ($item['verb']===ACTIVITY_TAG){
                $r = q("SELECT * from `item`,`contact` WHERE 
                `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
index 85ba99dd3163218832ede6053b9f2effaa6f5791..3783d2accd9dbbce3d8bdf3fac9056d7897c98e4 100644 (file)
@@ -727,6 +727,39 @@ function get_poke_verbs() {
        return $arr;
 }
 
+function get_mood_verbs() {
+       
+       // index is present tense verb
+       // value is array containing past tense verb, translation of present, translation of past
+
+       $arr = array(
+               'happy'      => t('happy'),
+               'sad'        => t('sad'),
+               'mellow'     => t('mellow'),
+               'tired'      => t('tired'),
+               'perky'      => t('perky'),
+               'angry'      => t('angry'),
+               'stupefied'  => t('stupified'),
+               'puzzled'    => t('puzzled'),
+               'interested' => t('interested'),
+               'bitter'     => t('bitter'),
+               'cheerful'   => t('cheerful'),
+               'alive'      => t('alive'),
+               'annoyed'    => t('annoyed'),
+               'anxious'    => t('anxious'),
+               'cranky'     => t('cranky'),
+               'disturbed'  => t('disturbed'),
+               'frustrated' => t('frustrated'),
+               'motivated'  => t('motivated'),
+               'relaxed'    => t('relaxed'),
+               'surprised'  => t('surprised'),
+       );
+
+       call_hooks('mood_verbs', $arr);
+       return $arr;
+}
+
+
 /**
  * 
  * Function: smilies
diff --git a/mod/mood.php b/mod/mood.php
new file mode 100644 (file)
index 0000000..7a793c7
--- /dev/null
@@ -0,0 +1,142 @@
+<?php
+
+require_once('include/security.php');
+require_once('include/bbcode.php');
+require_once('include/items.php');
+
+
+function mood_init(&$a) {
+
+       if(! local_user())
+               return;
+
+       $uid = local_user();
+       $verb = notags(trim($_GET['verb']));
+       
+       if(! $verb) 
+               return;
+
+       $verbs = get_mood_verbs();
+
+       if(! in_array($verb,$verbs))
+               return;
+
+       $activity = ACTIVITY_MOOD . '#' . urlencode($verb);
+
+       $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0);
+
+
+       logger('mood: verb ' . $verb, LOGGER_DEBUG);
+
+
+       if($parent) {
+               $r = q("select uri, private, allow_cid, allow_gid, deny_cid, deny_gid 
+                       from item where id = %d and parent = %d and uid = %d limit 1",
+                       intval($parent),
+                       intval($parent),
+                       intval($uid)
+               );
+               if(count($r)) {
+                       $parent_uri = $r[0]['uri'];
+                       $private    = $r[0]['private'];
+                       $allow_cid  = $r[0]['allow_cid'];
+                       $allow_gid  = $r[0]['allow_gid'];
+                       $deny_cid   = $r[0]['deny_cid'];
+                       $deny_gid   = $r[0]['deny_gid'];
+               }
+       }
+       else {
+
+               $private = 0;
+
+               $allow_cid     =  $a->user['allow_cid'];
+               $allow_gid     =  $a->user['allow_gid'];
+               $deny_cid      =  $a->user['deny_cid'];
+               $deny_gid      =  $a->user['deny_gid'];
+       }
+
+       $poster = $a->contact;
+
+       $uri = item_new_uri($a->get_hostname(),$uid);
+
+       $action = sprintf( t('%1$s is currently %2$s'), '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' , $verbs[$verb]); 
+
+       $arr = array();
+
+       $arr['uid']           = $uid;
+       $arr['uri']           = $uri;
+       $arr['parent-uri']    = (($parent_uri) ? $parent_uri : $uri);
+       $arr['type']          = 'activity';
+       $arr['wall']          = 1;
+       $arr['contact-id']    = $poster['id'];
+       $arr['owner-name']    = $poster['name'];
+       $arr['owner-link']    = $poster['url'];
+       $arr['owner-avatar']  = $poster['thumb'];
+       $arr['author-name']   = $poster['name'];
+       $arr['author-link']   = $poster['url'];
+       $arr['author-avatar'] = $poster['thumb'];
+       $arr['title']         = '';
+       $arr['allow_cid']     = $allow_cid;
+       $arr['allow_gid']     = $allow_gid;
+       $arr['deny_cid']      = $deny_cid;
+       $arr['deny_gid']      = $deny_gid;
+       $arr['last-child']    = 1;
+       $arr['visible']       = 1;
+       $arr['verb']          = $activity;
+       $arr['private']       = $private;
+
+       $arr['origin']        = 1;
+       $arr['body']          = $action;
+
+       $item_id = item_store($arr);
+       if($item_id) {
+               q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
+                       dbesc($a->get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id),
+                       intval($uid),
+                       intval($item_id)
+               );
+               proc_run('php',"include/notifier.php","tag","$item_id");
+       }
+
+
+       call_hooks('post_local_end', $arr);
+
+       proc_run('php',"include/notifier.php","like","$post_id");
+
+       return;
+}
+
+
+
+function mood_content(&$a) {
+
+       if(! local_user()) {
+               notice( t('Permission denied.') . EOL);
+               return;
+       }
+
+       $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : '0');
+
+
+
+       $verbs = get_mood_verbs();
+
+       $shortlist = array();
+       foreach($verbs as $k => $v)
+               if($v !== 'NOTRANSLATION')
+                       $shortlist[] = array($k,$v);
+
+
+       $tpl = get_markup_template('mood_content.tpl');
+
+       $o = replace_macros($tpl,array(
+               '$title' => t('Mood'),
+               '$desc' => t('Set your current mood and tell your friends'),
+               '$verbs' => $shortlist,
+               '$parent' => $parent,
+               '$submit' => t('Submit'),
+       ));
+
+       return $o;
+
+}
\ No newline at end of file
index 5cd88d7e2a8ee5d448a44d74d978eaa777601ce9..edcb27d021f86a721631acf50a4d71971520fb9b 100644 (file)
@@ -73,7 +73,7 @@ function poke_init(&$a) {
 
        $poster = $a->contact;
 
-       $uri = item_new_uri($a->get_hostname(),$owner_uid);
+       $uri = item_new_uri($a->get_hostname(),$uid);
 
        $arr = array();
 
diff --git a/view/mood_content.tpl b/view/mood_content.tpl
new file mode 100644 (file)
index 0000000..9349c56
--- /dev/null
@@ -0,0 +1,20 @@
+<h3>$title</h3>
+
+<div id="mood-desc">$desc</div>
+
+<form action="mood" method="get">
+<br />
+<br />
+
+<input id="mood-parent" type="hidden" value="$parent" name="parent" />
+
+<select name="verb" id="mood-verb-select" >
+{{ for $verbs as $v }}
+<option value="$v.0">$v.1</option>
+{{ endfor }}
+</select>
+<br />
+<br />
+<input type="submit" name="submit" value="$submit" />
+</form>
+