function WriteDiscussion($Discussion, &$Sender, &$Session, $Alt) {
   $CssClass = 'Item';
   $CssClass .= $Discussion->Bookmarked == '1' ? ' Bookmarked' : '';
   $CssClass .= $Alt.' ';
   $CssClass .= $Discussion->Announce == '1' ? ' Announcement' : '';
   $CssClass .= $Discussion->Closed == '1' ? ' Closed' : '';
   $CssClass .= $Discussion->InsertUserID == $Session->UserID ? ' Mine' : '';
   $CssClass .= ($Discussion->CountUnreadComments > 0 && $Session->IsValid()) ? ' New' : '';
   $Sender->EventArguments['Discussion'] = &$Discussion;
   $Sender->FireEvent('BeforeDiscussionName');
   
   $DiscussionName = Gdn_Format::Text($Discussion->Name);
   if ($DiscussionName == '')
      $DiscussionName = T('Blank Discussion Topic');

   static $FirstDiscussion = TRUE;
   if (!$FirstDiscussion)
      $Sender->FireEvent('BetweenDiscussion');
   else
      $FirstDiscussion = FALSE;
?>
<li class="<?php echo $CssClass; ?>">
   <?php
      if ($Discussion->FirstPhoto) {
         $PhotoImage = 'n'.basename($Discussion->FirstPhoto);
         $PhotoUrl = Gdn_Upload::Url(dirname($Discussion->FirstPhoto).'/'.$PhotoImage);
         echo Img($PhotoUrl, array('alt' => $Discussion->FirstName));
		}
   ?>
   <div class="ItemContent Discussion">
      <?php echo Anchor($DiscussionName, '/discussion/'.$Discussion->DiscussionID.'/'.Gdn_Format::Url($Discussion->Name).($Discussion->CountCommentWatch > 0 && C('Vanilla.Comments.AutoOffset') ? '/#Item_'.$Discussion->CountCommentWatch : ''), 'Title'); ?>
      <?php $Sender->FireEvent('AfterDiscussionTitle'); ?>
      <div class="Meta">
         <span class="Author"><?php echo $Discussion->FirstName; ?></span>
         <?php
            echo '<span class="Counts'.($Discussion->CountUnreadComments > 0 ? ' NewCounts' : '').'">'
               .($Discussion->CountUnreadComments > 0 ? $Discussion->CountUnreadComments.'/' : '')
               .$Discussion->CountComments
            .'</span>';
            if ($Discussion->LastCommentID != '')
               echo '<span class="LastCommentBy">'.sprintf(T('Latest %1$s'), $Discussion->LastName).'</span> ';
               
            echo '<span class="LastCommentDate">'.Gdn_Format::Date($Discussion->LastDate).'</span> ';
         ?>
      </div>
   </div>
</li>
<?php
}
    public function DoAttachment($bbcode, $action, $name, $default, $params, $content)
    {
        $Medias = $this->Media();
        $MediaID = $content;
        if (isset($Medias[$MediaID])) {
            $Media = $Medias[$MediaID];
            //         decho($Media, 'Media');
            $Src = htmlspecialchars(Gdn_Upload::Url(GetValue('Path', $Media)));
            $Name = htmlspecialchars(GetValue('Name', $Media));
            if (GetValue('ImageWidth', $Media)) {
                return <<<EOT
<div class="Attachment Image"><img src="{$Src}" alt="{$Name}" /></div>
EOT;
            } else {
                return Anchor($Name, $Src, 'Attachment File');
            }
        }
        return Anchor(T('Attachment not found.'), '#', 'Attachment NotFound');
    }
function MediaThumbnail($Media, $Data = FALSE)
{
    $Media = (array) $Media;
    if (GetValue('ThumbPath', $Media)) {
        $Src = Gdn_Upload::Url(ltrim(GetValue('ThumbPath', $Media), '/'));
    } else {
        $Width = GetValue('ImageWidth', $Media);
        $Height = GetValue('ImageHeight', $Media);
        if (!$Width || !$Height) {
            $Height = MediaModel::ThumbnailHeight();
            if (!$Height) {
                $Height = 100;
            }
            SetValue('ThumbHeight', $Media, $Height);
            return DefaultMediaThumbnail($Media);
        }
        $RequiresThumbnail = FALSE;
        if (MediaModel::ThumbnailHeight() && $Height > MediaModel::ThumbnailHeight()) {
            $RequiresThumbnail = TRUE;
        } elseif (MediaModel::ThumbnailWidth() && $Width > MediaModel::ThumbnailWidth()) {
            $RequiresThumbnail = TRUE;
        }
        $Path = ltrim(GetValue('Path', $Media), '/');
        if ($RequiresThumbnail) {
            $Src = Url('/utility/thumbnail/' . GetValue('MediaID', $Media, 'x') . '/' . $Path, TRUE);
        } else {
            $Src = Gdn_Upload::Url($Path);
        }
    }
    if ($Data) {
        $Result = array('src' => $Src, 'width' => GetValue('ThumbWidth', $Media), 'height' => GetValue('ThumbHeight', $Media));
    } else {
        $Result = Img($Src, array('class' => 'ImageThumbnail', 'width' => GetValue('ThumbWidth', $Media), 'height' => GetValue('ThumbHeight', $Media)));
    }
    return $Result;
}
Beispiel #4
0
?>
</h1>
<?php 
echo $this->Form->Open(array('enctype' => 'multipart/form-data'));
echo $this->Form->Errors();
?>
<ul>
   <li>
      <?php 
echo $this->Form->Label('Banner Title', 'Garden.Title');
echo Wrap(T('The banner title appears on the top-left of every page. If a banner logo is uploaded, it will replace the banner title on user-facing forum pages.'), 'div', array('class' => 'Info'));
echo $this->Form->TextBox('Garden.Title');
?>
   </li>
   <li>
      <?php 
echo $this->Form->Label('Banner Logo', 'Garden.Logo');
$Logo = $this->Data('Logo');
if ($Logo) {
    echo Wrap(Img(Gdn_Upload::Url($Logo)), 'div');
    echo Wrap(Anchor(T('Remove Banner Logo'), '/dashboard/settings/removelogo/' . $Session->TransientKey(), 'SmallButton'), 'div', array('style' => 'padding: 10px 0;'));
    echo Wrap(T('Browse for a new banner logo if you would like to change it:'), 'div', array('class' => 'Info'));
} else {
    echo Wrap(T('The banner logo appears at the top of your forum.'), 'div', array('class' => 'Info'));
}
echo $this->Form->Input('Logo', 'file');
?>
   </li>
</ul>
<?php 
echo $this->Form->Close('Save');
 /**
  * Create or update a comment.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $DiscussionID Unique ID to add the comment to. If blank, this method will throw an error.
  */
 public function Comment($DiscussionID = '')
 {
     // Get $DiscussionID from RequestArgs if valid
     if ($DiscussionID == '' && count($this->RequestArgs)) {
         if (is_numeric($this->RequestArgs[0])) {
             $DiscussionID = $this->RequestArgs[0];
         }
     }
     // If invalid $DiscussionID, get from form.
     $this->Form->SetModel($this->CommentModel);
     $DiscussionID = is_numeric($DiscussionID) ? $DiscussionID : $this->Form->GetFormValue('DiscussionID', 0);
     // Set discussion data
     $this->DiscussionID = $DiscussionID;
     $this->Discussion = $Discussion = $this->DiscussionModel->GetID($DiscussionID);
     // Is this an embedded comment being posted to a discussion that doesn't exist yet?
     $vanilla_type = $this->Form->GetFormValue('vanilla_type', '');
     $vanilla_url = $this->Form->GetFormValue('vanilla_url', '');
     $vanilla_category_id = $this->Form->GetFormValue('vanilla_category_id', '');
     $Attributes = array('ForeignUrl' => $vanilla_url);
     $vanilla_identifier = $this->Form->GetFormValue('vanilla_identifier', '');
     // Only allow vanilla identifiers of 32 chars or less - md5 if larger
     if (strlen($vanilla_identifier) > 32) {
         $Attributes['vanilla_identifier'] = $vanilla_identifier;
         $vanilla_identifier = md5($vanilla_identifier);
     }
     if (!$Discussion && $vanilla_url != '' && $vanilla_identifier != '') {
         $Discussion = $Discussion = $this->DiscussionModel->GetForeignID($vanilla_identifier, $vanilla_type);
         if ($Discussion) {
             $this->DiscussionID = $DiscussionID = $Discussion->DiscussionID;
             $this->Form->SetValue('DiscussionID', $DiscussionID);
         }
     }
     // If so, create it!
     if (!$Discussion && $vanilla_url != '' && $vanilla_identifier != '') {
         // Add these values back to the form if they exist!
         $this->Form->AddHidden('vanilla_identifier', $vanilla_identifier);
         $this->Form->AddHidden('vanilla_type', $vanilla_type);
         $this->Form->AddHidden('vanilla_url', $vanilla_url);
         $this->Form->AddHidden('vanilla_category_id', $vanilla_category_id);
         $PageInfo = FetchPageInfo($vanilla_url);
         if (!($Title = $this->Form->GetFormValue('Name'))) {
             $Title = GetValue('Title', $PageInfo, '');
             if ($Title == '') {
                 $Title = T('Undefined discussion subject.');
             }
         }
         $Description = GetValue('Description', $PageInfo, '');
         $Images = GetValue('Images', $PageInfo, array());
         $LinkText = T('EmbededDiscussionLinkText', 'Read the full story here');
         if (!$Description && count($Images) == 0) {
             $Body = FormatString('<p><a href="{Url}">{LinkText}</a></p>', array('Url' => $vanilla_url, 'LinkText' => $LinkText));
         } else {
             $Body = FormatString('
         <div class="EmbeddedContent">{Image}<strong>{Title}</strong>
            <p>{Excerpt}</p>
            <p><a href="{Url}">{LinkText}</a></p>
            <div class="ClearFix"></div>
         </div>', array('Title' => $Title, 'Excerpt' => $Description, 'Image' => count($Images) > 0 ? Img(GetValue(0, $Images), array('class' => 'LeftAlign')) : '', 'Url' => $vanilla_url, 'LinkText' => $LinkText));
         }
         if ($Body == '') {
             $Body = $vanilla_url;
         }
         if ($Body == '') {
             $Body = T('Undefined discussion body.');
         }
         // Validate the CategoryID for inserting.
         $Category = CategoryModel::Categories($vanilla_category_id);
         if (!$Category) {
             $vanilla_category_id = C('Vanilla.Embed.DefaultCategoryID', 0);
             if ($vanilla_category_id <= 0) {
                 // No default category defined, so grab the first non-root category and use that.
                 $vanilla_category_id = $this->DiscussionModel->SQL->Select('CategoryID')->From('Category')->Where('CategoryID >', 0)->Get()->FirstRow()->CategoryID;
                 // No categories in the db? default to 0
                 if (!$vanilla_category_id) {
                     $vanilla_category_id = 0;
                 }
             }
         } else {
             $vanilla_category_id = $Category['CategoryID'];
         }
         $EmbedUserID = C('Garden.Embed.UserID');
         if ($EmbedUserID) {
             $EmbedUser = Gdn::UserModel()->GetID($EmbedUserID);
         }
         if (!$EmbedUserID || !$EmbedUser) {
             $EmbedUserID = Gdn::UserModel()->GetSystemUserID();
         }
         $EmbeddedDiscussionData = array('InsertUserID' => $EmbedUserID, 'DateInserted' => Gdn_Format::ToDateTime(), 'DateUpdated' => Gdn_Format::ToDateTime(), 'CategoryID' => $vanilla_category_id, 'ForeignID' => $vanilla_identifier, 'Type' => $vanilla_type, 'Name' => $Title, 'Body' => $Body, 'Format' => 'Html', 'Attributes' => serialize($Attributes));
         $this->EventArguments['Discussion'] = $EmbeddedDiscussionData;
         $this->FireEvent('BeforeEmbedDiscussion');
         $DiscussionID = $this->DiscussionModel->SQL->Insert('Discussion', $EmbeddedDiscussionData);
         $ValidationResults = $this->DiscussionModel->ValidationResults();
         if (count($ValidationResults) == 0 && $DiscussionID > 0) {
             $this->Form->AddHidden('DiscussionID', $DiscussionID);
             // Put this in the form so reposts won't cause new discussions.
             $this->Form->SetFormValue('DiscussionID', $DiscussionID);
             // Put this in the form values so it is used when saving comments.
             $this->SetJson('DiscussionID', $DiscussionID);
             $this->Discussion = $Discussion = $this->DiscussionModel->GetID($DiscussionID, DATASET_TYPE_OBJECT, array('Slave' => FALSE));
             // Update the category discussion count
             if ($vanilla_category_id > 0) {
                 $this->DiscussionModel->UpdateDiscussionCount($vanilla_category_id, $DiscussionID);
             }
         }
     }
     // If no discussion was found, error out
     if (!$Discussion) {
         $this->Form->AddError(T('Failed to find discussion for commenting.'));
     }
     $PermissionCategoryID = GetValue('PermissionCategoryID', $Discussion);
     // Setup head
     $this->AddJsFile('jquery.autosize.min.js');
     $this->AddJsFile('post.js');
     $this->AddJsFile('autosave.js');
     // Setup comment model, $CommentID, $DraftID
     $Session = Gdn::Session();
     $CommentID = isset($this->Comment) && property_exists($this->Comment, 'CommentID') ? $this->Comment->CommentID : '';
     $DraftID = isset($this->Comment) && property_exists($this->Comment, 'DraftID') ? $this->Comment->DraftID : '';
     $this->EventArguments['CommentID'] = $CommentID;
     $this->EventArguments['DraftID'] = $DraftID;
     // Determine whether we are editing
     $Editing = $CommentID > 0 || $DraftID > 0;
     $this->EventArguments['Editing'] = $Editing;
     // If closed, cancel & go to discussion
     if ($Discussion && $Discussion->Closed == 1 && !$Editing && !$Session->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $PermissionCategoryID)) {
         Redirect(DiscussionUrl($Discussion));
     }
     // Add hidden IDs to form
     $this->Form->AddHidden('DiscussionID', $DiscussionID);
     $this->Form->AddHidden('CommentID', $CommentID);
     $this->Form->AddHidden('DraftID', $DraftID, TRUE);
     // Check permissions
     if ($Discussion && $Editing) {
         // Permisssion to edit
         if ($this->Comment->InsertUserID != $Session->UserID) {
             $this->Permission('Vanilla.Comments.Edit', TRUE, 'Category', $Discussion->PermissionCategoryID);
         }
         // Make sure that content can (still) be edited.
         $EditContentTimeout = C('Garden.EditContentTimeout', -1);
         $CanEdit = $EditContentTimeout == -1 || strtotime($this->Comment->DateInserted) + $EditContentTimeout > time();
         if (!$CanEdit) {
             $this->Permission('Vanilla.Comments.Edit', TRUE, 'Category', $Discussion->PermissionCategoryID);
         }
         // Make sure only moderators can edit closed things
         if ($Discussion->Closed) {
             $this->Permission('Vanilla.Comments.Edit', TRUE, 'Category', $Discussion->PermissionCategoryID);
         }
         $this->Form->SetFormValue('CommentID', $CommentID);
     } else {
         if ($Discussion) {
             // Permission to add
             $this->Permission('Vanilla.Comments.Add', TRUE, 'Category', $Discussion->PermissionCategoryID);
         }
     }
     if (!$this->Form->IsPostBack()) {
         // Form was validly submitted
         if (isset($this->Comment)) {
             $this->Form->SetData((array) $this->Comment);
         }
     } else {
         // Save as a draft?
         $FormValues = $this->Form->FormValues();
         $FormValues = $this->CommentModel->FilterForm($FormValues);
         if ($DraftID == 0) {
             $DraftID = $this->Form->GetFormValue('DraftID', 0);
         }
         $Type = GetIncomingValue('Type');
         $Draft = $Type == 'Draft';
         $this->EventArguments['Draft'] = $Draft;
         $Preview = $Type == 'Preview';
         if ($Draft) {
             $DraftID = $this->DraftModel->Save($FormValues);
             $this->Form->AddHidden('DraftID', $DraftID, TRUE);
             $this->Form->SetValidationResults($this->DraftModel->ValidationResults());
         } else {
             if (!$Preview) {
                 // Fix an undefined title if we can.
                 if ($this->Form->GetFormValue('Name') && GetValue('Name', $Discussion) == T('Undefined discussion subject.')) {
                     $Set = array('Name' => $this->Form->GetFormValue('Name'));
                     if (isset($vanilla_url) && $vanilla_url && strpos(GetValue('Body', $Discussion), T('Undefined discussion subject.')) !== FALSE) {
                         $LinkText = T('EmbededDiscussionLinkText', 'Read the full story here');
                         $Set['Body'] = FormatString('<p><a href="{Url}">{LinkText}</a></p>', array('Url' => $vanilla_url, 'LinkText' => $LinkText));
                     }
                     $this->DiscussionModel->SetField(GetValue('DiscussionID', $Discussion), $Set);
                 }
                 $Inserted = !$CommentID;
                 $CommentID = $this->CommentModel->Save($FormValues);
                 // The comment is now half-saved.
                 if (is_numeric($CommentID) && $CommentID > 0) {
                     if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
                         $this->CommentModel->Save2($CommentID, $Inserted, TRUE, TRUE);
                     } else {
                         $this->JsonTarget('', Url("/vanilla/post/comment2.json?commentid={$CommentID}&inserted={$Inserted}"), 'Ajax');
                     }
                     // $Discussion = $this->DiscussionModel->GetID($DiscussionID);
                     $Comment = $this->CommentModel->GetID($CommentID, DATASET_TYPE_OBJECT, array('Slave' => FALSE));
                     $this->EventArguments['Discussion'] = $Discussion;
                     $this->EventArguments['Comment'] = $Comment;
                     $this->FireEvent('AfterCommentSave');
                 } elseif ($CommentID === SPAM || $CommentID === UNAPPROVED) {
                     $this->StatusMessage = T('CommentRequiresApprovalStatus', 'Your comment will appear after it is approved.');
                 }
                 $this->Form->SetValidationResults($this->CommentModel->ValidationResults());
                 if ($CommentID > 0 && $DraftID > 0) {
                     $this->DraftModel->Delete($DraftID);
                 }
             }
         }
         // Handle non-ajax requests first:
         if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
             if ($this->Form->ErrorCount() == 0) {
                 // Make sure that this form knows what comment we are editing.
                 if ($CommentID > 0) {
                     $this->Form->AddHidden('CommentID', $CommentID);
                 }
                 // If the comment was not a draft
                 if (!$Draft) {
                     // Redirect to the new comment.
                     if ($CommentID > 0) {
                         Redirect("discussion/comment/{$CommentID}/#Comment_{$CommentID}");
                     } elseif ($CommentID == SPAM) {
                         $this->SetData('DiscussionUrl', DiscussionUrl($Discussion));
                         $this->View = 'Spam';
                     }
                 } elseif ($Preview) {
                     // If this was a preview click, create a comment shell with the values for this comment
                     $this->Comment = new stdClass();
                     $this->Comment->InsertUserID = $Session->User->UserID;
                     $this->Comment->InsertName = $Session->User->Name;
                     $this->Comment->InsertPhoto = $Session->User->Photo;
                     $this->Comment->DateInserted = Gdn_Format::Date();
                     $this->Comment->Body = ArrayValue('Body', $FormValues, '');
                     $this->Comment->Format = GetValue('Format', $FormValues, C('Garden.InputFormatter'));
                     $this->AddAsset('Content', $this->FetchView('preview'));
                 } else {
                     // If this was a draft save, notify the user about the save
                     $this->InformMessage(sprintf(T('Draft saved at %s'), Gdn_Format::Date()));
                 }
             }
         } else {
             // Handle ajax-based requests
             if ($this->Form->ErrorCount() > 0) {
                 // Return the form errors
                 $this->ErrorMessage($this->Form->Errors());
             } else {
                 // Make sure that the ajax request form knows about the newly created comment or draft id
                 $this->SetJson('CommentID', $CommentID);
                 $this->SetJson('DraftID', $DraftID);
                 if ($Preview) {
                     // If this was a preview click, create a comment shell with the values for this comment
                     $this->Comment = new stdClass();
                     $this->Comment->InsertUserID = $Session->User->UserID;
                     $this->Comment->InsertName = $Session->User->Name;
                     $this->Comment->InsertPhoto = $Session->User->Photo;
                     $this->Comment->DateInserted = Gdn_Format::Date();
                     $this->Comment->Body = ArrayValue('Body', $FormValues, '');
                     $this->View = 'preview';
                 } elseif (!$Draft) {
                     // If the comment was not a draft
                     // If Editing a comment
                     if ($Editing) {
                         // Just reload the comment in question
                         $this->Offset = 1;
                         $Comments = $this->CommentModel->GetIDData($CommentID, array('Slave' => FALSE));
                         $this->SetData('Comments', $Comments);
                         $this->SetData('Discussion', $Discussion);
                         // Load the discussion
                         $this->ControllerName = 'discussion';
                         $this->View = 'comments';
                         // Also define the discussion url in case this request came from the post screen and needs to be redirected to the discussion
                         $this->SetJson('DiscussionUrl', DiscussionUrl($this->Discussion) . '#Comment_' . $CommentID);
                     } else {
                         // If the comment model isn't sorted by DateInserted or CommentID then we can't do any fancy loading of comments.
                         $OrderBy = GetValueR('0.0', $this->CommentModel->OrderBy());
                         //                     $Redirect = !in_array($OrderBy, array('c.DateInserted', 'c.CommentID'));
                         //							$DisplayNewCommentOnly = $this->Form->GetFormValue('DisplayNewCommentOnly');
                         //                     if (!$Redirect) {
                         //                        // Otherwise load all new comments that the user hasn't seen yet
                         //                        $LastCommentID = $this->Form->GetFormValue('LastCommentID');
                         //                        if (!is_numeric($LastCommentID))
                         //                           $LastCommentID = $CommentID - 1; // Failsafe back to this new comment if the lastcommentid was not defined properly
                         //
                         //                        // Don't reload the first comment if this new comment is the first one.
                         //                        $this->Offset = $LastCommentID == 0 ? 1 : $this->CommentModel->GetOffset($LastCommentID);
                         //                        // Do not load more than a single page of data...
                         //                        $Limit = C('Vanilla.Comments.PerPage', 30);
                         //
                         //                        // Redirect if the new new comment isn't on the same page.
                         //                        $Redirect |= !$DisplayNewCommentOnly && PageNumber($this->Offset, $Limit) != PageNumber($Discussion->CountComments - 1, $Limit);
                         //                     }
                         //                     if ($Redirect) {
                         //                        // The user posted a comment on a page other than the last one, so just redirect to the last page.
                         //                        $this->RedirectUrl = Gdn::Request()->Url("discussion/comment/$CommentID/#Comment_$CommentID", TRUE);
                         //                     } else {
                         //                        // Make sure to load all new comments since the page was last loaded by this user
                         //								if ($DisplayNewCommentOnly)
                         $this->Offset = $this->CommentModel->GetOffset($CommentID);
                         $Comments = $this->CommentModel->GetIDData($CommentID, array('Slave' => FALSE));
                         $this->SetData('Comments', $Comments);
                         $this->SetData('NewComments', TRUE);
                         $this->ClassName = 'DiscussionController';
                         $this->ControllerName = 'discussion';
                         $this->View = 'comments';
                         //                     }
                         // Make sure to set the user's discussion watch records
                         $CountComments = $this->CommentModel->GetCount($DiscussionID);
                         $Limit = is_object($this->Data('Comments')) ? $this->Data('Comments')->NumRows() : $Discussion->CountComments;
                         $Offset = $CountComments - $Limit;
                         $this->CommentModel->SetWatch($this->Discussion, $Limit, $Offset, $CountComments);
                     }
                 } else {
                     // If this was a draft save, notify the user about the save
                     $this->InformMessage(sprintf(T('Draft saved at %s'), Gdn_Format::Date()));
                 }
                 // And update the draft count
                 $UserModel = Gdn::UserModel();
                 $CountDrafts = $UserModel->GetAttribute($Session->UserID, 'CountDrafts', 0);
                 $this->SetJson('MyDrafts', T('My Drafts'));
                 $this->SetJson('CountDrafts', $CountDrafts);
             }
         }
     }
     // Include data for FireEvent
     if (property_exists($this, 'Discussion')) {
         $this->EventArguments['Discussion'] = $this->Discussion;
     }
     if (property_exists($this, 'Comment')) {
         $this->EventArguments['Comment'] = $this->Comment;
     }
     $this->FireEvent('BeforeCommentRender');
     if ($this->DeliveryType() == DELIVERY_TYPE_DATA) {
         $Comment = $this->Data('Comments')->FirstRow(DATASET_TYPE_ARRAY);
         if ($Comment) {
             $Photo = $Comment['InsertPhoto'];
             if (strpos($Photo, '//') === FALSE) {
                 $Photo = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s'));
             }
             $Comment['InsertPhoto'] = $Photo;
         }
         $this->Data = array('Comment' => $Comment);
         $this->RenderData($this->Data);
     } else {
         require_once $this->FetchViewLocation('helper_functions', 'Discussion');
         // Render default view.
         $this->Render();
     }
 }
 /**
  *
  *
  * @param $Path
  * @param $Controller
  */
 public function init($Path, $Controller)
 {
     $Smarty = $this->smarty();
     // Get a friendly name for the controller.
     $ControllerName = get_class($Controller);
     if (StringEndsWith($ControllerName, 'Controller', true)) {
         $ControllerName = substr($ControllerName, 0, -10);
     }
     // Get an ID for the body.
     $BodyIdentifier = strtolower($Controller->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::alphaNumeric(strtolower($Controller->RequestMethod)));
     $Smarty->assign('BodyID', $BodyIdentifier);
     //$Smarty->assign('Config', Gdn::Config());
     // Assign some information about the user.
     $Session = Gdn::session();
     if ($Session->isValid()) {
         $User = array('Name' => $Session->User->Name, 'Photo' => '', 'CountNotifications' => (int) val('CountNotifications', $Session->User, 0), 'CountUnreadConversations' => (int) val('CountUnreadConversations', $Session->User, 0), 'SignedIn' => true);
         $Photo = $Session->User->Photo;
         if ($Photo) {
             if (!IsUrl($Photo)) {
                 $Photo = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s'));
             }
         } else {
             if (function_exists('UserPhotoDefaultUrl')) {
                 $Photo = UserPhotoDefaultUrl($Session->User, 'ProfilePhoto');
             } elseif ($ConfigPhoto = C('Garden.DefaultAvatar')) {
                 $Photo = Gdn_Upload::url($ConfigPhoto);
             } else {
                 $Photo = Asset('/applications/dashboard/design/images/defaulticon.png', true);
             }
         }
         $User['Photo'] = $Photo;
     } else {
         $User = false;
         /*array(
           'Name' => '',
           'CountNotifications' => 0,
           'SignedIn' => FALSE);*/
     }
     $Smarty->assign('User', $User);
     // Make sure that any datasets use arrays instead of objects.
     foreach ($Controller->Data as $Key => $Value) {
         if ($Value instanceof Gdn_DataSet) {
             $Controller->Data[$Key] = $Value->resultArray();
         } elseif ($Value instanceof stdClass) {
             $Controller->Data[$Key] = (array) $Value;
         }
     }
     $BodyClass = val('CssClass', $Controller->Data, '', true);
     $Sections = Gdn_Theme::section(null, 'get');
     if (is_array($Sections)) {
         foreach ($Sections as $Section) {
             $BodyClass .= ' Section-' . $Section;
         }
     }
     $Controller->Data['BodyClass'] = $BodyClass;
     // Set the current locale for themes to take advantage of.
     $Locale = Gdn::locale()->Locale;
     $CurrentLocale = array('Key' => $Locale, 'Lang' => str_replace('_', '-', $Locale));
     if (class_exists('Locale')) {
         $CurrentLocale['Language'] = Locale::getPrimaryLanguage($Locale);
         $CurrentLocale['Region'] = Locale::getRegion($Locale);
         $CurrentLocale['DisplayName'] = Locale::getDisplayName($Locale, $Locale);
         $CurrentLocale['DisplayLanguage'] = Locale::getDisplayLanguage($Locale, $Locale);
         $CurrentLocale['DisplayRegion'] = Locale::getDisplayRegion($Locale, $Locale);
     }
     $Smarty->assign('CurrentLocale', $CurrentLocale);
     $Smarty->assign('Assets', (array) $Controller->Assets);
     $Smarty->assign('Path', Gdn::request()->path());
     // Assign the controller data last so the controllers override any default data.
     $Smarty->assign($Controller->Data);
     $Smarty->Controller = $Controller;
     // for smarty plugins
     $Smarty->security = true;
     $Smarty->security_settings['IF_FUNCS'] = array_merge($Smarty->security_settings['IF_FUNCS'], array('Category', 'CheckPermission', 'InSection', 'InCategory', 'MultiCheckPermission', 'GetValue', 'SetValue', 'Url'));
     $Smarty->security_settings['MODIFIER_FUNCS'] = array_merge($Smarty->security_settings['MODIFIER_FUNCS'], array('sprintf'));
     $Smarty->secure_dir = array($Path);
 }
 /**
  * Get path to icon.
  *
  * @return string Path to icon
  */
 public function getIconUrl()
 {
     $Icon = C('Garden.TouchIcon') ? Gdn_Upload::Url(C('Garden.TouchIcon')) : Asset(self::DEFAULT_PATH);
     return $Icon;
 }
Beispiel #8
0
echo Wrap(T('LogoDescription', 'The banner logo appears at the top of your site. Some themes may not display this logo.'), 'div', array('class' => 'Info'));
$Logo = $this->Data('Logo');
if ($Logo) {
    echo Wrap(Img(Gdn_Upload::Url($Logo)), 'div');
    echo Wrap(Anchor(T('Remove Banner Logo'), '/dashboard/settings/removelogo/' . $Session->TransientKey(), 'SmallButton'), 'div', array('style' => 'padding: 10px 0;'));
    echo Wrap(T('LogoBrowse', 'Browse for a new banner logo if you would like to change it:'), 'div', array('class' => 'Info'));
}
echo $this->Form->Input('Logo', 'file');
?>
         </li>
         <li>
            <?php 
echo $this->Form->Label('Favicon', 'Favicon');
echo Wrap(T('FaviconDescription', "Your site's favicon appears in your browser's title bar. It will be scaled to 16x16 pixels."), 'div', array('class' => 'Info'));
$Favicon = $this->Data('Favicon');
if ($Favicon) {
    echo Wrap(Img(Gdn_Upload::Url($Favicon)), 'div');
    echo Wrap(Anchor(T('Remove Favicon'), '/dashboard/settings/removefavicon/' . $Session->TransientKey(), 'SmallButton'), 'div', array('style' => 'padding: 10px 0;'));
    echo Wrap(T('FaviconBrowse', 'Browse for a new favicon if you would like to change it:'), 'div', array('class' => 'Info'));
} else {
    echo Wrap(T('FaviconDescription', "The shortcut icon that shows up in your browser's bookmark menu (16x16 px)."), 'div', array('class' => 'Info'));
}
echo $this->Form->Input('Favicon', 'file');
?>
         </li>
      </ul>
   </div>
</div>
<?php 
echo '<div class="Buttons">' . $this->Form->Button('Save') . '</div>';
echo $this->Form->Close();
 /**
  * Add UserCategory modifiers
  *
  * Update &$Categories in memory by applying modifiers from UserCategory for
  * the currently logged-in user.
  *
  * @since 2.0.18
  * @access public
  * @param array &$Categories
  * @param bool $AddUserCategory
  */
 public static function JoinUserData(&$Categories, $AddUserCategory = TRUE)
 {
     $IDs = array_keys($Categories);
     $DoHeadings = C('Vanilla.Categories.DoHeadings');
     if ($AddUserCategory) {
         $SQL = clone Gdn::SQL();
         $SQL->Reset();
         if (Gdn::Session()->UserID) {
             $Key = 'UserCategory_' . Gdn::Session()->UserID;
             $UserData = Gdn::Cache()->Get($Key);
             if ($UserData === Gdn_Cache::CACHEOP_FAILURE) {
                 $UserData = $SQL->GetWhere('UserCategory', array('UserID' => Gdn::Session()->UserID))->ResultArray();
                 $UserData = Gdn_DataSet::Index($UserData, 'CategoryID');
                 Gdn::Cache()->Store($Key, $UserData);
             }
         } else {
             $UserData = array();
         }
         //         Gdn::Controller()->SetData('UserData', $UserData);
         foreach ($IDs as $ID) {
             $Category = $Categories[$ID];
             $DateMarkedRead = GetValue('DateMarkedRead', $Category);
             $Row = GetValue($ID, $UserData);
             if ($Row) {
                 $UserDateMarkedRead = $Row['DateMarkedRead'];
                 if (!$DateMarkedRead || $UserDateMarkedRead && Gdn_Format::ToTimestamp($UserDateMarkedRead) > Gdn_Format::ToTimestamp($DateMarkedRead)) {
                     $Categories[$ID]['DateMarkedRead'] = $UserDateMarkedRead;
                     $DateMarkedRead = $UserDateMarkedRead;
                 }
                 $Categories[$ID]['Unfollow'] = $Row['Unfollow'];
             } else {
                 $Categories[$ID]['Unfollow'] = FALSE;
             }
             // Calculate the following field.
             $Following = !((bool) GetValue('Archived', $Category) || (bool) GetValue('Unfollow', $Row, FALSE));
             $Categories[$ID]['Following'] = $Following;
             // Calculate the read field.
             if ($DoHeadings && $Category['Depth'] <= 1) {
                 $Categories[$ID]['Read'] = FALSE;
             } elseif ($DateMarkedRead) {
                 if (GetValue('LastDateInserted', $Category)) {
                     $Categories[$ID]['Read'] = Gdn_Format::ToTimestamp($DateMarkedRead) >= Gdn_Format::ToTimestamp($Category['LastDateInserted']);
                 } else {
                     $Categories[$ID]['Read'] = TRUE;
                 }
             } else {
                 $Categories[$ID]['Read'] = FALSE;
             }
         }
     }
     // Add permissions.
     $Session = Gdn::Session();
     foreach ($IDs as $CID) {
         $Category = $Categories[$CID];
         $Categories[$CID]['Url'] = Url($Category['Url'], '//');
         if ($Photo = val('Photo', $Category)) {
             $Categories[$CID]['PhotoUrl'] = Gdn_Upload::Url($Photo);
         }
         if ($Category['LastUrl']) {
             $Categories[$CID]['LastUrl'] = Url($Category['LastUrl'], '//');
         }
         $Categories[$CID]['PermsDiscussionsView'] = $Session->CheckPermission('Vanilla.Discussions.View', TRUE, 'Category', $Category['PermissionCategoryID']);
         $Categories[$CID]['PermsDiscussionsAdd'] = $Session->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', $Category['PermissionCategoryID']);
         $Categories[$CID]['PermsDiscussionsEdit'] = $Session->CheckPermission('Vanilla.Discussions.Edit', TRUE, 'Category', $Category['PermissionCategoryID']);
         $Categories[$CID]['PermsCommentsAdd'] = $Session->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $Category['PermissionCategoryID']);
     }
 }
 /**
  * Undocumented method.
  *
  * @todo Method RenderMaster() needs a description.
  */
 public function RenderMaster()
 {
     // Build the master view if necessary
     if (in_array($this->_DeliveryType, array(DELIVERY_TYPE_ALL))) {
         $this->MasterView = $this->MasterView();
         // Only get css & ui components if this is NOT a syndication request
         if ($this->SyndicationMethod == SYNDICATION_NONE && is_object($this->Head)) {
             //            if (ArrayHasValue($this->_CssFiles, 'style.css')) {
             //               $this->AddCssFile('custom.css');
             //
             //               // Add the theme option's css file.
             //               if ($this->Theme && $this->ThemeOptions) {
             //                  $Filenames = GetValueR('Styles.Value', $this->ThemeOptions);
             //                  if (is_string($Filenames) && $Filenames != '%s')
             //                     $this->_CssFiles[] = array('FileName' => ChangeBasename('custom.css', $Filenames), 'AppFolder' => FALSE, 'Options' => FALSE);
             //               }
             //            } elseif (ArrayHasValue($this->_CssFiles, 'admin.css')) {
             //               $this->AddCssFile('customadmin.css');
             //            }
             $this->EventArguments['CssFiles'] =& $this->_CssFiles;
             $this->FireEvent('BeforeAddCss');
             $ETag = AssetModel::ETag();
             $CombineAssets = C('Garden.CombineAssets');
             $ThemeType = IsMobile() ? 'mobile' : 'desktop';
             // And now search for/add all css files.
             foreach ($this->_CssFiles as $CssInfo) {
                 $CssFile = $CssInfo['FileName'];
                 // style.css and admin.css deserve some custom processing.
                 if (in_array($CssFile, array('style.css', 'admin.css'))) {
                     if (!$CombineAssets) {
                         // Grab all of the css files from the asset model.
                         $AssetModel = new AssetModel();
                         $CssFiles = $AssetModel->GetCssFiles($ThemeType, ucfirst(substr($CssFile, 0, -4)), $ETag);
                         foreach ($CssFiles as $Info) {
                             $this->Head->AddCss($Info[1], 'all', TRUE, $CssInfo);
                         }
                     } else {
                         $Basename = substr($CssFile, 0, -4);
                         $this->Head->AddCss(Url("/utility/css/{$ThemeType}/{$Basename}-{$ETag}.css", '//'), 'all', FALSE, $CssInfo['Options']);
                     }
                     continue;
                 }
                 if (StringBeginsWith($CssFile, 'http')) {
                     $this->Head->AddCss($CssFile, 'all', GetValue('AddVersion', $CssInfo, TRUE), $CssInfo['Options']);
                     continue;
                 } elseif (strpos($CssFile, '/') !== FALSE) {
                     // A direct path to the file was given.
                     $CssPaths = array(CombinePaths(array(PATH_ROOT, str_replace('/', DS, $CssFile))));
                 } else {
                     //                  $CssGlob = preg_replace('/(.*)(\.css)/', '\1*\2', $CssFile);
                     $AppFolder = $CssInfo['AppFolder'];
                     if ($AppFolder == '') {
                         $AppFolder = $this->ApplicationFolder;
                     }
                     // CSS comes from one of four places:
                     $CssPaths = array();
                     if ($this->Theme) {
                         // Use the default filename.
                         $CssPaths[] = PATH_THEMES . DS . $this->Theme . DS . 'design' . DS . $CssFile;
                     }
                     // 3. Application or plugin.
                     if (StringBeginsWith($AppFolder, 'plugins/')) {
                         // The css is coming from a plugin.
                         $AppFolder = substr($AppFolder, strlen('plugins/'));
                         $CssPaths[] = PATH_PLUGINS . "/{$AppFolder}/design/{$CssFile}";
                         $CssPaths[] = PATH_PLUGINS . "/{$AppFolder}/{$CssFile}";
                     } elseif (in_array($AppFolder, array('static', 'resources'))) {
                         // This is a static css file.
                         $CssPaths[] = PATH_ROOT . "/resources/css/{$CssFile}";
                     } else {
                         // Application default. eg. root/applications/app_name/design/
                         $CssPaths[] = PATH_APPLICATIONS . DS . $AppFolder . DS . 'design' . DS . $CssFile;
                     }
                     // 4. Garden default. eg. root/applications/dashboard/design/
                     $CssPaths[] = PATH_APPLICATIONS . DS . 'dashboard' . DS . 'design' . DS . $CssFile;
                 }
                 // Find the first file that matches the path.
                 $CssPath = FALSE;
                 foreach ($CssPaths as $Glob) {
                     $Paths = SafeGlob($Glob);
                     if (is_array($Paths) && count($Paths) > 0) {
                         $CssPath = $Paths[0];
                         break;
                     }
                 }
                 // Check to see if there is a CSS cacher.
                 $CssCacher = Gdn::Factory('CssCacher');
                 if (!is_null($CssCacher)) {
                     $CssPath = $CssCacher->Get($CssPath, $AppFolder);
                 }
                 if ($CssPath !== FALSE) {
                     $CssPath = substr($CssPath, strlen(PATH_ROOT));
                     $CssPath = str_replace(DS, '/', $CssPath);
                     $this->Head->AddCss($CssPath, 'all', TRUE, $CssInfo['Options']);
                 }
             }
             // Add a custom js file.
             if (ArrayHasValue($this->_CssFiles, 'style.css')) {
                 $this->AddJsFile('custom.js');
             }
             // only to non-admin pages.
             // And now search for/add all JS files.
             $Cdns = array();
             if (Gdn::Request()->Scheme() != 'https' && !C('Garden.Cdns.Disable', FALSE)) {
                 $Cdns = array('jquery.js' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js');
             }
             $this->EventArguments['Cdns'] =& $Cdns;
             $this->FireEvent('AfterJsCdns');
             foreach ($this->_JsFiles as $Index => $JsInfo) {
                 $JsFile = $JsInfo['FileName'];
                 if (isset($Cdns[$JsFile])) {
                     $JsFile = $Cdns[$JsFile];
                 }
                 if (strpos($JsFile, '//') !== FALSE) {
                     // This is a link to an external file.
                     $this->Head->AddScript($JsFile, 'text/javascript', GetValue('Options', $JsInfo, array()));
                     continue;
                 } elseif (strpos($JsFile, '/') !== FALSE) {
                     // A direct path to the file was given.
                     $JsPaths = array(CombinePaths(array(PATH_ROOT, str_replace('/', DS, $JsFile)), DS));
                 } else {
                     $AppFolder = $JsInfo['AppFolder'];
                     if ($AppFolder == '') {
                         $AppFolder = $this->ApplicationFolder;
                     }
                     // JS can come from a theme, an any of the application folder, or it can come from the global js folder:
                     $JsPaths = array();
                     if ($this->Theme) {
                         // 1. Application-specific js. eg. root/themes/theme_name/app_name/design/
                         $JsPaths[] = PATH_THEMES . DS . $this->Theme . DS . $AppFolder . DS . 'js' . DS . $JsFile;
                         // 2. Garden-wide theme view. eg. root/themes/theme_name/design/
                         $JsPaths[] = PATH_THEMES . DS . $this->Theme . DS . 'js' . DS . $JsFile;
                     }
                     // 3. The application or plugin folder.
                     if (StringBeginsWith(trim($AppFolder, '/'), 'plugins/')) {
                         $JsPaths[] = PATH_PLUGINS . strstr($AppFolder, '/') . "/js/{$JsFile}";
                         $JsPaths[] = PATH_PLUGINS . strstr($AppFolder, '/') . "/{$JsFile}";
                     } else {
                         $JsPaths[] = PATH_APPLICATIONS . "/{$AppFolder}/js/{$JsFile}";
                     }
                     // 4. Global JS folder. eg. root/js/
                     $JsPaths[] = PATH_ROOT . DS . 'js' . DS . $JsFile;
                     // 5. Global JS library folder. eg. root/js/library/
                     $JsPaths[] = PATH_ROOT . DS . 'js' . DS . 'library' . DS . $JsFile;
                 }
                 // Find the first file that matches the path.
                 $JsPath = FALSE;
                 foreach ($JsPaths as $Glob) {
                     $Paths = SafeGlob($Glob);
                     if (is_array($Paths) && count($Paths) > 0) {
                         $JsPath = $Paths[0];
                         break;
                     }
                 }
                 if ($JsPath !== FALSE) {
                     $JsSrc = str_replace(array(PATH_ROOT, DS), array('', '/'), $JsPath);
                     $Options = (array) $JsInfo['Options'];
                     $Options['path'] = $JsPath;
                     $Version = GetValue('Version', $JsInfo);
                     if ($Version) {
                         TouchValue('version', $Options, $Version);
                     }
                     $this->Head->AddScript($JsSrc, 'text/javascript', $Options);
                 }
             }
         }
         // Add the favicon.
         $Favicon = C('Garden.FavIcon');
         if ($Favicon) {
             $this->Head->SetFavIcon(Gdn_Upload::Url($Favicon));
         }
         // Make sure the head module gets passed into the assets collection.
         $this->AddModule('Head');
     }
     // Master views come from one of four places:
     $MasterViewPaths = array();
     $MasterViewPath2 = ViewLocation($this->MasterView() . '.master', '', $this->ApplicationFolder);
     if (strpos($this->MasterView, '/') !== FALSE) {
         $MasterViewPaths[] = CombinePaths(array(PATH_ROOT, str_replace('/', DS, $this->MasterView) . '.master*'));
     } else {
         if ($this->Theme) {
             // 1. Application-specific theme view. eg. root/themes/theme_name/app_name/views/
             $MasterViewPaths[] = CombinePaths(array(PATH_THEMES, $this->Theme, $this->ApplicationFolder, 'views', $this->MasterView . '.master*'));
             // 2. Garden-wide theme view. eg. /path/to/application/themes/theme_name/views/
             $MasterViewPaths[] = CombinePaths(array(PATH_THEMES, $this->Theme, 'views', $this->MasterView . '.master*'));
         }
         // 3. Application default. eg. root/app_name/views/
         $MasterViewPaths[] = CombinePaths(array(PATH_APPLICATIONS, $this->ApplicationFolder, 'views', $this->MasterView . '.master*'));
         // 4. Garden default. eg. root/dashboard/views/
         $MasterViewPaths[] = CombinePaths(array(PATH_APPLICATIONS, 'dashboard', 'views', $this->MasterView . '.master*'));
     }
     // Find the first file that matches the path.
     $MasterViewPath = FALSE;
     foreach ($MasterViewPaths as $Glob) {
         $Paths = SafeGlob($Glob);
         if (is_array($Paths) && count($Paths) > 0) {
             $MasterViewPath = $Paths[0];
             break;
         }
     }
     if ($MasterViewPath != $MasterViewPath2) {
         Trace("Master views differ. Controller: {$MasterViewPath}, ViewLocation(): {$MasterViewPath2}", TRACE_WARNING);
     }
     $this->EventArguments['MasterViewPath'] =& $MasterViewPath;
     $this->FireEvent('BeforeFetchMaster');
     if ($MasterViewPath === FALSE) {
         trigger_error(ErrorMessage("Could not find master view: {$this->MasterView}.master*", $this->ClassName, '_FetchController'), E_USER_ERROR);
     }
     /// A unique identifier that can be used in the body tag of the master view if needed.
     $ControllerName = $this->ClassName;
     // Strip "Controller" from the body identifier.
     if (substr($ControllerName, -10) == 'Controller') {
         $ControllerName = substr($ControllerName, 0, -10);
     }
     // Strip "Gdn_" from the body identifier.
     if (substr($ControllerName, 0, 4) == 'Gdn_') {
         $ControllerName = substr($ControllerName, 4);
     }
     $this->SetData('CssClass', $this->Application . ' ' . $ControllerName . ' ' . $this->RequestMethod . ' ' . $this->CssClass, TRUE);
     // Check to see if there is a handler for this particular extension.
     $ViewHandler = Gdn::Factory('ViewHandler' . strtolower(strrchr($MasterViewPath, '.')));
     if (is_null($ViewHandler)) {
         $BodyIdentifier = strtolower($this->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::AlphaNumeric(strtolower($this->RequestMethod)));
         include $MasterViewPath;
     } else {
         $ViewHandler->Render($MasterViewPath, $this);
     }
 }
Beispiel #11
0
 public static function Url($Media)
 {
     static $UseDownloadUrl = NULL;
     if ($UseDownloadUrl === NULL) {
         $UseDownloadUrl = C('Plugins.FileUpload.UseDownloadUrl');
     }
     //      decho($Media);
     if (is_string($Media)) {
         $SubPath = $Media;
         if (method_exists('Gdn_Upload', 'Url')) {
             $Url = Gdn_Upload::Url("{$SubPath}");
         } else {
             $Url = "/uploads/{$SubPath}";
         }
     } elseif ($UseDownloadUrl) {
         $Url = '/discussion/download/' . GetValue('MediaID', $Media) . '/' . rawurlencode(GetValue('Name', $Media));
     } else {
         $SubPath = ltrim(GetValue('Path', $Media), '/');
         if (method_exists('Gdn_Upload', 'Url')) {
             $Url = Gdn_Upload::Url("{$SubPath}");
         } else {
             $Url = "/uploads/{$SubPath}";
         }
     }
     return $Url;
 }
 /**
  *
  *
  * @since 2.0.18
  * @access public
  * @param array $Data Dataset.
  */
 protected static function CalculateData(&$Data)
 {
     foreach ($Data as &$Category) {
         $Category['CountAllDiscussions'] = $Category['CountDiscussions'];
         $Category['CountAllComments'] = $Category['CountComments'];
         $Category['Url'] = self::CategoryUrl($Category, FALSE, '/');
         $Category['ChildIDs'] = array();
         if (GetValue('Photo', $Category)) {
             $Category['PhotoUrl'] = Gdn_Upload::Url($Category['Photo']);
         } else {
             $Category['PhotoUrl'] = '';
         }
         if ($Category['DisplayAs'] == 'Default') {
             if ($Category['Depth'] <= C('Vanilla.Categories.NavDepth', 0)) {
                 $Category['DisplayAs'] = 'Categories';
             } else {
                 $Category['DisplayAs'] = 'Discussions';
             }
         }
         if (!GetValue('CssClass', $Category)) {
             $Category['CssClass'] = 'Category-' . $Category['UrlCode'];
         }
         if (isset($Category['AllowedDiscussionTypes']) && is_string($Category['AllowedDiscussionTypes'])) {
             $Category['AllowedDiscussionTypes'] = unserialize($Category['AllowedDiscussionTypes']);
         }
     }
     $Keys = array_reverse(array_keys($Data));
     foreach ($Keys as $Key) {
         $Cat = $Data[$Key];
         $ParentID = $Cat['ParentCategoryID'];
         if (isset($Data[$ParentID]) && $ParentID != $Key) {
             $Data[$ParentID]['CountAllDiscussions'] += $Cat['CountAllDiscussions'];
             $Data[$ParentID]['CountAllComments'] += $Cat['CountAllComments'];
             array_unshift($Data[$ParentID]['ChildIDs'], $Key);
         }
     }
 }
Beispiel #13
0
// Define the current profile picture
$Picture = '';
if ($this->User->Photo != '') {
    if (StringBeginsWith($this->User->Photo, 'http')) {
        $Picture = Img($this->User->Photo, array('class' => 'ProfilePhotoLarge'));
    } else {
        $Picture = Img(Gdn_Upload::Url(ChangeBasename($this->User->Photo, 'p%s')), array('class' => 'ProfilePhotoLarge'));
    }
}
// Define the current thumbnail icon
$Thumbnail = $this->User->Photo;
if (!$Thumbnail && function_exists('UserPhotoDefaultUrl')) {
    $Thumbnail = UserPhotoDefaultUrl($this->User);
}
if ($Thumbnail && !preg_match('`^https?://`i', $Thumbnail)) {
    $Thumbnail = Gdn_Upload::Url(ChangeBasename($Thumbnail, 'n%s'));
}
$Thumbnail = Img($Thumbnail, array('alt' => T('Thumbnail')));
?>
<div class="SmallPopup">
<h2 class="H"><?php 
echo $this->Data('Title');
?>
</h2>
<?php 
echo $this->Form->Open(array('enctype' => 'multipart/form-data'));
echo $this->Form->Errors();
?>
<ul>
   <?php 
if ($Picture != '') {
Beispiel #14
0
 /**
  * Renders the banner logo, or just the banner title if the logo is not defined.
  */
 public static function Logo()
 {
     $Logo = C('Garden.Logo');
     if ($Logo) {
         $Logo = ltrim($Logo, '/');
         // Fix the logo path.
         if (StringBeginsWith($Logo, 'uploads/')) {
             $Logo = substr($Logo, strlen('uploads/'));
         }
     }
     $Title = C('Garden.Title', 'Title');
     echo $Logo ? Img(Gdn_Upload::Url($Logo), array('alt' => $Title)) : $Title;
 }
      <?php 
echo $this->Form->Label('Description', 'Description');
echo $this->Form->TextBox('Description', array('MultiLine' => TRUE));
?>
   </li>
   <li>
      <?php 
echo $this->Form->Label('Css Class', 'CssClass');
echo $this->Form->TextBox('CssClass', array('MultiLine' => FALSE));
?>
   </li>
   <li>
      <?php 
echo $this->Form->Label('Photo', 'PhotoUpload');
if ($Photo = $this->Form->GetValue('Photo')) {
    echo Img(Gdn_Upload::Url($Photo));
    echo '<br />' . Anchor(T('Delete Photo'), CombinePaths(array('vanilla/settings/deletecategoryphoto', $this->Category->CategoryID, Gdn::Session()->TransientKey())), 'SmallButton Danger PopConfirm');
}
echo $this->Form->Input('PhotoUpload', 'file');
?>
   </li>
   <?php 
echo $this->Form->Simple($this->Data('_ExtendedFields', array()), array('Wrap' => array('', '')));
?>
   <?php 
if ($this->ShowCustomPoints) {
    ?>
   <li>
      <?php 
    echo $this->Form->Label('Display As', 'DisplayAs');
    echo $this->Form->DropDown('DisplayAs', array('Default' => 'Default', 'Categories' => 'Categories', 'Discussions' => 'Discussions'));
Beispiel #16
0
 function UserPhoto($User, $Options = array())
 {
     if (is_string($Options)) {
         $Options = array('LinkClass' => $Options);
     }
     if ($Px = GetValue('Px', $Options)) {
         $User = UserBuilder($User, $Px);
     } else {
         $User = (object) $User;
     }
     $LinkClass = ConcatSep(' ', GetValue('LinkClass', $Options, ''), 'PhotoWrap');
     $ImgClass = GetValue('ImageClass', $Options, 'ProfilePhoto');
     $Size = GetValue('Size', $Options);
     if ($Size) {
         $LinkClass .= " PhotoWrap{$Size}";
         $ImgClass .= " {$ImgClass}{$Size}";
     } else {
         $ImgClass .= " {$ImgClass}Medium";
         // backwards compat
     }
     $FullUser = Gdn::UserModel()->GetID(GetValue('UserID', $User), DATASET_TYPE_ARRAY);
     $UserCssClass = GetValue('_CssClass', $FullUser);
     if ($UserCssClass) {
         $LinkClass .= ' ' . $UserCssClass;
     }
     $LinkClass = $LinkClass == '' ? '' : ' class="' . $LinkClass . '"';
     $Photo = GetValue('Photo', $User);
     $Name = GetValue('Name', $User);
     $Title = htmlspecialchars(GetValue('Title', $Options, $Name));
     if ($FullUser['Banned']) {
         $Photo = 'http://cdn.vanillaforums.com/images/banned_100.png';
         $Title .= ' (' . T('Banned') . ')';
     }
     if (!$Photo && function_exists('UserPhotoDefaultUrl')) {
         $Photo = UserPhotoDefaultUrl($User, $ImgClass);
     }
     if ($Photo) {
         if (!preg_match('`^https?://`i', $Photo)) {
             $PhotoUrl = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s'));
         } else {
             $PhotoUrl = $Photo;
         }
         $Href = Url(UserUrl($User));
         return '<a title="' . $Title . '" href="' . $Href . '"' . $LinkClass . '>' . Img($PhotoUrl, array('alt' => htmlspecialchars($Name), 'class' => $ImgClass)) . '</a>';
     } else {
         return '';
     }
 }
Beispiel #17
0
echo Wrap(T('FaviconDescription', "Your site's favicon appears in your browser's title bar. It will be scaled to 16x16 pixels."), 'div', array('class' => 'Info'));
$Favicon = $this->Data('Favicon');
if ($Favicon) {
    echo Wrap(Img(Gdn_Upload::Url($Favicon)), 'div');
    echo Wrap(Anchor(T('Remove Favicon'), '/dashboard/settings/removefavicon/' . $Session->TransientKey(), 'SmallButton'), 'div', array('style' => 'padding: 10px 0;'));
    echo Wrap(T('FaviconBrowse', 'Browse for a new favicon if you would like to change it:'), 'div', array('class' => 'Info'));
} else {
    echo Wrap(T('FaviconDescription', "The shortcut icon that shows up in your browser's bookmark menu (16x16 px)."), 'div', array('class' => 'Info'));
}
echo $this->Form->Input('Favicon', 'file');
?>
         </li>
         <li>
            <?php 
echo $this->Form->Label('Share Image', 'ShareImage');
echo Wrap(T('ShareImageDescription', "When someone shares a link from your site we try and grab an image from the page. If there isn't an image on the page then we'll use this image instead. The image should be at least 50&times;50, but we recommend 200&times;200."), 'div', array('class' => 'Info'));
$ShareImage = $this->Data('ShareImage');
if ($ShareImage) {
    echo Wrap(Img(Gdn_Upload::Url($ShareImage), array('style' => 'max-width: 300px')), 'div');
    echo Wrap(Anchor(T('Remove Image'), '/dashboard/settings/removeshareimage', 'SmallButton Hijack'), 'div', array('style' => 'padding: 10px 0;'));
    echo Wrap(T('FaviconBrowse', 'Browse for a new favicon if you would like to change it:'), 'div', array('class' => 'Info'));
}
echo $this->Form->Input('ShareImage', 'file');
?>
         </li>
      </ul>
   </div>
</div>
<?php 
echo '<div class="Buttons">' . $this->Form->Button('Save') . '</div>';
echo $this->Form->Close();
 public function CalculateRow(&$Row)
 {
     $ActivityType = self::GetActivityType($Row['ActivityTypeID']);
     $Row['ActivityType'] = GetValue('Name', $ActivityType);
     if (is_string($Row['Data'])) {
         $Row['Data'] = @unserialize($Row['Data']);
     }
     $Row['PhotoUrl'] = Url($Row['Route'], TRUE);
     if (!$Row['Photo']) {
         if (isset($Row['ActivityPhoto'])) {
             $Row['Photo'] = $Row['ActivityPhoto'];
             $Row['PhotoUrl'] = UserUrl($Row, 'Activity');
         } else {
             $User = Gdn::UserModel()->GetID($Row['ActivityUserID'], DATASET_TYPE_ARRAY);
             if ($User) {
                 $Photo = $User['Photo'];
                 $Row['PhotoUrl'] = UserUrl($User);
                 if (!$Photo || StringBeginsWith($Photo, 'http')) {
                     $Row['Photo'] = $Photo;
                 } else {
                     $Row['Photo'] = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s'));
                 }
             }
         }
     }
     $Data = $Row['Data'];
     if (isset($Data['ActivityUserIDs'])) {
         $Row['ActivityUserID'] = array_merge(array($Row['ActivityUserID']), $Data['ActivityUserIDs']);
     }
     if (isset($Data['RegardingUserIDs'])) {
         $Row['RegardingUserID'] = array_merge(array($Row['RegardingUserID']), $Data['RegardingUserIDs']);
     }
     $Row['Url'] = ExternalUrl($Row['Route']);
     if ($Row['HeadlineFormat']) {
         $Row['Headline'] = FormatString($Row['HeadlineFormat'], $Row);
     } else {
         $Row['Headline'] = Gdn_Format::ActivityHeadline($Row);
     }
 }
Beispiel #19
0
 function UserPhoto($User, $Options = array())
 {
     $User = (object) $User;
     if (is_string($Options)) {
         $Options = array('LinkClass' => $Options);
     }
     $LinkClass = GetValue('LinkClass', $Options, 'ProfileLink');
     $ImgClass = GetValue('ImageClass', $Options, 'ProfilePhotoMedium');
     $LinkClass = $LinkClass == '' ? '' : ' class="' . $LinkClass . '"';
     $Photo = $User->Photo;
     if (!$Photo && function_exists('UserPhotoDefaultUrl')) {
         $Photo = UserPhotoDefaultUrl($User);
     }
     if ($Photo) {
         if (!preg_match('`^https?://`i', $Photo)) {
             $PhotoUrl = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s'));
         } else {
             $PhotoUrl = $Photo;
         }
         $Href = Url(UserUrl($User));
         return '<a title="' . $User->Name . '" href="' . $Href . '"' . $LinkClass . '>' . Img($PhotoUrl, array('alt' => $User->Name, 'class' => $ImgClass)) . '</a>';
     } else {
         return '';
     }
 }
 /**
  * Returns the mobile banner logo. If there is no mobile logo defined then this will just return
  * the regular logo or the mobile title.
  *
  * @return string
  */
 public static function MobileLogo()
 {
     $Logo = C('Garden.MobileLogo', C('Garden.Logo'));
     $Title = C('Garden.MobileTitle', C('Garden.Title', 'Title'));
     if ($Logo) {
         return Img(Gdn_Upload::Url($Logo), array('alt' => $Title));
     } else {
         return $Title;
     }
 }
   function UserPhoto($User, $Options = array()) {
		$User = (object)$User;
      if (is_string($Options))
         $Options = array('LinkClass' => $Options);
      
      $LinkClass = GetValue('LinkClass', $Options, 'ProfileLink');
      $ImgClass = GetValue('ImageClass', $Options, 'ProfilePhotoBig');
      
      $LinkClass = $LinkClass == '' ? '' : ' class="'.$LinkClass.'"';
      if ($User->Photo) {
         if (!preg_match('`^https?://`i', $User->Photo)) {
            $PhotoUrl = Gdn_Upload::Url(ChangeBasename($User->Photo, 'n%s'));
         } else {
            $PhotoUrl = $User->Photo;
         }
         
         return '<a title="'.htmlspecialchars($User->Name).'" href="'.Url('/profile/'.$User->UserID.'/'.rawurlencode($User->Name)).'"'.$LinkClass.'>'
            .Img($PhotoUrl, array('alt' => htmlspecialchars($User->Name), 'class' => $ImgClass))
            .'</a>';
      } else {
         return '';
      }
   }
Beispiel #22
0
 /**
  * Render the entire head module.
  */
 public function ToString()
 {
     // Add the canonical Url if necessary.
     if (method_exists($this->_Sender, 'CanonicalUrl') && !C('Garden.Modules.NoCanonicalUrl', FALSE)) {
         $CanonicalUrl = $this->_Sender->CanonicalUrl();
         if (!preg_match('`^https?://`', $CanonicalUrl)) {
             $CanonicalUrl = Gdn::Router()->ReverseRoute($CanonicalUrl);
         }
         $this->_Sender->CanonicalUrl($CanonicalUrl);
         //            $CurrentUrl = Url('', TRUE);
         //            if ($CurrentUrl != $CanonicalUrl) {
         $this->AddTag('link', array('rel' => 'canonical', 'href' => $CanonicalUrl));
         //            }
     }
     // Include facebook open-graph meta information.
     if ($FbAppID = C('Plugins.Facebook.ApplicationID')) {
         $this->AddTag('meta', array('property' => 'fb:app_id', 'content' => $FbAppID));
     }
     $SiteName = C('Garden.Title', '');
     if ($SiteName != '') {
         $this->AddTag('meta', array('property' => 'og:site_name', 'content' => $SiteName));
     }
     $Title = Gdn_Format::Text($this->Title('', TRUE));
     if ($Title != '') {
         $this->AddTag('meta', array('property' => 'og:title', 'itemprop' => 'name', 'content' => $Title));
     }
     if (isset($CanonicalUrl)) {
         $this->AddTag('meta', array('property' => 'og:url', 'content' => $CanonicalUrl));
     }
     if ($Description = $this->_Sender->Description()) {
         $this->AddTag('meta', array('name' => 'description', 'property' => 'og:description', 'itemprop' => 'description', 'content' => $Description));
     }
     // Default to the site logo if there were no images provided by the controller.
     if (count($this->_Sender->Image()) == 0) {
         $Logo = C('Garden.ShareImage', C('Garden.Logo', ''));
         if ($Logo != '') {
             // Fix the logo path.
             if (StringBeginsWith($Logo, 'uploads/')) {
                 $Logo = substr($Logo, strlen('uploads/'));
             }
             $Logo = Gdn_Upload::Url($Logo);
             $this->AddTag('meta', array('property' => 'og:image', 'itemprop' => 'image', 'content' => $Logo));
         }
     } else {
         foreach ($this->_Sender->Image() as $Img) {
             $this->AddTag('meta', array('property' => 'og:image', 'itemprop' => 'image', 'content' => $Img));
         }
     }
     $this->FireEvent('BeforeToString');
     $Tags = $this->_Tags;
     // Make sure that css loads before js (for jquery)
     usort($this->_Tags, array('HeadModule', 'TagCmp'));
     // "link" comes before "script"
     $Tags2 = $this->_Tags;
     // Start with the title.
     $Head = '<title>' . Gdn_Format::Text($this->Title()) . "</title>\n";
     $TagStrings = array();
     // Loop through each tag.
     foreach ($this->_Tags as $Index => $Attributes) {
         $Tag = $Attributes[self::TAG_KEY];
         // Inline the content of the tag, if necessary.
         if (GetValue('_hint', $Attributes) == 'inline') {
             $Path = GetValue('_path', $Attributes);
             if (!StringBeginsWith($Path, 'http')) {
                 $Attributes[self::CONTENT_KEY] = file_get_contents($Path);
                 if (isset($Attributes['src'])) {
                     $Attributes['_src'] = $Attributes['src'];
                     unset($Attributes['src']);
                 }
                 if (isset($Attributes['href'])) {
                     $Attributes['_href'] = $Attributes['href'];
                     unset($Attributes['href']);
                 }
             }
         }
         // If we set an IE conditional AND a "Not IE" condition, we will need to make a second pass.
         do {
             // Reset tag string
             $TagString = '';
             // IE conditional? Validates condition.
             $IESpecific = isset($Attributes['_ie']) && preg_match('/((l|g)t(e)? )?IE [0-9\\.]/', $Attributes['_ie']);
             // Only allow $NotIE if we're not doing a conditional this loop.
             $NotIE = !$IESpecific && isset($Attributes['_notie']);
             // Open IE conditional tag
             if ($IESpecific) {
                 $TagString .= '<!--[if ' . $Attributes['_ie'] . ']>';
             }
             if ($NotIE) {
                 $TagString .= '<!--[if !IE]> -->';
             }
             // Build tag
             $TagString .= '<' . $Tag . Attribute($Attributes, '_');
             if (array_key_exists(self::CONTENT_KEY, $Attributes)) {
                 $TagString .= '>' . $Attributes[self::CONTENT_KEY] . '</' . $Tag . '>';
             } elseif ($Tag == 'script') {
                 $TagString .= '></script>';
             } else {
                 $TagString .= ' />';
             }
             // Close IE conditional tag
             if ($IESpecific) {
                 $TagString .= '<![endif]-->';
             }
             if ($NotIE) {
                 $TagString .= '<!-- <![endif]-->';
             }
             // Cleanup (prevent infinite loop)
             if ($IESpecific) {
                 unset($Attributes['_ie']);
             }
             $TagStrings[] = $TagString;
         } while ($IESpecific && isset($Attributes['_notie']));
         // We need a second pass
     }
     //endforeach
     $Head .= implode("\n", array_unique($TagStrings));
     foreach ($this->_Strings as $String) {
         $Head .= $String;
         $Head .= "\n";
     }
     return $Head;
 }
Beispiel #23
0
?>
</td>
         <td><?php 
echo T('Thumbnail');
?>
</td>
      </tr>
   </thead>
   <tbody>
      <tr>
         <td>
            <?php 
echo Img(Gdn_Upload::Url(ChangeBasename($this->User->Photo, 'p%s')), array('id' => 'cropbox'));
?>
         </td>
         <td>
            <div style="<?php 
echo 'width:' . $this->ThumbSize . 'px;height:' . $this->ThumbSize . 'px;';
?>
overflow:hidden;">
               <?php 
echo Img(Gdn_Upload::Url(ChangeBasename($this->User->Photo, 'p%s')), array('id' => 'preview'));
?>
            </div>
         </td>
      </tr>
   </tbody>
</table>

<?php 
echo $this->Form->Close('Save', '', array('class' => 'Button Primary'));
 public function SetCalculatedFields(&$User)
 {
     if ($v = GetValue('Attributes', $User)) {
         if (is_string($v)) {
             SetValue('Attributes', $User, @unserialize($v));
         }
     }
     if ($v = GetValue('Permissions', $User)) {
         SetValue('Permissions', $User, @unserialize($v));
     }
     if ($v = GetValue('Preferences', $User)) {
         SetValue('Preferences', $User, @unserialize($v));
     }
     if ($v = GetValue('Photo', $User)) {
         if (!IsUrl($v)) {
             $PhotoUrl = Gdn_Upload::Url(ChangeBasename($v, 'n%s'));
         } else {
             $PhotoUrl = $v;
         }
         SetValue('PhotoUrl', $User, $PhotoUrl);
     }
     if ($v = GetValue('AllIPAddresses', $User)) {
         $IPAddresses = explode(',', $v);
         foreach ($IPAddresses as $i => $IPAddress) {
             $IPAddresses[$i] = ForceIPv4($IPAddress);
         }
         SetValue('AllIPAddresses', $User, $IPAddresses);
     }
     TouchValue('_CssClass', $User, '');
     if ($v = GetValue('Banned', $User)) {
         SetValue('_CssClass', $User, 'Banned');
     }
     $this->EventArguments['User'] =& $User;
     $this->FireEvent('SetCalculatedFields');
 }
 public function remote_login()
 {
     $user_login = Gdn::Session()->User->Name;
     $avatar = '';
     if (Gdn::Session()->User->Photo != '') {
         $avatar = Gdn_Upload::Url(ChangeBasename(Gdn::Session()->User->Photo, 'p%s'));
     }
     $isAdmin = Gdn::Session()->User->Admin;
     $chatId = C('Plugin.Chatwee.Chatid');
     $clientKey = C('Plugin.Chatwee.APIKey');
     $ismobile = $this->check_user_agent('mobile') == true ? 1 : 0;
     $ip = $this->get_the_user_ip();
     if (isset($_COOKIE["chch-SI"])) {
         $this->remote_logout();
     }
     if (isset($_SESSION['chatwee'][$user_login])) {
         $previousSessionId = $_SESSION['chatwee'][$user_login];
     } else {
         if (isset($_COOKIE["chch-PSI"])) {
             $previousSessionId = $_COOKIE["chch-PSI"];
         } else {
             $previousSessionId = null;
         }
     }
     $url = "http://chatwee-api.com/api/remotelogin?chatId=" . $chatId . "&clientKey=" . $clientKey . "&login="******"&isAdmin=" . $isAdmin . "&ipAddress=" . $ip . "&avatar=" . $avatar . "&isMobile=" . $ismobile . "&previousSessionId=" . $previousSessionId;
     $url = str_replace(' ', '%20', $url);
     $response = $this->get_response($url);
     $sessionArray = json_decode($response);
     if ($sessionArray->errorCode) {
         //	update_option('chatwee-settings-group[ssoiserror]',$sessionArray->errorMessage);
     } else {
         //	update_option('chatwee-settings-group[ssoiserror]','');
         $sessionId = $sessionArray->sessionId;
     }
     $fullDomain = $_SERVER["HTTP_HOST"];
     $isNumericDomain = preg_match('/\\d|"."/', $fullDomain);
     if ($isNumericDomain) {
         $CookieDomain = $fullDomain;
     } else {
         $hostChunks = explode(".", $fullDomain);
         $hostChunks = array_slice($hostChunks, -2);
         $CookieDomain = "." . implode(".", $hostChunks);
     }
     setcookie("chch-SI", $sessionId, time() + 2592000, "/", $CookieDomain);
     $_SESSION['chatwee'][$user_login] = $_SESSION['chatwee'][$user_login] == '' ? $sessionId : $_SESSION['chatwee'][$user_login];
 }
Beispiel #26
0
    $BannedPhoto = C('Garden.BannedPhoto', 'http://cdn.vanillaforums.com/images/banned_large.png');
    if ($BannedPhoto) {
        $Photo = Gdn_Upload::Url($BannedPhoto);
    }
}
if ($Photo) {
    ?>
   <div class="Photo PhotoWrap PhotoWrapLarge <?php 
    echo GetValue('_CssClass', $User);
    ?>
">
      <?php 
    if (StringBeginsWith($Photo, 'http')) {
        $Img = Img($Photo, array('class' => 'ProfilePhotoLarge'));
    } else {
        $Img = Img(Gdn_Upload::Url(ChangeBasename($Photo, 'p%s')), array('class' => 'ProfilePhotoLarge'));
    }
    if (!$User->Banned && (Gdn::Session()->UserID == $User->UserID || Gdn::Session()->CheckPermission('Garden.Users.Edit'))) {
        echo Anchor(Wrap(T('Change Picture')), '/profile/picture?userid=' . $User->UserID, 'ChangePicture');
    }
    echo $Img;
    ?>
   </div>
<?php 
} else {
    if ($User->UserID == Gdn::Session()->UserID || Gdn::Session()->CheckPermission('Garden.Users.Edit')) {
        ?>
   <div class="Photo"><?php 
        echo Anchor(T('Add a Profile Picture'), '/profile/picture?userid=' . $User->UserID, 'AddPicture BigButton');
        ?>
</div>
    public function DoAttachment($bbcode, $action, $name, $default, $params, $content)
    {
        $Medias = $this->Media();
        $Parts = explode(':', $default);
        $MediaID = $Parts[0];
        if (isset($Medias[$MediaID])) {
            $Media = $Medias[$MediaID];
            //         decho($Media, 'Media');
            $Src = htmlspecialchars(Gdn_Upload::Url(GetValue('Path', $Media)));
            $Name = htmlspecialchars(GetValue('Name', $Media));
            return <<<EOT
<div class="Attachment"><img src="{$Src}" alt="{$Name}" /></div>
EOT;
        }
        return '';
    }
Beispiel #28
0
 /**
  * Take a user object an return the URL to their photo.
  *
  * @param object|array $User
  */
 function userPhotoUrl($User)
 {
     $FullUser = Gdn::UserModel()->GetID(GetValue('UserID', $User), DATASET_TYPE_ARRAY);
     $Photo = GetValue('Photo', $User);
     if ($FullUser && $FullUser['Banned']) {
         $Photo = 'http://cdn.vanillaforums.com/images/banned_100.png';
     }
     if (!$Photo && function_exists('UserPhotoDefaultUrl')) {
         $Photo = UserPhotoDefaultUrl($User);
     }
     if ($Photo) {
         if (!isUrl($Photo)) {
             $PhotoUrl = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s'));
         } else {
             $PhotoUrl = $Photo;
         }
         return $PhotoUrl;
     }
     return '';
 }
Beispiel #29
0
 /**
  * Returns the current image in a field.
  * This is meant to be used with image uploads so that users can see the current value.
  * 
  * @param type $FieldName
  * @param type $Attributes
  * @since 2.1
  */
 public function CurrentImage($FieldName, $Attributes = array())
 {
     $Result = $this->Hidden($FieldName);
     $Value = $this->GetValue($FieldName);
     if ($Value) {
         TouchValue('class', $Attributes, 'CurrentImage');
         $Result .= Img(Gdn_Upload::Url($Value), $Attributes);
     }
     return $Result;
 }
Beispiel #30
0
 public function Init($Path, $Controller)
 {
     $Smarty = $this->Smarty();
     // Get a friendly name for the controller.
     $ControllerName = get_class($Controller);
     if (StringEndsWith($ControllerName, 'Controller', TRUE)) {
         $ControllerName = substr($ControllerName, 0, -10);
     }
     // Get an ID for the body.
     $BodyIdentifier = strtolower($Controller->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::AlphaNumeric(strtolower($Controller->RequestMethod)));
     $Smarty->assign('BodyID', $BodyIdentifier);
     //$Smarty->assign('Config', Gdn::Config());
     // Assign some information about the user.
     $Session = Gdn::Session();
     if ($Session->IsValid()) {
         $User = array('Name' => $Session->User->Name, 'Photo' => '', 'CountNotifications' => (int) GetValue('CountNotifications', $Session->User, 0), 'CountUnreadConversations' => (int) GetValue('CountUnreadConversations', $Session->User, 0), 'SignedIn' => TRUE);
         $Photo = $Session->User->Photo;
         if ($Photo) {
             if (!preg_match('`^https?://`i', $Photo)) {
                 $Photo = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s'));
             }
         } else {
             if (function_exists('UserPhotoDefaultUrl')) {
                 $Photo = UserPhotoDefaultUrl($Session->User, 'ProfilePhoto');
             } elseif ($ConfigPhoto = C('Garden.DefaultAvatar')) {
                 $Photo = Gdn_Upload::Url($ConfigPhoto);
             } else {
                 $Photo = Asset('/applications/dashboard/design/images/defaulticon.png', TRUE);
             }
         }
         $User['Photo'] = $Photo;
     } else {
         $User = FALSE;
         /*array(
           'Name' => '',
           'CountNotifications' => 0,
           'SignedIn' => FALSE);*/
     }
     $Smarty->assign('User', $User);
     // Make sure that any datasets use arrays instead of objects.
     foreach ($Controller->Data as $Key => $Value) {
         if ($Value instanceof Gdn_DataSet) {
             $Controller->Data[$Key] = $Value->ResultArray();
         } elseif ($Value instanceof stdClass) {
             $Controller->Data[$Key] = (array) $Value;
         }
     }
     $BodyClass = GetValue('CssClass', $Controller->Data, '', TRUE);
     $Sections = Gdn_Theme::Section(NULL, 'get');
     if (is_array($Sections)) {
         foreach ($Sections as $Section) {
             $BodyClass .= ' Section-' . $Section;
         }
     }
     $Controller->Data['BodyClass'] = $BodyClass;
     $Smarty->assign('Assets', (array) $Controller->Assets);
     $Smarty->assign('Path', Gdn::Request()->Path());
     // Assigign the controller data last so the controllers override any default data.
     $Smarty->assign($Controller->Data);
     $Smarty->Controller = $Controller;
     // for smarty plugins
     $Smarty->security = TRUE;
     $Smarty->security_settings['IF_FUNCS'] = array_merge($Smarty->security_settings['IF_FUNCS'], array('CheckPermission', 'MultiCheckPermission', 'GetValue', 'SetValue', 'Url', 'InSection', 'InCategory'));
     $Smarty->security_settings['MODIFIER_FUNCS'] = array_merge($Smarty->security_settings['MODIFIER_FUNCS'], array('sprintf'));
     $Smarty->secure_dir = array($Path);
 }