function getActivityData($a_params) { //indicates number of activity indicator, now in [0..5] $indicatorNr = $a_params['indicatorNr']; //indicates number for sub activity indicator, possible value depends on value of indicatorNr $subIndicatorNr = $a_params['subIndicatorNr']; $f_params = array(); //indicates for what other users data is visible. 0=mean other, 1=anonymous others, 2=others $f_params['privacyLevel'] = $a_params['privacyLevel']; //0=all groups, so elgg total. If >0 then data is filtered for group guid $f_params['groupGuid'] = $a_params['groupGuid']; //indicates if activity and performance should be shared with other users. 0=no, 1=yes $f_params['shareWithOthers'] = $a_params['shareWithOthers']; //indicates if activity and performance should always shared. 0=no, 1=yes $f_params['alwaysShowOthers'] = $a_params['alwaysShowOthers']; //comma separated list of user guids that must be excluded from the data //if one of these users is the current user, me should be excluded from the data $f_params['excludedFromDashboardUserGuids'] = $a_params['excludedFromDashboardUserGuids']; //if >0 get all data starting from startEpoch $f_params['startEpoch'] = $a_params['startEpoch']; //if >0 get all data till endEpoch $f_params['endEpoch'] = $a_params['endEpoch']; //get all data in intervals between startEpoch and endEpoch $f_params['numberOfMonths'] = $a_params['numberOfMonths']; //get all data in intervals between startEpoch and endEpoch $f_params['numberOfIntervals'] = $a_params['numberOfIntervals']; //get end date, it is in format yyyy-mm-dd $f_params['endDate'] = $a_params['endDate']; //indicates for which users data should be given. 0=all users, 1=current user, 2=all but current user $f_params['userCollectionNr'] = $a_params['userCollectionNr']; //minimal 1 interval if ($f_params['numberOfIntervals'] == 0) { $f_params['numberOfIntervals'] = 1; } //determine endEpoch if not set if ($f_params['endEpoch'] == 0) { if ($f_params['endDate'] != '') { $f_params['endEpoch'] = strtotime($f_params['endDate']); } else { //set it to now $f_params['endEpoch'] = time(); } } //if numberOfMonths > 0, set endEpoch to end of month so intervals roughly correspond to months if ($f_params['numberOfMonths'] > 0) { $month = date("m", $f_params['endEpoch']); $year = date("Y", $f_params['endEpoch']); $f_params['endEpoch'] = mktime(23, 59, 59, ++$month, 0, $year); } //determine $startEpoch if ($f_params['numberOfMonths'] > 0) { $f_params['startEpoch'] = strtotime("-" . $f_params['numberOfMonths'] . " Months", $f_params['endEpoch']); } else { if ($f_params['startEpoch'] == 0) { //get oldest timestamp in database $sql = " SELECT posted AS time FROM elgg_river ORDER BY posted ASC LIMIT 1"; $f_params['startEpoch'] = getTime($sql); } } $f_params['intervalTime'] = ($f_params['endEpoch'] - $f_params['startEpoch']) / $f_params['numberOfIntervals']; $users = getUsers($f_params); $f_params['users'] = $users; $showUsers = getShowUsers($f_params); $f_params['showUsers'] = $showUsers; $userGuids = getUserGuids($f_params); $f_params['userGuids'] = $userGuids; $userNames = getUserNames($f_params); $f_params['userNames'] = $userNames; // $numberOfCreatedUsers = getNumberOfIntervalUsers($f_params, "create"); // $numberOfBannedUsers = getNumberOfIntervalUsers($f_params, "ban"); $numberOfUsers = getNumberOfUsers($f_params); // $f_params['numberOfCreatedUsers'] = $numberOfCreatedUsers; // $f_params['numberOfBannedUsers'] = $numberOfBannedUsers; $f_params['numberOfUsers'] = $numberOfUsers; $data = ""; if ($indicatorNr == 0 && $subIndicatorNr == -1) { //I am productive $data = getUserResults(getData0($f_params), $f_params); } else { if ($indicatorNr == 1 && $subIndicatorNr == -1) { //I deliver quality contributions $data = getUserResults(getData1($f_params), $f_params); } else { if ($indicatorNr == 2 && $subIndicatorNr == -1) { //I am involved $data = getUserResults(getData2($f_params), $f_params); } else { if ($indicatorNr == 3 && $subIndicatorNr == -1) { //I am socially active $data = getUserResults(getData3($f_params), $f_params); } else { if ($indicatorNr == 4 && $subIndicatorNr == -1) { //I am available $data = getUserResults(getData4($f_params), $f_params); } else { if ($indicatorNr == 5 && $subIndicatorNr == -1) { //I am reading $data = getUserResults(getData5($f_params), $f_params); } else { if ($indicatorNr == 0 && $subIndicatorNr == 0) { //I am productive, number of objects created and updated, by all users, current user or all but current user $data = getResult(getNumberOfCreatedAndUpdatedObjects($f_params)); } else { if ($indicatorNr == 0 && $subIndicatorNr == 1) { //I am involved, number of comments to other users, for all users, current user or all but current user $data = getResult(getNumberOfCommentsToOthers($f_params)); } else { if ($indicatorNr == 1 && $subIndicatorNr == 0) { //I deliver quality contributions, number of ratings from others on created or updated objects and groups, for all users, current user or all but current user $data = getResult(getNumberOfRatingsFromOthers($f_params)); } else { if ($indicatorNr == 1 && $subIndicatorNr == 1) { //I deliver quality contributions, mean rating from others on created or updated objects and groups, for all users, current user or all but current user $data = getResult(getMeanRatingFromOthers($f_params)); } else { if ($indicatorNr == 2 && $subIndicatorNr == 0) { //I am involved, number of ratings to others on created or updated objects and groups, for all users, current user or all but current user $data = getResult(getNumberOfRatingsToOthers($f_params)); } else { if ($indicatorNr == 2 && $subIndicatorNr == 1) { //I am involved, number of comments to other users, for all users, current user or all but current user $data = getResult(getNumberOfCommentsToOthers($f_params)); } else { if ($indicatorNr == 3 && $subIndicatorNr == 0) { //I am socially active, number of friend requests by others, for all users, current user or all but current user $data = getResult(getNumberOfFriendRequestsFromOthers($f_params)); } else { if ($indicatorNr == 3 && $subIndicatorNr == 1) { //I am socially active, number of friend requests to others, for all users, current user or all but current user $data = getResult(getNumberOfFriendRequestsToOthers($f_params)); } else { if ($indicatorNr == 4 && $subIndicatorNr == 0) { //I am available, number of plugin views (also updates), for all users, current user or all but current user $data = getResult(getNumberOfPluginViews($f_params)); } } } } } } } } } } } } } } } $result = ''; if ($indicatorNr >= 0 && $subIndicatorNr >= 0) { $result .= "{"; $result .= "\"userids\": " . getResult($userGuids) . ",\n"; $result .= "\"usernames\": " . getStringResult($userNames) . ",\n"; $result .= "\"showUsers\": " . getResult($showUsers) . ",\n"; $result .= "\"count\": " . $data; $result .= "}"; } else { if ($indicatorNr >= 0 && $subIndicatorNr == -1) { $result .= "{"; $result .= "\"userids\": " . getResult($userGuids) . ",\n"; $result .= "\"usernames\": " . getStringResult($userNames) . ",\n"; $result .= "\"showUsers\": " . getResult($showUsers) . ",\n"; $result .= "\"data\": " . $data; $result .= "}"; } else { $result .= "{"; $result .= "\"userids\": " . getResult($userGuids) . ",\n"; $result .= "\"usernames\": " . getStringResult($userNames) . ",\n"; $result .= "\"showUsers\": " . getResult($showUsers) . ",\n"; $f_params['data0'] = getData0($f_params); $f_params['data1'] = getData1($f_params); $f_params['data2'] = getData2($f_params); $f_params['data3'] = getData3($f_params); $f_params['data4'] = getData4($f_params); $result .= "\"data0\": " . getUserResults($f_params['data0'], $f_params) . ",\n" . "\"data1\": " . getUserResults($f_params['data1'], $f_params) . ",\n" . "\"data2\": " . getUserResults($f_params['data2'], $f_params) . ",\n" . "\"data3\": " . getUserResults($f_params['data3'], $f_params) . ",\n" . "\"data4\": " . getUserResults($f_params['data4'], $f_params); $result .= "}"; } } return $result; }
/** * Function getuserConvo * * * @param $id * @param $showing * @return mixed|string */ function getuserConvo($id, $showing) { global $dbConn; $bot_name = isset($_SESSION['poadmin']['bot_name']) ? $_SESSION['poadmin']['bot_name'] : 'Bot'; $bot_id = isset($_SESSION['poadmin']['bot_id']) ? $_SESSION['poadmin']['bot_id'] : 0; $nameList = getUserNames(); $user_name = $nameList[$id]; switch ($showing) { case "today": $sqladd = "AND DATE(`timestamp`) = '" . date('Y-m-d') . "'"; $title = "Today's "; break; case "previous week": $lastweek = strtotime("-1 week"); $sqladd = "AND DATE(`timestamp`) >= '" . $lastweek . "'"; $title = "Last week's "; break; case "previous 2 weeks": $lasttwoweek = strtotime("-2 week"); $sqladd = "AND DATE(`timestamp`) >= '" . $lasttwoweek . "'"; $title = "Last two week's "; break; case "previous month": $lastmonth = strtotime("-1 month"); $sqladd = "AND DATE(`timestamp`) >= '" . $lastmonth . "'"; $title = "Last month's "; break; case "previous 6 months": $lastsixmonth = strtotime("-6 month"); $sqladd = "AND DATE(`timestamp`) >= '" . $lastsixmonth . "'"; $title = "Last six month's "; break; case "past 12 months": $lastyear = strtotime("-1 year"); $sqladd = "AND DATE(`timestamp`) >= '" . $lastyear . "'"; $title = "Last twelve month's "; break; case "all time": $sql = ""; $title = "All "; break; default: $sqladd = ""; $title = "Last "; } $lasttimestamp = ""; $i = 1; //get undefined defaults from the db $sql = "SELECT * FROM `conversation_log` WHERE `bot_id` = '{$bot_id}' AND `user_id` = {$id} {$sqladd} ORDER BY `id` ASC"; $list = "<hr><br/><h4>{$title} conversations for user: {$id}</h4>"; $list .= "<div class=\"convolist\">"; $result = db_fetchAll($sql, null, __FILE__, __FUNCTION__, __LINE__); foreach ($result as $row) { $thisdate = date("Y-m-d", strtotime($row['timestamp'])); if ($thisdate != $lasttimestamp) { if ($i > 1) { if ($showing == "last 20") { break; } } $date = date("Y-m-d"); $list .= "<hr><br/><h4>Conversation#{$i} {$thisdate}</h4>"; $i++; } $list .= "<br><span style=\"color:DARKBLUE;\">{$user_name}: " . $row['input'] . "</span>"; $list .= "<br><span style=\"color:GREEN;\">{$bot_name}: " . $row['response'] . "</span>"; $lasttimestamp = $thisdate; } $list .= "</div>"; $list = str_ireplace('<script', '<script', $list); return $list; }
function displayNewsItems($group_id = 0, $max_news_items = 10, $max_news_length = -1, $display_mode = 1, $lang_id = 'AUTO', $strip_tags = true, $allowed_tags = '<p><a><img>', $custom_placeholder = false, $sort_by = 1, $sort_order = 1, $not_older_than = 0, $group_id_type = 'group_id', $lang_filter = false) { global $wb, $database, $LANG; /** * Is the first arg an array() we're using this one! * Keep in mind, that all other args may be overwriten/ignore by * the settings inside this array! * * e.g. * $config = array( 'max_news_items' => 5 ); * displayNewsItems( $config, 23, ... * * Only 5 news-items (not 23) are shown, as the first array overwrites the following params! * */ $all_args = func_get_args(); if (isset($all_args[0]) && is_array($all_args[0])) { // param 1 is pass as an array! We're using this as our config! $defaults = array('group_id' => 0, 'max_news_items' => 10, 'max_news_length' => -1, 'display_mode' => 1, 'lang_id' => 'AUTO', 'strip_tags' => true, 'allowed_tags' => '<p><a><img>', 'custom_placeholder' => false, 'sort_by' => 1, 'sort_order' => 1, 'not_older_than' => 0, 'group_id_type' => 'group_id', 'lang_filter' => false); // overwrite the defaults within the values of the $config foreach ($all_args[0] as $key => $val) { $defaults[$key] = $val; } foreach ($defaults as $key => $val) { ${$key} = $val; } } /** * Include required Anynews files */ require_once 'code/anynews_functions.php'; require_once 'thirdparty/truncate.php'; require_once WB_PATH . '/include/phplib/template.inc'; /** * Sanitize user specified function parameters */ sanitizeUserInputs($group_id, 'i{0;0;999}'); sanitizeUserInputs($max_news_items, 'i{10;1;999}'); sanitizeUserInputs($max_news_length, 'i{-1;0;250}'); sanitizeUserInputs($display_mode, 'i{1;1;99}'); sanitizeUserInputs($strip_tags, 'b'); sanitizeUserInputs($allowed_tags, 's{TRIM}'); sanitizeUserInputs($sort_by, 'i{1;1;5}'); sanitizeUserInputs($sort_order, 'i{1;1;2}'); sanitizeUserInputs($not_older_than, 'd{0;0;999}'); sanitizeUserInputs($group_id_type, 'l{group_id;group_id;page_id;section_id;post_id}'); sanitizeUserInputs($lang_filter, 'b'); /** * Include Anynews language file depending on defined $lang_id */ $lang_id = getValidLanguageId($lang_id); loadLanguageFile($lang_id); /** * Create template object and configure it */ $tpl = new Template(dirname(__FILE__) . '/templates'); // configure handling of unknown {variables} (remove:=default, keep, comment) $tpl->set_unknowns('remove'); // configure debug mode (0:= default, 1:=variable assignments, 2:=calls to get variable, 4:=show internals) $tpl->debug = 0; // set template file depending on $display_mode if (file_exists(dirname(__FILE__) . '/templates/display_mode_' . $display_mode . '.htt')) { // set user defined template $tpl->set_file('page', 'display_mode_' . $display_mode . '.htt'); } else { // set default template $tpl->set_file('page', 'display_mode_1.htt'); } // define "read more block" used to show/hide readmore link depending on long news content $tpl->set_block('page', 'readmore_link_block', 'readmore_link_block_handle'); // define optional "custom block" which can be used in template files if needed $tpl->set_block('page', 'custom_block', 'custom_block_handle'); // define "news block" used for text outputs of individual news items (news text, links etc.) $tpl->set_block('page', 'news_block', 'news_block_handle'); // define "news wrapper block" shown if at least one news entry exists $tpl->set_block('page', 'news_available_block', 'news_available_block_handle'); // define "no news wrapper block" shown in no news entry exists $tpl->set_block('page', 'no_news_available_block', 'no_news_available_block_handle'); // replace placeholders with values from language file foreach ($LANG['ANYNEWS'][0] as $key => $value) { $tpl->set_var($key, $value); } /** * Work out SQL query for group_id, limiting news to display depedning by defined $news_filter * option 1: $group_id:=0 => '1' * option 2: $group_id:=X => `group_id_type` = 'X' * option 3: $group_id:=array(2,3) => `group_id_type` IN (2,3) */ // show all news items if 0 is contained in group_id array if (is_array($group_id) && in_array(0, $group_id)) { $group_id = 0; } // check for multiple groups or single group values if (is_array($group_id)) { // SQL query for multiple groups $sql_group_id = "t1.`{$group_id_type}` IN (" . implode(',', $group_id) . ")"; } else { // SQL query for single or empty groups $sql_group_id = $group_id ? "t1.`{$group_id_type}` = '{$group_id}'" : '1'; } /** * Work out SQL query for the not older than option * This options allows to restrict the matches to news not older than X days */ // work out current server time (also used for published_when and published_until checks) $server_time = time(); $sql_not_older_than = '1'; if ($not_older_than > 0) { $sql_not_older_than = ' (t1.`published_when` >= \'' . ($server_time - $not_older_than * 24 * 60 * 60) . '\')'; } /** * Work out SQL query to hide news added via news pages NOT matching $lang_id * Requires to organize news items via news pages with page language set to $lang_id * Returns all news entries if no news page was found matching given $lang_id **/ $sql_lang_filter = '1'; if ($lang_filter) { // get all page_ids which page language match defined $lang_id $page_ids = getPageIdsByLanguage($lang_id); if (count($page_ids) > 0) { $sql_lang_filter = 't1.`page_id` in (' . implode(',', $page_ids) . ')'; } } /** * Work out SQL sort by and sort order query string */ // creates SQL query for sort by option $order_by_options = array('t1.`position`', 't1.`posted_when`', 't1.`published_when`', 'RAND()', '`comments`'); $sql_order_by = $order_by_options[$sort_by - 1]; // creates SQL query for sort order option $sql_sort_order = $sort_order == 1 ? 'DESC' : 'ASC'; /** * Perform SQL database query for Anynews */ $news_table = TABLE_PREFIX . 'mod_news_posts'; $comments_table = TABLE_PREFIX . 'mod_news_comments'; $sql = "SELECT t1.*, COUNT(`comment_id`) as `comments`\n\t\t\tFROM `{$news_table}` as t1\n\t\t\tLEFT JOIN `{$comments_table}` as t2\n\t\t\tON t1.`post_id` = t2.`post_id`\n\t\t\tWHERE t1.`active` = '1'\n\t\t\tAND {$sql_group_id}\n\t\t\tAND {$sql_lang_filter}\n\t\t\tAND (t1.`published_when` = '0' or t1.`published_when` <= '{$server_time}')\n\t\t\tAND (t1.`published_until` = '0' OR t1.`published_until` >= '{$server_time}')\n\t\t\tAND {$sql_not_older_than}\n\t\t\tGROUP BY t1.`post_id`\n\t\t\tORDER BY {$sql_order_by} {$sql_sort_order}\n\t\t\tLIMIT 0, {$max_news_items}\n\t\t"; /** * Process database query and output the template files */ $results = $database->query($sql); if ($results && $results->numRows() > 0) { // fetch news group titles from news database table $news_group_titles = getNewsGroupTitles(); // fetch user names from users database table $user_list = getUserNames(); // loop through all news articles found $news_counter = 1; while ($row = $results->fetchRow()) { // build absolute links from [wblink] tags found in news short or long text database field $wb->preprocess($row['content_short']); $wb->preprocess($row['content_long']); // fetch custom placeholders from short/long text fields and replace template placeholders with values $custom_vars_short_text = getCustomOutputVariables($row['content_short'], $custom_placeholder, 'SHORT'); $custom_vars_long_text = getCustomOutputVariables($row['content_long'], $custom_placeholder, 'LONG'); $custom_vars = array_merge($custom_vars_short_text, $custom_vars_long_text); // replace custom placeholders in template with values foreach ($custom_vars as $key => $value) { $tpl->set_var($key, $value); } // remove tags from short and long text if defined $row['content_short'] = $strip_tags ? strip_tags($row['content_short'], $allowed_tags) : $row['content_short']; $row['content_long'] = $strip_tags ? strip_tags($row['content_long'], $allowed_tags) : $row['content_long']; // shorten news text to defined news length (-1 for full text length) if ($max_news_length != -1 && strlen($row['content_short']) > $max_news_length) { // consider start position if short content starts with <p> or <div> $start_pos = preg_match('#^(<(p|div)>)#', $row['content_short'], $match) ? strlen($match[0]) : 0; $row['content_short'] = truncate(substr($row['content_short'], $start_pos), $max_news_length, '...', false, true); } // work out group image if exists $group_id = $row['group_id']; $image = ''; if (file_exists(WB_PATH . MEDIA_DIRECTORY . '/.news/image' . $group_id . '.jpg')) { $image = '<img src="' . WB_URL . MEDIA_DIRECTORY . '/.news/image' . $group_id . '.jpg' . '" alt="" />'; } // replace news article dependend template placeholders $tpl->set_var(array('WB_URL' => WB_URL, 'GROUP_IMAGE' => $image, 'NEWS_ID' => $news_counter, 'POST_ID' => (int) $row['post_id'], 'SECTION_ID' => (int) $row['section_id'], 'PAGE_ID' => (int) $row['page_id'], 'GROUP_ID' => (int) $row['group_id'], 'GROUP_TITLE' => array_key_exists($row['group_id'], $news_group_titles) ? htmlentities($news_group_titles[$row['group_id']]) : '', 'POSTED_BY' => (int) $row['posted_by'], 'USERNAME' => array_key_exists($row['posted_by'], $user_list) ? htmlentities($user_list[$row['posted_by']]['USERNAME']) : '', 'DISPLAY_NAME' => array_key_exists($row['posted_by'], $user_list) ? htmlentities($user_list[$row['posted_by']]['DISPLAY_NAME']) : '', 'TITLE' => $strip_tags ? strip_tags($row['title']) : $row['title'], 'COMMENTS' => isset($row['comments']) ? $row['comments'] : 0, 'LINK' => WB_URL . PAGES_DIRECTORY . $row['link'] . PAGE_EXTENSION, 'CONTENT_SHORT' => $image . $row['content_short'], 'CONTENT_LONG' => $row['content_long'], 'POSTED_WHEN' => date($LANG['ANYNEWS'][0]['DATE_FORMAT'], $row['posted_when']), 'PUBLISHED_WHEN' => date($LANG['ANYNEWS'][0]['DATE_FORMAT'], $row['published_when']), 'PUBLISHED_UNTIL' => date($LANG['ANYNEWS'][0]['DATE_FORMAT'], $row['published_until']))); // remove "read more block" from template if no long content is available $tpl->parse('readmore_link_block_handle', 'readmore_link_block', false); if (!isset($row['content_long']) || !strlen($row['content_long']) > 0) { $tpl->set_var('readmore_link_block_handle', ''); } // add optional custom template block in append mode (add per loop) $tpl->parse('custom_block_handle', 'custom_block', true); // add template values in news block in append mode (add per loop) $tpl->parse('news_block_handle', 'news_block', true); // remove custom variables to start blank for the next news entry foreach ($custom_vars as $key => $value) { $tpl->set_var($key, ''); } $news_counter++; } // update the total number of news items $tpl->set_var('NEWS_ITEMS', $news_counter - 1); // remove the "no news available block" from output $tpl->set_var('no_news_available_block_handle', ''); // parse the news content block $tpl->parse('news_available_block_handle', 'news_available_block', false); } else { // update the total number of news items $tpl->set_var('NEWS_ITEMS', 0); // remove the "news available block" from output $tpl->set_var('news_available_block_handle', ''); // remove blocks not used $tpl->parse('no_news_available_block_handle', 'no_news_available_block', true); } // ouput the final template $tpl->pparse('output', 'page'); }