Author Topic: Fast-create categories?  (Read 18974 times)

0 Members and 1 Guest are viewing this topic.

Offline nicky9

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: Fast-create categories?
« Reply #15 on: May 22, 2008, 11:18:13 AM »
Exactly what part in the source code does the reading of folders from /MyMap and creates categories based on that? I'm trying to modify this myself.

Offline nicky9

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: Fast-create categories?
« Reply #16 on: May 25, 2008, 03:31:24 PM »
I've tried to change the get_dir function to sort alphabetically by last name, but I get error messages: Can anybody see anything wrong?


function get_dir($dir, $id, $pos = 0) {
  global $a, $b, $file, $dir_array, $dir_parent_array, $id, $id2, $id3, $data_src_path, $thumbnail_options;

  $handle = opendir($dir);
  $folders = array();
  while ($file = @readdir($handle)) {
    if (@is_dir($dir.$file) && !eregi("^\.{1,2}$", $file) && $file != basename($thumbnail_options['subfolder'])) {
      $folders[] = $file;
    }
  }
  @closedir($handle);
   
  $first_name = array();
  $last_name = array();
  $name_temp = array();
  unset($file);
   
   foreach ($folders as $file) {
    $id2 = 0;
    $id3 = 0;
      
      if (substr($file,$id2,1) != ' ') {                                   // This if-statement is supposed to separate
         $first_name[$id2] = substr($file,$id2,1);    // the first and last name.
           $id2++;
           }
         else
           {
           $last_name[$id3] = substr($file,$id3,1);   // This creates the last name
             $id3++;
         }
      $name_temp = array(                                             // Here it's supposed to create an array
         array($first_name, $last_name)                 // of first_name and last_name
         );
   }
   unset($file);
   
   function compare_lastname($a, $b)                                          // This function sorts the array by the last name.
   {
     return strnatcmp($a[1], $b[1]);
   }

   # sort alphabetically by name                                                   // This calls the above function.
   usort($name_temp, 'compare_lastname');
   
   
   $id = 0;                                                                        // This puts the sorted folders back to one string (firstname
   foreach ($name_temp as $file) {                                      // and last name(, separated by a space.
      $folders[$id] =  $name_temp[$id][0] . ' ' . $name_temp[$id][1];   //Is this the right way to put it together?
      $id++;
   }
   unset($file);
      
   $id = 0;
    foreach ($folders as $file) {
    $id++;
    $dir_array[$id] = array(
      "cat_name" => $file,
      "cat_path" => $dir.$file,
      "cat_folder_path" => str_replace($data_src_path."/", "", $dir.$file),
      "parent_id" => $pos
    );
    $dir_parent_array[$pos][] = $id;
    get_dir($dir.$file."/", $id, $id);
  }
  return true;
}

Offline nicky9

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: Fast-create categories?
« Reply #17 on: May 26, 2008, 05:53:45 PM »
To sort folders that have firstname and lastname by lastname I did this:

Put beneath source code before the function get_dir,


function compare_fullname($a, $b)
{
  $retval = strnatcmp($a[1], $b[1]);
  if(!$retval) return strnatcmp($a[0], $b[0]);
  return $retval;
}


function sortbylastname($folders) {
   $string = array();
   $string2 = array();
   foreach ($folders as $name)  {
      $string[] = explode(" ", $name);
   }

   # sort alphabetically by name
   usort($string, 'compare_fullname');
   
   foreach ($string as $name)  {
      $string2[] = implode(" ", $name);
   }   
   return $string2;
}

*************************

Also, within function get_dir, you have to replace line

sort($folders);

with

$folders = sortbylastname($folders);

Offline nicky9

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
One more question...
« Reply #18 on: May 26, 2008, 05:59:51 PM »
I have one more question:

That plug-in is constructed so that you have to "Click here to continue" for every category that is created. So If I have 400 folders that is supposed to be converted into 400 categories, I have to click it 400 times. Pretty time consuming. I've tried to take it away but haven't managed to get it to work.

Did Jan create it? How do I remove it so that it just converts all folders to categories at once, without having to click and confirm?

Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: Fast-create categories?
« Reply #19 on: May 26, 2008, 06:22:49 PM »
nicky9,

seems that you are the only one person in this forum who needs "fast-create categories"..

all what you see was done by Jan.. i don't think that he will change it (only 4 you), because we are all happy with this solution.

i gived you already a link for your system for "fast-create categories".. how you solve it with 2-3-4 clicks..

creating folders on your pc..
upload folders to your ftp
run batch-import.php (only 1 click needed!)

cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi