/** * Gets the user avatar of the selected <code>system</code> * * @param string $system Avatar system to be used * @param int $userid user id * @param string $username username or name * @param int $height height of the avatar * * @return string user avatar */ public static function get_user_avatar($system, $userid, $displayname = 'username', $height = 48, $email = null, $attribs = array(), $img_attribs = array()) { $db = JFactory::getDBO(); $avatar = ''; $userid = !empty($userid) ? $userid : 0; switch ($system) { case 'cjblog': $api = JPATH_ROOT . DS . 'components' . DS . 'com_cjblog' . DS . 'api.php'; if (file_exists($api)) { include_once $api; $avatar = CjBlogApi::get_user_avatar($userid, $height, $displayname, $attribs, $img_attribs); } break; case 'jomsocial': if (!$userid) { return CjFunctions::get_user_avatar('gravatar', $userid, $displayname, $height, $email, $attribs, $img_attribs); } include_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'defines.community.php'; require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php'; require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'helpers' . DS . 'string.php'; $user = CFactory::getUser($userid); $name = CStringHelper::escape($user->getDisplayName()); $userLink = CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid); $img_attribs['height'] = $height . 'px'; $img_attribs['style'] = isset($img_attribs['style']) ? $img_attribs['style'] . '; max-height: ' . $height . 'px' : 'max-height: ' . $height . 'px'; $avatar_image = JHtml::image($user->getThumbAvatar(), $name, $img_attribs); $avatar = $userid > 0 ? JHtml::link($userLink, $avatar_image, $attribs) : JHtml::link('#', $avatar_image, $attribs); 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('cb.field'); cbimport('language.front'); outputCbTemplate($_CB_framework->getUi()); $img_attribs['height'] = $height . 'px'; $img_attribs['style'] = isset($img_attribs['style']) ? $img_attribs['style'] . '; max-height: ' . $height . 'px' : 'max-height: ' . $height . 'px'; if ($userid > 0) { $cbUser = CBuser::getInstance($userid); if ($cbUser !== null) { $avatar = $cbUser->getField('avatar', null, 'php', 'profile', 'list'); $name = $cbUser->getField('name'); $link = cbSef('index.php?option=com_comprofiler&task=userProfile&user='******'avatar'], '', $img_attribs), $attribs); } } else { if ($height <= 90) { $avatar = JHtml::link('#', Jhtml::image(selectTemplate() . 'images/avatar/tnnophoto_n.png', '', $img_attribs), $attribs); } else { $avatar = JHtml::link('#', Jhtml::image(selectTemplate() . 'images/avatar/nophoto_n.png', '', $img_attribs), $attribs); } } break; case 'touch': $avatarLoc = JURI::base(true) . '/index2.php?option=com_community&controller=profile&task=avatar&width=' . $height . '&height=' . $height . '&user_id=' . $userid . '&no_ajax=1'; $avatar = '<img src="' . $avatarLoc . '" style="border: 1px solid #cccccc; height: "' . $height . '"px;" alt=""/>'; $link = JRoute::_("index.php?option=com_community&view=profile&user_id={$userid}&Itemid=" . JRequest::getInt('Itemid')); $avatar = '<a href="' . $link . '">' . $avatar . '</a>'; break; case 'gravatar': if (null == $email && $userid > 0) { $strSql = 'SELECT email FROM #__users WHERE id=' . $userid; $db->setQuery($strSql); $email = $db->loadResult(); } $avatar = '<img src="https://www.gravatar.com/avatar/' . md5(strtolower(trim($email))) . '?s=' . $height . '&d=mm&r=g"/>'; break; case 'kunena': if (CJFunctions::_initialize_kunena()) { $class = 'avatar'; $user = KunenaFactory::getUser($userid); $avatarHtml = $user->getAvatarImage($class, $height, $height); $avatar = $user->getLink($avatarHtml); } else { if (file_exists(JPATH_ROOT . DS . 'components' . DS . 'com_kunena' . DS . 'class.kunena.php')) { require_once JPATH_ROOT . DS . 'components' . DS . 'com_kunena' . DS . 'class.kunena.php'; require_once JPATH_ROOT . DS . 'components' . DS . 'com_kunena' . DS . 'lib' . DS . 'kunena.link.class.php'; $kunena_user = KunenaFactory::getUser((int) $userid); $displayname = $kunena_user->getName(); // Takes care of realname vs username setting $avatarlink = $kunena_user->getAvatarLink('', $height, $height); $avatar = CKunenaLink::GetProfileLink($userid, $avatarlink, $displayname); } } break; case 'aup': $api_AUP = JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; if (file_exists($api_AUP)) { require_once $api_AUP; $avatar = AlphaUserPointsHelper::getAupAvatar($userid, 1, $height, $height); } 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); $img_attribs[] = array('style' => 'max-height: ' . $height . 'px'); $avatar_image = JHtml::image($my->getAvatar(SOCIAL_AVATAR_MEDIUM), $my->getName(), $img_attribs); $profile_url = FRoute::profile(array('id' => $my->getAlias())); $avatar = JHtml::link($profile_url, $avatar_image, $attribs); } break; } return $avatar; }
/** * Loads the jquery library and set of jquery plugins passed as parameters to the function. * * The required jquery plugins should be passed as associative array of names with name as libs * Ex: * <code> * $params = array('libs'=>array('ui', 'form', 'validate', 'treeview', 'menu', 'waypoints', 'tags', 'inlinelabel', 'scrollto'), 'theme'=>'start'); * CJFunctions::load_jquery($params); * </code> * * @param array $params */ public static function load_jquery($params = array()) { $app = JFactory::getApplication(); $document = JFactory::getDocument(); $plugins = !empty($app->jqueryplugins) ? $app->jqueryplugins : array(); $custom_tag = isset($params['custom_tag']) ? true : false; if (!in_array('baseloc', $plugins)) { $document->addScriptDeclaration('var cjlib_loc = "' . CJLIB_URI . '";'); $plugins[] = 'baseloc'; } if (APP_VERSION <= 2.5 && !$app->get('jquery', false)) { CJFunctions::add_script_to_document($document, 'jquery.min.js', $custom_tag); CJFunctions::add_script_to_document($document, 'jquery.noconflict.js', $custom_tag); $app->set('jquery', true); } else { if (APP_VERSION > 2.5) { JHtml::_('jquery.framework'); } } if (!in_array('ui', $plugins) && in_array('ui', $params['libs'])) { if (APP_VERSION <= 2.5) { $theme = !empty($params['theme']) && strcmp($params['theme'], 'default') != 0 ? JFile::makeSafe($params['theme']) : 'start'; if ($theme != 'none') { $document->addStyleSheet(CJLIB_URI . '/jquery/themes/' . $theme . '/jquery-ui.css'); CJFunctions::add_script_to_document($document, 'jquery-ui.min.js', $custom_tag); } else { $document->addStyleSheet(CJLIB_URI . '/jquery/themes/no-theme/jquery-ui.css'); CJFunctions::add_script_to_document($document, 'jquery-ui-core.min.js', $custom_tag); } } else { JHtml::_('jquery.ui', array('core', 'sortable')); } $plugins[] = 'ui'; } if (!in_array('extras', $plugins)) { if (in_array('extras', $params['libs'])) { $document->addStyleSheet(CJLIB_URI . '/jquery/jquery.extras.min.css'); CJFunctions::add_script_to_document($document, 'jquery.extras.min.js', $custom_tag); CJFunctions::add_script_to_document($document, 'jquery.form.min.js', $custom_tag); $plugins[] = 'extras'; $plugins[] = 'form'; $plugins[] = 'validate'; $plugins[] = 'treeview'; } else { /** deprecated */ if (in_array('menu', $params['libs'])) { CJFunctions::add_script_to_document($document, 'jquery.extras.min.js', $custom_tag); $document->addStyleSheet(CJLIB_URI . '/jquery/jquery.extras.min.css'); $plugins[] = 'extras'; } } } if (!in_array('json', $plugins) && in_array('json', $params['libs'])) { CJFunctions::add_script_to_document($document, 'json2.js', $custom_tag); $plugins[] = 'json'; } if (!in_array('validate', $plugins) && in_array('validate', $params['libs'])) { $lang = JFactory::getLanguage()->getTag(); $locale = strstr($lang, '-', true); CJFunctions::add_script('https://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js', $custom_tag); if ($locale != 'en') { CJFunctions::add_script('https://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/localization/messages_' . $locale . '.js', $custom_tag); } //CJFunctions::add_script_to_document($document, 'jquery.validate.min.js', $custom_tag); $plugins[] = 'validate'; } if (!in_array('rating', $plugins) && in_array('rating', $params['libs'])) { CJFunctions::add_script_to_document($document, 'jquery.raty.min.js', $custom_tag); $plugins[] = 'rating'; } if (!in_array('form', $plugins) && in_array('form', $params['libs'])) { CJFunctions::add_script(CJLIB_MEDIA_URI . '/jquery/jquery.form.min.js', $custom_tag); $plugins[] = 'form'; } // if(!in_array('morris', $plugins) && in_array('morris', $params['libs'])){ // CJFunctions::add_script_to_document($document, 'raphael-min.js', $custom_tag); // CJFunctions::add_script_to_document($document, 'morris.min.js', $custom_tag); // $plugins[] = 'morris'; // } if (!in_array('datepicker', $plugins) && in_array('datepicker', $params['libs'])) { $document->addStyleSheet(CJLIB_URI . '/jquery/datepicker.css'); CJFunctions::add_script_to_document($document, 'bootstrap-datepicker.js', $custom_tag); $plugins[] = 'datepicker'; } if (!in_array('treeview', $plugins) && in_array('treeview', $params['libs'])) { $document->addStyleSheet(CJLIB_URI . '/jquery/jquery.treeview.css'); CJFunctions::add_script_to_document($document, 'jquery.treeview.js', $custom_tag); $plugins[] = 'treeview'; } if (!in_array('colorbox', $plugins) && in_array('colorbox', $params['libs'])) { $document->addStyleSheet(CJLIB_URI . '/jquery/colorbox.css'); CJFunctions::add_script_to_document($document, 'jquery.colorbox.min.js', $custom_tag); $plugins[] = 'colorbox'; } if (!in_array('social', $plugins) && in_array('social', $params['libs'])) { $document->addStyleSheet(CJLIB_URI . '/jquery/social/socialcount-with-icons.min.css'); CJFunctions::add_script_to_document($document, 'socialcount.min.js', $custom_tag, CJLIB_URI . '/jquery/social/'); $plugins[] = 'social'; } if (!in_array('chosen2', $plugins) && in_array('chosen2', $params['libs'])) { if (APP_VERSION <= 2.5) { $document->addStyleSheet(CJLIB_URI . '/jquery/chosen/chosen.css'); CJFunctions::add_script_to_document($document, 'chosen.jquery.min.js', $custom_tag, CJLIB_URI . '/jquery/chosen/'); CJFunctions::add_script_to_document($document, 'ajax-chosen.min.js', $custom_tag, CJLIB_URI . '/jquery/chosen/'); if (in_array('chosentags', $params['libs'])) { CJFunctions::add_script_to_document($document, 'cj.chosentags.js', $custom_tag, CJLIB_URI . '/jquery/chosen/'); } } else { $document->addStyleSheet(JUri::root(true) . '/media/jui/css/chosen.css'); $document->addScript(JUri::root(true) . '/media/system/js/core.js'); $document->addScript(JUri::root(true) . '/media/jui/js/chosen.jquery.js'); if (in_array('chosentags', $params['libs'])) { $document->addScript(JUri::root(true) . '/media/jui/js/ajax-chosen.min.js'); $document->addScript(CJLIB_URI . '/jquery/chosen/cj.chosentags.js'); } } $plugins[] = 'chosen2'; } if (!in_array('chosen', $plugins) && in_array('chosen', $params['libs'])) { if (APP_VERSION <= 2.5) { $document->addStyleSheet(CJLIB_URI . '/jquery/chosen/chosen.css'); CJFunctions::add_script_to_document($document, 'chosen.jquery.min.js', $custom_tag, CJLIB_URI . '/jquery/chosen/'); CJFunctions::add_script_to_document($document, 'ajax-chosen.min.js', $custom_tag, CJLIB_URI . '/jquery/chosen/'); CJFunctions::add_script_to_document($document, 'cj.chosentags.js', $custom_tag, CJLIB_URI . '/jquery/chosen/'); } else { $document->addStyleSheet(JUri::root(true) . '/media/jui/css/chosen.css'); $document->addScript(JUri::root(true) . '/media/system/js/core.js'); $document->addScript(JUri::root(true) . '/media/jui/js/chosen.jquery.js'); $document->addScript(JUri::root(true) . '/media/jui/js/ajax-chosen.min.js'); $document->addScript(CJLIB_URI . '/jquery/chosen/cj.chosentags.js'); } $plugins[] = 'chosen'; } if (!in_array('tags', $plugins) && in_array('tags', $params['libs'])) { $document->addStyleSheet(CJLIB_URI . '/jquery/cj.tags.min.css'); CJFunctions::add_script_to_document($document, 'cj.tags.js', $custom_tag); $plugins[] = 'tags'; } if (!in_array('backbone', $plugins) && in_array('backbone', $params['libs'])) { CJFunctions::add_script_to_document($document, 'underscore-min.js', $custom_tag); CJFunctions::add_script_to_document($document, 'backbone-min.js', $custom_tag); $plugins[] = 'backbone'; } if (!in_array('bootstrap', $plugins) && in_array('bootstrap', $params['libs']) && !CJLib::$_bootstrap_loaded) { if (APP_VERSION == '2.5') { CJFunctions::add_script_to_document($document, 'bootstrap.min.js', $custom_tag, CJLIB_MEDIA_URI . '/bootstrap/js/'); CjFunctions::add_css_to_document($document, CJLIB_MEDIA_URI . '/bootstrap/css/bootstrap.min.css', $custom_tag); } else { JHtml::_('bootstrap.framework'); CjFunctions::add_css_to_document($document, CJLIB_MEDIA_URI . '/bootstrap/css/bootstrap.min.css', $custom_tag); // JHtmlBootstrap::loadCss(true, $document->direction); } $document->addScriptDeclaration('<!--[if lt IE 9]><script type="text/javascript" src="' . CJLIB_MEDIA_URI . '/bootstrap/js/respond.min.js"><![endif]-->'); $plugins[] = 'bootstrap'; CJLib::$_bootstrap_loaded = true; } if (!in_array('fontawesome', $plugins) && in_array('fontawesome', $params['libs'])) { // CjFunctions::add_css_to_document($document, '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css', $custom_tag); CjFunctions::add_css_to_document($document, CJLIB_MEDIA_URI . '/fontawesome/css/font-awesome.min.css', $custom_tag); $plugins[] = 'fontawesome'; } if (!in_array('blockui', $plugins) && in_array('blockui', $params['libs'])) { CJFunctions::add_script(CJLIB_MEDIA_URI . '/jquery/jquery.blockui.js', $custom_tag); $plugins[] = 'blockui'; } if (!in_array('message', $plugins) && in_array('message', $params['libs'])) { CJFunctions::add_script(CJLIB_MEDIA_URI . '/jquery/jquery.message.min.js', $custom_tag); CjFunctions::add_css_to_document($document, CJLIB_MEDIA_URI . '/jquery/jquery.message.css', $custom_tag); $plugins[] = 'message'; } if (!in_array('dygraph', $plugins) && in_array('dygraph', $params['libs'])) { CJFunctions::add_script(CJLIB_MEDIA_URI . '/jquery/dygraph-combined.js', $custom_tag); $plugins[] = 'dygraph'; } $app->jqueryplugins = $plugins; }
private function send_invitations($sid, $contacts, $remaining = 0) { if (!empty($contacts)) { $app = JFactory::getApplication(); $user = JFactory::getUser(); $model = JModelLegacy::getInstance('survey', 'CommunitySurveysModel'); $params = JComponentHelper::getParams(S_APP_NAME); $itemid = CJFunctions::get_active_menu_id(true, 'index.php?option=' . S_APP_NAME . '&view=surveys'); $editor = $user->authorise('core.wysiwyg', S_APP_NAME) ? $params->get('default_editor', 'bbcode') : 'none'; $subject = $app->input->getString('invitation-subject', JText::_('TXT_INVITE_DEFAULT_SUB')); $default_body = $editor == 'wysiwyg' ? str_replace("\n", '<br>', JText::_('TXT_INVITE_DEFAULT_BODY')) : JText::_('TXT_INVITE_DEFAULT_BODY'); $body = CJFunctions::get_clean_var('invitation-body', true, $default_body); $body = CJFunctions::process_html($body, $editor == 'bbcode'); $messageid = $app->input->getInt('messageid', 0); $count = count($contacts); $keys = $model->create_survey_keys($sid, $count); $survey = $model->get_survey_details($sid, 0, false, false, false); if (!empty($keys) && count($keys) > 0) { $emails = array(); foreach ($keys as $i => $key) { $link = str_replace('/administrator/', '/', JRoute::_('index.php?option=' . S_APP_NAME . '&view=response&task=take_survey&key=' . $key . $itemid, false, -1)); $link = '<a href="' . $link . '">' . CjFunctions::escape($survey->title) . '</a>'; $email = new stdClass(); $email->name = $contacts[$i]->name; $email->subid = 0; $email->link = $link; $email->email = $contacts[$i]->email; $emails[] = $email; $contacts[$i]->key = $key; $i++; } $template = $params->get('mail-tpl-newanswer', 'mail-blue.tpl'); $sent = $model->add_messages_to_queue($sid, $subject, $body, $emails, $template, $messageid); $model->update_key_userids($sid, $contacts); if ($sent === false) { echo json_encode(array('error' => JText::_('MSG_ERROR_PROCESSING') . (S_DEBUG_ENABLED ? $model->getError() : ''))); } else { echo json_encode(array('message' => JText::sprintf('MSG_INVITATIONS_ADDED_TO_QUEUE', $sent), 'remaining' => $remaining)); } } else { echo json_encode(array('error' => JText::_('MSG_NO_CREDITS') . (S_DEBUG_ENABLED ? $model->getError() : ''))); } } else { echo json_encode(array('error' => JText::_('MSG_NO_CONTACTS_SELECTED'))); } }