1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
<?php
class WebmarksController extends ModulesController {
var $name = 'Webmarks';
var $helpers = array('BeTree', 'BeToolbar');
var $components = array('BeLangText', 'BeFileHandler', 'BeSecurity');
var $uses = array('BEObject', 'Link', 'Tree','Category','Area') ;
protected $moduleName = 'webmarks';
protected $categorizableModels = array('Link');
public function index($id = null, $order = "", $dir = true, $page = 1, $dim = 20) {
$conf = Configure::getInstance() ;
$filter = array(
'object_type_id'=>$conf->objectTypes['link']['id'],
'Link.*'=>"",
'count_annotation' => 'EditorNote'
);
$this->paginatedList($id, @$filter, $order, $dir, $page, $dim);
$this->loadCategories($filter["object_type_id"]);
}
public function view($id = null) {
$this->viewObject($this->Link, $id);
}
public function save() {
$this->checkWriteModulePermission();
$this->data['url'] = $this->Link->checkUrl($this->data['url']);
$conditions = array('url' => $this->data['url']);
if (!empty($this->data["id"])) {
$conditions[] = "Link.id <>" . $this->data["id"];
}
$link = $this->Link->find('all',array('conditions' => $conditions));
if(!empty($link)) {
$this->Link->id = $link[0]['id'];
$this->userWarnMessage(__("webmark already present", true)." - ".$link[0]['id'] . " - " .$link[0]['title']);
$this->setResult("WARN");
return;
}
if(empty($this->data['title'])) {
$this->data['title'] = $this->Link->readHtmlTitle($this->data['url']);
}
$this->Transaction->begin();
$this->saveObject($this->Link);
$this->Transaction->commit();
$this->userInfoMessage(__("webmark saved", true)." - ".$this->data["title"]);
$this->eventInfo("webmark [". $this->data["title"]."] saved");
}
public function delete() {
$this->checkWriteModulePermission();
$objectsListDeleted = $this->deleteObjects("Link");
$this->userInfoMessage(__("News deleted", true) . " - " . $objectsListDeleted);
$this->eventInfo("News $objectsListDeleted deleted");
}
public function deleteSelected() {
$this->checkWriteModulePermission();
$objectsListDeleted = $this->deleteObjects("Link");
$this->userInfoMessage(__("News deleted", true) . " - " . $objectsListDeleted);
$this->eventInfo("News $objectsListDeleted deleted");
}
public function categories() {
$this->showCategories($this->Link);
}
public function checkUrl() {
$this->data = $this->params['form'];
$this->Link->id = $this->params['form']['id'];
$http_code = $this->Link->responseForUrl($this->params['form']['url']);
$http_response_date = date('Y-m-d H:m:s',time());
$saved_url = $this->Link->field("url",array("id" => $this->params['form']['id']));
if($saved_url == $this->params['form']['url']) {
$this->Link->saveField("http_code",$http_code);
$this->Link->saveField("http_response_date",$http_response_date);
}
$this->set("http_code",$http_code);
$this->set("http_response_date",$http_response_date);
$this->layout = null;
}
public function checkMultiUrl() {
$this->doMultiCheck();
}
private function doMultiCheck() {
$objectsToModify = array();
$objectsListDesc = "";
$beObject = ClassRegistry::init("BEObject");
if(!empty($this->params['form']['objects_selected'])) {
$objectsToModify = $this->params['form']['objects_selected'];
$this->Transaction->begin() ;
$modelName = "Link";
foreach ($objectsToModify as $id) {
$model = $this->loadModelByType($modelName);
$model->id = $id;
$link = $model->findById($id);
$date = new DateTime();
if(!$model->saveField("http_code",$model->responseForUrl($link['url'])))
throw new BeditaException(__("Error checking url for link: ", true) . $id);
if(!$model->saveField("http_response_date",$date->format(DATE_RFC3339)))
throw new BeditaException(__("Error checking url for link: ", true) . $id);
$objectsListDesc .= $id . ",";
}
$this->Transaction->commit() ;
}
return trim($objectsListDesc, ",");
}
protected function forward($action, $result) {
$moduleRedirect = array(
'checkMultiUrl' => array(
'OK' => $this->referer(),
'ERROR' => $this->referer()
)
);
return $this->moduleForward($action, $result, $moduleRedirect);
}
}