Exemple #1
0
 private function translatePost($post, $threadsPage = false)
 {
     global $config, $board;
     $apiPost = array();
     $fields = $threadsPage ? $this->threadsPageFields : $this->postFields;
     $this->translateFields($fields, $post, $apiPost);
     if (isset($config['poster_ids']) && $config['poster_ids']) {
         $apiPost['id'] = poster_id($post->ip, $post->thread, $board['uri']);
     }
     if ($threadsPage) {
         return $apiPost;
     }
     // Handle country field
     if (isset($post->body_nomarkup) && $this->config['country_flags']) {
         $modifiers = extract_modifiers($post->body_nomarkup);
         if (isset($modifiers['flag']) && isset($modifiers['flag alt']) && preg_match('/^[a-z]{2}$/', $modifiers['flag'])) {
             $country = strtoupper($modifiers['flag']);
             if ($country) {
                 $apiPost['country'] = $country;
                 $apiPost['country_name'] = $modifiers['flag alt'];
             }
         }
     }
     if ($config['slugify'] && !$post->thread) {
         $apiPost['semantic_url'] = $post->slug;
     }
     // Handle files
     // Note: 4chan only supports one file, so only the first file is taken into account for 4chan-compatible API.
     if (isset($post->files) && $post->files && !$threadsPage) {
         $file = $post->files[0];
         $this->translateFile($file, $post, $apiPost);
         if (sizeof($post->files) > 1) {
             $extra_files = array();
             foreach ($post->files as $i => $f) {
                 if ($i == 0) {
                     continue;
                 }
                 $extra_file = array();
                 $this->translateFile($f, $post, $extra_file);
                 $extra_files[] = $extra_file;
             }
             $apiPost['extra_files'] = $extra_files;
         }
     }
     return $apiPost;
 }
Exemple #2
0
 private function translatePost($post, $threadsPage = false)
 {
     global $config, $board;
     $apiPost = array();
     $fields = $threadsPage ? $this->threadsPageFields : $this->postFields;
     $this->translateFields($fields, $post, $apiPost);
     if ($this->config['poster_ids']) {
         if ($post->thread) {
             $apiPost['id'] = poster_id($post->ip, $post->thread, $board['uri']);
         } else {
             $apiPost['id'] = poster_id($post->ip, $post->id, $board['uri']);
         }
     }
     if ($threadsPage) {
         return $apiPost;
     }
     // Handle country field
     if (isset($post->body_nomarkup) && $this->config['country_flags']) {
         $modifiers = extract_modifiers($post->body_nomarkup);
         if (isset($modifiers['flag']) && isset($modifiers['flag alt']) && preg_match('/^[a-z]{2}$/', $modifiers['flag'])) {
             $country = strtoupper($modifiers['flag']);
             if ($country) {
                 $apiPost['country'] = $country;
                 $apiPost['country_name'] = $modifiers['flag alt'];
             }
         }
     }
     // Handle files
     if (isset($post->files) && $post->files && !$threadsPage) {
         $file = $post->files[0];
         $this->translateFile($file, $apiPost);
         if (sizeof($post->files) > 1) {
             $extra_files = array();
             foreach ($post->files as $i => $f) {
                 if ($i == 0) {
                     continue;
                 }
                 $extra_file = array();
                 $this->translateFile($f, $extra_file);
                 $extra_files[] = $extra_file;
             }
             $apiPost['extra_files'] = $extra_files;
         }
     }
     return $apiPost;
 }