function getThumbConfig($tconfig, $rid, $template) { $out = array(); include_once MODX_BASE_PATH . 'assets/snippets/DocLister/lib/jsonHelper.class.php'; $thumbs = \jsonHelper::jsonDecode(urldecode($tconfig), array('assoc' => true), true); foreach ($thumbs as $thumb) { if ($thumb['rid'] == $rid || $thumb['template'] == $template) { $out[] = $thumb; } } return $out; }
<?php if (!defined('MODX_BASE_PATH')) { die('HACK???'); } $ID = $modx->documentObject['id']; $params = is_array($modx->Event->params) ? $modx->Event->params : array(); $params = array_merge($params, array('api' => 1, 'debug' => '0')); $json = $modx->runSnippet("DocLister", $params); $children = jsonHelper::jsonDecode($json, array('assoc' => true)); $children = is_array($children) ? $children : array(); $self = $prev = $next = null; foreach ($children as $key => $data) { if (!empty($self)) { $next = $key; break; } if ($key == $ID) { $self = $key; if (empty($prev)) { $prev = end($children); $prev = $prev['id']; } } else { $prev = $key; } } if (empty($next)) { reset($children); $next = current($children); $next = $next['id'];
/** * Декодирует конкретное поле * @param string $field Имя поля * @param bool $store обновить распакованное поле * @return array ассоциативный массив с данными из json строки */ public function decodeField($field, $store = false) { $out = array(); if ($this->isDecodableField($field)) { $data = $this->get($field); $out = jsonHelper::jsonDecode($data, array('assoc' => true), true); } if ($store) { $this->field[$field] = $out; $this->markAsDecode($field); } return $out; }
/** * Разбор JSON строки при помощи json_decode * * @param $json string строка c JSON * @param array $config ассоциативный массив с настройками для json_decode * @param bool $nop создавать ли пустой объект запрашиваемого типа * @return array|mixed|xNop */ public function jsonDecode($json, $config = array(), $nop = false) { $this->debug->debug('Decode JSON: ' . $this->debug->dumpData($json) . "\r\nwith config: " . $this->debug->dumpData($config), 'jsonDecode', 2); $config = jsonHelper::jsonDecode($json, $config, $nop); $this->isErrorJSON($json); $this->debug->debugEnd("jsonDecode"); return $config; }
/** * Преобразует json или строку с разделителем в массив. * * @param $arr * @param string $sep * @return array|mixed|\xNop */ public function loadArray($arr, $sep = ',') { if (is_scalar($arr)) { $out = \jsonHelper::jsonDecode($arr, array('assoc' => true)); if (is_null($out) && $sep) { $out = array_filter(explode($sep, $arr)); } return $out; } elseif (is_array($arr)) { return $arr; } else { return array(); } }