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.</p>'); } else { global $connections; $form = new cnFormObjects(); $tmplt = new cnTemplate(); $tmplt->buildCatalog(); !isset($_GET['type']) ? $type = 'all' : ($type = esc_attr($_GET['type'])); $templates = $tmplt->getCatalog($type); $connections->displayMessages(); ?> <div class="wrap"> <div id="icon-connections" class="icon32"> <br> </div> <h2>Connections : Templates</h2> <ul class="subsubsub"> <li><a <?php if ($type === 'all') { echo 'class="current" '; } ?> href="admin.php?page=connections_templates&type=all">All</a> | </li> <li><a <?php if ($type === 'individual') { echo 'class="current" '; } ?> href="admin.php?page=connections_templates&type=individual">Individual</a> | </li> <li><a <?php if ($type === 'organization') { echo 'class="current" '; } ?> href="admin.php?page=connections_templates&type=organization">Organization</a> | </li> <li><a <?php if ($type === 'family') { echo 'class="current" '; } ?> href="admin.php?page=connections_templates&type=family">Family</a> | </li> <li><a <?php if ($type === 'anniversary') { echo 'class="current" '; } ?> href="admin.php?page=connections_templates&type=anniversary">Anniversary</a> | </li> <li><a <?php if ($type === 'birthday') { echo 'class="current" '; } ?> href="admin.php?page=connections_templates&type=birthday">Birthday</a></li> </ul> <table cellspacing="0" cellpadding="0" id="availablethemes"> <tbody> <tr> <td class="current_template"> <h2>Current Template</h2> <div id="current-theme"> <?php $currentTemplate = $connections->options->getActiveTemplate($type); if (!empty($currentTemplate)) { $author = ''; if (isset($currentTemplate->thumbnailPath)) { echo '<div class="current-template"><img class="template-thumbnail" src="' . $currentTemplate->thumbnailURL . '" /></div>'; } if (isset($currentTemplate->uri)) { $author = '<a title="Visit author\'s homepage." href="http://' . esc_attr($currentTemplate->uri) . '">' . esc_attr($currentTemplate->author) . '</a>'; } else { $author = esc_attr($currentTemplate->author); } echo '<h3>', esc_attr($currentTemplate->name), ' ', esc_attr($currentTemplate->version), ' by ', $author, '</h3>'; echo '<p class="theme-description">', esc_attr($currentTemplate->description), '</p>'; // Remove the current template so it does not show in the available templates. unset($templates->{$currentTemplate->slug}); } ?> </div> <div class="clear"></div> </td> <td class="template_instructions" colspan="2"> <p><strong>Instructions:</strong></p> <p> By default the <code>[connections_list]</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>list_type</code> shortcode attribute 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 specific entry type, select the appropriate tab and then activate the template. If multiple entry types are specified in the <code>list_type</code> shortcode attribute, the template for the entry type listed first will be used to display the entry list. </p> <p> The <code>[upcoming_list]</code> shortcode which displays the upcoming anniversaries and birthdays will be displayed with the template that is activated under their respective tabs. </p> <p> The current active template for each template type can be overridden by using the the <code>template</code> shortcode attribute. </p> </td> </tr> <tr> <td class="install_template" colspan="3"> <h2>Install Template</h2> <?php $formAttr = array('action' => 'admin.php?page=connections_templates&type=' . $type . '&action=install', 'method' => 'post', 'enctype' => 'multipart/form-data'); $form->open($formAttr); $form->tokenField('install_template'); ?> <p> <label for='template'>Select Template: <input type='file' value='' name='template' size='25' /> </label> <input type="submit" value="Install Now" class="button"> </p> <?php $form->close(); ?> </td> </tr> <tr> <td class="current_template" colspan="3"> <h2>Available Templates</h2> </td> </tr> <?php $templateNames = array_keys((array) $templates); natcasesort($templateNames); $table = array(); $rows = ceil(count((array) $templates) / 3); for ($row = 1; $row <= $rows; $row++) { for ($col = 1; $col <= 3; $col++) { $table[$row][$col] = array_shift($templateNames); } } foreach ($table as $row => $cols) { ?> <tr> <?php foreach ($cols as $col => $slug) { $activateTokenURL = NULL; $deleteTokenURL = NULL; $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($templates->{$slug})) { continue; } $author = ''; if (isset($templates->{$slug}->thumbnailPath)) { echo '<div class="center-thumbnail"><img class="template-thumbnail" src="' . $templates->{$slug}->thumbnailURL . '" /></div>'; } if (isset($templates->{$slug}->uri)) { $author = '<a title="Visit author\'s homepage." href="' . esc_attr($templates->{$slug}->uri) . '">' . esc_attr($templates->{$slug}->author) . '</a>'; } else { $author = esc_attr($templates->{$slug}->author); } echo '<h3>', esc_attr($templates->{$slug}->name), ' ', esc_attr($templates->{$slug}->version), ' by ', $author, '</h3>'; echo '<p class="description">', esc_attr($templates->{$slug}->description), '</p>'; echo '<p>Shortcode Override: <code>template="' . $slug . '"</code></p>'; if ($templates->{$slug}->custom === FALSE) { echo '<p>This a supplied template and can not be deleted.</p>'; } ?> <span class="action-links"> <?php $activateTokenURL = $form->tokenURL('admin.php?page=connections_templates&action=activate&type=' . $type . '&template=' . esc_attr($templates->{$slug}->slug), 'activate_' . esc_attr($templates->{$slug}->slug)); if ($templates->{$slug}->custom === TRUE) { $deleteTokenURL = $form->tokenURL('admin.php?page=connections_templates&action=delete&type=' . $type . '&template=' . esc_attr($templates->{$slug}->slug), 'delete_' . esc_attr($templates->{$slug}->slug)); } ?> <a class="activatelink" href="<?php echo esc_attr($activateTokenURL); ?> " title="Activate '<?php echo esc_attr($templates->{$slug}->name); ?> '">Activate</a> <?php if (isset($deleteTokenURL)) { ?> | <a class="deletelink" href="<?php echo esc_attr($deleteTokenURL); ?> " title="Delete '<?php echo esc_attr($templates->{$slug}->name); ?> '" onclick="return confirm('You are about to delete this theme \'<?php echo esc_attr($templates->{$slug}->name); ?> \'\n \'Cancel\' to stop, \'OK\' to delete.');">Delete</a> <?php } ?> </span> </td> <?php } ?> </tr> <?php } ?> </tbody> </table> </div> <?php } }
/** * Renders the "Customize" button. * * @access private * @since 8.4 * * @param cnTemplate $template * @param string $customizerURL * @param string $returnURL */ function cnTemplateCustomizerButton($template, $customizerURL, $returnURL) { if ($template->supports('customizer')) { $href = add_query_arg(array('url' => urlencode(add_query_arg('cn-template', $template->getSlug(), $customizerURL)), 'cn-template' => $template->getSlug(), 'return' => urlencode($returnURL)), 'customize.php'); /** * NOTE: According to the docs for the JavaScript Customizer API, you can auto focus * to the panel, section or control you wish via the URL. Which does work. * * However, if you add this via @see add_query_arg() or escape it using * @see esc_url() the required bracket will be removed which are required * for auto focusing via the URL too function. This is why I added it after * escaping the URL. * * @link https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/#focusing */ ?> <a class="button" href="<?php echo esc_url($href) . '&autofocus[section]=cn_template_customizer_section_display'; ?> " title="Customize '<?php echo esc_attr($template->getName()); ?> '"><?php _e('Customize', 'connections'); ?> </a> <?php } }
/** * @param cnTemplate $template */ public function __construct($template) { $this->template = $template; add_filter('cn_list_atts-' . $template->getSlug(), array(__CLASS__, 'initOptions')); }
public function setDefaultTemplates() { $templates = new cnTemplate(); $templates->buildCatalog(); $all = $templates->getCatalog('all'); $anniversary = $templates->getCatalog('anniversary'); $birthday = $templates->getCatalog('birthday'); $this->setActiveTemplate('all', $all->card); $this->setActiveTemplate('individual', $all->card); $this->setActiveTemplate('organization', $all->card); $this->setActiveTemplate('family', $all->card); $this->setActiveTemplate('anniversary', $anniversary->{'anniversary-light'}); $this->setActiveTemplate('birthday', $birthday->{'birthday-light'}); $this->defaultTemplatesSet = TRUE; }
function processActivateTemplate() { $templateName = esc_attr($_GET['template']); check_admin_referer('activate_' . $templateName); global $connections; $tmplts = new cnTemplate(); $tmplts->buildCatalog(); $type = esc_attr($_GET['type']); $slug = esc_attr($_GET['template']); $template = $tmplts->getCatalog($type); $connections->options->setActiveTemplate($type, $template->$slug); $connections->options->saveOptions(); $connections->setSuccessMessage('template_change_active'); }
function _upcoming_list($atts, $content = null) { global $connections, $wpdb; $template = new cnTemplate(); $atts = shortcode_atts(array('list_type' => 'birthday', 'days' => '30', 'private_override' => FALSE, 'date_format' => 'F jS', 'show_lastname' => FALSE, 'list_title' => NULL, 'template' => $connections->options->getActiveTemplate('birthday')), $atts); 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'] . "` != '')"; } if ($atts['list_title'] == NULL) { 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']; } /* * $atts['template'] can be either a string or an object. It is a string when set * with the shortcode attribute. If it is a string, the template will be loaded * via the cnTemplate class. * * If the attribute is not set, it will be the object returned from the * cnOptions::getActiveTemplate() method which stores the default template * per list style. */ if (isset($atts['template']) && !is_object($atts['template'])) { $template->load($atts['template']); $template->includeFunctions(); } else { $template->init($connections->options->getActiveTemplate($atts['list_type'])); $template->includeFunctions(); } /* Old and busted query!2 $sql = "SELECT id, ".$atts['list_type'].", last_name, first_name FROM ".$wpdb->prefix."connections where (YEAR(DATE_ADD(CURRENT_DATE, INTERVAL ".$atts['days']." DAY))" . " - YEAR(FROM_UNIXTIME(".$atts['list_type'].")) )" . " - ( MID(DATE_ADD(CURRENT_DATE, INTERVAL ".$atts['days']." DAY),5,6)" . " < MID(FROM_UNIXTIME(".$atts['list_type']."),5,6) )" . " > ( YEAR(CURRENT_DATE)" . " - YEAR(FROM_UNIXTIME(".$atts['list_type'].")) )" . " - ( MID(CURRENT_DATE,5,6)" . " < MID(FROM_UNIXTIME(".$atts['list_type']."),5,6) )" . $visibilityfilter . " ORDER BY FROM_UNIXTIME(".$atts['list_type'].") ASC"; */ // Get the current date from WP which should have the current time zone offset. $wpCurrentDate = date('Y-m-d', $connections->options->wpCurrentTime); /* * */ $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)" . " <= MID(DATE_ADD(FROM_UNIXTIME(`" . $atts['list_type'] . "`), INTERVAL " . $connections->options->sqlTimeOffset . " SECOND),5,6) )" . $visibilityfilter; $results = $wpdb->get_results($newSQL); if ($results != NULL) { /*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 (mktime(23, 59, 59, date('m', $row->{$atts}['list_type']), date('d', $row->{$atts}['list_type']), date('Y', $connections->options->wpCurrentTime)) < $connections->options->wpCurrentTime) { $dateSort[] = $row->{$atts}['list_type'] = mktime(0, 0, 0, date('m', $row->{$atts}['list_type']), date('d', $row->{$atts}['list_type']), date('Y', $connections->options->wpCurrentTime) + 1); } else { $dateSort[] = $row->{$atts}['list_type'] = mktime(0, 0, 0, date('m', $row->{$atts}['list_type']), date('d', $row->{$atts}['list_type']), date('Y', $connections->options->wpCurrentTime)); } } array_multisort($dateSort, SORT_ASC, $results); $out = ''; // Prints the template's CSS file. if (method_exists($template, 'printCSS')) { $out .= $template->printCSS(); } // Prints the javascript tag in the footer if $template->js path is set if (method_exists($template, 'printJS')) { $template->printJS(); } $out .= '<div class="connections-list cn-upcoming ' . $atts['list_type'] . '">' . "\n"; $out .= '<div class="cn-upcoming-title">' . $list_title . '</div>'; foreach ($results as $row) { $entry = new cnvCard($row); $vCard =& $entry; $entry->name = ''; $alternate == '' ? $alternate = '-alternate' : ($alternate = ''); !$atts['show_lastname'] ? $entry->name = $entry->getFirstName() : ($entry->name = $entry->getFullFirstLastName()); if (isset($template->file)) { $out .= '<div class="cn-upcoming-row' . $alternate . ' vcard ' . $template->slug . '">' . "\n"; ob_start(); include $template->file; $out .= ob_get_contents(); ob_end_clean(); $out .= '</div>' . "\n"; } else { // If no template is found, return an error message. return '<p style="color:red; font-weight:bold; text-align:center;">ERROR: Template "' . $atts['template_name'] . '" not found.</p>'; } } $out .= "</div>\n"; return $out; } }
/** * @access public * @since unknown * * @param cnTemplate $template */ public function __construct($template) { $this->template = $template; $template->part(array('tag' => 'card', 'type' => 'action', 'callback' => array(__CLASS__, 'card'))); $template->part(array('tag' => 'css', 'type' => 'action', 'callback' => array($template, 'printCSS'))); }