1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8//this script may only be included - so its better to die if called directly. 9if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) { 10 header("location: index.php"); 11 exit; 12} 13 14function smarty_block_activityframe($params, $content, $smarty, &$repeat) 15{ 16 if ($repeat) { 17 return; 18 } 19 20 $commentMode = 'default'; 21 if (isset($params['comment']) && in_array($params['comment'], ['object', 'activity', 'disabled'])) { 22 $commentMode = $params['comment']; 23 } 24 25 $likeMode = 'default'; 26 if (isset($params['like']) && $params['like'] == 'disabled') { 27 $likeMode = 'disabled'; 28 } 29 30 $likes = isset($params['activity']['like_list']) ? $params['activity']['like_list'] : []; 31 if (! is_array($likes)) { 32 $params['activity']['like_list'] = $likes = []; 33 } 34 35 if (isset($params['activity']['user_groups']) && is_array($params['activity']['user_groups'])) { 36 $userGroups = TikiLib::lib('user')->get_user_groups($GLOBALS['user']); 37 $choiceGroups = TikiLib::lib('user')->get_groups_userchoice(); 38 $sharedGroups = array_intersect($params['activity']['user_groups'], $userGroups, $choiceGroups); 39 } else { 40 $sharedGroups = []; 41 } 42 43 if (isset($params['activity']['object_type'], $params['activity']['object_id'])) { 44 // Use the activity 45 $object = [ 46 'type' => $params['activity']['object_type'], 47 'id' => $params['activity']['object_id'], 48 ]; 49 } elseif (isset($params['activity']['type'], $params['activity']['object'])) { 50 // Not a registered activity, use parent object 51 $object = [ 52 'type' => $params['activity']['type'], 53 'id' => $params['activity']['object'], 54 ]; 55 } else { 56 $object = []; 57 } 58 59 /* 60 Comment modes. 61 By default the activity is picked, with a fallback to the object if not a registered 62 activity. 63 64 * disabled - completely remove comments 65 * activity - prevent fallback to object 66 * object - comments use object's comments 67 */ 68 if (empty($object) || $commentMode == 'disabled') { 69 $comment = null; 70 } elseif ($object['type'] == 'activity' && $commentMode == 'object') { 71 if (isset($params['activity']['type'], $params['activity']['object'])) { 72 // Not a registered activity, use parent object 73 $comment = [ 74 'type' => $params['activity']['type'], 75 'id' => $params['activity']['object'], 76 ]; 77 } else { 78 $comment = null; 79 } 80 } elseif ($object['type'] != 'activity' && $commentMode == 'activity') { 81 $comment = null; 82 } else { 83 $comment = $object; 84 } 85 86 $smarty = TikiLib::lib('smarty'); 87 $smarty->assign( 88 'activityframe', 89 [ 90 'content' => $content, 91 'activity' => $params['activity'], 92 'object' => $object, 93 'comment' => $comment, 94 'heading' => $params['heading'], 95 'like' => in_array($GLOBALS['user'], $likes), 96 'likeactive' => $likeMode != 'disabled', 97 'sharedgroups' => $sharedGroups, 98 'summary' => isset($params['summary']) ? $params['summary'] : null, 99 'params' => $params, 100 ] 101 ); 102 $out = $smarty->fetch('activity/activityframe.tpl'); 103 104 return $out; 105} 106