Example #1
0
 public function startup()
 {
     $this->data['generator'] = 'harrison ' . AppController::VERSION . ', ephFrame';
     $this->data['contact'] = Registry::get('ContactEmail');
     // iterate over metatags to find @[files] ?
     foreach ($this->data as $key => $value) {
         if (!is_string($value) || !($filename = preg_match_first($value, '/^@(.+)/'))) {
             continue;
         }
         $File = new File($filename);
         if ($File->exists()) {
             $this->data[$key] = $File->toArray();
         } else {
             $this->data[$key] = '';
         }
     }
     return parent::startup();
 }
Example #2
0
 /**
  * 
  * Validate data and update record into 
  * Data Base. If an errors, redirect user to add form
  * and show error message where speaks as not to admit 
  * errors in the future
  * 
  */
 public function update($id = null)
 {
     $id = (int) $id;
     if ($id < 1) {
         redirect('/' . $this->module . '/');
     }
     $target = $this->Model->getById($id);
     if (!$target) {
         redirect('/' . $this->module . '/');
     }
     //turn access
     if (!$this->ACL->turn(array($this->module, 'edit_materials'), false) && (!empty($_SESSION['user']['id']) && $target->getAuthor_id() == $_SESSION['user']['id'] && $this->ACL->turn(array($this->module, 'edit_mine_materials'), false)) === false) {
         return $this->showInfoMessage(__('Permission denied'), '/' . $this->module . '/');
     }
     $errors = $this->Register['Validate']->check($this->Register['action']);
     // Check additional fields if an exists.
     // This must be doing after define $error variable.
     if (is_object($this->AddFields)) {
         try {
             $_addFields = $this->AddFields->checkFields();
         } catch (Exception $e) {
             $errors[] = $this->AddFields->getErrors();
         }
     }
     $fields = array('description', 'tags', 'sourse', 'sourse_email', 'sourse_site');
     $fields_settings = $this->Register['Config']->read('fields', $this->module);
     foreach ($fields as $field) {
         if (empty($_POST[$field]) && in_array($field, $fields_settings)) {
             ${$field} = '';
         } else {
             ${$field} = trim($_POST[$field]);
         }
     }
     // Обрезаем переменные до длины, указанной в параметре maxlength тега input
     $title = trim(mb_substr($_POST['title'], 0, 128));
     $edit = trim($_POST['main_text']);
     $commented = !empty($_POST['commented']) ? 1 : 0;
     $available = !empty($_POST['available']) ? 1 : 0;
     $in_cat = intval($_POST['cats_selector']);
     // Если пользователь хочет посмотреть на сообщение перед отправкой
     if (isset($_POST['viewMessage'])) {
         $_SESSION['viewMessage'] = array_merge(array('title' => null, 'main_text' => null, 'in_cat' => $in_cat, 'description' => null, 'tags' => null, 'sourse' => null, 'sourse_email' => null, 'sourse_site' => null, 'commented' => null, 'available' => null), $_POST);
         redirect('/' . $this->module . '/edit_form/' . $id);
     }
     if (!empty($in_cat)) {
         $catModel = $this->Register['ModManager']->getModelInstance($this->module . 'Categories');
         $category = $catModel->getById($in_cat);
         if (!$category) {
             $errors[] = '<li>' . __('Can not find category') . '</li>' . "\n";
         }
     }
     // Errors
     if (!empty($errors)) {
         $_SESSION['FpsForm'] = array_merge(array('title' => null, 'main_text' => null, 'in_cat' => $in_cat, 'description' => null, 'tags' => null, 'sourse' => null, 'sourse_email' => null, 'sourse_site' => null, 'commented' => null, 'available' => null), $_POST);
         $_SESSION['FpsForm']['errors'] = $errors;
         redirect('/' . $this->module . '/edit_form/' . $id);
     }
     downloadAttaches($this->module, $id);
     if (!$this->ACL->turn(array($this->module, 'record_comments_management'), false)) {
         $commented = '1';
     }
     if (!$this->ACL->turn(array($this->module, 'hide_material'), false)) {
         $available = '1';
     }
     //remove cache
     $this->Cache->clean(CACHE_MATCHING_TAG, array('module_' . $this->module, 'record_id_' . $id));
     $this->DB->cleanSqlCache();
     // Auto tags generation
     if (empty($tags)) {
         $TagGen = new MetaTags();
         $tags = $TagGen->getTags($edit);
         $tags = !empty($tags) && is_array($tags) ? implode(',', array_keys($tags)) : '';
     }
     $max_lenght = $this->Register['Config']->read('max_lenght', $this->module);
     $edit = mb_substr($edit, 0, $max_lenght);
     $data = array('title' => $title, 'main' => $edit, 'category_id' => $in_cat, 'description' => $description, 'tags' => $tags, 'sourse' => $sourse, 'sourse_email' => $sourse_email, 'sourse_site' => $sourse_site, 'commented' => $commented, 'available' => $available);
     $target($data);
     $target->save();
     if (is_object($this->AddFields)) {
         $this->AddFields->save($id, $_addFields);
     }
     if ($this->Log) {
         $this->Log->write('editing ' . $this->module, $this->module . ' id(' . $id . ')');
     }
     return $this->showInfoMessage(__('Operation is successful'), getReferer());
 }
Example #3
0
 private function grabHtml()
 {
     //print_r()
     $this->html = Utils::curl($this->domain);
     if (!$this->html) {
         $this->errorcode = 102;
         return false;
     }
     $m = new MetaTags($this->html);
     $charset = $m->getCharset();
     if (!empty($charset) and strtolower($charset) != 'utf-8') {
         $this->html = iconv($charset, "utf-8//IGNORE", $this->html);
     }
     return true;
 }
Example #4
0
 /**
  * 
  * Validate data and update record into 
  * Data Base. If an errors, redirect user to add form
  * and show error message where speaks as not to admit 
  * errors in the future
  * 
  */
 public function update($id = null)
 {
     $id = (int) $id;
     if ($id < 1) {
         redirect('/' . $this->module . '/');
     }
     $target = $this->Model->getById($id);
     if (!$target) {
         redirect('/' . $this->module . '/');
     }
     //turn access
     if (!$this->ACL->turn(array($this->module, 'edit_materials'), false) && (!empty($_SESSION['user']['id']) && $target->getAuthor_id() == $_SESSION['user']['id'] && $this->ACL->turn(array($this->module, 'edit_mine_materials'), false)) === false) {
         return $this->showInfoMessage(__('Permission denied'), '/' . $this->module . '/');
     }
     $errors = $this->Register['Validate']->check($this->Register['action']);
     // Check additional fields if an exists.
     // This must be doing after define $error variable.
     if (is_object($this->AddFields)) {
         try {
             $_addFields = $this->AddFields->checkFields();
         } catch (Exception $e) {
             $errors[] = $this->AddFields->getErrors();
         }
     }
     $valobj = $this->Register['Validate'];
     $fields = array('description', 'tags', 'sourse', 'sourse_email', 'sourse_site', 'download_url', 'download_url_size');
     $fields_settings = $this->Register['Config']->read('fields', $this->module);
     foreach ($fields as $field) {
         if (empty($_POST[$field]) && in_array($field, $fields_settings)) {
             ${$field} = null;
         } else {
             ${$field} = trim($_POST[$field]);
         }
     }
     // Обрезаем переменные до длины, указанной в параметре maxlength тега input
     $title = trim(mb_substr($_POST['title'], 0, 128));
     $editLoad = trim($_POST['mainText']);
     $in_cat = intval($_POST['cats_selector']);
     $commented = !empty($_POST['commented']) ? 1 : 0;
     $available = !empty($_POST['available']) ? 1 : 0;
     if (!$this->ACL->turn(array($this->module, 'record_comments_management'), false)) {
         $commented = '1';
     }
     if (!$this->ACL->turn(array($this->module, 'hide_material'), false)) {
         $available = '1';
     }
     // Preview
     if (isset($_POST['viewMessage'])) {
         $_SESSION['viewMessage'] = array_merge(array('title' => null, 'mainText' => null, 'in_cat' => $in_cat, 'description' => null, 'tags' => null, 'sourse' => null, 'sourse_email' => null, 'sourse_site' => null, 'download_url' => null, 'download_url_size' => null, 'commented' => null, 'available' => null), $_POST);
         redirect('/' . $this->module . '/edit_form/' . $id);
     }
     if (!empty($in_cat)) {
         $sectionsModel = $this->Register['ModManager']->getModelInstance($this->module . 'Categories');
         $category = $sectionsModel->getById($in_cat);
         if (!$category) {
             $errors[] = __('Can not find category');
         }
     }
     // Delete attached file if an exists and we get flag from editor
     if (!empty($_POST['delete_file']) || !empty($_FILES['attach_file']['name'])) {
         if ($target->getDownload() && file_exists($this->attached_files_path . $target->getDownload())) {
             _unlink($this->attached_files_path . $target->getDownload());
         }
     }
     // Errors
     if (!empty($errors)) {
         $_SESSION['FpsForm'] = array_merge(array('title' => null, 'mainText' => null, 'description' => null, 'tags' => null, 'sourse' => null, 'sourse_email' => null, 'in_cat' => $in_cat, 'sourse_site' => null, 'download_url' => null, 'download_url_size' => null, 'commented' => null, 'available' => null), $_POST);
         $_SESSION['FpsForm']['errors'] = $errors;
         redirect('/' . $this->module . '/edit_form/' . $id);
     }
     //Проверяем прикрепленный файл...
     $file = '';
     if (!empty($_FILES['attach_file']['name'])) {
         $file = $this->__saveFile($_FILES['attach_file']);
     }
     downloadAttaches($this->module, $id);
     // Auto tags generation
     if (empty($tags)) {
         $TagGen = new MetaTags();
         $tags = $TagGen->getTags($editLoad);
         $tags = !empty($tags) && is_array($tags) ? implode(',', array_keys($tags)) : '';
     }
     $max_lenght = Config::read('max_lenght', $this->module);
     $editLoad = mb_substr($editLoad, 0, $max_lenght);
     // Запрос на обновление новости
     $data = array('id' => $id, 'title' => $title, 'main' => $editLoad, 'category_id' => $in_cat, 'description' => $description, 'tags' => $tags, 'sourse' => $sourse, 'sourse_email' => $sourse_email, 'sourse_site' => $sourse_site, 'download_url' => $download_url, 'download_url_size' => $download_url_size, 'commented' => $commented, 'available' => $available);
     if (!empty($file)) {
         $data['download'] = $file;
     }
     $target($data);
     $target->save();
     // Save additional fields if they is active
     if (is_object($this->AddFields)) {
         $this->AddFields->save($id, $_addFields);
     }
     //clear cache
     $this->Cache->clean(CACHE_MATCHING_TAG, array('record_id_' . $id, 'module_' . $this->module));
     $this->DB->cleanSqlCache();
     if ($this->Log) {
         $this->Log->write('editing ' . $this->module, 'ent. id(' . $id . ')');
     }
     return $this->showInfoMessage(__('Operation is successful'), getReferer());
 }