Exemplo n.º 1
0
 /**
  * Display the widget!
  *
  * @param array MUST contain at least the basic display params
  */
 function display($params)
 {
     /**
      * @var Blog
      */
     global $Blog;
     global $disp;
     $this->init_display($params);
     // Default link class
     $link_class = $this->disp_params['link_default_class'];
     $blog_ID = intval($this->disp_params['blog_ID']);
     if ($blog_ID > 0) {
         // Try to use blog from widget setting
         $BlogCache =& get_BlogCache();
         $current_Blog =& $BlogCache->get_by_ID($blog_ID, false, false);
     }
     if (empty($current_Blog)) {
         // Blog is not defined in setting or it doesn't exist in DB
         // Use current blog
         $current_Blog =& $Blog;
     }
     if (empty($current_Blog)) {
         // We cannot use this widget without a current collection:
         return false;
     }
     switch ($this->disp_params['link_type']) {
         case 'recentposts':
             $url = $current_Blog->get('recentpostsurl');
             if (is_same_url($url, $Blog->get('url'))) {
                 // This menu item has the same url as front page of blog
                 $EnabledWidgetCache =& get_EnabledWidgetCache();
                 $Widget_array =& $EnabledWidgetCache->get_by_coll_container($current_Blog->ID, NT_('Menu'));
                 if (!empty($Widget_array)) {
                     foreach ($Widget_array as $Widget) {
                         $Widget->init_display($params);
                         if (isset($Widget->param_array, $Widget->param_array['link_type']) && $Widget->param_array['link_type'] == 'home') {
                             // Don't display this menu if 'Blog home' menu item exists with the same url
                             return false;
                         }
                     }
                 }
             }
             $text = T_('Recently');
             if ($disp == 'posts') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'search':
             $url = $current_Blog->get('searchurl');
             $text = T_('Search');
             // Is this the current display?
             if ($disp == 'search') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'arcdir':
             $url = $current_Blog->get('arcdirurl');
             $text = T_('Archives');
             if ($disp == 'arcdir') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'catdir':
             $url = $current_Blog->get('catdirurl');
             $text = T_('Categories');
             if ($disp == 'catdir') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'tags':
             $url = $current_Blog->get('tagsurl');
             $text = T_('Tags');
             if ($disp == 'tags') {
                 // Let's display the link as selected:
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'postidx':
             $url = $current_Blog->get('postidxurl');
             $text = T_('Post index');
             if ($disp == 'postidx') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'mediaidx':
             $url = $current_Blog->get('mediaidxurl');
             $text = T_('Photo index');
             if ($disp == 'mediaidx') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'sitemap':
             $url = $current_Blog->get('sitemapurl');
             $text = T_('Site map');
             if ($disp == 'sitemap') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'latestcomments':
             if (!$current_Blog->get_setting('comments_latest')) {
                 // This page is disabled
                 return false;
             }
             $url = $current_Blog->get('lastcommentsurl');
             $text = T_('Latest comments');
             if ($disp == 'comments') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'owneruserinfo':
             $url = url_add_param($current_Blog->get('userurl'), 'user_ID=' . $current_Blog->owner_user_ID);
             $text = T_('Owner details');
             // Is this the current display?
             global $User;
             if ($disp == 'user' && !empty($User) && $User->ID == $current_Blog->owner_user_ID) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'ownercontact':
             if (!($url = $current_Blog->get_contact_url(true))) {
                 // user does not allow contact form:
                 return;
             }
             $text = T_('Contact');
             // Is this the current display?
             if ($disp == 'msgform' || isset($_GET['disp']) && $_GET['disp'] == 'msgform') {
                 // Let's display the link as selected
                 // fp> I think it's interesting to select this link , even if the recipient ID is different from the owner
                 // odds are there is no other link to highlight in this case
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'login':
             if (is_logged_in()) {
                 // Don't display this link for already logged in users
                 return false;
             }
             global $Settings;
             $url = get_login_url('menu link', $Settings->get('redirect_to_after_login'), false, $current_Blog->ID);
             if (isset($this->BlockCache)) {
                 // Do NOT cache because some of these links are using a redirect_to param, which makes it page dependent.
                 // so this will be cached by the PageCache; there is no added benefit to cache it in the BlockCache
                 // (which could have been shared between several pages):
                 $this->BlockCache->abort_collect();
             }
             $text = T_('Log in');
             // Is this the current display?
             if ($disp == 'login') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'logout':
             if (!is_logged_in()) {
                 return false;
             }
             $url = get_user_logout_url($current_Blog->ID);
             $text = T_('Log out');
             break;
         case 'register':
             if (!($url = get_user_register_url(NULL, 'menu link', false, '&', $current_Blog->ID))) {
                 return false;
             }
             if (isset($this->BlockCache)) {
                 // Do NOT cache because some of these links are using a redirect_to param, which makes it page dependent.
                 // Note: also beware of the source param.
                 // so this will be cached by the PageCache; there is no added benefit to cache it in the BlockCache
                 // (which could have been shared between several pages):
                 $this->BlockCache->abort_collect();
             }
             $text = T_('Register');
             // Is this the current display?
             if ($disp == 'register') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'profile':
             if (!is_logged_in()) {
                 return false;
             }
             $url = get_user_profile_url($current_Blog->ID);
             $text = T_('Edit profile');
             // Is this the current display?  (Edit my Profile)
             if (in_array($disp, array('profile', 'avatar', 'pwdchange', 'userprefs', 'subs'))) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'avatar':
             if (!is_logged_in()) {
                 return false;
             }
             $url = get_user_avatar_url($current_Blog->ID);
             $text = T_('Profile picture');
             // Note: we never highlight this, it will always highlight 'profile' instead
             break;
         case 'users':
             global $Settings;
             if (!is_logged_in() && !$Settings->get('allow_anonymous_user_list')) {
                 // Don't allow anonymous users to see users list
                 return false;
             }
             $url = $current_Blog->get('usersurl');
             $text = T_('User directory');
             // Is this the current display?
             // Note: If $user_ID is not set, it means we are viewing "My Profile" instead
             global $user_ID;
             if ($disp == 'users' || $disp == 'user' && !empty($user_ID)) {
                 // Let's display the link as selected
                 // Note: we also highlight this for any user profile that is displayed
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'item':
             $ItemCache =& get_ItemCache();
             /**
              * @var Item
              */
             $item_ID = intval($this->disp_params['item_ID']);
             $disp_Item =& $ItemCache->get_by_ID($item_ID, false, false);
             if (empty($disp_Item)) {
                 // Item not found
                 return false;
             }
             $url = $disp_Item->get_permanent_url();
             $text = $disp_Item->title;
             // Is this the current item?
             global $Item;
             if (!empty($Item) && $disp_Item->ID == $Item->ID) {
                 // The current page is currently displaying the Item this link is pointing to
                 // Let's display it as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'url':
             if (empty($this->disp_params['link_href'])) {
                 // Don't display a link if url is empty
                 return false;
             }
             $url = $this->disp_params['link_href'];
             $text = '[URL]';
             // should normally be overriden below...
             // Note: we never highlight this link
             break;
         case 'postnew':
             if (!check_item_perm_create()) {
                 // Don't allow users to create a new post
                 return false;
             }
             $url = url_add_param($current_Blog->get('url'), 'disp=edit');
             $text = T_('Write a new post');
             // Is this the current display?
             if ($disp == 'edit') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'myprofile':
             if (!is_logged_in()) {
                 // Don't show this link for not logged in users
                 return false;
             }
             $url = $current_Blog->get('userurl');
             $text = T_('My profile');
             // Is this the current display?  (Edit my Profile)
             global $user_ID, $current_User;
             // If $user_ID is not set, it means we will fall back to the current user, so it's ok
             // If $user_ID is set, it means we are browsing the directory instead
             if ($disp == 'user' && empty($user_ID)) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'admin':
             global $current_User;
             if (!(is_logged_in() && $current_User->check_perm('admin', 'restricted') && $current_User->check_status('can_access_admin'))) {
                 // Don't allow admin url for users who have no access to backoffice
                 return false;
             }
             global $admin_url;
             $url = $admin_url;
             $text = T_('Admin') . ' »';
             break;
         case 'home':
         default:
             $url = $current_Blog->get('url');
             $text = T_('Front Page');
             global $is_front;
             if ($disp == 'front' || !empty($is_front)) {
                 // Let's display the link as selected on front page
                 $link_class = $this->disp_params['link_selected_class'];
             }
     }
     // Override default link text?
     if (!empty($this->param_array['link_text'])) {
         // We have a custom link text:
         $text = $this->param_array['link_text'];
     }
     echo $this->disp_params['block_start'];
     echo $this->disp_params['block_body_start'];
     echo $this->disp_params['list_start'];
     if ($link_class == $this->disp_params['link_selected_class']) {
         echo $this->disp_params['item_selected_start'];
     } else {
         echo $this->disp_params['item_start'];
     }
     echo '<a href="' . $url . '" class="' . $link_class . '">' . $text . '</a>';
     if ($link_class == $this->disp_params['link_selected_class']) {
         echo $this->disp_params['item_selected_end'];
     } else {
         echo $this->disp_params['item_end'];
     }
     echo $this->disp_params['list_end'];
     echo $this->disp_params['block_body_end'];
     echo $this->disp_params['block_end'];
     return true;
 }
Exemplo n.º 2
0
/**
 * Initialize blog enabled widgets. It will call every enabled widget request_required_files() function.
 *
 * @param integer blog ID
 */
function init_blog_widgets($blog_id)
{
    /**
     * @var EnabledWidgetCache
     */
    $EnabledWidgetCache =& get_EnabledWidgetCache();
    $container_Widget_array =& $EnabledWidgetCache->get_by_coll_ID($blog_id);
    if (!empty($container_Widget_array)) {
        foreach ($container_Widget_array as $container => $Widget_array) {
            foreach ($Widget_array as $ComponentWidget) {
                // Let the Widget initialize itself:
                $ComponentWidget->request_required_files();
            }
        }
    }
}
Exemplo n.º 3
0
 /**
  * Display a container
  *
  * @todo fp> if it doesn't get any skin specific, move it outta here! :P
  * fp> Do we need Skin objects in the frontoffice at all? -- Do we want to include the dispatcher into the Skin object? WARNING: globals
  * fp> We might want to customize the container defaults. -- Per blog or per skin?
  *
  * @param string
  * @param array
  */
 function container($sco_name, $params = array())
 {
     /**
      * Blog currently displayed
      * @var Blog
      */
     global $Blog;
     global $admin_url, $rsc_url;
     global $Timer;
     $timer_name = 'skin_container(' . $sco_name . ')';
     $Timer->start($timer_name);
     if (false) {
         // DEBUG:
         echo '<div class="debug_container">';
         echo '<div class="debug_container_name"><span class="debug_container_action"><a href="' . $admin_url . '?ctrl=widgets&amp;blog=' . $Blog->ID . '">Edit</a></span>' . $sco_name . '</div>';
     }
     /**
      * @var EnabledWidgetCache
      */
     $EnabledWidgetCache =& get_EnabledWidgetCache();
     $Widget_array =& $EnabledWidgetCache->get_by_coll_container($Blog->ID, $sco_name);
     if (!empty($Widget_array)) {
         foreach ($Widget_array as $ComponentWidget) {
             // Let the Widget display itself (with contextual params):
             $widget_timer_name = 'Widget->display(' . $ComponentWidget->code . ')';
             $Timer->start($widget_timer_name);
             $ComponentWidget->display_with_cache($params, array());
             $Timer->pause($widget_timer_name);
         }
     }
     if (false) {
         // DEBUG:
         echo get_icon('pixel', 'imgtag', array('class' => 'clear'));
         echo '</div>';
     }
     $Timer->pause($timer_name);
 }
Exemplo n.º 4
0
 /**
  * Display a container
  *
  * @todo fp> if it doesn't get any skin specific, move it outta here! :P
  * fp> Do we need Skin objects in the frontoffice at all? -- Do we want to include the dispatcher into the Skin object? WARNING: globals
  * fp> We might want to customize the container defaults. -- Per blog or per skin?
  *
  * @param string
  * @param array
  */
 function container($sco_name, $params = array())
 {
     /**
      * Blog currently displayed
      * @var Blog
      */
     global $Blog;
     global $admin_url, $rsc_url;
     global $Timer, $Session;
     $timer_name = 'skin_container(' . $sco_name . ')';
     $Timer->start($timer_name);
     $display_containers = $Session->get('display_containers_' . $Blog->ID) == 1;
     if ($display_containers) {
         // Wrap container in visible container:
         echo '<div class="dev-blocks dev-blocks--container">';
         echo '<div class="dev-blocks-name"><span class="dev-blocks-action"><a href="' . $admin_url . '?ctrl=widgets&amp;blog=' . $Blog->ID . '">Edit</a></span>Container: <b>' . $sco_name . '</b></div>';
     }
     /**
      * @var EnabledWidgetCache
      */
     $EnabledWidgetCache =& get_EnabledWidgetCache();
     $Widget_array =& $EnabledWidgetCache->get_by_coll_container($Blog->ID, $sco_name);
     if (!empty($Widget_array)) {
         foreach ($Widget_array as $w => $ComponentWidget) {
             // Let the Widget display itself (with contextual params):
             if ($w == 0) {
                 // Use special params for first widget in the current container
                 $orig_params = $params;
                 if (isset($params['block_first_title_start'])) {
                     $params['block_title_start'] = $params['block_first_title_start'];
                 }
                 if (isset($params['block_first_title_end'])) {
                     $params['block_title_end'] = $params['block_first_title_end'];
                 }
             }
             $widget_timer_name = 'Widget->display(' . $ComponentWidget->code . ')';
             $Timer->start($widget_timer_name);
             $ComponentWidget->display_with_cache($params, array());
             if ($w == 0) {
                 // Restore the params for next widgets after first
                 $params = $orig_params;
                 unset($orig_params);
             }
             $Timer->pause($widget_timer_name);
         }
     }
     if ($display_containers) {
         // End of visible container:
         //echo get_icon( 'pixel', 'imgtag', array( 'class' => 'clear' ) );
         echo '</div>';
     }
     $Timer->pause($timer_name);
 }