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 != '') { if (strtolower(substr($Discussion->FirstPhoto, 0, 7)) == 'http://' || strtolower(substr($Discussion->FirstPhoto, 0, 8)) == 'https://') { $PhotoUrl = $Discussion->FirstPhoto; } else { $PhotoUrl = 'uploads/' . ChangeBasename($Discussion->FirstPhoto, 'n%s'); } 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->FirstDate) . '</span> '; ?> </div> </div> </li> <?php }
<?php if (!defined('APPLICATION')) { exit; } // If the photo contains an http://, it is just an icon, don't show it here. if ($this->User->Photo != '' && strtolower(substr($this->User->Photo, 0, 7)) != 'http://') { ?> <div class="Photo"> <?php echo Img('uploads/' . ChangeBasename($this->User->Photo, 'p%s')); ?> </div> <?php }
/** * * * @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); }
/** * Generic save procedure. */ public function Save($FormPostValues, $Settings = FALSE) { // See if the user's related roles should be saved or not. $SaveRoles = ArrayValue('SaveRoles', $Settings); // Define the primary key in this model's table. $this->DefineSchema(); // Add & apply any extra validation rules: if (array_key_exists('Email', $FormPostValues)) { $this->Validation->ApplyRule('Email', 'Email'); } // Custom Rule: This will make sure that at least one role was selected if saving roles for this user. if ($SaveRoles) { $this->Validation->AddRule('OneOrMoreArrayItemRequired', 'function:ValidateOneOrMoreArrayItemRequired'); // $this->Validation->AddValidationField('RoleID', $FormPostValues); $this->Validation->ApplyRule('RoleID', 'OneOrMoreArrayItemRequired'); } // Make sure that the checkbox val for email is saved as the appropriate enum if (array_key_exists('ShowEmail', $FormPostValues)) { $FormPostValues['ShowEmail'] = ForceBool($FormPostValues['ShowEmail'], '0', '1', '0'); } // Validate the form posted values $UserID = ArrayValue('UserID', $FormPostValues); $Insert = $UserID > 0 ? FALSE : TRUE; if ($Insert) { $this->AddInsertFields($FormPostValues); } else { $this->AddUpdateFields($FormPostValues); } $this->EventArguments['FormPostValues'] = $FormPostValues; $this->FireEvent('BeforeSaveValidation'); $RecordRoleChange = TRUE; if ($this->Validate($FormPostValues, $Insert) === TRUE) { $Fields = $this->Validation->ValidationFields(); // All fields on the form that need to be validated (including non-schema field rules defined above) $RoleIDs = ArrayValue('RoleID', $Fields, 0); $Username = ArrayValue('Name', $Fields); $Email = ArrayValue('Email', $Fields); $Fields = $this->Validation->SchemaValidationFields(); // Only fields that are present in the schema // Remove the primary key from the fields collection before saving $Fields = RemoveKeyFromArray($Fields, $this->PrimaryKey); // Make sure to encrypt the password for saving... if (array_key_exists('Password', $Fields)) { $PasswordHash = new Gdn_PasswordHash(); $Fields['Password'] = $PasswordHash->HashPassword($Fields['Password']); } $this->EventArguments['Fields'] = $Fields; $this->FireEvent('BeforeSave'); // Check the validation results again in case something was added during the BeforeSave event. if (count($this->Validation->Results()) == 0) { // If the primary key exists in the validated fields and it is a // numeric value greater than zero, update the related database row. if ($UserID > 0) { // If they are changing the username & email, make sure they aren't // already being used (by someone other than this user) if (ArrayValue('Name', $Fields, '') != '' || ArrayValue('Email', $Fields, '') != '') { if (!$this->ValidateUniqueFields($Username, $Email, $UserID)) { return FALSE; } } $this->SQL->Put($this->Name, $Fields, array($this->PrimaryKey => $UserID)); // Record activity if the person changed his/her photo $Photo = ArrayValue('Photo', $FormPostValues); if ($Photo !== FALSE) { AddActivity($UserID, 'PictureChange', '<img src="' . Asset('uploads/' . ChangeBasename($Photo, 't%s')) . '" alt="' . T('Thumbnail') . '" />'); } } else { $RecordRoleChange = FALSE; if (!$this->ValidateUniqueFields($Username, $Email)) { return FALSE; } // Define the other required fields: $Fields['Email'] = $Email; // And insert the new user $UserID = $this->_Insert($Fields); // Make sure that the user is assigned to one or more roles: $SaveRoles = TRUE; // Report that the user was created $Session = Gdn::Session(); AddActivity($UserID, 'JoinCreated', T('Welcome Aboard!'), $Session->UserID > 0 ? $Session->UserID : ''); } // Now update the role settings if necessary if ($SaveRoles) { // If no RoleIDs were provided, use the system defaults if (!is_array($RoleIDs)) { $RoleIDs = Gdn::Config('Garden.Registration.DefaultRoles'); } $this->SaveRoles($UserID, $RoleIDs, $RecordRoleChange); } $this->EventArguments['UserID'] = $UserID; $this->FireEvent('AfterSave'); } else { $UserID = FALSE; } } else { $UserID = FALSE; } return $UserID; }
?> </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'));
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 ''; } }
/** * 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(); } }
public function Thumbnail() { $this->Permission('Garden.SignIn.Allow'); $this->AddJsFile('jquery.jcrop.pack.js'); $this->AddJsFile('profile.js'); $Session = Gdn::Session(); if (!$Session->IsValid()) { $this->Form->AddError('You must be authenticated in order to use this form.'); } $this->GetUserInfo(); $this->Form->SetModel($this->UserModel); $this->Form->AddHidden('UserID', $this->User->UserID); if ($this->User->Photo == '') { $this->Form->AddError('You must first upload a picture before you can create a thumbnail.'); } // Define the thumbnail size $this->ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 32); // Define the source (profile sized) picture & dimensions. if (preg_match('`https?://`i', $this->User->Photo)) { $this->Form->AddError('You cannont edit the thumbnail of an externally linked profile picture.'); $this->SourceSize = 0; } else { $Source = PATH_ROOT . '/uploads/' . ChangeBasename($this->User->Photo, 'p%s'); $this->SourceSize = getimagesize($Source); } // Add some more hidden form fields for jcrop $this->Form->AddHidden('x', '0'); $this->Form->AddHidden('y', '0'); $this->Form->AddHidden('w', $this->ThumbSize); $this->Form->AddHidden('h', $this->ThumbSize); $this->Form->AddHidden('HeightSource', $this->SourceSize[1]); $this->Form->AddHidden('WidthSource', $this->SourceSize[0]); $this->Form->AddHidden('ThumbSize', $this->ThumbSize); if ($this->Form->AuthenticatedPostBack() === TRUE) { try { // Get the dimensions from the form // Get the source image $SourceImage = imagecreatefromjpeg($Source); // Create the new target image $TargetImage = imagecreatetruecolor($this->ThumbSize, $this->ThumbSize); // Fill the target thumbnail imagecopyresampled($TargetImage, $SourceImage, 0, 0, $this->Form->GetValue('x'), $this->Form->GetValue('y'), $this->ThumbSize, $this->ThumbSize, $this->Form->GetValue('w'), $this->Form->GetValue('h')); // Save the target thumbnail imagejpeg($TargetImage, PATH_ROOT . '/uploads/' . ChangeBasename($this->User->Photo, 'n%s')); } catch (Exception $ex) { $this->Form->AddError($ex->getMessage()); } // If there were no problems, redirect back to the user account if ($this->Form->ErrorCount() == 0) { Redirect('dashboard/profile/' . Gdn_Format::Url($this->User->Name)); } } $this->Render(); }
public static function Link($Path, $Text = FALSE, $Format = '<a href="%url" class="%class">%text</a>', $Options = array()) { $Session = Gdn::Session(); $Class = GetValue('class', $Options, ''); $WithDomain = GetValue('WithDomain', $Options); $Target = GetValue('Target', $Options, ''); switch ($Path) { case 'activity': TouchValue('Permissions', $Options, 'Garden.Activity.View'); break; case 'dashboard': $Path = 'dashboard/settings'; TouchValue('Permissions', $Options, 'Garden.Settings.Manage'); if (!$Text) $Text = T('Dashboard'); break; case 'inbox': $Path = 'messages/inbox'; TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text) $Text = T('Inbox'); if ($Session->IsValid() && $Session->User->CountUnreadConversations) { $Class = trim($Class.' HasCount'); $Text .= ' <span class="Alert">'.$Session->User->CountUnreadConversations.'</span>'; } break; case 'profile': TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text && $Session->IsValid()) $Text = $Session->User->Name; if ($Session->IsValid() && $Session->User->CountNotifications) { $Class = trim($Class.' HasCount'); $Text .= ' <span class="Alert">'.$Session->User->CountNotifications.'</span>'; } break; case 'user': $Path = 'profile'; TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text && $Session->IsValid()) $Text = $Session->User->Name; break; case 'photo': $Path = 'profile'; TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text && $Session->IsValid()) { $IsFullPath = strtolower(substr($Session->User->Photo, 0, 7)) == 'http://' || strtolower(substr($Session->User->Photo, 0, 8)) == 'https://'; $PhotoUrl = ($IsFullPath) ? $Session->User->Photo : Gdn_Upload::Url(ChangeBasename($Session->User->Photo, 'n%s')); $Text = Img($PhotoUrl, array('alt' => htmlspecialchars($Session->User->Name))); } break; case 'drafts': TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text) $Text = T('My Drafts'); if ($Session->IsValid() && $Session->User->CountDrafts) { $Class = trim($Class.' HasCount'); $Text .= ' <span class="Alert">'.$Session->User->CountDrafts.'</span>'; } break; case 'discussions/bookmarked': TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text) $Text = T('My Bookmarks'); if ($Session->IsValid() && $Session->User->CountBookmarks) { $Class = trim($Class.' HasCount'); $Text .= ' <span class="Count">'.$Session->User->CountBookmarks.'</span>'; } break; case 'discussions/mine': TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text) $Text = T('My Discussions'); if ($Session->IsValid() && $Session->User->CountDiscussions) { $Class = trim($Class.' HasCount'); $Text .= ' <span class="Count">'.$Session->User->CountDiscussions.'</span>'; } break; case 'signin': case 'signinout': // The destination is the signin/signout toggle link. if ($Session->IsValid()) { if(!$Text) $Text = T('Sign Out'); $Path = SignOutUrl($Target); $Class = ConcatSep(' ', $Class, 'SignOut'); } else { if(!$Text) $Text = T('Sign In'); $Attribs = array(); $Path = SignInUrl($Target); if (SignInPopup() && strpos(Gdn::Request()->Url(), 'entry') === FALSE) $Class = ConcatSep(' ', $Class, 'SignInPopup'); } break; } if (GetValue('Permissions', $Options) && !$Session->CheckPermission($Options['Permissions'])) return ''; $Url = Gdn::Request()->Url($Path, $WithDomain); if (strcasecmp(trim($Path, '/'), Gdn::Request()->Path()) == 0) $Class = ConcatSep(' ', $Class, 'Selected'); // Build the final result. $Result = $Format; $Result = str_replace('%url', $Url, $Result); $Result = str_replace('%text', $Text, $Result); $Result = str_replace('%class', $Class, $Result); return $Result; }
public function SetCalculatedFields(&$User) { if ($v = GetValue('Attributes', $User)) 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 (!preg_match('`^https?://`i', $v)) { $PhotoUrl = Gdn_Upload::Url(ChangeBasename($v, 'n%s')); } else { $PhotoUrl = $v; } SetValue('PhotoUrl', $User, $PhotoUrl); } }
echo T('Original'); ?> </th> <td><?php echo T('Thumbnail'); ?> </td> </tr> </thead> <tbody> <tr> <th> <?php echo Img('uploads/' . ChangeBasename($this->User->Photo, 'p%s'), array('id' => 'cropbox')); ?> </th> <td> <div style="<?php echo 'width:' . $this->ThumbSize . 'px;height:' . $this->ThumbSize . 'px;'; ?> overflow:hidden;"> <?php echo Img('uploads/' . ChangeBasename($this->User->Photo, 'p%s'), array('id' => 'preview')); ?> </div> </td> </tr> </tbody> </table> <?php echo $this->Form->Close('Save');
<?php if (!defined('APPLICATION')) exit(); if ($this->User->Photo != '') { ?> <div class="Photo"> <?php if (strpos($this->User->Photo, 'http') === 0) echo Img($this->User->Photo); else echo Img(Gdn_Upload::Url(ChangeBasename($this->User->Photo, 'p%s'))); ?> </div> <?php }
public function Base_BeforeAddCss_Handler($Sender) { $WebRoot = Gdn::Request()->WebRoot(); // Find all css file paths $CssToCache = array(); foreach ($Sender->CssFiles() as $CssInfo) { $CssFile = $CssInfo['FileName']; if (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 = $Sender->ApplicationFolder; } // CSS comes from one of four places: $CssPaths = array(); if ($Sender->Theme) { // 1. Application-specific css. eg. root/themes/theme_name/app_name/design/ // $CssPaths[] = PATH_THEMES . DS . $Sender->Theme . DS . $AppFolder . DS . 'design' . DS . $CssGlob; // 2. Theme-wide theme view. eg. root/themes/theme_name/design/ // a) Check to see if a customized version of the css is there. if ($Sender->ThemeOptions) { $Filenames = GetValueR('Styles.Value', $Sender->ThemeOptions); if (is_string($Filenames) && $Filenames != '%s') { $CssPaths[] = PATH_THEMES . DS . $Sender->Theme . DS . 'design' . DS . ChangeBasename($CssFile, $Filenames); } } // b) Use the default filename. $CssPaths[] = PATH_THEMES . DS . $Sender->Theme . DS . 'design' . DS . $CssFile; } // 3. 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; } } if ($CssPath !== FALSE) { $CssPath = substr($CssPath, strlen(PATH_ROOT) + 1); $CssPath = str_replace(DS, '/', $CssPath); $CssToCache[] = $CssPath; } } $CssToCache = array_unique($CssToCache); // And now search for/add all JS files $JsToCache = array(); // Add the global js files $GlobalJS = array('jquery.js', 'jquery.livequery.js', 'jquery.form.js', 'jquery.popup.js', 'jquery.gardenhandleajaxform.js', 'global.js'); foreach ($Sender->JsFiles() as $JsInfo) { $JsFile = $JsInfo['FileName']; // Ignore the JsFile if it is in the globaljs minify group (defined in plugins/Minifiy/min/groupsConfig.php). if (!in_array($JsFile, $GlobalJS)) { if (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 = $Sender->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 ($Sender->Theme) { // 1. Application-specific js. eg. root/themes/theme_name/app_name/design/ $JsPaths[] = PATH_THEMES . DS . $Sender->Theme . DS . $AppFolder . DS . 'js' . DS . $JsFile; // 2. Garden-wide theme view. eg. root/themes/theme_name/design/ $JsPaths[] = PATH_THEMES . DS . $Sender->Theme . DS . 'js' . DS . $JsFile; } // 3. This application folder $JsPaths[] = PATH_APPLICATIONS . DS . $AppFolder . DS . 'js' . DS . $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) { $JsPath = str_replace(array(PATH_ROOT, DS), array('', '/'), $JsPath); $JsPath = substr($JsPath, 0, 1) == '/' ? substr($JsPath, 1) : $JsPath; $JsToCache[] = $JsPath; } } } $JsToCache = array_unique($JsToCache); // Remove all js & css from the controller $Sender->ClearCssFiles(); $Sender->ClearJsFiles(); // Add minified css & js directly to the head module $Url = 'plugins/Minify/min/?'; $BasePath = Gdn::Request()->WebRoot(); if ($BasePath != '') { $BasePath = 'b=' . $BasePath . '&'; } $Sender->Head->AddCss($Url . $BasePath . 'f=' . implode(',', $CssToCache), 'screen'); $Sender->Head->AddScript($Url . 'g=globaljs'); $Sender->Head->AddScript($Url . $BasePath . 'f=' . implode(',', $JsToCache)); }
$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>
$Col = 0; $Classes = array('FirstCol', 'MiddleCol', 'LastCol'); foreach ($this->data('ThemeInfo.Options.Styles') as $Key => $Options) { $Basename = val('Basename', $Options, '%s'); if ($Col == 0) { echo '<tr>'; } $Active = ''; if ($this->data('ThemeOptions.Styles.Key') == $Key || !$this->data('ThemeOptions.Styles.Key') && $Basename == '%s') { $Active = ' Active'; } $KeyID = str_replace(' ', '_', $Key); echo "<td id=\"{$KeyID}_td\" class=\"{$Classes[$Col]}{$Active}\">"; echo '<h4>', t($Key), '</h4>'; // Look for a screenshot for for the style. $Screenshot = SafeGlob(PATH_THEMES . DS . $this->data('ThemeFolder') . DS . 'design' . DS . ChangeBasename('screenshot.*', $Basename), array('gif', 'jpg', 'png')); if (is_array($Screenshot) && count($Screenshot) > 0) { $Screenshot = basename($Screenshot[0]); echo img('/themes/' . $this->data('ThemeFolder') . '/design/' . $Screenshot, array('alt' => t($Key), 'width' => '160')); } $Disabled = $Active ? ' Disabled' : ''; echo '<div class="Buttons">', anchor(t('Select'), '?style=' . urlencode($Key), 'SmallButton SelectThemeStyle' . $Disabled, array('Key' => $Key)), '</div>'; if (isset($Options['Description'])) { echo '<div class="Info2">', $Options['Description'], '</div>'; } echo '</td>'; $Col = ($Col + 1) % 3; if ($Col == 0) { echo '</tr>'; } }
/** * 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 ''; }
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 ''; } }
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); }
function UserPhoto($User, $CssClass = '') { $CssClass = $CssClass == '' ? '' : ' class="' . $CssClass . '"'; if ($User->Photo != '') { $IsFullPath = strtolower(substr($User->Photo, 0, 7)) == 'http://' || strtolower(substr($User->Photo, 0, 8)) == 'https://'; $PhotoUrl = $IsFullPath ? $User->Photo : 'uploads/' . ChangeBasename($User->Photo, 'n%s'); //return '<a href="'.Url(DOMAIN.'/account/'.$User->UserID.'/'.urlencode($User->Name)).'"'.$CssClass.'>' return '<a href="' . Url('/profile/' . $User->UserID . '/' . urlencode($User->Name)) . '"' . $CssClass . '>' . Img($PhotoUrl, array('alt' => urlencode($User->Name))) . '</a>'; } else { return ''; } }
public function GetCssFiles($ThemeType, $Basename, $ETag, &$NotFound = NULL) { $NotFound = array(); // Gather all of the css paths. switch ($Basename) { case 'Style': $this->_CssFiles = array(array('style.css', 'dashboard', array('Sort' => -10))); break; case 'Admin': $this->_CssFiles = array(array('admin.css', 'dashboard', array('Sort' => -10))); break; default: $this->_CssFiles = array(); } // Throw an event so that plugins can add their css too. $this->EventArguments['ETag'] = $ETag; $this->EventArguments['ThemeType'] = $ThemeType; $this->FireEvent($Basename . 'Css'); // Include theme customizations last so that they override everything else. switch ($Basename) { case 'Style': $this->AddCssFile('custom.css', FALSE, array('Sort' => 10)); if (Gdn::Controller()->Theme && Gdn::Controller()->ThemeOptions) { $Filenames = GetValueR('Styles.Value', Gdn::Controller()->ThemeOptions); if (is_string($Filenames) && $Filenames != '%s') { $this->AddCssFile(ChangeBasename('custom.css', $Filenames), FALSE, array('Sort' => 11)); } } break; case 'Admin': $this->AddCssFile('customadmin.css', FALSE, array('Sort' => 10)); break; } $this->FireEvent('AfterGetCssFiles'); // Hunt the css files down. $Paths = array(); foreach ($this->_CssFiles as $Info) { $Filename = $Info[0]; $Folder = GetValue(1, $Info); $Options = GetValue(2, $Info); $Css = GetValue('Css', $Options); if ($Css) { // Add some literal Css. $Paths[] = array(FALSE, $Folder, $Options); } else { list($Path, $UrlPath) = self::CssPath($ThemeType, $Filename, $Folder); if ($Path) { $Paths[] = array($Path, $UrlPath, $Options); } else { $NotFound[] = array($Filename, $Folder, $Options); } } } // Sort the paths. usort($Paths, array('AssetModel', '_ComparePath')); return $Paths; }
public static function Link($Path, $Text = FALSE, $Format = NULL, $Options = array()) { $Session = Gdn::Session(); $Class = GetValue('class', $Options, ''); $WithDomain = GetValue('WithDomain', $Options); $Target = GetValue('Target', $Options, ''); if ($Target == 'current') { $Target = trim(Url('', TRUE), '/ '); } if (is_null($Format)) { $Format = '<a href="%url" class="%class">%text</a>'; } switch ($Path) { case 'activity': TouchValue('Permissions', $Options, 'Garden.Activity.View'); break; case 'category': $Breadcrumbs = Gdn::Controller()->Data('Breadcrumbs'); if (is_array($Breadcrumbs) && count($Breadcrumbs) > 0) { $Last = array_pop($Breadcrumbs); $Path = GetValue('Url', $Last); $DefaultText = GetValue('Name', $Last, T('Back')); } else { $Path = '/'; $DefaultText = C('Garden.Title', T('Back')); } if (!$Text) { $Text = $DefaultText; } break; case 'dashboard': $Path = 'dashboard/settings'; TouchValue('Permissions', $Options, array('Garden.Settings.Manage', 'Garden.Settings.View')); if (!$Text) { $Text = T('Dashboard'); } break; case 'home': $Path = '/'; if (!$Text) { $Text = T('Home'); } break; case 'inbox': $Path = 'messages/inbox'; TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text) { $Text = T('Inbox'); } if ($Session->IsValid() && $Session->User->CountUnreadConversations) { $Class = trim($Class . ' HasCount'); $Text .= ' <span class="Alert">' . $Session->User->CountUnreadConversations . '</span>'; } if (!$Session->IsValid()) { $Text = FALSE; } break; case 'forumroot': $Route = Gdn::Router()->GetDestination('DefaultForumRoot'); if (is_null($Route)) { $Path = '/'; } else { $Path = CombinePaths(array('/', $Route)); } break; case 'profile': TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text && $Session->IsValid()) { $Text = $Session->User->Name; } if ($Session->IsValid() && $Session->User->CountNotifications) { $Class = trim($Class . ' HasCount'); $Text .= ' <span class="Alert">' . $Session->User->CountNotifications . '</span>'; } break; case 'user': $Path = 'profile'; TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text && $Session->IsValid()) { $Text = $Session->User->Name; } break; case 'photo': $Path = 'profile'; TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text && $Session->IsValid()) { $IsFullPath = strtolower(substr($Session->User->Photo, 0, 7)) == 'http://' || strtolower(substr($Session->User->Photo, 0, 8)) == 'https://'; $PhotoUrl = $IsFullPath ? $Session->User->Photo : Gdn_Upload::Url(ChangeBasename($Session->User->Photo, 'n%s')); $Text = Img($PhotoUrl, array('alt' => htmlspecialchars($Session->User->Name))); } break; case 'drafts': TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text) { $Text = T('My Drafts'); } if ($Session->IsValid() && $Session->User->CountDrafts) { $Class = trim($Class . ' HasCount'); $Text .= ' <span class="Alert">' . $Session->User->CountDrafts . '</span>'; } break; case 'discussions/bookmarked': TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text) { $Text = T('My Bookmarks'); } if ($Session->IsValid() && $Session->User->CountBookmarks) { $Class = trim($Class . ' HasCount'); $Text .= ' <span class="Count">' . $Session->User->CountBookmarks . '</span>'; } break; case 'discussions/mine': TouchValue('Permissions', $Options, 'Garden.SignIn.Allow'); if (!$Text) { $Text = T('My Discussions'); } if ($Session->IsValid() && $Session->User->CountDiscussions) { $Class = trim($Class . ' HasCount'); $Text .= ' <span class="Count">' . $Session->User->CountDiscussions . '</span>'; } break; case 'signin': case 'signinout': // The destination is the signin/signout toggle link. if ($Session->IsValid()) { if (!$Text) { $Text = T('Sign Out'); } $Path = SignOutUrl($Target); $Class = ConcatSep(' ', $Class, 'SignOut'); } else { if (!$Text) { $Text = T('Sign In'); } $Attribs = array(); $Path = SignInUrl($Target); if (SignInPopup() && strpos(Gdn::Request()->Url(), 'entry') === FALSE) { $Class = ConcatSep(' ', $Class, 'SignInPopup'); } } break; } if ($Text == FALSE && strpos($Format, '%text') !== FALSE) { return ''; } if (GetValue('Permissions', $Options) && !$Session->CheckPermission($Options['Permissions'], FALSE)) { return ''; } $Url = Gdn::Request()->Url($Path, $WithDomain); if ($TK = GetValue('TK', $Options)) { if (in_array($TK, array(1, 'true'))) { $TK = 'TransientKey'; } $Url .= (strpos($Url, '?') === FALSE ? '?' : '&') . $TK . '=' . urlencode(Gdn::Session()->TransientKey()); } if (strcasecmp(trim($Path, '/'), Gdn::Request()->Path()) == 0) { $Class = ConcatSep(' ', $Class, 'Selected'); } // Build the final result. $Result = $Format; $Result = str_replace('%url', $Url, $Result); $Result = str_replace('%text', $Text, $Result); $Result = str_replace('%class', $Class, $Result); return $Result; }
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); } }
// 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 != '') {
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]; }
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 ''; } }
/** * 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'); } if (ArrayHasValue($this->_CssFiles, 'admin.css')) { $this->AddCssFile('customadmin.css'); } $this->EventArguments['CssFiles'] =& $this->_CssFiles; $this->FireEvent('BeforeAddCss'); // And now search for/add all css files foreach ($this->_CssFiles as $CssInfo) { $CssFile = $CssInfo['FileName']; if (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) { // 1. Application-specific css. eg. root/themes/theme_name/app_name/design/ // $CssPaths[] = PATH_THEMES . DS . $this->Theme . DS . $AppFolder . DS . 'design' . DS . $CssGlob; // 2. Theme-wide theme view. eg. root/themes/theme_name/design/ // a) Check to see if a customized version of the css is there. if ($this->ThemeOptions) { $Filenames = GetValueR('Styles.Value', $this->ThemeOptions); if (is_string($Filenames) && $Filenames != '%s') { $CssPaths[] = PATH_THEMES . DS . $this->Theme . DS . 'design' . DS . ChangeBasename($CssFile, $Filenames); } } // b) 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}"; } 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 foreach ($this->_JsFiles as $Index => $JsInfo) { $JsFile = $JsInfo['FileName']; if (strpos($JsFile, '//') !== FALSE) { // This is a link to an external file. $this->Head->AddScript($JsFile); continue; } if (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 $this->Head->SetFavIcon(C('Garden.FavIcon', Asset('themes/' . $this->Theme . '/design/favicon.png'))); // Make sure the head module gets passed into the assets collection. $this->AddModule('Head'); } // Master views come from one of four places: $MasterViewPaths = array(); 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; } } $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); } }
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 Get($UserID = FALSE) { if (!$UserID) { $UserID = Gdn::Session()->UserID; } if (($UserID != Gdn::Session()->UserID || !Gdn::Session()->UserID) && !Gdn::Session()->CheckPermission('Garden.Users.Edit')) { throw new Exception(T('You do not have permission to view other profiles.'), 401); } $UserModel = new UserModel(); // Get the user. $User = $UserModel->GetID($UserID, DATASET_TYPE_ARRAY); if (!$User) { throw new Exception(T('User not found.'), 404); } $PhotoUrl = $User['Photo']; if ($PhotoUrl && strpos($PhotoUrl, '//') == FALSE) { $PhotoUrl = Url('/uploads/' . ChangeBasename($PhotoUrl, 'n%s'), TRUE); } $User['Photo'] = $PhotoUrl; // Remove unwanted fields. $this->Data = ArrayTranslate($User, array('UserID', 'Name', 'Email', 'Photo')); $this->Render(); }
} echo '</div>'; ?> </div> <?php if ($this->PictureData->numRows() > 0) { ?> <div class="PictureBox"> <?php foreach ($this->PictureData->result() as $picture) { echo '<span class="AddonPicture">'; echo '<a rel="popable[gallery]" href="#Pic_' . $picture->AddonPictureID . '"><img src="' . Gdn_Upload::url(ChangeBasename($picture->File, 'at%s')) . '" itemprop="screenshot" /></a>'; if ($session->UserID == $this->data('InsertUserID') || checkPermission('Addons.Addon.Manage')) { echo '<a class="Popup DeletePicture" href="' . Url('/addon/deletepicture/' . $picture->AddonPictureID) . '">x</a>'; } echo '<div id="Pic_' . $picture->AddonPictureID . '" style="display: none;"><img src="' . Gdn_Upload::url(ChangeBasename($picture->File, 'ao%s')) . '" /></div>'; echo '</span>'; } ?> </div> <?php } ?> <h2 class="Questions" style="position:relative;">Questions</h2> <?php if (is_object($this->DiscussionData) && $this->DiscussionData->numRows() > 0) { ?> <ul class="DataList Discussions"> <?php $this->ShowOptions = false; include $this->fetchViewLocation('discussions', 'DiscussionsController', 'vanilla');