/**
  * generate box to save it
  * @return \wtb_seo_box
  */
 public function generateBox()
 {
     $box = new wtb_seo_box();
     for ($int = 1; $int <= 3; $int++) {
         $section = new wtb_seo_box_section($int);
         // keyword
         $section->keyword = '';
         $inputName = $section->getInfoKey('keyword');
         if (!empty($_POST[$inputName])) {
             $section->keyword = trim($_POST[$inputName]);
             $section->density = $this->getFromPostRequest($section->getInfoKey('density'));
             $section->score = $this->getFromPostRequest($section->getInfoKey('score'));
             $section->wdf = $this->getFromPostRequest($section->getInfoKey('wdf'));
             $section->idf = $this->getFromPostRequest($section->getInfoKey('idf'));
             // parameters
             $section->parameters = array();
             $paramsInputName = $section->getInfoKey('checkboxes');
             if (!empty($_POST[$paramsInputName]) and is_array($_POST[$paramsInputName])) {
                 $section->parameters = $_POST[$paramsInputName];
             }
         }
         $box->addSection($section);
     }
     return $box;
 }
 public function getSection($int)
 {
     $section = new wtb_seo_box_section($int);
     $section->keyword = esc_attr($this->getMetaData($section->getInfoKey('keyword')));
     if (empty($section->keyword)) {
         return false;
     }
     $section->density = esc_attr($this->getMetaData($section->getInfoKey('density')));
     $section->score = esc_attr($this->getMetaData($section->getInfoKey('score')));
     $section->wdf = esc_attr($this->getMetaData($section->getInfoKey('wdf')));
     $section->idf = esc_attr($this->getMetaData($section->getInfoKey('idf')));
     $section->parameters = array();
     $params = (array) json_decode($this->getMetaData($section->getInfoKey('checkboxes')));
     if (!is_array($params) or empty($params)) {
         $params = array();
     }
     foreach ($params as $key => $value) {
         $section->parameters[$key] = $value;
     }
     return $section;
 }
 /**
  * calculate section score
  * @param wtb_seo_box_section $section
  * @return float
  */
 protected function calcScore($section)
 {
     $maxAvailable = 0;
     $score = 0;
     // keyword in title 25%
     if ($section->isParamAllowed('title')) {
         $maxAvailable += 25;
         $score += !empty($section->parameters['title']) ? 25 : 0;
     }
     // keyword in H1 21%
     if ($section->isParamAllowed('h1')) {
         $maxAvailable += 21;
         $score += !empty($section->parameters['h1']) ? 21 : 0;
     }
     // keyword in H2 8%
     if ($section->isParamAllowed('h2')) {
         $maxAvailable += 8;
         $score += !empty($section->parameters['h2']) ? 8 : 0;
     }
     // keyword in H3 5%
     if ($section->isParamAllowed('h3')) {
         $maxAvailable += 5;
         $score += !empty($section->parameters['h3']) ? 5 : 0;
     }
     // keyword in bold 3%
     if ($section->isParamAllowed('bold')) {
         $maxAvailable += 3;
         $score += !empty($section->parameters['bold']) ? 3 : 0;
     }
     // keyword in italic 3%
     if ($section->isParamAllowed('italic')) {
         $maxAvailable += 3;
         $score += !empty($section->parameters['italic']) ? 3 : 0;
     }
     // keyword in underline 3%
     if ($section->isParamAllowed('underline')) {
         $maxAvailable += 3;
         $score += !empty($section->parameters['underline']) ? 3 : 0;
     }
     // keyword in alt 2%
     if ($section->isParamAllowed('alt')) {
         $maxAvailable += 2;
         $score += !empty($section->parameters['alt']) ? 2 : 0;
     }
     // keyword desnsity 15%
     $maxAvailable += 15;
     if ($section->density >= $section->perfectDensity * 1.27) {
         $score += 0;
     } else {
         if ($section->density >= $section->perfectDensity * 1.23) {
             $score += 6;
         } else {
             if ($section->density >= $section->perfectDensity * 1.16) {
                 $score += 9;
             } else {
                 if ($section->density >= $section->perfectDensity * 1.1) {
                     $score += 13;
                 } else {
                     if ($section->density > $section->perfectDensity) {
                         $score += 15;
                     } else {
                         if ($section->perfectDensity != 0) {
                             $score += number_format(15 * $section->density / $section->perfectDensity, 2);
                         }
                     }
                 }
             }
         }
     }
     // lenght 15%
     $maxAvailable += 15;
     if ($this->getTotalWordCount() >= $this->idealPostLenght) {
         $score += 15;
     } else {
         if ($this->idealPostLenght != 0) {
             $score += 15 * $this->getTotalWordCount() / $this->idealPostLenght;
         }
     }
     return $score * 100 / $maxAvailable;
 }