idx для instagramWidget

Приветствую!

В общем вопрос следует из темы.
Необходимо втулить новую переменную idx в instagram*Widget, чтобы он начал считать каждый элемент!
Пробовал обернуть в pdoPage нифига!
Пробовал втулить кое какие решения в код сниппета и нифига!

Помогите пожалуйста, бьюсь уже второй час, никак не могу понять, что делаю не так!
Вот код сниппета:
<?php
// Supply a userId and an accessToken
$userid         = $scriptProperties['userId'];
$accessToken    = $scriptProperties['accessToken'];
// Debug mode
$debug          = $modx->getOption('debug', $scriptProperties, '0');;

// Verify if user id and access token is set in the snippet properties
if($userid == '' || $accessToken == ''){
  $modx->log(modX::LOG_LEVEL_ERROR, '[instagram*Feed] missing required properties userId & accessToken!');
  return;
}

// Get snippet options
$limit        = $modx->getOption('limit', $scriptProperties, '8');
$tpl          = $modx->getOption('tpl', $scriptProperties, 'instagram*WidgetTestTpl');

// Gets our data
function fetchData($url){
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, 20);
     $result = curl_exec($ch);
     curl_close($ch); 
     return $result;
}

// Pulls and parses data.
$result = fetchData("https://api.instagram*.com/v1/users/{$userid}/media/recent/?access_token={$accessToken}");
$result = json_decode($result);

// counter
$i=0;


foreach ($result->data as $post){
    if($i==$limit) break;
    
    // Get all post tags separate by a comma
    $allTags = $post->tags;
    foreach ($allTags as $k => $v) {
      $tags .=  $v.',';
    }


    $output .= $modx->getChunk($tpl ,array(
       // USER INFO
       'username'                         => $post->user->username, // URL rewrite style
       'fullname'                         => $post->user->full_name,
       'userid'                           => $post->user->id,
       'profile_picture'                  => $post->user->profile_picture,
       // POST / IMAGE
       'post.type'                        => $post->type, // Return image or video
       'post.page'                        => $post->link, // Post dedicated page
       'post.created_time'                => $post->created_time,
       'post.location.name'               => $post->location->name,
       'post.like.count'                  => $post->likes->count,
       'post.text'                        => $post->caption->text,
       'post.tags'                        => $tags,
       // IMAGE THUMBNAIL
       'image.thumbnail.url'              => $post->images->thumbnail->url,
       'image.thumbnail.width'            => $post->images->thumbnail->width,
       'image.thumbnail.height'           => $post->images->thumbnail->height,
       // IMAGE LOW RESOLUTION
       'image.low_resolution.url'         => $post->images->low_resolution->url,
       'image.low_resolution.width'       => $post->images->low_resolution->width,
       'image.low_resolution.height'      => $post->images->low_resolution->height,
       // IMAGE STANDARD RESOLUTION
       'image.standard_resolution.url'    => $post->images->standard_resolution->url,
       'image.standard_resolution.width'  => $post->images->standard_resolution->width,
       'image.standard_resolution.height' => $post->images->standard_resolution->height,
       // VIDEO LOW RESOLUTION
       'video.low_resolution.url'         => $post->videos->low_resolution->url,
       'video.low_resolution.width'       => $post->videos->low_resolution->width,
       'video.low_resolution.height'      => $post->videos->low_resolution->height,
       // VIDEO STANDARD RESOLUTION
       'video.standard_resolution.url'    => $post->videos->standard_resolution->url,
       'video.standard_resolution.width'  => $post->videos->standard_resolution->width,
       'video.standard_resolution.height' => $post->videos->standard_resolution->height,
       // VIDEO STANDARD RESOLUTION
       'video.low_bandwidth.url'          => $post->videos->low_bandwidth->url,
       'video.low_bandwidth.width'        => $post->videos->low_bandwidth->width,
       'video.low_bandwidth.height'       => $post->videos->low_bandwidth->height,
    ));
    
    $i++; 
}

if($debug == 0){
    return $output;
}else if($debug == 1){
    echo '<pre>';
    print_r($result);
    echo '</pre>';
}
Andrey
05 декабря 2017, 20:38
modx.pro
857
0

Комментарии: 3

Andrey
05 декабря 2017, 23:40
0
Было решение сделать что то вроде такого:
В сниппете найдите функцию getResources, в ней есть цикл foreach. Там как раз используется переменная $i. Вот в конце этого цикла сразу перед $i++; добавьте код $resources[$i]['idx'] = $i;. Таким образом, у Вас появится новый плейсхолдер idx. Далее можете его использовать в чанке.
Но это доя сниппета Instagram Latest Posts, а он кривоватый чуть чуть!
    Андрей
    06 декабря 2017, 09:48
    +1
    Там где идет массив с данными, добавьте туда строку просто:

    $output .= $modx->getChunk($tpl ,array(
       'idx' => $i,
       'username'  => $post->user->username,
       ...
    );
      Andrey
      06 декабря 2017, 19:32
      0
      Честь вам и хвала, добрый человек! До конца всей вашей долгой и счастливой жизни!
      Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
      3