Beispiel #1
0
 /**
  * Были ли ошибки во время работы с JSON
  *
  * @param $json string строка с JSON для записи в лог при отладке
  * @return bool|string
  */
 public function isErrorJSON($json)
 {
     require_once MODX_BASE_PATH . "assets/snippets/DocLister/lib/jsonHelper.class.php";
     $error = \jsonHelper::json_last_error_msg();
     if (!in_array($error, array('error_none', 'other'))) {
         $error = true;
     }
     return $error;
 }
 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'];
Beispiel #4
0
 /**
  * Декодирует конкретное поле
  * @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
  *
  * @param $json string строка с JSON для записи в лог при отладке
  * @return bool|string
  */
 public function isErrorJSON($json)
 {
     $error = jsonHelper::json_last_error_msg();
     if (!in_array($error, array('error_none', 'other'))) {
         $this->debug->error($this->getMsg('json.' . $error) . ": " . $this->debug->dumpData($json, 'code'), 'JSON');
         $error = true;
     }
     return $error;
 }
Beispiel #6
0
 /**
  * Преобразует 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();
     }
 }