public function save() { $app = JFactory::getApplication(); $model = $this->getModel('badges'); $ruleId = $app->input->post->getInt('ruleId', 0); $userId = $app->input->post->getInt('userId', 0); if ($ruleId && $userId) { $return = $model->get_badge_rules(); $badgeRules = !empty($return->rules) ? $return->rules : array(); if (!empty($badgeRules)) { $selectedRule = null; foreach ($badgeRules as $badgeRule) { if ($badgeRule->id == $ruleId) { $selectedRule = $badgeRule; break; } } if ($selectedRule && $selectedRule->rule_content) { $ruleContent = json_decode($selectedRule->rule_content); if (!empty($ruleContent->rules)) { $params = array(); foreach ($ruleContent->rules as $rule) { $params[$rule->name] = $app->input->post->get($rule->name, null, $rule->dataType); } CjBlogApi::trigger_badge_rule($selectedRule->rule_name, $params, $userId); $this->setRedirect(JRoute::_('index.php?option=' . CJBLOG . '&view=badgeactivity', false), JText::_('COM_CJBLOG_SUCCESS')); return; } } } } $this->setRedirect(JRoute::_('index.php?option=' . CJBLOG . '&view=badgeactivity&task=add', false), JText::_('COM_CJBLOG_ERROR_PROCESSING')); }
function upload_avatar() { $input = JFactory::getApplication()->input; $user = JFactory::getUser(); $id = $input->getInt('id', 0); $xhr = $input->server->get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'; if (!$xhr) { echo '<textarea>'; } if ($user->id != $id && !$user->authorise('core.manage')) { echo json_encode(array('error' => JText::_('JERROR_ALERTNOAUTHOR'))); } else { if (!$id) { echo json_encode(array('error' => JText::_('MSG_ERROR_PROCESSING'))); } else { $tmp_file = $input->files->get('input-avatar-image'); if ($tmp_file['error'] > 0) { echo json_encode(array('error' => JText::_('MSG_ERROR_PROCESSING'))); } else { $temp_image_path = $tmp_file['tmp_name']; $temp_image_name = $tmp_file['name']; $temp_image_ext = JFile::getExt($temp_image_name); list($temp_image_width, $temp_image_height, $temp_image_type) = getimagesize($temp_image_path); if ($temp_image_type === NULL || $temp_image_width < 128 || $temp_image_height < 128 || !in_array(strtolower($temp_image_ext), array('png', 'jpg', 'gif')) || !in_array($temp_image_type, array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF))) { echo json_encode(array('error' => JText::_('MSG_INVALID_IMAGE_FILE'))); } else { $user_profile = CjBlogApi::get_user_profile($id); $file_name = ''; if (!empty($user_profile['avatar'])) { $file_name = $user_profile['avatar']; } else { $file_name = CJFunctions::generate_random_key(25, 'abcdefghijklmnopqrstuvwxyz1234567890') . '.' . $temp_image_ext; } $uploaded_image_path = CJBLOG_AVATAR_BASE_DIR . 'original' . DS . $file_name; if (JFile::upload($temp_image_path, $uploaded_image_path)) { echo json_encode(array('avatar' => array('url' => CJBLOG_AVATAR_BASE_URI . 'original/' . $file_name, 'file_name' => $file_name, 'width' => $temp_image_width, 'height' => $temp_image_height))); } else { echo json_encode(array('error' => JText::_('MSG_ERROR_PROCESSING'))); } } } } } if (!$xhr) { echo '</textarea>'; } jexit(); }
public static function trigger_badge_rule($name, array $params, $userid = 0) { $db = JFactory::getDbo(); if (!$userid) { $userid = JFactory::getUser()->id; } if (CjBlogApi::$_enable_logging) { JLog::add('Trigger Badge Rule - Before Start - Available Badge Rules: ' . count(CjBlogApi::$_badge_rules), JLog::DEBUG, CJBLOG); } if (empty(CjBlogApi::$_badge_rules)) { $query = ' select id, asset_name, rule_name, rule_content, badge_id, access from ' . T_CJBLOG_BADGE_RULES . ' where badge_id in (select badge_id from ' . T_CJBLOG_BADGES . ' where published = 1) and published = 1'; $db->setQuery($query); $rules = $db->loadObjectList(); if (!empty($rules)) { foreach ($rules as $rule) { $content = json_decode($rule->rule_content); if (!empty($content)) { CjBlogApi::$_badge_rules[$rule->rule_name][] = array('id' => $rule->id, 'asset' => $rule->asset_name, 'content' => $content, 'badge_id' => $rule->badge_id, 'access' => $rule->access); } } } else { JLog::add('Trigger Badge Rule - No Rules Loaded. DB Error: ' . $db->getErrorMsg(), JLog::ERROR, CJBLOG); } } if (CjBlogApi::$_enable_logging) { JLog::add('Trigger Badge Rule - Rules Loaded: ' . count(CjBlogApi::$_badge_rules), JLog::DEBUG, CJBLOG); } if (!empty(CjBlogApi::$_badge_rules[$name])) { foreach (CjBlogApi::$_badge_rules[$name] as $badge_rule) { if (!in_array($badge_rule['access'], JAccess::getAuthorisedViewLevels($userid))) { continue; } $rule_content = $badge_rule['content']; if (!empty($rule_content->rules)) { $validated = 0; if (CjBlogApi::$_enable_logging) { JLog::add('Trigger Badge Rule - Before validation. Conditions: ' . count($rule_content->rules), JLog::DEBUG, CJBLOG); } switch ($rule_content->join) { case 'and': $validated = 1; foreach ($rule_content->rules as $rule) { if (empty($params[$rule->name])) { return -1; } if (!CjBlogApi::validate_condition($rule->compare, $rule->dataType, $rule->value, $params[$rule->name])) { $validated = 0; break; } } break; case 'or': foreach ($rule_content->rules as $rule) { if (empty($params[$rule->name])) { return false; } if (CjBlogApi::validate_condition($rule->compare, $rule->dataType, $rule->value, $params[$rule->name])) { $validated = 1; break; } } break; } if (CjBlogApi::$_enable_logging) { JLog::add('Trigger Badge Rule - After validation. Status: ' . $validated, JLog::DEBUG, CJBLOG); } if ($validated == 0) { continue; } // validated, assign badge now. $where = ''; $created = JFactory::getDate()->toSql(); if ($rule_content->multiple == 1) { $ref_id = !empty($params['ref_id']) ? (int) $params['ref_id'] : 0; $where = ' and ref_id > 0 and ref_id=' . $ref_id; } else { $ref_id = 0; } $query = ' select count(*) from ' . T_CJBLOG_USER_BADGE_MAP . ' where user_id = ' . $userid . ' and rule_id = ' . $badge_rule['id'] . ' and badge_id = ' . $badge_rule['badge_id'] . $where; $db->setQuery($query); $count = $db->loadResult(); if ($count > 0) { if (CjBlogApi::$_enable_logging) { JLog::add('Trigger Badge Rule - Conflicting badge exists, returning.', JLog::DEBUG, CJBLOG); } continue; } $query = ' insert into ' . T_CJBLOG_USER_BADGE_MAP . '(user_id, badge_id, rule_id, ref_id, date_assigned) values (' . $userid . ',' . $badge_rule['badge_id'] . ',' . $badge_rule['id'] . ',' . $ref_id . ',' . $db->quote($created) . ')'; $db->setQuery($query); if ($db->query()) { $query = 'update ' . T_CJBLOG_USERS . ' set num_badges = (select count(*) from ' . T_CJBLOG_USER_BADGE_MAP . ' where user_id = ' . $userid . ') where id = ' . $userid; $db->setQuery($query); $db->query(); $query = 'update ' . T_CJBLOG_BADGE_RULES . ' set num_assigned = num_assigned + 1 where id = ' . $badge_rule['id']; $db->setQuery($query); $db->query(); if (CjBlogApi::$_enable_logging) { JLog::add('Trigger Badge Rule - Badge assigned. User ID: ' . $userid . '| Badge ID: ' . $badge_rule['badge_id'], JLog::DEBUG, CJBLOG); } continue; } JLog::add('Trigger Badge Rule - After processing, something went wrong. DB Error: ' . $db->getErrorMsg(), JLog::ERROR, CJBLOG); } } return true; } if (CjBlogApi::$_enable_logging) { JLog::add('Trigger Badge Rule - No rules found with the rule name - ' . $name . ' - to execute.', JLog::DEBUG, CJBLOG); } return false; }
function check_user_credits($userid = 0) { $app = JFactory::getApplication(); if (!$userid) { $user = JFactory::getUser(); $userid = $user->id; } $params = JComponentHelper::getParams(S_APP_NAME); $points_per_credit = (int) $params->get('points_per_credit', 0); if (!$points_per_credit) { return -1; } switch ($params->get('points_system', 'none')) { case 'cjblog': $api = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_cjblog' . DIRECTORY_SEPARATOR . 'api.php'; if (file_exists($api)) { include_once $api; $profile = CjBlogApi::get_user_profile($userid); if (!empty($profile)) { return floor($profile['points'] / $points_per_credit); } } break; case 'aup': $api_AUP = JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; if (file_exists($api_AUP)) { require_once $api_AUP; $profile = AlphaUserPointsHelper::getUserInfo('', $userid); if (!empty($profile)) { return floor($profile->points / $points_per_credit); } } break; case 'jomsocial': $query = 'select points from #__community_users where userid=' . $userid; $this->_db->setQuery($query); $points = (int) $this->_db->loadResult(); return floor($points / $points_per_credit); case 'easysocial': $query = 'select sum(points) from #__social_points_history where user_id = ' . $userid . ' and state = 1'; $this->_db->setQuery($query); $points = (int) $this->_db->loadResult(); return floor($points / $points_per_credit); } return -1; }
public static function get_user_points($system, $userid = 0) { if (!$userid) { return 0; } $app = JFactory::getApplication(); switch ($system) { case 'cjblog': $api = JPATH_ROOT . '/components/com_cjblog/api.php'; if (file_exists($api)) { include_once $api; $profile = CjBlogApi::get_user_profile($userid); if (!empty($profile)) { return $profile['points']; } } break; case 'aup': $api_AUP = JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; if (file_exists($api_AUP)) { require_once $api_AUP; $profile = AlphaUserPointsHelper::getUserInfo('', $userid); if (!empty($profile)) { return $profile->points; } } break; case 'jomsocial': $db = JFactory::getDbo(); $query = 'select points from #__community_users where userid=' . (int) $userid; $db->setQuery($query); return (int) $db->loadResult(); case 'easysocial': require_once JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/foundry.php'; $my = Foundry::user($userid); $points = $my->getPoints(); return $points; default: return 0; } return -1; }
public function onContentChangeState($context, $pks, $value) { if ($context != 'com_content.article') { return true; } $api = JPATH_ROOT . '/components/com_cjblog/api.php'; if (file_exists($api)) { $db = JFactory::getDbo(); JArrayHelper::toInteger($pks); $query = ' select count(*) as articles, created_by from #__content where created_by in (select created_by from #__content where id in (' . implode(',', $pks) . ')) and state = 1 group by created_by'; $db->setQuery($query); $contents = $db->loadObjectList(); if (count($contents) > 0) { require_once $api; foreach ($contents as $content) { CjBlogApi::trigger_badge_rule('com_content.num_articles', array('num_articles' => $content->articles), $content->created_by); $query = 'update #__cjblog_users set num_articles = ' . $content->articles . ' where id = ' . $content->created_by; $db->setQuery($query); $db->query(); } } } else { die('CjBlog component is not installed.'); } }
function display($tpl = null) { $app = JFactory::getApplication(); $active = $app->getMenu()->getActive(); $model = $this->getModel(); $cache = JFactory::getCache(); $document = JFactory::getDocument(); /********************************** PARAMS *****************************/ $appparams = JComponentHelper::getParams(CJBLOG); $menuParams = new JRegistry(); if ($active) { $menuParams->loadString($active->params); } $this->params = clone $menuParams; $this->params->merge($appparams); /********************************** PARAMS *****************************/ $id = $app->input->getInt('id', 0); $result = new stdClass(); $page_heading = ''; $page_url = 'index.php?option=' . CJBLOG . '&view=users'; switch ($this->action) { case 'top_bloggers': $result = $model->get_users(2); $page_heading = JText::_('LBL_TOP_BLOGGERS'); $page_url = $page_url . '&task=top'; break; case 'search': $query = $app->input->getString('search', ''); $result = $model->get_users(4, array('query' => $query)); $page_heading = JText::_('LBL_SEARCH'); break; case 'badge_owners': $result = $model->get_users(3, array('badge_id' => $id)); $badge = CjBlogApi::get_badge_details($id); $page_heading = JText::sprintf('TXT_USERS_WHO_WON_BADGE', $badge['title'], array('jsSafe' => true)); $page_url = $page_url . '&task=badge&id=' . $id . ':' . $badge['alias']; break; case 'new_bloggers': default: $result = $model->get_users(1); $page_heading = JText::_('LBL_NEW_BLOGGERS'); break; } if (!empty($result->users)) { $userIds = array_keys($result->users); if (!empty($userIds)) { $api = new CjLibApi(); $avatarApp = $this->params->get('avatar_component', 'cjforum'); $profileApp = $this->params->get('profile_component', 'cjforum'); $api->prefetchUserProfiles($avatarApp, $userIds); if ($avatarApp != $profileApp) { $api->prefetchUserProfiles($profileApp, $userIds); } } } $this->params->set('page_heading', $this->params->get('page_heading', $page_heading)); $title = $this->params->get('page_title', ''); if (empty($title)) { $title = $page_heading; } $document->setTitle(CjBlogHelper::get_page_title($title)); $this->assign('brand', $app->getCfg('sitename')); if (!empty($result)) { $this->assignRef('users', $result->users); $this->assignRef('pagination', $result->pagination); $this->assignRef('state', $result->state); } $this->assignRef('page_url', $page_url); if ($this->params->get('menu-meta_description')) { $document->setDescription($this->params->get('menu-meta_description')); } if ($this->params->get('menu-meta_keywords')) { $document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); } if ($this->params->get('robots')) { $document->setMetadata('robots', $this->params->get('robots')); } parent::display($tpl); }
if (!$user->guest && $avatarApp == 'cjblog' && ($user->id == $this->profile['id'] || $user->authorise('core.manage'))) { ?> <div class="center"><a href="#" onclick="return false" class="btn-edit-avatar"><?php echo JText::_('LBL_CHANGE_AVATAR'); ?> </a></div> <?php } ?> <div class="lead nospace-bottom center fn title"><span class="full-name"><?php echo $this->escape($this->profile['name']); ?> </span></div> <p class="center" style="white-space: nowrap;"><?php echo CjBlogApi::get_user_badges_markup($this->profile); ?> </p> </li> </ul> <ul class="nav nav-tabs nav-stacked nospace-top"> <li> <?php echo JHtml::link(JRoute::_('index.php?option=' . CJBLOG . '&view=blog&id=' . $this->profile['id'] . ':' . $this->profile['username'] . $blog_itemid), JText::_('LBL_VISIT_MY_BLOG'), array('class' => '')); ?> </li> <li> <?php echo JHtml::link(JRoute::_('index.php?option=' . CJBLOG . '&view=user&task=articles&id=' . $this->profile['id'] . ':' . $this->profile['username'] . $user_itemid), JText::_('LBL_MY_ARTICLES'), array('class' => '')); ?>
echo $this->escape($this->user['name']); ?> <small> ( <a href="<?php echo $api->getUserProfileUrl($profileApp, $this->user['id'], true); ?> "> <?php echo JText::_('LBL_PROFILE'); ?> </a> ) </small> </h2> <p><?php echo CjBlogApi::get_user_badges_markup($this->user); ?> </p> <?php if (!empty($this->user['about'])) { ?> <div><?php echo $this->user['about']; ?> </div> <?php } ?> </div> </div> </div>
function save_custom_points() { $app = JFactory::getApplication(); $ids = $app->input->getArray(array('cid' => 'array', 'points' => 'int', 'description' => 'string')); JArrayHelper::toInteger($ids['cid']); if (!empty($ids['cid']) && !empty($ids['description']) && $ids['points'] != 0) { foreach ($ids['cid'] as $userid) { CjBlogApi::award_points('com_system.custom', $userid, $ids['points'], null, $ids['description']); } $this->setRedirect(JRoute::_('index.php?option=' . CJBLOG . '&view=points', false), JText::_('COM_CJBLOG_SUCCESS')); } else { $this->setRedirect(JRoute::_('index.php?option=' . CJBLOG . '&view=points', false), JText::_('COM_CJBLOG_FAILED')); } }
public static function getUserProfileUrl($system, $userId = 0, $urlOnly = true, $name = 'Guest', $attribs = array()) { $url = null; switch ($system) { case 'cjforum': break; case 'cjblog': $api = JPATH_ROOT . '/components/com_cjblog/api.php'; if (file_exists($api)) { require_once $api; $url = CjBlogApi::get_user_profile_url($userId, 'name', false, $attribs); } break; case 'jomsocial': $jspath = JPATH_BASE . '/components/com_community/libraries/core.php'; if (file_exists($jspath)) { include_once $jspath; $url = CRoute::_('index.php? option=com_community&view=profile&userid=' . $userId); } break; case 'cb': global $_CB_framework, $_CB_database, $ueConfig, $mainframe; $api = JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php'; if (!is_file($api)) { return; } require_once $api; cbimport('cb.database'); cbimport('cb.tables'); cbimport('language.front'); cbimport('cb.field'); $url = cbSef('index.php?option=com_comprofiler&task=userProfile&user='******'kunena': if (CJFunctions::_initialize_kunena() && $userId > 0) { $user = KunenaFactory::getUser($userId); if ($user === false) { break; } $url = KunenaRoute::_('index.php?option=com_kunena&func=profile&userid=' . $user->userid, true); } break; case 'aup': $api_AUP = JPATH_SITE . '/components/com_alphauserpoints/helper.php'; if (file_exists($api_AUP)) { require_once $api_AUP; $url = AlphaUserPointsHelper::getAupLinkToProfil($userId); } break; case 'easysocial': $api = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_easysocial' . DS . 'includes' . DS . 'foundry.php'; if (file_exists($api)) { require_once $api; $my = Foundry::user($userId); $url = FRoute::profile(array('id' => $my->getAlias())); $name = $my->getName(); } break; } if ($url && !$urlOnly) { $url = JHtml::link($url, $name, $attribs); } return null == $url ? $name : $url; }