本文整理汇总了PHP中PerchUtil::array_sort方法的典型用法代码示例。如果您正苦于以下问题:PHP PerchUtil::array_sort方法的具体用法?PHP PerchUtil::array_sort怎么用?PHP PerchUtil::array_sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PerchUtil
的用法示例。
在下文中一共展示了PerchUtil::array_sort方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_categories_from_ids_runtime
public function get_categories_from_ids_runtime($ids, $sort = false)
{
if (PerchUtil::count($this->from_ids_cache)) {
$out = array_filter($this->from_ids_cache, function ($a) use($ids) {
return in_array($a['catID'], $ids);
});
if ($sort !== false) {
$parts = explode(' ', trim($sort));
$sort_field = $parts[0];
if (isset($parts[1]) && ($parts[1] == 'ASC' || $parts[1] == 'DESC')) {
$sort_dir = $parts[1];
} else {
$sort_dir = 'ASC';
}
$out = PerchUtil::array_sort($out, $sort_field, $sort_dir == 'DESC' ? true : false);
}
return $this->return_flattened_instances($out);
}
if (!$sort) {
$sort = 'catTreePosition ASC';
}
$sql = 'SELECT * FROM ' . $this->table . ' ORDER BY ' . $sort;
$rows = $this->db->get_rows($sql);
if (PerchUtil::count($rows)) {
$this->from_ids_cache = $rows;
return $this->get_categories_from_ids_runtime($ids, $sort);
}
}
示例2: get_templates
public function get_templates($path = false, $include_hidden = false, $initial_path = false)
{
$Perch = Perch::fetch();
if ($path === false) {
$path = PERCH_TEMPLATE_PATH . '/categories';
}
if ($initial_path === false) {
$initial_path = $path;
}
$a = array();
if (is_dir($path)) {
if ($dh = opendir($path)) {
while (($file = readdir($dh)) !== false) {
if (substr($file, 0, 1) != '.' && ($include_hidden || substr($file, 0, 1) != '_') && !preg_match($Perch->ignore_pattern, $file)) {
$extension = PerchUtil::file_extension($file);
if ($extension == 'html' || $extension == 'htm') {
$p = str_replace($initial_path, '', $path);
if (!$p) {
$a[PerchLang::get('Categories')][] = array('filename' => $file, 'path' => $file, 'label' => $this->template_display_name($file));
} else {
$a[] = array('filename' => $file, 'path' => ltrim($p, '/') . '/' . $file, 'label' => $this->template_display_name($file));
}
} else {
$a[$this->template_display_name($file)] = $this->get_templates($path . '/' . $file, $include_hidden, $initial_path);
}
}
}
closedir($dh);
}
if (PerchUtil::count($a)) {
$a = PerchUtil::array_sort($a, 'label');
}
}
return $a;
}
示例3: get_list
public function get_list($filter_mode = false, $sort = true)
{
$db = PerchDB::fetch();
$sql = 'SELECT * FROM ' . $this->table;
// Extend this later...
// switch ($filter_mode) {
// default:
// # code...
// break;
// }
$results = $db->get_rows($sql);
if ($sort && PerchUtil::count($results) > 0) {
$results = PerchUtil::array_sort($results, 'Location');
}
return $this->return_instances($results);
}
示例4: get_templates
/**
* Get an array of templates in the content folder.
*
* @param string $path
* @return void
* @author Drew McLellan
*/
public function get_templates($path = false, $include_hidden = false, $initial_path = false)
{
$Perch = Perch::fetch();
if ($path === false) {
$path = PERCH_TEMPLATE_PATH . '/forms/emails';
}
if ($initial_path === false) {
$initial_path = $path;
}
$a = array();
$groups = array();
$p = false;
if (is_dir($path)) {
if ($dh = opendir($path)) {
while (($file = readdir($dh)) !== false) {
if (substr($file, 0, 1) != '.' && ($include_hidden || substr($file, 0, 1) != '_') && !preg_match($Perch->ignore_pattern, $file)) {
$extension = PerchUtil::file_extension($file);
if ($extension == 'html' || $extension == 'htm') {
$p = str_replace($initial_path, '', $path);
if (!$p) {
$a[PerchLang::get('Templates')][] = array('filename' => $file, 'value' => $file, 'path' => $file, 'label' => $this->template_display_name($file));
} else {
$a[] = array('filename' => $file, 'value' => ltrim($p, '/') . '/' . $file, 'path' => ltrim($p, '/') . '/' . $file, 'label' => $this->template_display_name($file));
}
} else {
// Use this one of infinite recursive nesting. Group stuff below normalised for HTML select optgroups that only do one level
//$a[$this->template_display_name($file)] = $this->get_templates($path.'/'.$file, $include_hidden, $initial_path);
if ($p) {
$group_name = $this->template_display_name(trim($p, '/\\') . '/' . $file);
} else {
$group_name = $this->template_display_name($file);
}
$groups[$group_name] = $this->get_templates($path . '/' . $file, $include_hidden, $initial_path);
}
}
}
closedir($dh);
}
if (PerchUtil::count($a)) {
$a = PerchUtil::array_sort($a, 'label');
}
}
return $a + $groups;
}
示例5: array
}
// If a success or failure message has been set, output that here
echo $message;
// Sub head
echo $HTML->heading2('Details');
// Output the edit form
echo $Form->form_start();
$details = array();
if (is_object($Set)) {
$details = $Set->to_array();
}
echo $Form->fields_from_template($Template, $details, array(), false);
$opts = array();
$templates = $Sets->get_templates();
if (PerchUtil::count($templates)) {
$opts = array();
foreach ($templates as $group_name => $group) {
$tmp = array();
$group = PerchUtil::array_sort($group, 'label');
foreach ($group as $file) {
$tmp[] = array('label' => $file['label'], 'value' => $file['path']);
}
$opts[$group_name] = $tmp;
}
}
echo $Form->grouped_select_field('setTemplate', 'Set template', $opts, isset($details['setTemplate']) ? $details['setTemplate'] : 'set.html');
echo $Form->grouped_select_field('setCatTemplate', 'Category template', $opts, isset($details['setCatTemplate']) ? $details['setCatTemplate'] : 'category.html');
echo $Form->submit_field();
echo $Form->form_end();
// Footer
include PERCH_PATH . '/core/inc/main_end.php';
示例6: get_custom
//.........这里部分代码省略.........
case 'eqbetwixt':
$vals = explode(',', $val);
if (PerchUtil::count($vals) == 2) {
if ($item[$key] >= trim($vals[0]) && $item[$key] <= trim($vals[1])) {
$out[] = $item;
}
}
break;
case 'in':
case 'within':
$vals = explode(',', $val);
if (PerchUtil::count($vals)) {
foreach ($vals as $value) {
if ($item[$key] == trim($value)) {
$out[] = $item;
break;
}
}
}
break;
}
}
}
$comments = $out;
}
}
// sort
if (isset($opts['sort'])) {
if (isset($opts['sort-order']) && $opts['sort-order'] == 'DESC') {
$desc = true;
} else {
$desc = false;
}
$comments = PerchUtil::array_sort($comments, $opts['sort'], $desc);
}
if (isset($opts['sort-order']) && $opts['sort-order'] == 'RAND') {
shuffle($comments);
}
// Pagination
if (isset($opts['paginate'])) {
$Paging->set_per_page(isset($opts['count']) ? (int) $opts['count'] : 10);
$opts['count'] = $Paging->per_page();
$opts['start'] = $Paging->lower_bound() + 1;
$Paging->set_total(PerchUtil::count($comments));
} else {
$Paging = false;
}
// limit
if (isset($opts['count']) || isset($opts['start'])) {
// count
if (isset($opts['count']) && $opts['count']) {
$count = (int) $opts['count'];
} else {
$count = PerchUtil::count($comments);
}
// start
if (isset($opts['start'])) {
if ($opts['start'] === 'RAND') {
$start = rand(0, PerchUtil::count($comments) - 1);
} else {
$start = (int) $opts['start'] - 1;
}
} else {
$start = 0;
}
// loop through
示例7: get_custom
//.........这里部分代码省略.........
if ($this_item == trim($value)) {
$out[$item['_id']] = $item;
break;
}
}
}
break;
}
}
}
// if 'AND' mode, run the next filter against the already filtered list
if ($filter_mode == 'AND') {
$filter_content = $out;
} else {
$filter_content = $content;
}
}
$content = $out;
}
}
// reindex array
$new_content = array();
foreach ($content as $c) {
$new_content[] = $c;
}
$content = $new_content;
// sort
if (isset($opts['sort'])) {
if (isset($opts['sort-order']) && $opts['sort-order'] == 'DESC') {
$desc = true;
} else {
$desc = false;
}
$content = PerchUtil::array_sort($content, $opts['sort'], $desc);
}
if (isset($opts['sort-order']) && $opts['sort-order'] == 'RAND') {
shuffle($content);
}
// Pagination
if (isset($opts['paginate'])) {
$Paging = $API->get('Paging');
if (isset($opts['pagination-var'])) {
$Paging->set_qs_param($opts['pagination-var']);
}
$Paging->set_per_page(isset($opts['count']) ? (int) $opts['count'] : 10);
$opts['count'] = $Paging->per_page();
$opts['start'] = $Paging->lower_bound() + 1;
$Paging->set_total(PerchUtil::count($content));
} else {
$Paging = false;
}
// limit
if (isset($opts['count']) || isset($opts['start'])) {
// count
if (isset($opts['count'])) {
$count = (int) $opts['count'];
} else {
$count = PerchUtil::count($content);
}
// start
if (isset($opts['start'])) {
if ($opts['start'] === 'RAND') {
$start = rand(0, PerchUtil::count($content) - 1);
} else {
$start = (int) $opts['start'] - 1;
}
示例8: get_custom
//.........这里部分代码省略.........
if ($item[$key] > trim($vals[0]) && $item[$key] < trim($vals[1])) {
$out[] = $item;
}
}
break;
case 'eqbetween':
case 'eqbetwixt':
$vals = explode(',', $val);
if (PerchUtil::count($vals) == 2) {
if ($item[$key] >= trim($vals[0]) && $item[$key] <= trim($vals[1])) {
$out[] = $item;
}
}
break;
case 'in':
case 'within':
$vals = explode(',', $val);
if (PerchUtil::count($vals)) {
foreach ($vals as $value) {
if ($item[$key] == trim($value)) {
$out[] = $item;
break;
}
}
}
break;
}
}
}
$content = $out;
}
}
}
// sort
if (isset($opts['sort'])) {
if (isset($opts['sort-order']) && $opts['sort-order'] == 'DESC') {
$desc = true;
} else {
$desc = false;
}
$content = PerchUtil::array_sort($content, $opts['sort'], $desc);
}
if (isset($opts['sort-order']) && $opts['sort-order'] == 'RAND') {
shuffle($content);
}
// Pagination
if (isset($opts['paginate'])) {
if (isset($opts['pagination_var'])) {
$Paging = new PerchPaging($opts['pagination_var']);
} else {
$Paging = new PerchPaging();
}
$Paging->set_per_page(isset($opts['count']) ? (int) $opts['count'] : 10);
$opts['count'] = $Paging->per_page();
$opts['start'] = $Paging->lower_bound() + 1;
$Paging->set_total(PerchUtil::count($content));
} else {
$Paging = false;
}
// limit
if (isset($opts['count']) || isset($opts['start'])) {
// count
if (isset($opts['count'])) {
$count = (int) $opts['count'];
} else {
$count = PerchUtil::count($content);
}
// start
if (isset($opts['start'])) {
if ($opts['start'] === 'RAND') {
$start = rand(0, PerchUtil::count($content) - 1);
} else {
$start = (int) $opts['start'] - 1;
}
} else {
$start = 0;
}
// loop through
$out = array();
for ($i = $start; $i < $start + $count; $i++) {
if (isset($content[$i])) {
$out[] = $content[$i];
} else {
break;
}
}
$content = $out;
}
// Paging to template
if (is_object($Paging) && $Paging->enabled()) {
$paging_array = $Paging->to_array($opts);
// merge in paging vars
foreach ($content as &$item) {
foreach ($paging_array as $key => $val) {
$item[$key] = $val;
}
}
}
return $content;
}
示例9: receive_from_template_fields
public function receive_from_template_fields($Template, $previous_values, $Factory = false, $Item = false, $clear_post = true, $strip_static = true)
{
$tags = $Template->find_all_tags_and_repeaters();
if (is_object($Item)) {
$Item->squirrel('itemID', '');
$Item->squirrel('itemRowID', '');
} else {
$Item = $Factory->return_instance(array('itemID' => '', 'itemRowID' => ''));
$Item->set_null_id();
}
$Item->squirrel('itemJSON', PerchUtil::json_safe_encode($previous_values));
$subprefix = '';
$postitems = $this->find_items('perch_');
$form_vars = array();
$options = array();
$search_text = ' ';
$API = new PerchAPI(1.0, $this->app_id);
$Resources = $API->get('Resources');
list($form_vars, $search_text) = PerchContent_Util::read_items_from_post($Item, $tags, $subprefix, $form_vars, $postitems, $this, $search_text, $options, $Resources, false, $Template);
if (isset($form_vars['_blocks'])) {
$form_vars['_blocks'] = PerchUtil::array_sort($form_vars['_blocks'], '_block_index');
}
$out = array();
if ($strip_static) {
if (PerchUtil::count($form_vars)) {
foreach ($form_vars as $key => $val) {
if (!in_array($key, $Factory->static_fields)) {
$out[$key] = $val;
}
}
}
} else {
$out = $form_vars;
}
// Clear values from Post (for reordering of blocks etc)
if ($clear_post) {
$_POST = array();
}
return $out;
}
示例10: find_all_tags_and_repeaters
//.........这里部分代码省略.........
foreach ($tag_pairs_to_process as $tag_type) {
// parse out tag pairs
$empty_opener = in_array($tag_type, $tag_pairs_with_empty_openers);
$close_tag = '</perch:' . $tag_type . '>';
$close_tag_len = mb_strlen($close_tag);
$open_tag = '<perch:' . $tag_type . ($empty_opener ? '' : ' ');
$order = 1;
// escape hatch
$i = 0;
$max_loops = 100;
// loop through while we have closing tags
while ($close_pos = mb_strpos($contents, $close_tag)) {
// we always have to go from the start, as the string length changes,
// but stop at the closing tag
$chunk = mb_substr($contents, 0, $close_pos);
// search from the back of the chunk for the opening tag
$open_pos = mb_strrpos($chunk, $open_tag);
// get the pair html chunk
$len = $close_pos + $close_tag_len - $open_pos;
$pair_html = mb_substr($contents, $open_pos, $len);
// find the opening tag - it's right at the start
$opening_tag_end_pos = mb_strpos($pair_html, '>') + 1;
$opening_tag = mb_substr($pair_html, 0, $opening_tag_end_pos);
// condition contents
$condition_contents = mb_substr($pair_html, $opening_tag_end_pos, 0 - $close_tag_len);
// Do the business
$OpeningTag = new PerchXMLTag($opening_tag);
$tmp = array();
if ($tag_type == 'repeater') {
$Repeater = new PerchRepeater($OpeningTag->attributes);
$Repeater->set('id', $OpeningTag->id());
//$Repeater->tags = $this->find_all_tags($type, $condition_contents);
$Repeater->tags = $this->find_all_tags_and_repeaters($type, $condition_contents);
$tmp['tag'] = $Repeater;
} elseif ($tag_type == 'blocks') {
$OpeningTag->set('id', '_blocks');
$OpeningTag->set('type', 'PerchBlocks');
$tmp['tag'] = $OpeningTag;
} else {
$tmp['tag'] = $OpeningTag;
}
// Set the order
if ($OpeningTag->order()) {
$tmp['order'] = (int) $OpeningTag->order();
} else {
$tmp['order'] = strpos($untouched_content, $opening_tag);
}
// If the tag isn't one to strip/exclude, add it to the list.
if (!in_array($tag_type, $tag_pairs_to_exclude)) {
$out[] = $tmp;
}
// Remove the pair so we can parse the next one
$contents = str_replace($pair_html, '', $contents);
// escape hatch counter
$i++;
if ($i > $max_loops) {
return $contents;
}
}
}
$s = '/<perch:(' . $type . '|categories)[^>]*>/';
$count = preg_match_all($s, $contents, $matches);
if ($count > 0) {
$i = 100;
if (is_array($matches[0])) {
foreach ($matches[0] as $match) {
$tmp = array();
$tmp['tag'] = new PerchXMLTag($match);
if (!in_array('categories', $this->disabled_features)) {
if ($tmp['tag']->tag_name() == 'perch:categories') {
$tmp['tag']->set('type', 'category');
}
}
if ($tmp['tag']->tag_name() == 'perch:related') {
$tmp['tag']->set('type', 'related');
}
if ($tmp['tag']->type() != 'repeater') {
if ($tmp['tag']->order()) {
$tmp['order'] = (int) $tmp['tag']->order();
} else {
$tmp['order'] = strpos($untouched_content, $match);
#PerchUtil::debug('Setting order to: '.$tmp['order']);
$i++;
}
$out[] = $tmp;
}
}
}
}
if (PerchUtil::count($out)) {
// sort tags using 'order' attribute
$out = PerchUtil::array_sort($out, 'order');
$final = array();
foreach ($out as $tag) {
$final[] = $tag['tag'];
}
return $final;
}
return false;
}
示例11: sort_for_region
/**
* Reorder the items within a region by the given field
*
* @param string $regionID
* @param string $rev
* @param string $field
* @param string $desc
* @return void
* @author Drew McLellan
*/
public function sort_for_region($regionID, $rev, $field, $desc = false)
{
$items = $this->get_flat_for_region($regionID, $rev);
if (PerchUtil::count($items)) {
$sorted = PerchUtil::array_sort($items, $field, $desc);
$i = 0;
foreach ($sorted as $item) {
$sql = 'UPDATE ' . $this->table . ' SET itemOrder=' . (1000 + $i) . ' WHERE itemID=' . $this->db->pdb((int) $item['itemID']) . ' AND itemRev=' . $this->db->pdb((int) $rev) . ' LIMIT 1';
$this->db->execute($sql);
$i++;
}
return true;
}
return false;
}
示例12: array
// Keep note of edited items
$edited_items = array();
if (is_array($tags)) {
if (PerchUtil::count($items)) {
foreach ($items as $Item) {
$Item->clear_resources();
$id = $Item->itemID();
$form_vars = array();
$file_paths = array();
$search_text = ' ';
$form_vars['_id'] = $id;
$postitems = $Form->find_items('perch_' . $id . '_');
$subprefix = '';
list($form_vars, $search_text) = PerchContent_Util::read_items_from_post($Item, $tags, $subprefix, $form_vars, $postitems, $Form, $search_text, $options, $Resources, false, $Template);
if (isset($form_vars['_blocks'])) {
$form_vars['_blocks'] = PerchUtil::array_sort($form_vars['_blocks'], '_block_index');
}
$data = array();
$data['itemJSON'] = PerchUtil::json_safe_encode($form_vars);
$data['itemSearch'] = $search_text;
//PerchUtil::debug($form_vars, 'success');
$Item->update($data);
$edited_items[] = $id;
}
}
}
// Sort based on region options
$Region->sort_items();
// Publish (or not if draft)
if (isset($_POST['save_as_draft'])) {
$Alert->set('success', PerchLang::get('Draft successfully updated'));
示例13: get_template_files
private function get_template_files($path = false, $include_hidden = false, $initial_path = false)
{
$Perch = Perch::fetch();
if ($path === false) {
$path = PERCH_TEMPLATE_PATH . '/pages';
}
if ($initial_path === false) {
$initial_path = $path;
}
$a = array();
if (is_dir($path)) {
if ($dh = opendir($path)) {
while (($file = readdir($dh)) !== false) {
if (substr($file, 0, 1) != '.' && $file != 'attributes' && ($include_hidden || substr($file, 0, 1) != '_') && !preg_match($Perch->ignore_pattern, $file)) {
$extension = PerchUtil::file_extension($file);
if ($extension == 'php' || $extension == str_replace('.', '', PERCH_DEFAULT_EXT)) {
$p = str_replace($initial_path, '', $path);
if (!$p) {
$a[] = array('filename' => $file, 'path' => $file, 'label' => $this->template_display_name($file), 'group' => 'general', 'sort' => '0_' . $file);
} else {
$out_path = ltrim($p, '/') . '/' . $file;
$a[] = array('filename' => $file, 'path' => $out_path, 'label' => $this->template_display_name($file), 'group' => trim($p, '/'), 'sort' => 'x_' . $out_path);
}
} else {
$a = array_merge($a, $this->get_template_files($path . '/' . $file, $include_hidden, $initial_path));
}
}
}
closedir($dh);
}
if (PerchUtil::count($a)) {
$a = PerchUtil::array_sort($a, 'sort');
}
}
return $a;
}