<?php

/**
 * Management of Lockee content display
 */
class Lockee_Content extends Lockee_Singleton
{
  /**
   * Init the content functionnality
   */
  protected function init() {}

  /**
   * Display the lock content in the post
   */
  public function display_content($content)
  {
    global $post;

    if (!$post) {
      return $content;
    }

    $id = $post->ID;
    $lockee_type = get_post_meta($id, 'lockee_type', true);
    $lockee_code = get_post_meta($id, 'lockee_code', true);
    $lockee_content = get_post_meta($id, 'lockee_content', true);

    if (empty($lockee_type) || empty($lockee_code)) {
      return $content;
    }

    $lockee_options = get_post_meta($id, 'lockee_options', true);

    $lock = Lockee_Utils::generateLock('open', $id, $lockee_type, '', $lockee_options);

    if ($post->post_type == 'lockee_lock' || empty($lockee_content)) {
      return $lock;
    }
    return $content . $lock;
  }
}
