Exemple #1
0
function connectionsShowTemplatesPage()
{
    /*
     * Check whether user can edit Settings
     */
    if (!current_user_can('connections_manage_template')) {
        wp_die('<p id="error-page" style="-moz-background-clip:border;
				-moz-border-radius:11px;
				background:#FFFFFF none repeat scroll 0 0;
				border:1px solid #DFDFDF;
				color:#333333;
				display:block;
				font-size:12px;
				line-height:18px;
				margin:25px auto 20px;
				padding:1em 2em;
				text-align:center;
				width:700px">' . __('You do not have sufficient permissions to access this page.', 'connections') . '</p>');
    } else {
        global $connections;
        // Purge the transient so the page is freshly scanned by the template API.
        delete_transient('cn_legacy_templates');
        // cnTemplateFactory::$templates = new stdClass();
        cnTemplateFactory::registerLegacy();
        $form = new cnFormObjects();
        $type = isset($_GET['type']) ? esc_attr($_GET['type']) : 'all';
        $template = cnTemplateFactory::getCatalog($type);
        ?>
		<div class="wrap">
			<?php 
        echo get_screen_icon('connections');
        ?>

			<h2>Connections : <?php 
        _e('Templates', 'connections');
        ?>
 <a class="button add-new-h2" href="http://connections-pro.com/templates/" target="_blank"><?php 
        _e('Get More', 'connections');
        ?>
</a></h2>

			<ul class="subsubsub">
				<li><a <?php 
        if ($type === 'all') {
            echo 'class="current" ';
        }
        ?>
href="admin.php?page=connections_templates&type=all"><?php 
        _e('All', 'connections');
        ?>
</a> | </li>
				<li><a <?php 
        if ($type === 'individual') {
            echo 'class="current" ';
        }
        ?>
href="admin.php?page=connections_templates&type=individual"><?php 
        _e('Individual', 'connections');
        ?>
</a> | </li>
				<li><a <?php 
        if ($type === 'organization') {
            echo 'class="current" ';
        }
        ?>
href="admin.php?page=connections_templates&type=organization"><?php 
        _e('Organization', 'connections');
        ?>
</a> | </li>
				<li><a <?php 
        if ($type === 'family') {
            echo 'class="current" ';
        }
        ?>
href="admin.php?page=connections_templates&type=family"><?php 
        _e('Family', 'connections');
        ?>
</a> | </li>
				<li><a <?php 
        if ($type === 'anniversary') {
            echo 'class="current" ';
        }
        ?>
href="admin.php?page=connections_templates&type=anniversary"><?php 
        _e('Anniversary', 'connections');
        ?>
</a> | </li>
				<li><a <?php 
        if ($type === 'birthday') {
            echo 'class="current" ';
        }
        ?>
href="admin.php?page=connections_templates&type=birthday"><?php 
        _e('Birthday', 'connections');
        ?>
</a></li>
			</ul>

			<br class="clear">

			<table cellspacing="0" cellpadding="0" id="currenttheme">
				<tbody>
					<tr>
						<td class="current_template">
							<h2><?php 
        _e('Current Template', 'connections');
        ?>
</h2>

							<div id="current-template">
								<?php 
        $slug = $connections->options->getActiveTemplate($type);
        $activeTemplate = cnTemplateFactory::getTemplate($slug);
        // var_dump( $activeTemplate );
        if ($activeTemplate) {
            if ($activeTemplate->getThumbnail()) {
                $thumbnail = $activeTemplate->getThumbnail();
                if (!empty($thumbnail['name'])) {
                    echo '<div class="center-thumbnail"><img class="template-thumbnail" src="', $thumbnail['url'], '" /></div>';
                } else {
                    echo '<div class="center-thumbnail"><div class="template-thumbnail-none">', __('Thumbnail Not Available', 'connections'), '</div></div>';
                }
            }
            if ($activeTemplate->getAuthorURL()) {
                $author = '<a title="' . __('Visit author\'s homepage.', 'connections') . '" href="' . $activeTemplate->getAuthorURL() . '">' . $activeTemplate->getAuthor() . '</a>';
            } else {
                $author = $activeTemplate->getAuthor();
            }
            echo '<h3>', $activeTemplate->getName(), ' ', $activeTemplate->getVersion(), ' by ', $author, '</h3>';
            echo '<p class="theme-description">', $activeTemplate->getDescription(), '</p>';
            // Remove the current template so it does not show in the available templates.
            unset($template->{$activeTemplate->getSlug()});
        } else {
            echo '<h3 class="error"> Template ', esc_attr($slug), ' can not be found.</h3>';
        }
        ?>
							</div>
							<div class="clear"></div>
						</td>

						<td class="template_instructions" colspan="2">
							<p><strong><?php 
        _e('Instructions', 'connections');
        ?>
:</strong></p>
							<p>
								<?php 
        _e('By default the <code><a href="http://connections-pro.com/documentation/connections/shortcodes/shortcode-connections/">[connections]</a></code> shortcode will show all entries types. To change the template used when displaying all entry types, select the "All" tab and activate the template. When the <code><a href="http://connections-pro.com/documentation/connections/shortcodes/shortcode-connections/list_type/">list_type</a></code>shortcode option is used to filter the entries based on the entry type, the template for that entry type will be used. To change the template used for a specific entry type, select the appropriate tab and then activate the template. If multiple entry types are specified in the <code><a href="http://connections-pro.com/documentation/connections/shortcodes/shortcode-connections/list_type/">list_type</a></code> shortcode option, the template for the entry type listed first will be used to display the entry list.', 'connections');
        ?>
							</p>

							<p>
								<?php 
        _e('The <code><a href="http://connections-pro.com/documentation/connections/shortcodes/shortcode-upcoming-list/">[upcoming_list]</a></code> shortcode which displays the upcoming anniversaries and birthdays will be displayed with the template that is activated under their respective tabs.', 'connections');
        ?>
							</p>

							<p>
								<?php 
        _e('The current active template for each template type can be overridden by using the <code><a href="http://connections-pro.com/documentation/connections/shortcodes/shortcode-connections/template-option/">template</a></code> shortcode option.', 'connections');
        ?>
							</p>
						</td>
					</tr>
				</tbody>
			</table>

			<table cellspacing="0" cellpadding="0" id="availablethemes">
				<tbody>
					<tr>
						<td class="current_template" colspan="3">
							<h2><?php 
        _e('Available Templates', 'connections');
        ?>
</h2>
						</td>
					</tr>

					<?php 
        $slugs = array_keys((array) $template);
        natcasesort($slugs);
        $table = array();
        $rows = ceil(count($slugs) / 3);
        for ($row = 1; $row <= $rows; $row++) {
            for ($col = 1; $col <= 3; $col++) {
                $table[$row][$col] = array_shift($slugs);
            }
        }
        foreach ($table as $row => $cols) {
            ?>
						<tr>
							<?php 
            foreach ($cols as $col => $slug) {
                $activateTokenURL = '';
                $deleteTokenURL = '';
                $class = array('available-theme');
                if ($row == 1) {
                    $class[] = 'top';
                }
                if ($row == $rows) {
                    $class[] = 'bottom';
                }
                if ($col == 1) {
                    $class[] = 'left';
                }
                if ($col == 3) {
                    $class[] = 'right';
                }
                ?>

								<td class="<?php 
                echo join(' ', $class);
                ?>
">

									<?php 
                if (!isset($template->{$slug})) {
                    continue;
                }
                // var_dump( $template->{ $slug } );
                if ($template->{$slug}->getThumbnail()) {
                    $thumbnail = $template->{$slug}->getThumbnail();
                    if (!empty($thumbnail['name'])) {
                        echo '<div class="center-thumbnail"><img class="template-thumbnail" src="', $thumbnail['url'], '" width="300" height="225"></div>';
                    } else {
                        echo '<div class="center-thumbnail"><div class="template-thumbnail-none" style="width: 300px; height: 225px"><p>', __('Thumbnail Not Available', 'connections'), '</p></div></div>';
                    }
                }
                if ($template->{$slug}->getAuthorURL()) {
                    $author = '<a title="Visit author\'s homepage." href="' . $template->{$slug}->getAuthorURL() . '">' . $template->{$slug}->getAuthor() . '</a>';
                } else {
                    $author = $template->{$slug}->getAuthor();
                }
                echo '<h3>', $template->{$slug}->getName(), ' ', $template->{$slug}->getVersion(), ' by ', $author, '</h3>';
                echo '<p class="description">', $template->{$slug}->getDescription(), '</p>';
                echo '<p>', __('Shortcode Override:', 'connections'), '<code> template="', $slug, '"</code></p>';
                ?>

									<span class="action-links">
										<?php 
                $activateTokenURL = $form->tokenURL('admin.php?cn-action=activate_template&type=' . $type . '&template=' . $template->{$slug}->getSlug(), 'activate_' . $template->{$slug}->getSlug());
                if ($template->{$slug}->isCustom() === TRUE && $template->{$slug}->isLegacy() === TRUE) {
                    $deleteTokenURL = $form->tokenURL('admin.php?cn-action=delete_template&type=' . $type . '&template=' . $template->{$slug}->getSlug(), 'delete_' . $template->{$slug}->getSlug());
                }
                ?>

										<a class="button-primary" href="<?php 
                echo esc_attr($activateTokenURL);
                ?>
" title="Activate '<?php 
                echo esc_attr($template->{$slug}->getName());
                ?>
'"><?php 
                _e('Activate', 'connections');
                ?>
</a>

										<?php 
                if (!empty($deleteTokenURL)) {
                    ?>
											 | <a class="button button-warning" href="<?php 
                    echo esc_attr($deleteTokenURL);
                    ?>
" title="Delete '<?php 
                    echo esc_attr($template->{$slug}->getName());
                    ?>
'" onclick="return confirm('You are about to delete this theme \'<?php 
                    echo esc_attr($template->{$slug}->getName());
                    ?>
\'\n  \'Cancel\' to stop, \'OK\' to delete.');">Delete</a>
										<?php 
                }
                ?>
									</span>
							<?php 
                if ($template->{$slug}->isCustom() === FALSE) {
                    echo '<p class="description">', __('This a core template and can not be deleted.', 'connections'), '</p>';
                } else {
                    if ($template->{$slug}->isCustom() === TRUE && $template->{$slug}->isLegacy() === FALSE) {
                        echo '<p class="description">', __('This template is a plugin. You can deactivate and delete the template from the Plugins admin page.', 'connections'), '</p>';
                    }
                }
            }
            ?>
								</td>
						</tr>
					<?php 
        }
        ?>


				</tbody>
			</table>

			<?php 
        if (file_exists(CN_CUSTOM_TEMPLATE_PATH) && is_writeable(CN_CUSTOM_TEMPLATE_PATH)) {
            ?>

			<table cellspacing="0" cellpadding="0" id="installthemes">
				<tbody>
					<tr>
						<td class="install_template" colspan="3">
							<h2><?php 
            _e('Install Legacy Template', 'connections');
            ?>
</h2>

							<p><?php 
            printf(__("If you puchased your template after 3.25.2013, please follow these <a href='%s'>installation instructions</a>. If you are upgrading your template purchased prior to 3.25.2013, please take note of the special upgrade instructions found on the same page.", 'connections'), 'http://connections-pro.com/documentation/plugin/install/templates/');
            ?>
</p>

							<?php 
            $formAttr = array('action' => '', 'method' => 'post', 'enctype' => 'multipart/form-data');
            $form->open($formAttr);
            $form->tokenField('install_template');
            ?>

							<p>
								<input type="hidden" name="cn-action" value="install_template"/>

								<label for='template'><?php 
            _e('Select Template:', 'connections');
            ?>
									<input type='file' value='' name='template' size='25' />
								</label>
								<input type="submit" value="<?php 
            _e('Install Now', 'connections');
            ?>
" class="button">
							</p>

							<?php 
            $form->close();
            ?>
						</td>
					</tr>
				</tbody>
			</table>

			<?php 
        }
        ?>

		</div>
	<?php 
    }
}
/**
 * Renders the Template admin page.
 *
 * @access private
 * @since  unknown
 */
function connectionsShowTemplatesPage()
{
    /*
     * Check whether user can edit Settings
     */
    if (!current_user_can('connections_manage_template')) {
        wp_die('<p id="error-page" style="-moz-background-clip:border;
				-moz-border-radius:11px;
				background:#FFFFFF none repeat scroll 0 0;
				border:1px solid #DFDFDF;
				color:#333333;
				display:block;
				font-size:12px;
				line-height:18px;
				margin:25px auto 20px;
				padding:1em 2em;
				text-align:center;
				width:700px">' . __('You do not have sufficient permissions to access this page.', 'connections') . '</p>');
    } else {
        // Grab an instance of the Connections object.
        $instance = Connections_Directory();
        $type = isset($_GET['type']) ? esc_attr($_GET['type']) : 'all';
        $templates = cnTemplateFactory::getCatalog($type);
        $adminURL = self_admin_url('admin.php');
        $pageURL = add_query_arg('page', 'connections_templates', $adminURL);
        $homeID = cnSettingsAPI::get('connections', 'connections_home_page', 'page_id');
        $homeURL = get_permalink($homeID);
        $customizerURL = add_query_arg('cn-customize-template', 'true', $homeURL);
        ?>
		<div class="wrap">

			<h1>Connections : <?php 
        _e('Templates', 'connections');
        ?>
				<a class="button add-new-h2" href="http://connections-pro.com/templates/" target="_blank"><?php 
        _e('Get More', 'connections');
        ?>
</a>
			</h1>

			<ul class="subsubsub">
				<li>
					<a <?php 
        if ('all' == $type) {
            echo 'class="current" ';
        }
        ?>
href="<?php 
        echo esc_url(add_query_arg('type', 'all', $pageURL));
        ?>
">
						<?php 
        _e('All', 'connections');
        ?>
					</a> |
				</li>
				<li>
					<a <?php 
        if ('individual' == $type) {
            echo 'class="current" ';
        }
        ?>
href="<?php 
        echo esc_url(add_query_arg('type', 'individual', $pageURL));
        ?>
">
						<?php 
        _e('Individual', 'connections');
        ?>
					</a> |
				</li>
				<li>
					<a <?php 
        if ('organization' == $type) {
            echo 'class="current" ';
        }
        ?>
href="<?php 
        echo esc_url(add_query_arg('type', 'organization', $pageURL));
        ?>
">
						<?php 
        _e('Organization', 'connections');
        ?>
					</a> |
				</li>
				<li>
					<a <?php 
        if ('family' == $type) {
            echo 'class="current" ';
        }
        ?>
href="<?php 
        echo esc_url(add_query_arg('type', 'family', $pageURL));
        ?>
">
						<?php 
        _e('Family', 'connections');
        ?>
					</a> |
				</li>
				<li>
					<a <?php 
        if ('anniversary' == $type) {
            echo 'class="current" ';
        }
        ?>
href="<?php 
        echo esc_url(add_query_arg('type', 'anniversary', $pageURL));
        ?>
">
						<?php 
        _e('Anniversary', 'connections');
        ?>
					</a> |
				</li>
				<li>
					<a <?php 
        if ('birthday' == $type) {
            echo 'class="current" ';
        }
        ?>
href="<?php 
        echo esc_url(add_query_arg('type', 'birthday', $pageURL));
        ?>
">
						<?php 
        _e('Birthday', 'connections');
        ?>
					</a>
				</li>
			</ul>

			<br class="clear">

			<table cellspacing="0" cellpadding="0" id="currenttheme">
				<tbody>
					<tr>
						<td class="current_template">
							<h2><?php 
        _e('Current Template', 'connections');
        ?>
</h2>

							<div id="current-template">
								<?php 
        $slug = $instance->options->getActiveTemplate($type);
        /** @var cnTemplate $activeTemplate */
        $activeTemplate = cnTemplateFactory::getTemplate($slug);
        if ($activeTemplate) {
            cnTemplateThumbnail($activeTemplate);
            cnTemplateAuthor($activeTemplate);
            cnTemplateDescription($activeTemplate);
            cnTemplateCustomizerButton($activeTemplate, $customizerURL, $pageURL);
            // Remove the current template so it does not show in the available templates.
            unset($templates->{$activeTemplate->getSlug()});
        } else {
            echo '<h3 class="error"> Template ', esc_attr($slug), ' can not be found.</h3>';
        }
        ?>
							</div>
							<div class="clear"></div>
						</td>

						<td class="template_instructions" colspan="2">
							<p>
								<strong><?php 
        _e('Instructions', 'connections');
        ?>
:</strong>
							</p>

							<p>
								<?php 
        _e('By default the <code><a href="http://connections-pro.com/documentation/connections/shortcodes/shortcode-connections/">&#91;connections&#93;</a></code> shortcode will show all entries types. To change the template used when displaying all entry types, select the "All" tab and activate the template. When the <code><a href="http://connections-pro.com/documentation/connections/shortcodes/shortcode-connections/list_type/">list_type</a></code>shortcode option is used to filter the entries based on the entry type, the template for that entry type will be used. To change the template used for a specific entry type, select the appropriate tab and then activate the template. If multiple entry types are specified in the <code><a href="http://connections-pro.com/documentation/connections/shortcodes/shortcode-connections/list_type/">list_type</a></code> shortcode option, the template for the entry type listed first will be used to display the entry list.', 'connections');
        ?>
							</p>

							<p>
								<?php 
        _e('The <code><a href="http://connections-pro.com/documentation/connections/shortcodes/shortcode-upcoming-list/">[upcoming_list]</a></code> shortcode which displays the upcoming anniversaries and birthdays will be displayed with the template that is activated under their respective tabs.', 'connections');
        ?>
							</p>

							<p>
								<?php 
        _e('The current active template for each template type can be overridden by using the <code><a href="http://connections-pro.com/documentation/connections/shortcodes/shortcode-connections/template-option/">template</a></code> shortcode option.', 'connections');
        ?>
							</p>
						</td>
					</tr>
				</tbody>
			</table> <!-- /#currenttheme -->

			<table cellspacing="0" cellpadding="0" id="availablethemes">
				<tbody>
					<tr>
						<td class="current_template" colspan="3">
							<h2><?php 
        _e('Available Templates', 'connections');
        ?>
</h2>
						</td>
					</tr>

					<?php 
        $slugs = array_keys((array) $templates);
        natcasesort($slugs);
        $table = array();
        $rows = ceil(count($slugs) / 3);
        for ($row = 1; $row <= $rows; $row++) {
            for ($col = 1; $col <= 3; $col++) {
                $table[$row][$col] = array_shift($slugs);
            }
        }
        foreach ($table as $row => $cols) {
            ?>
						<tr>
							<?php 
            foreach ($cols as $col => $slug) {
                if (!isset($templates->{$slug})) {
                    continue;
                }
                /** @var cnTemplate $template */
                $template = $templates->{$slug};
                $class = array('available-theme');
                if ($row == 1) {
                    $class[] = 'top';
                }
                if ($row == $rows) {
                    $class[] = 'bottom';
                }
                if ($col == 1) {
                    $class[] = 'left';
                }
                if ($col == 3) {
                    $class[] = 'right';
                }
                ?>

								<td <?php 
                echo cnHTML::attribute('class', $class);
                ?>
>

									<?php 
                cnTemplateThumbnail($template);
                cnTemplateAuthor($template);
                cnTemplateDescription($template);
                cnTemplateDeactivateText($template);
                cnTemplateShortcodeOverride($template);
                ?>

									<span class="action-links">
										<?php 
                cntemplateActivateButton($template, $type);
                cnTemplateDeleteButton($template);
                cnTemplateCustomizerButton($template, $customizerURL, $pageURL);
                ?>
									</span>
								</td>
								<?php 
            }
            ?>
						</tr>
						<?php 
        }
        ?>
				</tbody>
			</table> <!-- /#availablethemes -->
		</div> <!-- /.wrap -->
		<?php 
    }
}
/**
 * Display the upcoming list.
 *
 * @access public
 * @since  unknown
 *
 * @param array  $atts
 * @param string $content [optional]
 * @param string $tag     [optional] When called as the callback for add_shortcode, the shortcode tag is passed
 *                        automatically. Manually setting the shortcode tag so the function can be called
 *                        independently.
 *
 * @return string
 */
function _upcoming_list($atts, $content = NULL, $tag = 'upcoming_list')
{
    global $connections, $wpdb;
    // $template =& $connections->template;
    $out = '';
    $alternate = '';
    $atts = shortcode_atts(array('list_type' => 'birthday', 'days' => '30', 'include_today' => TRUE, 'private_override' => FALSE, 'date_format' => 'F jS', 'show_lastname' => FALSE, 'show_title' => TRUE, 'list_title' => NULL, 'template' => NULL), $atts, $tag);
    /*
     * Convert some of the $atts values in the array to boolean.
     */
    cnFormatting::toBoolean($atts['include_today']);
    cnFormatting::toBoolean($atts['private_override']);
    cnFormatting::toBoolean($atts['show_lastname']);
    cnFormatting::toBoolean($atts['repeat_alphaindex']);
    cnFormatting::toBoolean($atts['show_title']);
    /*
     * If a list type was specified in the shortcode, load the template based on that type.
     * However, if a specific template was specified, that should preempt the template to be loaded based on the list type if it was specified..
     */
    if (!empty($atts['template'])) {
        $template = cnTemplateFactory::getTemplate($atts['template']);
    } else {
        $templateSlug = $connections->options->getActiveTemplate($atts['list_type']);
        $template = cnTemplateFactory::getTemplate($templateSlug);
    }
    // No template found return error message.
    if ($template == FALSE) {
        return '<p style="color:red; font-weight:bold; text-align:center;">' . sprintf(__('ERROR: Template %1$s not found.', 'connections'), $atts['template']) . '</p>';
    }
    do_action('cn_template_include_once-' . $template->getSlug());
    do_action('cn_template_enqueue_js-' . $template->getSlug());
    /*
     * Set the query vars and run query.
     */
    // Show only public or private [if permitted] entries.
    if (is_user_logged_in() || $atts['private_override'] != FALSE) {
        $visibilityfilter = " AND (visibility='private' OR visibility='public') AND (" . $atts['list_type'] . " != '')";
    } else {
        $visibilityfilter = " AND (visibility='public') AND (`" . $atts['list_type'] . "` != '')";
    }
    // Get the current date from WP which should have the current time zone offset.
    $wpCurrentDate = date('Y-m-d', $connections->options->wpCurrentTime);
    // Whether or not to include the event occurring today or not.
    $atts['include_today'] ? $includeToday = '<=' : ($includeToday = '<');
    $newSQL = "SELECT * FROM " . CN_ENTRY_TABLE . " WHERE" . "  (YEAR(DATE_ADD('{$wpCurrentDate}', INTERVAL " . $atts['days'] . " DAY))" . " - YEAR(DATE_ADD(FROM_UNIXTIME(`" . $atts['list_type'] . "`), INTERVAL " . $connections->options->sqlTimeOffset . " SECOND)) )" . " - ( MID(DATE_ADD('{$wpCurrentDate}', INTERVAL " . $atts['days'] . " DAY),5,6)" . " < MID(DATE_ADD(FROM_UNIXTIME(`" . $atts['list_type'] . "`), INTERVAL " . $connections->options->sqlTimeOffset . " SECOND),5,6) )" . " > ( YEAR('{$wpCurrentDate}')" . " - YEAR(DATE_ADD(FROM_UNIXTIME(`" . $atts['list_type'] . "`), INTERVAL " . $connections->options->sqlTimeOffset . " SECOND)) )" . " - ( MID('{$wpCurrentDate}',5,6)" . " " . $includeToday . " MID(DATE_ADD(FROM_UNIXTIME(`" . $atts['list_type'] . "`), INTERVAL " . $connections->options->sqlTimeOffset . " SECOND),5,6) )" . $visibilityfilter;
    //$out .= print_r($newSQL , TRUE);
    $results = $wpdb->get_results($newSQL);
    //$out .= print_r($results , TRUE);
    // If there are no results no need to proceed and output message.
    if (empty($results)) {
        $noResultMessage = __('No results.', 'connections');
        $noResultMessage = apply_filters('cn_upcoming_no_result_message', $noResultMessage);
        $out .= '<p class="cn-upcoming-no-results">' . $noResultMessage . '</p>';
    } else {
        /*The SQL returns an array sorted by the birthday and/or anniversary date. However the year end wrap needs to be accounted for.
        		Otherwise earlier months of the year show before the later months in the year. Example Jan before Dec. The desired output is to show
        		Dec then Jan dates.  This function checks to see if the month is a month earlier than the current month. If it is the year is changed to the following year rather than the current.
        		After a new list is built, it is resorted based on the date.*/
        foreach ($results as $key => $row) {
            if (gmmktime(23, 59, 59, gmdate('m', $row->{$atts}['list_type']), gmdate('d', $row->{$atts}['list_type']), gmdate('Y', $connections->options->wpCurrentTime)) < $connections->options->wpCurrentTime) {
                $dateSort[] = $row->{$atts}['list_type'] = gmmktime(0, 0, 0, gmdate('m', $row->{$atts}['list_type']), gmdate('d', $row->{$atts}['list_type']), gmdate('Y', $connections->options->wpCurrentTime) + 1);
            } else {
                $dateSort[] = $row->{$atts}['list_type'] = gmmktime(0, 0, 0, gmdate('m', $row->{$atts}['list_type']), gmdate('d', $row->{$atts}['list_type']), gmdate('Y', $connections->options->wpCurrentTime));
            }
        }
        array_multisort($dateSort, SORT_ASC, $results);
        if (empty($atts['list_title'])) {
            switch ($atts['list_type']) {
                case 'birthday':
                    if ($atts['days'] >= 1) {
                        $list_title = 'Upcoming Birthdays the next ' . $atts['days'] . ' days';
                    } else {
                        $list_title = 'Today\'s Birthdays';
                    }
                    break;
                case 'anniversary':
                    if ($atts['days'] >= 1) {
                        $list_title = 'Upcoming Anniversaries the next ' . $atts['days'] . ' days';
                    } else {
                        $list_title = 'Today\'s Anniversaries';
                    }
                    break;
            }
        } else {
            $list_title = $atts['list_title'];
        }
        ob_start();
        // Prints the template's CSS file.
        do_action('cn_template_inline_css-' . $template->getSlug(), $atts);
        $out .= ob_get_contents();
        ob_end_clean();
        $out .= '<div class="connections-list cn-upcoming cn-' . $atts['list_type'] . '" id="cn-list" data-connections-version="' . $connections->options->getVersion() . '-' . $connections->options->getDBVersion() . '">' . "\n";
        $out .= "\n" . '<div class="cn-template cn-' . $template->getSlug() . '" id="cn-' . $template->getSlug() . '">' . "\n";
        $out .= "\n" . '<div class="cn-clear" id="cn-list-head">' . "\n";
        if ($atts['show_title']) {
            $out .= '<div class="cn-upcoming-title">' . $list_title . '</div>';
        }
        $out .= "\n" . '</div>' . "\n";
        $out .= '<div class="cn-clear" id="cn-list-body">' . "\n";
        foreach ($results as $row) {
            $entry = new cnvCard($row);
            $vCard =& $entry;
            $entry->name = '';
            $alternate == '' ? $alternate = '-alternate' : ($alternate = '');
            /*
             * Whether or not to show the last name.
             * Setting $entry->name is for compatibility to versions prior to 0.7.1.6
             */
            !$atts['show_lastname'] ? $entry->name = $entry->getFirstName() : ($entry->name = $entry->getFullFirstLastName());
            if (!$atts['show_lastname']) {
                $entry->setLastName('');
            }
            $out .= '<div class="cn-upcoming-row' . $alternate . ' vcard ' . '">' . "\n";
            ob_start();
            do_action('cn_action_card-' . $template->getSlug(), $entry, $template, $atts);
            $out .= ob_get_contents();
            ob_end_clean();
            $out .= '</div>' . "\n";
        }
        $out .= "\n" . '</div>' . "\n";
        $out .= "\n" . '<div class="cn-clear" id="cn-list-foot">' . "\n";
        $out .= "\n" . '</div>' . "\n";
        $out .= "\n" . '</div>' . "\n";
        $out .= "\n" . '</div>' . "\n";
    }
    if (cnSettingsAPI::get('connections', 'connections_compatibility', 'strip_rnt')) {
        $search = array("\r\n", "\r", "\n", "\t");
        $replace = array('', '', '', '');
        $out = str_replace($search, $replace, $out);
    }
    return $out;
}