Issues

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

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:


    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:


    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

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:


    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');
    }

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.

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

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.