@@ -148,52 +148,64 @@ function gitsync_commits_shortcode($atts) {
148148 // Display the data
149149 $ output = '' ; // Initialize output variable
150150
151- if (!empty ($ commits_data )) {
151+ if (!empty ($ commits_data )) {
152152 // Display commits
153153 $ output .= '<ul> ' ;
154154 foreach ($ commits_data as $ commit ) {
155- // Check if the commit message contains "Translate-URL:", and if so, exclude the exact line that contains it
156- $ commit_message = explode ("\n" , $ commit ['commit ' ]['message ' ]);
157- $ filtered_message = '' ;
158- $ found_translate_url = false ;
159- foreach ($ commit_message as $ line ) {
160- if (strpos ($ line , 'Translate-URL: ' ) !== false ) {
161- $ found_translate_url = true ;
162- } else {
163- // Remove line breaks within the commit message
164- $ filtered_message .= str_replace ("\n" , "" , $ line ) . " " ;
155+ if (
156+ isset ($ commit ['author ' ]['html_url ' ]) &&
157+ isset ($ commit ['author ' ]['avatar_url ' ]) &&
158+ isset ($ commit ['commit ' ]['author ' ]['name ' ]) &&
159+ isset ($ commit ['html_url ' ]) &&
160+ isset ($ commit ['commit ' ]['message ' ]) &&
161+ isset ($ commit ['commit ' ]['author ' ]['date ' ])
162+ ) {
163+ // Check if the commit message contains "Translate-URL:", and if so, exclude the exact line that contains it
164+ $ commit_message = explode ("\n" , $ commit ['commit ' ]['message ' ]);
165+ $ filtered_message = '' ;
166+ $ found_translate_url = false ;
167+ foreach ($ commit_message as $ line ) {
168+ if (strpos ($ line , 'Translate-URL: ' ) !== false ) {
169+ $ found_translate_url = true ;
170+ } else {
171+ // Remove line breaks within the commit message
172+ $ filtered_message .= str_replace ("\n" , "" , $ line ) . " " ;
173+ }
165174 }
175+
176+ // Generate list items for each commit
177+ $ output .= '<li> ' ;
178+
179+ // Make the author image clickable and link to the user's GitHub profile
180+ $ output .= '<a href=" ' . esc_url ($ commit ['author ' ]['html_url ' ]) . '" target="_blank"> ' ;
181+ $ output .= '<img src=" ' . esc_url ($ commit ['author ' ]['avatar_url ' ]) . '" alt=" ' . esc_attr ($ commit ['commit ' ]['author ' ]['name ' ]) . '" width="24" height="24" style="vertical-align: middle; margin-right: 8px;" /> ' ;
182+ $ output .= '</a> ' ;
183+
184+ // Commit Number (Clickable)
185+ $ commit_number = substr ($ commit ['sha ' ], 0 , 7 ); // Extract the first 7 characters
186+ $ output .= '<a href=" ' . esc_url ($ commit ['html_url ' ]) . '" target="_blank">Commit # ' . esc_html ($ commit_number ) . '</a> ' ;
187+
188+ // Commit Message (remove any line breaks within the commit message)
189+ $ output .= ' - ' . esc_html ($ filtered_message );
190+
191+ // Calculate the time since the commit was created
192+ $ time_since_creation = time_since_creation ($ commit ['commit ' ]['author ' ]['date ' ]);
193+ $ output .= ' - Since ( ' . $ time_since_creation . ') ' ;
194+
195+ // Make the author name clickable and link to the user's GitHub profile
196+ $ output .= ' - <a href=" ' . esc_url ($ commit ['author ' ]['html_url ' ]) . '" target="_blank"> ' . esc_html ($ commit ['commit ' ]['author ' ]['name ' ]) . '</a> ' ;
197+
198+ $ output .= '</li> ' ;
199+ } else {
200+ // Handle incomplete commit data
201+ $ output .= '<li>Weblate translation commit.</li> ' ;
166202 }
167-
168- // Generate list items for each commit
169- $ output .= '<li> ' ;
170-
171- // Make the author image clickable and link to the user's GitHub profile
172- $ output .= '<a href=" ' . esc_url ($ commit ['author ' ]['html_url ' ]) . '" target="_blank"> ' ;
173- $ output .= '<img src=" ' . esc_url ($ commit ['author ' ]['avatar_url ' ]) . '" alt=" ' . esc_attr ($ commit ['commit ' ]['author ' ]['name ' ]) . '" width="24" height="24" style="vertical-align: middle; margin-right: 8px;" /> ' ;
174- $ output .= '</a> ' ;
175-
176- // Commit Number (Clickable)
177- $ commit_number = substr ($ commit ['sha ' ], 0 , 7 ); // Extract the first 7 characters
178- $ output .= '<a href=" ' . esc_url ($ commit ['html_url ' ]) . '" target="_blank">Commit # ' . esc_html ($ commit_number ) . '</a> ' ;
179-
180- // Commit Message (remove any line breaks within the commit message)
181- $ output .= ' - ' . esc_html ($ filtered_message );
182-
183- // Calculate the time since the commit was created
184- $ time_since_creation = time_since_creation ($ commit ['commit ' ]['author ' ]['date ' ]);
185- $ output .= ' - Since ( ' . $ time_since_creation . ') ' ;
186-
187- // Make the author name clickable and link to the user's GitHub profile
188- $ output .= ' - <a href=" ' . esc_url ($ commit ['author ' ]['html_url ' ]) . '" target="_blank"> ' . esc_html ($ commit ['commit ' ]['author ' ]['name ' ]) . '</a> ' ;
189-
190- $ output .= '</li> ' ;
191203 }
192204 $ output .= '</ul> ' ;
193205 } else {
194206 $ output .= '<p>No new commits found.</p> ' ;
195207 }
196-
208+
197209 return $ output ;
198210}
199211
0 commit comments