public function move($id, $index, $neworder)
 {
     if ($old = $this->indexof($id, $index)) {
         if ($old != $newindex) {
             array_move($this->items[$index], $old, $newindex);
             $this->save();
         }
     }
 }
    $xfieldsindex = intval($_GET['id']);
    if (!isset($xfieldsindex)) {
        msgbox('Информация', 'Выберите поле, которое хотите сдвинуть!', 'javascript:history.go(-1)');
        exit;
    }
    array_move($xfields, $xfieldsindex, -1);
    @profilesave($xfields);
}
//**************** Двигаем поле вниз ****************** //
if ($_GET['act'] == 'movedown') {
    $xfieldsindex = intval($_GET['id']);
    if (!isset($xfieldsindex)) {
        msgbox('Информация', 'Выберите поле, которое хотите сдвинуть!', 'javascript:history.go(-1)');
        exit;
    }
    array_move($xfields, $xfieldsindex, +1);
    @profilesave($xfields);
}
//**************** Редактирование поля ****************** //
if ($_GET['act'] == 'edit') {
    $xfieldsindex = intval($_GET['id']);
    $editedxfield = $xfields[$xfieldsindex];
    //**************** Если нажали кнопку "Сохранить" ****************** //
    if (isset($_POST['edit_save'])) {
        $editedxfield = $_POST['editedxfield'];
        if (strlen(trim($editedxfield[0])) > 0 and strlen(trim($editedxfield[1])) > 0) {
            $editedxfield[0] = totranslit(trim($editedxfield[0]));
            $editedxfield[0] = str_replace('-', '_', $editedxfield[0]);
            $editedxfield[1] = htmlspecialchars(trim($editedxfield[1]));
            foreach ($xfields as $name => $value) {
                if ($name != $xfieldsindex and $value[0] == $editedxfield[0]) {
Beispiel #3
0
function process_changes($changes)
{
    /*
    $changes should be in the following structure:
    array(
    	1 => array(
    		'file'	=>	'app_resources/somefile.php',
    		'type'	=>	'add | replace',
    		'find'	=>	array('line1', 'line2'),
    		'change'	=>	array('line to add', 'line to add')
    	)
    );
    */
    foreach ($changes as $key => $change) {
        if (!isset($change['file']) || !isset($change['type']) || !isset($change['find']) || !isset($change['change'])) {
            echo '<li>' . translate('changesmissingkey', $key) . '</li></ul></div>';
            return;
        }
        $file = file_get_contents(FORUM_ROOT . '/' . $change['file']);
        $lines = explode("\n", $file);
        foreach ($lines as $line_num => $line) {
            if (trim($line) == trim($change['find'][0])) {
                $success = true;
                foreach ($change['find'] as $find_num => $cur_find) {
                    if (trim($cur_find) != trim($lines[$line_num + $find_num])) {
                        $success = false;
                        break;
                    }
                }
                if ($success) {
                    //if there is a match, then add the code!
                    if ($change['type'] == 'add') {
                        $lines = array_move($lines, $line_num + sizeof($change['find']), sizeof($change['change']));
                        for ($i = 0; $i < sizeof($change['change']); $i++) {
                            $lines[$i + $line_num + sizeof($change['find'])] = $change['change'][$i];
                        }
                    } else {
                        if ($change['type'] == 'replace') {
                            for ($i = 0; $i < sizeof($change['find']); $i++) {
                                $lines[$i + $line_num] = '';
                            }
                            //make more room if necessary
                            if (sizeof($change['find']) < sizeof($change['change'])) {
                                array_splice($lines, $line_num, 0, array_fill(0, sizeof($change['change']) - sizeof($change['find']), ''));
                            } else {
                                if (sizeof($change['find']) > sizeof($change['change'])) {
                                    for ($i = 0; $i < sizeof($change['find']) - sizeof($change['change']); $i++) {
                                        unset($lines[$line_num + $i]);
                                    }
                                }
                            }
                            for ($i = 0; $i < sizeof($change['change']); $i++) {
                                $lines[$i + $line_num] = $change['change'][$i];
                            }
                        } else {
                            echo '<li>' . translate('invalidchangetype', $change['type']) . '</li></ul></div>';
                        }
                    }
                    file_put_contents(FORUM_ROOT . '/' . $change['file'], implode("\n", $lines));
                    break;
                }
            }
        }
    }
}
 /**
  * Moves a field up or down.
  *
  * The ordering indicates the position they are displayed on entity's
  * editing form.
  *
  * @param int $id Field instance id
  * @param string $direction Direction, 'up' or 'down'
  * @return void Redirects to previous page
  */
 public function move($id, $direction)
 {
     $instance = $this->_getOrThrow($id);
     $unordered = [];
     $direction = !in_array($direction, ['up', 'down']) ? 'up' : $direction;
     $position = false;
     $list = $this->_getInstances();
     foreach ($list as $k => $field) {
         if ($field->id === $instance->id) {
             $position = $k;
         }
         $unordered[] = $field;
     }
     if ($position !== false) {
         $ordered = array_move($unordered, $position, $direction);
         $before = md5(serialize($unordered));
         $after = md5(serialize($ordered));
         if ($before != $after) {
             foreach ($ordered as $k => $field) {
                 $field->set('ordering', $k);
                 $this->FieldInstances->save($field);
             }
         }
     }
     $this->title(__d('field', 'Reorder Field'));
     $this->redirect($this->referer());
 }
session_name('pubTool');
header('P3P: CP="CAO PSA OUR"');
session_start();
function array_move(&$a, $oldpos, $newpos)
{
    if ($oldpos == $newpos) {
        return;
    }
    array_splice($a, max($newpos, 0), 0, array_splice($a, max($oldpos, 0), 1));
}
if (isset($_GET['remove'])) {
    $index = $_GET['remove'];
    unset($_SESSION["linkList"][$index]);
    $_SESSION["linkList"] = array_values($_SESSION["linkList"]);
}
if (isset($_GET['up'])) {
    $index = $_GET['up'];
    array_move($_SESSION["linkList"], $index, $index - 1);
}
if (isset($_GET['down'])) {
    $index = $_GET['down'];
    array_move($_SESSION["linkList"], $index, $index + 1);
}
if (isset($_GET['clear'])) {
    unset($_SESSION["linkList"]);
}
?>

<meta http-equiv="refresh" content="0;url=./linkFrame.php">
Beispiel #6
0
/**
 * 数组向上或向下移动一位
 * @param  array  $ary     数组
 * @param  string $key     数组索引
 * @param  string $orderby 向上或向下移动
 * @return array           返回新的数组
 */
function array_move_item(array $ary, string $key, $orderby = 'UP', $num = 1)
{
    $keys = array_keys($ary);
    $index = array_search($key, $keys);
    $count = count($keys);
    if (strtoupper($orderby) == 'UP' && $index > 0) {
        $v = -$num;
    } elseif (strtoupper($orderby) == 'DOWN' && $index < $count) {
        $v = $num;
    }
    if ($v) {
        $keys = array_move($keys, $index, $v);
        extract($ary);
        $ary = compact($keys);
    }
    return $ary;
}
Beispiel #7
0
 /**
  * 菜单项向下移一位
  * @param  int    $idx 菜单位置索引
  * @return boolean
  */
 public function down(int $idx, $index = 0)
 {
     if ($idx < 0) {
         return false;
     }
     $_menu =& $this->_BUFFER[$index];
     $_menu = array_move($_menu, $idx);
     $this->write();
     return false;
 }
Beispiel #8
0
function gallery_main()
{
    $images = get_field('gallery');
    function array_move(&$a, $oldpos, $newpos)
    {
        if ($oldpos == $newpos) {
            return;
        }
        array_splice($a, max($newpos, 0), 0, array_splice($a, max($oldpos, 0), 1));
    }
    $last_key = key(array_slice($images, -1, 1, TRUE));
    $number = 0;
    foreach ($images as $key => $image) {
        $image['width'] <= $image['height'] ? $number++ : ($number += 2);
        $number == 2 ? $number = 0 : '';
        $number % 2 == 0 && $number > 3 ? $number = 0 . array_move($images, $key, $store) : '';
        if ($key == $last_key && $number % 2 != 0) {
            // array_move($images, $store, $last_key - 1 );
            unset($images[$store - 1]);
        }
        $image['width'] <= $image['height'] ? $store = $key + 1 : '';
    }
    if ($images) {
        ?>
<div class="your-class"><?php 
        foreach ($images as $key => $image) {
            $image['width'] <= $image['height'] ? $orientation = 'portrait' : ($orientation = 'landscape');
            ?>
<div>
                <a data-size="<?php 
            echo $image['width'];
            ?>
 x <?php 
            echo $image['height'];
            ?>
" href="<?php 
            echo $image['url'];
            ?>
"><img src="<?php 
            echo $image['sizes'][$orientation];
            ?>
" alt="<?php 
            echo $image['alt'];
            ?>
" /></a>
            </div>
            <?php 
            if ($image['width'] > $image['height']) {
                ?>
                 <div class="spacer"></div>
            <?php 
            }
            ?>
        <?php 
        }
        ?>
        </div>
    <a class="click-slide" >click here</a>
    <?php 
    }
}
 /**
  * Moves language up or down.
  *
  * @param int $id Language's ID
  * @param string $direction Direction, 'up' or 'down'
  * @return void Redirects to previous page
  */
 public function move($id, $direction)
 {
     $this->loadModel('Locale.Languages');
     $language = $this->Languages->get($id);
     $unordered = $this->Languages->find()->select(['id', 'ordering'])->order(['ordering' => 'ASC'])->all()->extract('id')->toArray();
     $position = array_search($language->id, $unordered);
     if (!is_integer($position)) {
         $this->redirect($this->referer());
     }
     $direction = $direction === 'up' ? 'down' : 'up';
     // fix orientation, top-down to left-right
     $ordered = array_move($unordered, $position, $direction);
     if (md5(serialize($ordered)) != md5(serialize($unordered))) {
         foreach ($ordered as $ordering => $id) {
             $this->Languages->updateAll(compact('ordering'), compact('id'));
         }
     }
     $this->title(__d('locale', 'Reorder Language'));
     $this->Flash->success(__d('locale', 'Language successfully reordered!'));
     $this->redirect($this->referer());
 }