]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-18830, improve flickr_public plugin license searching, easier to use "
authordongsheng <dongsheng>
Wed, 24 Jun 2009 05:49:52 +0000 (05:49 +0000)
committerdongsheng <dongsheng>
Wed, 24 Jun 2009 05:49:52 +0000 (05:49 +0000)
lang/en_utf8/repository_flickr_public.php
repository/flickr_public/repository.class.php

index 34d2b992fc7924e44d57d5597c75945e6d3b492b..d21747db945df3f7f09f9c3ffb7131483e17a1e2 100644 (file)
@@ -10,12 +10,14 @@ $string['by-nc-nd'] = 'Attribution-NonCommercial-NoDerivs License';
 $string['by'] = 'Attribution License';
 $string['by-sa'] = 'Attribution-ShareAlike License';
 $string['by-nd'] = 'Attribution-NoDerivs License';
+$string['commercialuse'] = 'Allow commercial uses of your work?';
 $string['creativecommonscommercial'] = 'Only creative commons commercial';
 $string['emailaddress'] = 'Email address';
 $string['fulltext'] = 'Full text';
 $string['information'] = '<div>Get <a href=\"http://www.flickr.com/services/api/keys/\">Flickr API Key</a> for your Moodle site. </div>';
 $string['invalidemail'] = 'Invalid email address for flickr';
 $string['license'] = 'License';
+$string['modification'] = 'Allow modifications of your work?';
 $string['notitle'] = 'notitle';
 $string['nullphotolist'] = 'There are no photos in this account';
 $string['tag'] = 'Tag';
@@ -23,5 +25,6 @@ $string['remember'] = 'Remember me';
 $string['repositoryname'] = 'Flickr public';
 $string['repositorydesc'] = 'Repository on flickr.com';
 $string['secret'] = 'Secret';
+$string['sharealike'] = 'Yes, as long as others share alike';
 $string['username'] = 'Flickr account email';
 
index 84a27117a565d0a77896a7eb01fd4ba2ba8e328a..8aeb95d05c355e3fab691b9700ace823ddcff500 100644 (file)
@@ -86,13 +86,11 @@ class repository_flickr_public extends repository {
         $this->sess_account = 'flickr_public_'.$this->id.'_account';
         $this->sess_tag     = 'flickr_public_'.$this->id.'_tag';
         $this->sess_text    = 'flickr_public_'.$this->id.'_text';
-        $this->sess_license = 'flickr_public_'.$this->id.'_license';
 
         if (!empty($account) or !empty($fulltext) or !empty($tag) or !empty($license)) {
             $SESSION->{$this->sess_tag}  = $tag;
             $SESSION->{$this->sess_text} = $fulltext;
             $SESSION->{$this->sess_account} = $account;
-            $SESSION->{$this->sess_license} = $license;
         }
     }
 
@@ -130,26 +128,30 @@ class repository_flickr_public extends repository {
             $email_field->type = 'text';
             $email_field->name = 'flickr_account';
 
-            $license = new stdclass;
-            $license->label = get_string('license', 'repository_flickr_public').': ';
-            $license->id    = 'flickr_license_type';
-            $license->type  = 'radio';
-            $license->name  = 'flickr_license';
-            // all -> all licenses
-            // cc  -> creative commons
-            // ccc -> reeative commons commercial
-            $license->value = implode('|', array('all', 1, 2, 3, 4, 5, 6));
-            $license->value_label = implode('|', array(
-                get_string('all', 'repository_flickr_public'),
-                get_string('by-nc-sa', 'repository_flickr_public'),
-                get_string('by-nc', 'repository_flickr_public'),
-                get_string('by-nc-nd', 'repository_flickr_public'),
-                get_string('by', 'repository_flickr_public'),
-                get_string('by-sa', 'repository_flickr_public'),
-                get_string('by-nd', 'repository_flickr_public')
-            ));
-
-            $ret['login'] = array($fulltext, $tag, $email_field, $license);
+            $commercial = new stdclass;
+            $commercial->label = get_string('commercialuse', 'repository_flickr_public').': ';
+            $commercial->id    = 'flickr_commercial_id';
+            $commercial->type  = 'radio';
+            $commercial->name  = 'flickr_commercial';
+            $commercial->value = implode('|', array('yes', 'no'));
+            $commercial->value_label = implode('|', array(
+                    get_string('yes'),
+                    get_string('no')
+                ));
+
+            $modification = new stdclass;
+            $modification->label = get_string('modification', 'repository_flickr_public').': ';
+            $modification->id    = 'flickr_modification_id';
+            $modification->type  = 'radio';
+            $modification->name  = 'flickr_modification';
+            $modification->value = implode('|', array('yes', 'sharealike', 'no'));
+            $modification->value_label = implode('|', array(
+                    get_string('yes'),
+                    get_string('sharealike', 'repository_flickr_public'),
+                    get_string('no')
+                ));
+
+            $ret['login'] = array($fulltext, $tag, $email_field, $commercial, $modification);
             $ret['login_btn_label'] = get_string('search');
             $ret['login_btn_action'] = 'search';
             return $ret;
@@ -162,21 +164,22 @@ class repository_flickr_public extends repository {
             echo '<tr><td><label>'.get_string('username', 'repository_flickr_public').'</label></td>';
             echo '<td><input type="text" name="flickr_account" /></td></tr>';
 
-            echo '<tr><td><label>'.get_string('license', 'repository_flickr_public').'</label></td>';
+            echo '<tr><td><label>'.get_string('commercialuse', 'repository_flickr_public').'</label></td>';
             echo '<td>';
-            echo '<input type="radio" name="flickr_license" value="all" /> '.get_string('all', 'repository_flickr_public');
+            echo '<input type="radio" name="flickr_commercial" value="yes" /> '.get_string('yes');
             echo '<br />';
-            echo '<input type="radio" name="flickr_license" value="1" /> '.get_string('by-nc-sa', 'repository_flickr_public');
+            echo '<input type="radio" name="flickr_commercial" value="no" /> '.get_string('no');
             echo '<br />';
-            echo '<input type="radio" name="flickr_license" value="2" /> '.get_string('by-nc', 'repository_flickr_public');
-            echo '<br />';
-            echo '<input type="radio" name="flickr_license" value="3" /> '.get_string('by-nc-nd', 'repository_flickr_public');
+            echo '</td></tr>';
+
+            echo '<tr><td><label>'.get_string('modification', 'repository_flickr_public').'</label></td>';
+            echo '<td>';
+            echo '<input type="radio" name="flickr_modification" value="yes" /> '.get_string('yes');
             echo '<br />';
-            echo '<input type="radio" name="flickr_license" value="4" /> '.get_string('by', 'repository_flickr_public');
+            echo '<input type="radio" name="flickr_modification" value="sharealike" /> '.get_string('sharealike', 'repository_flickr_public');
             echo '<br />';
-            echo '<input type="radio" name="flickr_license" value="5" /> '.get_string('by-sa', 'repository_flickr_public');
+            echo '<input type="radio" name="flickr_modification" value="no" /> '.get_string('no');
             echo '<br />';
-            echo '<input type="radio" name="flickr_license" value="6" /> '.get_string('by-nd', 'repository_flickr_public');
             echo '</td></tr>';
 
             echo '</table>';
@@ -222,29 +225,50 @@ class repository_flickr_public extends repository {
         } else {
             $page = 1;
         }
-        if (!empty($SESSION->{$this->sess_tag}) or !empty($SESSION->{$this->sess_text}) 
-            or !empty($SESSION->{$this->sess_account}) or !empty($this->nsid))
-        {
-            if ( empty($SESSION->{$this->sess_license}) or $SESSION->{$this->sess_license}=='all') {
-                $photos = $this->flickr->photos_search(array(
-                    'tags'=>$SESSION->{$this->sess_tag},
-                    'page'=>$page,
-                    'per_page'=>24,
-                    'user_id'=>$this->nsid,
-                    'text'=>$SESSION->{$this->sess_text}
-                    )
-                );
-            } else {
-                $photos = $this->flickr->photos_search(array(
-                    'tags'=>$SESSION->{$this->sess_tag},
-                    'page'=>$page,
-                    'per_page'=>24,
-                    'user_id'=>$this->nsid,
-                    'license'=>$SESSION->{$this->sess_license},
-                    'text'=>$SESSION->{$this->sess_text}
-                    )
-                );
-            }
+        // including all licenses by default
+        $licenses = array(1=>1, 2, 3, 4, 5, 6, 7);
+
+        $commercial   = optional_param('flickr_commercial', '', PARAM_RAW);
+        $modification = optional_param('flickr_modification', '', PARAM_RAW);
+
+        if ($commercial == 'yes') {
+            // including
+            // 4: Attribution License
+            // 5: Attribution ShareAlike
+            // 6: Attribution NoDerives
+            // 7: unknown license
+            unset($licenses[1], $licenses[2], $licenses[3]);
+        }
+        if ($modification == 'yes') {
+            // including
+            // 1: Attribution NonCommercial ShareAlike
+            // 2: Attribution NonCommercial
+            // 4: Attribution License
+            // 5: Attribution ShareAlike
+            // 7: unknown license
+            unset($licenses[3], $licenses[6]);
+        }
+        if ($modification == 'sharealike') {
+            // including
+            // 1: Attribution NonCommercial ShareAlike
+            // 5: Attribution ShareAlike
+            unset($licenses[2], $licenses[3], $licenses[4], $licenses[6], $licenses[7]);
+        }
+
+        $licenses = implode(',', $licenses);
+
+        if (!empty($SESSION->{$this->sess_tag})         // use tag to search
+            or !empty($SESSION->{$this->sess_text})     // use keyword to search
+            or !empty($this->nsid)/*use pre-defined accound*/) {                   
+            $photos = $this->flickr->photos_search(array(
+                'tags'=>$SESSION->{$this->sess_tag},
+                'page'=>$page,
+                'per_page'=>24,
+                'user_id'=>$this->nsid,
+                'license'=>$licenses,
+                'text'=>$SESSION->{$this->sess_text}
+                )
+            );
         }
         $ret = array();
         $ret['total'] = $photos['total'];