function directory_to_array($directory, $extension = "", $full_path = true)
{
    $array_items = array();
    if ($handle = opendir($directory)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                if (is_dir($directory . "/" . $file)) {
                    $array_items = array_merge($array_items, directory_to_array($directory . "/" . $file, $extension, $full_path));
                } else {
                    $file_ext = substr(strrchr($file, "."), 1);
                    if (!$extension || in_array($file_ext, $extension)) {
                        if ($full_path) {
                            $array_items[] = $directory . "/" . $file;
                        } else {
                            $array_items[] = $file;
                        }
                    }
                }
            }
        }
        closedir($handle);
    } else {
        die(TEXT_FAILED_OPEN_DIR . $directory);
    }
    return $array_items;
}
function directory_to_array($directory, $ignores = NULL, $only_binary_files = false)
{
    if (!$ignores) {
        $ignores = array('.', '..');
    }
    $array_items = array();
    $handle = @opendir($directory);
    if (!$handle) {
        return array();
    }
    $file = readdir($handle);
    $dirs = array();
    while ($file !== false) {
        if (in_array($file, $ignores)) {
            $file = readdir($handle);
            continue;
        }
        $filepath = realpath($directory . "/" . $file);
        $dir = array_pop(explode("/", $directory));
        if (!is_readable($filepath)) {
            $file = readdir($handle);
            continue;
        }
        if (is_dir($filepath)) {
            array_push($dirs, $filepath);
        } else {
            if ($only_binary_files && !is_binary($filepath)) {
                $file = readdir($handle);
                continue;
            }
            $relative_path = $dir != '' ? $dir . "/" : '';
            $array_items[] = preg_replace("/\\/\\//si", "/", $relative_path . $file);
        }
        $file = readdir($handle);
    }
    sort($array_items);
    sort($dirs);
    foreach ($dirs as $filepath) {
        $files = directory_to_array($filepath, $ignores, $only_binary_files);
        if ($dir != '') {
            array_walk($files, 'add_prefix', $dir);
        }
        $array_items = array_merge($array_items, $files);
    }
    closedir($handle);
    return $array_items;
}
Beispiel #3
0
function directory_to_array($directory, $extension = "", $full_path = true)
{
    $array_items = array();
    if (!($contents = scandir($directory))) {
        return $array_items;
    }
    foreach ($contents as $file) {
        if ($file != "." && $file != "..") {
            if (is_dir($directory . "/" . $file)) {
                $array_items = array_merge($array_items, directory_to_array($directory . "/" . $file, $extension, $full_path));
            } else {
                $file_ext = substr(strrchr($file, "."), 1);
                if (!$extension || in_array($file_ext, $extension)) {
                    $array_items[] = $full_path ? $directory . "/" . $file : $file;
                }
            }
        }
    }
    return $array_items;
}
Beispiel #4
0
 public function get_available_models()
 {
     $CI =& get_instance();
     $CI->load->helper('directory');
     $CI->load->helper('file');
     $all_models = array();
     $exclude = array('index.html');
     $models = directory_to_array(APPPATH . 'models/', TRUE, $exclude, FALSE, TRUE);
     $all_models['application'] = array_combine($models, $models);
     // loop through allowed modules and get models
     $modules_allowed = $CI->config->item('modules_allowed', 'fuel');
     foreach ($modules_allowed as $module) {
         $module_path = MODULES_PATH . $module . '/models/';
         if (file_exists($module_path)) {
             $models = directory_to_array($module_path, TRUE, $exclude, FALSE, TRUE);
             $all_models[$module] = array_combine($models, $models);
         }
     }
     return $all_models;
 }
 /**
  * Returns whether documenation exists for the advanced module
  *
  * @access	public
  * @return	boolean
  */
 public function tests()
 {
     $dir_path = $this->server_path() . 'tests/';
     $tests = array();
     // if a directory, grab all the tests in it
     if (is_dir($dir_path)) {
         $tests = directory_to_array($dir_path);
     }
     return $tests;
 }
function um_component_directory_get_all_files($component, $binary = false)
{
    if (!$component || !isset($component->path)) {
        return array();
    }
    if (!is_dir($component->path)) {
        return array();
    }
    $path = $component->path;
    if (substr($path, -1) != '/') {
        $path .= "/";
    }
    $files = directory_to_array($path, array('.svn', '.cvs', '.git', '.', '..'), $binary);
    $blacklisted = um_component_get_all_blacklisted($component);
    return array_diff($files, $blacklisted);
}
Beispiel #7
0
function DBSavePost($post_id, $pinned, $boardName, $title, $content, $user_id, $added_tags, $deleted_tags)
{
    $date = getTime();
    global $db;
    $stmt = $db->stmt_init();
    if ($stmt->prepare('CALL Check_Post_Owner(?,?)')) {
        $stmt->bind_param('ii', $post_id, $user_id);
        $stmt->execute();
        $stmt->bind_result($result);
        $stmt->fetch();
        $stmt->close();
        if ($result == 0 || $post_id == -1) {
            $db->next_result();
            $stmt = $db->stmt_init();
            //htmlspecialchars($title, ENT_HTML401, 'UTF-8', false)
            if ($stmt->prepare('CALL Save_Post(?,?,?,?,?,?,?,?)')) {
                $stmt->bind_param('isiissii', $post_id, $boardName, $user_id, $pinned, $title, $content, $date, $date);
                $stmt->execute();
                $post_id_out = NULL;
                $stmt->bind_result($post_id_out);
                $stmt->fetch();
                $stmt->close();
                if ($added_tags != null) {
                    for ($t = 0; $t < sizeof($added_tags); $t++) {
                        DBSavePostTag($post_id_out, $added_tags[$t], "Save");
                    }
                }
                if ($deleted_tags != null) {
                    for ($t = 0; $t < sizeof($deleted_tags); $t++) {
                        DBSavePostTag($post_id_out, $deleted_tags[$t], "Delete");
                    }
                }
                if ($post_id_out > 0) {
                    $encoded_post_id = str_replace("/", "SLASH", fnEncrypt("p" . $post_id_out));
                    $user_dir = "../tmp/" . $user_id . "/";
                    $target_dir = "../upload/" . $encoded_post_id . "/";
                    $files = directory_to_array($user_dir);
                    // if there are more than 0 files in the ../tmp/[UserID] directory
                    if (sizeof($files) > 0) {
                        // if ../upload/[UserID] direcoty does not exists, create the directory
                        if (!(file_exists($target_dir) && is_dir($target_dir))) {
                            @mkdir($target_dir, 0777, true);
                        } else {
                            //delete all files
                        }
                        $index = 0;
                        while ($file = $files[$index++]) {
                            $filesize = filesize($file);
                            $filealias = end(explode("/", $file));
                            $fileextension = end(explode(".", $filealias));
                            $filename = substr($filealias, 14);
                            $fileDirectory = $target_dir . $filename;
                            $fileAddress = publicUrl . "/upload/" . $encoded_post_id . "/" . $filename;
                            //DB Save
                            //$result = DBSaveUploadFile($fileextension, $post_id_out, -1, $filesize, $fileDirectory, $fileAddress);
                            //Check Image is in the DOM
                            $doc = new DOMDocument();
                            @$doc->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'));
                            $tags = $doc->getElementsByTagName('img');
                            foreach ($tags as $tag) {
                                $source = $tag->getAttribute('src');
                                if ($source == $user_dir . $filealias) {
                                    $tag->removeAttribute('src');
                                    $tag->setAttribute('src', $fileDirectory);
                                }
                            }
                            $newContent = @$doc->saveHTML('body');
                            $newContent = str_replace('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">', '', $newContent);
                            $db->next_result();
                            $stmt = $db->stmt_init();
                            //htmlspecialchars($title, ENT_HTML401, 'UTF-8', false)
                            if ($stmt->prepare('CALL Save_Post(?,?,?,?,?,?,?,?)')) {
                                $stmt->bind_param('isiissii', $post_id, $boardName, $user_id, $pinned, $title, $newContent, $date, $date);
                                $stmt->execute();
                                $post_id_out = NULL;
                                $stmt->bind_result($post_id_out);
                                $stmt->fetch();
                                $stmt->close();
                            }
                            //Move file from /tmp/ to /upload/
                            rename($file, $user_dir . $filename);
                            copy($user_dir . $filename, $target_dir . $filename);
                            unlink($user_dir . $filename);
                        }
                    }
                }
                return $post_id_out;
            }
        }
    }
    return -1;
}
 /**
  * Returns a list of file types that are allowed for a particular folder
  *
  * @access	public
  * @param	string	folder name
  * @param	boolean	will recursively look inside nested folders. Default is FALSE
  * @param	boolean	will include the server path. Default is FALSE
  * @return	mixed
  */
 public function dir_files($folder, $recursive = FALSE, $append_path = FALSE)
 {
     $dir = assets_server_path($folder);
     return directory_to_array($dir, $recursive, array(), $append_path);
 }
 /**
  * Initialize the user preferences
  *
  * Accepts an associative array as input, containing display preferences
  *
  * @access	public
  * @param	array	config preferences
  * @return	void
  */
 public function initialize($config = array())
 {
     // setup any intialized variables
     foreach ($config as $key => $val) {
         if (isset($this->{$key})) {
             $this->{$key} = $val;
         }
     }
     // grab layouts from the directory if layouts auto is true in the fuel_layouts config
     $this->CI->load->helper('file');
     $this->CI->load->helper('directory');
     $layout_path = APPPATH . 'views/' . $this->layouts_folder;
     $layouts = get_filenames($layout_path);
     $layout_files = directory_to_array($layout_path, TRUE);
     if (!empty($layout_files)) {
         foreach ($layout_files as $file) {
             $layout = end(explode('/', $file));
             $layout = substr($layout, 0, -4);
             $file_dir = ltrim(dirname($file), '/');
             if ($file_dir != ltrim($layout_path, '/')) {
                 $group = end(explode('/', $file_dir));
             } else {
                 $group = '';
             }
             // we won't show those that have underscores in front of them'
             if (substr($group, 0, 1) != '_') {
                 if (empty($this->layouts[$layout]) and substr($layout, 0, 1) != '_') {
                     $this->layouts[$layout] = array('class' => 'Fuel_layout', 'group' => $group);
                 } else {
                     if (!empty($this->layouts[$layout])) {
                         if (!is_object($this->layouts[$layout]) and empty($this->layouts[$layout]['group'])) {
                             $this->layouts[$layout]['group'] = $group;
                         }
                     }
                 }
             }
         }
     }
     // grab layouts from advanced module
     $advanced_modules = $this->CI->fuel->modules->advanced(FALSE);
     foreach ($advanced_modules as $mod) {
         $path = $mod->path() . 'config/' . $mod->name() . '_layouts.php';
         if (file_exists($path)) {
             include $path;
             if (!empty($config['layouts'])) {
                 $this->layouts = array_merge($this->layouts, $config['layouts']);
             }
             if (!empty($config['blocks'])) {
                 $this->blocks = array_merge($this->blocks, $config['blocks']);
             }
         } elseif (method_exists($mod, 'setup_layouts')) {
             $mod->setup_layouts();
         }
     }
     // initialize layout objects
     foreach ($this->layouts as $name => $init) {
         $this->add($name, $init);
     }
 }
 /**
  * Deletes an asset and will perform any necessary folder cleanup
  *
  * @access	protected
  * @param	string	An asset file to delete
  * @return	string
  */
 protected function _delete($file)
 {
     $CI =& get_instance();
     $file = $this->get_file($file);
     $deleted = FALSE;
     // cleanup beginning slashes
     $doc_root = preg_replace("!{$_SERVER['SCRIPT_NAME']}\$!", '', $_SERVER['SCRIPT_FILENAME']);
     $filepath = $doc_root . $file;
     // normalize file path
     $parent_folder = dirname($filepath) . '/';
     if (file_exists($filepath)) {
         $deleted = unlink($filepath);
     }
     $max_depth = 5;
     $i = 0;
     $end = FALSE;
     while (!$end) {
         // if it is the last file in a subfolder (not one of the main asset folders), then we recursively remove the folder to clean things up
         $excluded_asset_folders = $CI->fuel->assets->excluded_asset_server_folders();
         if (!in_array($parent_folder, $excluded_asset_folders)) {
             $dir_files = directory_to_array($parent_folder);
             // if empty, now remove
             if (empty($dir_files)) {
                 @rmdir($parent_folder);
             } else {
                 $end = TRUE;
             }
         } else {
             $end = TRUE;
         }
         $parent_folder = dirname($parent_folder) . '/';
     }
     $i++;
     if ($max_depth == $i) {
         $end = TRUE;
     }
     return $deleted;
 }
Beispiel #11
0
/**
 * Insert into the DB of the course all the directories
 * @param   string path of the /work directory of the course
 * @return  -1 on error, sql query result on success
 * @author  Julio Montoya
 * @version April 2008
 * @param string $base_work_dir
 */
function insert_all_directory_in_course_table($base_work_dir)
{
    $dir_to_array = directory_to_array($base_work_dir, true);
    $only_dir = array();
    for ($i = 0; $i < count($dir_to_array); $i++) {
        $only_dir[] = substr($dir_to_array[$i], strlen($base_work_dir), strlen($dir_to_array[$i]));
    }
    $course_id = api_get_course_int_id();
    $group_id = api_get_group_id();
    $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
    for ($i = 0; $i < count($only_dir); $i++) {
        $url = $only_dir[$i];
        $params = ['c_id' => $course_id, 'url' => $url, 'title' => '', 'description' => '', 'author' => '', 'active' => '1', 'accepted' => '1', 'filetype' => 'folder', 'post_group_id' => $group_id];
        Database::insert($work_table, $params);
    }
}
Beispiel #12
0
 /**
  * Deletes an asset and will perform any necessary folder cleanup
  *
  * @access	protected
  * @param	string	An asset file to delete
  * @return	string
  */
 protected function _delete($file)
 {
     $CI =& get_instance();
     $file = $this->get_file($file);
     $deleted = FALSE;
     // cleanup beginning slashes
     $assets_folder = WEB_ROOT . $CI->config->item('assets_path');
     $file = trim(str_replace($assets_folder, '', $file), '/');
     // Causes issues in some environments like GoDaddy... was originally changed for the assets to potentially be in a parent folder
     // $doc_root = preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']);
     // $filepath = $doc_root.$file;
     // normalize file path
     $filepath = $assets_folder . $file;
     $parent_folder = dirname($filepath) . '/';
     if (file_exists($filepath)) {
         $deleted = unlink($filepath);
     }
     $max_depth = 5;
     $i = 0;
     $end = FALSE;
     while (!$end) {
         // if it is the last file in a subfolder (not one of the main asset folders), then we recursively remove the folder to clean things up
         $excluded_asset_folders = $CI->fuel->assets->excluded_asset_server_folders();
         if (!in_array($parent_folder, $excluded_asset_folders)) {
             $dir_files = directory_to_array($parent_folder);
             // if empty, now remove
             if (empty($dir_files)) {
                 @rmdir($parent_folder);
             } else {
                 $end = TRUE;
             }
         } else {
             $end = TRUE;
         }
         $parent_folder = dirname($parent_folder) . '/';
     }
     $i++;
     if ($max_depth == $i) {
         $end = TRUE;
     }
     return $deleted;
 }
Beispiel #13
0
 function _get_tests($folder, $module = NULL)
 {
     $return = array();
     if (file_exists($folder)) {
         $tests = directory_to_array($folder);
         foreach ($tests as $test) {
             $dir = '/' . $test;
             if (substr($test, -9) == '_test.php') {
                 $val = str_replace(EXT, '', end(explode('/', $test)));
                 $return[$module . ':' . $dir] = !empty($module) ? '<strong>' . $module . ':</strong> ' . humanize($val) : humanize($val);
             }
         }
     }
     return $return;
 }
Beispiel #14
0
// 			$filealias = end(explode("/", $file));
// 			$filename = substr($filealias, 14);
// 			rename ($file, $user_dir.$filename);
// 			copy ($user_dir.$filename, $target_dir.$filename);
// 			unlink($user_dir.$filename);
// 		}
// 	}
// }
$post_id_out = 217;
$user_id = 52;
if ($post_id_out > 0) {
    echo "hi";
    $encoded_post_id = fnEncrypt("p" . $post_id_out);
    $user_dir = "../tmp/" . $user_id . "/";
    $target_dir = "../upload/" . $encoded_post_id . "/";
    $files = directory_to_array($user_dir);
    echo "hi";
    // if there are more than 0 files in the ../tmp/[UserID] directory
    if (sizeof($files) > 0) {
        echo "hi";
        // if ../upload/[UserID] direcoty does not exists, create the directory
        if (!(file_exists($target_dir) && is_dir($target_dir))) {
            @mkdir($target_dir, 0777, true);
        } else {
            //delete all files
        }
        $index = 0;
        while ($file = $files[$index++]) {
            $filesize = filesize($file);
            $filealias = end(explode("/", $file));
            $fileextension = end(explode(".", $filealias));
 /**
  * Returns an array of view files pages used with opt-in controller method
  *
  * @access	public
  * @param	string name of view subfolder to search
  * @return	array
  */
 public function views($subfolder = '')
 {
     $this->CI->load->helper('directory');
     if (!empty($subfolder)) {
         $subfolder = trim($subfolder, '/') . '/';
     }
     $views_path = APPPATH . 'views/' . $subfolder;
     $view_pages = directory_to_array($views_path, TRUE, '/^_(.*)|\\.html$/', FALSE, TRUE);
     sort($view_pages);
     return $view_pages;
 }
Beispiel #16
0
/**
 * Insert into the DB of the course all the directories
 * @param   string path of the /work directory of the course
 * @return  -1 on error, sql query result on success
 * @author  Julio Montoya
 * @version April 2008
 * @param string $base_work_dir
 */

function insert_all_directory_in_course_table($base_work_dir)
{
    $dir_to_array = directory_to_array($base_work_dir, true);
    $only_dir = array();

    for ($i = 0; $i < count($dir_to_array); $i++) {
        $only_dir[] = substr($dir_to_array[$i], strlen($base_work_dir), strlen($dir_to_array[$i]));
    }
    $course_id = api_get_course_int_id();
    $group_id  = api_get_group_id();

    for($i = 0; $i < count($only_dir); $i++) {
        global $work_table;
        $url = Database::escape_string($only_dir[$i]);
        $sql = "INSERT INTO " . $work_table . " SET
               c_id         = '$course_id',
               url          = '".$url."',
               title        = '',
               description  = '',
               author       = '',
               active       = '1',
               accepted     = '1',
               filetype     = 'folder',
               post_group_id = '".$group_id."',
               sent_date    = '0000-00-00 00:00:00' ";
        Database::query($sql);
    }
}
 /**
  * Initialize the user preferences
  *
  * Accepts an associative array as input, containing display preferences
  *
  * @access	public
  * @param	array	config preferences
  * @return	void
  */
 public function initialize($config = array())
 {
     // setup any intialized variables
     foreach ($config as $key => $val) {
         if (isset($this->{$key})) {
             $this->{$key} = $val;
         }
     }
     // grab layouts from the directory if layouts auto is true in the fuel_layouts config
     $this->CI->load->helper('file');
     $this->CI->load->helper('directory');
     $layout_path = APPPATH . 'views/' . $this->layouts_folder;
     $layouts = get_filenames($layout_path);
     $layout_files = directory_to_array($layout_path, TRUE);
     if (!empty($layout_files)) {
         foreach ($layout_files as $file) {
             $layout = end(explode('/', $file));
             $layout = substr($layout, 0, -4);
             $file_dir = ltrim(dirname($file), '/');
             if ($file_dir != ltrim($layout_path, '/')) {
                 $group = end(explode('/', $file_dir));
             } else {
                 $group = '';
             }
             // we won't show those that have underscores in front of them'
             if (substr($group, 0, 1) != '_') {
                 if (empty($this->layouts[$layout]) and substr($layout, 0, 1) != '_') {
                     $this->layouts[$layout] = array('class' => 'Fuel_layout', 'group' => $group);
                 } else {
                     if (!empty($this->layouts[$layout])) {
                         if (!is_object($this->layouts[$layout]) and empty($this->layouts[$layout]['group'])) {
                             $this->layouts[$layout]['group'] = $group;
                         }
                     }
                 }
             }
         }
     }
     // initialize layout objects
     foreach ($this->layouts as $name => $init) {
         $layout = $this->create($name, $init);
         if ($layout) {
             $this->_layouts[$name] = $layout;
         }
     }
 }
 /**
  * Returns an array with the keys as links and the values as the name of the file
  * 
  * @access	public
  * @param	stirng	The name of the folder relative to the MODULES_PATH
  * @param	string	Module folder name (optional)
  * @param	array	An array of files to exclude from the list (optional)
  * @return	array
  */
 function folder_files($folder, $module = NULL, $exclude = array())
 {
     $this->CI->load->helper('file');
     $this->CI->load->helper('directory');
     $folder_arr = explode('/', $folder);
     if (isset($folder_arr[1])) {
         $module = $folder_arr[0];
         $folder = $folder_arr[1];
     }
     if (empty($module)) {
         $module = $this->page_segment(2);
     }
     $module_path = MODULES_PATH . $module . '/';
     // force exclude to an array
     $exclude = (array) $exclude;
     // add PHP extension if it doesn't exist'
     foreach ($exclude as $key => $val) {
         if (!preg_match('#.+\\.php$#', $val)) {
             $exclude[$key] = $val . EXT;
         }
     }
     $exclude[] = 'index.html';
     $files = directory_to_array($module_path . $folder, FALSE, $exclude, FALSE, TRUE);
     $return = array();
     if (is_array($files)) {
         foreach ($files as $file) {
             if ($module != FUEL_FOLDER) {
                 $url = user_guide_url('modules/' . $module . '/' . strtolower($file));
             } else {
                 $url = user_guide_url(strtolower($file));
             }
             $return[$url] = humanize($file);
         }
     }
     return $return;
 }
Beispiel #19
0
 public function test_page_cache()
 {
     // create a page so we can load it to create the cached files
     $location = 'test-cache';
     $page = $this->fuel->pages->create($location);
     $page->layout = 'none';
     $page_vars = array('body' => 'This is a test {date("Y-m-d")}', 'blocks' => FALSE);
     $page->add_variables($page_vars);
     $page->save();
     // now load the page to cache it
     $page_contents = $this->load_page($location);
     $cache_id = $this->fuel->cache->create_id($location);
     $test = $this->fuel->cache->is_cached($cache_id, $this->fuel->config('page_cache_group'));
     $expected = TRUE;
     $this->run($test, $expected, 'Test that pages are being cached');
     // check compiled folder to see how if any files exists
     $dwoo = $this->CI->config->item('cache_path') . 'dwoo/compiled/';
     $files = get_filenames($dwoo);
     $test = count($files) > 1;
     // take into account index.html
     $expected = TRUE;
     $this->run($test, $expected, 'Test that the compiled template was created', '****May fail if run via CLI because the folders can\'t be removed****');
     // now clear the compiled folder
     $this->fuel->cache->clear_compiled();
     $files = directory_to_array($dwoo);
     $test = count($files) == 1;
     $expected = TRUE;
     $this->run($test, $expected, 'Test that the compiled template directory was deleted');
     // remove the page... gets deleted with closing of script and database... cache still exists because of permissions issue
     //$page->delete();
 }
Beispiel #20
0
/**
 * Insert into the DB of the course all the directories
 * @param	string path of the /work directory of the course
 * @return	-1 on error, sql query result on success
 * @author 	Julio Montoya Dokeos
 * @version April 2008
 */
function insert_all_directory_in_course_table($base_work_dir)
{
    $dir_to_array = directory_to_array($base_work_dir, true);
    $only_dir = array();
    for ($i = 0; $i < count($dir_to_array); $i++) {
        $only_dir[] = substr($dir_to_array[$i], strlen($base_work_dir), strlen($dir_to_array[$i]));
    }
    $course_id = api_get_course_int_id();
    $group_id = api_get_group_id();
    for ($i = 0; $i < count($only_dir); $i++) {
        global $work_table;
        $sql_insert_all = "INSERT INTO " . $work_table . " SET\n\t\t\t\t\t\t\t   c_id \t\t= '{$course_id}',\n\t\t\t\t\t\t\t   url \t\t\t= '" . $only_dir[$i] . "',\n\t\t\t\t\t\t\t   title        = '',\n\t\t\t                   description \t= '',\n\t\t\t                   author      \t= '',\n\t\t\t\t\t\t\t   active\t\t= '0',\n\t\t\t\t\t\t\t   accepted\t\t= '1',\n\t\t\t\t\t\t\t   filetype\t\t= 'folder',\n\t\t\t\t\t\t\t   post_group_id = '" . $group_id . "',\n\t\t\t\t\t\t\t   sent_date\t= '0000-00-00 00:00:00' ";
        Database::query($sql_insert_all);
    }
}
Beispiel #21
0
 function all_pages_including_views($paths_as_keys = FALSE, $apply_site_url = TRUE, $include_modules = TRUE)
 {
     $CI =& get_instance();
     $CI->load->helper('directory');
     $CI->load->module_library(FUEL_FOLDER, 'fuel_modules');
     $cms_pages = $this->list_locations(FALSE);
     // get valid view files that may show up
     $views_path = APPPATH . 'views/';
     $view_files = directory_to_array($views_path, true, '/^_(.*)/', FALSE, TRUE);
     // module pages
     if ($include_modules) {
         $module_pages = $CI->fuel_modules->get_pages();
     }
     // merge them together for a complete list
     $pages = array();
     // must get the merged unique values (array_values resets the indexes)
     $pages = array_values(array_unique(array_merge($cms_pages, $view_files, $module_pages)));
     sort($pages);
     if ($paths_as_keys) {
         $keyed_pages = array();
         foreach ($pages as $page) {
             $key = $apply_site_url ? site_url($page) : $page;
             $keyed_pages[$key] = $page;
         }
         $pages = $keyed_pages;
     }
     // apply the site_url function to all pages
     return $pages;
 }
/**
 * Returns an array of file names from a directory
 *
 * @access	public
 * @param 	string
 * @param 	boolean
 * @param 	mixed
 * @param 	boolean
 * @return	array
 */
function directory_to_array($directory, $recursive = TRUE, $exclude = array(), $append_path = TRUE, $no_ext = FALSE, $_first_time = TRUE)
{
    static $orig_directory;
    if ($_first_time) {
        $orig_directory = $directory;
    }
    $array_items = array();
    if ($handle = @opendir($directory)) {
        while (false !== ($file = readdir($handle))) {
            if (strncmp($file, '.', 1) !== 0 and (empty($exclude) or is_array($exclude) and !in_array($file, $exclude) or is_string($exclude) and !preg_match($exclude, $file))) {
                if (is_dir($directory . "/" . $file)) {
                    if ($recursive) {
                        $array_items = array_merge($array_items, directory_to_array($directory . "/" . $file, $recursive, $exclude, $append_path, $no_ext, FALSE));
                    }
                } else {
                    if ($no_ext) {
                        $period_pos = strrpos($file, '.');
                        if ($period_pos) {
                            $file = substr($file, 0, $period_pos);
                        }
                    }
                    $file_prefix = !$append_path ? substr($directory, strlen($orig_directory)) : $directory;
                    $file = $file_prefix . "/" . $file;
                    $file = str_replace("//", "/", $file);
                    // replace double slash
                    if (substr($file, 0, 1) == '/') {
                        $file = substr($file, 1);
                    }
                    // remove begining slash
                    if (!empty($file) and !in_array($file, $array_items)) {
                        $array_items[] = $file;
                    }
                }
            }
        }
        closedir($handle);
    }
    return $array_items;
}
Beispiel #23
0
function DBSavePost($post_id, $pinned, $boardName, $title, $content, $user_id, $added_tags, $deleted_tags, $addedFiles, $deletedFiles)
{
    //echo json_encode_unescaped($addedFiles);
    $date = getTime();
    global $db;
    $stmt = $db->stmt_init();
    if ($pinned && $_SESSION['UserLevel'] > exec_level) {
        $pinned = false;
    }
    if ($stmt->prepare('CALL Check_Post_Owner(?,?)')) {
        $stmt->bind_param('ii', $post_id, $user_id);
        $stmt->execute();
        $stmt->bind_result($result);
        $stmt->fetch();
        $stmt->close();
        if ($result == 0 || $post_id == -1) {
            $db->next_result();
            $stmt = $db->stmt_init();
            //htmlspecialchars($title, ENT_HTML401, 'UTF-8', false)
            if ($stmt->prepare('CALL Save_Post(?,?,?,?,?,?,?,?)')) {
                $stmt->bind_param('isiissii', $post_id, $boardName, $user_id, $pinned, $title, $content, $date, $date);
                $stmt->execute();
                $post_id_out = NULL;
                $stmt->bind_result($post_id_out);
                $stmt->fetch();
                $stmt->close();
                if ($added_tags != null) {
                    for ($t = 0; $t < sizeof($added_tags); $t++) {
                        DBSavePostTag($post_id_out, $added_tags[$t], "Save");
                    }
                }
                if ($deleted_tags != null) {
                    for ($t = 0; $t < sizeof($deleted_tags); $t++) {
                        DBSavePostTag($post_id_out, $deleted_tags[$t], "Delete");
                    }
                }
                if ($post_id_out > 0) {
                    $encoded_post_id = str_replace("/", "SLASH", fnEncrypt("p" . $post_id_out));
                    $user_dir = "../tmp/" . $user_id . "/";
                    $target_dir = "../upload/" . $encoded_post_id . "/";
                    // if there are more than 0 files in the ../tmp/[UserID] directory
                    if (sizeof($addedFiles) > 0) {
                        $currentfiles = directory_to_array($user_dir);
                        $index = 0;
                        while ($existingFile = $currentfiles[$index++]) {
                            $alias = end(split("/", $existingFile));
                            $array = split("-", $alias);
                            $fileTime = $array[0] / 1000;
                            $time = getTime();
                            if ($time - $fileTime > 86400) {
                                unlink($existingFile);
                            }
                        }
                        // if ../upload/[UserID] direcoty does not exists, create the directory
                        if (!(file_exists($target_dir) && is_dir($target_dir))) {
                            @mkdir($target_dir, 0777, true);
                        }
                        $index = 0;
                        while ($file = $addedFiles[$index++]['file']) {
                            $filesize = filesize($user_dir . $file['alias']);
                            $filealias = $file['alias'];
                            $fileextension = end(explode(".", $filealias));
                            $filename = $file['name'];
                            //echo "{filealias:" . $filealias . "\n filename:" . $filename ."}";
                            $filename_no_ext = substr($filename, 0, strlen($filename) - strlen($fileextension) - 1);
                            $oldfilename = $filename;
                            $fileSufix = '';
                            $fileCounter = 1;
                            while (file_exists($target_dir . $filename)) {
                                $filename = $filename_no_ext . '(' . $fileCounter . ').' . $fileextension;
                                $fileCounter++;
                            }
                            $fileDirectory = $target_dir . $filename;
                            $fileAddress = publicUrl . "/upload/" . $encoded_post_id . "/" . $filename;
                            //DB Save
                            $result = DBSaveUploadFile($fileextension, $post_id_out, -1, $filesize, $fileDirectory, $fileAddress, $filename);
                            //Check Image is in the DOM
                            $doc = new DOMDocument();
                            @$doc->loadHTML(mb_convert_encoding(str_replace("&", "&amp;", $content), 'HTML-ENTITIES', 'UTF-8'));
                            $tags = $doc->getElementsByTagName('img');
                            foreach ($tags as $tag) {
                                $source = $tag->getAttribute('src');
                                //echo "\r\noriginal source: " . $source;
                                // BYUNGHOON: !==false, ===false is the proper+safe way to check strpos
                                if (strpos($source, $filealias) !== false && strpos($source, "\\/upload\\/") === false) {
                                    $tag->removeAttribute('src');
                                    $tag->setAttribute('src', $fileAddress);
                                    //echo "fileaddress: " . $fileAddress . " \t";
                                }
                            }
                            $newContent = @$doc->saveHTML();
                            $newContent = str_replace('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">', '', $newContent);
                            $newContent = str_replace("&amp;", "&", $newContent);
                            $content = $newContent;
                            $db->next_result();
                            $stmt = $db->stmt_init();
                            //htmlspecialchars($title, ENT_HTML401, 'UTF-8', false)
                            if ($stmt->prepare('CALL Save_Post(?,?,?,?,?,?,?,?)')) {
                                $stmt->bind_param('isiissii', $post_id_out, $boardName, $user_id, $pinned, $title, $content, $date, $date);
                                $stmt->execute();
                                $post_id_out = NULL;
                                $stmt->bind_result($post_id_out);
                                $stmt->fetch();
                                $stmt->close();
                            }
                            //Move file from /tmp/ to /upload/
                            rename($user_dir . $filealias, $user_dir . $filename);
                            copy($user_dir . $filename, $target_dir . $filename);
                            unlink($user_dir . $filename);
                        }
                    }
                }
                if ($deletedFiles != null) {
                    foreach ($deletedFiles as $filename) {
                        $encoded_post_id = str_replace("/", "SLASH", fnEncrypt("p" . $post_id_out));
                        $target_dir = "../upload/" . $encoded_post_id . "/" . $filename;
                        if (file_exists($target_dir)) {
                            unlink($target_dir);
                        }
                        $db->next_result();
                        $stmt = $db->stmt_init();
                        if ($stmt->prepare('CALL Delete_Post_File(?, ?)')) {
                            $stmt->bind_param('is', $post_id, $filename);
                            $stmt->execute();
                            $stmt->close();
                        }
                    }
                }
                return $post_id_out;
            }
        }
    }
    return -1;
}
 function delete($file)
 {
     $CI =& get_instance();
     $CI->load->helper('convert');
     $filepath = WEB_ROOT . $CI->config->item('assets_path') . $file;
     $parent_folder = dirname($filepath) . '/';
     if (file_exists($filepath)) {
         $deleted = unlink($filepath);
     }
     $max_depth = 5;
     $i = 0;
     $end = FALSE;
     while (!$end) {
         // if it is the last file in a subfolder (not one of the main asset folders), then we recursively remove the folder to clean things up
         if (!in_array($parent_folder, $this->_get_excluded_asset_server_folders())) {
             $dir_files = directory_to_array($parent_folder);
             // if empty, now remove
             if (empty($dir_files)) {
                 @rmdir($parent_folder);
             } else {
                 $end = TRUE;
             }
         } else {
             $end = TRUE;
         }
         $parent_folder = dirname($parent_folder) . '/';
     }
     $i++;
     if ($max_depth == $i) {
         $end = TRUE;
     }
     return $deleted;
 }
 public function options_list_with_views($where = array(), $dir_folder = '', $dir_filter = '^_(.*)|\\.html$', $order = TRUE, $recursive = TRUE)
 {
     $CI =& get_instance();
     $CI->load->helper('directory');
     $module_path = APPPATH;
     if (is_array($dir_folder)) {
         $module = key($dir_folder);
         $dir_folder = current($dir_folder);
         if (is_string($module)) {
             $module_path = MODULES_PATH . $module;
         }
     }
     $dir_folder = trim($dir_folder, '/');
     $blocks_path = $module_path . '/views/_blocks/' . $dir_folder;
     // don't display blocks with preceding underscores or .html files'
     $block_files = directory_to_array($blocks_path, $recursive, '#' . $dir_filter . '#', FALSE, TRUE);
     $view_blocks = array();
     foreach ($block_files as $block) {
         $view_blocks[$block] = $block;
     }
     // if a dir_folder exists, then we will look for any CMS blocks that may be prefixed with that dir_folder
     // (e.g. sections/left_block becomes just left_block)
     if (!empty($dir_folder) and empty($where)) {
         $where = 'name LIKE "' . $dir_folder . '/%"';
     }
     $blocks = parent::options_list('name', 'name', $where, $order);
     // continue filter of cms blocks dir_folder is specified
     $cms_blocks = array();
     if (!empty($dir_folder)) {
         $cms_blocks = array();
         foreach ($blocks as $key => $val) {
             $key = preg_replace('#^' . $dir_folder . '/(.+)#', '$1', $key);
             $cms_blocks[$key] = $key;
         }
     } else {
         $cms_blocks = $blocks;
     }
     $blocks = array_merge($view_blocks, $cms_blocks);
     if ($order) {
         ksort($blocks);
     }
     return $blocks;
 }
 /**
  * Deletes an asset and will perform any necessary folder cleanup
  *
  * @access	protected
  * @param	string	An asset file to delete
  * @return	string
  */
 protected function _delete($file)
 {
     $CI =& get_instance();
     $file = $this->get_file($file);
     $deleted = FALSE;
     // cleanup beginning slashes
     $assets_folder = WEB_ROOT . $CI->config->item('assets_path');
     $file = trim(str_replace($assets_folder, '', $file), '/');
     // normalize file path
     $filepath = $assets_folder . $file;
     $parent_folder = dirname($filepath) . '/';
     if (file_exists($filepath)) {
         $deleted = unlink($filepath);
     }
     $max_depth = 5;
     $i = 0;
     $end = FALSE;
     while (!$end) {
         // if it is the last file in a subfolder (not one of the main asset folders), then we recursively remove the folder to clean things up
         $excluded_asset_folders = $CI->fuel->assets->excluded_asset_server_folders();
         if (!in_array($parent_folder, $excluded_asset_folders)) {
             $dir_files = directory_to_array($parent_folder);
             // if empty, now remove
             if (empty($dir_files)) {
                 @rmdir($parent_folder);
             } else {
                 $end = TRUE;
             }
         } else {
             $end = TRUE;
         }
         $parent_folder = dirname($parent_folder) . '/';
     }
     $i++;
     if ($max_depth == $i) {
         $end = TRUE;
     }
     return $deleted;
 }
Beispiel #27
0
 /**
  * Returns an array of view files pages used with opt-in controller method
  *
  * @access	public
  * @return	array
  */
 public function views()
 {
     $this->CI->load->helper('directory');
     $views_path = APPPATH . 'views/';
     $view_pages = directory_to_array($views_path, TRUE, '/^_(.*)|\\.html$/', FALSE, TRUE);
     return $view_pages;
 }