Example #1
0
 static function getTags($tagger, $tagged)
 {
     $tags = array();
     # XXX: store this in memcached
     $profile_tag = new Profile_tag();
     $profile_tag->tagger = $tagger;
     $profile_tag->tagged = $tagged;
     $profile_tag->find();
     while ($profile_tag->fetch()) {
         $tags[] = $profile_tag->tag;
     }
     $profile_tag->free();
     return $tags;
 }
 static function cleanup($profile_list)
 {
     $ptag = new Profile_tag();
     $ptag->tagger = $profile_list->tagger;
     $ptag->tag = $profile_list->tag;
     $ptag->find();
     while ($ptag->fetch()) {
         if (Event::handle('StartUntagProfile', array($ptag))) {
             $orig = clone $ptag;
             $result = $ptag->delete();
             if (!$result) {
                 common_log_db_error($this, 'DELETE', __FILE__);
             }
             Event::handle('EndUntagProfile', array($orig));
         }
     }
 }
Example #3
0
 function hasLocalTags()
 {
     $tags = new Profile_tag();
     $tags->joinAdd(array('tagger', 'user:id'));
     $tags->whereAdd('tagged  = ' . $this->id);
     $tags->whereAdd('tagger != ' . $this->id);
     $tags->limit(0, 1);
     $tags->fetch();
     return $tags->N == 0 ? false : true;
 }
Example #4
0
function initProfileLists()
{
    printfnq("Ensuring all profile tags have a corresponding list...");
    $ptag = new Profile_tag();
    $ptag->selectAdd();
    $ptag->selectAdd('tagger, tag, count(*) as tagged_count');
    $ptag->whereAdd('NOT EXISTS (SELECT tagger, tagged from profile_list ' . 'where profile_tag.tagger = profile_list.tagger ' . 'and profile_tag.tag = profile_list.tag)');
    $ptag->groupBy('tagger, tag');
    $ptag->orderBy('tagger, tag');
    if ($ptag->find()) {
        while ($ptag->fetch()) {
            $plist = new Profile_list();
            $plist->tagger = $ptag->tagger;
            $plist->tag = $ptag->tag;
            $plist->private = 0;
            $plist->created = common_sql_now();
            $plist->modified = $plist->created;
            $plist->mainpage = common_local_url('showprofiletag', array('tagger' => $plist->getTagger()->nickname, 'tag' => $plist->tag));
            $plist->tagged_count = $ptag->tagged_count;
            $plist->subscriber_count = 0;
            $plist->insert();
            $orig = clone $plist;
            // After insert since it uses auto-generated ID
            $plist->uri = common_local_url('profiletagbyid', array('id' => $plist->id, 'tagger_id' => $plist->tagger));
            $plist->update($orig);
        }
    }
    printfnq("DONE.\n");
}
 function showContent()
 {
     // XXX: cache this
     $tags = new Profile_tag();
     $plist = new Profile_list();
     $plist->private = false;
     $tags->joinAdd($plist);
     $tags->selectAdd();
     $tags->selectAdd('profile_tag.tag');
     $tags->selectAdd('count(profile_tag.tag) as weight');
     $tags->groupBy('profile_tag.tag');
     $tags->orderBy('weight DESC');
     $tags->limit(TAGS_PER_PAGE);
     $cnt = $tags->find();
     if ($cnt > 0) {
         $this->elementStart('div', array('id' => 'tagcloud', 'class' => 'section'));
         $tw = array();
         $sum = 0;
         while ($tags->fetch()) {
             $tw[$tags->tag] = $tags->weight;
             $sum += $tags->weight;
         }
         ksort($tw);
         $this->elementStart('dl');
         // TRANS: DT element on on page with public list cloud.
         $this->element('dt', null, _('List cloud'));
         $this->elementStart('dd');
         $this->elementStart('ul', 'tags xoxo tag-cloud');
         foreach ($tw as $tag => $weight) {
             if ($sum) {
                 $weightedSum = $weight / $sum;
             } else {
                 $weightedSum = 0.5;
             }
             $this->showTag($tag, $weight, $weightedSum);
         }
         $this->elementEnd('ul');
         $this->elementEnd('dd');
         $this->elementEnd('dl');
         $this->elementEnd('div');
     } else {
         $this->showEmptyList();
     }
 }