heungsub / me2pheungp

A forked Me2PHP, the Me2DAY API client library. It supports recent Me2PHP specifications.

Clone this repository (size: 270.6 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/heungsub/me2pheungp/
commit 81: 9013f4ef49ae
parent 80: 671424a00bb5
branch: Me2PHP
* 파일첨부 시 헤더 개선 * `Me2Callback` 사용법 다시 되돌림.
Heungsub Lee / heungsub
9 months ago

Changed (Δ434 bytes):

raw changeset »

Me2/Api.php (27 lines added, 22 lines removed)

Me2/Attachment.php (9 lines added, 2 lines removed)

Up to file-list Me2/Api.php:

@@ -63,33 +63,38 @@ abstract class Me2Api {
63
63
                break;
64
64
            }
65
65
66
            $content_type = $attached ? 'multipart/form-data'
67
                          : 'application/x-www-form-urlencoded';
68
            $content_disposition = array_pop(explode('/', $content_type));
69
            $nonce = self::generateNonce();
70
            $boundary = "--------------------------------$nonce";
71
            $contents = '';
66
            if ($attached) {
67
                $content_type = 'multipart/form-data';
68
                $content_disposition = array_pop(explode('/', $content_type));
69
                $nonce = self::generateNonce();
70
                $boundary = "--------------------------------$nonce";
71
                $contents = '';
72
72
73
            foreach ($parameters as $param => $value) {
74
                $contents .= '--'.$boundary.$crlf;
75
                $contents .= "Content-Disposition: $content_disposition"
76
                          .  "; name=\"$param\"";
73
                foreach ($parameters as $param => $value) {
74
                    $contents .= '--'.$boundary.$crlf;
75
                    $contents .= "Content-Disposition: $content_disposition"
76
                              .  "; name=\"$param\"";
77
77
78
                if ($value instanceof Me2Image) {
79
                    $name = $value->name;
80
                    $mime = $value->mime;
78
                    if ($value instanceof Me2Image) {
79
                        $name = $value->name;
80
                        $mime = $value->mime;
81
81
82
                    $contents .= "; filename=\"$name\"$crlf"
83
                              .  "Content-Transfer-Encoding: binary$crlf"
84
                              .  "Content-Type: $mime$crlf";
85
                } else {
86
                    $contents .= $crlf;
82
                        $contents .= "; filename=\"$name\"$crlf"
83
                                  .  "Content-Transfer-Encoding: binary$crlf"
84
                                  .  "Content-Type: $mime$crlf";
85
                    } else {
86
                        $contents .= $crlf;
87
                    }
88
                    $contents .= $crlf . $value . $crlf;
87
89
                }
88
                $contents .= $crlf . $value . $crlf;
90
                $contents .= "--$boundary$crlf";
91
92
                $headers['Content-Type'] = "$content_type; boundary=$boundary";
93
            } else {
94
                $content_type = 'application/x-www-form-urlencoded';
95
                $headers['Content-Type'] = $content_type;
96
                $contents = "$query$crlf";
89
97
            }
90
            $contents .= "--$boundary$crlf";
91
92
            $headers['Content-Type'] = "$content_type; boundary=$boundary";
93
98
            $headers['Content-Length'] = strlen($contents);
94
99
        } else {
95
100
            $contents = '';

Up to file-list Me2/Attachment.php:

@@ -65,10 +65,17 @@ final class Me2Image extends Me2Attachme
65
65
    }
66
66
}
67
67
68
abstract class Me2Callback extends Me2Attachment {
69
    function __construct($url, $icon) {
68
class Me2Callback extends Me2Attachment {
69
    const Document = 'document';
70
    const Photo = 'photo';
71
    const Video = 'video';
72
    const Audio = 'audio';
73
    const Friend = 'friend';
74
75
    function __construct($url, $icon, $type = self::Document) {
70
76
        $this->url = $url;
71
77
        $this->icon = $icon;
78
        $this->type = $type;
72
79
    }
73
80
74
81
    function __toString() {