Beispiel #1
0
function mx_medialink($fname, $hashcode, $hashdir = null, $addin = '', $download = false)
{
    global $s3, $mxuser;
    preg_match('%([^.]+)$%', $fname, $ext);
    if (!$hashdir) {
        $hashdir = $mxuser->hashdir;
    }
    $keyname = 'users/' . $hashdir . '/media/' . $hashcode . $addin . '.' . strtolower($ext[0]);
    if ($addin != '-preview' && $addin != '-small' && $addin != '-thumb') {
        $timeout = '60 minutes';
    } else {
        $timeout = '15 days';
    }
    if (!$download) {
        $url = gets3url($keyname, $timeout);
    } else {
        $url = $s3->get_object_url(MXS3BUCKET, $keyname, $timeout, array('response' => array('content-type' => 'application/octet-stream', 'content-disposition' => 'inline; filename=' . $fname)));
    }
    return mx_secureurl($url);
    //return mx_option('usersURL').'/'.$hashdir.'/media/'.$hashcode.'.'.strtolower($ext[0]);
    //return mx_option('siteurl').'/stream.php?id='.$this->id.'&hc='.$hashcode;
}
Beispiel #2
0
function mx_sharetools($userid, $artist = true)
{
    global $s3, $mxdb;
    $user = mx_getuserpublicinfo($userid);
    mx_checkvalues($user);
    //die(print_r($user,true));
    if ($artist) {
        $name = $user->artistname;
        $page = 'artists';
        $opt = 'artprof';
    } else {
        $name = mx_getname($user);
        $page = 'fans';
        $opt = 'fanprof';
    }
    if (!$name) {
        return _('Available Soon');
    }
    //die(print_r($user,true));
    //if (!is_admin()) return _('Available Soon');
    // big badges
    $fmt = array('large' => '150px wide', 'small' => '100px wide', 'square' => '80px x 96px');
    // smaller on-musxpand badges
    $badgesize = array(_('Small') => '-small', _('Large') => '');
    $badgecolor = array(_('White') => '', _('Black') => '-black');
    if (!$user->badges) {
        // QR codes generation
        /*
        $xcard=new XMLWriter();
        $xcard->openMemory();
        $xcard->startDocument('1.0','UTF-8');
        $xcard->startElementNs(null,'vcards','urn:ietf:params:xml:ns:vcard-4.0');
        $xcard->startElement('vcard');
        
        $xcard->startElement('n'); // name
        $xcard->startElement('surname'); // family name
        $xcard->text($user->lastname);
        $xcard->endElement(); // surname
        $xcard->startElement('given'); // first name
        $xcard->text($user->firstname);
        $xcard->endElement(); // given
        $xcard->endElement(); // n
        
        $xcard->startElement('fn'); // fullname
        $xcard->startElement('text'); // text
        $xcard->text($name);
        $xcard->endElement(); // text
        $xcard->endElement(); // fn
        
        $xcard->startElement('org'); // org
        $xcard->startElement('text'); // text
        $xcard->text('MusXpand');
        $xcard->endElement(); // text
        $xcard->endElement(); // org
        
        $xcard->startElement('title'); // shortbio
        $xcard->startElement('text'); // text
        $xcard->text($user->about);
        $xcard->endElement(); // text
        $xcard->endElement(); // shortbio
        
        $xcard->startElement('photo'); // photo
        $xcard->startElement('uri'); // URI
        $xcard->text(mx_fanpic($user->id,'small',$user->gender,$isartist));
        $xcard->endElement(); // URI
        $xcard->endElement(); // photo
        
        $xcard->startElement('adr'); // address
        $xcard->startElement('parameters'); // parameters
        $xcard->startElement('type'); // type
        $xcard->text($isartist?'work':'home');
        $xcard->endElement(); // type
        $xcard->startElement('label'); // label
        $location='';
        if ($user->city) $location.=$user->city;
        if ($user->state) $location.=($location?', ':'').$user->state;
        if ($user->country) $location.=($location?'\n':'').mx_getcountryname($user->country);
        $xcard->text($location);
        $xcard->endElement(); // label
        $xcard->startElement('locality'); // locality
        $xcard->text($user->city);
        $xcard->endElement(); // locality
        $xcard->startElement('region'); // region
        $xcard->text($user->state);
        $xcard->endElement(); // region
        $xcard->startElement('country'); // country
        $xcard->text(mx_getcountryname($user->country));
        $xcard->endElement(); // country
        $xcard->endElement(); // parameters
        $xcard->endElement(); // address
        
        $xcard->startElement('email'); // country
        $xcard->startElement('text'); // text
        $xcard->text($user->email);
        $xcard->endElement(); // text
        $xcard->endElement(); // email
        
        $xcard->startElement('rev'); // revision
        $xcard->startElement('timestamp'); // date
        $xcard->text(gmdate('Ymd\THis\Z'));
        $xcard->endElement(); // date
        $xcard->endElement(); // rev
        
        $xcard->endElement(); // vcard
        $xcard->endElement(); // vcards
        
        $xvcard=$xcard->flush();
        */
        $saveart = $artist;
        foreach (array(true, false) as $artist) {
            $vcard = 'BEGIN:VCARD' . CRLF . 'VERSION:4.0' . CRLF;
            //$vcard.='SOURCE:'.mx_option('siteurl').'/vcf.php?a='.$user->id.CRLF;
            $vcard .= 'KIND:individual' . CRLF;
            //$vcard.='XML:'.$xvcard.CRLF;
            if ($artist) {
                $vcard .= 'FN:' . $name . CRLF;
                $vcard .= 'N:' . $user->lastname . ';' . $user->firstname . CRLF;
            } else {
                $vcard .= 'FN:' . $user->fullname . CRLF;
                $vcard .= 'N:' . $user->lastname . ';' . $user->firstname . CRLF;
            }
            $vcard .= 'PHOTO:' . mx_fanpic($user->id, 'small', $user->gender, $artist) . CRLF;
            if ($user->gender != MXNOSEX) {
                $vcard .= 'GENDER:' . ($user->gender == MXSEXMALE ? 'M' : 'F') . CRLF;
            }
            if ($user->birthdate) {
                $vcard .= 'BDAY:' . str_replace('-', '', $user->birthdate) . CRLF;
            }
            $vcard .= 'ADR;TYPE=' . ($artist ? 'work' : 'home') . ':;;;' . $user->city . ';' . $user->state . ';;' . mx_getcountryname($user->country) . CRLF;
            $vcard .= 'EMAIL:' . $user->email . CRLF;
            if ($user->timezone) {
                $vcard .= 'TZ:' . $user->timezone . CRLF;
            }
            if ($user->about) {
                $vcard .= 'TITLE:"' . $user->shortbio . '"' . CRLF;
            }
            $vcard .= 'LOGO:' . mx_option('logoURL') . CRLF;
            //$vcard.='ORG:'.CRLF;
            $vcard .= 'UID:urn:uuid:' . $user->hashdir . CRLF;
            $vcard .= 'URL:' . mx_actionurl($artist ? 'artists' : 'fans', $artist ? 'artprof' : 'fanprof', $user->id) . CRLF;
            $vcard .= 'REV:' . gmdate('Ymd\\THis\\Z') . CRLF;
            $vcard .= 'END:VCARD' . CRLF;
            QRcode::png($vcard, mx_option('usersdir') . '/tmp/' . $user->hashdir . '_QR' . ($artist ? 'a' : 'f') . '.png', 'L', 2, 4);
            $keyname = 'users/' . $user->hashdir . '/pics/qr_' . ($artist ? 'a' : 'f') . '.png';
            $res = $s3->create_object(MXS3BUCKET, $keyname, array('fileUpload' => mx_option('usersdir') . '/tmp/' . $user->hashdir . '_QR' . ($artist ? 'a' : 'f') . '.png', 'acl' => AmazonS3::ACL_PUBLIC));
            //@unlink(mx_option('usersdir').'/tmp/'.$user->hashdir.'_'.$value.'.jpg');
            file_put_contents(mx_option('usersdir') . '/tmp/' . $user->hashdir . '_vCard' . ($artist ? 'a' : 'f') . '.vcf', $vcard);
            $keyname = 'users/' . $user->hashdir . '/pics/vCard_' . ($artist ? 'a' : 'f') . '.vcf';
            $res = $s3->create_object(MXS3BUCKET, $keyname, array('fileUpload' => mx_option('usersdir') . '/tmp/' . $user->hashdir . '_vCard' . ($artist ? 'a' : 'f') . '.vcf', 'acl' => AmazonS3::ACL_PUBLIC));
            @unlink(mx_option('usersdir') . '/tmp/' . $user->hashdir . '_vCard' . ($artist ? 'a' : 'f') . '.vcf');
        }
        $artist = $saveart;
    }
    if (!$user->badges) {
        // badges generation
        ini_set('allow_url_fopen', 1);
        $keyname = 'users/' . $user->hashdir . '/pics/me_large.jpg';
        $picurl = mx_secureurl(gets3url($keyname, '2 minutes'));
        // load pic
        $pic = imagecreatefromjpeg($picurl);
        if (!$pic) {
            $pic = imagecreatefrompng(mx_fanpic($user->id, 'large', $user->gender, false));
        }
        $w = imagesx($pic);
        $h = imagesy($pic);
        $nhl = round($h * 150 / $w);
        $nhs = round($h * 100 / $w);
        $mwh = min($w, $h);
        $imlarge = imagecreatetruecolor(150, $nhl + 16);
        $imsmall = imagecreatetruecolor(100, $nhs + 16);
        $imsquare = imagecreatetruecolor(80, 80 + 16);
        $fgl = imagecolorallocate($imlarge, 255, 255, 255);
        $fgs = imagecolorallocate($imsmall, 255, 255, 255);
        $fgq = imagecolorallocate($imsquare, 255, 255, 255);
        $bgl = imagecolorallocate($imlarge, 0xff, 0xff, 0x99);
        $bgs = imagecolorallocate($imsmall, 0xff, 0xff, 0x99);
        $bgq = imagecolorallocate($imsquare, 0xff, 0xff, 0x99);
        //imagefill($imlarge,0,0,$fcl);
        //imagefill($imsmall,0,0,$fcs);
        //imagefill($imsquare,0,0,$fcq);
        //imagefilledrectangle($imlarge,1,$nhl,148,$nhl+14,$bgl);
        //imagefilledrectangle($imsmall,1,$nhs,98,$nhs+14,$bgs);
        //imagefilledrectangle($imsquare,1,80,78,80+14,$bgq);
        imageline($imlarge, 0, $nhl - 1, 150 - 1, $nhl - 1, $fgl);
        imageline($imsmall, 0, $nhs - 1, 100 - 1, $nhs - 1, $fgs);
        imageline($imsquare, 0, 80 - 1, 80 - 1, 80 - 1, $fgq);
        imageantialias($imlarge, true);
        imageantialias($imsmall, true);
        imageantialias($imsquare, true);
        imagecopyresampled($imlarge, $pic, 1, 1, 0, 0, 150 - 2, $nhl - 2, $w, $h);
        imagecopyresampled($imsmall, $pic, 1, 1, 0, 0, 100 - 2, $nhs - 2, $w, $h);
        imagecopyresampled($imsquare, $pic, 1, 1, $mwh == $h ? ($w - $mwh) / 2 : 0, $mwh == $w ? ($h - $mwh) / 2 : 0, 80 - 2, 80 - 2, $mwh, $mwh);
        // add artistname
        $font = mx_option('rootdir') . '/fonts/HoboStd.otf';
        $textl = $texts = $textq = strtoupper($name);
        while (($factl = 16 / max(array(16, strlen($textl)))) < 0.6) {
            $textl = substr($textl, 0, strrpos($textl, ' ')) . '...';
        }
        while (($facts = 12 / max(array(12, strlen($texts)))) < 0.6) {
            $texts = substr($texts, 0, strrpos($texts, ' ')) . '...';
        }
        while (($factq = 9 / max(array(9, strlen($textq)))) < 0.6) {
            $textq = substr($textq, 0, strrpos($textq, ' ')) . '...';
        }
        $szl = 9.4 * $factl;
        $szs = 9.4 * $facts;
        $szq = 9.4 * $factq;
        $txtl = imagettfbbox($szl, 0, $font, $textl);
        $txts = imagettfbbox($szs, 0, $font, $texts);
        $txtq = imagettfbbox($szq, 0, $font, $textq);
        imagettftext($imlarge, $szl, 0, (150 - $txtl[2] - $txtl[0]) / 2 - 1, $nhl + (16 - $txtl[1] - $txtl[7]) / 2, $fgl, $font, $textl);
        imagettftext($imsmall, $szs, 0, (100 - $txts[2] - $txts[0]) / 2 - 1, $nhs + (16 - $txts[1] - $txts[7]) / 2, $fgs, $font, $texts);
        imagettftext($imsquare, $szq, 0, (80 - $txtq[2] - $txtq[0]) / 2 - 1, 80 + (16 - $txtq[1] - $txtq[7]) / 2, $fgq, $font, $textq);
        /*
        $logo=imagecreatefrompng(mx_option('rootdir').'/images/general/musxpand-logo.png');
        $imlogo=imagerotate($logo,90,0);
        $lw=imagesx($imlogo);
        $lh=imagesy($imlogo);
        imagecopyresampled($imlarge,$imlogo,129,0,0,0,$lw/2,$lh/2,$lw,$lh);
        */
        imagejpeg($imlarge, mx_option('usersdir') . '/tmp/' . $user->hashdir . '_large.jpg');
        imagejpeg($imsquare, mx_option('usersdir') . '/tmp/' . $user->hashdir . '_square.jpg');
        imagejpeg($imsmall, mx_option('usersdir') . '/tmp/' . $user->hashdir . '_small.jpg');
        foreach ($fmt as $value => $desc) {
            $keyname = 'users/' . $user->hashdir . '/pics/badge_' . $value . '.jpg';
            $res = $s3->create_object(MXS3BUCKET, $keyname, array('fileUpload' => mx_option('usersdir') . '/tmp/' . $user->hashdir . '_' . $value . '.jpg', 'acl' => AmazonS3::ACL_PUBLIC));
            @unlink(mx_option('usersdir') . '/tmp/' . $user->hashdir . '_' . $value . '.jpg');
        }
        // mini-badges
        $keyname = 'users/' . $user->hashdir . '/pics/me_square.jpg';
        $picurl = mx_secureurl(gets3url($keyname, '2 minutes'));
        // load pic
        $pic = imagecreatefromjpeg($picurl);
        if (!$pic) {
            $pic = imagecreatefrompng(mx_fanpic($user->id, 'large', $user->gender, false));
        }
        $pw = imagesx($pic);
        $ph = imagesy($pic);
        $badgepref = 'badge-on-musxpand';
        foreach ($badgesize as $sname => $ssuf) {
            switch ($ssuf) {
                case '':
                    $offx = 9;
                    $offy = 1;
                    break;
                case '-small':
                default:
                    $offx = -2;
                    $offy = 1;
                    break;
            }
            foreach ($badgecolor as $cname => $csuf) {
                $badgemask = imagecreatefrompng(mx_option('rootdir') . '/images/badges/' . $badgepref . $ssuf . $csuf . '.png');
                $bw = imagesx($badgemask);
                $bh = imagesy($badgemask);
                $badge = imagecreatetruecolor($bw, $bh);
                //imagepalettecopy($badge, $badgemask);
                $transp = imagecolorallocatealpha($badge, 0, 0, 0, 127);
                imagefill($badge, 0, 0, $transp);
                imageantialias($badge, true);
                //imagealphablending($badge,false);
                //imagealphablending($badgemask,false);
                imagecopyresampled($badge, $pic, floor(($bh - 72) / 2) + $offx, floor(($bh - 72) / 2) + $offy, 0, 0, 72, 72, $pw, $ph);
                imagecopyresampled($badge, $badgemask, 0, 0, 0, 0, $bw, $bh, $bw, $bh);
                imagesavealpha($badge, true);
                $tmpfile = mx_option('usersdir') . '/tmp/' . $user->hashdir . '_mini' . $ssuf . $csuf . '.png';
                imagepng($badge, $tmpfile);
                $keyname = 'users/' . $user->hashdir . '/pics/minibadge' . $ssuf . $csuf . '.png';
                $res = $s3->create_object(MXS3BUCKET, $keyname, array('fileUpload' => $tmpfile, 'acl' => AmazonS3::ACL_PUBLIC));
                @unlink($tmpfile);
            }
        }
        ini_set('allow_url_fopen', 0);
        $user->badges = 1;
        $mxdb->updateuser($user, 'badges');
    }
    $str = '<div class="badges"><table><tr>';
    foreach ($fmt as $value => $desc) {
        $str .= '<th>' . sprintf(_('Badge %s'), $desc) . '</th>';
    }
    $str .= '</tr><tr>';
    foreach ($fmt as $value => $desc) {
        $keyname = 'users/' . $user->hashdir . '/pics/badge_' . $value . '.jpg';
        $str .= '<td><img src="' . mx_secureurl(gets3url($keyname)) . '" /></td>';
    }
    $str .= '</tr><tr>';
    foreach ($fmt as $value => $desc) {
        $str .= '<th>' . _('Code') . '</th>';
    }
    $str .= '</tr><tr>';
    foreach ($fmt as $value => $desc) {
        $keyname = 'users/' . $user->hashdir . '/pics/badge_' . $value . '.jpg';
        $str .= '<td>';
        $str .= '<textarea id="b_' . $value . '" onmouseover="this.select(); setcopybtn(\'bt_' . $value . '\',\'b_' . $value . '\');">';
        $str .= '<a href="' . mx_actionurl($page, $opt, $user->id) . '" alt="' . $name . '">' . '<img src="' . mx_secureurl(gets3url($keyname)) . '" />' . '</a>';
        $str .= '</textarea><br/>';
        $str .= '<a style="display:none;" href="#" class="toclipbtn" id="bt_' . $value . '">' . _('Copy') . '</a>';
        $str .= '</td>';
    }
    $str .= '</tr></table>';
    //$str.='<center><a href="'.mx_actionurl('artists','artprof',$user->id).'">'.$user->artistname.'</a></center>';
    $str .= '</div>';
    // smaller on-musxpand badges
    $str .= '<div class="badges"><table>';
    $i = 0;
    foreach ($badgesize as $sname => $ssuf) {
        $i++;
        $j = 0;
        foreach ($badgecolor as $cname => $csuf) {
            $j++;
            $value = $i . '_' . $j;
            $str .= '<tr><th>' . sprintf(_('MX Badge, %s, %s'), $sname, $cname) . '</th>' . '<th>' . _('Code') . '</th></tr>';
            $keyname = 'users/' . $user->hashdir . '/pics/minibadge' . $ssuf . $csuf . '.png';
            $str .= '<tr><td><img src="' . mx_secureurl(gets3url($keyname)) . '" /></td>';
            $str .= '<td>';
            $str .= '<textarea id="b_' . $value . '" onmouseover="this.select(); setcopybtn(\'bt_' . $value . '\',\'b_' . $value . '\');">';
            $str .= '<a href="' . mx_actionurl($page, $opt, $user->id) . '" alt="' . $name . '">' . '<img src="' . mx_secureurl(gets3url($keyname)) . '" />' . '</a>';
            $str .= '</textarea><br/>';
            $str .= '<a style="display:none;" href="#" class="toclipbtn" id="bt_' . $value . '">' . _('Copy') . '</a>';
            $str .= '</td>';
            $str .= '</tr>';
        }
    }
    $str .= '</table>';
    $str .= '</div>';
    return $str;
}