php - How do I get the folder structure through the smugmug api (phpsmug) -


i using smugphp , have completed of login stuff above block of code. trying folder structure have created in smugmug website. unfortunately gives me category , name of leaf of folder tree. there doesn't seem way intermediate folders.

any appreciated.

$categories=$f->categories_get();  $subcategories=$f->subcategories_getall();  echo "categories<br>"; ($i=0;$i<count($categories);$i++){   print_r($categories[$i]);   echo "<br><br>"; } echo "subcategories<br>"; ($i=0;$i<count($subcategories);$i++){   print_r($subcategories[$i]);   echo "<br><br>"; } 

i don't know if best or cleanest solution, code below able trick smugmug giving me want. force depth first search , ignore duplicates. hope helps other people, please let me know if there better solution out there.

<?php  require_once("phpsmug/phpsmug.php");  class smugmug{     private $f;     private $folders;     public function __construct(){         $this->f=new phpsmug("apikey=mfdv7qwg8vzt2tsk2dv7rzx10yxnu7uf","apiver=1.2.2"); $this->f->login("apikey=mfdv7qwg8vzt2tsk2dv7rzx10yxnu7uf","emailaddress=email@gmail.com","password=password");         $this->folders=[];     }      public function get_folders(){         $this->folders=$this->_get_folders();     }      private function new_id($id,$folders){         if (!isset($folders)){             return false;         }         ($i=0;$i<count($folders);$i++){             if ($id==$folders[$i]['id']){                 return false;             }             if ($this->new_id($id,$folders[$i]['subfolders'])==false){                 return false;             }         }         return true;     }     private function _get_folders($id=-1){         $folders=[];         if ($id==-1){             $categories = $this->f->categories_get();         } else {             $categories = $this->f->subcategories_get("categoryid=$id");         }         $k=0;         ($i=0;$i<count($categories);$i++){             $folder['id']=$categories[$i]['id'];             if ($this->new_id($folder['id'],$folders)){                 $folder['name']=$categories[$i]['name'];                 $folders[$i]=$folder;                 $subfolders=$this->_get_folders($folder['id']);                 $folders[$i]['subfolders']=$subfolders;             }         }         return $folders;     }     public function print_folders(){         $this->_print_folders($this->folders);     }     private function _print_folders($folders,$prefix=""){         ($i=0;$i<count($folders);$i++){             echo $prefix.$folders[$i]['name']."<br>";             $this->_print_folders($folders[$i]['subfolders'],$prefix."-");         }     } }  ?> 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -