You are here

function socialcalc_parse_edit in Sheetnode 6

Same name and namespace in other branches
  1. 5 socialcalc.inc \socialcalc_parse_edit()
  2. 7.2 socialcalc.inc \socialcalc_parse_edit()
  3. 7 socialcalc.inc \socialcalc_parse_edit()

File

./socialcalc.inc, line 78
SocialCalc manipulation functions Translated from socialcalc-3.js and companion files

Code

function socialcalc_parse_edit($data) {
  $edit = array(
    'rowpanes' => array(
      0 => array(
        'first' => 1,
        'last' => 1,
      ),
    ),
    'colpanes' => array(
      0 => array(
        'first' => 1,
        'last' => 1,
      ),
    ),
    'range' => array(
      'hasrange' => FALSE,
    ),
  );
  $line = strtok($data, "\n");
  while ($line !== FALSE) {
    $line = rtrim($line);
    $parts = explode(':', $line);
    switch ($parts[0]) {
      case "version":
        break;
      case "rowpane":
        $edit['rowpanes'][$parts[1] - 0] = array(
          'first' => $parts[2] - 0,
          'last' => $parts[3] - 0,
        );
        break;
      case "colpane":
        $edit['colpanes'][$parts[1] - 0] = array(
          'first' => $parts[2] - 0,
          'last' => $parts[3] - 0,
        );
        break;
      case "ecell":
        $edit['ecell']['pos'] = socialcalc_coord_to_cr($parts[1]);
        $edit['ecell']['coord'] = $parts[1];
        $edit['highlights'][$parts[1]] = "cursor";
        break;
      case "range":
        $range['hasrange'] = TRUE;
        $range['anchorcoord'] = $parts[1];
        $range['anchorpos'] = socialcalc_coord_to_cr($parts[1]);
        $range['top'] = $parts[2] - 0;
        $range['bottom'] = $parts[3] - 0;
        $range['left'] = $parts[4] - 0;
        $range['right'] = $parts[5] - 0;
        for ($row = $range['top']; $row <= $range['bottom']; $row++) {
          for ($col = $range['left']; $col <= $range['right']; $col++) {
            $coord = socialcalc_cr_to_coord($col, $row);
            if (@$edit['highlights'][$coord] != "cursor") {
              $edit['highlights'][$coord] = "range";
            }
          }
        }
        $edit['range'] = $range;
        break;
      default:
        $key = array_shift($parts);
        $edit[$key] = $parts;
        break;
    }
    $line = strtok("\n");
  }
  return $edit;
}