예제 #1
0
 public function ActivityController_Render_Before(&$Sender)
 {
     $Session = Gdn::Session();
     if (!$Session->CheckPermission('Plugins.Privacy.Activity')) {
         if (!$Session->IsValid()) {
             Redirect(Gdn::Authenticator()->SignInUrl(Gdn_Url::Request()));
         } else {
             Redirect(Gdn::Config('Routes.DefaultPermission'));
         }
     }
 }
예제 #2
0
 /**
  * Parses the query string looking for supplied request parameters. Places
  * anything useful into this object's Controller properties.
  *
  * @param int $FolderDepth
  * @todo $folderDepth needs a description.
  */
 protected function _AnalyzeRequest($FolderDepth = 2)
 {
     // Here are some examples of what this method could/would receive:
     // /application/controllergroup/controller/method/argn
     // /controllergroup/controller/method/argn
     // /application/controllergroup/controller/argn
     // /controllergroup/controller/argn
     // /controllergroup/controller
     // /application/controller/method/argn
     // /controller/method/argn
     // /application/controller/argn
     // /controller/argn
     // /controller
     // Clear the slate
     $this->_ApplicationFolder = '';
     $this->_ControllerFolder = '';
     $this->_ControllerName = '';
     $this->_ControllerMethod = 'index';
     $this->_ControllerMethodArgs = array();
     // Retrieve and parse the request
     if ($this->Request == '') {
         $this->Request = Gdn_Url::Request();
         $Prefix = strtolower(substr($this->Request, 0, strpos($this->Request, '/')));
         switch ($Prefix) {
             case 'rss':
                 $this->_SyndicationMethod = SYNDICATION_RSS;
                 $this->Request = substr($this->Request, 4);
                 break;
             case 'atom':
                 $this->_SyndicationMethod = SYNDICATION_ATOM;
                 $this->Request = substr($this->Request, 5);
                 break;
             default:
                 $this->_SyndicationMethod = SYNDICATION_NONE;
                 break;
         }
     }
     if ($this->Request == '') {
         $this->Request = $this->Routes['DefaultController'];
     }
     // Check for re-routing
     // Is there a literal match?
     if (isset($this->Routes[$this->Request])) {
         $this->Request = $this->Routes[$this->Request];
     } else {
         // Check for other matching custom routes
         foreach ($this->Routes as $Route => $Destination) {
             // Check for wild-cards
             $Route = str_replace(array(':alphanum', ':num'), array('.+', '[0-9]+'), $Route);
             // Check for a match
             if (preg_match('#^' . $Route . '$#', $this->Request)) {
                 // Do we have a back-reference?
                 if (strpos($Destination, '$') !== FALSE && strpos($this->Request, '(') !== FALSE) {
                     $Destination = preg_replace('#^' . $Route . '$#', $Destination, $this->Request);
                 }
                 $this->Request = $Destination;
             }
         }
     }
     $Parts = explode('/', $this->Request);
     $Length = count($Parts);
     if ($Length == 1 || $FolderDepth <= 0) {
         $FolderDepth = 0;
         $this->_ControllerName = $Parts[0];
         $this->_MapParts($Parts, 0);
         $this->_FetchController(TRUE);
         // Throw an error if this fails because there's nothing else to check
     } else {
         if ($Length == 2) {
             // Force a depth of 1 because only one of the two url parts can be a folder.
             $FolderDepth = 1;
         }
     }
     if ($FolderDepth == 2) {
         // print_r($Parts);
         // echo $Parts[1];
         $this->_ApplicationFolder = $Parts[0];
         $this->_ControllerFolder = $Parts[1];
         $this->_MapParts($Parts, 2);
         if (!$this->_FetchController()) {
             // echo '<div>Failed. AppFolder: '.$this->_ApplicationFolder.'; Cont Folder: '.$this->_ControllerFolder.'; Cont: '.$this->_ControllerName.';</div>';
             $this->_AnalyzeRequest(1);
         }
     } else {
         if ($FolderDepth == 1) {
             // Try the application folder first
             $Found = FALSE;
             if (in_array($Parts[0], $this->EnabledApplicationFolders())) {
                 // Check to see if the first part is an application
                 $this->_ApplicationFolder = $Parts[0];
                 $this->_MapParts($Parts, 1);
                 $Found = $this->_FetchController();
             }
             if (!$Found) {
                 // echo '<div>Failed. AppFolder: '.$this->_ApplicationFolder.'; Cont Folder: '.$this->_ControllerFolder.'; Cont: '.$this->_ControllerName.';</div>';
                 // Check to see if the first part is a controller folder
                 $this->_ApplicationFolder = '';
                 $this->_ControllerFolder = $Parts[0];
                 $this->_MapParts($Parts, 1);
                 if (!$this->_FetchController()) {
                     // echo '<div>Failed. AppFolder: '.$this->_ApplicationFolder.'; Cont Folder: '.$this->_ControllerFolder.'; Cont: '.$this->_ControllerName.';</div>';
                     $this->_AnalyzeRequest(0);
                 }
             }
         }
     }
 }
예제 #3
0
function WriteActivityComment($Comment, &$Sender, &$Session)
{
    ?>
<li id="Activity_<?php 
    echo $Comment->ActivityID;
    ?>
" class="<?php 
    echo $Comment->ActivityType;
    ?>
"><?php 
    if ($Comment->ActivityPhoto != '') {
        if ($Comment->InsertUserID == $Session->UserID) {
            echo '<a href="' . Url('/garden/profile/' . urlencode($Comment->ActivityName)) . '">' . $Sender->Html->Image('uploads/n' . $Comment->ActivityPhoto) . '</a>';
        } else {
            echo $Sender->Html->Image('uploads/n' . $Comment->ActivityPhoto);
        }
    }
    ?>
<h3><?php 
    echo $Session->UserID == $Comment->InsertUserID || $Session->CheckPermission('Garden.Activity.Delete') ? Anchor('Delete', 'garden/activity/delete/' . $Comment->ActivityID . '/' . $Session->TransientKey() . '?Return=' . urlencode(Gdn_Url::Request()), 'Delete') : '';
    ?>
<strong><?php 
    echo Format::ActivityHeadline($Comment, $Sender->ProfileUserID);
    ?>
<em><?php 
    echo Format::Date($Comment->DateInserted);
    ?>
</em></strong></h3>
   <blockquote><?php 
    echo Format::Display($Comment->Story);
    ?>
</blockquote>
</li>
<?php 
}
 public function RemoteSignOutUrl()
 {
     $Session = Gdn::Session();
     $Url = sprintf($this->_SignOutUrl, urlencode(Gdn_Url::Request()));
     $Url = str_replace('{Session_TransientKey}', $Session->TransientKey(), $Url);
     return $Url;
 }
예제 #5
0
// This header is redundantly set in the controller.
//header('X-Garden-Version: '.APPLICATION.' '.APPLICATION_VERSION);
Gdn::FactoryInstall(Gdn::AliasCache, 'Gdn_Cache', CombinePaths(array(PATH_LIBRARY_CORE, 'class.cache.php')), Gdn::FactoryRealSingleton, 'Initialize');
// Default request object
Gdn::FactoryInstall(Gdn::AliasRequest, 'Gdn_Request', PATH_LIBRARY . DS . 'core' . DS . 'class.request.php', Gdn::FactoryRealSingleton, 'Create');
Gdn::Request()->FromEnvironment();
/// Load the configurations for the installed items.
$Gdn_EnabledApplications = Gdn::Config('EnabledApplications', array());
foreach ($Gdn_EnabledApplications as $ApplicationName => $ApplicationFolder) {
    $Gdn_Config->Load(PATH_APPLICATIONS . DS . $ApplicationFolder . DS . 'settings' . DS . 'configuration.php', 'Use');
}
/// Load the custom configurations again so that application setting defaults are overridden.
$Gdn_Config->Load(PATH_CONF . DS . 'config.php', 'Use');
unset($Gdn_Config);
// Redirect to the setup screen if Dashboard hasn't been installed yet.
if (!Gdn::Config('Garden.Installed', FALSE) && strpos(Gdn_Url::Request(), 'setup') === FALSE) {
    header('location: ' . Gdn::Request()->Url('dashboard/setup', TRUE));
    exit;
}
/// Install some of the services.
// Default database.
Gdn::FactoryInstall(Gdn::AliasDatabase, 'Gdn_Database', PATH_LIBRARY . DS . 'database' . DS . 'class.database.php', Gdn::FactorySingleton, array('Database'));
// Database drivers.
Gdn::FactoryInstall('MySQLDriver', 'Gdn_MySQLDriver', PATH_LIBRARY . DS . 'database' . DS . 'class.mysql.driver.php', Gdn::FactoryInstance);
Gdn::FactoryInstall('MySQLStructure', 'Gdn_MySQLStructure', PATH_LIBRARY . DS . 'database' . DS . 'class.mysql.structure.php', Gdn::FactoryInstance);
// Form class
Gdn::FactoryInstall('Form', 'Gdn_Form', PATH_LIBRARY . DS . 'core' . DS . 'class.form.php', Gdn::FactoryInstance);
// Identity, Authenticator & Session.
Gdn::FactoryInstall('Identity', 'Gdn_CookieIdentity', PATH_LIBRARY_CORE . DS . 'class.cookieidentity.php');
Gdn::FactoryInstall(Gdn::AliasSession, 'Gdn_Session', PATH_LIBRARY_CORE . DS . 'class.session.php');
Gdn::FactoryInstall(Gdn::AliasAuthenticator, 'Gdn_Auth', PATH_LIBRARY_CORE . DS . 'class.auth.php', Gdn::FactorySingleton);
예제 #6
0
 function Url($Path = '', $WithDomain = FALSE, $RemoveSyndication = FALSE)
 {
     $Result = Gdn::Request()->Url($Path, $WithDomain);
     return $Result;
     // Cache the rewrite urls config setting in this object.
     static $RewriteUrls = NULL;
     if (is_null($RewriteUrls)) {
         $RewriteUrls = ForceBool(Gdn::Config('Garden.RewriteUrls', FALSE));
     }
     $Prefix = substr($Path, 0, 7);
     if (in_array($Prefix, array('http://', 'https:/'))) {
         return $Path;
     }
     if ($Path == '#' || $Path == '') {
         $Path = Gdn_Url::Request(FALSE, FALSE, $RemoveSyndication) . $Path;
     }
     $Paths = array();
     if (!$WithDomain) {
         $Paths[] = '/';
     }
     $Paths[] = Gdn_Url::WebRoot($WithDomain);
     if (!$RewriteUrls) {
         $Paths[] = 'index.php';
     }
     $Paths[] = $Path;
     return CombinePaths($Paths, '/');
 }
예제 #7
0
 function Url($Destination = '', $WithDomain = FALSE, $RemoveSyndication = FALSE)
 {
     // Cache the rewrite urls config setting in this object.
     static $RewriteUrls = NULL;
     if (is_null($RewriteUrls)) {
         $RewriteUrls = ForceBool(Gdn::Config('Garden.RewriteUrls', FALSE));
     }
     $Prefix = substr($Destination, 0, 7);
     if (in_array($Prefix, array('http://', 'https:/'))) {
         return $Destination;
     } else {
         if ($Destination == '#' || $Destination == '') {
             if ($WithDomain) {
                 return Gdn_Url::Request(TRUE, TRUE, $RemoveSyndication) . $Destination;
             } else {
                 return '/' . Gdn_Url::Request(TRUE, FALSE, $RemoveSyndication) . $Destination;
             }
         } else {
             $Paths = array();
             if (!$WithDomain) {
                 $Paths[] = '/';
             }
             $Paths[] = Gdn_Url::WebRoot($WithDomain);
             if (!$RewriteUrls) {
                 $Paths[] = 'index.php';
             }
             $Paths[] = $Destination;
             return CombinePaths($Paths, '/');
         }
     }
 }
예제 #8
0
	public function DiscussionController_BeforeDiscussion_Handler(&$Sender) {
		echo sprintf($this->Code, Gdn_Url::Request(true, true, true));
	}
 public function SignOutUrl()
 {
     $Url = sprintf($this->_SignOutUrl, urlencode(Gdn_Url::Request()));
     return Gdn::Config('Garden.Authenticator.SignOutUrl');
 }
예제 #10
0
 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;
 }
예제 #11
0
 public function DiscussionController_AfterDiscussionBody_Handler(&$Sender)
 {
     echo '<div class="fb-like" data-href="';
     echo Gdn_Url::Request(true, true, true);
     echo '" data-send="false" data-width="450" data-show-faces="false" data-font="lucida grande"></div>';
 }
예제 #12
0
 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;
 }
예제 #13
0
function WriteActivityComment($Comment, &$Sender, &$Session)
{
    ?>
<li id="Activity_<?php 
    echo $Comment->ActivityID;
    ?>
" class="<?php 
    echo $Comment->ActivityType;
    if ($Comment->ActivityPhoto != '') {
        echo ' HasPhoto';
    }
    ?>
"><?php 
    if ($Comment->ActivityPhoto != '') {
        echo '<a href="' . Url('/garden/profile/' . urlencode($Comment->ActivityName)) . '" class="Photo">' . $Sender->Html->Image('uploads/n' . $Comment->ActivityPhoto) . '</a>';
    }
    echo '<div>';
    echo UserAnchor($Comment->ActivityName, 'Name');
    echo Format::Display($Comment->Story);
    echo '<div class="Meta">';
    echo Format::Date($Comment->DateInserted);
    echo $Session->UserID == $Comment->InsertUserID || $Session->CheckPermission('Garden.Activity.Delete') ? '<span>&bull;</span>' . Anchor('Delete', 'garden/activity/delete/' . $Comment->ActivityID . '/' . $Session->TransientKey() . '?Return=' . urlencode(Gdn_Url::Request())) : '';
    echo '</div>';
    echo '</div>';
    ?>
</li>
<?php 
}
예제 #14
0
    function writeActivityComment($Comment, $Activity)
    {
        $Session = Gdn::session();
        $Author = UserBuilder($Comment, 'Insert');
        $PhotoAnchor = userPhoto($Author, 'Photo');
        $CssClass = 'Item ActivityComment ActivityComment';
        if ($PhotoAnchor != '') {
            $CssClass .= ' HasPhoto';
        }
        ?>
        <li id="ActivityComment_<?php 
        echo $Comment['ActivityCommentID'];
        ?>
" class="<?php 
        echo $CssClass;
        ?>
">
            <?php 
        if ($PhotoAnchor != '') {
            ?>
                <div class="Author Photo"><?php 
            echo $PhotoAnchor;
            ?>
</div>
            <?php 
        }
        ?>
            <div class="ItemContent ActivityComment">
                <?php 
        echo userAnchor($Author, 'Title Name');
        ?>
                <div class="Excerpt"><?php 
        echo Gdn_Format::to($Comment['Body'], $Comment['Format']);
        ?>
</div>
                <div class="Meta">
                    <span class="DateCreated"><?php 
        echo Gdn_Format::date($Comment['DateInserted'], 'html');
        ?>
</span>
                    <?php 
        if (ActivityModel::canDelete($Activity)) {
            echo anchor(t('Delete'), "dashboard/activity/deletecomment?id={$Comment['ActivityCommentID']}&tk=" . $Session->TransientKey() . '&target=' . urlencode(Gdn_Url::Request()), 'DeleteComment');
        }
        ?>
                </div>
            </div>
        </li>
    <?php 
    }
예제 #15
0
 public function ToString($HighlightRoute = '')
 {
     if ($HighlightRoute == '') {
         $HighlightRoute = $this->_HighlightRoute;
     }
     if ($HighlightRoute == '') {
         $HighlightRoute = Gdn_Url::Request();
     }
     $HighlightUrl = Url($HighlightRoute);
     // Apply a sort to the items if given.
     if (is_array($this->Sort)) {
         $Sort = array_flip($this->Sort);
         foreach ($this->Items as $Group => &$Item) {
             if (isset($Sort[$Group])) {
                 $Item['Sort'] = $Sort[$Group];
             } else {
                 $Item['_Sort'] += count($Sort);
             }
             foreach ($Item['Links'] as $Url => &$Link) {
                 if (isset($Sort[$Url])) {
                     $Link['Sort'] = $Sort[$Url];
                 } elseif (isset($Sort[$Link['Text']])) {
                     $Link['Sort'] = $Sort[$Link['Text']];
                 } else {
                     $Link['_Sort'] += count($Sort);
                 }
             }
         }
     }
     // Sort the groups.
     $this->_Compare($this->Items);
     uasort($this->Items, array($this, '_Compare'));
     // Sort the items within the groups.
     foreach ($this->Items as &$Item) {
         $this->_Compare($Item['Links']);
         uasort($Item['Links'], array($this, '_Compare'));
         // Highlight the group.
         if (GetValue('Url', $Item) && Url($Item['Url']) == $HighlightUrl) {
             $Item['Attributes']['class'] = ConcatSep(' ', GetValue('class', $Item['Attributes']), 'Active');
         }
         // Hightlight the correct item in the group.
         foreach ($Item['Links'] as &$Link) {
             if (GetValue('Url', $Link) && Url($Link['Url']) == $HighlightUrl) {
                 $Link['Attributes']['class'] = ConcatSep(' ', GetValue('class', $Link['Attributes']), 'Active');
                 $Item['Attributes']['class'] = ConcatSep(' ', GetValue('class', $Item['Attributes']), 'Active');
             }
         }
     }
     return parent::ToString();
 }
예제 #16
0
 /**
  *
  *
  * @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;
 }
예제 #17
0
function WriteActivityComment($Comment, &$Sender, &$Session)
{
    $Author = UserBuilder($Comment, 'Insert');
    $PhotoAnchor = UserPhoto($Author, 'Photo');
    $CssClass = 'Item ActivityComment ActivityComment';
    if ($PhotoAnchor != '') {
        $CssClass .= ' HasPhoto';
    }
    ?>
<li id="ActivityComment_<?php 
    echo $Comment['ActivityCommentID'];
    ?>
" class="<?php 
    echo $CssClass;
    ?>
">
   <?php 
    if ($PhotoAnchor != '') {
        ?>
   <div class="Author Photo"><?php 
        echo $PhotoAnchor;
        ?>
</div>
   <?php 
    }
    ?>
   <div class="ItemContent ActivityComment">
      <?php 
    echo UserAnchor($Author, 'Title Name');
    ?>
      <div class="Excerpt"><?php 
    echo Gdn_Format::To($Comment['Body'], $Comment['Format']);
    ?>
</div>
      <div class="Meta">
         <span class="DateCreated"><?php 
    echo Gdn_Format::Date($Comment['DateInserted'], 'html');
    ?>
</span>
         <?php 
    if ($Session->UserID == $Comment['InsertUserID'] || $Session->CheckPermission('Garden.Activity.Delete')) {
        echo Anchor(T('Delete'), "dashboard/activity/deletecomment?id={$Comment['ActivityCommentID']}&tk=" . $Session->TransientKey() . '&target=' . urlencode(Gdn_Url::Request()), 'DeleteComment');
    }
    ?>
      </div>
   </div>
</li>
<?php 
}
예제 #18
0
function WriteActivityComment($Comment, &$Sender, &$Session)
{
    $Author = UserBuilder($Comment, 'Activity');
    $PhotoAnchor = UserPhoto($Author, 'Photo');
    $CssClass = 'Item ActivityComment Condensed ' . $Comment->ActivityType;
    if ($PhotoAnchor != '') {
        $CssClass .= ' HasPhoto';
    }
    ?>
<li id="Activity_<?php 
    echo $Comment->ActivityID;
    ?>
" class="<?php 
    echo $CssClass;
    ?>
">
   <?php 
    if ($PhotoAnchor != '') {
        ?>
   <div class="Author Photo"><?php 
        echo $PhotoAnchor;
        ?>
</div>
   <?php 
    }
    ?>
   <div class="ItemContent ActivityComment">
      <?php 
    echo UserAnchor($Author, 'Title Name');
    ?>
      <div class="Excerpt"><?php 
    echo Gdn_Format::Display($Comment->Story);
    ?>
</div>
      <div class="Meta">
         <span class="DateCreated"><?php 
    echo Gdn_Format::Date($Comment->DateInserted);
    ?>
</span>
         <?php 
    if ($Session->UserID == $Comment->InsertUserID || $Session->CheckPermission('Garden.Activity.Delete')) {
        echo Anchor(T('Delete'), 'dashboard/activity/delete/' . $Comment->ActivityID . '/' . $Session->TransientKey() . '?Return=' . urlencode(Gdn_Url::Request()), 'DeleteComment');
    }
    ?>
      </div>
   </div>
</li>
<?php 
}
예제 #19
0
파일: index.php 프로젝트: kidmax/Garden
/*
Copyright 2008, 2009 Mark O'Sullivan
This file is part of Garden.
Garden is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Garden is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Garden.  If not, see <http://www.gnu.org/licenses/>.
Contact Mark O'Sullivan at mark [at] lussumo [dot] com
*/
// Report and track all errors.
error_reporting(E_ALL);
ini_set('display_errors', 'on');
ini_set('track_errors', 1);
ob_start();
// 1. Define the constants we need to get going.
define('APPLICATION', 'Garden');
define('APPLICATION_VERSION', '1.0');
define('DS', DIRECTORY_SEPARATOR);
define('PATH_ROOT', dirname(__FILE__));
// 2. Include the header.
require_once PATH_ROOT . DS . 'bootstrap.php';
// 3. Start the application.
if (strpos(Gdn_Url::Request(), 'gardensetup') === FALSE) {
    Gdn::Session()->Start(Gdn::Authenticator());
}
$Dispatcher = Gdn::Dispatcher();
$EnabledApplications = Gdn::Config('EnabledApplications');
$Dispatcher->EnabledApplicationFolders($EnabledApplications);
$Dispatcher->PassProperty('EnabledApplications', $EnabledApplications);
$Dispatcher->Routes = Gdn::Config('Routes');
// Process the request.
$Dispatcher->Dispatch();
예제 #20
0
 /**
  * Returns the xhtml for the opening of the form (the form tag and all
  * hidden elements).
  *
  * @param array $Attributes An associative array of attributes for the form tag. Here is a list of
  *  "special" attributes and their default values:
  *
  *   Attribute  Options     Default
  *   ----------------------------------------
  *   method     get,post    post
  *   action     [any url]   [The current url]
  *   ajax       TRUE,FALSE  FALSE
  *
  * @return string
  *
  * @todo check that missing DataObject parameter
  */
 public function Open($Attributes = FALSE)
 {
     $Return = '<form';
     if ($this->InputPrefix != '') {
         $Return .= $this->_IDAttribute($this->InputPrefix, $Attributes);
     }
     // Method
     $MethodFromAttributes = ArrayValueI('method', $Attributes);
     $this->Method = $MethodFromAttributes === FALSE ? $this->Method : $MethodFromAttributes;
     // Action
     $ActionFromAttributes = ArrayValueI('action', $Attributes);
     if ($this->Action == '') {
         $this->Action = Url(Gdn_Url::Request());
     }
     $this->Action = $ActionFromAttributes === FALSE ? $this->Action : $ActionFromAttributes;
     $Return .= ' method="' . $this->Method . '"' . ' action="' . $this->Action . '"' . $this->_AttributesToString($Attributes) . ">\n";
     // Postback Key - don't allow it to be posted in the url (prevents csrf attacks & hijacks)
     if ($this->Method != "get") {
         $Session = Gdn::Session();
         $Return .= $this->Hidden('TransientKey', array('value' => $Session->TransientKey()));
         // Also add a honeypot if Forms.HoneypotName has been defined
         $HoneypotName = Gdn::Config('Garden.Forms.HoneypotName');
         if ($HoneypotName) {
             $Return .= $this->Hidden($HoneypotName, array('Name' => $HoneypotName, 'style' => "display: none;"));
         }
     }
     // Render all other hidden inputs that have been defined
     $Return .= $this->GetHidden();
     return $Return;
 }
예제 #21
0
function WriteActivityComment($Comment, &$Sender, &$Session)
{
    $Author = UserBuilder($Comment, 'Activity');
    ?>
<li id="Activity_<?php 
    echo $Comment->ActivityID;
    ?>
" class="<?php 
    echo $Comment->ActivityType;
    if ($Comment->ActivityPhoto != '') {
        echo ' HasPhoto';
    }
    ?>
"><?php 
    echo UserPhoto($Author, 'Photo');
    echo '<div>';
    echo UserAnchor($Author, 'Name');
    echo Format::Display($Comment->Story);
    echo '<div class="Meta">';
    echo Format::Date($Comment->DateInserted);
    echo $Session->UserID == $Comment->InsertUserID || $Session->CheckPermission('Garden.Activity.Delete') ? '<span>&bull;</span>' . Anchor('Delete', 'garden/activity/delete/' . $Comment->ActivityID . '/' . $Session->TransientKey() . '?Return=' . urlencode(Gdn_Url::Request())) : '';
    echo '</div>';
    echo '</div>';
    ?>
</li>
<?php 
}