/** * Returns an img tag. */ function Img($Image, $Attributes = '', $WithDomain = FALSE) { if ($Attributes == '') { $Attributes = array(); } if (substr($Image, 0, 7) != 'http://' && $Image != '') { $Image = Asset($Image, $WithDomain); } return '<img src="' . $Image . '"' . Attribute($Attributes) . ' />'; }
/** * 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 (!isUrl($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 = htmlEntityDecode(Gdn_Format::text($this->title('', true))); if ($Title != '') { $this->addTag('meta', array('name' => 'twitter:title', 'property' => 'og:title', 'content' => $Title)); } if (isset($CanonicalUrl)) { $this->addTag('meta', array('property' => 'og:url', 'content' => $CanonicalUrl)); } if ($Description = trim(Gdn_Format::reduceWhiteSpaces($this->_Sender->Description()))) { $this->addTag('meta', array('name' => 'description', 'property' => 'og:description', 'content' => $Description)); } $hasRelevantImage = false; // 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', 'content' => $Logo)); } } else { foreach ($this->_Sender->Image() as $Img) { $this->addTag('meta', array('name' => 'twitter:image', 'property' => 'og:image', 'content' => $Img)); $hasRelevantImage = true; } } // For the moment at least, only discussions are supported. if ($Title && val('DiscussionID', $this->_Sender)) { if ($hasRelevantImage) { $twitterCardType = 'summary_large_image'; } else { $twitterCardType = 'summary'; } // Let's force a description for the image card since it makes sense to see a card with only an image and a title. if (!$Description && $twitterCardType === 'summary_large_image') { $Description = '...'; } // Card && Title && Description are required if ($twitterCardType && $Description) { $this->addTag('meta', array('name' => 'twitter:description', 'content' => $Description)); $this->addTag('meta', array('name' => 'twitter:card', 'content' => $twitterCardType)); } } $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 (val('_hint', $Attributes) == 'inline') { $Path = val('_path', $Attributes); if ($Path && !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; }
function wrap($String, $Tag = 'span', $Attributes = '') { if ($Tag == '') { return $String; } if (is_array($Attributes)) { $Attributes = Attribute($Attributes); } // Strip the first part of the tag as the closing tag - this allows us to // easily throw 'span class="something"' into the $Tag field. $Space = strpos($Tag, ' '); $ClosingTag = $Space ? substr($Tag, 0, $Space) : $Tag; return '<' . $Tag . $Attributes . '>' . $String . '</' . $ClosingTag . '>'; }
/** * * * @param string $HighlightRoute * @return string * @throws Exception */ public function toString($HighlightRoute = '') { if ($HighlightRoute == '') { $HighlightRoute = $this->_HighlightRoute; } if ($HighlightRoute == '') { $HighlightRoute = Gdn_Url::Request(); } $this->fireEvent('BeforeToString'); $Username = ''; $UserID = ''; $Session_TransientKey = ''; $Session = Gdn::session(); $Admin = false; if ($Session->isValid() === true) { $UserID = $Session->User->UserID; $Username = $Session->User->Name; $Session_TransientKey = $Session->TransientKey(); $Admin = $Session->User->Admin > 0 ? true : false; } $Menu = ''; if (count($this->Items) > 0) { // Apply the menu group sort if present... if (is_array($this->Sort)) { $Items = array(); $Count = count($this->Sort); for ($i = 0; $i < $Count; ++$i) { $Group = $this->Sort[$i]; if (array_key_exists($Group, $this->Items)) { $Items[$Group] = $this->Items[$Group]; unset($this->Items[$Group]); } } foreach ($this->Items as $Group => $Links) { $Items[$Group] = $Links; } } else { $Items = $this->Items; } foreach ($Items as $GroupName => $Links) { $ItemCount = 0; $LinkCount = 0; $OpenGroup = false; $Group = ''; foreach ($Links as $Key => $Link) { $CurrentLink = false; $ShowLink = false; $RequiredPermissions = array_key_exists('Permission', $Link) ? $Link['Permission'] : false; if ($RequiredPermissions !== false && !is_array($RequiredPermissions)) { $RequiredPermissions = explode(',', $RequiredPermissions); } // Show if there are no permissions or the user has ANY of the specified permissions or the user is admin $ShowLink = $Admin || $RequiredPermissions === false || Gdn::session()->checkPermission($RequiredPermissions, false); if ($ShowLink === true) { if ($ItemCount == 1) { $Group .= '<ul>'; $OpenGroup = true; } elseif ($ItemCount > 1) { $Group .= "</li>\r\n"; } $Url = val('Url', $Link); if (substr($Link['Text'], 0, 1) === '\\') { $Text = substr($Link['Text'], 1); } else { $Text = str_replace('{Username}', $Username, $Link['Text']); } $Attributes = val('Attributes', $Link, array()); $AnchorAttributes = val('AnchorAttributes', $Link, array()); if ($Url !== false) { $Url = url(str_replace(array('{Username}', '{UserID}', '{Session_TransientKey}'), array(urlencode($Username), $UserID, $Session_TransientKey), $Link['Url'])); $CurrentLink = $Url == url($HighlightRoute); $CssClass = val('class', $Attributes, ''); if ($CurrentLink) { $Attributes['class'] = $CssClass . ' Highlight'; } $Group .= '<li' . Attribute($Attributes) . '><a' . Attribute($AnchorAttributes) . ' href="' . $Url . '">' . $Text . '</a>'; ++$LinkCount; } else { $Group .= '<li' . Attribute($Attributes) . '>' . $Text; } ++$ItemCount; } } if ($OpenGroup === true) { $Group .= "</li>\r\n</ul>\r\n"; } if ($Group != '' && $LinkCount > 0) { $Menu .= $Group . "</li>\r\n"; } } if ($Menu != '') { $Menu = '<ul id="' . $this->HtmlId . '"' . ($this->CssClass != '' ? ' class="' . $this->CssClass . '"' : '') . '>' . $Menu . '</ul>'; } } return $Menu; }
<?php if (!defined('APPLICATION')) exit(); ?> <div> <?php $this->CheckPermissions(); // Loop through all the groups. foreach ($this->Items as $Item) { // Output the group. echo '<div class="Box Group '.GetValue('class', $Item['Attributes']).'">'; if ($Item['Text'] != '') echo "\n", '<h4>', isset($Item['Url']) ? Anchor($Item['Text'], $Item['Url']) : $Item['Text'], '</h4>'; if (count($Item['Links'])) { echo "\n", '<ul class="PanelInfo">'; // Loop through all the links in the group. foreach ($Item['Links'] as $Link) { echo "\n <li".Attribute($Link['Attributes']).">", Anchor($Link['Text'], $Link['Url']); '</li>'; } echo "\n", '</ul>'; } echo "\n", '</div>'; } ?> </div>
function FlashHtml($Movie, $Attributes = array(), $Params = array(), $FlashVars = False) { static $DefaultAttributes = array('width' => 400, 'height' => 300, 'type' => 'application/x-shockwave-flash'); static $DefaultParams = array('allowfullscreen' => 'true', 'allowscriptaccess' => 'always', 'quality' => 'best', 'menu' => 'false'); // BUG: 'wmode' => 'transparent' $ScriptRender = GetValue('ScriptRender', $Attributes, False, True); if (!is_array($Params)) { $Params = array(); } $Params = array_merge($DefaultParams, $Params); $Movie = Asset($Movie, True); // check size if (!array_key_exists('width', $Attributes) || !array_key_exists('height', $Attributes)) { $ImageInfo = GetImageSize($Movie); if ($ImageInfo != False) { $Attributes['width'] = $ImageInfo[0]; $Attributes['height'] = $ImageInfo[1]; } } $Attributes = array_merge($DefaultAttributes, $Attributes); $FlashVars = GetValue('FlashVars', $Attributes, $FlashVars, True); if ($FlashVars != False) { $FlashVars = Gdn_Format::ObjectAsArray($FlashVars); $Vars = array(); foreach ($FlashVars as $Name => $Value) { $Vars[] = $Name . '=' . $Value; } // encodeuricomponent $Params['flashvars'] = implode('&', $Vars); } $MSIE = strpos(ArrayValue('HTTP_USER_AGENT', $_SERVER), 'MSIE') > 0; if ($MSIE != False) { $Mode = GetValue('wmode', $Attributes, False, True); if ($Mode !== False) { $Params['wmode'] = $Mode; } $Params['movie'] = $Movie; $ObjectParams = ''; foreach ($Params as $Name => $Value) { $ObjectParams .= '<param name="' . $Name . '" value="' . $Value . '" />'; } // TODO: ADD CLASSID FOR IE $Result = '<object' . Attribute($Attributes) . '>' . $ObjectParams . '</object>'; } else { $Attributes['src'] = $Movie; $Attributes = array_merge($Attributes, $Params); $Result = '<embed' . Attribute($Attributes) . ' />'; } if ($ScriptRender) { $Result = JavaScript($Result, True); } // detect flash version you should manually return $Result; }
function Wrap($String, $Tag = 'span', $Attributes = '') { if ($Tag == '') return $String; if (is_array($Attributes)) $Attributes = Attribute($Attributes); return '<'.$Tag.$Attributes.'>'.$String.'</'.$Tag.'>'; }
/** * Returns the "show x more (or less) items" link. * * @param string The type of link to return: more or less */ public function ToString($Type = 'more') { if ($this->_PropertiesDefined === FALSE) { trigger_error(ErrorMessage('You must configure the pager with $Pager->Configure() before retrieving the pager.', 'MorePager', 'GetSimple'), E_USER_ERROR); } $Pager = ''; if ($Type == 'more') { $ClientID = $this->ClientID == '' ? '' : $this->ClientID . 'More'; if ($this->Offset + $this->Limit >= $this->TotalRecords) { $Pager = ''; // $this->Offset .' + '. $this->Limit .' >= '. $this->TotalRecords; } else { $ActualRecordsLeft = $RecordsLeft = $this->TotalRecords - $this->_LastOffset; if ($RecordsLeft > $this->Limit) { $RecordsLeft = $this->Limit; } $NextOffset = $this->Offset + $this->Limit; $Pager .= Anchor(sprintf(Translate($this->MoreCode), $ActualRecordsLeft), sprintf($this->Url, $NextOffset, $this->Limit)); } } else { if ($Type == 'less') { $ClientID = $this->ClientID == '' ? '' : $this->ClientID . 'Less'; if ($this->Offset <= 0) { $Pager = ''; } else { $RecordsBefore = $this->Offset; if ($RecordsBefore > $this->Limit) { $RecordsBefore = $this->Limit; } $PreviousOffset = $this->Offset - $this->Limit; if ($PreviousOffset < 0) { $PreviousOffset = 0; } $Pager .= Anchor(sprintf(Translate($this->LessCode), $this->Offset), sprintf($this->Url, $PreviousOffset, $RecordsBefore)); } } } if ($Pager == '') { return $this->PagerEmpty; } else { return sprintf($this->Wrapper, Attribute(array('id' => $ClientID, 'class' => $this->CssClass)), $Pager); } }
$Options[] = Anchor(T('Add'), 'candy/section/add/' . $Node->SectionID, ''); } if (IsContentOwner($Node, 'Candy.Sections.Edit')) { $Options[] = Anchor(T('Edit'), 'candy/section/edit/' . $Node->SectionID, ''); } if ($Node->Depth == 0) { // This is root //$Options[] = Anchor('Properties', 'candy/content/properties/'.$Node->ContentID, ''); } else { if ($PermissionSwap) { $Options[] = Anchor(T('Swap'), 'candy/section/swap/' . $Node->SectionID, ''); } if ($PermissionMove) { $Options[] = Anchor(T('Move'), 'candy/section/move/' . $Node->SectionID, ''); } if ($PermissionDelete) { $Options[] = Anchor(T('Delete'), 'candy/section/delete/' . $Node->SectionID, 'PopConfirm'); } //$Options[] = Anchor('Properties', 'candy/section/properties/'.$Node->SectionID, ''); } echo "\n<li" . Attribute($ItemAttribute) . '>'; echo '<div>'; echo SectionAnchor($Node); if (count($Options) > 0) { echo Wrap(implode(', ', $Options), 'span', array('class' => 'Options')); } echo '</div>'; } echo str_repeat("</li></ul>", $Node->Depth) . '</li>'; echo "</ol>"; }
<?php if (!defined('APPLICATION')) { exit; } $this->CheckPermissions(); // Loop through all the groups. foreach ($this->Items as $Item) { // Output the group. echo '<div class="Box Group ' . GetValue('class', $Item['Attributes']) . '">'; if ($Item['Text'] != '') { echo "\n", '<h4>', isset($Item['Url']) ? anchor($Item['Text'], $Item['Url']) : $Item['Text'], '</h4>'; } if (count($Item['Links'])) { echo "\n", '<ul class="PanelInfo">'; // Loop through all the links in the group. foreach ($Item['Links'] as $Link) { echo "\n <li" . Attribute($Link['Attributes']) . ">", anchor($Link['Text'], $Link['Url']), '</li>'; } echo "\n", '</ul>'; } echo "\n", '</div>'; }
public function ToString() { $String = ''; return $String; // Use native breadcrumbs render if (!$this->bCrumbsWrapped && $this->bAutoWrapCrumbs) { $this->WrapCrumbs(); } $this->FireEvent('BeforeToString'); $CountItems = count($this->Items); if ($CountItems == 0) { return $String; } $LastCrumbLinked = C('Candy.Modules.BreadCrumbsLastCrumbLinked', False); $Count = 0; foreach ($this->Items as $GroupName => $Links) { foreach ($Links as $Key => $Link) { $AnchorAttributes = array(); // not used yet $ListAttributes = array(); $Text = $GroupName; //$Text = ArrayValue('Text', $Link); $Count = $Count + 1; $Attributes = ArrayValue('Attributes', $Link, array()); if ($Count == 1) { $CssClassSuffix = 'First'; $ListAttributes['class'] = 'BreadCrumbs'; } elseif ($Count == $CountItems) { $CssClassSuffix = 'Last'; } else { $CssClassSuffix = ''; } $Attributes['class'] = trim($CssClassSuffix . 'Crumb ' . ArrayValue('class', $Attributes, '')); $Url = ArrayValue('Url', $Link); if ($Url === NULL && GetValue('HomeLink', $Attributes, False, True)) { $Url = '/'; } $AnchorAttributes['href'] = Url($Url, True); $Anchor = '<a' . Attribute($AnchorAttributes) . '>' . $Text . '</a>'; if ($Count == $CountItems) { if ($LastCrumbLinked) { $Text = $Anchor; } $Item = '<li' . Attribute($Attributes) . '>' . $Text . '</li>'; } else { $Item = '<li' . Attribute($Attributes) . '>' . $Anchor; } $String .= str_repeat("\t", $Count); $String .= "\n<ul" . Attribute($ListAttributes) . '>' . $Item; } } $String .= str_repeat("\n</ul></li>", $Count - 1) . '</ul>'; //if (!$this->bCustomAssetTarget) $String = Wrap($String, 'div', array('id' => $this->HtmlId)); $String = Wrap($String, 'div', array('id' => $this->HtmlId)); return $String; }
public function ToString() { $Head = '<title>' . Gdn_Format::Text($this->Title()) . "</title>\n"; // Add the canonical Url if necessary. if (method_exists($this->_Sender, 'CanonicalUrl')) { $CanonicalUrl = $this->_Sender->CanonicalUrl(); $CurrentUrl = Gdn::Request()->Url('', TRUE); if ($CurrentUrl != $CanonicalUrl) { $this->AddTag('link', array('rel' => 'canonical', 'href' => $CanonicalUrl)); } } // Make sure that css loads before js (for jquery) ksort($this->_Tags); // "link" comes before "script" foreach ($this->_Tags as $Tag => $Collection) { $Count = count($Collection); for ($i = 0; $i < $Count; ++$i) { $Head .= '<' . $Tag . Attribute($Collection[$i]) . ($Tag == 'script' ? '></' . $Tag . '>' : ' />') . "\n"; } } $Count = count($this->_Strings); for ($i = 0; $i < $Count; ++$i) { $Head .= $this->_Strings[$i]; } return $Head; }
public function ToStringPrevNext($Type = 'more') { $this->CssClass = ConcatSep(' ', $this->CssClass, 'PrevNextPager'); $CurrentPage = PageNumber($this->Offset, $this->Limit); $Pager = ''; if ($CurrentPage > 1) { $PageParam = 'p' . ($CurrentPage - 1); $Pager .= Anchor(T('Previous'), self::FormatUrl($this->Url, $PageParam), 'Previous'); } $HasNext = TRUE; if ($this->CurrentRecords !== FALSE && $this->CurrentRecords < $this->Limit) { $HasNext = FALSE; } if ($HasNext) { $PageParam = 'p' . ($CurrentPage + 1); $Pager = ConcatSep(' ', $Pager, Anchor('Next', self::FormatUrl($this->Url, $PageParam), 'Next')); } $ClientID = $this->ClientID; $ClientID = $Type == 'more' ? $ClientID . 'After' : $ClientID . 'Before'; if (isset($this->HtmlBefore)) { $Pager = $this->HtmlBefore . $Pager; } return $Pager == '' ? '' : sprintf($this->Wrapper, Attribute(array('id' => $ClientID, 'class' => $this->CssClass)), $Pager); }
public function ToString($HighlightRoute = '') { if ($HighlightRoute == '') { $HighlightRoute = $this->_HighlightRoute; } if ($HighlightRoute == '') { $HighlightRoute = Gdn_Url::Request(); } $Username = ''; $UserID = ''; $Session_TransientKey = ''; $Permissions = array(); $Session = Gdn::Session(); $HasPermissions = FALSE; $Admin = FALSE; if ($Session->IsValid() === TRUE) { $UserID = $Session->User->UserID; $Username = $Session->User->Name; $Session_TransientKey = $Session->TransientKey(); $Permissions = $Session->GetPermissions(); $HasPermissions = count($Permissions) > 0; $Admin = $Session->User->Admin == '1' ? TRUE : FALSE; } $Menu = ''; if (count($this->Items) > 0) { // Apply the menu sort if present... if (is_array($this->Sort)) { $Items = array(); $Count = count($this->Sort); for ($i = 0; $i < $Count; ++$i) { $Group = $this->Sort[$i]; if (array_key_exists($Group, $this->Items)) { $Items[$Group] = $this->Items[$Group]; unset($this->Items[$Group]); } } foreach ($Items as $Group => $Links) { $LinkNames = ConsolidateArrayValuesByKey($Links, 'Text'); $SortedLinks = array(); for ($j = 0; $j < $Count; ++$j) { $SortName = $this->Sort[$j]; $Key = array_search($SortName, $LinkNames); if ($Key !== FALSE) { $SortedLinks[] = $Links[$Key]; unset($Links[$Key]); $LinkNames[$Key] = '-=EMPTY=-'; } } $SortedLinks = array_merge($SortedLinks, $Links); $Items[$Group] = $SortedLinks; } } else { $Items = $this->Items; } // Build the menu foreach ($Items as $GroupName => $Links) { $ItemCount = 0; $LinkCount = 0; $OpenGroup = FALSE; $GroupIsActive = FALSE; $GroupAnchor = ''; $Group = ''; foreach ($Links as $Key => $Link) { $CurrentLink = FALSE; $ShowLink = FALSE; $RequiredPermissions = array_key_exists('Permission', $Link) ? $Link['Permission'] : FALSE; if ($RequiredPermissions !== FALSE && !is_array($RequiredPermissions)) { $RequiredPermissions = explode(',', $RequiredPermissions); } // Show if there are no permissions or the user has the required permissions or the user is admin $ShowLink = $Admin || $RequiredPermissions === FALSE || ArrayInArray($RequiredPermissions, $Permissions, FALSE) === TRUE; if ($ShowLink === TRUE) { if ($ItemCount == 1) { $Group .= '<ul class="PanelInfo">'; $OpenGroup = TRUE; } else { if ($ItemCount > 1) { $Group .= "</li>\r\n"; } } $Url = ArrayValue('Url', $Link); if (substr($Link['Text'], 0, 1) === '\\') { $Text = substr($Link['Text'], 1); } else { $Text = str_replace('{Username}', $Username, $Link['Text']); } $Attributes = ArrayValue('Attributes', $Link, array()); if ($Url !== FALSE) { $Url = str_replace(array('{Username}', '{UserID}', '{Session_TransientKey}'), array(urlencode($Username), $UserID, $Session_TransientKey), $Link['Url']); if (substr($Url, 0, 5) != 'http:') { if ($GroupAnchor == '' && $this->AutoLinkGroups) { $GroupAnchor = $Url; } $Url = Url($Url); $CurrentLink = $Url == Url($HighlightRoute); if ($CurrentLink && !$GroupIsActive) { $GroupIsActive = TRUE; } } $CssClass = ArrayValue('class', $Attributes, ''); if ($CurrentLink) { $Attributes['class'] = $CssClass . ' Active'; } $Group .= '<li' . Attribute($Attributes) . '><a href="' . $Url . '">' . $Text . '</a>'; ++$LinkCount; } else { $GroupAttributes = $Attributes; $GroupName = $Text; } ++$ItemCount; } } if ($OpenGroup === TRUE) { $Group .= "</li>\r\n</ul>\r\n"; $GroupAttributes['class'] = 'Box Group ' . GetValue('class', $GroupAttributes, ''); if ($GroupIsActive) { $GroupAttributes['class'] .= ' Active'; } if ($GroupName != '') { if ($LinkCount == 1 && $GroupName == $Text) { $Group = ''; } $GroupUrl = Url($GroupAnchor); $Group = Wrap(Wrap($GroupAnchor == '' ? $GroupName : "<a href=\"{$GroupUrl}\">{$GroupName}</a>", 'h4') . $Group, 'div', $GroupAttributes); } } if ($Group != '' && $LinkCount > 0) { $Menu .= $Group . "\r\n"; } } if ($Menu != '') { $Menu = '<div' . ($this->HtmlId == '' ? '' : ' id="' . $this->HtmlId . '"') . ' class="' . ($this->CssClass != '' ? $this->CssClass : '') . '">' . $Menu . '</div>'; } } return $Menu; }
public function ToString() { // Add the canonical Url if necessary. if (method_exists($this->_Sender, 'CanonicalUrl')) { $CanonicalUrl = $this->_Sender->CanonicalUrl(); $CurrentUrl = Gdn::Request()->Url('', TRUE); if ($CurrentUrl != $CanonicalUrl) $this->AddTag('link', array('rel' => 'canonical', 'href' => $CanonicalUrl)); } $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']); } } } $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 .= ' />'; $TagStrings[] = $TagString; } $Head .= implode("\n", array_unique($TagStrings)); foreach ($this->_Strings as $String) { $Head .= $String; $Head .= "\n"; } return $Head; }
public function ToString() { // Add the canonical Url if necessary. if (method_exists($this->_Sender, 'CanonicalUrl')) { $CanonicalUrl = $this->_Sender->CanonicalUrl(); $CurrentUrl = Gdn::Request()->Url('', TRUE); if ($CurrentUrl != $CanonicalUrl) { $this->AddTag('link', array('rel' => 'canonical', 'href' => $CanonicalUrl)); } } $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"; // Loop through each tag. foreach ($this->_Tags as $Index => $Attributes) { $Tag = $Attributes[self::TAG_KEY]; unset($Attributes[self::CONTENT_KEY], $Attributes[self::SORT_KEY], $Attributes[self::TAG_KEY]); $Head .= '<' . $Tag . Attribute($Attributes); if (array_key_exists(self::CONTENT_KEY, $Attributes)) { $Head .= '>' . $Attributes[self::CONTENT_KEY] . '</' . $Tag . '>'; } elseif ($Tag == 'script') { $Head .= '></script>'; } else { $Head .= ' />'; } $Head .= "\n"; } foreach ($this->_Strings as $String) { $Head .= $String; $Head .= "\n"; } return $Head; }
<?php if (!defined('APPLICATION')) { exit; } $CheckViewingProperty = 'PageID'; $Page = GetValueR('Page', $this->_Sender); $ViewingID = isset($Page->{$CheckViewingProperty}) ? $Page->{$CheckViewingProperty} : ''; ?> <div class="Box BoxSections"> <ul class="PanelInfo"> <?php foreach ($this->Data('Items') as $Item) { $CssClass = $ViewingID == $Item->{$CheckViewingProperty} ? ' Active' : ''; echo "\n<li" . Attribute('class', $CssClass) . '>'; echo Anchor($Item->Title, GetValue('URI', $Item)); echo '</li>'; } ?> </ul> </div>
/** * Returns the "show x more (or less) items" link. * * @param string The type of link to return: more or less */ public function ToString($Type = 'more') { if ($this->_PropertiesDefined === FALSE) { trigger_error(ErrorMessage('You must configure the pager with $Pager->Configure() before retrieving the pager.', 'MorePager', 'GetSimple'), E_USER_ERROR); } $PageCount = ceil($this->TotalRecords / $this->Limit); $CurrentPage = ceil($this->Offset / $this->Limit) + 1; $PagesToDisplay = 7; $MidPoint = 2; // Middle navigation point for the pager // First page number to display (based on the current page number and the // middle position, figure out which page number to start on). $FirstPage = $CurrentPage - $MidPoint; // $Pager = '<span>TotalRecords: '.$this->TotalRecords.'; Limit: '.$this->Limit.'; Offset: '.$this->Offset.'; PageCount: '.$PageCount.'</span>'; $Pager = ''; $PreviousText = T($this->LessCode); $NextText = T($this->MoreCode); if ($CurrentPage == 1) { $Pager = '<span class="Previous">' . $PreviousText . '</span>'; } else { $PageParam = 'p' . ($CurrentPage - 1); $Pager .= Anchor($PreviousText, sprintf($this->Url, $PageParam), 'Previous'); } // We don't need elipsis at all (ie. 1 2 3 4 5) if ($PageCount <= 1) { // Don't build anything } else { if ($PageCount < 10) { for ($i = 1; $i <= $PageCount; $i++) { $PageParam = 'p' . $i; $Pager .= Anchor($i, sprintf($this->Url, $PageParam), $this->_GetCssClass($i, $CurrentPage)); } } else { if ($FirstPage <= 3) { // We're on a page that is before the first elipsis (ie. 1 2 3 4 5 6 7 ... 81) for ($i = 1; $i <= 7; $i++) { $PageParam = 'p' . $i; $Pager .= Anchor($i, sprintf($this->Url, $PageParam), $this->_GetCssClass($i, $CurrentPage)); } $Pager .= '<span>...</span>'; $Pager .= Anchor($PageCount, sprintf($this->Url, 'p' . $PageCount, $this->Limit)); } else { if ($FirstPage >= $PageCount - 6) { // We're on a page that is after the last elipsis (ie. 1 ... 75 76 77 78 79 80 81) $Pager .= Anchor(1, sprintf($this->Url, '', 'p1')); $Pager .= '<span>...</span>'; for ($i = $PageCount - 6; $i <= $PageCount; $i++) { $PageParam = 'p' . $i; $Pager .= Anchor($i, sprintf($this->Url, $PageParam), $this->_GetCssClass($i, $CurrentPage)); } } else { // We're between the two elipsises (ie. 1 ... 4 5 6 7 8 ... 81) $Pager .= Anchor(1, sprintf($this->Url, '', 'p1')); $Pager .= '<span>...</span>'; for ($i = $CurrentPage - 2; $i <= $CurrentPage + 2; $i++) { $PageParam = 'p' . $i; $Pager .= Anchor($i, sprintf($this->Url, $PageParam), $this->_GetCssClass($i, $CurrentPage)); } $Pager .= '<span>...</span>'; $Pager .= Anchor($PageCount, sprintf($this->Url, 'p' . $PageCount)); } } } } if ($CurrentPage == $PageCount) { $Pager .= '<span class="Next">' . $NextText . '</span>'; } else { $PageParam = 'p' . ($CurrentPage + 1); $Pager .= Anchor($NextText, sprintf($this->Url, $PageParam, ''), 'Next'); // extra sprintf parameter in case old url style is set } if ($PageCount <= 1) { $Pager = ''; } $ClientID = $this->ClientID; $ClientID = $Type == 'more' ? $ClientID . 'After' : $ClientID . 'Before'; return sprintf($this->Wrapper, Attribute(array('id' => $ClientID, 'class' => $this->CssClass)), $Pager); }
public function ToString() { $Head = array(); $Head[] = '<title>' . $this->Title() . '</title>'; // Make sure that css loads before js (for jquery) ksort($this->_Tags); // "link" comes before "script" foreach ($this->_Tags as $Tag => $Collection) { $Count = count($Collection); for ($i = 0; $i < $Count; ++$i) { $Head[] = '<' . $Tag . ' ' . Attribute($Collection[$i]) . ($Tag == 'script' ? '></' . $Tag . '>' : ' />'); } } $Count = count($this->_Strings); for ($i = 0; $i < $Count; ++$i) { $Head[] = $this->_Strings[$i]; } return implode("\n", $Head); }
function Anchor($Text, $Destination = '', $CssClass = '', $Attributes = '', $ForceAnchor = FALSE) { if (!is_array($CssClass) && $CssClass != '') { $CssClass = array('class' => $CssClass); } if ($Destination == '' && $ForceAnchor === FALSE) { return $Text; } if ($Attributes == '') { $Attributes = array(); } if (substr($Destination, 0, 7) != 'http://' && ($Destination != '' || $ForceAnchor === FALSE)) { $Destination = Url($Destination); } return '<a href="' . $Destination . '"' . Attribute($CssClass) . Attribute($Attributes) . '>' . $Text . '</a>'; }
/** * * * @param string $Type * @return string */ public function toStringPrevNext($Type = 'more') { $this->CssClass = ConcatSep(' ', $this->CssClass, 'PrevNextPager'); $CurrentPage = PageNumber($this->Offset, $this->Limit); $Pager = ''; if ($CurrentPage > 1) { $PageParam = 'p' . ($CurrentPage - 1); $Pager .= anchor(t('Previous'), $this->PageUrl($CurrentPage - 1), 'Previous', array('rel' => 'prev')); } $HasNext = true; if ($this->CurrentRecords !== false && $this->CurrentRecords < $this->Limit) { $HasNext = false; } if ($HasNext) { $PageParam = 'p' . ($CurrentPage + 1); $Pager = ConcatSep(' ', $Pager, anchor(t('Next'), $this->PageUrl($CurrentPage + 1), 'Next', array('rel' => 'next'))); } $ClientID = $this->ClientID; $ClientID = $Type == 'more' ? $ClientID . 'After' : $ClientID . 'Before'; if (isset($this->HtmlBefore)) { $Pager = $this->HtmlBefore . $Pager; } return $Pager == '' ? '' : sprintf($this->Wrapper, Attribute(array('id' => $ClientID, 'class' => $this->CssClass)), $Pager); }
/** * Returns the xhtml for a standard input tag. * * @param string $FieldName The name of the field that is being displayed/posted with this input. It * should related directly to a field name in $this->_DataArray. * @param string $Type The type attribute for the input. * @param array $Attributes An associative array of attributes for the input. (e.g. maxlength, onclick, class) * Setting 'InlineErrors' to FALSE prevents error message even if $this->InlineErrors is enabled. * @return string */ public function Input($FieldName, $Type = 'text', $Attributes = FALSE) { if ($Type == 'text' || $Type == 'password') { $CssClass = ArrayValueI('class', $Attributes); if ($CssClass == FALSE) $Attributes['class'] = 'InputBox'; } // Show inline errors? $ShowErrors = $this->_InlineErrors && array_key_exists($FieldName, $this->_ValidationResults); // Add error class to input element if ($ShowErrors) $this->AddErrorClass($Attributes); $Return = '<input type="' . $Type . '"'; $Return .= $this->_IDAttribute($FieldName, $Attributes); if ($Type == 'file') $Return .= Attribute('name', ArrayValueI('Name', $Attributes, $FieldName)); else $Return .= $this->_NameAttribute($FieldName, $Attributes); $Return .= $this->_ValueAttribute($FieldName, $Attributes); $Return .= $this->_AttributesToString($Attributes); $Return .= ' />'; if (strtolower($Type) == 'checkbox') { if (substr($FieldName, -2) == '[]') $FieldName = substr($FieldName, 0, -2); $Return .= '<input type="hidden" name="Checkboxes[]" value="' . $FieldName . '" />'; } // Append validation error message if ($ShowErrors && ArrayValueI('InlineErrors', $Attributes, TRUE)) $Return .= $this->InlineError($FieldName); return $Return; }
public static function Image($Url, $Attributes = '') { return '<img src="' . Asset($Url) . '"' . Attribute($Attributes) . ' />'; }
/** * 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; }
/** * Returns the "show x more (or less) items" link. * * @param string The type of link to return: more or less */ public function toString($Type = 'more') { if ($this->_PropertiesDefined === false) { trigger_error(ErrorMessage('You must configure the pager with $Pager->configure() before retrieving the pager.', 'MorePager', 'GetSimple'), E_USER_ERROR); } // Urls with url-encoded characters will break sprintf, so we need to convert them for backwards compatibility. $this->Url = str_replace(array('%1$s', '%2$s', '%s'), array('{Offset}', '{Size}', '{Offset}'), $this->Url); $Pager = ''; if ($Type == 'more') { $ClientID = $this->ClientID == '' ? '' : $this->ClientID . 'More'; if ($this->Offset + $this->Limit >= $this->TotalRecords) { $Pager = ''; // $this->Offset .' + '. $this->Limit .' >= '. $this->TotalRecords; } else { $ActualRecordsLeft = $RecordsLeft = $this->TotalRecords - $this->_LastOffset; if ($RecordsLeft > $this->Limit) { $RecordsLeft = $this->Limit; } $NextOffset = $this->Offset + $this->Limit; $Pager .= anchor(sprintf(t($this->MoreCode), $ActualRecordsLeft), self::FormatUrl($this->Url, $NextOffset, $this->Limit), '', array('rel' => 'nofollow')); } } elseif ($Type == 'less') { $ClientID = $this->ClientID == '' ? '' : $this->ClientID . 'Less'; if ($this->Offset <= 0) { $Pager = ''; } else { $RecordsBefore = $this->Offset; if ($RecordsBefore > $this->Limit) { $RecordsBefore = $this->Limit; } $PreviousOffset = $this->Offset - $this->Limit; if ($PreviousOffset < 0) { $PreviousOffset = 0; } $Pager .= anchor(sprintf(t($this->LessCode), $this->Offset), self::FormatUrl($this->Url, $PreviousOffset, $RecordsBefore), '', array('rel' => 'nofollow')); } } if ($Pager == '') { return $this->PagerEmpty; } else { return sprintf($this->Wrapper, Attribute(array('id' => $ClientID, 'class' => $this->CssClass)), $Pager); } }
/** * Builds page navigation links. * * @param string $Type Type of link to return: 'more' or 'less'. * @return string HTML page navigation links. */ public function ToString($Type = 'more') { if ($this->_PropertiesDefined === FALSE) trigger_error(ErrorMessage('You must configure the pager with $Pager->Configure() before retrieving the pager.', 'MorePager', 'GetSimple'), E_USER_ERROR); $PageCount = ceil($this->TotalRecords / $this->Limit); $CurrentPage = ceil($this->Offset / $this->Limit) + 1; // Show $Range pages on either side of current $Range = C('Garden.Modules.PagerRange', 3); // String to represent skipped pages $Separator = C('Garden.Modules.PagerSeparator', '…'); // Show current page plus $Range pages on either side $PagesToDisplay = ($Range * 2) + 1; if ($PagesToDisplay + 2 >= $PageCount) { // Don't display an ellipses if the page count is only a little bigger that the number of pages. $PagesToDisplay = $PageCount; } // Urls with url-encoded characters will break sprintf, so we need to convert them for backwards compatibility. $this->Url = str_replace(array('%1$s', '%2$s', '%s'), '{Page}', $this->Url); $Pager = ''; $PreviousText = T($this->LessCode); $NextText = T($this->MoreCode); // Previous if ($CurrentPage == 1) { $Pager = '<span class="Previous">'.$PreviousText.'</span>'; } else { $PageParam = 'p'.($CurrentPage - 1); $Pager .= Anchor($PreviousText, self::FormatUrl($this->Url, $PageParam), 'Previous'); } // Build Pager based on number of pages (Examples assume $Range = 3) if ($PageCount <= 1) { // Don't build anything } else if ($PageCount <= $PagesToDisplay) { // We don't need elipsis (ie. 1 2 3 4 5 6 7) for ($i = 1; $i <= $PageCount ; $i++) { $PageParam = 'p'.$i; $Pager .= Anchor($i, self::FormatUrl($this->Url, $PageParam), $this->_GetCssClass($i, $CurrentPage)); } } else if ($CurrentPage + $Range <= $PagesToDisplay + 1) { // +1 prevents 1 ... 2 // We're on a page that is before the first elipsis (ex: 1 2 3 4 5 6 7 ... 81) for ($i = 1; $i <= $PagesToDisplay; $i++) { $PageParam = 'p'.$i; $Pager .= Anchor($i, self::FormatUrl($this->Url, $PageParam), $this->_GetCssClass($i, $CurrentPage)); } $Pager .= '<span class="Ellipsis">'.$Separator.'</span>'; $Pager .= Anchor($PageCount, self::FormatUrl($this->Url, 'p'.$PageCount, $this->Limit)); } else if ($CurrentPage + $Range >= $PageCount - 1) { // -1 prevents 80 ... 81 // We're on a page that is after the last elipsis (ex: 1 ... 75 76 77 78 79 80 81) $Pager .= Anchor(1, self::FormatUrl($this->Url, 'p1')); $Pager .= '<span class="Ellipsis">'.$Separator.'</span>'; for ($i = $PageCount - ($PagesToDisplay - 1); $i <= $PageCount; $i++) { $PageParam = 'p'.$i; $Pager .= Anchor($i, self::FormatUrl($this->Url, $PageParam), $this->_GetCssClass($i, $CurrentPage)); } } else { // We're between the two elipsises (ex: 1 ... 4 5 6 7 8 9 10 ... 81) $Pager .= Anchor(1, self::FormatUrl($this->Url, 'p1')); $Pager .= '<span class="Ellipsis">'.$Separator.'</span>'; for ($i = $CurrentPage - $Range; $i <= $CurrentPage + $Range; $i++) { $PageParam = 'p'.$i; $Pager .= Anchor($i, self::FormatUrl($this->Url, $PageParam), $this->_GetCssClass($i, $CurrentPage)); } $Pager .= '<span class="Ellipsis">'.$Separator.'</span>'; $Pager .= Anchor($PageCount, self::FormatUrl($this->Url, 'p'.$PageCount)); } // Next if ($CurrentPage == $PageCount) { $Pager .= '<span class="Next">'.$NextText.'</span>'; } else { $PageParam = 'p'.($CurrentPage + 1); $Pager .= Anchor($NextText, self::FormatUrl($this->Url, $PageParam, ''), 'Next'); // extra sprintf parameter in case old url style is set } if ($PageCount <= 1) $Pager = ''; $ClientID = $this->ClientID; $ClientID = $Type == 'more' ? $ClientID.'After' : $ClientID.'Before'; if (isset($this->HtmlBefore)) { $Pager = $this->HtmlBefore.$Pager; } return $Pager == '' ? '' : sprintf($this->Wrapper, Attribute(array('id' => $ClientID, 'class' => $this->CssClass)), $Pager); }
/** * Returns the xhtml for a standard input tag. * * @param string $FieldName The name of the field that is being displayed/posted with this input. It * should related directly to a field name in $this->_DataArray. * @param string $Type The type attribute for the input. * @param array $Attributes An associative array of attributes for the input. ie. maxlength, onclick, * class, etc * @return string */ public function Input($FieldName, $Type = 'text', $Attributes = FALSE) { if ($Type == 'text' || $Type == 'password') { $CssClass = ArrayValueI('class', $Attributes); if ($CssClass == FALSE) { $Attributes['class'] = 'InputBox'; } } $Return = '<input type="' . $Type . '"'; $Return .= $this->_IDAttribute($FieldName, $Attributes); if ($Type == 'file') { $Return .= Attribute('name', ArrayValueI('Name', $Attributes, $FieldName)); } else { $Return .= $this->_NameAttribute($FieldName, $Attributes); } $Return .= $this->_ValueAttribute($FieldName, $Attributes); $Return .= $this->_AttributesToString($Attributes); $Return .= ' />'; if (strtolower($Type) == 'checkbox') { if (substr($FieldName, -2) == '[]') { $FieldName = substr($FieldName, 0, -2); } $Return .= '<input type="hidden" name="Checkboxes[]" value="' . $FieldName . '" />'; } return $Return; }
public function ToString($HighlightRoute = '') { if ($HighlightRoute == '') { $HighlightRoute = $this->_HighlightRoute; } if ($HighlightRoute == '') { $HighlightRoute = Gdn_Url::Request(); } $Username = ''; $UserID = ''; $Session_TransientKey = ''; $Permissions = array(); $Session = Gdn::Session(); $HasPermissions = FALSE; $Admin = FALSE; if ($Session->IsValid() === TRUE) { $UserID = $Session->User->UserID; $Username = $Session->User->Name; $Session_TransientKey = $Session->TransientKey(); $Permissions = $Session->GetPermissions(); $HasPermissions = count($Permissions) > 0; $Admin = $Session->User->Admin == '1' ? TRUE : FALSE; } $Menu = ''; if (count($this->Items) > 0) { // Apply the menu group sort if present... if (is_array($this->Sort)) { $Items = array(); $Count = count($this->Sort); for ($i = 0; $i < $Count; ++$i) { $Group = $this->Sort[$i]; if (array_key_exists($Group, $this->Items)) { $Items[$Group] = $this->Items[$Group]; unset($this->Items[$Group]); } } foreach ($this->Items as $Group => $Links) { $Items[$Group] = $Links; } } else { $Items = $this->Items; } foreach ($Items as $GroupName => $Links) { $ItemCount = 0; $LinkCount = 0; $OpenGroup = FALSE; $Group = ''; foreach ($Links as $Key => $Link) { $CurrentLink = FALSE; $ShowLink = FALSE; $RequiredPermissions = array_key_exists('Permission', $Link) ? $Link['Permission'] : FALSE; if ($RequiredPermissions !== FALSE && !is_array($RequiredPermissions)) { $RequiredPermissions = explode(',', $RequiredPermissions); } // Show if there are no permissions or the user has the required permissions or the user is admin $ShowLink = $Admin || $RequiredPermissions === FALSE || ArrayInArray($RequiredPermissions, $Permissions, FALSE) === TRUE; if ($ShowLink === TRUE) { if ($ItemCount == 1) { $Group .= '<ul>'; $OpenGroup = TRUE; } else { if ($ItemCount > 1) { $Group .= "</li>\r\n"; } } $Url = ArrayValue('Url', $Link); if (substr($Link['Code'], 0, 1) === '\\') { $Text = substr($Link['Code'], 1); } else { $Text = str_replace('{Username}', $Username, Gdn::Translate($Link['Code'])); } $Attributes = ArrayValue('Attributes', $Link, array()); if ($Url !== FALSE) { $Url = str_replace(array('{Username}', '{UserID}', '{Session_TransientKey}'), array(urlencode($Username), $UserID, $Session_TransientKey), $Link['Url']); if (substr($Url, 0, 5) != 'http:') { $Url = Url($Url); $CurrentLink = $Url == Url($HighlightRoute); } $CssClass = ArrayValue('class', $Attributes, ''); if ($CurrentLink) { $Attributes['class'] = $CssClass . ' Highlight'; } $Group .= '<li' . Attribute($Attributes) . '><a href="' . $Url . '">' . $Text . '</a>'; ++$LinkCount; } else { $Group .= '<li' . Attribute($Attributes) . '>' . $Text; } ++$ItemCount; } } if ($OpenGroup === TRUE) { $Group .= "</li>\r\n</ul>\r\n"; } if ($Group != '' && $LinkCount > 0) { $Menu .= $Group . "</li>\r\n"; } } if ($Menu != '') { $Menu = '<ul id="' . $this->HtmlId . '"' . ($this->CssClass != '' ? ' class="' . $this->CssClass . '"' : '') . '>' . $Menu . '</ul>'; } } return $Menu; }
/** * Returns the xhtml for a standard input tag. * * @param string $FieldName The name of the field that is being displayed/posted with this input. It * should related directly to a field name in $this->_DataArray. * @param string $Type The type attribute for the input. * @param array $Attributes An associative array of attributes for the input. (e.g. maxlength, onclick, class) * Setting 'InlineErrors' to FALSE prevents error message even if $this->InlineErrors is enabled. * @return string */ public function Input($FieldName, $Type = 'text', $Attributes = FALSE) { if ($Type == 'text' || $Type == 'password') { $CssClass = ArrayValueI('class', $Attributes); if ($CssClass == FALSE) { $Attributes['class'] = 'InputBox'; } } // Show inline errors? $ShowErrors = $this->_InlineErrors && array_key_exists($FieldName, $this->_ValidationResults); // Add error class to input element if ($ShowErrors) { $this->AddErrorClass($Attributes); } $Return = ''; $Wrap = GetValue('Wrap', $Attributes, FALSE, TRUE); $Strength = GetValue('Strength', $Attributes, FALSE, TRUE); if ($Wrap) { $Return .= '<div class="TextBoxWrapper">'; } if (strtolower($Type) == 'checkbox') { if (isset($Attributes['nohidden'])) { unset($Attributes['nohidden']); } else { $Return .= '<input type="hidden" name="Checkboxes[]" value="' . (substr($FieldName, -2) === '[]' ? substr($FieldName, 0, -2) : $FieldName) . '" />'; } } $Return .= '<input type="' . $Type . '"'; $Return .= $this->_IDAttribute($FieldName, $Attributes); if ($Type == 'file') { $Return .= Attribute('name', ArrayValueI('Name', $Attributes, $FieldName)); } else { $Return .= $this->_NameAttribute($FieldName, $Attributes); } if ($Strength) { $Return .= ' data-strength="true"'; } $Return .= $this->_ValueAttribute($FieldName, $Attributes); $Return .= $this->_AttributesToString($Attributes); $Return .= ' />'; // Append validation error message if ($ShowErrors && ArrayValueI('InlineErrors', $Attributes, TRUE)) { $Return .= $this->InlineError($FieldName); } if ($Type == 'password' && $Strength) { $Return .= <<<PASSWORDMETER <div class="PasswordStrength"> <div class="Background"></div> <div class="Strength"></div> <div class="Separator" style="left: 20%;"></div> <div class="Separator" style="left: 40%;"></div> <div class="Separator" style="left: 60%;"></div> <div class="Separator" style="left: 80%;"></div> <div class="StrengthText"> </div> </div> PASSWORDMETER; } if ($Wrap) { $Return .= '</div>'; } return $Return; }
/** * Take a user object, and writes out an anchor of the user's name to the user's profile. */ function userAnchor($User, $CssClass = null, $Options = null) { static $NameUnique = null; if ($NameUnique === null) { $NameUnique = c('Garden.Registration.NameUnique'); } if (is_array($CssClass)) { $Options = $CssClass; $CssClass = null; } elseif (is_string($Options)) { $Options = array('Px' => $Options); } $Px = GetValue('Px', $Options, ''); $Name = GetValue($Px . 'Name', $User, t('Unknown')); // $Text = GetValue('Text', $Options, htmlspecialchars($Name)); // Allow anchor text to be overridden. $Text = GetValue('Text', $Options, ''); if ($Text == '') { // get all fields since that is better for caching! $profileFields = Gdn::userMetaModel()->getUserMeta($User->UserID, 'Profile.%', 'Profile.'); $Text = $profileFields['Profile.' . c('Nickname.Fieldname')]; if ($Text == '') { $Text = htmlspecialchars($Name); } // return } else { $Text = htmlspecialchars($Name); } $Attributes = array('class' => $CssClass, 'rel' => GetValue('Rel', $Options)); if (isset($Options['title'])) { $Attributes['title'] = $Options['title']; } $UserUrl = UserUrl($User, $Px); return '<a href="' . htmlspecialchars(Url($UserUrl)) . '"' . Attribute($Attributes) . '>' . $Text . '</a>'; }