Ejemplo n.º 1
0
 public function testListIndexes()
 {
     $this->index2 = $this->client->initIndex(safe_name('ListTest2'));
     $task = $this->index2->addObject(array("firstname" => "Robin"));
     $this->index2->waitTask($task['taskID']);
     $resAfter = $this->client->listIndexes();
     $this->assertTrue($this->containsValue($resAfter["items"], "name", safe_name('ListTest2')));
 }
Ejemplo n.º 2
0
 public function tearDown()
 {
     try {
         $this->client->deleteIndex(safe_name('àlgol?à-php'));
     } catch (AlgoliaSearch\AlgoliaException $e) {
         // not fatal
     }
 }
Ejemplo n.º 3
0
 public function testConstructHost()
 {
     $this->setExpectedException('Exception');
     $host = array("toto");
     $this->badClient = new \AlgoliaSearch\Client(getenv('ALGOLIA_APPLICATION_ID'), getenv('ALGOLIA_API_KEY'), $host);
     $this->badIndex = $this->badClient->initIndex(safe_name('àlgol?à-php'));
     $res = $this->badIndex->addObject(array("firstname" => "Robin"));
     $this->badIndex->waitTask($res['taskID']);
 }
Ejemplo n.º 4
0
 public function testDeleteIndex()
 {
     $this->index2 = $this->client->initIndex(safe_name('ListTest2'));
     $task = $this->index2->addObject(array("firstname" => "Robin"));
     $this->index2->waitTask($task['taskID']);
     $res = $this->client->listIndexes();
     $this->assertTrue($this->includeValue($res['items'], 'name', safe_name('ListTest2')));
     $task = $this->client->deleteIndex(safe_name('ListTest2'));
     $this->index2->waitTask($task['taskID']);
     $resAfter = $this->client->listIndexes();
     $this->assertFalse($this->includeValue($resAfter['items'], 'name', safe_name('ListTest2')));
 }
Ejemplo n.º 5
0
 public function testCopyIndex()
 {
     $this->index2 = $this->client->initIndex(safe_name('àlgol?à2-php'));
     $task = $this->index2->addObject(array("firstname" => "Robin"));
     $this->index2->waitTask($task['taskID']);
     $this->expectOutputString('');
     $task = $this->client->copyIndex(safe_name('àlgol?à2-php'), safe_name('àlgol?à-php'));
     //$this->client->waitTask($task['taskID']);
     $this->index = $this->client->initIndex(safe_name('àlgol?à-php'));
     $this->index2 = $this->client->initIndex(safe_name('àlgol?à2-php'));
     $res = $this->index->search('');
     $this->assertEquals(1, $res['nbHits']);
     $del = $this->index->deleteObject($res['hits'][0]['objectID']);
     $this->index->waitTask($del['taskID']);
     $res = $this->index2->search('');
     $this->assertEquals(1, $res['nbHits']);
     $this->assertEquals("Robin", $res['hits'][0]['firstname']);
 }
Ejemplo n.º 6
0
function safe_file_name($file_name, $force_extension = null)
{
    if (strpos($file_name, '.') === false) {
        $file_name .= '.';
    }
    if (($slash_pos = strrpos($file_name, '/')) !== false) {
        $file_name = substr($file_name, $slash_pos + 1);
    }
    if ($force_extension === null) {
        $force_extension = '.' . safe_name(substr($file_name, strrpos($file_name, '.') + 1));
    } else {
        if ($force_extension != '') {
            $force_extension = '.' . $force_extension;
        }
    }
    $f = substr($file_name, 0, strrpos($file_name, '.'));
    $out = rtrim(safe_name($f) . $force_extension, '.');
    return $out ? $out : Null;
}
Ejemplo n.º 7
0
 public function save($array = array())
 {
     $this->load->library('File_Upload', 'file_upload');
     // Get ID
     $book_id = @$array['book_id'];
     if (empty($book_id)) {
         throw new Exception('Invalid book ID');
     }
     unset($array['book_id']);
     unset($array['section']);
     unset($array['id']);
     // Remove background
     if (isset($array['remove_background']) && !empty($array['remove_background'])) {
         $array['background'] = '';
     }
     unset($array['remove_background']);
     // Remove thumbnail
     if (isset($array['remove_thumbnail']) && !empty($array['remove_thumbnail'])) {
         $array['thumbnail'] = '';
     }
     unset($array['remove_thumbnail']);
     // Remove publisher thumbnail
     if (isset($array['remove_publisher_thumbnail']) && !empty($array['remove_publisher_thumbnail'])) {
         $array['publisher_thumbnail'] = '';
     }
     unset($array['remove_publisher_thumbnail']);
     // Manage slug
     if (isset($array['slug'])) {
         // Get previous slug
         $this->db->select('slug');
         $this->db->from($this->books_table);
         $this->db->where('book_id', $book_id);
         $query = $this->db->get();
         $result = $query->result();
         if (!isset($result[0])) {
             throw new Exception('Could not find book');
         }
         $slug = $result[0]->slug;
         // Scrub slug
         if (!function_exists('safe_name')) {
             $ci = get_instance();
             $ci->load->helper('url');
         }
         $array['slug'] = safe_name($array['slug'], false);
         // Don't allow forward slashes
         // If slug has changed, rename folder on filesystem and update text content URLs
         if ($array['slug'] != $slug) {
             $dbprefix = $this->db->dbprefix;
             // Since we're using a custom MySQL query below
             if (empty($dbprefix)) {
                 die('Could not resolve DB prefix. Nothing has been saved. Please try again');
             }
             // Check if folder already exists, if so, add a "-N"
             $orig_slug = $array['slug'];
             $count = 1;
             while (file_exists($array['slug'])) {
                 $array['slug'] = create_suffix($orig_slug, $count);
                 $count++;
             }
             // Rename folder on the filesystem
             if (false === @rename(confirm_slash(FCPATH) . $slug, confirm_slash(FCPATH) . $array['slug'])) {
                 throw new Exception('Could not rename directory or the source directory doesn\'t exist.');
             }
             // Update hard URLs in version contet
             $old = confirm_slash(base_url()) . confirm_slash($slug);
             $new = confirm_slash(base_url()) . confirm_slash($array['slug']);
             $query = $this->db->query("UPDATE " . $dbprefix . $this->versions_table . " SET content = replace(content, '{$old}', '{$new}')");
         }
     }
     // File -- save thumbnail
     if (isset($_FILES['upload_thumb']) && $_FILES['upload_thumb']['size'] > 0) {
         try {
             $chmod_mode = $this->config->item('chmod_mode');
             if (empty($chmod_mode)) {
                 $chmod_mode = 0777;
             }
             $book = $this->get($book_id);
             $slug = $book->slug;
             $array['thumbnail'] = $this->file_upload->uploadThumb($slug, $chmod_mode);
         } catch (Exception $e) {
             throw new Exception($e->getMessage());
         }
     }
     // File -- save publisher thumbnail
     if (isset($_FILES['upload_publisher_thumb']) && $_FILES['upload_publisher_thumb']['size'] > 0) {
         try {
             $chmod_mode = $this->config->item('chmod_mode');
             if (empty($chmod_mode)) {
                 $chmod_mode = 0777;
             }
             $book = $this->get($book_id);
             $slug = $book->slug;
             $array['publisher_thumbnail'] = $this->file_upload->uploadPublisherThumb($slug, $chmod_mode);
         } catch (Exception $e) {
             throw new Exception($e->getMessage());
         }
     }
     // Remove book versions (ie, main menu), which is handled by save_versions()
     foreach ($array as $field => $value) {
         if (substr($field, 0, 13) != 'book_version_') {
             continue;
         }
         unset($array[$field]);
     }
     // Save row
     $this->db->where('book_id', $book_id);
     $this->db->update($this->books_table, $array);
     return $array;
 }
Ejemplo n.º 8
0
 public function create($array = array())
 {
     if ('array' != gettype($array)) {
         $array = (array) $array;
     }
     if (!isset($array['book_id']) || empty($array['book_id'])) {
         die('Could not find book ID');
     }
     if (!isset($array['user_id']) || empty($array['user_id'])) {
         $array['user_id'] = 0;
     }
     // Talk to Craig and John about this
     if (!function_exists('safe_name')) {
         $ci = get_instance();
         $ci->load->helper('url');
     }
     if (!isset($array['slug']) || empty($array['slug'])) {
         if (!isset($array['title']) && !isset($array['identifier'])) {
             die('Could not find slug, title, or identifier.');
         }
         if (isset($array['identifier']) && !empty($array['identifier'])) {
             $title_for_slug = trim($array['identifier']);
         } elseif (isset($array['title'])) {
             $title_for_slug = trim($array['title']);
         }
         $slug = safe_name($title_for_slug, false);
     } else {
         $slug = safe_name($array['slug']);
     }
     $slug = $this->safe_slug($slug, $array['book_id']);
     $data = array();
     $data['book_id'] = (int) $array['book_id'];
     $data['slug'] = (string) $slug;
     $data['type'] = isset($array['type']) ? $array['type'] : 'composite';
     $data['is_live'] = isset($array['is_live']) ? $array['is_live'] : 1;
     $data['color'] = isset($array['color']) && $array['color'] != '#ffffff' ? $array['color'] : '';
     $data['user'] = (int) $array['user_id'];
     $data['created'] = date('c');
     if (isset($array['category']) && !empty($array['category'])) {
         $data['category'] = $array['category'];
     }
     if (isset($array['thumbnail'])) {
         $data['thumbnail'] = is_array($array['thumbnail']) ? $array['thumbnail'][0] : $array['thumbnail'];
     }
     if (isset($array['background'])) {
         $data['background'] = is_array($array['background']) ? $array['background'][0] : $array['background'];
     }
     if (isset($array['banner'])) {
         $data['banner'] = is_array($array['banner']) ? $array['banner'][0] : $array['banner'];
     }
     if (isset($array['custom_style'])) {
         $data['custom_style'] = is_array($array['custom_style']) ? $array['custom_style'][0] : $array['custom_style'];
     }
     if (isset($array['custom_scripts'])) {
         $data['custom_scripts'] = is_array($array['custom_scripts']) ? $array['custom_scripts'][0] : $array['custom_scripts'];
     }
     if (isset($array['audio'])) {
         $data['audio'] = is_array($array['audio']) ? $array['audio'][0] : $array['audio'];
     }
     $this->db->insert($this->pages_table, $data);
     $id = $this->db->insert_id();
     return $id;
 }
Ejemplo n.º 9
0
<?php

/* $Id$ */
function safe_name($name)
{
    $sname = '';
    $name = preg_replace('/((\\.\\.)?\\/|\\/+)/', '_', $name);
    for ($i = 0; $i < strlen($name); $i++) {
        $c = $name[$i];
        if (preg_match('/[\\s\\r\\n]/', $c)) {
            $c = '_';
        } else {
            if (!preg_match('/[a-zA-Z0-9\\,\\.\\_\\+\\=\\(\\)\\[\\]\\-\\{\\}\\*\\&\\^\\%\\!\\"\']/', $c)) {
                $c = sprintf('x%02X', ord($c));
            }
        }
        $sname .= $c;
    }
    return $sname;
}
$file_name = @$_GET['name'];
$name = 'uploads/' . safe_name($file_name);
$file_content = @file_get_contents('php://input');
@file_put_contents($name, $file_content);
echo "<a href=\"./backend/{$name}\" target=\"_blank\">{$file_name}</a><br/>";
Ejemplo n.º 10
0
 public function testMultipleQueries()
 {
     $res = $this->index->addObject(array("firstname" => "Robin"));
     $this->index->waitTask($res['taskID']);
     $results = $this->client->multipleQueries(array(array('indexName' => safe_name('àlgol?à-php'), 'query' => '')));
     $this->assertEquals(1, $results['results'][0]['nbHits']);
     $this->assertEquals('Robin', $results['results'][0]['hits'][0]['firstname']);
 }
Ejemplo n.º 11
0
 function __link_to($to = 'a=')
 {
     ///// V1.1.1 created for wp
     //// ////////////
     ///////
     global $optimizer;
     $opt = "";
     $get = $_GET;
     $link = "";
     $to1 = explode("&", $to);
     $i = 0;
     $fu = false;
     foreach ($to1 as $val) {
         //echo($k);
         $to2 = explode("=", $val);
         /////if action encode to base64
         if (empty($to2[0])) {
             continue;
         }
         if ($to2[0] == 'act') {
             $to2[1] = base64_encode($to2[1]);
         }
         if ($to2[0] == 'fl') {
             $to2[1] = base64_encode($to2[1]);
         }
         if ($to2[0] == 'p') {
             $to2[1] = base64_encode($to2[1]);
         }
         if ($to2[0] == 'permalink') {
             $fu = $to2[1];
             continue;
         }
         if (!isset($to2[1])) {
             continue;
         }
         $get[$to2[0]] = $to2[1];
     }
     //print_r($get);
     foreach ($get as $key => $val) {
         if (empty($val)) {
             continue;
         }
         $sep = ++$i == 1 ? "" : "&";
         $link = $link . $sep . $key . "=" . $val;
     }
     $fu = explode('.', $fu);
     $fuu = '';
     foreach ($fu as $k => $v) {
         $fuu .= safe_name($v) . "/";
     }
     return "?{$link}";
 }
Ejemplo n.º 12
0
function get_partition_info($device, $reload = FALSE)
{
    global $_ENV, $paths;
    $disk = array();
    $attrs = isset($_ENV['DEVTYPE']) ? get_udev_info($device, $_ENV, $reload) : get_udev_info($device, NULL, $reload);
    // $GLOBALS["echo"]($attrs);
    $device = realpath($device);
    if ($attrs['DEVTYPE'] == "partition") {
        $disk['serial_short'] = isset($attrs["ID_SCSI_SERIAL"]) ? $attrs["ID_SCSI_SERIAL"] : $attrs['ID_SERIAL_SHORT'];
        $disk['serial'] = "{$attrs[ID_MODEL]}_{$disk[serial_short]}";
        $disk['device'] = $device;
        // Grab partition number
        preg_match_all("#(.*?)(\\d+\$)#", $device, $matches);
        $disk['part'] = $matches[2][0];
        $disk['disk'] = $matches[1][0];
        if (isset($attrs['ID_FS_LABEL'])) {
            $disk['label'] = safe_name($attrs['ID_FS_LABEL_ENC']);
        } else {
            if (isset($attrs['ID_VENDOR']) && isset($attrs['ID_MODEL'])) {
                $disk['label'] = sprintf("%s %s", safe_name($attrs['ID_VENDOR']), safe_name($attrs['ID_MODEL']));
            } else {
                $disk['label'] = safe_name($attrs['ID_SERIAL']);
            }
            $all_disks = array_unique(array_map(function ($ar) {
                return realpath($ar);
            }, listDir("/dev/disk/by-id")));
            $disk['label'] = count(preg_grep("%" . $matches[1][0] . "%i", $all_disks)) > 2 ? $disk['label'] . "-part" . $matches[2][0] : $disk['label'];
        }
        $disk['fstype'] = safe_name($attrs['ID_FS_TYPE']);
        $disk['fstype'] = !$disk['fstype'] && verify_precleared($disk['disk']) ? "precleared" : $disk['fstype'];
        $disk['target'] = str_replace("\\040", " ", trim(shell_exec("/bin/cat /proc/mounts 2>&1|/bin/grep {$device}|/bin/awk '{print \$2}'")));
        $disk['size'] = intval(trim(shell_exec("/sbin/blockdev --getsize64 {$device} 2>/dev/null")));
        $disk['used'] = intval(trim(shell_exec("/bin/df --output=used,source 2>/dev/null|/bin/grep -v 'Filesystem'|/bin/grep {$device}|/bin/awk '{print \$1}'"))) * 1024;
        $disk['avail'] = $disk['size'] - $disk['used'];
        if ($disk['mountpoint'] = get_config($disk['serial'], "mountpoint.{$disk[part]}")) {
            if (!$disk['mountpoint']) {
                goto empty_mountpoint;
            }
        } else {
            empty_mountpoint:
            $disk['mountpoint'] = $disk['target'] ? $disk['target'] : preg_replace("%\\s+%", "_", sprintf("%s/%s", $paths['usb_mountpoint'], $disk['label']));
        }
        $disk['owner'] = isset($_ENV['DEVTYPE']) ? "udev" : "user";
        $disk['automount'] = is_automount($disk['serial'], strpos($attrs['DEVPATH'], "usb"));
        $disk['shared'] = config_shared($disk['serial'], $disk['part'], strpos($attrs['DEVPATH'], "usb"));
        $disk['command'] = get_config($disk['serial'], "command.{$disk[part]}");
        $disk['command_bg'] = get_config($disk['serial'], "command_bg.{$disk[part]}");
        $disk['prog_name'] = basename($disk['command'], ".sh");
        $disk['logfile'] = $paths['device_log'] . $disk['prog_name'] . ".log";
        return $disk;
    }
}
Ejemplo n.º 13
0
function get_partition_info($device){
  global $_ENV, $paths;
  $disk = array();
  $attrs = (isset($_ENV['DEVTYPE'])) ? get_udev_info($device, $_ENV) : get_udev_info($device);
  $device = realpath($device);
  if ($attrs['DEVTYPE'] == "partition") {
    $disk['serial']       = $attrs['ID_SERIAL'];
    $disk['serial_short'] = $attrs['ID_SERIAL_SHORT'];
    $disk['device']       = $device;
    // Grab partition number
    preg_match_all("#(.*?)(\d+$)#", $device, $matches);
    $disk['part']   =  $matches[2][0];
    if (isset($attrs['ID_FS_LABEL'])){
      $disk['label'] = safe_name($attrs['ID_FS_LABEL_ENC']);
    } else {
      if (isset($attrs['ID_VENDOR']) && isset($attrs['ID_MODEL'])){
        $disk['label'] = sprintf("%s %s", safe_name($attrs['ID_VENDOR']), safe_name($attrs['ID_MODEL']));
      } else {
        $disk['label'] = safe_name($attrs['ID_SERIAL']);
      }
      $all_disks = array_unique(array_map(function($ar){return realpath($ar);},listDir("/dev/disk/by-id")));
      $disk['label']  = (count(preg_grep("%".$matches[1][0]."%i", $all_disks)) > 2) ? $disk['label']."-part".$matches[2][0] : $disk['label'];
    }
    $disk['fstype'] = safe_name($attrs['ID_FS_TYPE']);
    $disk['target'] = str_replace("\\040", " ", trim(shell_exec("cat /proc/mounts 2>&1|grep ${device}|awk '{print $2}'")));
    $disk['size']   = intval(trim(shell_exec("blockdev --getsize64 ${device} 2>/dev/null")));
    $disk['used']   = intval(trim(shell_exec("df --output=used,source 2>/dev/null|grep -v 'Filesystem'|grep ${device}|awk '{print $1}'")))*1024;
    $disk['avail']  = $disk['size'] - $disk['used'];
    if ( $disk['mountpoint'] = get_config($disk['serial'], "mountpoint.{$disk[part]}") ) {
      if (! $disk['mountpoint'] ) goto empty_mountpoint;
    } else {
      empty_mountpoint:
      $disk['mountpoint'] = $disk['target'] ? $disk['target'] : preg_replace("%\s+%", "_", sprintf("%s/%s", $paths['usb_mountpoint'], $disk['label']));
    }
    $disk['owner'] = (isset($_ENV['DEVTYPE'])) ? "udev" : "user";
    $disk['automount'] = is_automount_2($disk['serial'],strpos($attrs['DEVPATH'],"usb"));
    return $disk;
  }
}
Ejemplo n.º 14
0
 public function prov_wasAttributedTo($value, $base_uri, $attribution = null)
 {
     if (isset($value->uri) && !empty($value->uri)) {
         $value = $value->uri;
     } elseif (!empty($attribution) && isset($attribution->fullname) && !empty($attribution->fullname)) {
         $value = safe_name($attribution->fullname);
     } elseif (!is_numeric($value) && isset($value->user_id)) {
         $value = $value->user_id;
     }
     if (isURL($value)) {
         return $value;
     }
     return confirm_slash($base_uri) . 'users/' . $value;
 }
Ejemplo n.º 15
0
}
$data = filter_raw_data($raw_data);
// hosts definition - we are only interested in hostname, parents and notes with position information
foreach ($data as $host) {
    if ((!empty($host["host_name"]) && !preg_match("/^\\!/", $host['host_name'])) | $host['register'] == 0) {
        $hostname = 'x' . safe_name($host["host_name"]) . 'x';
        $hosts[$hostname]['host_name'] = $hostname;
        $hosts[$hostname]['nagios_host_name'] = $host["host_name"];
        $hosts[$hostname]['alias'] = "<i>(" . $host["alias"] . ")</i>";
        // iterate for every option for the host
        foreach ($host as $option => $value) {
            // get parents information
            if ($option == "parents") {
                $parents = explode(',', $value);
                foreach ($parents as $parent) {
                    $parent = safe_name($parent);
                    $hosts[$hostname]['parents'][] = "x" . $parent . "x";
                }
                continue;
            }
            // we are only interested in latlng values from notes
            if ($option == "notes") {
                if (preg_match("/latlng/", $value)) {
                    $value = explode(":", $value);
                    $hosts[$hostname]['latlng'] = trim($value[1]);
                    continue;
                } else {
                    continue;
                }
            }
            // another few information we are interested in