public static function getIcons() { if (self::$icons === null) { $path = waConfig::get('wa_path_root') . '/wa-content/img/users/'; if (!file_exists($path) || !is_dir($path)) { $list = array(); } if (!($dh = opendir($path))) { $list = array(); } $list = array(); while (false !== ($file = readdir($dh))) { if ($file == '.' || $file == '..') { continue; } if (is_dir($path . '/' . $file)) { continue; } else { $list[] = $file; } } closedir($dh); foreach ($list as &$l) { $p = strpos($l, '.png'); if ($p !== false) { $l = substr($l, 0, $p); } } unset($l); natsort($list); self::$icons = array_values($list); } return self::$icons; }
function king_def() { global $king; $fields = array('notify_type', 'notify_id', 'notify_time', 'trade_no', 'out_trade_no', 'subject', 'body', 'price', 'discount', 'quantity', 'total_fee', 'payment_type', 'use_coupon', 'coupon_discount', 'is_total_fee_adjust', 'trade_status', 'refund_status', 'logistics_status', 'logistics_type', 'logistics_fee', 'logistics_payment', 'receive_name', 'receive_address', 'receive_zip', 'receive_phone', 'receive_mobile', 'seller_email', 'seller_id', 'buyer_id', 'buyer_email', 'gmt_create', 'gmt_payment', 'gmt_send_goods', 'gmt_refund', 'gmt_close', 'gmt_logistics_modify'); natsort($fields); $array = array(); foreach ($fields as $val) { if (isset($_POST[$val])) { //首先这些值需要先存在 $array[] = $val . '=' . $_POST[$val]; } } if (is_array($array)) { //万一不是数组就得输出错误提示 $sign = md5(implode('&', $array) . $king->config('alipaykey', 'portal')); if ($sign != kc_post('sign')) { exit('fail'); } } else { exit('fail'); } /* 这里开始写数据更新过程 */ switch (kc_post('trade_status')) { case 'WAIT_BUYER_PAY': $trade_status = 1; break; case 'WAIT_SELLER_SEND_GOODS': $trade_status = 3; break; case 'WAIT_BUYER_CONFIRM_GOODS': $trade_status = 4; break; case 'TRADE_FINISHED': $trade_status = 5; break; case 'TRADE_CLOSED': $trade_status = 10; break; case 'modify.tradeBase.totalFee': $trade_status = 11; break; } if (isset(kc_post('refund_status'))) { switch (kc_post('refund_status')) { case 'WAIT_SELLER_AGREE': $trade_status = 8; break; case 'REFUND_SUCCESS': $trade_status = 9; break; case 'REFUND_CLOSED': $trade_status = 10; break; } } $array = array('nstatus' => $trade_status, 'tid' => kc_post('trade_no'), 'buyer_id' => kc_post('buyer_email'), 'seller' => kc_post('seller_email'), 'paymethod' => 'alipay'); $ono = kc_get('out_trade_no', 2, 1); $king->db->update('%s_orders', $array, "ono='{$ono}'"); exit('success'); }
public function main() { $db = ConnectionManager::getDataSource('default'); $db->query($this->migrationsTableSql); $results = $db->query("select migrations from __migrations"); $applied = array(); foreach ($results as $result) { $applied[] = $result['__migrations']['migrations']; } $migrations = glob(APP . 'Config' . DS . 'Schema' . DS . 'migrations' . DS . '*.sql'); natsort($migrations); $db->begin(); try { foreach ($migrations as $filename) { list($migration, $ignore) = explode('.', basename($filename)); if (in_array($migration, $applied)) { continue; } $this->out("Migrating to {$migration}."); $db->query(file_get_contents($filename)); $db->query("INSERT INTO `__migrations` VALUES ('{$migration}')"); } $db->commit(); $this->out('Done.'); } catch (Exception $e) { $this->out("<error>Migration failed. Rolling back.</error>"); $db->rollback(); throw $e; } }
public static function build_http_query($params = array()) { if (empty($params)) { return ""; } // Urlencode both keys and values $keys = Utility::urlencode_rfc3986(array_keys($params)); $values = Utility::urlencode_rfc3986(array_values($params)); $params = array_combine($keys, $values); // params are sorted by name, using lexicographical byte value ordering. // Ref: Spec: 9.1.1 (1) uksort($params, 'strcmp'); $pairs = array(); foreach ($params as $parameter => $value) { if (is_array($value)) { // If two or more params share the same name, they are sorted by their value // Ref: Spec: 9.1.1 (1) natsort($value); foreach ($value as $duplicate_value) { $pairs[] = $parameter . '=' . $duplicate_value; } } else { $pairs[] = $parameter . '=' . $value; } } // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61) // Each name-value pair is separated by an '&' character (ASCII code 38) return implode('&', $pairs); }
function getPublicKey($tab = array(), $mod, $e, $block_limit) { $length_tab = count($tab); $public_key = array(); $key_inv_mod = inv_mod($e, $mod); $password_permut = array(); // if (super_croissance_check($tab)) { for ($i = 0; $i < $length_tab; $i++) { $current_operation = $tab[$i] * $e; $modulo_operation = my_modulo($current_operation, $mod); array_push($public_key, $modulo_operation); } // ordonée sans changer la valeur de la clé natsort($public_key); // on fait un foreach pour trouver les valeurs de la clé foreach ($public_key as $key => $value) { array_push($password_permut, $key); } echo "\n Alice garde precieusement le mot de passe : [ "; foreach ($password_permut as $index_pass) { echo $index_pass; } echo " ]\n"; // on sort en modifiant les valeurs de l'index sort($public_key); echo "\n Alice envoie une clé publique à Bernard : [ "; foreach ($public_key as $values_in_key) { echo $values_in_key, " "; } echo " ]\n"; echo "\n Et envoie la limite de block à Bernard : [ ", $block_limit, " ]\n"; return [$public_key, $password_permut]; // } }
private function getCategories() { $category_models = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get(); $categories = $this->recursivePrint($category_models); natsort($categories); return $categories; }
/** * Result postprocessor, that transforms the results to hash. */ protected function prepareResult($rows) { // Process ARRAY_KEY feature. if (is_array($rows) && $rows) { // Find ARRAY_KEY* AND PARENT_KEY fields in field list. $pk = null; $ak = array(); foreach (current($rows) as $fieldName => $dummy) { if (0 == strncasecmp($fieldName, self::ALIAS_ARRAY_KEY, strlen(self::ALIAS_ARRAY_KEY))) { $ak[] = $fieldName; } else { if (0 == strncasecmp($fieldName, self::ALIAS_PARENT_KEY, strlen(self::ALIAS_PARENT_KEY))) { $pk = $fieldName; } } } natsort($ak); // sort ARRAY_KEY* using natural comparision if ($ak) { // Tree-based array? Fields: ARRAY_KEY, PARENT_KEY if ($pk !== null) { return $this->prepareResult2Forest($rows, $ak[0], $pk); } // Key-based array? Fields: ARRAY_KEY. return $this->prepareResult2Hash($rows, $ak); } } return $rows; }
function getTeamspeakVersionsFromHTML($htmlSource) { $teamspeakVersionArray = null; $dom = new DOMDocument(); try { $dom->loadHTML($htmlSource); $tableElements = $dom->getElementsByTagName("tr"); foreach ($tableElements as $tableElement) { foreach ($tableElement->childNodes as $tableChildElement) { $tableElementValue = $tableChildElement->nodeValue; //If an element ends with a forward slash then it is a directory if (substr($tableElementValue, -1) == "/") { $tableElementValue = substr($tableElementValue, 0, strlen($tableElementValue) - 1); //Does the element match a version number? if (preg_match("^((?:\\d+\\.)?(?:\\d+\\.)?\\d+\\.\\d+)\$^", $tableElementValue)) { //Build array. $teamspeakVersionArray[] = $tableElementValue; } } } } } catch (Exception $e) { } //Sort the array naturally natsort($teamspeakVersionArray); return $teamspeakVersionArray; }
protected function _buildQuery($params, $separator = '&', $noQuotes = true, $subList = false) { if (empty($params)) { return ''; } //encode both keys and values $keys = $this->_encode(array_keys($params)); $values = $this->_encode(array_values($params)); $params = array_combine($keys, $values); // Parameters are sorted by name, using lexicographical byte value ordering. // http://oauth.net/core/1.0/#rfc.section.9.1.1 uksort($params, 'strcmp'); // Turn params array into an array of "key=value" strings foreach ($params as $key => $value) { if (is_array($value)) { // If two or more parameters share the same name, // they are sorted by their value. OAuth Spec: 9.1.1 (1) natsort($value); $params[$key] = $this->_buildQuery($value, $separator, $noQuotes, true); continue; } if (!$noQuotes) { $value = '"' . $value . '"'; } $params[$key] = $value; } if ($subList) { return $params; } foreach ($params as $key => $value) { $params[$key] = $key . '=' . $value; } return implode($separator, $params); }
public function index() { $this->title($this('configuration')); $modules = array(); foreach ($this->get_modules() as $module) { if ($module->administrable) { $modules[$module->name] = $module->get_title(); } } natsort($modules); $langs = array(); foreach (preg_grep('/\\.php$/', scandir('./neofrag/lang/')) as $file) { $lang = array(); include './neofrag/lang/' . $file; $langs[substr($file, 0, -4)] = $lang['lang']; } natsort($langs); $this->load->library('form')->add_rules(array('name' => array('label' => $this('site_title'), 'value' => $this->config->nf_name, 'rules' => 'required'), 'description' => array('label' => $this('site_description'), 'value' => $this->config->nf_description, 'rules' => 'required'), 'contact' => array('label' => $this('contact_email'), 'value' => $this->config->nf_contact, 'type' => 'email', 'rules' => 'required'), 'default_page' => array('label' => $this('default_page'), 'values' => $modules, 'value' => $this->config->nf_default_page, 'type' => 'select', 'rules' => 'required'), 'default_language' => array('label' => $this('language'), 'values' => $langs, 'value' => $this->config->nf_default_language, 'type' => 'select', 'rules' => 'required'), 'humans_txt' => array('label' => '<a href="http://humanstxt.org/">humans.txt</a>', 'type' => 'textarea', 'value' => $this->config->nf_humans_txt), 'robots_txt' => array('label' => '<a href="http://www.robotstxt.org//">robots.txt</a>', 'type' => 'textarea', 'value' => $this->config->nf_robots_txt), 'analytics' => array('label' => $this('code_analytics'), 'type' => 'textarea', 'value' => $this->config->nf_analytics), 'debug' => array('label' => $this('debug_mode'), 'type' => 'radio', 'value' => $this->config->nf_debug, 'values' => array($this('debug_disabled'), $this('debug_errors_only'), $this('debug_full')))))->add_submit($this('save'))->display_required(FALSE); if ($this->form->is_valid($post)) { foreach ($post as $var => $value) { $this->config('nf_' . $var, $value); } refresh(); } return new Panel(array('title' => $this('general_settings'), 'icon' => 'fa-cogs', 'content' => $this->form->display())); }
/** * @test installing plugins */ public function testInstaller() { $this->__cleanSystem(); $this->assertTrue(App::import('lib', 'Installer.Installer'), 'Could not import the insatller lib'); $this->assertTrue(App::import('Lib', 'Installer.ReleaseVersion'), 'Could not import Versions lib'); $Installer = new InstallerLib(); $Version = new ReleaseVersion(array('connection' => 'test_suite')); $connectionDetails = $Installer->cleanConnectionDetails(array('connection' => $this->db->config)); $this->assertTrue($Installer->installPlugin($Version, $connectionDetails)); $expected = array('0' => 'acos', '1' => 'aros', '2' => 'aros_acos', '3' => 'schema_migrations', '4' => 'sessions'); $this->assertEqual($expected, $this->db->listSources()); $this->assertTrue($Installer->installPlugin($Version, $connectionDetails, 'Installer')); $expected = array('0' => 'acos', '1' => 'aros', '2' => 'aros_acos', '3' => 'core_plugins', '4' => 'schema_migrations', '5' => 'sessions'); $this->assertEqual($expected, $this->db->listSources()); $pluginsToInstall = App::objects('plugin'); natsort($pluginsToInstall); foreach ($pluginsToInstall as $k => $pluginToInstall) { if (in_array($pluginToInstall, array('Migrations'))) { continue; } $this->assertTrue($Installer->installPlugin($Version, $connectionDetails, $pluginToInstall), sprintf('%s could not be installed', $pluginToInstall)); } foreach ($pluginsToInstall as $pluginToInstall) { $this->__checkVersionCount($pluginToInstall); } }
public function twig_sort($array, $method = 'asort', $sort_flag = 'SORT_REGULAR') { settype($sort_flag, 'integer'); switch ($method) { case 'asort': asort($array, $sort_flag); break; case 'arsort': arsort($array, $sort_flag); break; case 'krsort': krsort($array, $sort_flag); break; case 'ksort': ksort($array, $sort_flag); break; case 'natcasesort': natcasesort($array); break; case 'natsort': natsort($array); break; case 'rsort': rsort($array, $sort_flag); break; case 'sort': sort($array, $sort_flag); break; case 'lastModifiedDate_desc': usort($array, array('App\\Respond\\Extensions\\BetterSortTwigExtension', 'lastModifiedDate_desc')); break; } return $array; }
protected function execute(InputInterface $input, OutputInterface $output) { $filename = $input->getArgument('csv'); $file = fopen($filename, 'r'); $this->container = $this->getApplication()->getKernel()->getContainer(); $om = $this->container->get('vib.doctrine.registry')->getManagerForClass('VIB\\CoreBundle\\Entity\\Entity'); $vm = $this->container->get('vib.doctrine.registry')->getManagerForClass('VIB\\FliesBundle\\Entity\\Vial'); $stocks = array(); if ($file) { while ($data = fgetcsv($file, 0, "\t")) { $stocks[] = $data[0]; } } natsort($stocks); $pdf = $this->container->get('vibfolks.pdflabel'); foreach ($stocks as $stockname) { $qb = $om->getRepository('VIB\\FliesBundle\\Entity\\Stock')->createQueryBuilder('b'); $qb->where('b.name like :term')->setParameter('term', $stockname); $stock = $qb->getQuery()->getSingleResult(); echo $stock->getName() . "\n"; foreach ($stock->getLivingVials() as $vial) { if (!$vial->isLabelPrinted()) { echo "\t" . $vial . "\n"; $pdf->addLabel($vial); $vm->markPrinted($vial); } } } $vm->flush(); $jobStatus = $pdf->printPDF(); echo $jobStatus . "\n"; }
/** * Return an array of suggestions from our Translation Memory API. Unlike * other services, we return values from both source and target languages. * * @param array $source_strings Matches from source strings * @param array $target_strings Matches from target strings * @param string $search The string to search for * @param int $max_results Optional, default to 10, the max number of results we return * * @return array An array of strings */ public static function getSuggestionsResults($source_strings, $target_strings, $search, $max_results = 10) { // Only interested in unique strings (values, not IDs). $data = ['source' => array_unique(array_values($source_strings)), 'target' => array_unique(array_values($target_strings))]; $output = ['source' => [], 'target' => []]; $flat_output = []; // Assign quality to each string in each group (source, target) foreach ($data as $group => $group_strings) { foreach ($group_strings as $single_string) { $quality = round(Strings::levenshteinQuality($search, $single_string), 2); $output[$group][$single_string] = $quality; } } // Determine how many suggestions we should display $limits = ['source' => $max_results / 2, 'target' => $max_results / 2]; if (count($output['source']) < $limits['source']) { $limits['target'] = $max_results - count($output['source']); } if (count($output['target']) < $limits['target']) { $limits['source'] = $max_results - count($output['target']); } // Sort them by quality, display higher quality results first foreach ($output as $group => $group_strings) { natsort($group_strings); $suggestions = array_keys(array_reverse($group_strings)); array_splice($suggestions, $limits[$group]); $flat_output = array_merge($flat_output, $suggestions); } return $flat_output; }
/** * @dataProvider unsortedArrayProvider */ public function test_natsort($array) { $arr1 = $arr2 = $array; Arr($arr1)->natsort(); natsort($arr2); $this->assertTrue($arr1 === $arr2); }
function getMyStellar() { // read the cookie, and create three groups // first group all the classes in the cookie // second group is the classes for the current semester // third group is the classes from previou semesters if (!isset($_COOKIE["mystellar"])) { $allTags = array(); } else { $term = StellarData::get_term(); $allTags = explode(",", $_COOKIE["mystellar"]); natsort($allTags); } $currentTags = array(); $currentIds = array(); $oldIds = array(); foreach ($allTags as $classTag) { $parts = explode(" ", $classTag); if ($parts[1] == $term) { $currentTags[] = $classTag; $currentIds[] = $parts[0]; } else { $oldIds[] = $parts[0]; } } return (object) array("allTags" => $allTags, "currentTags" => $currentTags, "currentIds" => $currentIds, "oldIds" => $oldIds); }
function fancy($path) { $fullpath = str_replace('?', '', BASE_URL) . 'public/images/' . $path; $image_dir = CMS_ROOT . '/public/images/' . $path; $handle = opendir($image_dir); // prvi korak: citaj direktorij i napravi polje if ($handle) { while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..') { if (strstr($file, '-thumb')) { $files[] = $file; } } } closedir($handle); } // drugi korak - propusti kroz petlju i ispisi slike $images = count($files); $counter = 1; if (count($files)) { natsort($files); //sortiranje; dodano u 0.8.1 while ($counter <= $images) { foreach ($files as $file) { $counter++; echo '<a class="photo" rel="my-gallery" href="', $fullpath, str_replace('-thumb', '', $file), '" title="', str_replace('-thumb', '', $file), '"><img src="', $fullpath, $file, '"/></a>'; } } } else { echo __('There are no images in this gallery.'); } }
function migrate() { global $MApp; // Get current counter $mlast = AppModel::getByStringId('migrations'); if ($mlast == NULL) { $mlast = 0; } else { $mlast = $mlast['current']; } // Do migrations after counter $mcur = $mlast; $migrations = glob($GLOBALS['dirpre'] . 'migrations/*.php'); natsort($migrations); foreach ($migrations as $m) { if (($mcur = str2int($m)) > $mlast) { require_once $m; echo "performed migration: {$mcur}<br />"; } } if ($mcur > $mlast) { $MApp->save(array('_id' => 'migrations', 'current' => $mcur)); echo "migrated from {$mlast} to {$mcur}"; } else { echo "migrations up to date"; } }
public function index($param) { // get installed CSS themes $files = Fari_File::listing('/public'); $themes = array(); foreach ($files as $file) { $css = end(explode('/', $file['path'])); // its cheap if ($file['type'] == 'file' && substr($css, -4) == '.css') { $themes[] = substr($css, 0, -4); } } natsort(&$themes); $this->view->themes = $themes; // are we saving changes? if ($_POST) { $css = Fari_Escape::text($_POST['css']); $title = Fari_Escape::text($_POST['title']); Fari_Db::update('settings', array('value' => $css), array('name' => 'theme')); Fari_Db::update('settings', array('value' => $title), array('name' => 'title')); Fari_Message::success('Settings change successful.'); } $this->view->messages = Fari_Message::get(); $this->view->settings = Fari_Db::toKeyValues(Fari_Db::select('settings', 'name, value'), 'name'); $this->view->display('settings'); }
function Get_ini_cont() { $IniArr = array(); $main_dir = rDir('../game_content'); $inisets = array(); foreach ($main_dir as $key => $value) { if (preg_match('/iniset(.*)/i', $value) && !preg_match('/\\./i', $value)) { array_push($inisets, $value); } } natsort($inisets); foreach ($inisets as $key => $value) { $iniFiles = rDir('../game_content/' . $value); foreach ($iniFiles as $key2 => $value2) { if (preg_match('/\\.ini/i', $value2)) { $entry = strtolower(preg_replace('/\\.ini/i', '', $value2)); if (!isset($IniArr[$entry]) || !is_array($IniArr[$entry])) { $IniArr[$entry] = array(); } $inicont = readINI('../game_content/' . $value . '/' . $value2); foreach ($inicont as $key3 => $value3) { $IniArr[$entry][$key3] = $value3; } } } } return $IniArr; }
protected function calculateBaseString($method, $url, $parameters) { $parameters = is_array($parameters) ? $parameters : array(); // init var $pairs = array(); $params = array(); // sort parameters by key uksort($parameters, 'strcmp'); foreach($parameters as $key => $value) { // sort by value if(is_array($value)) { $value = natsort($value); } $params[] = self::urlencode($key) .'='. self::urlencode($value); } // builds base $parts = array( strtoupper($method), $url, implode('&', $params) ); $parts = self::urlencode($parts); $base = implode('&', $parts); return $base; }
static function sortmulti($array, $index, $order, $natsort = false, $case_sensitive = false) { if (is_array($array) && count($array) > 0) { foreach (array_keys($array) as $key) { $temp[$key] = $array[$key][$index]; } if (!$natsort) { if ($order == 'asc') { asort($temp); } else { arsort($temp); } } else { if ($case_sensitive === true) { natsort($temp); } else { natcasesort($temp); } if ($order != 'asc') { $temp = array_reverse($temp, true); } } $sorted = array(); foreach (array_keys($temp) as $key) { if (is_numeric($key)) { $sorted[] = $array[$key]; } else { $sorted[$key] = $array[$key]; } } return $sorted; } return $array; }
/** * Returns the colors of the image in an array, ordered in descending order, where the keys are the colors, and the values are the count of the color. * * @return array */ function Get_Color() { if (isset($this->image)) { $im = $this->image; $imgWidth = imagesx($im); $imgHeight = imagesy($im); for ($y = 0; $y < $imgHeight; $y++) { for ($x = 0; $x < $imgWidth; $x++) { $index = imagecolorat($im, $x, $y); $Colors = imagecolorsforindex($im, $index); $Colors['red'] = intval(($Colors['red'] + 15) / 32) * 32; //ROUND THE COLORS, TO REDUCE THE NUMBER OF COLORS, SO THE WON'T BE ANY NEARLY DUPLICATE COLORS! $Colors['green'] = intval(($Colors['green'] + 15) / 32) * 32; $Colors['blue'] = intval(($Colors['blue'] + 15) / 32) * 32; if ($Colors['red'] >= 256) { $Colors['red'] = 240; } if ($Colors['green'] >= 256) { $Colors['green'] = 240; } if ($Colors['blue'] >= 256) { $Colors['blue'] = 240; } $hexarray[] = substr("0" . dechex($Colors['red']), -2) . substr("0" . dechex($Colors['green']), -2) . substr("0" . dechex($Colors['blue']), -2); } } $hexarray = array_count_values($hexarray); natsort($hexarray); $hexarray = array_reverse($hexarray, true); return $hexarray; } else { die("You must enter a filename! (\$image parameter)"); } }
/** * @return Returns the array sorted as required * @param $aryData Array containing data to sort * @param $strIndex name of column to use as an index * @param $strSortBy Column to sort the array by * @param $strSortType String containing either asc or desc [default to asc] * @desc Naturally sorts an array using by the column $strSortBy */ function array_natsort($aryData, $strIndex, $strSortBy, $strSortType = false) { // if the parameters are invalid if (!is_array($aryData) || !$strIndex || !$strSortBy) { // return the array return $aryData; } // create our temporary arrays $arySort = $aryResult = array(); // loop through the array foreach ($aryData as $aryRow) { // set up the value in the array $arySort[$aryRow[$strIndex]] = $aryRow[$strSortBy]; } // apply the natural sort natsort($arySort); // if the sort type is descending if ($strSortType == "desc") { // reverse the array arsort($arySort); } // loop through the sorted and original data foreach ($arySort as $arySortKey => $arySorted) { foreach ($aryData as $aryOriginal) { // if the key matches if ($aryOriginal[$strIndex] == $arySortKey) { // add it to the output array array_push($aryResult, $aryOriginal); } } } // return the return return $aryResult; }
/** * Returns the file path for the given key. Returning the most recent version and clearing old cache keys. * * @access protected * @author Oliver Lillie * @param string $key The cache key string. * @return string Returns the found file path for the given cache key. */ protected function _getFile($key) { $file_prefix = $this->_getFilePathPrefix($key); $matches = glob($file_prefix . '*'); if (empty($matches) === false) { natsort($matches); $cur_time = time(); $oldest = 0; foreach ($matches as $path) { $name = basename($path); $parts = explode('_', $name); if ($parts[1] < $cur_time) { @unlink($path); } else { if ($parts[1] > $oldest) { $oldest = $parts[1]; } } } if ($oldest > 0) { return $file_prefix . $oldest; } } return null; }
function rcms_scandir($directory) { $dir = array(); if (is_dir($directory)) { $fh = opendir($directory); while (false !== ($filename = readdir($fh))) { if (substr($filename, 0, 1) != '.') { array_push($dir, $filename); } } closedir($fh); } if ($exp != '') { $files = array(); natsort($dir); for ($i = 0; $i < sizeof($dir); $i++) { if (preg_match($exp, $dir[$i])) { $files[] = $dir[$i]; } } return $files; } else { return $dir; } }
public function init() { $dir = Yii::getPathOfAlias('app.migrations'); if (!is_dir($dir)) { mkdir($dir); mkdir($dir . DIRECTORY_SEPARATOR . '1'); } $migDir = glob($dir . DIRECTORY_SEPARATOR . "*", GLOB_ONLYDIR); natsort($migDir); $mig = array(); $migrations = array(); foreach ($migDir as $d) { $sqls = glob($d . DIRECTORY_SEPARATOR . "*.sql"); $idx = str_replace($dir . DIRECTORY_SEPARATOR, '', $d); if (!isset($mig[$idx])) { $mig = array($idx => array()) + $mig; } foreach ($sqls as $sql_file) { $data = file_get_contents($sql_file); $file = str_replace($d . DIRECTORY_SEPARATOR, '', $sql_file); $mig[$idx][$file] = $data; } } foreach ($mig as $id => $m) { $migrations[] = array('id' => $id, 'items' => $m); } $this->migrations = $migrations; $this->name = Setting::get('db.migration_name', ''); $this->done = $this->list; }
public function CheckPermissions() { if ($this->FoldersToCheck === null) { $this->GetFoldersToCheck(); } // Make the folders appear in alphabetical order to make it easier to go through and fix up permissions natsort($this->FoldersToCheck); // Then order them by their depth usort($this->FoldersToCheck, array($this, 'dir_depth_compare')); include_once(ISC_BASE_PATH.'/lib/class.file.php'); $f = new FileClass(); $result = array(); foreach($this->FoldersToCheck as $folder) { $path = ISC_BASE_PATH . '/' . $folder; if(file_exists($path)) { if(is_dir($path) && $f->CheckDirWritable($path)) { } else if (is_file($path) && $f->CheckFileWritable($path)) { } else { $result[] = array($folder, TARGET_NOT_WRITABLE, $file); } } else { $result[] = array($folder, TARGET_DOESNT_EXIST); } } return $result; }
public function testNormalizesGluedHeaders() { $h = new Header('Zoo', array('foo, Faz', 'bar')); $result = $h->normalize(true)->toArray(); natsort($result); $this->assertEquals(array('bar', 'foo', 'Faz'), $result); }
/** * @return array */ public static function getThemes() { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $files = Folder::all('gantry-themes://', ['recursive' => false, 'files' => false]); /** @var array|ThemeDetails[] $list */ $list = []; natsort($files); foreach ($files as $theme) { if ($locator('gantry-themes://' . $theme . '/gantry/theme.yaml')) { $details = new ThemeDetails($theme); // Stream needs to be valid URL. $streamName = 'gantry-themes-' . preg_replace('|[^a-z\\d+.-]|ui', '-', $theme); if (!$locator->schemeExists($streamName)) { $locator->addPath($streamName, '', $details->getPaths()); } $details['name'] = $theme; $details['title'] = $details['details.name']; $details['preview_url'] = $gantry['platform']->getThemePreviewUrl($theme); $details['admin_url'] = $gantry['platform']->getThemeAdminUrl($theme); $details['params'] = []; $list[$details->name] = $details; } } // Add Thumbnails links after adding all the paths to the locator. foreach ($list as $details) { $details['thumbnail'] = $details->getUrl("details.images.thumbnail"); } return $list; }