⌈⌋ branch:  freshcode


Check-in [9e7bb1667b]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
SHA1:9e7bb1667b0676d2e3c561c876526a4f9d8e02d0
Date: 2014-08-03 01:39:11
User: mario
Comment:Split out gravatar email into separate database field `submitter_image`. (In templates still called `submitter_img` however.)
Tags And Properties
  • branch=trunk inherited from [82405bb421]
  • sym-trunk inherited from [82405bb421]
Context
2014-08-03
22:54
[2d2225e623] Added small #search_q box in #tools header (user: mario, tags: trunk)
01:39
[9e7bb1667b] Split out gravatar email into separate database field `submitter_image`. (In templates still called `submitter_img` however.) (user: mario, tags: trunk)
01:37
[08b1e91919] Updated autoupdate testing descriptions. (user: mario, tags: trunk)
Changes

Changes to aux.php.

124
125
126
127
128
129
130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145


146

147
148
149
150
151
152
153
154
155
156
157
158
    //
    $entry["formatted_date"] = date_fmt($entry["t_published"]);
    
    // HTML context
    $entry = array_map("input::_html", $entry);

    // user image
    $entry["submitter_img"] = submitter_gravatar($entry["submitter"]);
}


/**
 * Strip email@xyz from submitter name list (else just hash name),
 * return gravatar or identicon.

 *
 */
function submitter_gravatar(&$user, $size=24) {
    $rx = "/[^,;\s]+@[^,;\s]+/";
    $m = array($user);
    
    // capture+strip email
    if (is_int(strpos($user, "@")) and preg_match($rx, $user, $m)) {


        $user = trim(preg_replace($rx, "", $user), ",; ");

    }
    
    // return html <img> snippet
    return "<img src=\"//www.gravatar.com/avatar/" . md5(current($m))
         . "?s=$size&d=identicon&r=pg\" width=$size height=$size class=gravatar>";
}



// Social media share links
function social_share_links($name, $url) {
    $c = array("google"=>0, "facebook"=>0, "twitter"=>0, "reddit"=>0, "linkedin"=>0, "stumbleupon"=>0, "delicious"=>0);







|




<
|
>


|
<
<


|
>
>
|
>



<
|







124
125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140


141
142
143
144
145
146
147
148
149
150

151
152
153
154
155
156
157
158
    //
    $entry["formatted_date"] = date_fmt($entry["t_published"]);
    
    // HTML context
    $entry = array_map("input::_html", $entry);

    // user image
    $entry["submitter_img"] = submitter_gravatar($entry["submitter_image"]);
}


/**

 * Convert email@xyz to gravatar or identicon,
 * keep raw URLs, or use default image for empty fields.
 *
 */
function submitter_gravatar($img, $size=24) {


    
    // capture+strip email
    if (is_int(strpos($img, "@"))) {
        $img = "//www.gravatar.com/avatar/" . md5($img) . "?s=$size&d=identicon&r=pg";
    }
    elseif (empty($img)) {
        $img = "/img/user.png";
    }
    
    // return html <img> snippet

    return "<img src=\"$img\" width=$size height=$size class=gravatar>";
}



// Social media share links
function social_share_links($name, $url) {
    $c = array("google"=>0, "facebook"=>0, "twitter"=>0, "reddit"=>0, "linkedin"=>0, "stumbleupon"=>0, "delicious"=>0);

Changes to db.sql.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
#
# title: freshcode database schema
# version: 0.6
#


CREATE TABLE [release] ( 
    name              VARCHAR( 100 )    NOT NULL,
    title             TEXT              NOT NULL,
    homepage          TEXT,
    description       TEXT              NOT NULL,
    license           VARCHAR( 100 ),
    tags              VARCHAR( 200 ),
    version           VARCHAR( 100 )    NOT NULL,
    state             VARCHAR( 20 ),
    scope             VARCHAR( 20 ),
    changes           TEXT,
    download          TEXT,
    urls              TEXT,
    autoupdate_module VARCHAR( 20 ),
    autoupdate_url    TEXT,
    autoupdate_regex  TEXT,
    t_published       INT,
    t_changed         INT,
    flag              INT               DEFAULT ( 0 ),
    deleted           BOOLEAN           DEFAULT ( 0 ),
    submitter_openid  TEXT,
    submitter         VARCHAR( 0, 50 ),
    lock              TEXT,
    hidden            BOOLEAN           DEFAULT ( 0 ),
    image             TEXT,
    social_links      INT               DEFAULT ( 0 ),

    CONSTRAINT 'release_revision' UNIQUE ( name, version COLLATE 'NOCASE', t_published, t_changed ) 
);

CREATE TABLE flags ( 
    name             TEXT,
    reason           TEXT,
    note             TEXT,
    submitter_openid TEXT,





<

|
|

|


|










|
|

|

|

|
>
|







1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#
# title: freshcode database schema
# version: 0.6
#


CREATE TABLE [release] ( 
    name              VARCHAR( 100 )     NOT NULL,
    title             TEXT               NOT NULL,
    homepage          TEXT,
    description       TEXT               NOT NULL,
    license           VARCHAR( 100 ),
    tags              VARCHAR( 200 ),
    version           VARCHAR( 100 )     NOT NULL,
    state             VARCHAR( 20 ),
    scope             VARCHAR( 20 ),
    changes           TEXT,
    download          TEXT,
    urls              TEXT,
    autoupdate_module VARCHAR( 20 ),
    autoupdate_url    TEXT,
    autoupdate_regex  TEXT,
    t_published       INT,
    t_changed         INT,
    flag              INT                DEFAULT ( 0 ),
    deleted           BOOLEAN            DEFAULT ( 0 ),
    submitter_openid  TEXT,
    submitter         VARCHAR( 0, 100 ),
    lock              TEXT,
    hidden            BOOLEAN            DEFAULT ( 0 ),
    image             TEXT,
    social_links      INT                DEFAULT ( 0 ),
    submitter_image   VARCHAR( 200 ),
    CONSTRAINT 'release_revisions' UNIQUE ( name, version COLLATE 'NOCASE', t_published, t_changed ) 
);

CREATE TABLE flags ( 
    name             TEXT,
    reason           TEXT,
    note             TEXT,
    submitter_openid TEXT,

Added img/user.png.

cannot compute difference between binary files

Changes to page_feed.php.

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
        "name" => $row["name"],
        "title" => $row["title"],
        "description" => $row["description"],
        "homepage" => $row["homepage"],
        "license" => $row["license"],
        "tags" => $row["tags"],
        "image" => $row["image"],
        "submitter" => preg_replace(array("/\S+@\S+/", "/^[\s,]+|[\s,]+$/"), "", $row["submitter"]),
        "urls" => p_key_value($row["urls"]),
    );
}

#-- version/release blocks
function feed_release($row) {
    return array(







|







47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
        "name" => $row["name"],
        "title" => $row["title"],
        "description" => $row["description"],
        "homepage" => $row["homepage"],
        "license" => $row["license"],
        "tags" => $row["tags"],
        "image" => $row["image"],
        "submitter" => $row["submitter"],
        "urls" => p_key_value($row["urls"]),
    );
}

#-- version/release blocks
function feed_release($row) {
    return array(

Changes to release.php.

113
114
115
116
117
118
119



120
121
122
123
124
125
126
...
141
142
143
144
145
146
147
















148
149
150
151
152
153
154
            "t_changed" => time(),
        );

        // Array excerpt if input didn't come from page_submit but Autoupdate or API
        if ($partial) {
            $newdata = array_intersect_key($newdata, array_flip($newkeys));
        }




        // Merge and apply input
        $this->exchangeArray(array_merge(
             $this->getArrayCopy(),   // any previous/extraneous control data is kept
             $prefill_flags,
             $newdata,
             $auto_flags,
................................................................................
     */
    function store($INSERT="INSERT") {
        $data = $this->getArrayCopy();
        return db("$INSERT INTO release (:?) VALUES (::)", $data, $data)
           and db("UPDATE release SET hidden=1 WHERE name=? AND version=? AND t_published < ?", $data["name"], "", time()-5);
    }


















    /**
     * Retrieve latest published release version.
     *
     * @return array
     */
    static function latest($name) {







>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
...
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
            "t_changed" => time(),
        );

        // Array excerpt if input didn't come from page_submit but Autoupdate or API
        if ($partial) {
            $newdata = array_intersect_key($newdata, array_flip($newkeys));
        }
        
        // Apply some logic filters
        $this->unpack($newdata);

        // Merge and apply input
        $this->exchangeArray(array_merge(
             $this->getArrayCopy(),   // any previous/extraneous control data is kept
             $prefill_flags,
             $newdata,
             $auto_flags,
................................................................................
     */
    function store($INSERT="INSERT") {
        $data = $this->getArrayCopy();
        return db("$INSERT INTO release (:?) VALUES (::)", $data, $data)
           and db("UPDATE release SET hidden=1 WHERE name=? AND version=? AND t_published < ?", $data["name"], "", time()-5);
    }


    /**
     * Split up fields,
     * in particular the email out of `submitter`.
     *
     */
    function unpack(&$newdata) {

        if (!empty($newdata["submitter"]) and is_int(strpos($newdata["submitter"], "@"))
        and preg_match($rx = "/[^,;\s]+@[^,;\s]+/", $newdata["submitter"], $match))
        {
            $newdata["submitter_image"] = $match[0];
            $newdata["submitter"] = trim(preg_replace($rx, "", $newdata["submitter"]), ", ");
        }
    }


    /**
     * Retrieve latest published release version.
     *
     * @return array
     */
    static function latest($name) {