public function main() { // Loop through 200 users at one time $limit = 200; // Set all points status to 0 first. $db = FD::db(); $sql = $db->sql(); $sql->update('#__social_points_history'); $sql->set('state', 0); $db->setQuery($sql); $db->Query(); // Now we need to merge all of these records into 1 $sql->clear(); // We need to use Joomla's date instead of mysql's NOW() because the timezone on mysql could be different. $date = FD::date(); $query = array(); $query[] = 'INSERT INTO `#__social_points_history`(`points_id`,`user_id`,`points`,`created`,`state`,`message`)'; $query[] = "SELECT 0, `user_id` ,SUM(`points`), '" . $date->toSql() . "', 1, 'COM_EASYSOCIAL_POINTS_AGGREGATED' FROM `#__social_points_history` GROUP BY `user_id`"; $query = implode(' ', $query); $sql->raw($query); $db->setQuery($sql); $db->Query(); // Then we need to delete all the unpublished records $sql->clear(); $sql->delete('#__social_points_history'); $sql->where('state', 0); $db->setQuery($sql); $db->Query(); // Also delete any points history that is assigned to guests $sql->clear(); $sql->delete('#__social_points_history'); $sql->where('user_id', 0); $db->setQuery($sql); $db->Query(); }
public function sidebarBottom($groupId) { $params = $this->getParams(); if (!$params->get('widget', true)) { return; } $group = FD::group($groupId); if (!$group->getAccess()->get('events.groupevent', true)) { return; } $my = FD::user(); $days = $params->get('widget_days', 14); $total = $params->get('widget_total', 5); $date = FD::date(); $now = $date->toSql(); $future = FD::date($date->toUnix() + $days * 24 * 60 * 60)->toSql(); $options = array(); $options['start-after'] = $now; $options['start-before'] = $future; $options['limit'] = $total; $options['state'] = SOCIAL_STATE_PUBLISHED; $options['ordering'] = 'start'; $options['group_id'] = $groupId; $events = FD::model('Events')->getEvents($options); if (empty($events)) { return; } $theme = FD::themes(); $theme->set('events', $events); $theme->set('app', $this->app); echo $theme->output('themes:/apps/user/events/widgets/dashboard/upcoming'); }
/** * Returns an array of news item in JSON format. * * @since 1.0 * @access public * @param Array A list of news items. * @return SocialAjax * */ public function getNews($news, $appNews = array()) { $ajax = FD::ajax(); // Format the output of the news item since we need the following values // day,month foreach ($news as &$item) { $date = explode('/', $item->date); $item->day = $date[0]; $item->month = $date[1]; } $theme = FD::themes(); $theme->set('items', $news); $content = $theme->output('admin/news/items'); if ($appNews) { foreach ($appNews as &$appItem) { $date = FD::date($appItem->updated); $appItem->lapsed = $date->toLapsed(); $appItem->day = $date->format('d'); $appItem->month = $date->format('M'); } } $theme = FD::themes(); $theme->set('items', $appNews); $apps = $theme->output('admin/news/apps'); return $ajax->resolve($content, $apps); }
/** * Restful api to submit a new comment on the site * * @since 1.2 * @access public * @param string * @return */ public function post() { // Get the user's id by validation $userId = $this->validateAuth(); $uid = $this->input->get('uid', 0, 'int'); $element = $this->input->get('element', '', 'string'); $verb = $this->input->get('verb', '', 'cmd'); $group = $this->input->get('group', '', 'cmd'); $streamId = $this->input->get('stream_id', 0, 'int'); // Determines the comments parent $parent = $this->input->get('parent', 0, 'int'); // Comment data $content = $this->input->get('content', '', 'default'); // Content cannot be empty if (empty($content)) { $this->set('code', 403); $this->set('message', JText::_('Please enter some contents for the comment.')); return parent::display(); } // Format the element $element = $element . '.' . $group . '.' . $verb; // Get the table object $table = FD::table('Comments'); $table->element = $element; $table->uid = $uid; $table->comment = $content; $table->created_by = $userId; $table->created = FD::date()->toSql(); $table->parent = $parent; $table->stream_id = $streamId; $state = $table->store(); $this->set('status', 1); parent::display(); }
public function onDisplay($user) { $regDate = FD::date($user->registerDate); $format = 'd M Y'; switch ($this->params->get('date_format')) { case 2: case '2': $format = 'M d Y'; break; case 3: case '3': $format = 'Y d M'; break; case 4: case '4': $format = 'Y M d'; break; } // linkage to advanced search page. // place the code here so that the timezone wont kick in. we search the date using GMT value. $field = $this->field; if ($field->searchable) { $date = $regDate->toFormat('Y-m-d'); $params = array('layout' => 'advanced'); $params['criterias[]'] = $field->unique_key . '|' . $field->element; $params['operators[]'] = 'between'; $params['conditions[]'] = $date . ' 00:00:00' . '|' . $date . ' 23:59:59'; $advsearchLink = FRoute::search($params); $this->set('advancedsearchlink', $advsearchLink); } $this->set('date', $regDate->toFormat($format)); return $this->display(); }
/** * Broadcast a message to a set of profiles on the site. * * @since 1.3 * @access public * @param int The profile id to target. 0 for all * @param string The message to be broadcasted * @param string The title for the announcement * @return */ public function broadcast($id, $content, $createdBy, $title = '', $link = '') { $db = FD::db(); $sql = $db->sql(); $query = array(); $query[] = 'INSERT INTO ' . $db->quoteName('#__social_broadcasts'); $query[] = '(`target_id`,`target_type`,`title`,`content`,`link`,`state`,`created`,`created_by`)'; // Get the creation date $date = FD::date(); $query[] = 'SELECT'; $query[] = '`user_id`,' . $db->Quote(SOCIAL_TYPE_USER) . ',' . $db->Quote($title) . ',' . $db->Quote($content) . ',' . $db->Quote($link) . ',1,' . $db->Quote($date->toSql()) . ',' . $db->Quote($createdBy); $query[] = 'FROM ' . $db->quoteName('#__social_profiles_maps'); $query[] = 'WHERE 1'; if (!empty($id)) { $query[] = 'AND ' . $db->quoteName('profile_id') . '=' . $db->Quote($id); } // Exclude the broadcaster because it would be pretty insane if I am spamming myself $my = FD::user(); $query[] = 'AND `user_id` !=' . $db->Quote($my->id); $query = implode(' ', $query); $sql->raw($query); $db->setQuery($sql); $state = $db->Query(); if (!$state) { return $state; } // Get the id of the new broadcasted item $id = $db->insertid(); return $id; }
/** * Given a path to the file, install the points. * * @since 1.0 * @access public * @param string The path to the .points file. * @return bool True if success false otherwise. */ public function install($file) { // Import platform's file library. jimport('joomla.filesystem.file'); // Convert the contents to an object $alerts = FD::makeObject($file); $result = array(); if ($alerts) { foreach ($alerts as $alert) { $table = FD::table('Alert'); $exists = $table->load(array('element' => $alert->element, 'rule' => $alert->rule)); if (!$exists) { $table->element = $alert->element; $table->rule = $alert->rule; $table->created = FD::date()->toSql(); if (!isset($alert->value)) { $table->email = true; $table->system = true; } else { $table->email = $alert->value->email; $table->system = $alert->value->system; } } $table->app = isset($alert->app) ? $alert->app : false; $table->field = isset($alert->field) ? $alert->field : false; $table->group = isset($alert->group) ? $alert->group : false; $table->extension = isset($alert->extension) ? $alert->extension : false; $table->core = isset($alert->core) ? $alert->core : 0; $table->app = isset($alert->app) ? $alert->app : 0; $table->field = isset($alert->field) ? $alert->field : 0; $result[] = $table->store(); } } return $result; }
public function getEndDate() { static $dates = array(); if (!isset($dates[$this->id])) { $dates[$this->id] = FD::date($this->date_end); } return $dates[$this->id]; }
/** * Stores the relationship data. * * @author Jason Rey <*****@*****.**> * @since 1.0 * @access public * @param boolean $updateNulls True to update fields even if they are null. * @return boolean True on success. */ public function store($updateNulls = false) { $db = FD::db(); if (is_null($this->created)) { $this->created = FD::date()->toSql(); } return parent::store($updateNulls); }
/** * Allows caller to update a stream * * @since 1.2 * @access public * @param string * @return */ public function update() { // Check for request forgeries FD::checkToken(); // Check for valid users FD::requireLogin(); // Get the current view $view = $this->getCurrentView(); // Get the stream id $id = JRequest::getInt('id'); $stream = FD::table('Stream'); $stream->load($id); // Check for valid stream id's. if (!$id || !$stream->id) { $view->setMessage(JText::_('COM_EASYSOCIAL_STREAM_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // @TODO: Check for permissions $my = FD::user(); if ($stream->cluster_id) { $group = FD::group($stream->cluster_id); if (!$my->isSiteAdmin() && $stream->actor_id != $my->id && !$group->isAdmin()) { $view->setMessage(JText::_('COM_EASYSOCIAL_STREAM_NO_PERMISSIONS_TO_EDIT'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } } else { if (!$my->isSiteAdmin() && $stream->actor_id != $my->id) { $view->setMessage(JText::_('COM_EASYSOCIAL_STREAM_NO_PERMISSIONS_TO_EDIT'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } } $content = JRequest::getVar('content', '', 'post', 'string', JREQUEST_ALLOWRAW); $mentions = JRequest::getVar('mentions'); // Format the json string to array if (!empty($mentions)) { foreach ($mentions as &$mention) { $mention = FD::json()->decode($mention); } } // Process the content $stream->content = $content; // Set the last edited date $stream->edited = FD::date()->toSql(); // Get the stream model and remove mentions $model = FD::model('Stream'); $model->removeMentions($stream->id); // Now we need to add new mentions if ($mentions) { $model->addMentions($stream->id, $mentions); } // Save the stream $stream->store(); // Because we know that story posts only has 1 item, we may safely assume that the first index. $items = $stream->getItems(); $item = $items[0]; return $view->call(__FUNCTION__, $item); }
public function post() { $app = JFactory::getApplication(); $element = $app->input->get('element', '', 'string'); $group = $app->input->get('group', '', 'string'); $verb = $app->input->get('verb', '', 'string'); $uid = $app->input->get('uid', 0, 'int'); //element id $input = $app->input->get('comment', "", 'RAW'); $params = $app->input->get('params', array(), 'ARRAY'); //params $streamid = $app->input->get('stream_id', '', 'INT'); //whole stream id $parent = $app->input->get('parent', 0, 'INT'); //parent comment id $result = new stdClass(); $valid = 1; if (!$uid) { $result->id = 0; $result->status = 0; $result->message = 'Empty element id not allowed'; $valid = 0; } // Message should not be empty. if (!$streamid) { $result->id = 0; $result->status = 0; $result->message = 'Empty stream id not allowed'; $valid = 0; } else { if ($valid) { // Normalize CRLF (\r\n) to just LF (\n) $input = str_ireplace("\r\n", "\n", $input); $compositeElement = $element . '.' . $group . '.' . $verb; $table = FD::table('comments'); $table->element = $compositeElement; $table->uid = $uid; $table->comment = $input; $table->created_by = FD::user()->id; $table->created = FD::date()->toSQL(); $table->parent = $parent; $table->params = $params; $table->stream_id = $streamid; $state = $table->store(); if ($state) { //create result obj $result->status = 1; $result->message = 'comment saved successfully'; } else { //create result obj $result->status = 0; $result->message = 'Unable to save comment'; } } } $this->plugin->setResponse($result); }
/** * Sends a new share to a user. * * @since 1.0 * @access public */ public function send() { FD::checkToken(); $token = JRequest::getString('token', ''); $recipients = JRequest::getVar('recipients', array()); $content = JRequest::getVar('content', ''); // Get the current view. $view = $this->getCurrentView(); // Cleaning if (is_string($recipients)) { $recipients = explode(',', FD::string()->escape($recipients)); } if (is_array($recipients)) { foreach ($recipients as &$recipient) { $recipient = FD::string()->escape($recipient); if (!JMailHelper::isEmailAddress($recipient)) { return $view->call(__FUNCTION__, false, JText::_('COM_EASYSOCIAL_SHARING_EMAIL_INVALID_RECIPIENT')); } } } $content = FD::string()->escape($content); // Check for valid data if (empty($recipients)) { return $view->call(__FUNCTION__, false, JText::_('COM_EASYSOCIAL_SHARING_EMAIL_NO_RECIPIENTS')); } if (empty($token)) { return $view->call(__FUNCTION__, false, JText::_('COM_EASYSOCIAL_SHARING_EMAIL_INVALID_TOKEN')); } $session = JFactory::getSession(); $config = FD::config(); $limit = $config->get('sharing.email.limit', 0); $now = FD::date()->toUnix(); $time = $session->get('easysocial.sharing.email.time'); $count = $session->get('easysocial.sharing.email.count'); if (is_null($time)) { $session->set('easysocial.sharing.email.time', $now); $time = $now; } if (is_null($count)) { $session->set('easysocial.sharing.email.count', 0); } $diff = $now - $time; if ($diff <= 3600) { if ($limit > 0 && $count >= $limit) { return $view->call(__FUNCTION__, false, JText::_('COM_EASYSOCIAL_SHARING_EMAIL_SHARING_LIMIT_MAXED')); } $count++; $session->set('easysocial.sharing.email.count', $count); } else { $session->set('easysocial.sharing.email.time', $now); $session->set('easysocial.sharing.email.count', 1); } $library = FD::get('Sharing'); $library->sendLink($recipients, $token, $content); $view->call(__FUNCTION__, true); }
public function onRegisterOAuthBeforeSave(&$post, $client) { if (empty($post['birthday'])) { return; } // Facebook format is M/D/Y, we reformat it to Y-M-D $date = explode('/', $post['birthday']); $reformedDate = FD::date($date[2] . '-' . $date[0] . '-' . $date[1]); $post[$this->inputName] = array('date' => $reformedDate->toSql()); }
/** * Purges the URL cache from the site * * @since 1.0 * @access public * @param int The number of days interval * @return bool True on success, false otherwise. */ public function clearExpired($interval) { $db = FD::db(); $sql = $db->sql(); $date = FD::date(); $query = 'DELETE FROM `#__social_links` WHERE DATE_ADD( `created` , INTERVAL ' . $interval . ' DAY) <= ' . $db->Quote($date->toMySQL()); $sql->raw($query); $db->setQuery($sql); return $db->Query(); }
/** * Responsible to process cron items for oauth items * * @since 1.0 * @access public * @param string * @return */ public function onCronExecute() { // We'll temporarily disable this. return; $model = FD::model('OAuth'); // Load up facebook client $facebookClient = FD::oauth('facebook'); // Get a list of pullable items $oauthUsers = $model->getPullableClients(); if (!$oauthUsers) { return; } // Go through each of the pullable users foreach ($oauthUsers as $oauthUser) { // Simulate the user now by passing in their valid token. $facebookClient->setAccess($oauthUser->token); // Get the stream items from Facebook $items = $facebookClient->pull(); // echo '<pre>'; // print_r( $items ); // echo '</pre>'; // exit; foreach ($items as $item) { // Store this into the stream now. $stream = FD::stream(); // Get the stream template $template = $stream->getTemplate(); $template->setActor($oauthUser->uid, $oauthUser->type); $template->setContext($item->get('id'), SOCIAL_TYPE_FACEBOOK); $template->setContent($item->get('content')); $template->setVerb('update'); $template->setAccess('core.view'); // Create the new stream item. $streamTable = $stream->add($template); // Store into the stream assets table as the app needs this. $assets = FD::table('StreamAsset'); $assets->stream_id = $streamTable->id; $assets->type = SOCIAL_TYPE_FACEBOOK; $assets->data = $item->toString(); $assets->store(); // Store into the import history. $history = FD::table('OAuthHistory'); $history->remote_id = $item->get('id'); $history->remote_type = $item->get('type'); $history->local_id = $streamTable->id; $history->local_type = SOCIAL_TYPE_STREAM; $history->store(); } // Update the last pulled item datetime. $oauthTable = FD::table('OAuth'); $oauthTable->bind($oauthUser); $oauthTable->last_pulled = FD::date()->toMySQL(); $state = $oauthTable->store(); } }
/** * Formats a given date string with a given date format * * @since 1.0 * @access public * @param string The current timestamp * @param string The language string format or the format for Date * @param bool Determine if it should be using the appropriate offset or GMT * @return */ public static function date($timestamp, $format = '', $withOffset = true) { // Get the current date object based on the timestamp provided. $date = FD::date($timestamp, $withOffset); // If format is not provided, we should use DATE_FORMAT_LC2 by default. $format = empty($format) ? 'DATE_FORMAT_LC2' : $format; // Get the proper format. $format = JText::_($format); $dateString = $date->toFormat($format); return $date->toFormat($format); }
/** * Generates a unique token for the current session. * Without this token, the caller isn't allowed to upload the file. * * @since 1.0 * @param null * @return string A 12 digit token that can only be used once. */ public function generateToken() { // Generate a unique id. $id = uniqid(); // Add md5 hash $id = md5($id); $table = FD::table('UploaderToken'); $table->token = $id; $table->created = FD::date()->toMySQL(); $table->store(); return $id; }
/** * Displays the age in the position profileHeaderA * * @since 1.0 * @access public * @param string * @return */ public function profileHeaderA($key, $user, $field) { $my = FD::user(); $privacyLib = FD::privacy($my->id); if (!$privacyLib->validate('core.view', $field->id, SOCIAL_TYPE_FIELD, $user->id)) { return; } $params = $field->getParams(); if ($params->get('show_age') && !$privacyLib->validate('field.birthday', $field->id, 'year', $user->id)) { return; } // Get the current stored value. $value = $field->data; if (empty($value)) { return false; } if (is_array($value) && isset($value['date']) && !$value['date']) { // empty value. just return empty string. return false; } $data = new SocialFieldsUserDateTimeObject($value); $date = null; if (!empty($data->year) && !empty($data->month) && !empty($data->day)) { $date = $data->year . '-' . $data->month . '-' . $data->day; } if (!$date) { return; } $allowYear = true; $theme = FD::themes(); if ($params->get('show_age')) { // Compute the age now. $age = $this->getAge($date); $theme->set('value', $age); } else { $allowYear = $privacyLib->validate('field.birthday', $field->id, 'year', $user->id); $format = $allowYear ? 'j F Y' : 'j F'; $birthday = FD::date($date, false)->format($format); $theme->set('value', $birthday); } // linkage to advanced search page. if ($allowYear && $field->searchable) { $date = $data->format('Y-m-d'); $params = array('layout' => 'advanced'); $params['criterias[]'] = $field->unique_key . '|' . $field->element; $params['operators[]'] = 'between'; $params['conditions[]'] = $date . ' 00:00:00' . '|' . $date . ' 23:59:59'; $advsearchLink = FRoute::search($params); $theme->set('advancedsearchlink', $advsearchLink); } $theme->set('params', $params); echo $theme->output('fields/user/birthday/widgets/display'); }
/** * Displays the dashboard widget * * @since 1.0 * @access public * @param string * @return */ public function sidebarBottom() { // Get the app params $params = $this->app->getParams(); $key = $params->get('dashboard_show_uniquekey', 'BIRTHDAY'); $displayYear = $params->get('dashboard_show_birthday', 1); // Get current logged in user $my = FD::user(); $birthdays = $this->getUpcomingBirthdays($key, $my->id); $ids = array(); $dateToday = FD::date()->toFormat('md'); $today = array(); $otherDays = array(); // Hide app when there's no upcoming birthdays if (!$birthdays) { return; } $my = FD::user(); $privacy = FD::privacy($my->id); if ($birthdays) { foreach ($birthdays as $birthday) { $ids[] = $birthday->uid; } // Preload list of users FD::user($ids); foreach ($birthdays as $birthday) { $obj = new stdClass(); $obj->user = FD::user($birthday->uid); $obj->birthday = $birthday->displayday; //Checking to display year here if ($displayYear) { $dateFormat = JText::_('COM_EASYSOCIAL_DATE_DMY'); //check birtday the year privacy if (!$privacy->validate('field.birthday', $birthday->field_id, 'year', $birthday->uid)) { $dateFormat = JText::_('COM_EASYSOCIAL_DATE_DM'); } } else { $dateFormat = JText::_('COM_EASYSOCIAL_DATE_DM'); } $obj->display = FD::date($obj->birthday)->format($dateFormat); if ($birthday->day == $dateToday) { $today[] = $obj; } else { $otherDays[] = $obj; } } } $this->set('ids', $ids); $this->set('birthdays', $birthdays); $this->set('today', $today); $this->set('otherDays', $otherDays); echo parent::display('widgets/upcoming.birthday'); }
public function main() { // Only birthday field and datetime field is affected $birthdayTable = FD::table('app'); $birthdayTable->load(array('type' => SOCIAL_APPS_TYPE_FIELDS, 'group' => SOCIAL_FIELDS_GROUP_USER, 'element' => 'birthday')); $datetimeTable = FD::table('app'); $datetimeTable->load(array('type' => SOCIAL_APPS_TYPE_FIELDS, 'group' => SOCIAL_FIELDS_GROUP_USER, 'element' => 'datetime')); // $appid = array($birthdayTable->id, $datetimeTable->id); $db = FD::db(); $sql = $db->sql(); // $sql->select('#__social_fields_data') // ->where('field_id', $appid, 'in') // ->where('data', '', '!='); $query = "select a.* from `#__social_fields_data` as a"; $query .= "\tinner join `#__social_fields` as b on a.`field_id` = b.`id`"; $query .= " where b.`app_id` IN ({$birthdayTable->id}, {$datetimeTable->id})"; $query .= " and a.`data` != ''"; // echo $query;exit; $sql->raw($query); $db->setQuery($sql); $result = $db->loadObjectList(); $json = FD::json(); foreach ($result as $row) { if (empty($row->data)) { continue; } $table = FD::table('fielddata'); $table->bind($row); if ($json->isJsonString($table->data)) { $val = $json->decode($table->data); if ($val->year && $val->month && $val->day) { $dateVal = $val->year . '-' . $val->month . '-' . $val->day; $table->raw = FD::date($val->year . '-' . $val->month . '-' . $val->day)->toSql(); } } else { try { $val = FD::date($table->data); } catch (Exception $e) { $table->data = ''; $table->raw = ''; $table->store(); continue; } $table->data = $json->encode(array('year' => $val->toFormat('Y'), 'month' => $val->toFormat('n'), 'day' => $val->toFormat('j'))); $table->raw = $val->toSql(); } $table->store(); } return true; }
/** * Main method to display the dashboard view. * * @since 1.0 * @access public * @return null * * @author Mark Lee <*****@*****.**> */ public function display($tpl = null) { // Add heading here. $this->setHeading(JText::_('COM_EASYSOCIAL_HEADING_DASHBOARD')); // Set page icon. $this->setIconUrl(rtrim(JURI::root(), '/') . '/media/com_easysocial/images/icons/logo/large.png', false); // Add description here. $this->setDescription(JText::_('COM_EASYSOCIAL_DESCRIPTION_DASHBOARD')); // Get users model $usersModel = FD::model('Users'); // Get total albums $photosModel = FD::model('Albums'); $totalAlbums = $photosModel->getTotalAlbums(); // Get mailer model $mailerModel = FD::model('Mailer'); $mailStats = $mailerModel->getDeliveryStats(); // profiles signup data $profilesModel = FD::model('Profiles'); $signupData = $profilesModel->getRegistrationStats(); $xAxes = array(); foreach ($signupData->dates as $date) { $xAxes[] = FD::date($date)->format(JText::_('COM_EASYSOCIAL_DATE_DM')); } // Add translation on the profile title foreach ($signupData->profiles as $profile) { $profile->title = JText::_($profile->title); } $pendingUsers = $usersModel->getPendingUsers(); $totalPending = count($pendingUsers); // Get total number of groups $groupsModel = FD::model('Groups'); $totalGroups = $groupsModel->getTotalGroups(); $this->set('mailStats', $mailStats); $this->set('axes', $xAxes); $this->set('signupData', $signupData); $this->set('totalPending', $totalPending); $this->set('pendingUsers', $pendingUsers); $this->set('totalUsers', $usersModel->getTotalUsers()); $this->set('totalOnline', $usersModel->getTotalOnlineUsers()); $this->set('totalGroups', $totalGroups); $this->set('totalAlbums', $totalAlbums); // Add Joomla button if (FD::user()->authorise('core.admin', 'com_easysocial')) { JToolbarHelper::preferences('com_easysocial'); } // Add clear cache button here. JToolbarHelper::custom('clearCache', 'trash', '', JText::_('COM_EASYSOCIAL_TOOLBAR_BUTTON_PURGE_CACHE'), false); echo parent::display('admin/easysocial/default'); }
/** * Returns the SocialDate object of the event end datetime. * * @author Jason Rey <*****@*****.**> * @since 1.3 * @access public * @return SocialDate The SocialDate object of the event end datetime. */ public function getEnd() { // If there's no end date, we assume that the end date is the same as the start date if (empty($this->end) || $this->end === '0000-00-00 00:00:00') { $datetime = FD::date($this->start, false); } else { $datetime = FD::date($this->end, false); } if (!empty($this->timezone)) { try { $datetime->setTimezone(new DateTimeZone($this->timezone)); } catch (Exception $e) { } } return $datetime; }
public function getCreatedEvents(SocialUser $user, $limit, $params) { $model = FD::model('Events'); $now = FD::date()->toSql(); $createdEvents = $model->getEvents(array('creator_uid' => $user->id, 'creator_type' => SOCIAL_TYPE_USER, 'state' => SOCIAL_STATE_PUBLISHED, 'ordering' => 'start', 'type' => array(SOCIAL_EVENT_TYPE_PUBLIC, SOCIAL_EVENT_TYPE_PRIVATE), 'limit' => $limit, 'start-after' => $now)); $createdTotal = $model->getTotalEvents(array('creator_uid' => $user->id, 'creator_type' => SOCIAL_TYPE_USER, 'state' => SOCIAL_STATE_PUBLISHED, 'type' => array(SOCIAL_EVENT_TYPE_PUBLIC, SOCIAL_EVENT_TYPE_PRIVATE), 'start-after' => $now)); $attendingEvents = $model->getEvents(array('guestuid' => $user->id, 'gueststate' => SOCIAL_EVENT_GUEST_GOING, 'state' => SOCIAL_STATE_PUBLISHED, 'ordering' => 'start', 'type' => array(SOCIAL_EVENT_TYPE_PUBLIC, SOCIAL_EVENT_TYPE_PRIVATE), 'limit' => $limit, 'start-after' => $now)); $attendingTotal = $model->getTotalEvents(array('guestuid' => $user->id, 'gueststate' => SOCIAL_EVENT_GUEST_GOING, 'state' => SOCIAL_STATE_PUBLISHED, 'type' => array(SOCIAL_EVENT_TYPE_PUBLIC, SOCIAL_EVENT_TYPE_PRIVATE), 'start-after' => $now)); $theme = FD::themes(); $theme->set('createdEvents', $createdEvents); $theme->set('createdTotal', $createdTotal); $theme->set('attendingEvents', $attendingEvents); $theme->set('attendingTotal', $attendingTotal); $theme->set('app', $this->app); echo $theme->output('themes:/apps/user/events/widgets/profile/events'); }
public function store($updateNulls = false) { $now = FD::date(); // Set created to now by default if (empty($this->created)) { $this->created = $now->toSql(); } // Set expired to 1 day later by default if (empty($this->expired)) { $this->expired = FD::date($now->toUnix() + 24 * 60 * 60)->toSql(); } if (is_array($this->value) || is_object($this->value)) { $this->value = FD::json()->encode($this->value); } return parent::store($updateNulls); }
/** * Synchronize Users on the site. * * @since 1.0 * @access public * @param string * @return */ public function syncUsers() { // Hardcoded to sync 50 users at a time. $limit = 100; // Fetch first $limit items to be processed. $db = FD::db(); $query = array(); $query[] = 'SELECT a.' . $db->nameQuote('id') . ' FROM ' . $db->nameQuote('#__users') . ' AS a'; $query[] = 'WHERE a.' . $db->nameQuote('id') . ' NOT IN( SELECT b.' . $db->nameQuote('user_id') . ' FROM ' . $db->nameQuote('#__social_users') . ' AS b )'; $query[] = 'LIMIT 0,' . $limit; $db->setQuery($query); $items = $db->loadObjectList(); $totalItems = count($items); if (!$items) { // Nothing to process here. $result = new stdClass(); $result->state = 1; $result = $this->getResultObj(JText::_('COM_EASYSOCIAL_INSTALLATION_MAINTENANCE_USERS_NO_UPDATES'), 1, JText::_('COM_EASYSOCIAL_INSTALLATION_STEP_SUCCESS')); return $this->output($result); } // Initialize all these users. $users = FD::user($items); // we need to sync the user into indexer foreach ($users as $user) { $indexer = FD::get('Indexer'); $contentSnapshot = array(); $contentSnapshot[] = $user->getName('realname'); // $contentSnapshot[] = $user->email; $idxTemplate = $indexer->getTemplate(); $content = implode(' ', $contentSnapshot); $idxTemplate->setContent($user->getName('realname'), $content); $url = ''; //FRoute::_( 'index.php?option=com_easysocial&view=profile&id=' . $user->id ); $idxTemplate->setSource($user->id, SOCIAL_INDEXER_TYPE_USERS, $user->id, $url); $date = FD::date(); $idxTemplate->setLastUpdate($date->toMySQL()); $indexer->index($idxTemplate); } // Detect if there are any more records. $query = array(); $query[] = 'SELECT COUNT(1) FROM ' . $db->nameQuote('#__users') . ' AS a'; $query[] = 'WHERE a.' . $db->nameQuote('id') . ' NOT IN( SELECT b.' . $db->nameQuote('user_id') . ' FROM ' . $db->nameQuote('#__social_users') . ' AS b )'; $db->setQuery($query); $total = $db->loadResult(); $result = $this->getResultObj(JText::sprintf('COM_EASYSOCIAL_INSTALLATION_MAINTENANCE_USERS_SYNCED', $totalItems), 2, JText::_('COM_EASYSOCIAL_INSTALLATION_STEP_SUCCESS')); return $this->output($result); }
public function calculateTotalRecur() { $in = FD::input(); $start = $in->getString('start'); $timezone = $in->getString('timezone'); $end = $in->getString('end'); $type = $in->getString('type'); $daily = $in->getVar('daily', array()); $allday = $in->getBool('allday', false); $eventId = $in->getString('eventId'); $changed = $in->getInt('changed'); $showWarningMessages = $in->getInt('showWarningMessages'); if (!empty($timezone) && $timezone !== 'UTC') { $dtz = new DateTimeZone($timezone); // This is to reverse the time back to UTC $start = JFactory::getDate($start, $dtz)->toSql(); } $eventStart = FD::date($start, false); $result = FD::model('Events')->getRecurringSchedule(array('eventStart' => $eventStart, 'end' => $end, 'type' => $type, 'daily' => $daily)); $schedule = array(); $tf = FD::config()->get('events.timeformat', '12h'); foreach ($result as $time) { $schedule[] = FD::date($time)->format(JText::_($allday ? 'COM_EASYSOCIAL_DATE_DMY' : 'COM_EASYSOCIAL_DATE_DMY' . ($tf == '12h' ? '12H' : '24H'))); } if (empty($schedule) && $type != 'none') { FD::ajax()->reject(JText::_('FIELD_EVENT_RECURRING_NO_RECURRING_EVENT_WILL_BE_CREATED')); } $theme = FD::themes(); $total = count($schedule); $limit = FD::config()->get('events.recurringlimit', 0); if (!empty($limit) && $limit != 0 && $total > $limit) { $msg = JText::sprintf('FIELD_EVENT_RECURRING_VALIDATION_MAX_RECURRING_LIMIT', $total, $limit); return FD::ajax()->reject($msg); } $theme->set('schedule', $schedule); $theme->set('type', $type); $hasChildren = !empty($eventId) && FD::model('Events')->getTotalEvents(array('state' => SOCIAL_STATE_PUBLISHED, 'parent_id' => $eventId)) > 0; $theme->set('hasChildren', $hasChildren); if ($type == 'daily') { $theme->set('days', array(JText::_('SUNDAY'), JText::_('MONDAY'), JText::_('TUESDAY'), JText::_('WEDNESDAY'), JText::_('THURSDAY'), JText::_('FRIDAY'), JText::_('SATURDAY'))); $theme->set('daily', $daily); } $theme->set('changed', $changed); $theme->set('showWarningMessages', $showWarningMessages); $html = $theme->output('fields/event/recurring/summary'); FD::ajax()->resolve($html); }
/** * Override parent's load implementation * * @since 1.0 * @access public * @param int The unique row id. * @param bool True to reset the default values before loading the new row. * * @author Mark Lee <*****@*****.**> */ public function load($key = null, $reset = true) { $state = parent::load($key, $reset); // If state is false, then we create the session here if (!$state) { $session = JFactory::getSession(); $this->session_id = $session->getId(); $this->created = FD::date()->toSql(); $state = $this->store(); } // @rule: We want to see which steps the user has already walked through. if (empty($this->step_access)) { $this->step_access = array(); } if (!empty($this->step_access) && is_string($this->step_access)) { $this->step_access = explode(',', $this->step_access); } return $state; }
/** * Retrieves the stats for kunena posts * * @since 1.2 * @access public * @param string * @return */ public function getStats($userId) { $db = FD::db(); $sql = $db->sql(); $dates = array(); // Get the past 7 days $curDate = FD::date(); for ($i = 0; $i < 7; $i++) { $obj = new stdClass(); if ($i == 0) { $dates[] = $curDate->toSql(true); } else { $unixdate = $curDate->toUnix(true); $new_unixdate = $unixdate - $i * 86400; $newdate = FD::date($new_unixdate); $dates[] = $newdate->toSql(true); } } // Reverse the dates $dates = array_reverse($dates); $result = array(); foreach ($dates as $date) { // Registration date should be Y, n, j $date = FD::date($date)->format('Y-m-d'); $query = array(); $query[] = 'SELECT COUNT(1) AS `cnt` FROM `#__kunena_messages` AS a'; $query[] = 'WHERE DATE_FORMAT( from_unixtime( a.' . $db->nameQuote('time') . ') , GET_FORMAT( DATE , "ISO" ) ) =' . $db->Quote($date); $query[] = 'AND a.' . $db->nameQuote('userid') . '=' . $db->Quote($userId); $query[] = 'AND a.' . $db->nameQuote('hold') . '=' . $db->Quote(0); $query[] = 'AND a.' . $db->nameQuote('parent') . '=' . $db->Quote(0); // $query[] = 'group by a.`userid`'; // $query[] = 'SELECT COUNT(1) AS `cnt` FROM `#__kunena_topics` AS a'; // $query[] = 'WHERE DATE_FORMAT( from_unixtime( a.' . $db->nameQuote( 'first_post_time' ) . ') , GET_FORMAT( DATE , "ISO" ) ) =' . $db->Quote( $date ); // $query[] = 'AND a.' . $db->nameQuote( 'first_post_userid' ) . '=' . $db->Quote( $userId ); // $query[] = 'AND a.' . $db->nameQuote( 'hold' ) . '=' . $db->Quote( 0 ); $query = implode(' ', $query); $sql->raw($query); $db->setQuery($sql); $total = $db->loadResult(); $result[] = $total; } return $result; }
/** * Installs a new theme * * @since 1.0 * @access public * @param string * @return */ public function install($file) { $source = $file['tmp_name']; $config = FD::config(); $fileName = md5($file['name'] . FD::date()->toMySQL()); $fileExtension = '_themes_install.zip'; $destination = SOCIAL_TMP . '/' . $fileName . $fileExtension; $state = JFile::upload($source, $destination); if (!$state) { $this->setError(JText::_('COM_EASYSOCIAL_THEMES_INSTALLER_ERROR_COPY_FROM_PHP')); return false; } // Extract to this folder $extracted = dirname($destination) . '/' . $fileName . '_themes_install'; $state = JArchive::extract($destination, $extracted); // Get the configuration file. $manifest = $extracted . '/config/template.json'; // Get the theme object $theme = FD::makeObject($manifest); // Move it to the appropriate folder $finalDest = SOCIAL_SITE_THEMES . '/' . strtolower($theme->element); // @TODO: If folder exists, overwrite it. For now, just throw an error. if (JFolder::exists($finalDest)) { // Cleanup folder JFile::delete($destination); JFolder::delete($extracted); $this->setError(JText::sprintf('COM_EASYSOCIAL_THEMES_INSTALLER_ERROR_SAME_THEME_FOLDER_EXISTS', $theme->element)); return false; } // Move the extracted folder over to the final destination $state = JFolder::move($extracted, $finalDest); if (!$state) { // Cleanup folder JFile::delete($destination); JFolder::delete($extracted); $this->setError(JText::_('COM_EASYSOCIAL_THEMES_INSTALLER_ERROR_MOVING_FOLDER_TO_THEMES_FOLDER')); return false; } // Cleanup the zip file. JFile::delete($destination); return true; }
public function syncIndex() { $indexer = FD::get('Indexer'); $tmpl = $indexer->getTemplate(); $group = FD::group($this->id); $url = $group->getPermalink(); $url = '/' . ltrim($url, '/'); $url = str_replace('/administrator/', '/', $url); $tmpl->setSource($this->id, SOCIAL_INDEXER_TYPE_GROUPS, $this->creator_uid, $url); $content = $this->description ? $this->title . ' ' . $this->description : $this->title; $tmpl->setContent($this->title, $content); $thumbnail = $group->getAvatar(SOCIAL_AVATAR_SQUARE); if ($thumbnail) { $tmpl->setThumbnail($thumbnail); } $date = FD::date(); $tmpl->setLastUpdate($date->toMySQL()); $state = $indexer->index($tmpl); return $state; }