]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15488: format code (mostly white space) + skeleton for documentation
authorjerome <jerome>
Tue, 16 Sep 2008 02:01:59 +0000 (02:01 +0000)
committerjerome <jerome>
Tue, 16 Sep 2008 02:01:59 +0000 (02:01 +0000)
repository/flickr/repository.class.php
repository/flickr_public/repository.class.php

index 99ff7b598b25469b7feaeab0c12349201ed4d0fb..2358a7894213612671f8bf0b73c122bba7e51f79 100755 (executable)
 
 require_once($CFG->libdir.'/flickrlib.php');
 
-class repository_flickr extends repository{
+/**
+ *
+ */
+class repository_flickr extends repository {
     private $flickr;
     public $photos;
 
-    public function __construct($repositoryid, $context = SITEID, $options = array()){
+    /**
+     *
+     * @global <type> $SESSION
+     * @global <type> $CFG
+     * @param <type> $repositoryid
+     * @param <type> $context
+     * @param <type> $options
+     */
+    public function __construct($repositoryid, $context = SITEID, $options = array()) {
         global $SESSION, $CFG;
+
         $options['page']    = optional_param('p', 1, PARAM_INT);
         parent::__construct($repositoryid, $context, $options);
 
@@ -29,9 +41,9 @@ class repository_flickr extends repository{
 
         $this->flickr = new phpFlickr($this->api_key, $this->secret, $this->token);
 
-        if(empty($this->token)){
+        if (empty($this->token)) {
             $frob  = optional_param('frob', '', PARAM_RAW);
-            if(!empty($frob)){
+            if (!empty($frob)) {
                 $auth_info = $this->flickr->auth_getToken($frob);
                 $this->token = $auth_info['token'];
                 $this->nsid  = $auth_info['user']['nsid'];
@@ -42,17 +54,33 @@ class repository_flickr extends repository{
         }
 
     }
-    public function check_login(){
+
+    /**
+     *
+     * @return <type>
+     */
+    public function check_login() {
         return !empty($this->token);
     }
-    public function logout(){
+
+    /**
+     *
+     * @return <type>
+     */
+    public function logout() {
         set_user_preference($this->setting, '');
         set_user_preference($this->setting.'_nsid', '');
         $this->token = '';
         $this->nsid  = '';
         return $this->print_login();
     }
-    public function set_option($options = array()){
+
+    /**
+     *
+     * @param <type> $options
+     * @return <type>
+     */
+    public function set_option($options = array()) {
         if (!empty($options['api_key'])) {
             set_config('api_key', trim($options['api_key']), 'flickr');
         }
@@ -65,8 +93,13 @@ class repository_flickr extends repository{
         return $ret;
     }
 
-    public function get_option($config = ''){
-        if($config==='api_key'){
+    /**
+     *
+     * @param <type> $config
+     * @return <type>
+     */
+    public function get_option($config = '') {
+        if ($config==='api_key') {
             return trim(get_config('flickr', 'api_key'));
         } elseif ($config ==='secret') {
             return trim(get_config('flickr', 'secret'));
@@ -78,16 +111,30 @@ class repository_flickr extends repository{
         return $options;
     }
 
-    public function global_search(){
+    /**
+     *
+     * @global <type> $SESSION
+     * @return <type>
+     */
+    public function global_search() {
         global $SESSION;
+
         if (empty($this->token)) {
             return false;
         } else {
             return true;
         }
     }
-    public function print_login($ajax = true){
+
+    /**
+     *
+     * @global <type> $SESSION
+     * @param <type> $ajax
+     * @return <type>
+     */
+    public function print_login($ajax = true) {
         global $SESSION;
+
         if($ajax){
             $ret = array();
             $popup_btn = new stdclass;
@@ -97,12 +144,21 @@ class repository_flickr extends repository{
             return $ret;
         }
     }
-    public function get_listing($path = '1', $search = ''){
+
+    /**
+     *
+     * @global <type> $SESSION
+     * @param <type> $path
+     * @param <type> $search
+     * @return <type>
+     */
+    public function get_listing($path = '1', $search = '') {
         global $SESSION;
+
         $nsid = get_user_preferences($this->setting.'_nsid');
         $photos_url = $this->flickr->urls_getUserPhotos($nsid);
 
-        if(!empty($search)) {
+        if (!empty($search)) {
             $photos = $this->flickr->photos_search(array(
                 'user_id'=>$nsid,
                 'per_page'=>25,
@@ -110,7 +166,7 @@ class repository_flickr extends repository{
                 'extras'=>'original_format',
                 'text'=>$search
                 ));
-        } elseif(!empty($path) && empty($search)) {
+        } elseif (!empty($path) && empty($search)) {
             $photos = $this->flickr->photos_search(array(
                 'user_id'=>$nsid,
                 'per_page'=>25,
@@ -122,14 +178,14 @@ class repository_flickr extends repository{
         $ret['manage'] = $photos_url;
         $ret['list']  = array();
         $ret['pages'] = $photos['pages'];
-        if(is_int($path) && $path <= $ret['pages']) {
+        if (is_int($path) && $path <= $ret['pages']) {
             $ret['page'] = $path;
         } else {
             $ret['page'] = 1;
         }
-        if(!empty($photos['photo'])){
+        if (!empty($photos['photo'])) {
             foreach ($photos['photo'] as $p) {
-                if(empty($p['title'])) {
+                if (empty($p['title'])) {
                     $p['title'] = get_string('notitle', 'repository_flickr');
                 }
                 if (isset($p['originalformat'])) {
@@ -141,29 +197,48 @@ class repository_flickr extends repository{
                     array('title'=>$p['title'].'.'.$format,'source'=>$p['id'],'id'=>$p['id'],'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'), 'date'=>'', 'size'=>'unknown', 'url'=>$photos_url.$p['id']);
             }
         }
-        if(empty($ret)) {
+        if (empty($ret)) {
             throw new repository_exception('nullphotolist', 'repository_flickr');
         } else {
             return $ret;
         }
     }
-    public function print_listing(){
+
+    /**
+     *
+     * @return <type>
+     */
+    public function print_listing() {
         return false;
     }
-    public function print_search(){
+
+    /**
+     *
+     * @return <type>
+     */
+    public function print_search() {
         echo '<input name="s" value="" />';
         parent::print_search();
         return true;
     }
-    public function get_file($photo_id, $file = ''){
+
+    /**
+     *
+     * @global <type> $CFG
+     * @param <type> $photo_id
+     * @param <type> $file
+     * @return <type>
+     */
+    public function get_file($photo_id, $file = '') {
         global $CFG;
+
         $result = $this->flickr->photos_getSizes($photo_id);
         $url = '';
-        if(!empty($result[4])) {
+        if (!empty($result[4])) {
             $url = $result[4]['source'];
-        } elseif(!empty($result[3])) {
+        } elseif (!empty($result[3])) {
             $url = $result[3]['source'];
-        } elseif(!empty($result[2])) {
+        } elseif (!empty($result[2])) {
             $url = $result[2]['source'];
         }
         if (!file_exists($CFG->dataroot.'/repository/download')) {
@@ -173,10 +248,10 @@ class repository_flickr extends repository{
             $dir = $CFG->dataroot.'/repository/download/';
         }
 
-        if(empty($file)) {
+        if (empty($file)) {
             $file = $photo_id.'_'.time().'.jpg';
         }
-        if(file_exists($dir.$file)) {
+        if (file_exists($dir.$file)) {
             $file = uniqid('m').$file;
         }
         $fp = fopen($dir.$file, 'w');
@@ -186,35 +261,62 @@ class repository_flickr extends repository{
         ));
         return $dir.$file;
     }
+
+    /**
+     *
+     * @return <type>
+     */
     public static function has_admin_config() {
         return true;
     }
 
+    /**
+     *
+     * @return <type>
+     */
     public static function has_multiple_instances() {
         return false;
     }
 
+    /**
+     *
+     * @return <type>
+     */
     public static function has_instance_config() {
         return false;
     }
 
+    /**
+     *
+     * @param <type> $
+     */
     public function instance_config_form(&$mform) {
         $mform->addElement('text', 'email_address', get_string('emailaddress', 'repository_flickr'));
         $mform->addRule('email_address', get_string('required'), 'required', null, 'client');
     }
 
-    public static function get_instance_option_names(){
+    /**
+     *
+     * @return <type>
+     */
+    public static function get_instance_option_names() {
         return array('email_address');
     }
 
+    /**
+     *
+     * @global <type> $CFG
+     * @param <type> $
+     */
     public function admin_config_form(&$mform) {
         global $CFG;
+        
         $api_key = get_config('flickr', 'api_key');
         $secret = get_config('flickr', 'secret');
 
         //retrieve the flickr instances
         $instances = repository_get_instances(array(),null,false,"flickr");
-        if (empty($instances)){
+        if (empty($instances)) {
             $callbackurl = get_string("callbackwarning","repository_flickr");
         }
         else {
@@ -237,7 +339,11 @@ class repository_flickr extends repository{
         $mform->addRule('secret', $strrequired, 'required', null, 'client');
     }
 
-    public static function get_admin_option_names(){
+    /**
+     *
+     * @return <type> 
+     */
+    public static function get_admin_option_names() {
         return array('api_key', 'secret');
     }
 
index 686ce01dbc942955977e8ffebb972537d401736c..31fa7caa4811430500cd14251853be6180b69e0c 100644 (file)
 
 require_once($CFG->libdir.'/flickrlib.php');
 
-class repository_flickr_public extends repository{
+/**
+ *
+ */
+class repository_flickr_public extends repository {
     private $flickr;
     public $photos;
 
-    public function set_option($options = array()){
+    /**
+     *
+     * @param <type> $options
+     * @return <type>
+     */
+    public function set_option($options = array()) {
         if (!empty($options['api_key'])) {
             set_config('api_key', trim($options['api_key']), 'flickr_public');
         }
@@ -25,8 +33,13 @@ class repository_flickr_public extends repository{
         return $ret;
     }
 
-    public function get_option($config = ''){
-        if($config==='api_key'){
+    /**
+     *
+     * @param <type> $config
+     * @return <type>
+     */
+    public function get_option($config = '') {
+        if ($config==='api_key') {
             return trim(get_config('flickr_public', 'api_key'));
         } else {
             $options['api_key'] = trim(get_config('flickr_public', 'api_key'));
@@ -35,7 +48,11 @@ class repository_flickr_public extends repository{
         return $options;
     }
 
-    public function global_search(){
+    /**
+     *
+     * @return <type>
+     */
+    public function global_search() {
         if (empty($this->flickr_account)) {
             return false;
         } else {
@@ -43,8 +60,16 @@ class repository_flickr_public extends repository{
         }
     }
 
-    public function __construct($repositoryid, $context = SITEID, $options = array()){
+    /**
+     *
+     * @global <type> $CFG
+     * @param <type> $repositoryid
+     * @param <type> $context
+     * @param <type> $options
+     */
+    public function __construct($repositoryid, $context = SITEID, $options = array()) {
         global $CFG;
+
         $options['page']    = optional_param('p', 1, PARAM_INT);
         parent::__construct($repositoryid, $context, $options);
         $this->api_key = $this->get_option('api_key');
@@ -53,20 +78,31 @@ class repository_flickr_public extends repository{
         $this->flickr_account = $this->get_option('email_address');
 
         $account = optional_param('flickr_account', '', PARAM_RAW);
-        if(!empty($account)) {
+        if (!empty($account)) {
             $people = $this->flickr->people_findByEmail($account);
-            if(!empty($people)) {
+            if (!empty($people)) {
                 $this->flickr_account = $account;
             } else {
                 throw new repository_exception('invalidemail', 'repository_flickr_public');
             }
         }
     }
-    public function check_login(){
+
+    /**
+     *
+     * @return <type>
+     */
+    public function check_login() {
         return !empty($this->flickr_account);
     }
-    public function print_login($ajax = true){
-        if($ajax){
+
+    /**
+     *
+     * @param <type> $ajax
+     * @return <type>
+     */
+    public function print_login($ajax = true) {
+        if ($ajax) {
             $ret = array();
             $email_field->label = get_string('username', 'repository_flickr_public').': ';
             $email_field->id    = 'account';
@@ -76,11 +112,16 @@ class repository_flickr_public extends repository{
             return $ret;
         }
     }
-    public function search(){
+
+    /**
+     *
+     * @return <type>
+     */
+    public function search() {
         $people = $this->flickr->people_findByEmail($this->flickr_account);
         $tag    = optional_param('tag', '', PARAM_CLEANHTML);
         $search = optional_param('s', '', PARAM_CLEANHTML);
-        if(!empty($tag)){
+        if (!empty($tag)) {
             $photos = $this->flickr->photos_search(array(
                 'tags'=>$tag
                 ));
@@ -94,7 +135,7 @@ class repository_flickr_public extends repository{
         $ret['nologin'] = true;
         $ret['pages'] = $photos['pages'];
         foreach ($photos['photo'] as $p) {
-            if(empty($p['title'])) {
+            if (empty($p['title'])) {
                 $p['title'] = get_string('notitle', 'repository_flickr_public');
             }
             if (isset($p['originalformat'])) {
@@ -105,13 +146,20 @@ class repository_flickr_public extends repository{
             $ret['list'][] =
                 array('title'=>$p['title'].'.'.$format,'source'=>$p['id'],'id'=>$p['id'],'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'), 'date'=>'', 'size'=>'unknown', 'url'=>'http://www.flickr.com/photos/'.$p['owner'].'/'.$p['id']);
         }
-        if(empty($ret)) {
+        if (empty($ret)) {
             throw new repository_exception('nullphotolist', 'repository_flickr_public');
         } else {
             return $ret;
         }
     }
-    public function get_listing($path = '1', $search = ''){
+
+    /**
+     *
+     * @param <type> $path
+     * @param <type> $search
+     * @return <type>
+     */
+    public function get_listing($path = '1', $search = '') {
         $people = $this->flickr->people_findByEmail($this->flickr_account);
         $photos_url = $this->flickr->urls_getUserPhotos($people['nsid']);
 
@@ -122,13 +170,13 @@ class repository_flickr_public extends repository{
         $ret['list']  = array();
         $ret['nologin'] = true;
         $ret['pages'] = $photos['pages'];
-        if(is_int($path) && $path <= $ret['pages']) {
+        if (is_int($path) && $path <= $ret['pages']) {
             $ret['page'] = $path;
         } else {
             $ret['page'] = 1;
         }
         foreach ($photos['photo'] as $p) {
-            if(empty($p['title'])) {
+            if (empty($p['title'])) {
                 $p['title'] = get_string('notitle', 'repository_flickr_public');
             }
             if (isset($p['originalformat'])) {
@@ -139,43 +187,62 @@ class repository_flickr_public extends repository{
             $ret['list'][] =
                 array('title'=>$p['title'].'.'.$format,'source'=>$p['id'],'id'=>$p['id'],'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'), 'date'=>'', 'size'=>'unknown', 'url'=>$photos_url.$p['id']);
         }
-        if(empty($ret)) {
+        if (empty($ret)) {
             throw new repository_exception('nullphotolist', 'repository_flickr_public');
         } else {
             return $ret;
         }
     }
-    public function print_listing(){
+
+    /**
+     *
+     * @return <type>
+     */
+    public function print_listing() {
         return false;
     }
-    public function print_search(){
+
+    /**
+     *
+     * @return <type>
+     */
+    public function print_search() {
         parent::print_search();
         echo '<label>Keyword: </label><input type="text" name="s" /><br />';
         echo '<label>Tag: </label><input type="text" name="tag" /><br />';
         return true;
     }
-    public function get_file($photo_id, $file = ''){
+
+    /**
+     *
+     * @global <type> $CFG
+     * @param <type> $photo_id
+     * @param <type> $file
+     * @return <type>
+     */
+    public function get_file($photo_id, $file = '') {
         global $CFG;
+
         $result = $this->flickr->photos_getSizes($photo_id);
         $url = '';
-        if(!empty($result[4])) {
+        if (!empty($result[4])) {
             $url = $result[4]['source'];
-        } elseif(!empty($result[3])) {
+        } elseif (!empty($result[3])) {
             $url = $result[3]['source'];
-        } elseif(!empty($result[2])) {
+        } elseif (!empty($result[2])) {
             $url = $result[2]['source'];
         }
         if (!file_exists($CFG->dataroot.'/repository/download')) {
             mkdir($CFG->dataroot.'/repository/download/', 0777, true);
         }
-        if(is_dir($CFG->dataroot.'/repository/download')) {
+        if (is_dir($CFG->dataroot.'/repository/download')) {
             $dir = $CFG->dataroot.'/repository/download/';
         }
 
-        if(empty($file)) {
+        if (empty($file)) {
             $file = $photo_id.'_'.time().'.jpg';
         }
-        if(file_exists($dir.$file)) {
+        if (file_exists($dir.$file)) {
             $file = uniqid('m').$file;
         }
         $fp = fopen($dir.$file, 'w');
@@ -185,27 +252,52 @@ class repository_flickr_public extends repository{
         ));
         return $dir.$file;
     }
+
+    /**
+     *
+     * @return <type>
+     */
     public static function has_admin_config() {
         return true;
     }
 
+    /**
+     *
+     * @return <type>
+     */
     public static function has_multiple_instances() {
         return true;
     }
 
+    /**
+     *
+     * @return <type>
+     */
     public static function has_instance_config() {
         return true;
     }
 
+    /**
+     *
+     * @param <type> $
+     */
     public function instance_config_form(&$mform) {
         $mform->addElement('text', 'email_address', get_string('emailaddress', 'repository_flickr_public'));
         //$mform->addRule('email_address', get_string('required'), 'required', null, 'client');
     }
 
+    /**
+     *
+     * @return <type>
+     */
     public static function get_instance_option_names() {
         return array('email_address');
     }
 
+    /**
+     *
+     * @param <type> $
+     */
     public function admin_config_form(&$mform) {
         $api_key = get_config('flickr_public', 'api_key');
         if (empty($api_key)) {
@@ -216,10 +308,17 @@ class repository_flickr_public extends repository{
         $mform->addRule('api_key', $strrequired, 'required', null, 'client');
     }
 
+    /**
+     *
+     * @return <type>
+     */
     public static function get_admin_option_names() {
         return array('api_key');
     }
 
+    /**
+     * 
+     */
     public static function type_init() {
         //here we create a default instances for this type
     }