function link_entities($deprecated = true) { $entities = array(); // mentions foreach ($this->mentions() as $entity) { $entities['start_' . str_pad($entity->indices[0], 5, '0', STR_PAD_LEFT)] = array('find' => $entity->screen_name, 'replace' => AKTT::profile_link($entity->screen_name), 'start' => $entity->indices[0], 'end' => $entity->indices[1]); } // hashtags foreach ($this->hashtags() as $entity) { $entities['start_' . str_pad($entity->indices[0], 5, '0', STR_PAD_LEFT)] = array('find' => $entity->text, 'replace' => AKTT::hashtag_link($entity->text), 'start' => $entity->indices[0], 'end' => $entity->indices[1]); } // URLs foreach ($this->urls() as $entity) { $entities['start_' . str_pad($entity->indices[0], 5, '0', STR_PAD_LEFT)] = array('find' => $entity->url, 'replace' => '<a href="' . esc_url($entity->expanded_url) . '">' . esc_html($entity->display_url) . '</a>', 'start' => $entity->indices[0], 'end' => $entity->indices[1]); } ksort($entities); $str = $this->content(); $diff = 0; foreach ($entities as $entity) { $start = $entity['start'] + $diff; $end = $entity['end'] + $diff; // $log = array(); // $log[] = 'diff: '.$diff; // $log[] = 'entity start: '.$entity['start']; // $log[] = 'entity start chars: '.AKTT::substr($this->content(), $entity['start'], 3); // $log[] = 'diff start: '.$start; // $log[] = 'diff start chars: '.AKTT::substr($str, $start, 3); // $log[] = 'entity end: '.$entity['end']; // $log[] = 'diff end: '.$end; // $log[] = 'find len: '.AKTT::strlen($entity['find']); // $log[] = 'find: '.htmlspecialchars($entity['find']); // $log[] = 'replace len: '.AKTT::strlen($entity['replace']); // $log[] = 'replace: '.htmlspecialchars($entity['replace']); // echo '<p>'.implode('<br>', $log).'</p>'; $str = AKTT::substr_replace($str, $entity['replace'], $start, $end - $start); $diff += AKTT::strlen($entity['replace']) - ($end - $start); } if ($this->is_native_retweet()) { $orig_screen_name = $this->data->retweeted_status->user->screen_name; $str = 'RT ' . AKTT::profile_link($orig_screen_name) . ': ' . $str; } return $str; }
function link_entities($defer_to_anywhere = true) { $entities = array(); // mentions $anywhere = Social::option('twitter_anywhere_api_key'); if (!$defer_to_anywhere || empty($anywhere) || is_feed()) { foreach ($this->mentions() as $entity) { $entities['start_' . str_pad($entity->indices[0], 5, '0', STR_PAD_LEFT)] = array('find' => $entity->screen_name, 'replace' => AKTT::profile_link($entity->screen_name), 'start' => $entity->indices[0], 'end' => $entity->indices[1]); } } // hashtags foreach ($this->hashtags() as $entity) { $entities['start_' . str_pad($entity->indices[0], 5, '0', STR_PAD_LEFT)] = array('find' => $entity->text, 'replace' => AKTT::hashtag_link($entity->text), 'start' => $entity->indices[0], 'end' => $entity->indices[1]); } // URLs foreach ($this->urls() as $entity) { $entities['start_' . str_pad($entity->indices[0], 5, '0', STR_PAD_LEFT)] = array('find' => $entity->url, 'replace' => '<a href="' . esc_url($entity->expanded_url) . '">' . esc_html($entity->display_url) . '</a>', 'start' => $entity->indices[0], 'end' => $entity->indices[1]); } ksort($entities); $str = $this->content(); $diff = 0; foreach ($entities as $entity) { $start = $entity['start'] + $diff; $end = $entity['end'] + $diff; // $log = array(); // $log[] = 'diff: '.$diff; // $log[] = 'entity start: '.$entity['start']; // $log[] = 'entity start chars: '.AKTT::substr($this->content(), $entity['start'], 3); // $log[] = 'diff start: '.$start; // $log[] = 'diff start chars: '.AKTT::substr($str, $start, 3); // $log[] = 'entity end: '.$entity['end']; // $log[] = 'diff end: '.$end; // $log[] = 'find len: '.AKTT::strlen($entity['find']); // $log[] = 'find: '.htmlspecialchars($entity['find']); // $log[] = 'replace len: '.AKTT::strlen($entity['replace']); // $log[] = 'replace: '.htmlspecialchars($entity['replace']); // echo '<p>'.implode('<br>', $log).'</p>'; $str = AKTT::substr_replace($str, $entity['replace'], $start, $end - $start); $diff += AKTT::strlen($entity['replace']) - ($end - $start); } return $str; }