Exemple #1
0
 /**
  * Outputs the content of the widget.
  * @param $args
  * @param $instance
  */
 function widget($args, $instance)
 {
     extract($args);
     extract($instance);
     // Clean up any whitespace
     $cssid = trim($cssid);
     $description = trim($description);
     $layouthtml = trim($layouthtml);
     // Show widget regardless if there are websites
     echo $before_widget;
     echo $before_title . $title . $after_title;
     // Start the wrapper for the portfolio, using a CSS ID if we have one
     if ($cssid) {
         printf('<div id="%s" class="wp-portfolio-widget">', $cssid);
     } else {
         echo '<div class="wp-portfolio-widget">';
     }
     // Add our optional description
     if ($description) {
         printf('<div class="wp-portfolio-widget-des">%s</div>', $description);
     }
     if (!$layouthtml) {
         $layouthtml = WPP_DEFAULT_WIDGET_TEMPLATE;
     }
     switch ($orderby) {
         case 'normal-asc':
             echo WPPortfolio_getAllPortfolioAsHTML($grouplist, $layouthtml, ' ', false, true, 'normal', $websitecount, true);
             break;
         case 'normal-desc':
             echo WPPortfolio_getAllPortfolioAsHTML($grouplist, $layouthtml, ' ', false, false, 'normal', $websitecount, true);
             break;
         case 'date-desc':
             echo WPPortfolio_getAllPortfolioAsHTML($grouplist, $layouthtml, ' ', false, true, 'dateadded', $websitecount, true);
             break;
         case 'date-asc':
             echo WPPortfolio_getAllPortfolioAsHTML($grouplist, $layouthtml, ' ', false, false, 'dateadded', $websitecount, true);
             break;
         case 'random':
             echo WPPortfolio_getRandomPortfolioSelectionAsHTML($grouplist, $websitecount, $layouthtml, true);
             break;
     }
     // Closing wrapper tag
     echo '</div>';
     // This always needs to go at the end.
     echo $after_widget;
 }
Exemple #2
0
/**
 * Turn the portfolio of websites in the database into a single page containing details and screenshots using the [wp-portfolio] shortcode.
 * @param $atts The attributes of the shortcode.
 * @return String The updated content for the post or page.
 */
function WPPortfolio_convertShortcodeToPortfolio($atts)
{
    // Process the attributes
    extract(shortcode_atts(array('groups' => '', 'hidegroupinfo' => 0, 'sitesperpage' => 0, 'orderby' => 'asc', 'ordertype' => 'normal', 'single' => 0), $atts));
    // Check if single contains a valid item ID
    if (is_numeric($single) && $single > 0) {
        $websiteDetails = WPPortfolio_getWebsiteDetails($single, OBJECT);
        // Portfolio item not found, abort
        if (!$websiteDetails) {
            return sprintf('<p>' . __('Portfolio item <b>ID %d</b> does not exist.', 'wp-portfolio') . '</p>', $single);
        } else {
            return WPPortfolio_renderPortfolio(array($websiteDetails), false, false, false, false);
        }
    }
    // If hidegroupinfo is 1, then hide group details by passing in a blank template to the render portfolio function
    $grouptemplate = false;
    // If false, then default group template is used.
    if (isset($atts['hidegroupinfo']) && $atts['hidegroupinfo'] == 1) {
        $grouptemplate = "&nbsp;";
    }
    // Sort ASC or DESC?
    $orderAscending = true;
    if (isset($atts['orderby']) && strtolower(trim($atts['orderby'])) == 'desc') {
        $orderAscending = false;
    }
    // Convert order type to use normal as default
    $orderType = strtolower(trim(WPPortfolio_getArrayValue($atts, 'ordertype')));
    if ($orderType != 'dateadded') {
        $orderType = 'normal';
    }
    // Groups
    $groups = false;
    if (isset($atts['groups'])) {
        $groups = $atts['groups'];
    }
    // Sites per page
    $sitesperpage = 0;
    if (isset($atts['sitesperpage'])) {
        $sitesperpage = $atts['sitesperpage'] + 0;
    }
    return WPPortfolio_getAllPortfolioAsHTML($groups, false, $grouptemplate, $sitesperpage, $orderAscending, $orderType);
}