Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
ManageController.php
1 <?php
2 
3 /**
4  * Gentics Portal.Node PHP
5  * Author & Copyright (c) by Gentics Software GmbH
6  * sales@gentics.com
7  * http://www.gentics.com
8  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
9  * You must not use this software without a valid license agreement.
10  *
11  * ManageController used for managing operations with RememberedPages like view, add, delete, share
12  *
13 **/
14 class ManageController extends BaseController
15 {
16  public $layout = false;
17 
18  /**
19  * Remembering page into database
20  * This action performs validations to prevent unautorized access
21  *
22  * @return void
23  **/
24  public function actionAdd($url, $title, $page_id, $additional, $key, $back_to_referer)
25  {
26  $data = array(
27  'url'=> $_GET['url'],
28  'title'=> $_GET['title'],
29  'page_id'=> $_GET['page_id'],
30  'additional' => $_GET['additional'],
31  'back_to_referer' => (boolean) $_GET['back_to_referer'],
32  );
33 
34  if($this->module->sign(serialize($data)) !== $key) {
35  throw new CHttpException(400, 'Invalid key');
36  }
37 
38  $rememberedPage = new RememberedPage();
39  $rememberedPage->collection_id = Yii::app()->getModule('remember')->getUserCollectionId();
40 
41  $rememberedPage->url = $url;
42  $rememberedPage->title = $title;
43  $rememberedPage->page_id = $page_id;
44  $rememberedPage->additional = unserialize($additional);
45 
46  if(!$rememberedPage->save()){
47 
48  throw new CHttpException(400, 'Internal error');
49  }
50  $this->redirect($back_to_referer === 'true' ? Yii::app()->request->getUrlReferrer() : $url);
51  }
52 
53  /**
54  * Action for sharing links by mail
55  *
56  * @var string
57  **/
58  public function actionShareByMail()
59  {
60  $mailForm = new ShareMailForm();
61  if(isset($_POST['ShareMailForm'])){
62  $mailForm->attributes = $_POST['ShareMailForm'];
63  }
64 
65  if($mailForm->validate()) {
66 
67  $mail = new PHPMailer(true);
68  $mail->SetFrom($this->module->shareByMailEmail);
69  $mail->AddAddress($mailForm->email);
70  $mail->Subject = $this->module->shareByMailSubject;
71 
72  $subject = $this->module->shareByMailSubject;
73 
74  $mailurls = array();
75  $mailurls_msg = $mailForm->links;
76  $mailurls_ = explode('<a href="http',$mailForm->links);
77  foreach($mailurls_ as $mailurls__){
78  $end = explode('"',$mailurls__);
79  if (trim($end[0]) != "" && strstr($end[0],$this->module->allowedURL) && !in_array(trim("http".$end[0]), $mailurls)){
80  $mailurls[] = trim("http".$end[0]);
81  }
82  }
83 
84  if (sizeof($mailurls) > 0){
85  $mail->AddStringAttachment($this->actionLoadPdf($mailurls), $this->module->pdfname);
86  }
87 
88  $msg = $this->renderPartial('/mail_templates/share_by_email', array('links'=>$mailurls_msg, 'description' => $mailForm->description), true);
89  $mail->MsgHTML(utf8_decode($msg));
90  $mail->Send();
91  }
92 
93  echo CActiveForm::validate($mailForm);
94  Yii::app()->end();
95  }
96 
97  /**
98  * Action for downloading PDFs
99  *
100  * @var string
101  **/
102  public function actionDownloadPdf()
103  {
104  $mailurls = array();
105  $mailurls_ = explode(' ',Yii::app()->request->getParam("links",""));
106  foreach($mailurls_ as $mailurls__){
107  if (trim($mailurls__) != "" && strstr($mailurls__,$this->module->allowedURL) && !in_array(trim($mailurls__), $mailurls)){
108  $mailurls[] = trim($mailurls__);
109  }
110  }
111  if (sizeof($mailurls) > 0){
112  header("Content-Type: application/pdf");
113  header("Content-disposition: attachment; filename=".$this->module->pdfname);
114  header("Pragma: no-cache");
115  echo $this->actionLoadPdf($mailurls);
116  exit;
117 
118  } else {
119  echo RememberModule::t("Error");
120  }
121  }
122 
123  public function actionLoadPdf($mailurls)
124  {
125  $filename = $this->module->tmpFolder.md5(date(DATE_RFC822).join("",$mailurls)).".pdf";
126  $statement = "wkhtmltopdf-amd64 -n --zoom 1 --page-width 1280px --footer-center \[page\] -T 14mm -B 14mm -L 14mm -R 14mm --disable-external-links --disable-internal-links ".join(" ",$mailurls)." ".$filename;#--disable-smart-shrinking
127  exec($statement);
128  $out = file_get_contents($filename);
129  unlink($filename);
130  return $out;
131  }
132 
133  /**
134  * Deleting single remembered page
135  *
136  * @return void
137  **/
138  public function actionDeletePage()
139  {
140  $id = Yii::app()->request->getQuery('id', '');
141  $isAjax = Yii::app()->request->isAjaxRequest;
142  $collectionId = Yii::app()->getModule('remember')->getUserCollectionId();
143 
144  $ids = explode(",",$id);
145  foreach($ids as $id){
146  $rememberedPage = RememberedPage::model()->findByPk($id);
147 
148  if($rememberedPage && $rememberedPage->collection_id == $collectionId){
149  $rememberedPage->delete();
150  }else{
151  throw new CHttpException(400);
152  }
153  }
154  if(!$isAjax){
155  if(isset($_SERVER['HTTP_REFERER'])){
156  $this->redirect($_SERVER['HTTP_REFERER']);
157  }
158  }else{
159  echo json_encode(array('status'=>'success'));
160  }
161  }
162 }