<?php

function include_configuration_file($file_path, $languages="all")
{
   if (!file_exists($file_path)) return;

   $content = file($file_path);
   $operations = array("define_in_php", "write_to_javascript_file");

   if ($languages == "all" || $languages == "javascript")
   {
      erase_file_contents(JAVASCRIPT_CONFIG_FILE_PATH);
   }

   switch ($languages)
   {
      case "php":
         return parse_configuration($content, $operations[0]);
      case "javascript":
         return parse_configuration($content, $operations[1]);
      default:
         return parse_configuration($content, $operations);
   }
}

function parse_configuration($body, $operations=NULL)
{
   $operations = (!is_array($operations)) ? array($operations) : $operations;
   foreach ($body as $line)
   {
      if (preg_match("/^ *#.*$/", $line) || trim($line) == "") continue;
      $equality = explode("=", $line, 2);
      $variable = strtoupper(trim($equality[0]));
      $variable = str_replace(" ", "_", $variable);
      $value = trim($equality[1]);
      foreach ($operations as $operation)
      {
         call_user_func($operation, $variable, $value);
      }
   }
}

function write_to_javascript_file($variable, $value)
{
   $equality = "var " . $variable . " = \"" . $value . "\";\n";
   file_put_contents(JAVASCRIPT_CONFIG_FILE_PATH, $equality, FILE_APPEND);
}

function define_in_php($variable, $value)
{
   $GLOBALS[$variable] = $value;
}

function erase_file_contents($file_path)
{
   $fp = fopen($file_path, 'w');
   fclose($fp);
}
<?php
namespace type;

function convert_to_array($item)
{
   if (is_array($item) == False)
   {
      return array($item);
   }

   return $item;
}
<?php
namespace sort;

function quick_sort(array &$array, $comparer=null, $left=0, $right=null)
{
   $right = set_right_index($right, $array);
   if ($right > $left)
   {
      $pivot = calculate_pivot_index($left, $right);
      $new_pivot = partition($array, $comparer, $left, $right, $pivot);
      quick_sort($array, $comparer, $left, $new_pivot - 1);
      quick_sort($array, $comparer, $new_pivot + 1, $right);
   }
}

function set_right_index($index, $array)
{
   if (is_null($index))
   {
      $index = count($array) - 1;
   }
   return $index;
}

function calculate_pivot_index($left_index, $right_index)
{
   $pivot_index = $right_index - ($right_index - $left_index) / 2;
   return $pivot_index;
}

function partition(&$array, $comparer, $left, $right, $pivot_index)
{
   $pivot_value = $array[$pivot_index];
   swap($array, $right, $pivot_index);
   $current = $left;
   for ($ii = $left; $ii < $right; $ii++)
   {
      $comparison = make_comparison($comparer, $array[$ii], $pivot_value);
      if ($comparison === True)
      {
         swap($array, $ii, $current++);
      }
   }
   swap($array, $current, $right);
   return $current;
}

function swap(&$array, $index_1, $index_2)
{
   $value = $array[$index_1];
   $array[$index_1] = $array[$index_2];
   $array[$index_2] = $value;
}

function make_comparison($comparer, $value_1, $value_2)
{
   if (!is_null($comparer))
   {
      $comparison = call_user_func($comparer, $value_1, $value_2);
   }
   else
   {
      $comparison = ($value_1 < $value_2);
   }
   return $comparison;
}
<?php
namespace file;

function count_depth($path)
{
   $stripped_path = trim($path, "/");
   return sizeof(explode("/", $path));
}
<?php

function remove_directory($directory_path, $remove_self=True)
{
   $directory_path = rtrim($directory_path, "/") . "/";
   $directory = opendir($directory_path);
   while ($file = readdir($directory))
   {
      if ($file[0] == '.') continue;
      
      $relative_path = $directory_path . $file;
      if (is_dir($relative_path))
      {
         remove_directory($relative_path);
         continue;
      }
      unlink($relative_path);
   }
   if ($remove_self) rmdir($directory_path);
}
<?php
namespace file;

function is_directory_empty($directory_path)
{
   $files = scandir($directory_path);
   return count($files) > 2;
}
<?php

function print_file_range($fp, $start, $end)
{
   fseek($fp, $start);
   echo "$start - $end\n";
   echo fread($fp, $end-$start) . "\n";
   
}
<?php

function build_path($directory_path, $file_path)
{
   $directory_path = rtrim($directory_path, "/") . "/";
   $path = $directory_path . $file_path;
   return $path;
}
18.210.22.132
18.210.22.132
18.210.22.132
 
June 5, 2016