<?php
  require("php/common_begin.php");
  
  $lst = Listopia::getInstance();
  // -------------------------------
  if (!$lst->isLoggedIn())
  {
    $lst->unloggedInPage();
    return;
  }
  // -------------------------------


  $userID = (isset($_GET['id']) ? (int)$_GET['id'] : null);
  if (isset($userID))
  {
    $query = $lst->getUserData($userID);
    if (!empty($query[0]))
    {
      $uid = ((int)$userID);
      $userTitle = stripslashes($query[0]['users']['user_name']);
    }
  }
  else if ($lst->isLoggedIn())
  {
    $uid = Session::getInstance()->gl_userid;
    $userTitle = Session::getInstance()->gl_username;
  }
  else
  {
    $uid = 0;
    $userTitle = "Nobody";
  }
    

  $lst->pageBegin(LS_ACFEED_DOCUMENT_TITLE, "Ego Ergo Dix", array("js/listopia-lists.js"));
  
  $sidebar = array(
    SideBarItem::BasicListNavigator,
    SideBarItem::Profile);
 
  $lst->contentsBeginWithSidebar($sidebar, LS_ACFEED_TITLE . " (" . $userTitle . ")", LS_ACFEED_DESC);

  if ($lst->isLoggedIn())
  {  
    // ---------------------------------------------------------------------------------------------
    $lst->UI_Misc()->openGenericBlock("Recent Comments On Your Posts");
    {
      $listsCounter = array();
      $postToDisplay = array();
      $listOrder = array();
      
      $query = $lst->Database()->select(array(
                          'fields'    => '*',
                          'table'     => 't_discussion',
                          'join'      => 't_items on t_items.item_id = t_discussion.disc_item join t_lists on t_lists.list_id = t_items.item_list',
                          'condition' => 'item_createdby = ' . $uid,

                          'order'     => 't_discussion.disc_datetime desc',
                          'limit'     => 50
                          ));
      if (!empty($query[0]))
      {
        foreach ($query as &$thePost)
        {
          $posterProfileLink = ProfileLink($thePost['t_discussion']['disc_user'], '#PageContent');
        
          $content = ConditionCommentForDisplay($lst->Database(), $thePost['t_discussion']['disc_comment']);
          printf("<p>&quot;%s&quot;</p> <div style='float:none' class='lst-post-author'><a $posterProfileLink >- {$thePost['t_discussion']['disc_username']}</a></div><br>", $content);
        
          if ($thePost['t_items']['item_extra'] != 'image')
            $itemBlurb = Truncate(stripslashes($thePost['t_items']['item_blurb']), 60);
          else
            $itemBlurb = "[image]";
            
          printf("<p style='text-align:right; font-size:0.9em; border-bottom: 1px solid #f0f0f0; margin-bottom:1.5em; padding-bottom:1.5em'><a %s>%s</a> on <strong><a %s>%s</a></strong></p>", 
            ListLink($thePost['t_items']['item_list'], "#entry_" . $thePost['t_items']['item_id']), 
            $itemBlurb,
            ListLink($thePost['t_items']['item_list'], "#PageContent"), 
            stripslashes($thePost['t_lists']['list_headline']));
                    
        }
      }
    }
    $lst->UI_Misc()->closeGenericBlock();    
 
  }
  else
  {
    $lst->UI_Misc()->AddCenteredMessageBlock(LS_NEWSTUFF_WHEN_LOGGEDOUT);
  }
  
  $lst->contentsEnd();

  $lst->UI_Login()->GenLoginDialog();
  
  // default script loading
  $lst->pageEndScripts();
  
  $lst->UI_Login()->GenLoginScripting();
?>

<!-- Local JS -->
<script type="text/javascript">
</script>

<?php
  $lst->pageEnd();

  require("php/common_end.php");
?>
