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  $mailurl = $mailForm->links;
75  if ( strstr($mailurl,$this->module->allowedURL) ) {
76  $mail->AddStringAttachment($this->actionLoadPdf(array($mailurl)), $this->module->pdfname);
77  }
78 
79  $msg = $this->renderPartial('/mail_templates/share_by_email', array('links'=>$mailurl, 'description' => $mailForm->description), true);
80  $mail->MsgHTML(utf8_decode($msg));
81  $mail->Send();
82  }
83 
84  echo CActiveForm::validate($mailForm);
85  Yii::app()->end();
86  }
87 
88  /**
89  * Action for downloading PDFs
90  *
91  * @var string
92  **/
93  public function actionDownloadPdf()
94  {
95  $mailurls = array();
96  $mailurls_ = explode(' ',Yii::app()->request->getParam("links",""));
97  foreach($mailurls_ as $mailurls__){
98  if (trim($mailurls__) != "" && strstr($mailurls__,$this->module->allowedURL) && !in_array(trim($mailurls__), $mailurls)){
99  $mailurls[] = trim($mailurls__);
100  }
101  }
102  if (sizeof($mailurls) > 0){
103  header("Content-Type: application/pdf");
104  header("Content-disposition: attachment; filename=".$this->module->pdfname);
105  header("Pragma: no-cache");
106  echo $this->actionLoadPdf($mailurls);
107  exit;
108 
109  } else {
110  echo RememberModule::t("Error");
111  }
112  }
113 
114  public function actionLoadPdf($mailurls)
115  {
116  $filename = $this->module->tmpFolder.md5(date(DATE_RFC822).join("",$mailurls)).".pdf";
117  $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
118  exec($statement);
119  $out = file_get_contents($filename);
120  unlink($filename);
121  return $out;
122  }
123 
124  /**
125  * Deleting single remembered page
126  *
127  * @return void
128  **/
129  public function actionDeletePage()
130  {
131  $id = Yii::app()->request->getQuery('id', '');
132  $isAjax = Yii::app()->request->isAjaxRequest;
133  $collectionId = Yii::app()->getModule('remember')->getUserCollectionId();
134 
135  $ids = explode(",",$id);
136  foreach($ids as $id){
137  $rememberedPage = RememberedPage::model()->findByPk($id);
138 
139  if($rememberedPage && $rememberedPage->collection_id == $collectionId){
140  $rememberedPage->delete();
141  }else{
142  throw new CHttpException(400);
143  }
144  }
145  if(!$isAjax){
146  if(isset($_SERVER['HTTP_REFERER'])){
147  $this->redirect($_SERVER['HTTP_REFERER']);
148  }
149  }else{
150  echo json_encode(array('status'=>'success'));
151  }
152  }
153 }