[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-includes/ -> template.php (source)

   1  <?php
   2  function gp_tmpl_load( $template, $args = array(), $template_path = null ) {
   3      $args = gp_tmpl_filter_args( $args );
   4  
   5      /**
   6       * Fires before a template is loaded.
   7       *
   8       * @since 1.0.0
   9       *
  10       * @param string $template The template name.
  11       * @param array  $args     Arguments passed to the template. Passed by reference.
  12       */
  13      do_action_ref_array( 'gp_pre_tmpl_load', array( $template, &$args ) );
  14      require_once GP_TMPL_PATH . 'helper-functions.php';
  15      $locations = array( GP_TMPL_PATH );
  16      if ( !is_null( $template_path ) ) {
  17          array_unshift( $locations, untrailingslashit( $template_path ) . '/' );
  18      }
  19  
  20      /**
  21       * Filter the locations to load template files from.
  22       *
  23       * @since 1.0.0
  24       *
  25       * @param array       $locations     File paths of template locations.
  26       * @param string      $template      The template name.
  27       * @param array       $args          Arguments passed to the template.
  28       * @param string|null $template_path Priority template location, if any.
  29       */
  30      $locations = apply_filters( 'gp_tmpl_load_locations', $locations, $template, $args, $template_path );
  31      if ( isset( $args['http_status'] ) )
  32          status_header( $args['http_status'] );
  33      foreach( $locations as $location ) {
  34           $file = $location . "$template.php";
  35          if ( is_readable( $file ) ) {
  36              extract( $args, EXTR_SKIP );
  37              include $file;
  38              break;
  39          }
  40      }
  41  
  42      /**
  43       * Fires after a template was loaded.
  44       *
  45       * @since 1.0.0
  46       *
  47       * @param string $template The template name.
  48       * @param array  $args     Arguments passed to the template. Passed by reference.
  49       */
  50      do_action_ref_array( 'gp_post_tmpl_load', array( $template, &$args ) );
  51  }
  52  
  53  function gp_tmpl_get_output() {
  54      $args = func_get_args();
  55      ob_start();
  56      call_user_func_array( 'gp_tmpl_load', $args );
  57      $contents = ob_get_contents();
  58      ob_end_clean();
  59      return $contents;
  60  }
  61  
  62  function gp_tmpl_header( $args = array( ) ) {
  63      gp_tmpl_load( 'header', $args );
  64  }
  65  
  66  function gp_tmpl_footer( $args = array( ) ) {
  67      gp_tmpl_load( 'footer', $args );
  68  }
  69  
  70  function gp_head() {
  71      /**
  72       * Fires inside the head element on the header template.
  73       *
  74       * @since 1.0.0
  75       */
  76      do_action( 'gp_head' );
  77  }
  78  
  79  function gp_footer() {
  80      /**
  81       * Fires at the end of the page, on the footer template.
  82       *
  83       * @since 1.0.0
  84       */
  85      do_action( 'gp_footer' );
  86  }
  87  
  88  function gp_nav_menu( $location = 'main' ) {
  89      $html  = '';
  90      $items = gp_nav_menu_items( $location );
  91  
  92      foreach ( $items as $link => $title ) {
  93          $html .= '<a href="' . $link . '">' . $title . '</a>';
  94      }
  95  
  96      return $html;
  97  }
  98  
  99  function gp_nav_menu_items( $location = 'main' ) {
 100      $items = array();
 101  
 102      if ( 'main' === $location ) {
 103          $items[ gp_url( '/projects' ) ]  = __( 'Projects', 'glotpress' );
 104          $items[ gp_url( '/languages' ) ] = __( 'Locales', 'glotpress' );
 105      }
 106      elseif ( 'side' === $location ) {
 107          if ( is_user_logged_in() ) {
 108              $user = wp_get_current_user();
 109              $items[ gp_url_profile( $user->user_nicename ) ] = __( 'Profile', 'glotpress' );
 110              $items[ gp_url( '/settings' ) ] = __( 'Settings', 'glotpress' );
 111              $items[ esc_url( wp_logout_url( gp_url_current() ) ) ]  = __( 'Log out', 'glotpress' );
 112          }
 113          else {
 114              $items[ esc_url( wp_login_url( gp_url_current() ) ) ] = __( 'Log in', 'glotpress' );
 115          }
 116      }
 117  
 118      /**
 119       * Filter the list of navigation menu items.
 120       *
 121       * @since 1.0.0
 122       *
 123       * @param array  $items    Menu items. URL as the key, menu label as the value.
 124       * @param string $location Location of the menu.
 125       */
 126      return apply_filters( 'gp_nav_menu_items', $items, $location );
 127  }
 128  
 129  function gp_tmpl_filter_args( $args ) {
 130      $clean_args = array();
 131      foreach( $args as $k => $v )
 132          if ( $k[0] != '_' && $k != 'GLOBALS' && !gp_startswith( $k, 'HTTP' ) && !gp_startswith( $k, 'PHP' ) )
 133              $clean_args[$k] = $v;
 134      return $clean_args;
 135  }
 136  
 137  function gp_tmpl_404( $args = array()) {
 138      gp_tmpl_load( '404', $args + array('title' => __('Not Found', 'glotpress' ), 'http_status' => 404 ) );
 139      exit();
 140  }
 141  
 142  function gp_title( $title = null ) {
 143      if ( ! is_null( $title ) ) {
 144          add_filter( 'gp_title', function() use ( $title ) {
 145              return $title;
 146          }, 5 );
 147      } else {
 148  
 149          /**
 150           * Filter the title of a page.
 151           *
 152           * @since 1.0.0
 153           *
 154           * @param string $title The title of a page.
 155           */
 156          return apply_filters( 'gp_title', '' );
 157      }
 158  }
 159  
 160  function gp_breadcrumb( $breadcrumb = null, $args = array() ) {
 161      if ( $breadcrumb ) {
 162          $breadcrumb = gp_array_flatten( $breadcrumb );
 163  
 164          add_filter( 'gp_breadcrumb_items', function( $breadcrumbs ) use ( $breadcrumb ) {
 165              return array_merge( $breadcrumbs, $breadcrumb );
 166          }, 1 );
 167      } else {
 168  
 169          /**
 170           * Filter the list of breadcrumb navigation items.
 171           *
 172           * @since 1.0.0
 173           *
 174           * @param array $breadcrumb_items Breadcrumb items as HTML string.
 175           */
 176          $breadcrumbs = apply_filters( 'gp_breadcrumb_items', array() );
 177  
 178          if ( $breadcrumbs ) {
 179              $defaults = array(
 180                  /* translators: separates links in the navigation breadcrumb */
 181                  'before'              => '<li>',
 182                  'after'               => '</li>',
 183                  'breadcrumb-template' => '<ul class="breadcrumb">{breadcrumb}</ul>',
 184              );
 185              $args = array_merge( $defaults, $args );
 186  
 187              $whole_breadcrumb = '';
 188  
 189              foreach ( $breadcrumbs as $breadcrumb ) {
 190                  $whole_breadcrumb .= $args['before'] . $breadcrumb . $args['after'];
 191              }
 192  
 193              $whole_breadcrumb  = str_replace( '{breadcrumb}', $whole_breadcrumb, $args['breadcrumb-template'] );
 194  
 195              /**
 196               * Filter the breadcrumb HTML output.
 197               *
 198               * @since 1.0.0
 199               *
 200               * @param string $whole_breadcrumb Breadcrumb HTML.
 201               */
 202              return apply_filters( 'gp_breadcrumb', $whole_breadcrumb );
 203          }
 204      }
 205  }
 206  
 207  function gp_project_names_from_root( $leaf_project ) {
 208      $names = array();
 209      $path_from_root = array_reverse( $leaf_project->path_to_root() );
 210  
 211      foreach ( $path_from_root as $project ) {
 212          $names[] = esc_html($project->name);
 213      }
 214  
 215      $project_path = implode( " | ", $names );
 216  
 217      return $project_path;
 218  }
 219  
 220  function gp_project_links_from_root( $leaf_project ) {
 221      if ( 0 === $leaf_project->id ) {
 222          return array();
 223      }
 224      $links = array();
 225      $path_from_root = array_reverse( $leaf_project->path_to_root() );
 226      $links[] = empty( $path_from_root)? __( 'Projects', 'glotpress' ) : gp_link_get( gp_url( '/projects' ), __( 'Projects', 'glotpress' ) );
 227      foreach( $path_from_root as $project ) {
 228          $links[] = gp_link_project_get( $project, esc_html( $project->name ) );
 229      }
 230      return $links;
 231  }
 232  
 233  function gp_breadcrumb_project( $project ) {
 234      return gp_breadcrumb( gp_project_links_from_root( $project ) );
 235  }
 236  
 237  function gp_js_focus_on( $html_id ) {
 238      return '<script type="text/javascript">document.getElementById(\'' . esc_js( $html_id ) . '\').focus();</script>';
 239  }
 240  
 241  function gp_select( $name_and_id, $options, $selected_key, $attrs = array() ) {
 242      $attributes = gp_html_attributes( $attrs );
 243      $attributes = $attributes ? " $attributes" : '';
 244      $res = "<select name='" . esc_attr( $name_and_id ) . "' id='" . esc_attr( $name_and_id ) . "' $attributes>\n";
 245      $labels = [
 246          'hidden' => _x( 'hidden', 'Priority', 'glotpress' ),
 247          'low'    => _x( 'low', 'Priority', 'glotpress' ),
 248          'normal' => _x( 'normal', 'Priority', 'glotpress' ),
 249          'high'   => _x( 'high', 'Priority', 'glotpress' ),
 250      ];
 251      foreach( $options as $value => $label ) {
 252          if ( isset( $labels[ $label ] ) ) {
 253              $label = $labels[ $label ];
 254          }
 255          $selected = selected( $value, $selected_key, false );
 256          $res .= "\t<option value='" . esc_attr( $value ) . "'$selected>" . esc_html( $label ) . "</option>\n";
 257      }
 258      $res .= "</select>\n";
 259      return $res;
 260  }
 261  
 262  function gp_radio_buttons( $name, $radio_buttons, $checked_key ) {
 263      $res = '';
 264      foreach( $radio_buttons as $value => $label ) {
 265          $checked = checked( $value, $checked_key, false );
 266          // TODO: something more flexible than <br />
 267          $res .= "\t<input type='radio' id='" . esc_attr( "{$name}[{$value}]" ) . "' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "'$checked/>&nbsp;";
 268          $res .= "<label for='" . esc_attr( "{$name}[{$value}]" ) . "'>" . esc_html( $label ) . "</label><br />\n";
 269      }
 270      return $res;
 271  }
 272  
 273  function gp_pagination( $page, $per_page, $objects ) {
 274      $surrounding = 2;
 275      $first = $prev_dots = $prev_pages = $next_pages = $next_dots = $last = '';
 276      $page = intval( $page )? intval( $page ) : 1;
 277      $pages = ceil( $objects / $per_page );
 278      if ( $page > $pages ) return '';
 279  
 280      if ( $page > 1 )
 281          $prev = gp_link_get( add_query_arg( array( 'page' => $page - 1 ) ), '&larr;', array('class' => 'previous') );
 282      else
 283          $prev = '<span class="previous disabled">&larr;</span>';
 284  
 285      if ( $page < $pages )
 286          $next = gp_link_get( add_query_arg( array( 'page' => $page + 1)), '&rarr;', array('class' => 'next') );
 287      else
 288          $next = '<span class="next disabled">&rarr;</span>';
 289  
 290      $current = '<span class="current">'.$page.'</span>';
 291      if ( $page > 1 ) {
 292          $prev_pages = array();
 293          foreach( range( max( 1, $page - $surrounding ), $page - 1 ) as $prev_page ) {
 294              $prev_pages[] = gp_link_get( add_query_arg( array( 'page' => $prev_page ) ), $prev_page );
 295          }
 296          $prev_pages = implode( ' ', $prev_pages );
 297          if ( $page - $surrounding > 1 ) $prev_dots = '<span class="dots">&hellip;</span>';
 298      }
 299      if ( $page < $pages ) {
 300          $next_pages = array();
 301          foreach( range( $page + 1, min( $pages, $page + $surrounding ) ) as $next_page ) {
 302              $next_pages[] = gp_link_get( add_query_arg( array( 'page' => $next_page ) ), $next_page );
 303          }
 304          $next_pages = implode( ' ', $next_pages );
 305          if ( $page + $surrounding < $pages ) $next_dots = '<span class="dots">&hellip;</span>';
 306      }
 307      if ( $prev_dots ) $first = gp_link_get( add_query_arg( array( 'page' => 1 ) ), 1 );
 308      if ( $next_dots ) $last = gp_link_get( add_query_arg( array( 'page' => $pages ) ), $pages );
 309       $html = <<<HTML
 310      <div class="paging">
 311          $prev
 312          $first
 313          $prev_dots
 314          $prev_pages
 315          $current
 316          $next_pages
 317          $next_dots
 318          $last
 319          $next
 320      </div>
 321  HTML;
 322  
 323      /**
 324       * Filter the pagination HTML output.
 325       *
 326       * @since 1.0.0
 327       *
 328       * @param string $html     The pagination HTML.
 329       * @param int    $page     Current page number.
 330       * @param int    $per_page Objects per page.
 331       * @param int    $objects  Total number of objects to page.
 332       */
 333      return apply_filters( 'gp_pagination', $html, $page, $per_page, $objects );
 334  }
 335  
 336  function gp_html_attributes( $attrs ) {
 337      $attrs = wp_parse_args( $attrs );
 338      $strings = array();
 339      foreach( $attrs as $key => $value ) {
 340          $strings[] = $key.'="'.esc_attr( $value ).'"';
 341      }
 342      return implode( ' ', $strings );
 343  }
 344  
 345  function gp_attrs_add_class( $attrs, $class_name ) {
 346      $attrs['class'] = isset( $attrs['class'] )? $attrs['class'] . ' ' . $class_name : $class_name;
 347      return $attrs;
 348  }
 349  
 350  /**
 351   * Returns HTML markup for a select element for all locales of a project.
 352   *
 353   * @since 1.0.0
 354   *
 355   * @param int    $project_id    ID of a project.
 356   * @param string $name_and_id   Name and ID of the select element.
 357   * @param string $selected_slug Slug of the current selected locale.
 358   * @param array  $attrs         Extra attributes.
 359   *
 360   * @return string HTML markup for a select element.
 361   */
 362  function gp_locales_by_project_dropdown( $project_id, $name_and_id, $selected_slug = null, $attrs = array() ) {
 363      $locales = GP_Locales::locales();
 364      if ( null != $project_id  ) {
 365          $sets = GP::$translation_set->by_project_id( $project_id );
 366  
 367          $temp_locales = array();
 368  
 369          foreach( $sets as $set ) {
 370              $temp_locales[ $set->locale ] = $locales[ $set->locale ];
 371          }
 372  
 373          if ( count( $temp_locales ) > 0 ) {
 374              $locales = $temp_locales;
 375          }
 376      }
 377      ksort( $locales );
 378  
 379      $options = array( '' => __( '&mdash; Locale &mdash;', 'glotpress' ) );
 380      foreach ( $locales as $key => $locale ) {
 381          $options[ $key ] = sprintf( '%s &mdash; %s', $locale->slug, $locale->english_name );
 382      }
 383  
 384      return gp_select( $name_and_id, $options, $selected_slug, $attrs );
 385  }
 386  
 387  /**
 388   * Returns HTML markup for a select element for all locales.
 389   *
 390   * @since 1.0.0
 391   *
 392   * @param string $name_and_id   Name and ID of the select element.
 393   * @param string $selected_slug Slug of the current selected locale.
 394   * @param array  $attrs         Extra attributes.
 395   *
 396   * @return string HTML markup for a select element.
 397   */
 398  function gp_locales_dropdown( $name_and_id, $selected_slug = null, $attrs = array() ) {
 399      return gp_locales_by_project_dropdown( null, $name_and_id, $selected_slug, $attrs );
 400  }
 401  
 402  /**
 403   * Returns HTML markup for a select element for projects.
 404   *
 405   * @since 1.0.0
 406   *
 407   * @param string $name_and_id         Name and ID of the select element.
 408   * @param string $selected_project_id The project id to mark as the currently selected.
 409   * @param array  $attrs               Extra attributes.
 410   * @param array  $exclude             An array of locales to exclude from the list.
 411   * @param array  $exclude_no_parent   Exclude the "No Parent" option from the list of locales.
 412   *
 413   * @return string HTML markup for a select element.
 414   */
 415  function gp_projects_dropdown( $name_and_id, $selected_project_id = null, $attrs = array(), $exclude = array(), $exclude_no_parent = false ) {
 416      if ( ! is_array( $exclude ) ) {
 417          $exclude = array( $exclude );
 418      }
 419  
 420      $projects = GP::$project->all();
 421      // TODO: mark which nodes are editable by the current user
 422      $tree = array();
 423      $top = array();
 424      foreach( $projects as $p ) {
 425          $tree[$p->id]['self'] = $p;
 426          if ( $p->parent_project_id ) {
 427              $tree[$p->parent_project_id]['children'][] = $p->id;
 428          } else {
 429              $top[] = $p->id;
 430          }
 431      }
 432  
 433      if ( ! $exclude_no_parent ) {
 434          $options = array( '' => __( '&mdash; No parent &mdash;', 'glotpress' ) );
 435      } else {
 436          $options = array();
 437      }
 438  
 439      foreach( $top as $top_id ) {
 440          $stack = array( $top_id );
 441  
 442          while ( !empty( $stack ) ) {
 443              $id = array_pop( $stack );
 444  
 445              if ( in_array( $id, $exclude ) ) {
 446                  continue;
 447              }
 448  
 449              $tree[$id]['level'] = gp_array_get( $tree[$id], 'level', 0 );
 450              $options[$id] = str_repeat( '-', $tree[$id]['level'] ) . $tree[$id]['self']->name;
 451              foreach( gp_array_get( $tree[$id], 'children', array() ) as $child_id ) {
 452                  $stack[] = $child_id;
 453                  $tree[$child_id]['level'] = $tree[$id]['level'] + 1;
 454              }
 455          }
 456      }
 457  
 458      return gp_select( $name_and_id, $options, $selected_project_id, $attrs );
 459  }
 460  
 461  function gp_array_of_things_to_json( $array ) {
 462      return wp_json_encode( array_map( function( $thing ) { return $thing->fields(); }, $array ) );
 463  }
 464  
 465  function gp_array_of_array_of_things_to_json( $array ) {
 466      $map_to_fields = function( $array ) {
 467          return array_map( function( $thing ) {
 468              return $thing->fields();
 469          }, $array );
 470      };
 471  
 472      return wp_json_encode( array_map( $map_to_fields, $array ) );
 473  }
 474  
 475  function things_to_fields( $data ) {
 476      if( is_array( $data ) ) {
 477          foreach( $data as $item_id => $item ) {
 478              $data[ $item_id ] = things_to_fields( $item );
 479          }
 480      }
 481      else if ( $data instanceof GP_Thing ) {
 482          $data = $data->fields();
 483      }
 484  
 485      return $data;
 486  }
 487  
 488  function gp_preferred_sans_serif_style_tag( $locale ) {
 489      if ( $locale->preferred_sans_serif_font_family ) {
 490          echo <<<HTML
 491      <style type="text/css">
 492          .foreign-text {
 493              font-family: "$locale->preferred_sans_serif_font_family", inherit;
 494          }
 495      </style>
 496  
 497  HTML;
 498      }
 499  }
 500  
 501  function gp_html_excerpt( $str, $count, $ellipsis = '&hellip;') {
 502      $excerpt = trim( wp_html_excerpt( $str, $count ) );
 503      if ( $str != $excerpt ) {
 504          $excerpt .= $ellipsis;
 505      }
 506      return $excerpt;
 507  }
 508  
 509  function gp_checked( $checked ) {
 510      if ( $checked ) {
 511          echo 'checked="checked"';
 512      }
 513  }
 514  
 515  function gp_project_actions( $project, $translation_sets ) {
 516      $actions = array(
 517          gp_link_get( gp_url_project( $project, 'import-originals' ), __( 'Import Originals', 'glotpress' ) ),
 518          gp_link_get( gp_url_project( $project, array( '-permissions' ) ), __( 'Permissions', 'glotpress') ),
 519          gp_link_get( gp_url_project( '', '-new', array('parent_project_id' => $project->id) ), __( 'New Sub-Project', 'glotpress' ) ),
 520          gp_link_get( gp_url( '/sets/-new', array( 'project_id' => $project->id ) ), __( 'New Translation Set', 'glotpress' ) ),
 521          gp_link_get( gp_url_project( $project, array( '-mass-create-sets' ) ), __( 'Mass-create Translation Sets', 'glotpress' ) ),
 522          gp_link_get( gp_url_project( $project, '-branch' ), __( 'Branch project', 'glotpress' ) ),
 523          gp_link_get( gp_url_project( $project, '-delete' ), __( 'Delete project', 'glotpress' ) ),
 524      );
 525  
 526      /**
 527       * Project action links.
 528       *
 529       * @since 1.0.0
 530       *
 531       * @param array      $actions Links as HTML strings.
 532       * @param GP_Project $project The project.
 533       */
 534      $actions = apply_filters( 'gp_project_actions', $actions, $project );
 535  
 536      echo '<ul>';
 537  
 538      foreach( $actions as $action ) {
 539          echo '<li>' . $action . '</li>';
 540      }
 541  
 542      if ( $translation_sets ) {
 543          echo '<li>' . gp_project_options_form( $project ) . '</li>';
 544      }
 545  
 546      echo '</ul>';
 547  }
 548  
 549  function gp_project_options_form( $project ) {
 550      return '
 551              <a href="#" class="personal-options" id="personal-options-toggle"> ' . __( 'Personal project options', 'glotpress' ) . ' &darr;</a>
 552              <div class="personal-options">
 553                  <form action="' . gp_url_project( $project, '-personal' ) . '" method="post">
 554                  <dl>
 555                      <dt><label for="source-url-template">' . __( 'Source file URL', 'glotpress' ) . '</label></dt>
 556                      <dd>
 557                          <input type="text" value="' . esc_html( $project->source_url_template() ) . '" name="source-url-template" id="source-url-template" />
 558                          <small>' . sprintf(
 559                              /* translators: 1: %file%, 2: %line%, 3: https://trac.example.org/browser/%file%#L%line% */
 560                              __( 'URL to a source file in the project. You can use %1$s and %2$s. Ex. %3$s', 'glotpress' ),
 561                              '<code>%file%</code>',
 562                              '<code>%line%</code>',
 563                              '<code>https://trac.example.org/browser/%file%#L%line%</code>'
 564                          ) . '</small>
 565                      </dd>
 566                  </dl>
 567                  <p>
 568                      <input type="submit" name="submit" value="' . esc_attr__( 'Save &rarr;', 'glotpress' ) . '" id="save" />
 569                      <a class="ternary" href="#" onclick="jQuery(\'#personal-options-toggle\').click();return false;">' . __( 'Cancel', 'glotpress' ) . '</a>
 570                  </p>
 571                  ' . gp_route_nonce_field( 'set-personal-options_' . $project->id, false ) . '
 572                  </form>
 573              </div>';
 574  }
 575  
 576  function gp_entry_actions( $seperator = ' &bull; ' ) {
 577      $actions = array(
 578          '<button class="copy" tabindex="-1" title="' . __( 'Copy the original string to the translation area (overwrites existing text).', 'glotpress' ) . '">' . __( 'Copy from original', 'glotpress' ) . '</button> ' .
 579          '<button class="inserttab" tabindex="-1" title="' . __( 'Insert tab (\t) at the current cursor position.', 'glotpress' ) . '">' . __( 'Insert tab', 'glotpress' ) . '</button> ' .
 580          '<button class="insertnl" tabindex="-1" title="' . __( 'Insert newline (\n) at the current cursor position.', 'glotpress' ) . '">' . __( 'Insert newline', 'glotpress' ) . '</button>',
 581      );
 582  
 583      /**
 584       * Filters entry action links.
 585       *
 586       * @since 1.0.0
 587       *
 588       * @param array $actions Links as HTML strings.
 589       */
 590      $actions = apply_filters( 'gp_entry_actions', $actions );
 591  
 592  
 593      echo implode( $seperator, $actions );
 594      /*
 595      <a href="#" class="copy" tabindex="-1"><?php _e( 'Copy from original', 'glotpress' ); ?></a> &bull;
 596      <a href="#" class="gtranslate" tabindex="-1"><?php _e( 'Translation from Google', 'glotpress' ); ?></a>
 597      */
 598  }
 599  
 600  /**
 601   * Generates a list of classes to be added to the translation row, based on translation entry properties.
 602   *
 603   * @since 2.2.0
 604   *
 605   * @param Translation_Entry $translation The translation entry object for the row.
 606   *
 607   * @return array
 608   */
 609  function gp_get_translation_row_classes( $translation ) {
 610      $classes = array();
 611      $classes[] = $translation->translation_status ? 'status-' . $translation->translation_status : 'untranslated';
 612      $classes[] = 'priority-' . gp_array_get( GP::$original->get_static( 'priorities' ), $translation->priority );
 613      $classes[] = $translation->warnings ? 'has-warnings' : 'no-warnings';
 614  
 615      if ( property_exists( $translation, 'root_translation_set_id' ) ) {
 616          $classes[] = $translation->translation_set_id === $translation->root_translation_set_id ? 'root-translation' : '';
 617      }
 618  
 619      /**
 620       * Filters the list of CSS classes for a translation row
 621       *
 622       * @since 2.2.0
 623       *
 624       * @param array             $classes     An array of translation row classes.
 625       * @param Translation_Entry $translation The translation entry object.
 626       */
 627      $classes = apply_filters( 'gp_translation_row_classes', $classes, $translation );
 628  
 629      return $classes;
 630  }
 631  
 632  /**
 633   * Outputs space separated list of classes for the translation row, based on translation entry properties.
 634   *
 635   * @since 2.2.0
 636   *
 637   * @param Translation_Entry $translation The translation entry object for the row.
 638   *
 639   * @return void
 640   */
 641  function gp_translation_row_classes( $translation ) {
 642      $classes = gp_get_translation_row_classes( $translation );
 643      echo esc_attr( implode( ' ', $classes ) );
 644  }


Generated: Sat Aug 17 01:01:56 2019 Cross-referenced by PHPXref 0.7.1