function create_data() { $svg_file = find_file($this->paths['tempdir'], '.svg'); $return = array(); if (empty($svg_file)) { zn_delete_folder($this->paths['tempdir']); $return['message'] = 'The zip did not contained any svg files.'; } $file_data = file_get_contents(trailingslashit($this->paths['tempdir']) . $svg_file); if (!is_wp_error($file_data) && !empty($file_data)) { $xml = simplexml_load_string($file_data); $font_attr = $xml->defs->font->attributes(); $this->font_name = (string) $font_attr['id']; $icon_list = array(); $glyphs = $xml->defs->font->children(); $class = ''; foreach ($glyphs as $item => $glyph) { if ($item == 'glyph') { $attributes = $glyph->attributes(); $unicode = (string) $attributes['unicode']; $d = (string) $attributes['d']; if ($class != 'hidden' && !empty($d)) { $unicode_key = trim(json_encode($unicode), '\\\\"'); if ($item == 'glyph' && !empty($unicode_key) && trim($unicode_key) != '') { $icon_list[$this->font_name][$unicode_key] = $unicode_key; } } } } if (!empty($icon_list) && !empty($this->font_name)) { $icon_list_file = fopen($this->paths['tempdir'] . '/icon_list.php', 'w'); if ($icon_list_file) { fwrite($icon_list_file, '<?php $icons = array();'); foreach ($icon_list[$this->font_name] as $unicode) { if (!empty($unicode)) { $delimiter = "'"; if (strpos($unicode, "'") !== false) { $delimiter = '"'; } fwrite($icon_list_file, "\r\n" . '$icons[\'' . $this->font_name . '\'][' . $delimiter . $unicode . $delimiter . '] = ' . $delimiter . $unicode . $delimiter . ';'); } } fclose($icon_list_file); } else { zn_delete_folder($this->paths['tempdir']); $return['message'] = 'There was a problem creating the icon list file'; return; } // RENAME ALL FILES SO WE CAN LOAD THEM BY FONT NAME $this->rename_files(); // RENAME THE FOLDER WITH THE FONT NAME $this->rename_folder(); // ADD FONT DATA TO FONT OPTION $this->add_font_data(); } } else { $return['message'] = 'The svg file could not be opened.'; } return $return; }
function smarty_function_picture($params, $template) { $src = smarty_plugin_get_variable($params, $template, 'src', true); $alt = smarty_plugin_get_variable($params, $template, 'alt'); $path = smarty_plugin_get_variable($params, $template, 'path'); $CI =& get_instance(); $CI->load->helper('image'); $file = find_file($src, 'static/img/'); // Try to find the image in static/img if ($file == null) { // We can't read the file $file = find_file($src, 'static/uploads/'); if ($file == null) { $src = 'default.png'; } } $size = get_image_size($src); $size = $size['width']; $attr = $params; $medias = array(); $ret = array(); $attr['src'] = $src; if ($path != '') { $attr['path'] = site_url($path); } $ret[] = '<picture ' . _parse_form_attributes($attr, array()) . ' >'; foreach ($params as $key => $value) { // Check if user has set the customized media if (strpos($key, 'media') !== false) { $media = str_replace('media', '', $key); $medias[] = $media; $ret[] = "\t" . '<source src="' . site_url('responsive/size/' . $value . '/' . $src) . '" media="(min-width:' . $media . 'px)">'; continue; } $attr[$key] = smarty_plugin_get_variable($params, $template, $key, false); } if ($path == '') { $resolutions = get_ci_config('resolutions'); foreach ($resolutions as $res) { if (array_search($res, $medias) !== false) { // If the resolution is already covered continue; } $ret[] = "\t" . '<source src="' . site_url('responsive/size/' . (double) $res / 2880 * (double) $size . '/' . $src) . '" media="(min-width:' . $res . 'px)">'; } } $ret[] = "\t" . '<noscript>'; $ret[] = "\t\t" . '<img src="' . site_url('static/img/' . $src) . '" alt="' . $alt . '">'; $ret[] = "\t" . '</noscript>'; $ret[] = '</picture>'; return implode("\n", $ret); }
function find_file($dirname, $fname, &$file_path) { $dir = opendir($dirname); while ($file = readdir($dir)) { if (empty($file_path) && $file != '.' && $file != '..') { if (is_dir($dirname . '/' . $file)) { find_file($dirname . '/' . $file, $fname, $file_path); } else { if (file_exists($dirname . '/' . $fname)) { $file_path = $dirname . '/' . $fname; return; } } } } }
function smarty_function_action($params, $template) { $action = get_default($params, 'obj', null); $alt = get_default($params, 'alt', ''); if ($action == null) { trigger_error('The obj parameter is required for action!'); return ''; } if (gettype($action) != 'object' || get_class($action) != 'Action') { trigger_error('The obj parameter must be of Class Action!'); return ''; } $fields = json_decode($action->fields); ci_log('The action to show is', $action); $data = array(); $uri = $action->uri(); if ($uri) { $data['href'] = $uri; } $content = lang($action->label); if (isset($action->logo) && $action->logo != '') { $data = array('src' => $action->logo, 'path' => '/responsive/size', 'data-toggle' => 'tooltip', 'data-placement' => isset($fields->placement) ? $fields->placement : 'right', 'data-original-title' => $action->label); $CI =& get_instance(); $CI->load->helper('image'); $file = find_file($data['src'], 'static/img/'); // Try to find the image in static/img if ($file == null) { // We can't read the file $data['src'] = 'default.png'; } $content = smarty_function_picture($data, $template); if (isset($action->controller) && isset($action->method) && $uri) { $data['href'] = $uri; } } return build_tag('a', $data, $content); }
public function download_song($username, $song_url) { if (!$this->ion_auth->username_check($username)) { redirect('errors/page_missing', 'refresh'); } //cached DB call $user = $this->cache->model('User_model', 'get_user_info', array($username), 300); // keep for 5 minutes //$user = $this->User_model->get_user_info($username); $where = array('user_id' => $user->id, 'song_url' => $song_url); //cached DB call $song = $this->cache->model('Song_model', 'get_song_where', array($where), 300); // keep for 5 minutes //$song = $this->Song_model->get_song_where(array('user_id'=>$user->id,'song_url'=>$song_url)); if ($this->uri->segment(5) == NULL) { redirect(base_url('song/' . $username . '/' . $song_url), 'refresh'); } //hash is set in the url so get the params from the url and compare to the current timestamp $hashGiven = $this->uri->segment(5); $timestamp = $this->uri->segment(4); $ip = $_SERVER['REMOTE_ADDR']; $salt = 'f**k!these&other$itesit$hiph0pvip0rd!e'; $path = $song->file_name; $hash = md5($salt . $ip . $timestamp . $path); //does the URI->segment(5) hash equal the hash algo from above $hash? is the time from $seg(4) greater than or equal to the current time? if so, proceed, if not, die. if ($hashGiven == $hash && $timestamp >= time()) { /***** *BEGIN DOWNLOAD FILE ******/ define('ALLOWED_REFERRER', ''); // Download folder, i.e. folder where you keep all files for download. // MUST end with slash (i.e. "/" ) define('BASE_DIR', FCPATH . 'audio_uploads/' . $username . '/'); // log downloads? true/false define('LOG_DOWNLOADS', FALSE); // log file name define('LOG_FILE', FCPATH . 'application/logs/downloads.log'); $allowed_ext = array('mp3' => 'audio/mpeg'); // If hotlinking not allowed then make hackers think there are some server problems if (ALLOWED_REFERRER !== '' && (!isset($_SERVER['HTTP_REFERER']) || strpos(strtoupper($_SERVER['HTTP_REFERER']), strtoupper(ALLOWED_REFERRER)) === false)) { die("Internal server error. Please contact system administrator."); } // Make sure program execution doesn't time out // Set maximum script execution time in seconds (0 means no limit) set_time_limit(0); if (!isset($song) || empty($song)) { die("Please specify a song to download."); } // Get real file name. // Remove any path info to avoid hacking by adding relative path, etc. $fname = basename($song->file_name); // get full file path (including subfolders) $file_path = ''; find_file(BASE_DIR, $fname, $file_path); if (!is_file($file_path)) { die("File does not exist. Make sure you specified correct file name."); } // file size in bytes $fsize = filesize($file_path); // file extension $fext = strtolower(substr(strrchr($fname, "."), 1)); // check if allowed extension if (!array_key_exists($fext, $allowed_ext)) { die("Not allowed file type."); } // get mime type if ($allowed_ext[$fext] == '') { $mtype = ''; // mime type is not set, get from server settings if (function_exists('mime_content_type')) { $mtype = mime_content_type($file_path); } else { if (function_exists('finfo_file')) { $finfo = finfo_open(FILEINFO_MIME); // return mime type $mtype = finfo_file($finfo, $file_path); finfo_close($finfo); } } if ($mtype == '') { $mtype = "application/force-download"; } } else { // get mime type defined by admin $mtype = $allowed_ext[$fext]; } //REMOVE UNDERSCORES FROM FILENAME $asfname = str_replace('_', ' ', $fname); // set headers header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Type: {$mtype}"); header("Content-Disposition: attachment; filename=\"{$asfname}\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . $fsize); // download // @readfile($file_path); $file = @fopen($file_path, "rb"); if ($file) { while (!feof($file)) { print fread($file, 1024 * 8); flush(); if (connection_status() != 0) { @fclose($file); die; } } @fclose($file); } // log downloads if (!LOG_DOWNLOADS) { die; } $f = @fopen(LOG_FILE, 'a+'); if ($f) { @fputs($f, date("m.d.Y g:ia") . " " . $_SERVER['REMOTE_ADDR'] . " " . $fname . "\n"); @fclose($f); } } else { die('<div align="center"><strong>Link has expired or is invalid.</strong><br /><a href="' . base_url('song/' . $username . '/' . $song_url) . '">Listen/Download' . $song->song_artist . ' - ' . $song->song_title . '</a></div>'); } }
function xmlrpc_find_file($params) { global $FILE_FOUND; global $FILE_LISTEN_URL; global $FILE_LENGTH; global $FILE_ENCODING; global $FILE_DURATION; $p0 = $params->getParam(0)->scalarval(); // server ID $p1 = $params->getParam(1)->scalarval(); // Asterisk call ID $p2 = $params->getParam(2)->scalarval(); // QM User ID $p3 = $params->getParam(3)->scalarval(); // Qm user name find_file($p0, $p1, $p2, $p3); $response = new XML_RPC_Value(array(new XML_RPC_Value($FILE_FOUND, 'boolean'), new XML_RPC_Value($FILE_LISTEN_URL), new XML_RPC_Value($FILE_LENGTH), new XML_RPC_Value($FILE_ENCODING), new XML_RPC_Value($FILE_DURATION)), "array"); return new XML_RPC_Response($response); }
checkerror("Source directory doesn't exist or can't be written to."); } $ac['SRCDIR'] = $ac['srcdir']; $ac['WORKDIR'] = $ac['srcdir']; $ac['ROOTDIR'] = $ac['rootdir']; $ac['BASEDIR'] = $ac['basedir']; checkvalue($ac['srcdir']); checking('for output filename'); checkvalue($ac['OUTPUT_FILENAME']); checking('whether to include CHM'); $ac['CHMONLY_INCL_BEGIN'] = $ac['CHMENABLED'] == 'yes' ? '' : '<!--'; $ac['CHMONLY_INCL_END'] = $ac['CHMENABLED'] == 'yes' ? '' : '-->'; checkvalue($ac['CHMENABLED']); checking("for PHP executable"); if ($ac['PHP'] == '' || $ac['PHP'] == 'no') { $ac['PHP'] = find_file($php_bin_names); } else { if (file_exists($cygwin_php_bat)) { $ac['PHP'] = $cygwin_php_bat; } } if ($ac['PHP'] == '') { checkerror("Could not find a PHP executable. Use --with-php=/path/to/php."); } if (!file_exists($ac['PHP']) || !is_executable($ac['PHP'])) { checkerror("PHP executable is invalid - how are you running configure? " . "Use --with-php=/path/to/php."); } $ac['PHP'] = abspath($ac['PHP']); checkvalue($ac['PHP']); checking("for language to build"); if ($ac['LANG'] == '') {
$main_heartbeat_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'main_heartbeat_active' LIMIT 1"), 0, "field_data"); if ($main_heartbeat_active == FALSE && $datbase_error == FALSE) { // Database Initialization initialization_database(); // Check if a custom PHP path is being used $php_location = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'php_location' LIMIT 1"), 0, "field_data"); if (empty($php_location) == FALSE) { // Check to make sure the binary/exe file exist before starting if (getenv("OS") == "Windows_NT") { if (file_exists($php_location . "php-win.exe") == FALSE) { // Can't start Timekoin, php-win.exe is missing or the path is wrong. // Try to find the file before starting. $find_php = find_file('C:/wamp', 'php-win.exe'); if (empty($find_php[0]) == TRUE) { // Not in wamp, search the whole drive $find_php = find_file('C:', 'php-win.exe'); } // Filter strings $symbols = array("/"); $find_php[0] = str_replace($symbols, "\\", $find_php[0]); // Filter for path setting $symbols = array("php-win.exe"); $find_php[0] = str_replace($symbols, "", $find_php[0]); if (empty($find_php[0]) == TRUE) { // Could not find it anywhere :( header("Location: index.php?menu=system&code=98"); exit; } else { // Found it! Save location and start Timekoin mysql_query("UPDATE `options` SET `field_data` = '" . addslashes($find_php[0]) . "' WHERE `options`.`field_name` = 'php_location' LIMIT 1"); }
/** * Try to find the file in folder recursively * * @author Jack * @date Sat Feb 21 10:37:11 2015 * @param folder * The folder to find the file * @param file * The filename * @param suffix (default null) * The file extension (only match the same extension) * @param blur (default false) * If using blur, will just locate the filename in the filename, not matching it * @return All the matching files */ function find_file($folder, $file, $suffix = null, $blur = false) { $ret = array(); if (is_array($folder)) { foreach ($folder as $f) { $ret = array_merge($ret, find_file($f, $file, $suffix, $blur)); } return $ret; } $iterator = new \DirectoryIterator($folder); foreach ($iterator as $fileinfo) { if ($fileinfo->isDot()) { continue; } if ($fileinfo->isFile()) { $name = $fileinfo->getPathname(); $info = pathinfo($name); if ($info && ($suffix == null || $suffix && $info['extension'] == $suffix)) { if ($info['filename'] == $file) { $ret[] = $name; } else { if ($blur && strpos($info['filename'], $file) !== false) { $ret[] = $name; } } } } else { if ($fileinfo->isDir()) { $ret = array_merge($ret, find_file($fileinfo->getPathname(), $file, $suffix, $blur)); } } } return $ret; }
function get_image_size($src) { $CI =& get_instance(); $CI->load->helper('image'); $file = find_file($src, 'static/img/'); // Try to find the image in static/img if ($file == null) { // We can't read the file $file = find_file($src, 'static/uploads/'); if ($file == null) { trigger_error('The responsive image can\'t be found'); return ''; } } if (extension_loaded('imagick')) { $img = new Imagick($file); return $img->getImageGeometry(); } if (extension_loaded('gd')) { $path_parts = pathinfo($file); $ext = $path_parts['extension']; if ($ext == 'jpg' || $ext == 'jpeg') { $src_img = imagecreatefromjpeg($file); } else { $src_img = imagecreatefrompng($file); } return array('width' => imageSX($src_img), 'height' => imageSY($src_img)); } return array(0, 0); }
// This could take a while // Search the entire hard drive looking for the php program if (getenv("OS") == "Windows_NT") { $find_php = find_file('C:', 'php-win.exe'); if (empty($find_php[0]) == TRUE) { // Try D: if not found on C: $find_php = find_file('D:', 'php-win.exe'); } // Filter strings $symbols = array("/"); $find_php[0] = str_replace($symbols, "\\", $find_php[0]); // Filter for path setting $symbols = array("php-win.exe"); $find_php[0] = str_replace($symbols, "", $find_php[0]); } else { $find_php = find_file('/usr', 'php'); } if (empty($find_php[0]) == TRUE) { // PHP File not found $body_text = options_screen2(); $body_text .= '<font color="red"><strong>Could NOT locate PHP program file!</strong></font>'; } else { // Save the found php path $sql = "UPDATE `options` SET `field_data` = '" . addslashes($find_php[0]) . "' WHERE `options`.`field_name` = 'php_location' LIMIT 1"; if (mysql_query($sql) == TRUE) { $body_text = options_screen2(); $body_text .= '<font color="blue"><strong>PHP File Location Found & Saved!</strong></font>'; } } } if ($_GET["newkeys"] == "confirm") {
function find_all($file, $in) { $files = find_file($file, $in); $filetypes = find_filetype($file, $in); $all_files = array_merge($files, $filetypes); return array_unique($all_files); }
function find_file($dir = '.', $pat = '') { $files = array(); $dh = opendir($dir); $reg = preg_replace(array('/\\./', '/\\*/'), array('\\.', '.*'), $pat); while ($file = readdir($dh)) { if ($file == '.' || $file == '..') { continue; } if (preg_match('/~$/', $file)) { continue; } $path = preg_replace('/\\.\\//', '', "{$dir}/{$file}"); if (is_dir($path)) { if ($file == "CVS") { continue; } if (!$pat) { $files[] = $path; } $files = array_merge($files, find_file($path, $pat)); } else { if ($pat && !preg_match("/^{$reg}\$/", $file)) { continue; } $files[] = $path; } } closedir($dh); return $files; }
function create_image_thumbnail($orig, $width, $height = 0) { $output_dir = 'application/cache/img/' . $width . 'x' . $height . '/'; // All the thumbnails is located in cache $out_file = find_file($orig, $output_dir); // Try to find the file from output dir if ($out_file != null) { // If the cached file is exists, return it return file_get_contents($out_file); } $file = find_file($orig, 'static/uploads/'); // Try to find the image in static/img if ($file == null) { // We can't read the in uploads $file = find_file($orig, 'static/img/'); // Try to find the image in static/img if ($file == null) { // We can't read the file { return null; } } if ($width == 'normal') { return file_get_contents($file); } if (!file_exists($output_dir)) { // If the output dir is not exists, then create it mkdir($output_dir, 0777, true); } $path_parts = pathinfo($file); $name = $path_parts['filename']; $ext = $path_parts['extension']; $out_file = FCPATH . $output_dir . $name . '.' . $ext; if (extension_loaded('imagick')) { $img = new Imagick($file); $img->thumbnailImage($width, $height); $img->writeImage($out_file); return file_get_contents($out_file); } if (extension_loaded('gd')) { ci_log('Thumbnailing file %s using GD', $file); if ($ext == 'jpg' || $ext == 'jpeg') { $src_img = imagecreatefromjpeg($file); } else { $src_img = imagecreatefrompng($file); } $old_x = imageSX($src_img); $old_y = imageSY($src_img); if ($height == 0) { $height = $old_y * $width / $old_x; } $dst_img = ImageCreateTrueColor($width, $height); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width, $height, $old_x, $old_y); if ($ext == 'jpg' || $ext == 'jpeg') { imagejpeg($dst_img, $out_file); } else { imagepng($dst_img, $out_file); } imagedestroy($dst_img); imagedestroy($src_img); } return null; }
function inner_create_image_thumbnail($orig, $width, $height = 0) { $output_dir = 'application/cache/img/' . $width . 'x' . $height . '/'; // All the thumbnails is located in cache $out_file = find_file($orig, $output_dir); // Try to find the file from output dir if ($out_file != null) { // If the cached file is exists, return it return $out_file; } $file = find_img($orig); if ($file == null) { // We can't read the file { return null; } if ($width == 'normal') { return $file; } if (!file_exists($output_dir)) { // If the output dir is not exists, then create it mkdir($output_dir, 0777, true); } $path_parts = pathinfo($file); $name = $path_parts['filename']; $ext = $path_parts['extension']; $out_file = FCPATH . $output_dir . $orig; $dir = dirname($out_file); if (!file_exists($dir)) { mkdir($dir, 0755, true); } if (extension_loaded('imagick')) { Imagick::setResourceLimit(6, 1); // Set the thread limit to image magick $img = new Imagick($file); $img->thumbnailImage($width, $height); $img->writeImage($out_file); return $out_file; } if (extension_loaded('gd')) { if ($ext == 'jpg' || $ext == 'jpeg') { $src_img = imagecreatefromjpeg($file); } else { $src_img = imagecreatefrompng($file); } $old_x = imageSX($src_img); $old_y = imageSY($src_img); if ($height == 0) { $height = $old_y * $width / $old_x; } $dst_img = ImageCreateTrueColor($width, $height); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width, $height, $old_x, $old_y); if ($ext == 'jpg' || $ext == 'jpeg') { imagejpeg($dst_img, $out_file); } else { imagepng($dst_img, $out_file); } imagedestroy($dst_img); imagedestroy($src_img); return $out_file; } return null; }
function find_file($dir, $pattern) { // Get a list of all matching files in the current directory $files = glob("{$dir}/{$pattern}"); // Find a list of all directories in the current directory foreach (glob("{$dir}/{*}", GLOB_BRACE | GLOB_ONLYDIR) as $sub_dir) { $arr = find_file($sub_dir, $pattern); // Resursive call $files = array_merge($files, $arr); // Merge array with files from subdirectory } return $files; }
} $inc = getIncludePaths(); foreach ($inc as $pref) { if ($pref == "./") { continue; } if (is_file($pref . 'sms3.6/project' . $name)) { return $pref . 'sms3.6/project' . $name; } } return false; } //---------------------------------------------------------------------------- $uri = $_SERVER['REQUEST_URI']; $uri = explode('?', $uri); $file = find_file($uri[0], $dr); if (is_file($file)) { $update_time = filemtime($file); $headers = getallheaders(); //header для типа файла $basename = basename($file); $ext = substr($basename, strrpos($basename, ".") + 1); switch ($ext) { case 'css': header('Content-Type: text/css;'); break; case 'js': header('Content-Type: application/x-javascript;'); break; default: header('Content-Type: text/html;');
function find_file($dirs, $filename, $exact = false) { $dir = @scandir($dirs); if (is_array($dir) and !empty($dir)) { foreach ($dir as $file) { if ($file !== '.' and $file !== '..') { if (is_file($dirs . '/' . $file)) { $filepath = realpath($dirs . '/' . $file); if (!$exact) { $pos = strpos($file, $filename); if ($pos === false) { } else { if (file_exists($filepath) and is_file($filepath)) { echo str_replace($filename, '<span style="color:red;font-weight:bold">' . $filename . '</span>', $filepath) . ' (' . round(filesize($filepath) / 1024) . 'kb)<br />'; } } } elseif ($file == $filename) { if (file_exists($filepath) and is_file($filepath)) { echo str_replace($filename, '<span style="color:red;font-weight:bold">' . $filename . '</span>', $filepath) . ' (' . round(filesize($filepath) / 1024) . 'kb)<br />'; } } } else { find_file($dirs . '/' . $file, $filename, $exact); } } } } }