Search

@Lewis, don’t worry about that last commit you made. I fixed the line endings issue and committed the change to the integration branch.

Members Extension - A collaborative development project

Check out the Change Log at the end of the README file. I’m trying to make sure that everyone gets the proper attribution for their contributions to this extension. Thank you to everyone who has contributed so far. This should be good proof to anyone who is worried about the ongoing development of extensions where the original creators are absentee. If an extension is considered important and useful for the community, it is very likely that someone will pick up the ball and run with it.

@Lewis, if you do want to undo, there is this resource: http://learn.github.com/p/undoing.html

Thanks Stephen! Also found this gem which I’m going checkout this weekend. Time to get ready for a concert tonight!

@bauhouse, I’m reading through that link I posted above and I caught a mistake. I added content.roles.php then made a change, but did not add again before I committed. I lost an additional change I made to not show the “create new” button as well when the error exists.

Anyways, I’ll make some more changes tomorrow which make sense to my previous commit, so hold off on merging. I’m out!

Thanks, Lewis. I’ll wait.

@bauhouse, I’ve learned a lot in the past 24 hours so hopefully my questions are easier to answer :-)

  1. If I cloned the members repository why am I not able to check out the integration branch? It doesn’t appear to be a branch…

  2. I understand now that when there is a merge conflict there are markers injected into the files to help you locate the conflict. I wasn’t getting any of those markers but there was a conflict. I assume it was the Windows LF… how did you figure that out?

When cloning a repository, the default branch is (usually) the master branch. Not all branches are necessarily included in the cloned repository. You actually need to create the branch locally, then pull from the remote. This will create a new branch that is based on the current branch:

    git checkout -b integration
    git pull origin integration

If the branches are substantially different, it’s may be best to create an empty branch, checkout the branch, then pull from the remote repository.

    git branch integration
    git checkout integration
    git pull origin integration

Not all conflicts involve changes within the files, but usually it does. I don’t know if that explains the lack of markers. I’m still figuring out some of those issues. I found out about the line endings issue when I would clone the symphony-2 repository and discover with a git status that the entire repository had changed. Running a git diff on a specific file would indicate that every line of the file had changed. I tried comparing the files in TextWrangler, and it found no difference. It was very puzzling until I realized that the only thing that was changing was the line endings. When trying to commit the files to GitHub, it seemed ridiculous to me that changing a couple lines still replaced the entire file. So I googled windows git line endings and discovered that this is a common problem.

How do I access data from the Members session in events-PHP?

How do I access data from the Members session in events-PHP?

Member’s data is automatically outputted:

<data>
    <events>
        <member-login-info logged-in="true" id="22">
            ...

No… I want to access it in the source of event.add-comment.php. Sending it via <input type="hidden" /> is not an option (Users could set ther ID manually).

Ah yes, $member-id. I added it to the param pool which should give you access.

Ah yes, $member-id. I added it to the param pool which should give you access.

Sorry, but I don’t understand.

You can access it like all of the other parameters but I don’t think it can be done directly from an event, so I think you’ll need to set up an extension with the following in the driver:

    public function getSubscribedDelegates() {
        return array(
            array(
                'page'      => '/frontend/',
                'delegate'  => 'FrontendParamsResolve',
                'callback'  => 'getID'
            )

    }

    public function getID($context) {
        $member-id = context = $context['params']['member-id']; //probably needs to be a class scope variable
        }
    }

You can access it like all of the other parameters but I don’t think it can be done directly from an event.

Not again. This is such a variable-visibility/accessibility-mess…

Not again. This is such a variable-visibility/accessibility-mess…

Perhaps, but I also may have it wrong.

@bauhouse,I ran out of git/Symphony time this week with school finals getting in the way. I’ll be traveling (sailing in Newport, RI) starting tomorrow for a week and will pick up where I left off on my return. Sorry for the wait.

No worries, Lewis. Happy sailing! I’d rather be sailing too.

At some point I will look into implementing Shibboleth SSO (using SimpleSAMLphp) for the members extension.

But for now all I can think about is my vacation. See you in two weeks. :-)

Guest Role Page Permissions

I’ve been working with the Members extension to find out how to work with displaying the correct navigation, depending on whether the user is logged in to the front end or not. When a member is logged in, the XML looks something like this:

<events>
    <member-login-info logged-in="true" id="16">
        <full-name handle="john-smith">John Smith</full-name>
        <first-name handle="john">John</first-name>
        <last-name handle="smith">Smith</last-name>
        <username username="member" password="4297f44b13955235245b2497399d7a93" />
        <role id="2">Member</role>
        <email handle="user-examplecom">user@example.com</email>
        <permissions>
            <pages>
                <page id="1" />
                <page id="2" />
                <page id="3" />
                <page id="4" />
                <page id="5" />
                <page id="6" />
                <page id="8" />
                <page id="9" />
            </pages>
        </permissions>
    </member-login-info>
</events>

However, when the member is not logged in, the XML looks something like this:

<events>
    <member-login-info logged-in="false" />
</events>

If the XSL template depends on the event XML for page permissions:

<xsl:template match="data/main-navigation">
    <ul id="main-navigation" class="nav">
        <xsl:apply-templates select="entry[page/page/@id = /data/events/member-login-info/permissions/pages/page/@id]" mode="main-navigation"/>
    </ul>
</xsl:template>

<xsl:template match="entry" mode="main-navigation">
    <li>
        <a href="{$root}/{title/@handle}/">
            <xsl:if test="title/@handle = $current-page">
                <xsl:attribute name="class">current</xsl:attribute>
            </xsl:if>
            <xsl:value-of select="title"/>
        </a>
    </li>
</xsl:template>

The current behaviour of the Members extension does not take into account the need for permissions for the default role: Guest. To fix this issue, I’ve modified the buildXML() method to the following:

public function buildXML(){

    if(!empty($this->_member_id)){
        $result = new XMLElement('member-login-info');
        $result->setAttribute('logged-in', 'true');

        if(!$this->Member) $this->initialiseMemberObject();

        $result->setAttributeArray(array('id' => $this->Member->get('id')));

        $entryManager = new EntryManager($this->_Parent);

        foreach($this->Member->getData() as $field_id => $values){

            if(!isset($fieldPool[$field_id]) || !is_object($fieldPool[$field_id]))
                $fieldPool[$field_id] =& $entryManager->fieldManager->fetch($field_id);

            $fieldPool[$field_id]->appendFormattedElement($result, $values, false);

        }

        $role_data = $this->Member->getData($this->roleField());
        $role = $this->fetchRole($role_data['role_id'], true);

        $permission = new XMLElement('permissions');

        $page_permissions = $role->pagePermissions();
        if(is_array($page_permissions) && !empty($page_permissions)){
            $pages = new XMLElement('pages');
            foreach($page_permissions as $page_id) 
                $pages->appendChild(new XMLElement('page', NULL, array('id' => $page_id)));

            $permission->appendChild($pages);
        }

        $event_permissions = $role->eventPermissions();
        if(is_array($event_permissions) && !empty($event_permissions)){

            foreach($event_permissions as $event_handle => $e){
                $obj = new XMLElement($event_handle);

                foreach(array_keys($e) as $action) $obj->appendChild(new XMLElement($action));

                $permission->appendChild($obj);
            }

        }

        $result->appendChild($permission);
    }

    else{
        $result = new XMLElement('member-login-info');
        $result->setAttribute('logged-in', 'false');

        $role_name = Symphony::Database()->fetchVar('name', 0, "SELECT `name` FROM `sym_members_roles` WHERE `id` = '1' ");
        $role_xml = new XMLElement('role', $role_name);
        $role_xml->setAttribute('id', '1');

        $result->appendChild($role_xml);

        $page_permissions = Symphony::Database()->fetchCol('page_id', "SELECT `page_id` FROM `sym_members_roles_page_permissions` WHERE `role_id` = '1' ");
        $permission = new XMLElement('permissions');

        if(is_array($page_permissions) && !empty($page_permissions)){
            $pages = new XMLElement('pages');
            foreach($page_permissions as $page_id) 
                $pages->appendChild(new XMLElement('page', NULL, array('id' => $page_id)));

            $permission->appendChild($pages);
        }

        $result->appendChild($permission);
    }

    return $result;

}

This assumes that the default role will always have the id = ‘1’, since this role cannot be deleted. Now, the Guest role will supply the page ids that are accessible by Guest users.

<member-login-info logged-in="false">
    <role id="1">Guest</role>
    <permissions>
        <pages>
            <page id="2" />
            <page id="3" />
            <page id="4" />
            <page id="6" />
            <page id="8" />
            <page id="9" />
        </pages>
    </permissions>
</member-login-info>

I’ll be pushing this change to the integration branch shortly. Just wanted to document it first.

Looks like a very good improvement. I can’t think of a different way to automagically build the navigation for guests.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details