Advertisement
jargon

puzzlum.net import listings

Sep 10th, 2020
1,615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. <?php
  2. function jensort(&$arr)
  3. {
  4.     return ksort($arr, SORT_NATURAL | SORT_FLAG_CASE);
  5. }
  6.  
  7. function namingway($name,$mode='prj')
  8. {
  9.     $ret=$name;
  10.     $ext='.php';
  11.        
  12.     switch ($mode) {
  13.     case 'prj':
  14.         $ret=substr($ret,0,-strlen($ext)).
  15.         str_replace($ext,'',substr($ret,-strlen($ext),strlen($ext)));
  16.         $ret='prj_'.str_replace(' ','_',$ret);
  17.         $ret=strtolower($ret);
  18.         break;
  19.     case 'list':
  20.         $ret=substr($ret,-strlen('.php'));
  21.         $ret=substr($ret,strlen('prj_'));
  22.         break;
  23.     default:
  24.         break;
  25.     }
  26.     return $ret;
  27. }
  28.  
  29. function include_listings($path)
  30. {
  31.     global $nen;
  32.  
  33.     $ret=array();
  34.    
  35.     if ($handle = opendir($nen['root'].'/'.$path.'/'));
  36.     {
  37.         //echo "Directory handle: $handle\n";
  38.         //echo "Entries:\n";
  39.    
  40.         /* This is the correct way to loop over the directory. */
  41.         while (false !== ($entry = readdir($handle)))
  42.             if(is_file($nen['root'].'/'.$path.'/'.$entry))
  43.             //if (($entry!=='.')&&($entry!=='..'))
  44.                 if (substr($entry,-strlen('.'.$nen['php']),strlen('.'.$nen['php']))==='.'.$nen['php'])
  45.                     {
  46.                         include_once($nen['root'].'/'.$path.'/'.$entry); //"$entry\n";
  47.                         if (function_exists(namingway($entry,'prj')))
  48.                             eval ('$ret[] = '.namingway($entry,'prj').'();');
  49.                             //echo htmlentities(var_dump($ret[$entry]));
  50.                     }
  51.         /* This is the WRONG way to loop over the directory. */
  52.         // while ($entry = readdir($handle)) {
  53.         // include_once $entry; //echo "$entry\n";
  54.         // }
  55.  
  56.         closedir($handle);
  57.     }
  58.     //echo htmlentities(var_dump($ret));
  59.     jensort($ret);
  60.     return $ret;
  61. }
  62.  
  63. ?>
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement