/** * Gets the user avatar linked with user profile. * * @param mixed $userids single id of the user or array of user ids * @param int $size height of the avatar * @param string $username what name to display username or name? * @param array $attribs An associative array of attributes to add to the link */ public static function get_user_avatar($userids, $size = 48, $username = '******', array $attribs = array(), array $image_attribs = array()) { if (!array_key_exists('height', $image_attribs)) { $image_attribs['height'] = $size; } if (!is_array($userids)) { $userids = intval($userids); } if (is_numeric($userids)) { $profile = self::get_user_profile($userids); $avatar_loc = self::get_user_avatar_image($userids, $size); $attribs['class'] = empty($attribs['class']) ? 'tooltip-hover' : $attribs['class'] . ' tooltip-hover'; $attribs['title'] = empty($attribs['title']) ? $profile[$username] : $attribs['title']; $attribs['data-toggle'] = 'tooltip'; $avatar_image = '<img src="' . $avatar_loc . '" alt="' . $attribs['title'] . '" ' . JArrayHelper::toString($image_attribs) . '/>'; $profile_url = self::get_user_profile_url($userids, $username, true); return JHtml::link($profile_url, $avatar_image, $attribs); } elseif (is_array($userids) && !empty($userids)) { $avatar_images = self::get_user_avatar_image($userids, $size); $profile_urls = self::get_user_profile_url($userids, $username, true); $profiles = self::get_user_profile($userids); $return = array(); foreach ($userids as $userid) { if (!empty($avatar_images[$userid]) && !empty($profile_urls[$userid])) { $attribs['class'] = empty($attribs['class']) ? 'tooltip-hover' : $attribs['class'] . ' tooltip-hover'; $attribs['title'] = CJFunctions::escape($profiles[$userid][$username]); $attribs['data-toggle'] = 'tooltip'; $avatar_loc = self::get_user_avatar_image($userids, $size); $avatar_image = '<img src="' . $avatar_loc[$userid] . '" alt="' . $attribs['title'] . '" ' . JArrayHelper::toString($image_attribs) . '/>'; $return[$userid] = JHtml::link($profile_urls[$userid], $avatar_image, $attribs); } } return $return; } return false; }
function generatePdfReport($pdfData, $mode, $params, $fileName) { $countries = CJFunctions::get_country_names(); $responses = array(); $include_email_in_reports = $params->get('include_email_in_reports', 0); foreach ($pdfData->responses as $response) { $responses[$response->id] = new stdClass(); $responses[$response->id]->created_by = $response->created_by; $responses[$response->id]->created = $response->created; $responses[$response->id]->username = $response->username; $responses[$response->id]->name = $response->name; if ($include_email_in_reports == 1) { $responses[$response->id]->email = $response->email; } $responses[$response->id]->questions = array(); foreach ($pdfData->questions as $question) { $responses[$response->id]->questions[$question->id] = new stdClass(); $responses[$response->id]->questions[$question->id]->answer = ''; $responses[$response->id]->questions[$question->id]->question_type = $question->question_type; } } if (!empty($pdfData->entries)) { foreach ($pdfData->entries as $entry) { if (isset($responses[$entry->response_id]) && isset($responses[$entry->response_id]->questions[$entry->question_id])) { if (!empty($entry->answer)) { if (empty($responses[$entry->response_id]->questions[$entry->question_id]->answer)) { $responses[$entry->response_id]->questions[$entry->question_id]->answer = $entry->answer; } else { $responses[$entry->response_id]->questions[$entry->question_id]->answer .= '<br/>' . $entry->answer; } if (!empty($entry->answer_image) && JFile::exists(S_IMAGES_UPLOAD_DIR . '/' . $entry->answer_image)) { //$image = JHtml::image(JURI::root(true).'/media/communitysurveys/images/'.$entry->answer_image, $entry->answer); $image = '<img src="' . JURI::root(true) . '/media/communitysurveys/images/' . $entry->answer_image . '">'; $responses[$entry->response_id]->questions[$entry->question_id]->answer .= '<br/>' . $image; } } if (!empty($entry->answer2)) { if (empty($responses[$entry->response_id]->questions[$entry->question_id]->answer)) { $responses[$entry->response_id]->questions[$entry->question_id]->answer = $entry->answer2; } else { $responses[$entry->response_id]->questions[$entry->question_id]->answer .= '<br/>' . $entry->answer2; } } if (!empty($entry->free_text)) { // do special types formatting // if ($responses[$entry->response_id]->questions[$entry->question_id]->question_type == S_SPECIAL_NAME) { $names = explode('|', $entry->free_text); if (!empty($names)) { $entry->free_text = $names[0] . '. ' . $names[1] . ' ' . $names[2]; } else { $entry->free_text = ''; } } else { if ($responses[$entry->response_id]->questions[$entry->question_id]->question_type == S_SPECIAL_ADDRESS) { $parts = explode('|||', $entry->free_text); if (count($parts) == 7) { $entry->free_text = '<address><strong>' . CJFunctions::escape($parts[0]) . '</strong><br>'; $entry->free_text .= CJFunctions::escape($parts[1]) . '<br>'; if (!empty($parts[2])) { $entry->free_text .= CJFunctions::escape($parts[2]) . '<br>'; } $entry->free_text .= CJFunctions::escape($parts[3]) . ', ' . CJFunctions::escape($parts[4]) . ', ' . CJFunctions::escape($parts[6]) . '<br>'; $entry->free_text .= !empty($countries[$parts[5]]) ? $countries[$parts[5]]->country_name : CJFunctions::escape($parts[5]); } else { $entry->free_text = ''; } } } // do special types formatting // if (empty($responses[$entry->response_id]->questions[$entry->question_id]->answer)) { $responses[$entry->response_id]->questions[$entry->question_id]->answer = $entry->free_text; } else { $responses[$entry->response_id]->questions[$entry->question_id]->answer .= '<br/>' . $entry->free_text; } } } } } $response_rows = array(); foreach ($responses as $id => $response) { $string = '<table class="table table-striped" width="100%">'; $string = $string . '<tr><th width="30%"><strong>Response ID:</strong></th><td width="70%">' . $id . '</td></tr>'; $string = $string . '<tr><th><strong>Response Date:</strong></th><td>' . $response->created . '</td></tr>'; $string = $string . '<tr><th><strong>User ID:</strong></th><td>' . $response->created_by . '</td></tr>'; $string = $string . '<tr><th><strong>Username:</strong></th><td>' . $response->username . '</td></tr>'; $string = $string . '<tr><th><strong>User Display Name:</strong></th><td>' . $response->name . '</td></tr>'; if ($include_email_in_reports == 1) { $string = $string . '<tr><td><strong>Email:</strong></td><td>' . $response->email . '</td></tr>'; } foreach ($pdfData->questions as $question) { $string = $string . '<tr><td colspan="2"> <hr></td></tr>'; $string = $string . '<tr><th colspan="2"><h3>' . $question->title . '</h3></th></tr>'; if (!empty($question->description)) { $string = $string . '<tr><td colspan="2">' . $question->description . '</td></tr>'; } $string = $string . '<tr><td colspan="2"> </td></tr>'; $string = $string . '<tr><td colspan="2">' . $response->questions[$question->id]->answer . '</td></tr>'; } $string = $string . '</table>'; array_push($response_rows, $string); } // create new PDF document require_once JPATH_COMPONENT_SITE . '/helpers/tcpdf.php'; $pdf = new MYPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set default header data $pdf->SetHeaderData('logo.png', PDF_HEADER_LOGO_WIDTH, $pdfData->title, ''); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('corejoomla.com'); $pdf->SetTitle('Survey Report'); $pdf->SetSubject('Survey Responses Report'); $pdf->SetKeywords('survey, report'); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // --------------------------------------------------------- // set font $pdf->SetFont('freesans'); foreach ($response_rows as $i => $response) { $pdf->AddPage(); $pdf->writeHTML($response, true, false, true, false, ''); $pdf->lastPage(); } $pdf->Output($fileName, $mode); }
public function onContentPrepare($context, &$article, &$params, $page = 0) { $app = JFactory::getApplication(); $menu = $app->getMenu(); if ($menu->getActive() == $menu->getDefault() || $context != 'com_content.article' || $page > 0 || empty($article->id)) { return true; } $db = JFactory::getDbo(); $document = JFactory::getDocument(); $user = JFactory::getUser(); $api = new CjLibApi(); $article_url = JRoute::_(ContentHelperRoute::getArticleRoute($article->id . ':' . $article->alias, $article->catid . ':' . $article->category_alias)); /******************************** TRIGGER BADGE RULE ******************************************/ CjBlogApi::trigger_badge_rule('com_content.num_hits', array('num_hits' => $article->hits, 'ref_id' => $article->id), $article->created_by); /******************************* TRIGGER POINTS RULES ******************************************/ $appparams = JComponentHelper::getParams('com_cjblog'); if ($appparams->get('enable_points')) { CjBlogApi::award_points('com_content.hits', $user->id, 0, $article->id, JHtml::link($article_url, $article->title)); CjBlogApi::award_points('com_content.popular_articles', $article->created_by, 0, $article->id, JHtml::link($article_url, $article->title), array('hits' => $article->hits)); } // Check if the plugin is disabled for the article category $include_categories = $this->params->get('include_categories'); $exclude_categories = $this->params->get('exclude_categories'); $about_length = $this->params->get('about_length', 180); if (!empty($include_categories)) { $include_categories = explode(',', $include_categories); if (!in_array($article->catid, $include_categories)) { return true; } } else { if (!empty($exclude_categories)) { $exclude_categories = explode(',', $exclude_categories); if (in_array($article->catid, $exclude_categories)) { return true; } } } $print = $app->input->getInt('print', 0); if ($print) { return true; } /********************************** CONTENT HEADER *********************************************/ require_once JPATH_ROOT . '/components/com_cjblog/router.php'; $CjLib = JPATH_ROOT . '/components/com_cjlib/framework.php'; CJLib::import('corejoomla.framework.core'); $custom_tag = false; JHtml::_('jquery.framework'); CJLib::behavior('bscore', array('customtag' => $custom_tag)); CJFunctions::load_jquery(array('libs' => array('rating', 'social', 'fontawesome'), 'custom_tag' => $custom_tag)); $document->addScript(JUri::root(true) . '/media/com_cjblog/js/cjblog.min.js'); $document->addStyleSheet(JUri::root(true) . '/media/com_cjblog/css/cjblog.min.css'); $articles_itemid = CJFunctions::get_active_menu_id(true, 'index.php?option=com_cjblog&view=articles'); $profile = CjBlogApi::get_user_profile($article->created_by); // $params->merge($appparams); $meta_header = ''; $meta_stats = ''; $meta_rating = ''; $meta_rating_readonly = ''; $social_buttons = ''; $tags_html = ''; $show_category = $appparams->get('show_category', 1); $show_date = $appparams->get('show_create_date', 1); $date_format = JText::_($appparams->get('date_format', 'd F Y')); $show_hits = $appparams->get('show_hits', 1); $show_author = $appparams->get('show_author', 1); $show_favoured = $appparams->get('show_favoured', 1); $show_rating = $appparams->get('show_rating', 1); $user_name = $appparams->get('user_display_name', 'name'); $hot_hits = $appparams->get('hot_article_num_hits', 250); $social_buttons = $appparams->get('display_social_buttons', 1); $sharing_buttons_customtag = $appparams->get('sharing_buttons_customtag', ''); $sharing_buttons_customtext = $appparams->get('sharing_buttons_customtext', ''); $social_buttons_theme = $appparams->get('social_buttons_theme', 'jssocials-theme-classic.css'); $sharing_position = $appparams->get('sharing_buttons_position', 'bottom'); $jssocial_label = $appparams->get('jssocial_button_label', 'true'); $jssocial_count = $appparams->get('jssocial_button_count', 'true'); $social_buttons_via = $appparams->get('tweet_button_via', ''); $social_buttons_hashtag = $appparams->get('tweet_button_hashtag', ''); $jssocial_email = $appparams->get('jssocial_button_email', '1'); $jssocial_twitter = $appparams->get('jssocial_button_twitter', '1'); $jssocial_facebook = $appparams->get('jssocial_button_facebook', '1'); $jssocial_googleplus = $appparams->get('jssocial_button_googleplus', '1'); $jssocial_linkedin = $appparams->get('jssocial_button_linkedin', '1'); $jssocial_pinterest = $appparams->get('jssocial_button_pinterest', '1'); $profileApp = $appparams->get('profile_component', 'cjblog'); $avatarApp = $appparams->get('avatar_component', 'cjblog'); $showProfile = JFactory::getUser($article->created_by)->authorise('core.showprofile', 'com_cjblog'); $bbcode = $appparams->get('default_editor', 'wysiwygbb') == 'wysiwygbb' ? true : false; $about = !empty($profile['about']) ? '<div>' . CJFunctions::preprocessHtml($profile['about'], false, $bbcode) . '</div>' : ''; if ($about_length > 0) { $about = CJFunctions::substrws($about, $about_length); } if ($show_category && $show_date) { $cat_url = JRoute::_('index.php?option=com_cjblog&view=articles&task=latest&id=' . $article->catid . ':' . $article->category_alias . $articles_itemid); $cat_link = JHtml::link($cat_url, CJFunctions::escape($article->category_title)); $formatted_date = CJFunctions::get_localized_date($article->created, $date_format); $meta_header = JText::sprintf('TXT_POSTED_IN_CATEGORY_ON', $cat_link, $formatted_date); } else { if ($show_category) { $cat_url = JRoute::_('index.php?option=com_cjblog&view=articles&task=latest&id=' . $article->catid . ':' . $article->category_alias . $articles_itemid); $cat_link = JHtml::link($cat_url, CJFunctions::escape($article->category_title)); $meta_header = JText::sprintf('TXT_POSTED_IN_CATEGORY', $cat_link); } else { if ($show_date) { $meta_header = JText::sprintf('TXT_POSTED_ON', CJFunctions::get_localized_date($article->created, $date_format)); } } } if ($article->hits > $hot_hits) { $meta_stats = $meta_stats . '<span class="label label-important hot-article">' . JText::_('LBL_HOT') . '</span> '; } if ($show_hits) { $meta_stats = $meta_stats . '<span class="label label-info">' . JText::sprintf('TXT_NUM_HITS', $article->hits) . '</span> '; } if ($show_favoured) { $query = 'select favorites from ' . T_CJBLOG_CONTENT . ' where id = ' . $article->id; $db->setQuery($query); $favored = (int) $db->loadResult(); if (!$user->guest) { $query = 'select count(*) from ' . T_CJBLOG_FAVORITES . ' where content_id = ' . $article->id . ' and user_id = ' . $user->id; $db->setQuery($query); $count = $db->loadResult(); if ($count == 0) { $meta_stats = $meta_stats . ' <span class="label label-info favorites">' . JText::sprintf('TXT_NUM_FAVOURED', $favored) . '</span> <a id="btn-add-to-favorites" class="btn btn-mini tooltip-hover" href="' . JRoute::_('index.php?option=com_cjblog&view=articles&task=favorite&id=' . $article->id . $articles_itemid) . '" onclick="return false;" title="' . JText::_('LBL_ADD_TO_FAVORITES') . '"> <i class="fa fa-star"></i> </a>'; } else { $meta_stats = $meta_stats . ' <span class="label label-info favorites tooltip-hover" title="' . JText::_('LBL_YOU_ADDED_TO_FAVORITES') . '"> <i class="fa fa-star"></i> ' . JText::sprintf('TXT_NUM_FAVOURED', $favored) . ' </span> <a id="btn-remove-favorite" class="btn btn-mini tooltip-hover" href="' . JRoute::_('index.php?option=com_cjblog&view=articles&task=remove_favorite&id=' . $article->id . $articles_itemid) . '" onclick="return false;" title="' . JText::_('LBL_REMOVE_FAVORITE') . '"> <i class="icon-remove"></i> </a>'; } } else { $meta_stats = $meta_stats . '<span class="label label-info favorites">' . JText::sprintf('TXT_NUM_FAVOURED', $favored) . '</span>'; } } $asset = 'com_content.article.' . $article->id; $redirect_url = base64_encode($article_url); if ($user->authorise('core.edit.own', $asset) && $article->created_by == $user->id || $user->authorise('core.manage')) { $meta_stats = $meta_stats . ' <a id="btn-edit-article" class="btn btn-mini tooltip-hover" href="' . JRoute::_(CjBlogHelperRoute::getFormRoute($article->id) . '&return=' . $redirect_url) . '" title="' . JText::_('LBL_EDIT_ARTICLE') . '"> <i class="fa fa-pencil"></i> </a>'; } if ($user->authorise('core.edit.state')) { if ($article->state == 1) { $meta_stats = $meta_stats . ' <a id="btn-publish-article" class="btn btn-mini tooltip-hover" href="' . JRoute::_('index.php?option=com_cjblog&view=articles&task=unpublish&id=' . $article->id . $articles_itemid . '&return=' . $redirect_url) . '" title="' . JText::_('LBL_PUBLISHED') . '"> <i class="fa fa-check"></i> </a>'; } else { $meta_stats = $meta_stats . ' <a id="btn-publish-article" class="btn btn-mini tooltip-hover" href="' . JRoute::_('index.php?option=com_cjblog&view=articles&task=publish&id=' . $article->id . $articles_itemid . '&return=' . $redirect_url) . '" title="' . JText::_('LBL_UNPUBLISHED') . '"> <i class="fa fa-ban"></i> </a>'; } } if ($show_rating && $user->authorise('articles.rate', 'com_cjblog')) { $rating = CJFunctions::get_rating(CJBLOG_ASSET_ID, $article->id); $meta_rating_readonly = ' <div class="pull-right"> <span class="article-star-rating-readonly" data-rating-score="' . $rating['rating'] . '" data-rating-hints="' . JText::_('LBL_RATING_HINTS') . '" data-rating-noratemsg="' . JText::_('LBL_RATING_NORATE_HINT') . '" data-rating-cancelhint="' . JText::_('LBL_RATING_CANCEL_HINT') . '"></span> (' . JText::sprintf('TXT_RATINGS', $rating['total_ratings']) . ') </div>'; $readonly = false; $hash = CJFunctions::get_hash('com_content.article.rating.item_' . $article->id); $cookie = $app->input->cookie->get($hash, null); if ($cookie) { $readonly = true; } else { if (!$user->guest) { $query = 'select count(*) from ' . T_CJ_RATING_DETAILS . ' where item_id = ' . $article->id . ' and asset_id = 1 and created_by = ' . $user->id; $db->setQuery($query); $count = (int) $db->loadResult(); if ($count > 0) { $app->input->cookie->set($hash, 1, time() + 60 * 60 * 24 * 365, $article_url); $readonly = true; } } } if (!$readonly) { $meta_rating = ' <div>' . JText::_('LBL_RATE_THIS_ARTICLE') . ':</div> <span class="article-star-rating" data-rating-score="' . $rating['rating'] . '" data-rating-url="' . JRoute::_('index.php?option=com_cjblog&view=articles&task=rate&id=' . $article->id . $articles_itemid) . '" data-rating-hints="' . JText::_('LBL_RATING_HINTS') . '" data-rating-noratemsg="' . JText::_('LBL_RATING_NORATE_HINT') . '" data-rating-cancelhint="' . JText::_('LBL_RATING_CANCEL_HINT') . '"></span> (<span id="article-rating-info">' . JText::sprintf('TXT_RATING_INFO', $rating['rating'], $rating['total_ratings']) . '</span>) <hr>'; } } if ($social_buttons == 1) { $params_image = new JRegistry(); $params_image->loadString($article->images); $intro = $params_image->get('image_intro'); $pinterest_image = false; if (!empty($intro)) { $pinterest_image = JUri::root() . $intro; } else { preg_match_all('/<img .*src=["|\']([^"|\']+)/i', $article->introtext . $article->fulltext, $matches); foreach ($matches[1] as $key => $file_path) { $pinterest_image = JUri::root() . $file_path; break; } } $document->addScript(JUri::root(true) . '/media/com_cjblog/js/jssocials.min.js'); $document->addStyleSheet(JUri::root(true) . '/media/com_cjblog/css/jssocials.css'); $document->addStyleSheet(JUri::root(true) . '/media/com_cjblog/css/' . $social_buttons_theme . ''); } if ($social_buttons == 1 || $social_buttons == 2) { if ($sharing_buttons_customtext == '') { $sharing_buttons_customtext = JText::_('LBL_SOCIAL_SHARING_DESC'); } $social_buttons_construct = '<div class="social-sharing"><p>' . $sharing_buttons_customtext . '</p></div>'; if ($social_buttons == 1) { $social_buttons_jssocials = ' showLabel: ' . $jssocial_label . ', showCount: ' . $jssocial_count . ', shares: ['; if ($jssocial_twitter == "1") { $social_buttons_jssocials = $social_buttons_jssocials . ' { share: "twitter", via: "' . $social_buttons_via . '", hashtags: "' . $social_buttons_hashtag . '", text: "' . $article->title . '"},'; } if ($jssocial_facebook == "1") { $social_buttons_jssocials = $social_buttons_jssocials . ' { share: "facebook"},'; } if ($jssocial_googleplus == "1") { $social_buttons_jssocials = $social_buttons_jssocials . ' { share: "googleplus"},'; } if ($jssocial_linkedin == "1") { $social_buttons_jssocials = $social_buttons_jssocials . ' { share: "linkedin"},'; } if ($jssocial_pinterest == "1" && $pinterest_image) { $social_buttons_jssocials = $social_buttons_jssocials . ' { share: "pinterest", media: "' . $pinterest_image . '"},'; } if ($jssocial_email == "1") { $social_buttons_jssocials = $social_buttons_jssocials . ' { share: "email", text: "' . $article->title . '"},'; } $social_buttons_jssocials = $social_buttons_jssocials . ' ]'; $social_buttons_top = $social_buttons_construct . ' <div id="share-top"> <script type="text/javascript"> jQuery("#share-top").jsSocials({' . $social_buttons_jssocials . ' }); </script> </div>'; $social_buttons_bottom = $social_buttons_construct . ' <div id="share-bottom"> <script type="text/javascript"> jQuery("#share-bottom").jsSocials({' . $social_buttons_jssocials . ' }); </script> </div>'; } else { $social_buttons_top = $social_buttons_construct . $sharing_buttons_customtag; $social_buttons_bottom = $social_buttons_top; } } JLoader::import('joomla.application.component.model'); JLoader::import('articles', JPATH_ROOT . '/components/com_cjblog/models'); $model = JModelLegacy::getInstance('articles', 'CjBlogModel'); $tags = $model->get_tags_by_itemids(array($article->id)); if (!empty($tags)) { $tags_html = '<div class="tags-list margin-top-10">'; foreach ($tags as $tag) { $tags_html .= ' <a title="' . JText::sprintf('TXT_TAGGED_ARTICLES', CJFunctions::escape($tag->tag_text)) . ' - ' . CJFunctions::escape($tag->description) . '" class="tooltip-hover label tag-item" href="' . JRoute::_('index.php?option=com_cjblog&view=articles&task=tag&id=' . $tag->tag_id . ':' . $tag->alias . $articles_itemid) . '"> <i class="fa fa-tags"></i> ' . CJFunctions::escape($tag->tag_text) . ' </a>'; } $tags_html .= '</div>'; } $avatar = $api->getUserAvatarImage($avatarApp, $article->created_by, $profile['email'], 48); if ($showProfile) { $profileUrl = $api->getUserProfileUrl($profileApp, $article->created_by); } else { $profileUrl = "#"; } $html_top = ' <div class="well well-small"> <div class="media clearfix" style="overflow: visible"> <div class="pull-left"><a href="' . $profileUrl . '" class="thumbnail nomargin-bottom"> <img class="img-avatar" src="' . $avatar . '" alt="' . CjLibUtils::escape($profile[$user_name]) . '" style="max-width: 48px;"></a> </div> <div class="media-body"> <div class="muted">' . ($show_author == 1 ? JText::sprintf('TXT_WRITTEN_BY', JHtml::link($profileUrl, CjLibUtils::escape($profile[$user_name]))) . ' ' : '') . $meta_header . '</div> <div style="margin-top: 5px;" class="clearfix"> <div class="pull-left">' . $meta_stats . '</div> ' . $meta_rating_readonly . ' </div> </div> ' . ($sharing_position == 'top' || $sharing_position == 'both' ? '<hr/>' . $social_buttons_top : '') . ' </div> </div>'; $html_bottom = $tags_html . ' <div class="panel panel-default"> <div class="panel-body"> <div class="media clearfix" style="overflow: visible"> ' . $meta_rating . ' ' . ($sharing_position == 'bottom' || $sharing_position == 'both' ? $social_buttons_bottom . '<hr/>' : '') . ' <div class="pull-left"><a href="' . $profileUrl . '" class="thumbnail nomargin-bottom"><img class="img-avatar" src="' . $avatar . '" alt="' . $profile[$user_name] . '" style="max-width: 48px;"></a></div> <div class="media-body"> <h4 class="media-heading">' . JText::sprintf('TXT_AUTHOR', CjLibUtils::escape($profile[$user_name])) . '</h4> <div style="margin: 5px 0;">' . CjBlogApi::get_user_badges_markup($profile) . '</div> ' . (!empty($profile[$user_name] && $showProfile) ? $about : '') . ' </div> </div> <input id="cjblog_page_id" value="article" type="hidden"> </div> </div>'; $article->text = '<div id="cj-wrapper">' . $html_top . $article->text . $html_bottom . '</div>'; }
/** * Gets the html markup for listing Joomla categories in a column list format, found in cjblog categories listing page * * @param list $categories the categories flat list to be displayed * @param JObject $params the params object of the component, should contain * <pre> * <strong>exclude_categories:</strong> array of category ids to exclude from adding to table * <strong>max_category_columns:</strong> maximum number of columns displayed in table * <strong>show_cat_num_articles:</strong> if set, displays number of items in the category * <strong>show_base_description:</strong> if set, displays the description of the item * <strong>show_base_image:</strong> if category has params, displays image set in params * <strong>max_category_subitems:</strong> number of child items need to be displayed below each category * </pre> * * @param array $options list of options to alter behavior * <pre> * <strong>class:</strong> the class name added to the container, default is category-table * <strong>base_url:</strong> the url should be used as base to build href for each category, id:alias is automatically added to it * <strong>itemid:</strong> the itemid to be added to the url before passing to JRoute * </pre> * @return string the final markup of the column formatted categories listing */ public static function get_joomla_categories_table($categories, $params, $options) { if (empty($categories)) { return ''; } //************************** PARAMS *********************************// $class = isset($options['class']) ? $options['class'] : 'category-table'; $base_url = $options['base_url']; $itemid = $options['itemid']; $categories_excluded = $params->get('exclude_categories', array()); //************************** PARAMS *********************************// $count_of_excluded = 0; foreach ($categories as $category) { if (in_array($category->id, $categories_excluded)) { $count_of_excluded++; } } $content = '<div class="' . $class . '" id="' . $class . '"><div class="row-fluid">'; $column_span = 12 / $params->get('max_category_columns', 3); $categories_per_column = ceil((count($categories) - $count_of_excluded) / $params->get('max_category_columns', 3)); $num_subcategories = 0; $i = 0; foreach ($categories as $category) { if (!in_array($category->id, $categories_excluded)) { if ($i % $categories_per_column == 0) { $content = $content . '<div class="span' . $column_span . '">'; } $content = $content . '<ul class="category"><li class="parent">'; $content = $content . '<a href="' . JRoute::_($base_url . '&id=' . $category->id . ':' . $category->alias . $itemid) . '">' . CJFunctions::escape($category->title) . '</a>'; if ($params->get('show_cat_num_articles')) { $content = $content . ' <span class="muted text-muted">(' . $category->numitems . ')</span>'; } if ($params->get('show_base_description')) { $content = $content . '<div>' . $category->description . '</div>'; } if ($params->get('show_base_image')) { $category_params = json_decode($category->params); if (!empty($category_params) && !empty($category_params->image)) { $content = $content . '<img class="img-polaroid padbottom-5" src="' . $category_params->image . '"/>'; } } $content = $content . '</li>'; $children = $category->getChildren(); if (!empty($children)) { $num_subcategories = 1; foreach ($children as $child) { if (!in_array($child->id, $categories_excluded)) { $content = $content . '<li>'; $content = $content . '<a href="' . JRoute::_($base_url . '&id=' . $child->id . ':' . $child->alias . $itemid) . '">' . CJFunctions::escape($child->title) . '</a>'; if ($params->get('show_cat_num_articles')) { $content = $content . ' <span class="muted text-muted">(' . $child->numitems . ')</span></li>'; } $content = $content . '</li>'; } if ($num_subcategories == $params->get('max_category_subitems')) { break; } } } $content = $content . '</ul>'; if ($i % $categories_per_column == $categories_per_column - 1 || $i + 1 == count($categories)) { $content = $content . '</div>'; } $i++; } // end if the category not excluded } // end for $content = $content . '</div></div>'; return $content; }
$content = $appparams->get('process_content_plugins', 0) == 1; $generator = new SurveyReports($wysiwyg, $bbcode, $content); $document->addScript(JURI::root(true) . '/media/' . S_APP_NAME . '/js/cj.surveys.min.js'); $document->addStyleSheet(JURI::root(true) . '/media/' . S_APP_NAME . '/css/cj.surveys.min.css'); $document->addScript('https://www.google.com/jsapi'); $document->addScriptDeclaration('google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(SurveyFactory.draw_consolidated_charts);'); ?> <?php if ($survey_id > 0) { ?> <div id="cj-wrapper" class="container-fuild"> <div class="row-fluid"> <h2 class="page-header margin-bottom-20"><?php echo CJFunctions::escape($item->title); ?> </h2> <div class="reports-wrapper"> <?php $class = ''; foreach ($item->questions as $item) { switch ($item->question_type) { case 1: echo $generator->get_page_header_question($item, $class); break; case 2: case 3: case 4: case 11:
<tr> <td> <a href="<?php echo JRoute::_('index.php?option=' . S_APP_NAME . '&view=surveys&task=edit&id=' . $item->id); ?> "> <?php echo CJFunctions::escape($item->title); ?> </a> </td> <td><div class="tooltip-hover" title="<?php echo $item->username; ?> "><?php echo CJFunctions::escape($item->name); ?> </div></td> <td style="text-align: center"> <a class="btn btn-mini btn-success btn-change-state" href="<?php echo JRoute::_($approval_link . $item->id); ?> "> <i class="icon-ok icon-white"></i> </a> </td> <td style="text-align: center"> <a class="btn btn-mini btn-danger btn-change-state" href="<?php echo JRoute::_($disapproval_link . $item->id); ?> ">
public function get_address_question($item, $class) { $free_text = ''; $country_options = array(); $classname = $item->mandatory ? ' required' : ''; $html = '<div id="qn-' . $item->id . '" class="question-item well well-transperant' . (isset($item->hidden) ? ' hideme ' : ' ') . $class . ' ' . $item->params->get('question_class', '') . ' clearfix"' . (isset($item->hidden) ? ' style="display: none;"' : '') . (isset($item->rule_answered) ? ' showitems="' . implode(',', $item->rule_answered) . '"' : '') . '>'; $html .= '<div class="question-title qtype-' . $item->question_type . ' ' . $item->params->get('title_class', '') . '">' . CJFunctions::escape($item->title) . '</div>'; $html .= '<div class="question-description ' . $item->params->get('description_class', '') . '">' . CJFunctions::process_html($item->description, $this->_bbcode, $this->_content) . '</div>'; if (!empty($item->responses)) { foreach ($item->responses as $response) { if (!empty($response->free_text)) { $free_text = CJFunctions::escape($response->free_text); break; } } } $address_parts = explode('|||', $free_text); if (count($address_parts) != 7) { $address_parts = array('', '', '', '', '', '', ''); } if (null == $this->_countries) { $this->_countries = CJFunctions::get_country_names(); } foreach ($this->_countries as $country) { $country_options[] = '<option value="' . $country->country_code . '"' . ($address_parts[5] == $country->country_code ? ' selected="selected"' : '') . '>' . CJFunctions::escape($country->country_name) . '</option>'; } $html .= ' <div class="container-fluid address-wrapper error no-space-left"> <div class="row-fluid"> <input type="text" name="address-name-' . $item->id . '" class="span12' . $classname . '" value="' . $address_parts[0] . '" placeholder="' . JText::_('LBL_ADDRESS_FULL_NAME') . '"> </div> <div class="row-fluid"> <input type="text" name="address-line1-' . $item->id . '" class="span12' . $classname . '" value="' . $address_parts[1] . '" placeholder="' . JText::_('LBL_ADDRESS_ADDRESS_LINE1') . '"> </div> <div class="row-fluid"> <input type="text" name="address-line2-' . $item->id . '" class="span7" value="' . $address_parts[2] . '" placeholder="' . JText::_('LBL_ADDRESS_ADDRESS_LINE2') . '"> <input type="text" name="address-city-' . $item->id . '" class="span5' . $classname . ' pull-right" value="' . $address_parts[3] . '" placeholder="' . JText::_('LBL_ADDRESS_ADDRESS_CITY') . '"> </div> <div class="row-fluid"> <input type="text" name="address-state-' . $item->id . '" class="span4' . $classname . '" value="' . $address_parts[4] . '" placeholder="' . JText::_('LBL_ADDRESS_ADDRESS_STATE') . '"> <select name="address-country-' . $item->id . '" size="1" class="span5' . $classname . '"> <option>' . JText::_('LBL_SELECT_OPTION') . '</option> ' . implode('', $country_options) . ' </select> <input type="text" name="address-zip-' . $item->id . '" class="span3' . $classname . ' pull-right" value="' . $address_parts[6] . '" placeholder="' . JText::_('LBL_ADDRESS_ADDRESS_ZIP') . '"> </div> </div>'; $html .= '</div>'; return $html; }
echo $this->lists['catid'] == $category->value ? ' selected="selected"' : ''; ?> > <?php echo $this->escape($category->text); ?> </option> <?php } ?> </select> </div> <div class="input-append"> <input class="input-medium" name="search" type="text" value="<?php echo CJFunctions::escape($this->lists['search']); ?> " placeholder="<?php echo JText::_('COM_COMMUNITYSURVEYS_SEARCH'); ?> "> <div class="btn-group"> <button class="btn" tabindex="-1" type="submit"><?php echo JText::_('COM_COMMUNITYSURVEYS_SEARCH'); ?> </button> <button class="btn dropdown-toggle" data-toggle="dropdown" tabindex="-1"> <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a class="btn-reset" href="#" onclick="return false;"><?php
public function get_address_question($item, $class, $escape = true) { $html = '<div id="qn-' . $item->id . '" class="question-item well well-transperant qn-page-header">'; $html .= '<div class="question-title qtype-' . $item->question_type . '"><i class="fa fa-question-circle"></i> ' . CJFunctions::escape($item->title) . '</div>'; $html .= '<div class="question-description">' . CJFunctions::process_html($item->description, $this->_bbcode, $this->_content) . '</div>'; foreach ($item->responses as $response) { if (!empty($response->free_text)) { $parts = explode('|||', $response->free_text); if (count($parts) == 7) { $response->free_text = '<address><strong>' . CJFunctions::escape($parts[0]) . '</strong><br>'; $response->free_text .= CJFunctions::escape($parts[1]) . '<br>'; if (!empty($parts[2])) { $response->free_text .= CJFunctions::escape($parts[2]) . '<br>'; } $response->free_text .= CJFunctions::escape($parts[3]) . ', ' . CJFunctions::escape($parts[4]) . ', ' . CJFunctions::escape($parts[6]) . '<br>'; $response->free_text .= CJFunctions::get_country_name(CJFunctions::escape($parts[5])); } else { $response->free_text = ''; } $html .= '<h4>' . JText::_('LBL_ANSWER') . '</h4>'; $html .= '<div>' . $response->free_text . '</div>'; } } $html .= '</div>'; return $html; }
public static function get_category_table_reccursive($categories, $params) { //************************** PARAMS *********************************// $base_url = $params['base_url']; $itemid = $params['itemid']; $parent_level = isset($params['parent_level']) ? $params['parent_level'] : 0; $max_columns = isset($params['max_columns']) ? $params['max_columns'] : 3; $max_subitems = isset($params['max_subitems']) ? $params['max_subitems'] : 5; $class = isset($params['class']) ? $params['class'] : 'category-table'; $level = isset($params['level_column']) ? $params['level_column'] : 'nlevel'; $exclude_categories = isset($params['exclude_categories']) ? explode(',', $params['exclude_categories']) : array(); //************************** PARAMS *********************************// $content = '<div class="' . $class . '" id="' . $class . '">'; $current_column = 0; $current_item = 0; $parent_categories = array(); $category_level = $parent_level + 1; // get top level categories first foreach ($categories as $category) { if ($category->{$level} == $category_level && !in_array($category->id, $exclude_categories)) { $parent_categories[] = $category; } } if (count($parent_categories) > 0) { // now we get number of parent categories, lets split to columns $categories_per_column = ceil(count($parent_categories) / $max_columns); $cursor = 0; $total_categories = count($categories); for ($col = 0; $col < $max_columns; $col++) { $content = $content . '<div class="span' . round(12 / $max_columns) . '">'; $previous_column = 'none'; $column_parent_count = 0; $sub_category_count = 0; for ($i = $cursor; $i < $total_categories; $i++) { $category = $categories[$i]; if (in_array($category->id, $exclude_categories)) { if ($i + 1 == $total_categories) { break; } $temp = $categories[++$i]; while ($temp->{$level} > $category->{$level} || $i == $total_categories) { $temp = $categories[++$i]; } if ($i == $total_categories) { break; } $category = $temp; } $category_url = JRoute::_($base_url . '&id=' . $category->id . ':' . $category->alias . $itemid); if ($category->{$level} == $category_level) { if ($previous_column != 'none') { $content = $content . '</ul>'; } if ($column_parent_count == $categories_per_column) { $cursor = $i; break; } $content = $content . '<ul class="category"><li class="parent"><a href="' . $category_url . '">' . CJFunctions::escape($category->title) . '</a>'; if ($params['show_cat_num_articles']) { $content = $content . ' <span class="muted">(' . $category->numitems . ')</span></li>'; } if ($params['show_base_description']) { $content = $content . '<div>' . $category->description . '</div>'; } if ($params['show_base_image']) { $category_params = json_decode($category->params); if (!empty($category_params) && !empty($category_params->image)) { $content = $content . '<img class="img-polaroid padbottom-5" src="' . $category_params->image . '"/>'; } } $previous_column = 'parent'; $column_parent_count++; $sub_category_count = 0; } else { if ($category->{$level} == $category_level + 1 && ($sub_category_count < $max_subitems || $max_subitems == -1)) { $content = $content . '<li><a href="' . $category_url . '">' . CJFunctions::escape($category->title) . '</a>'; if ($params['show_cat_num_articles']) { $content = $content . ' <span class="muted">(' . $category->numitems . ')</span></li>'; } $previous_column = 'child'; $sub_category_count++; } } if ($i == $total_categories - 1) { $cursor = $i + 1; $content = $content . '</ul>'; } } $content = $content . '</div>'; } } $content = $content . '</div>'; return $content; }
public function download_consolidated_pdf_report() { $user = JFactory::getUser(); $app = JFactory::getApplication(); $model = $this->getModel('survey'); $params = JComponentHelper::getParams(S_APP_NAME); $id = $app->input->getInt('id', 0); if (!$id || !$model->authorize_survey($id)) { CJFunctions::throw_error(JText::_('MSG_UNAUTHORIZED'), 401); } else { $wysiwyg = $user->authorise('core.wysiwyg', S_APP_NAME) ? true : false; $bbcode = $wysiwyg && $params->get('default_editor', 'bbcode') == 'bbcode'; $content = $params->get('process_content_plugins', 0) == 1; require_once JPATH_COMPONENT . '/helpers/reports.php'; $generator = new SurveyReports($wysiwyg, $bbcode, $content); $survey = $model->get_consolidated_report($id); $headStyles = array(); $headStyles[] = CJLIB_URI . '/bootstrap/css/bootstrap.min.css'; $headStyles[] = JURI::root(true) . '/media/' . S_APP_NAME . '/css/cj.surveys.min.css'; $headScripts = array(); $headScripts[] = CJLIB_URI . '/jquery/jquery.min.js'; $headScripts[] = CJLIB_URI . '/jquery/jquery.noconflict.js'; $headScripts[] = CJLIB_URI . '/bootstrap/js/bootstrap.min.js'; $headScripts[] = 'https://www.google.com/jsapi'; $headScripts[] = JURI::root(true) . '/media/' . S_APP_NAME . '/js/cj.surveys.min.js'; $html = '<html xmlns="http://www.w3.org/1999/xhtml" dir="' . JFactory::getDocument()->direction . '"><head>'; $html = $html . '<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta http-equiv="content-type" content="text/html; charset=utf-8" />'; // foreach ($headStyles as $style) // { // $html = $html . '<link rel="stylesheet" href="'.$style.'" type="text/css" />'; // } // foreach ($headScripts as $script) // { // $html = $html . '<script src="'.$script.'" type="text/javascript"></script>'; // } // $html .= '<script type="text/javascript">google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(SurveyFactory.draw_consolidated_charts);</script>'; $html .= '</head><body><div id="cj-wrapper" class="container-fuild"><div class="reports-wrapper margin-top-20">'; $html .= '<h2 class="page-header margin-bottom-10">' . CJFunctions::escape($survey->title) . '</h2>'; foreach ($survey->questions as $item) { switch ($item->question_type) { case 1: $html .= $generator->get_page_header_question($item, ''); break; case 2: case 3: case 4: case 11: case 12: $html .= $generator->get_choice_question($item, ''); break; case 5: case 6: $html .= $generator->get_grid_question($item, ''); break; } } $html .= '</div></div></body></html>'; // All validations done, write data now $fileName = 'survey_' . $id . '_' . date('dmYHis') . '.pdf'; // create new PDF document require_once JPATH_COMPONENT_SITE . '/helpers/tcpdf.php'; $pdf = new MYPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set default header data $pdf->SetHeaderData('logo.png', PDF_HEADER_LOGO_WIDTH, $survey->title, ''); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('corejoomla.com'); $pdf->SetTitle('Survey Report'); $pdf->SetSubject('Consolidated Report'); $pdf->SetKeywords('survey, report'); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // --------------------------------------------------------- // set font $pdf->SetFont('freesans'); $pdf->AddPage(); $pdf->writeHTML($html, true, false, true, false, ''); $pdf->lastPage(); $pdf->Output($fileName, $mode); jexit(); } }
}); //--> </script> <div id="cj-wrapper"> <form id="survey-form" name="survey-form" action="<?php echo JRoute::_('index.php?option=com_communitysurveys&view=response' . $itemid); ?> "> <div id="survey-error" class="alert alert-error" style="display: none;"></div> <?php if ($params->get('display_title', 1) == 1) { ?> <h4 class="page-header"><?php echo CJFunctions::escape($survey->title); ?> </h4> <?php } ?> <div id="survey-content"> <?php if ($survey->skip_intro == 1) { ?> <?php $class = ''; foreach ($survey->questions as $qid => $question) { switch ($question->question_type) { case 1:
/** * Function to get the tree table listing. A fields parameter should be passed with the list of columns need to be rendered. Each column of this array should be an associative array with the following fields.<br/> * <strong>header:</strong>header title of the column<br/> * <strong>id:</strong> flag to indicate if the id need to include in the category url<br/> * <strong>src:</strong> base url of the category edit function<br/> * <strong>type:</strong> type of the column - category, text, link, slink, up, down<br/> * <strong>align:</strong> in case of text type field, alignment<br/> * <strong>image-X:</strong> alt images (image-0 and image-1) for flag fields * <strong>src-X:</strong> alt srcs of flag fields * <strong>value:</strong> value of the item, if not to include title<br/> * * @param string $content the return content * @param array $nodes list of category nodes * @param array $fields extra fields to be added to table. * @param unknown_type $nlevel * @return string */ function get_tree_table($content, $nodes, $fields = array(), $nlevel = 0) { $num = 0; static $row_num; foreach ($nodes as $node) { $row_num++; $content = $content . '<tr class="row' . $row_num % 2 . '">'; $content = $content . '<td>' . $row_num . '</td>'; foreach ($fields as $field) { switch ($field['type']) { case 'category': $url = $field['src'] . ($field['id'] ? '&id=' . $node[$this->properties['id_column']] . ':' . $node['alias'] : ''); $content = $content . '<td>' . str_repeat('… ', $nlevel) . JHtml::link($url, CJFunctions::escape($node[$this->properties['title_column']])) . '</td>'; break; case 'text': $content = $content . '<td align="' . $field['align'] . '">' . CJFunctions::escape($node[$field['name']]) . '</td>'; break; case 'link': $url = $field['src'] . ($field['id'] ? '&id=' . $node[$this->properties['id_column']] . ':' . $node['alias'] : ''); $value = $field['value'] != null ? $field['value'] : ($field['value'] == null ? $field['header'] : $node[$field['title_column']]); $content = $content . '<td align="' . $field['align'] . '"><a href="' . $url . '">' . $value . '</a></td>'; break; case 'slink': $url = $field['src-' . $node[$field['name']]] . ($field['id'] ? '&id=' . $node[$this->properties['id_column']] . ':' . $node['alias'] : ''); $class = !empty($field['class']) ? 'class="' . $field['class'] . '"' : ''; $content = $content . '<td align="' . $field['align'] . '">'; $content = $content . '<a ' . $class . ' href="' . $url . '">' . $field['image-' . $node[$field['name']]] . '</a></td>'; break; case 'up': $url = $field['src'] . ($field['id'] ? '&id=' . $node[$this->properties['id_column']] . ':' . $node['alias'] : ''); if ($num > 0) { $attribs = !empty($field['attribs']) ? $field['attribs'] : array(); $content = $content . '<td align="' . $field['align'] . '">' . JHtml::link(JRoute::_($url), $field['value'], $attribs) . '</td>'; } else { $content = $content . '<td></td>'; } break; case 'down': $url = $field['src'] . ($field['id'] ? '&id=' . $node[$this->properties['id_column']] . ':' . $node['alias'] : ''); if ($num < count($nodes) - 1) { $attribs = !empty($field['attribs']) ? $field['attribs'] : array(); $content = $content . '<td align="' . $field['align'] . '">' . JHtml::link(JRoute::_($url), $field['value'], $attribs) . '</a></td>'; } else { $content = $content . '<td></td>'; } break; } } $content = $content . '</tr>'; if (!empty($node['children'])) { $content = $content . $this->get_tree_table('', $node['children'], $fields, $nlevel + 1); } $num++; } return $content; }