ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 10328


Ignore:
Timestamp:
Jan 23, 2009, 4:14:19 AM (11 years ago)
Author:
ebihara
Message:

#3111:(opWebAPIPlugin)removed support for searching by GData API protocol, and removed some dummy datas

Location:
OpenPNE3/plugins/opWebAPIPlugin/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/plugins/opWebAPIPlugin/trunk/apps/api/modules/feeds/actions/actions.class.php

    r10201 r10328  
    2020  public function preExecute()
    2121  {
    22     $list = SnsConfigPeer::get('op_web_api_plugin_ip_list');
     22    $list = SnsConfigPeer::get('op_web_api_plugin_ip_list', '127.0.0.1');
    2323    $this->forward404Unless(in_array(@$_SERVER['REMOTE_ADDR'], explode("\n", $list)));
    2424
    25     $this->getResponse()->setHttpHeader('GData-Version', 2);
    2625    $this->getResponse()->setHttpHeader('Content-Type', 'text/xml');
    2726
     
    3736
    3837 /**
    39   * Executes retrieveEntries action
     38  * Executes feedEntries action
    4039  *
    4140  * @param sfRequest $request A request object
    4241  */
    43   public function executeRetrieveEntries($request)
     42  public function executeFeedEntries($request)
    4443  {
    45     $this->result = $this->api->retrieve();
     44    $this->result = $this->api->feed();
     45    $this->forward404Unless($this->result);
     46    return $this->renderText($this->result);
     47  }
     48
     49 /**
     50  * Executes retrieveEntry action
     51  *
     52  * @param sfRequest $request A request object
     53  */
     54  public function executeRetrieveEntry($request)
     55  {
     56    $this->result = $this->api->entry();
    4657    $this->forward404Unless($this->result);
    4758    return $this->renderText($this->result);
  • OpenPNE3/plugins/opWebAPIPlugin/trunk/lib/api/opAPI.class.php

    r10199 r10328  
    2727  public function getParameter($name, $default = null)
    2828  {
    29     if (!isset($this->parameters))
     29    if (!isset($this->parameters[$name]))
    3030    {
    3131      return $default;
     
    3333
    3434    return $this->parameters[$name];
     35  }
     36
     37  public function getGeneralFeed($title)
     38  {
     39    sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url'));
     40    $internalUri = sfContext::getInstance()->getRouting()->getCurrentInternalUri();
     41
     42    $feed = new opGDataDocumentFeed();
     43    $feed->setTitle($title.' - '.opConfig::get('sns_name'));
     44    $feed->setId(md5($internalUri));
     45    $feed->setLink(url_for($internalUri, true), 'self');
     46
     47    return $feed;
    3548  }
    3649
     
    4659    return $result;
    4760  }
    48 
    49   public function createFeedBySNS()
    50   {
    51     $feed = new opGDataDocumentFeed();
    52     $feed->setTitle(opConfig::get('sns_name'));
    53     $feed->setAuthor(opConfig::get('admin_email'), opConfig::get('admin_email'));
    54 
    55     return $feed;
    56   }
    57 
    58   public function parseSearchQueries()
    59   {
    60     $result = array();
    61 
    62     if (isset($this->parameters['id']))
    63     {
    64       $result['id'] = $this->parameters['id'];
    65     }
    66 
    67     if (isset($this->parameters['q']))
    68     {
    69       $fulltext = array('include' => array(), 'exclude' => array());
    70 
    71       $extracted = opToolkit::extractEnclosedStrings($this->parameters['q']);
    72       $words = $extracted['enclosed'];
    73       $queryString = $extracted['base'];
    74 
    75       $words = array_merge($words, explode(' ', $queryString));
    76       foreach ($words as $value)
    77       {
    78         if ($value[0] === '-')
    79         {
    80           $fulltext['exclude'][] = $value;
    81         }
    82         else
    83         {
    84           $fulltext['include'][] = $value;
    85         }
    86       }
    87 
    88       $result['fulltext'] = $fulltext;
    89     }
    90 
    91     return $result;
    92   }
    9361}
  • OpenPNE3/plugins/opWebAPIPlugin/trunk/lib/api/opAPICommunityTopic.class.php

    r10321 r10328  
    1818class opAPICommunityTopic extends opAPI implements opAPIInterface
    1919{
    20   public function retrieve()
     20  public function feed()
    2121  {
    22     $topics = CommunityTopicPeer::retrieveByPks($this->search());
    23     if (!$topics)
     22    if ($id = $this->getParameter('community_id'))
     23    {
     24      $communityTopic = CommunityTopicPeer::retrieveByCommunityId($id);
     25    }
     26    else
     27    {
     28      $communityTopic = CommunityTopicPeer::doSelect(new Criteria());
     29    }
     30
     31    if (!$communityTopic)
    2432    {
    2533      return false;
    2634    }
    2735
    28     sfContext::getInstance()->getConfiguration()->loadHelpers(array('sfImage', 'Asset'));
    29 
    30     $feed = $this->createFeedBySNS();
    31     $feed->setId('http://example.com/');
    32 
    33     foreach ($topics as $topic)
     36    $feed = $this->getGeneralFeed('CommunityTopics');
     37    foreach ($communityTopic as $topic)
    3438    {
    3539      $entry = $feed->addEntry();
    3640      $this->createEntryByTopic($topic, $entry);
    3741    }
    38 
    39     $feed->setUpdated($topic->getUpdatedAt());
     42    $feed->setUpdated($communityTopic[0]->getCreatedAt());
    4043
    4144    return $feed->publish();
     45  }
     46
     47  public function entry()
     48  {
     49    $id = $this->getRequiredParameter('id');
     50    $topic = CommunityTopicPeer::retrieveByPk($id);
     51    $entry = $this->createEntryByTopic($topic);
     52    return $entry->publish();
    4253  }
    4354
     
    97108  }
    98109
    99   public function search()
    100   {
    101     $query = $this->parseSearchQueries();
    102     if (isset($query['id']))
    103     {
    104       return array($query['id']);
    105     }
    106 
    107     $result = array();
    108 
    109     if (false !== $ids = $this->fullTextSearch($query['fulltext']))
    110     {
    111       $result = array_merge($result, $ids);
    112     }
    113 
    114     return $result;
    115   }
    116 
    117   public function fullTextSearch($query)
    118   {
    119     return false;
    120   }
    121 
    122110  protected function createEntryByTopic(CommunityTopic $topic, SimpleXMLElement $entry = null)
    123111  {
    124     sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url'));
     112    sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url', 'opUtil'));
    125113
    126114    $member = $topic->getMember();
     
    133121    $entry = new opGDataDocumentEntry($entry);
    134122    $entry->setTitle($topic->getName());
    135     $entry->setContent($topic->getName());
    136     $entry->setId($topic->getId());
     123    $entry->setId(md5(CommunityTopic::PEER.$topic->getId()));
    137124    $entry->setAuthor($topic->getName(), $mailAddress);
    138125    $entry->setPublished($topic->getCreatedAt());
    139126    $entry->setUpdated($topic->getUpdatedAt());
    140     $entry->setLink(url_for('@feeds_update_entry?model=topic&id='.$topic->getId(), true), 'edit');
     127    $entry->setLink(app_url_for('pc_frontend', 'communityTopic/detail?id='.$topic->getId(), true), 'self', 'alternate');
    141128
    142129    return $entry;
  • OpenPNE3/plugins/opWebAPIPlugin/trunk/lib/api/opAPICommunityTopicComment.class.php

    r10325 r10328  
    1818class opAPICommunityTopicComment extends opAPI implements opAPIInterface
    1919{
    20   public function retrieve()
     20  public function feed()
    2121  {
    22     $comments = CommunityTopicCommentPeer::retrieveByPks($this->search());
    23     if (!$comments)
     22    if ($id = $this->getParameter('topic_id'))
     23    {
     24      $communityTopicComment = CommunityTopicCommentPeer::retrieveByCommunityTopicId($id);
     25    }
     26    else
     27    {
     28      $communityTopicComment = CommunityTopicCommentPeer::doSelect(new Criteria());
     29    }
     30
     31    if (!$communityTopicComment)
    2432    {
    2533      return false;
    2634    }
    2735
    28     sfContext::getInstance()->getConfiguration()->loadHelpers(array('sfImage', 'Asset'));
    29 
    30     $feed = $this->createFeedBySNS();
    31     $feed->setId('http://example.com/');
    32 
    33     foreach ($comments as $comment)
     36    $feed = $this->getGeneralFeed('CommunityTopicComments');
     37    foreach ($communityTopicComment as $comment)
    3438    {
    3539      $entry = $feed->addEntry();
    3640      $this->createEntryByTopicComment($comment, $entry);
    3741    }
    38 
    39     $feed->setUpdated($comment->getUpdatedAt());
     42    $feed->setUpdated($communityTopicComment[0]->getCreatedAt());
    4043
    4144    return $feed->publish();
     45  }
     46
     47  public function entry()
     48  {
     49    $id = $this->getRequiredParameter('id');
     50    $comment = CommunityTopicCommentPeer::retrieveByPk($id);
     51    $entry = $this->createEntryByTopicComment($comment);
     52    return $entry->publish();
    4253  }
    4354
     
    97108  }
    98109
    99   public function search()
    100   {
    101     $query = $this->parseSearchQueries();
    102     if (isset($query['id']))
    103     {
    104       return array($query['id']);
    105     }
    106 
    107     $result = array();
    108 
    109     if (false !== $ids = $this->fullTextSearch($query['fulltext']))
    110     {
    111       $result = array_merge($result, $ids);
    112     }
    113 
    114     return $result;
    115   }
    116 
    117   public function fullTextSearch($query)
    118   {
    119     return false;
    120   }
    121 
    122110  protected function createEntryByTopicComment(CommunityTopicComment $comment, SimpleXMLElement $entry = null)
    123111  {
    124     sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url'));
     112    sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url', 'opUtil'));
    125113
    126114    $member = $comment->getMember();
     
    134122    $entry->setTitle($comment->getCommunityTopic()->getName());
    135123    $entry->setContent($comment->getBody());
    136     $entry->setId($comment->getId());
     124    $entry->setId(md5(CommunityTopicComment::PEER.$comment->getId()));
    137125    $entry->setAuthor($member->getName(), $mailAddress);
    138126    $entry->setPublished($comment->getCreatedAt());
    139127    $entry->setUpdated($comment->getUpdatedAt());
    140     $entry->setLink(url_for('@feeds_update_entry?model=communityTopicComment&id='.$comment->getId(), true), 'edit');
     128    $entry->setLink(app_url_for('pc_frontend', 'communityTopic/detail?id='.$comment->getCommunityTopic()->getId(), true), 'self', 'alternate');
    141129
    142130    return $entry;
  • OpenPNE3/plugins/opWebAPIPlugin/trunk/lib/api/opAPIDiary.class.php

    r10200 r10328  
    1818class opAPIDiary extends opAPI implements opAPIInterface
    1919{
    20   public function retrieve()
     20  public function feed()
    2121  {
    22     $diaries = DiaryPeer::retrieveByPks($this->search());
    23     if (!$diaries)
     22    if ($id = $this->getParameter('member_id'))
     23    {
     24      $diaries = DiaryPeer::getMemberDiaryPager($id, $this->getParameter('_pg', 1));
     25    }
     26    else
     27    {
     28      $diaries = DiaryPeer::getDiaryPager($this->getParameter('_pg', 1));
     29    }
     30
     31    if (!$result = $diaries->getResults())
    2432    {
    2533      return false;
    2634    }
    2735
    28     sfContext::getInstance()->getConfiguration()->loadHelpers(array('sfImage', 'Asset'));
    29 
    30     $feed = $this->createFeedBySNS();
    31     $feed->setId('http://example.com/');
    32 
    33     foreach ($diaries as $diary)
     36    $feed = $this->getGeneralFeed('Diaries');
     37    foreach ($result as $diary)
    3438    {
    3539      $entry = $feed->addEntry();
    3640      $this->createEntryByDiary($diary, $entry);
    3741    }
    38 
    39     $feed->setUpdated($diary->getUpdatedAt());
     42    $feed->setUpdated($result[0]->getCreatedAt());
    4043
    4144    return $feed->publish();
     45  }
     46
     47  public function entry()
     48  {
     49    $id = $this->getRequiredParameter('id');
     50    $diary = DiaryPeer::retrieveByPk($id);
     51    $entry = $this->createEntryByDiary($diary);
     52    return $entry->publish();
    4253  }
    4354
     
    95106  }
    96107
    97   public function search()
    98   {
    99     $query = $this->parseSearchQueries();
    100     if (isset($query['id']))
    101     {
    102       return array($query['id']);
    103     }
    104 
    105     $result = array();
    106 
    107     if (false !== $ids = $this->fullTextSearch($query['fulltext']))
    108     {
    109       $result = array_merge($result, $ids);
    110     }
    111 
    112     return $result;
    113   }
    114 
    115   public function fullTextSearch($query)
    116   {
    117     return false;
    118   }
    119 
    120108  protected function createEntryByDiary(Diary $diary, SimpleXMLElement $entry = null)
    121109  {
    122     sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url'));
     110    sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url', 'opUtil'));
    123111
    124112    $member = $diary->getMember();
     
    132120    $entry->setTitle($diary->getTitle());
    133121    $entry->setContent($diary->getBody());
    134     $entry->setId($diary->getId());
     122    $entry->setId(md5(Diary::PEER.$diary->getId()));
    135123    $entry->setAuthor($member->getName(), $mailAddress);
    136124    $entry->setPublished($diary->getCreatedAt());
    137125    $entry->setUpdated($diary->getUpdatedAt());
    138     $entry->setLink(url_for('@feeds_update_entry?model=diary&id='.$member->getId(), true), 'edit');
     126    $entry->setLink(app_url_for('pc_frontend', '@diary_show?id='.$diary->getId(), true), 'self', 'alternate');
     127    $entry->setLink(app_url_for('mobile_frontend', '@diary_show?id='.$diary->getId(), true), 'self', 'alternate');
    139128
    140129    return $entry;
  • OpenPNE3/plugins/opWebAPIPlugin/trunk/lib/api/opAPIInterface.class.php

    r10199 r10328  
    1818interface opAPIInterface
    1919{
    20   public function retrieve();
     20  public function feed();
     21  public function entry();
    2122  public function insert();
    2223  public function update();
    2324  public function delete();
    24   public function search();
    2525}
  • OpenPNE3/plugins/opWebAPIPlugin/trunk/lib/opWebAPIPluginRouting.class.php

    r10199 r10328  
    2222
    2323    $routes = array(
    24       'feeds_retrieve_entry' => new sfRequestRoute(
    25         '/feeds/:model/*',
    26         array('module' => 'feeds', 'action' => 'retrieveEntries'),
     24      'feeds_feed' => new sfRequestRoute(
     25        '/feeds/:model/feed/*',
     26        array('module' => 'feeds', 'action' => 'feedEntries'),
     27        array('sf_method' => array('get'))
     28      ),
     29
     30      'feeds_entry' => new sfRequestRoute(
     31        '/feeds/:model/id/:id',
     32        array('module' => 'feeds', 'action' => 'retrieveEntry'),
    2733        array('sf_method' => array('get'))
    2834      ),
Note: See TracChangeset for help on using the changeset viewer.