Ejemplo n.º 1
0
 public function run($function, array $params = array())
 {
     $hooks = Utils::get('ThinHooks');
     $res = null;
     if (Arrays::exists($function, $hooks)) {
         if (Arrays::exists('before', $hooks[$function])) {
             $action = $hooks[$function]['before'];
             if (is_callable($action, true, $before)) {
                 $res = $before();
             }
         }
         if (null === $res) {
             $res = '';
         }
         $res .= call_user_func_array($function, $params);
         if (Arrays::exists('after', $hooks[$function])) {
             $action = $hooks[$function]['after'];
             if (is_callable($action, true, $after)) {
                 $res .= $after();
             }
         }
         return $res;
     } else {
         return call_user_func_array($function, $params);
     }
 }
Ejemplo n.º 2
0
 public function query($sql)
 {
     $resource = mssql_query($sql, $this->link);
     if ($resource) {
         if (is_resource($resource)) {
             $i = 0;
             $data = array();
             while ($result = mssql_fetch_assoc($resource)) {
                 $data[$i] = $result;
                 $i++;
             }
             mssql_free_result($resource);
             $query = new Object();
             $row = isset(Arrays::first($data)) ? Arrays::first($data) : array();
             $query->setRow($row)->setRows($data)->setNumRows($i);
             unset($data);
             return $query;
         } else {
             return true;
         }
     } else {
         trigger_error('Error: ' . mssql_get_last_message($this->link) . '<br />' . $sql);
         exit;
     }
 }
Ejemplo n.º 3
0
function splitArrayCategory($stat, $sep, $page)
{
    $array = Arrays::getArray($stat);
    $phrase = Phrases::getPhrase($stat);
    $inserts = null;
    for ($i = 0; $i < count($array); $i++) {
        if ($i > 0) {
            $inserts .= $sep;
        }
        if ($stat == "achievement") {
            $img = "<img src='images/achievements/" . $array[$i] . ".png' class='img'> ";
        } else {
            if ($stat == "stat.killEntity" || $stat == "stat.entityKilledBy") {
                $img = "<img src='images/mobs/" . $array[$i] . ".png' class='img'> ";
            } else {
                if ($stat != "stat") {
                    $img = "<img src='images/items/" . $array[$i] . ".png' class='img'> ";
                }
            }
        }
        $link = "top.php?do={$stat}&page={$page}&sort=" . $array[$i];
        $asc = " <a href='{$link}&order=ASC'><img src='images/up.png' class='sort'></a>";
        $desc = " <a href='{$link}&order=DESC'><img src='images/down.png' class='sort'></a>";
        $inserts .= $img . $phrase[$i] . $asc . $desc;
    }
    return $inserts;
}
Ejemplo n.º 4
0
 protected function _element($data = '', $tab = '', $start = 0)
 {
     static $start;
     $eof = eol();
     $output = '';
     $attrs = '';
     $tab = str_repeat("\t", $start);
     if (!is_array($data)) {
         return $data . $eof;
     } else {
         foreach ($data as $k => $v) {
             if (is_numeric($k)) {
                 $k = 'li';
             }
             $end = "/" . Arrays::getFirst(explode(' ', $k));
             if (!is_array($v)) {
                 $output .= "{$tab}<{$k}>{$v}<{$end}>{$eof}";
             } else {
                 $output .= $tab . "<{$k}>{$eof}" . $this->_element($v, $tab, $start++) . $tab . "<{$end}>" . $tab . $eof;
                 $start--;
             }
         }
     }
     return $output;
 }
Ejemplo n.º 5
0
 public function orderBy($tab, $fieldOrder, $orderDirection = 'ASC')
 {
     $sortFunc = function ($key, $direction) {
         return function ($a, $b) use($key, $direction) {
             if ('ASC' == $direction) {
                 return $a[$key] > $b[$key];
             } else {
                 return $a[$key] < $b[$key];
             }
         };
     };
     if (Arrays::is($fieldOrder) && !Arrays::is($orderDirection)) {
         $t = array();
         foreach ($fieldOrder as $tmpField) {
             array_push($t, $orderDirection);
         }
         $orderDirection = $t;
     }
     if (!Arrays::is($fieldOrder) && Arrays::is($orderDirection)) {
         $orderDirection = Arrays::first($orderDirection);
     }
     if (Arrays::is($fieldOrder) && Arrays::is($orderDirection)) {
         for ($i = 0; $i < count($fieldOrder); $i++) {
             usort($tab, $sortFunc($fieldOrder[$i], $orderDirection[$i]));
         }
     } else {
         usort($tab, $sortFunc($fieldOrder, $orderDirection));
     }
     return $tab;
 }
Ejemplo n.º 6
0
 public function calculation_sheet_custom($keys)
 {
     include_once APPPATH . "models/helperClasses/Calculation_Sheet.php";
     $this->db->select("*");
     $this->db->where(array('entryDate >=' => $keys['from_date'], 'entryDate <=' => $keys['to_date']));
     if ($keys['company_id'] != 'all') {
         $this->db->where('company_id', $keys['company_id']);
     }
     if ($keys['contractor_id'] != 'all') {
         $this->db->where('contractor_id', $keys['contractor_id']);
     }
     if ($keys['product'] != 'all' && $keys['product'] != '') {
         $this->db->where('product', $keys['product']);
     }
     if ($keys['product_type'] != 'all' && $keys['product_type'] != '') {
         if ($_GET['product_type'] == 'black oil') {
             $this->db->where('product_type', 'black oil');
         }
         if ($_GET['product_type'] == 'white oil') {
             $this->db->where('product_type', 'white oil');
         }
     }
     $result = $this->db->get('calculation_sheet_view')->result();
     $calculation_sheet_white_oil = array();
     foreach ($result as $record) {
         array_push($calculation_sheet_white_oil, new Calculation_Sheet($record));
     }
     $grouped = Arrays::groupBy($calculation_sheet_white_oil, Functions::extractField('destination'), 'invoice_number');
     ksort($grouped);
     return $grouped;
 }
Ejemplo n.º 7
0
 public function findByIdSet($idSet)
 {
     $ids = Arrays::toStringSQL($idSet, ",");
     $sql = "SELECT id, login, firstname, lastname, email, online, gender, birthdate, avatar, lastActive\n\t\t\t\tFROM user \n\t\t\t\tWHERE id in ({$ids})";
     $users = $this->execute($sql);
     return $result = count($users) > 0 ? $users : null;
 }
Ejemplo n.º 8
0
 /**
  * Loads HTTP data.
  * @return void
  */
 public function loadHttpData()
 {
     $path = $this->getHtmlName();
     // img_x or img['x']
     $path = explode('[', strtr(str_replace(']', '', strpos($path, '[') === FALSE ? $path . '.x' : substr($path, 0, -2)), '.', '_'));
     $this->setValue(Arrays::get($this->getForm()->getHttpData(), $path, NULL));
 }
Ejemplo n.º 9
0
Archivo: Cli.php Proyecto: schpill/thin
 private function format($text = '', $parameters = array())
 {
     if (!Arrays::is($parameters) && 'NONE' == $parameters) {
         return $text;
     }
     if (!Arrays::is($parameters) && isset($this->styles[$parameters])) {
         $parameters = $this->styles[$parameters];
     }
     $codes = array();
     $fg = isAke($parameters, 'fg', null);
     $bg = isAke($parameters, 'bg', null);
     if (!empty($fg)) {
         $codes[] = $this->foreground[$fg];
     }
     if (!empty($bg)) {
         $codes[] = $this->background[$bg];
     }
     foreach ($this->options as $option => $value) {
         $paramOpt = isAke($parameters, $option, null);
         if (!empty($paramOpt)) {
             $codes[] = $value;
         }
     }
     return "[" . implode(';', $codes) . 'm' . $text . "";
 }
Ejemplo n.º 10
0
Archivo: Db.php Proyecto: schpill/thin
 public static function connexion()
 {
     $args = func_get_args();
     $class = '\\Thin\\Db\\' . ucfirst(Inflector::lower(Arrays::first($args)));
     array_shift($args);
     return call_user_func_array([$class, 'instance'], $args);
 }
Ejemplo n.º 11
0
 /**
  * Returns the file list for a given directory
  *
  * @param string $strDir           - the absolute local path to the directory (e.g. /dir/mydir)
  * @param string $baseUrl          - the relative uri (e.g. /tl_files/mydir)
  * @param string $protectedBaseUrl - domain + request uri -> absUrl will be domain + request uri + ?file=$baseUrl/filename.ext
  *
  * @return array file list containing file objects.
  */
 public static function getFileList($strDir, $baseUrl, $protectedBaseUrl = null)
 {
     $arrResult = array();
     if (is_dir($strDir)) {
         if ($handler = opendir($strDir)) {
             while (($strFile = readdir($handler)) !== false) {
                 if (substr($strFile, 0, 1) == '.') {
                     continue;
                 }
                 $arrFile = array();
                 $arrFile['filename'] = htmlentities($strFile);
                 if ($protectedBaseUrl) {
                     $arrFile['absUrl'] = $protectedBaseUrl . (empty($_GET) ? '?' : '&') . 'file=' . urlencode($arrFile['absUrl']);
                 } else {
                     $arrFile['absUrl'] = str_replace('\\', '/', str_replace('//', '', $baseUrl . '/' . $strFile));
                 }
                 $arrFile['path'] = str_replace($arrFile['filename'], '', $arrFile['absUrl']);
                 $arrFile['filesize'] = self::formatSizeUnits(filesize(str_replace('\\', '/', str_replace('//', '', $strDir . '/' . $strFile))), true);
                 $arrResult[] = $arrFile;
             }
             closedir($handler);
         }
     }
     Arrays::aasort($arrResult, 'filename');
     return $arrResult;
 }
Ejemplo n.º 12
0
 public function __call($method, $args)
 {
     if (true === $this->__has($method)) {
         return $this->__fire($method, $args);
     }
     $reverse = strrev($method);
     $last = $reverse[0];
     if ('s' == $last) {
         if (!count($args)) {
             return isAke($this->values, $method);
         } else {
             $this->values[$method] = !Arrays::is($this->values[$method]) ? array() : $this->values[$method];
             foreach ($args as $arg) {
                 array_push($this->values[$method], $arg);
             }
         }
         return $this;
     } else {
         $method .= 's';
         if (!count($args)) {
             $val = isAke($this->values, $method);
             return count($val) ? Arrays::first($val) : null;
         } else {
             $this->values[$method] = !Arrays::is($this->values[$method]) ? array() : $this->values[$method];
             foreach ($args as $arg) {
                 array_push($this->values[$method], $arg);
             }
         }
         return $this;
     }
 }
Ejemplo n.º 13
0
 public function __call($func, $argv)
 {
     if (substr($func, 0, 3) == 'get') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         if (isset($argv[0])) {
             $environment = $argv[0];
         } else {
             $environment = APPLICATION_ENV;
         }
         return getConfig($key, $environment);
     } elseif (substr($func, 0, 3) == 'set') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         $value = Arrays::first($argv);
         if (isset($argv[1])) {
             $environment = $argv[1];
         } else {
             $environment = 'all';
         }
         setConfig($key, $value, $environment);
         return $this;
     } elseif (substr($func, 0, 3) == 'has') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         if (isset($argv[0])) {
             $environment = $argv[0];
         } else {
             $environment = APPLICATION_ENV;
         }
         return null !== getConfig($key, $environment);
     }
 }
Ejemplo n.º 14
0
	/**
	 * Search a value in a (multidimensional) array - replacement for array_search().
	 *
	 * This function returns the key of the element that contains the specified keyword.
	 * The element can be an array, it will be recursively scanned for the keyword.
	 * The key of the parent element (not the child element) which contains the keyword
	 * will be returned. If there are more than one elements with the specified keyword
	 * the key of the first found element will be returned. If nothing is found boolean
	 * FALSE will be returned.
	 *
	 * Example:
	 * <code>
	 * $mimeTypes = array(
	 *	'image/gif' => array('gif'),
	 *	'image/jpeg' => array('jpe', 'jpeg', 'jpg'),
	 *	'image/png' => array('png', 'x-png'),
	 * );
	 * echo Arrays::find($mimeTypes, 'jpg');
	 * // Output: image/jpeg
	 * </code>
	 *
	 * @param array Array to search in
	 * @param mxied Text to find
	 * @return mixed Key of array or false on failure
	 */
	public static function find(array $array, $keyword) {
		foreach($array as $key => $value) {
			if($keyword === $value || (is_array($value) == true && Arrays::find($array, $value) !== false)) {
				return $key;
			}
		}
		return false;
	}
Ejemplo n.º 15
0
 /**
  * @covers h4kuna\DataType\Basic\Arrays::column
  * @todo   Implement testColumn().
  */
 public function testColumn()
 {
     $array = array(array('name' => 'Joe', 'id' => 1), array('name' => 'Doe', 'id' => 2), array('name' => 'Foo', 'id' => 3), array('name' => 'Bar', 'id' => 4));
     $this->assertSame(array('Joe', 'Doe', 'Foo', 'Bar'), Arrays::column($array, 'name'));
     $this->assertSame(array(1 => 'Joe', 2 => 'Doe', 3 => 'Foo', 4 => 'Bar'), Arrays::column($array, 'name', 'id'));
     $this->assertSame(array(1 => array('name' => 'Joe', 'id' => 1), 2 => array('name' => 'Doe', 'id' => 2), 3 => array('name' => 'Foo', 'id' => 3), 4 => array('name' => 'Bar', 'id' => 4)), Arrays::column($array, NULL, 'id'));
     $this->assertSame($array, Arrays::column($array));
 }
Ejemplo n.º 16
0
 public function code($code = 200)
 {
     $messages = Arrays::multikey($this->config['messages']);
     if (isset($messages[$code])) {
         return $messages[$code];
     }
     return false;
 }
Ejemplo n.º 17
0
 /**
  * Static method for instantiating a singleton object.
  *
  * @return object
  */
 public static final function instance()
 {
     $className = get_called_class();
     if (!Arrays::exists(static::$instances[$className])) {
         static::$instances[$className] = new $className(func_get_args());
     }
     return static::$instances[$className];
 }
Ejemplo n.º 18
0
 public function __call($method, $args)
 {
     if (0 == count($args)) {
         return static::get($method);
     } elseif (1 == count($args)) {
         return static::set($method, Arrays::first($args));
     }
 }
Ejemplo n.º 19
0
 /**
  * @param string $name
  * @return mixed
  */
 public static function get($name, $default = null)
 {
     if (Arrays::exists($name, $_COOKIE)) {
         if (isset($_COOKIE[$name])) {
             return $_COOKIE[$name];
         }
     }
     return $default;
 }
Ejemplo n.º 20
0
 public static function send($arguments = array())
 {
     $response = static::request('messages/send', $arguments);
     if (false !== $response && Arrays::is($response)) {
         $response = Arrays::first($response);
         return $response['status'] == 'sent' ? true : $response['status'];
     }
     return false;
 }
Ejemplo n.º 21
0
 public static function createObject($className, $classParams = null)
 {
     if (is_array($classParams) && !Arrays::isAssoc($classParams)) {
         // Invoke Object with multiple arguments
         return new $className(...$classParams);
     }
     // Invoke Object with single argument
     return new $className($classParams);
 }
Ejemplo n.º 22
0
 public function pre_saved_sorting_columns($module)
 {
     $result = $this->db->get_where('sort', array('view' => $module))->result();
     if (sizeof($result) > 0) {
         $grouped = Arrays::groupBy($result, Functions::extractField('sort_by'), 'priority');
         return $grouped;
     }
     return null;
 }
Ejemplo n.º 23
0
 public function pre_saved_sorting_columns($module)
 {
     $multiple_sorting_info = $this->multiple_sorting_info($module);
     $objects = array();
     foreach ($multiple_sorting_info as $record) {
         array_push($objects, json_decode(json_encode($record), FALSE));
     }
     $grouped = Arrays::groupBy($objects, Functions::extractField('column_name'), 'column_priority');
     return $grouped;
 }
Ejemplo n.º 24
0
 public function set($exp = 'H:i:s')
 {
     if (!is_string($exp)) {
         return Error::set('Error', 'stringParameter', 'exp');
     }
     $chars = $this->config['setDateFormatChars'];
     $chars = Arrays::multikey($chars);
     $newClock = str_ireplace(array_keys($chars), array_values($chars), $exp);
     return date($newClock);
 }
Ejemplo n.º 25
0
 public function del($key)
 {
     $files = $this->search($key . '#');
     if (count($files)) {
         $key = Arrays::first($files);
         unset($this->buffer[$key]);
         $this->commit();
     }
     return $this;
 }
Ejemplo n.º 26
0
 public function __construct(array $array, $callback = null)
 {
     $path = CACHE_PATH . DS . Utils::UUID();
     File::mkdir($path);
     File::put($file, "<?php\nreturn " . var_export($array, 1) . ';');
     $this->assoc = Arrays::isAssoc($array);
     $this->file = $file;
     $this->callback = $callback;
     $this->count = count($array);
 }
Ejemplo n.º 27
0
 public function del($key)
 {
     $pattern = strstr($key, '#') ? $key : $key . '#';
     $rows = $this->search($pattern);
     if (count($rows)) {
         $key = Arrays::first($rows);
         $this->db->srem($this->ns, $key);
     }
     return $this;
 }
Ejemplo n.º 28
0
 public function set($exp = '')
 {
     if (!is_string($exp)) {
         return Error::set('Error', 'stringParameter', 'exp');
     }
     $chars = $this->config['setTimeFormatChars'];
     $chars = Arrays::multikey($chars);
     $setExp = str_ireplace(array_keys($chars), array_values($chars), $exp);
     return strftime($setExp);
 }
Ejemplo n.º 29
0
 /**
  * Nastaví pole názvů souborů ve složce.
  * @param int $orderBy řazení ASC = 0, DESC = 1
  * @param string $contains Vytřídí všechny soubory co v názvu neobsahují tento řetězec
  */
 public function sortOutFilles($orderBy = 0, $contains = NULL)
 {
     $nameFiles = scandir($this->dirPath, $orderBy);
     /* odstraní všechny prvky pole co neobsahují řetězec */
     if ($contains && !empty($nameFiles)) {
         $nameFiles = Arrays::sortOut($nameFiles, $contains);
     }
     $this->nameFillesInFolder = $nameFiles;
     return $nameFiles;
 }
 public static function mixedToString($mixed_)
 {
     if (is_array($mixed_)) {
         return Arrays::toString($mixed_);
     }
     if (is_object($mixed_) && false === method_exists($mixed_, '__toString')) {
         return get_class($mixed_);
     }
     return trim((string) $mixed_);
 }