Issues

ZF-7739: Incorrect parsing of comment ids in Zend_Gdata_YouTube::replyToCommentEntry

Issue Type: Bug Created: 2009-08-31T10:47:42.000+0000 Last Updated: 2012-11-20T20:52:33.000+0000 Status: Closed Fix version(s): Reporter: Lee Parker (wlp1979) Assignee: None Tags: - Zend_Gdata

Related issues: Attachments:

Description

The Zend_Gdata_YouTube::replyToCommentEntry method assumes a certain structure to the id field of comment entries from YouTube. While the way the id field is parsed, corresponds to the documentation for YouTube's api, it doesn't correspond to the id values I'm getting back from YouTube.

Example: Documented ID string: tag:youtube,2008:video:xpI6VNvRTII:comment:F53EAC190E4EA5C9 ID string from YouTube: http://gdata.youtube.com/feeds/api/…

The reason the method needs to parse the ID string is to build the proper href for the in-reply-to link. However, it can get this href directly from the original comment entry by calling $commentEntry->getSelfLink();

Original code:

<pre class="highlight">
    public function replyToCommentEntry($commentEntry, $commentText)
    {
        $newComment = $this->newCommentEntry();
        $newComment->content = $this->newContent()->setText($commentText);
        $commentId = $commentEntry->getId();
        $commentIdArray = explode(':', $commentId);

        // create a new link element
        $inReplyToLinkHref = self::VIDEO_URI . '/' . $commentIdArray[3] .
            '/comments/' . $commentIdArray[5];
        $inReplyToLink = $this->newLink($inReplyToLinkHref,
            self::IN_REPLY_TO_SCHEME, $type="application/atom+xml");
        $links = $newComment->getLink();
        $links[] = $inReplyToLink;
        $newComment->setLink($links);
        $commentFeedPostUrl = self::VIDEO_URI . '/' . $commentIdArray[3] .
            '/comments';
        return $this->insertEntry($newComment,
            $commentFeedPostUrl, 'Zend_Gdata_YouTube_CommentEntry');
    }

Here is my proposed fix:

<pre class="highlight">
    public function replyToCommentEntry($commentEntry, $commentText)
    {
        $newComment = $this->newCommentEntry();
        $newComment->content = $this->newContent()->setText($commentText);

        // create a new link element
        $inReplyToLinkHref = $commentEntry->getSelfLink()->href;
        $inReplyToLink = $this->newLink($inReplyToLinkHref,
            self::IN_REPLY_TO_SCHEME, $type="application/atom+xml");
        $links = $newComment->getLink();
        $links[] = $inReplyToLink;
        $newComment->setLink($links);
        $commentFeedPostUrl = self::VIDEO_URI . '/' . $commentIdArray[3] .
            '/comments';
        return $this->insertEntry($newComment,
            $commentFeedPostUrl, 'Zend_Gdata_YouTube_CommentEntry');
    }

Comments

Posted by Lee Parker (wlp1979) on 2009-08-31T14:08:02.000+0000

I just realized that there is one more place where the data from the parsed id field is used. We need the video id in order to construct the url to which the new comment is posted. So, we get the video id from the "alternate" link in the comment entry which is the standard link to view a video.

Here is my fix corrected to get the video id as well:

<pre class="highlight">
    public function replyToCommentEntry($commentEntry, $commentText)
    {
        $newComment = $this->newCommentEntry();
        $newComment->content = $this->newContent()->setText($commentText);

        // create a new link element
        $inReplyToLinkHref = $commentEntry->getSelfLink()->href;
        $inReplyToLink = $this->newLink($inReplyToLinkHref,
            self::IN_REPLY_TO_SCHEME, $type="application/atom+xml");
        $links = $newComment->getLink();
        $links[] = $inReplyToLink;
        $newComment->setLink($links);
        
        parse_str(parse_url($commentEntry->getAlternateLink()->href, PHP_URL_QUERY), $query);
        $commentFeedPostUrl = self::VIDEO_URI . '/' . $query['v'] .
            '/comments';
        return $this->insertEntry($newComment,
            $commentFeedPostUrl, 'Zend_Gdata_YouTube_CommentEntry');
    }

Posted by Trevor Johns (tjohns) on 2009-08-31T15:17:52.000+0000

Lee, Thanks for reporting this, as well as suggesting a patch.

However, before I can apply your patch, for legal reasons you need to send in a signed copy of the Zend Framework CLA:

<a rel="nofollow" href="http://framework.zend.com/wiki/display/ZFPROP/Contributor+License+Agreement">http://framework.zend.com/wiki/display/&hellip;</a>

Would you be okay doing this? If so, please let me know once your CLA has been received by Zend and you've been added to the developer group in Jira.

Posted by Lee Parker (wlp1979) on 2009-09-28T11:17:01.000+0000

My CLA has finally been received by Zend, and I am in the zf-framework-dev group.

Posted by Rob Allen (rob) on 2012-11-20T20:52:33.000+0000

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts