Esempio n. 1
0
 static function setTag($tagger, $tagged, $tag, $desc = null, $private = false)
 {
     $ptag = Profile_tag::pkeyGet(array('tagger' => $tagger, 'tagged' => $tagged, 'tag' => $tag));
     # if tag already exists, return it
     if (!empty($ptag)) {
         return $ptag;
     }
     $tagger_profile = Profile::staticGet('id', $tagger);
     $tagged_profile = Profile::staticGet('id', $tagged);
     if (Event::handle('StartTagProfile', array($tagger_profile, $tagged_profile, $tag))) {
         if (!$tagger_profile->canTag($tagged_profile)) {
             // TRANS: Client exception thrown trying to set a tag for a user that cannot be tagged.
             throw new ClientException(_('You cannot tag this user.'));
             return false;
         }
         $tags = new Profile_list();
         $tags->tagger = $tagger;
         $count = (int) $tags->count('distinct tag');
         if ($count >= common_config('peopletag', 'maxtags')) {
             // TRANS: Client exception thrown trying to set more tags than allowed.
             throw new ClientException(sprintf(_('You already have created %d or more tags ' . 'which is the maximum allowed number of tags. ' . 'Try using or deleting some existing tags.'), common_config('peopletag', 'maxtags')));
             return false;
         }
         $plist = new Profile_list();
         $plist->query('BEGIN');
         $profile_list = Profile_list::ensureTag($tagger, $tag, $desc, $private);
         if ($profile_list->taggedCount() >= common_config('peopletag', 'maxpeople')) {
             // TRANS: Client exception thrown when trying to add more people than allowed to a list.
             throw new ClientException(sprintf(_('You already have %1$d or more people in list %2$s, ' . 'which is the maximum allowed number.' . 'Try unlisting others first.'), common_config('peopletag', 'maxpeople'), $tag));
             return false;
         }
         $newtag = new Profile_tag();
         $newtag->tagger = $tagger;
         $newtag->tagged = $tagged;
         $newtag->tag = $tag;
         $result = $newtag->insert();
         if (!$result) {
             common_log_db_error($newtag, 'INSERT', __FILE__);
             return false;
         }
         try {
             $plist->query('COMMIT');
             Event::handle('EndTagProfile', array($newtag));
         } catch (Exception $e) {
             $newtag->delete();
             $profile_list->delete();
             throw $e;
             return false;
         }
         $profile_list->taggedCount(true);
         self::blowCaches($tagger, $tagged);
     }
     return $newtag;
 }
Esempio n. 2
0
 /**
  * Create a new list
  *
  * @return boolean success
  */
 function handlePost()
 {
     $name = $this->arg('name');
     if (empty($name)) {
         // mimick twitter
         // TRANS: Client error displayed when trying to create a list without a name.
         print _("A list must have a name.");
         exit(1);
     }
     // twitter creates a new list by appending a number to the end
     // if the list by the given name already exists
     // it makes more sense to return the existing list instead
     $private = null;
     if ($this->arg('mode') === 'public') {
         $private = false;
     } else {
         if ($this->arg('mode') === 'private') {
             $private = true;
         }
     }
     $list = Profile_list::ensureTag($this->auth_user->id, $this->arg('name'), $this->arg('description'), $private);
     if (empty($list)) {
         return false;
     }
     switch ($this->format) {
         case 'xml':
             $this->showSingleXmlList($list);
             break;
         case 'json':
             $this->showSingleJsonList($list);
             break;
         default:
             // TRANS: Client error displayed when coming across a non-supported API method.
             $this->clientError(_('API method not found.'), 404);
     }
     return true;
 }