PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/application/controllers/ContentController.php

https://github.com/tavishvaidya/site
PHP | 1766 lines | 944 code | 290 blank | 532 comment | 170 complexity | 4ff03e0b828b7885123ab7f6340caaf9 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * ContentController -> Viewing content
  4. *
  5. * Copyright (c) <2009>, Joel Peltonen <joel.peltonen@cs.tamk.fi>
  6. * Copyright (c) <2009>, Pekka Piispanen <pekka.piispanen@cs.tamk.fi>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  12. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
  16. * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. * License text found in /license/
  19. */
  20. /**
  21. * ContentController - class
  22. *
  23. * @package controllers
  24. * @author Joel Peltonen & Pekka Piispanen
  25. * @copyright 2009 Joel Peltonen & Pekka Piispanen
  26. * @license GPL v2
  27. * @version 1.0
  28. */
  29. class ContentController extends Oibs_Controller_CustomController
  30. {
  31. /**
  32. * init
  33. *
  34. * Initialization of content controller
  35. *
  36. */
  37. public function init()
  38. {
  39. parent::init();
  40. $ajaxContext = $this->_helper->getHelper('AjaxContext');
  41. $ajaxContext->addActionContext('list', 'xml')->initContext();
  42. $this->baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
  43. $this->view->title = 'content-title';
  44. } // end of init()
  45. /**
  46. * indexAction
  47. *
  48. * Content index -- redicrects user to help/guidelines for adding content
  49. */
  50. public function indexAction()
  51. {
  52. //$this->view->title = "Massidea.org";
  53. //if (!$this->view->authenticated){
  54. $url = $this->_urlHelper->url(array('controller' => 'help',
  55. 'action' => 'guidelines',
  56. 'language' => $this->view->language),
  57. 'lang_default', true);
  58. $this->_redirect($url);
  59. //}
  60. }
  61. /**
  62. * listAction
  63. *
  64. * Lists content by content type.
  65. *
  66. */
  67. public function listAction()
  68. {
  69. $url = $this->_urlHelper->url(array('controller' => 'index',
  70. 'language' => $this->view->language),
  71. 'lang_default', true);
  72. // Get cache from registry
  73. $cache = Zend_Registry::get('cache');
  74. // Set array for content data
  75. $data = array();
  76. // Get requests
  77. $params = $this->getRequest()->getParams();
  78. // Get content type
  79. $cty = isset($params['type']) ? $params['type'] : 'all';
  80. if($cty != "idea" && $cty != "finfo" && $cty != "problem") $this->_redirect($url);
  81. // Get page nummber and items per page
  82. $page = isset($params['page']) ? $params['page'] : 1;
  83. $count = isset($params['count']) ? $params['count'] : 15;
  84. // Get list oreder value
  85. $order = isset($params['order']) ? $params['order'] : 'created';
  86. $ind = isset($params['ind']) ? $params['ind'] : 0;
  87. // Get current language id
  88. // $languages = new Default_Model_Languages();
  89. // $idLngInd = $languages->getLangIdByLangName($this->view->language);
  90. // Get recent content by type
  91. $contentModel = new Default_Model_Content();
  92. $data = $contentModel->listRecent($cty, $page, $count, $order, $this->view->language, $ind);
  93. $results = array();
  94. // gather other content data and insert to results array
  95. if(isset($data[0])) {
  96. $contentHasTagModel = new Default_Model_ContentHasTag();
  97. // $contentRatingsModel = new Default_Model_ContentRatings();
  98. $i = 0;
  99. foreach ($data as $content) {
  100. $results[$i] = $content;
  101. $results[$i]['tags'] = $contentHasTagModel
  102. ->getContentTags($content['id_cnt']);
  103. //$results[$i]['ratingdata'] = $contentRatingsModel
  104. // ->getPercentagesById($content['id_cnt']);
  105. $i++;
  106. }
  107. }
  108. // Get total content count
  109. $contentCount = $contentModel->getContentCountByContentType($cty, $this->view->language);
  110. // Calculate total page count
  111. $pageCount = ceil($contentCount / $count);
  112. // Most viewed content
  113. $mostViewedData = $contentModel->getMostViewedType($cty, $page, $count, 'views', 'en', $ind);
  114. // Get all industries
  115. //$industries = new Default_Model_Industries();
  116. //$this->view->industries = $industries->getNamesAndIdsById($ind, $idLngInd);
  117. // Get industry data by id
  118. //$this->view->industryParent = $industries->getById($ind);
  119. // Load most popular tags from cache
  120. if(!$result = $cache->load('IndexTags')) {
  121. $tagsModel = new Default_Model_Tags();
  122. $tags = $tagsModel->getPopular(20);
  123. /*
  124. // resize tags
  125. foreach ($tags as $k => $tag) {
  126. $size = round(50 + ($tag['count'] * 30));
  127. if ($size > 300) {
  128. $size = 300;
  129. }
  130. $tags[$k]['tag_size'] = $size;
  131. }
  132. */
  133. // Action helper for tags
  134. $tags = $this->_helper->tagsizes->tagCalc($tags);
  135. //Action helper for define is tag running number divisible by two
  136. $tags = $this->_helper->tagsizes->isTagDivisibleByTwo($tags);
  137. // Save most popular tags data to cache
  138. $cache->save($tags, 'IndexTags');
  139. } else {
  140. $tags = $result;
  141. }
  142. // Custom pagination to fix memory error on large amount of data
  143. /*
  144. $paginator = new Zend_View();
  145. $paginator->setScriptPath('../application/views/scripts');
  146. $paginator->pageCount = $pageCount;
  147. $paginator->currentPage = $page;
  148. $paginator->pagesInRange = 10;
  149. */
  150. // Send to view
  151. $this->view->tags = $tags;
  152. //$this->view->contentPaginator = $paginator;
  153. $this->view->contentData = $results;
  154. $this->view->type = $cty;
  155. $this->view->count = $count;
  156. $this->view->page = $page;
  157. $this->view->contentCount = $contentCount;
  158. $this->view->ind = $ind;
  159. $this->view->mostViewedData = $mostViewedData;
  160. // RSS type for the layout
  161. $this->view->rsstype = $cty;
  162. } // end of listAction()
  163. /**
  164. * addAction
  165. *
  166. * Adds new content by content type.
  167. *
  168. */
  169. public function addAction()
  170. {
  171. // Get authentication
  172. $auth = Zend_Auth::getInstance();
  173. // If user has identity
  174. if ($auth->hasIdentity()) {
  175. // Get requests
  176. $params = $this->getRequest()->getParams();
  177. // Get content type
  178. $contentType = isset($params['contenttype']) ? $params['contenttype'] : '';
  179. $relatesToId = isset($params['relatestoid']) ? $params['relatestoid'] : 0;
  180. // Get all content types from the database
  181. $modelContentTypes = new Default_Model_ContentTypes();
  182. //$contentTypes = $modelContentTypes->getAllNamesAndIds();
  183. $validContentType = $modelContentTypes->contentTypeExists($contentType);
  184. /*
  185. // Setting the variable first to be true
  186. $invalidContentType = true;
  187. // If set content type exists in database, invalidContentType
  188. // is set to false
  189. foreach($contentTypes as $cty){
  190. if($contentType == $cty['key_cty']) {
  191. $invalidContentType = false;
  192. }
  193. }
  194. */
  195. // Variable $relatesToId is set to 0, just in case that user is not
  196. // adding idea and there's no relatesto_id set
  197. $content = new Default_Model_Content();
  198. if(!$validContentType) {
  199. $message = 'content-add-contenttype-missing-or-invalid';
  200. $url = $this->_urlHelper->url(array('controller' => 'msg',
  201. 'action' => 'index',
  202. 'language' => $this->view->language),
  203. 'lang_default', true);
  204. $this->flash($message, $url);
  205. } elseif($relatesToId != 0) {
  206. /*if($relatesToId == 0) {
  207. $message = 'content-add-relatesto-id-missing';
  208. $url = $this->_urlHelper->url(array('controller' => 'msg',
  209. 'action' => 'index',
  210. 'language' => $this->view->language),
  211. 'lang_default', true);
  212. $this->flash($message, $url);
  213. } */
  214. // Checking if the content that idea is related to exists
  215. $contentExists = $content->checkIfContentExists($relatesToId);
  216. if(!$contentExists) {
  217. $message = 'content-add-invalid-related-content';
  218. $url = $this->_urlHelper->url(array('controller' => 'msg',
  219. 'action' => 'index',
  220. 'language' => $this->view->language),
  221. 'lang_default', true);
  222. $this->flash($message, $url);
  223. }
  224. }
  225. $this->view->contenttype = $this->view->translate($contentType);
  226. $this->view->short_contenttype = $contentType;
  227. $this->view->relatesToId = $relatesToId;
  228. if($relatesToId != 0) {
  229. $relatesToTypeId = $content->getContentTypeIdByContentId($relatesToId);
  230. $this->view->relatesToType = $modelContentTypes->getTypeById($relatesToTypeId);
  231. $this->view->relatesToHeader = $content->getContentHeaderByContentId($relatesToId);
  232. }
  233. // Content type id is needed when adding content to database
  234. $contentTypeId = $modelContentTypes->getIdByType($contentType);
  235. // Cacheing of formData
  236. $cache = Zend_Registry::get('cache');
  237. $formDataCacheTag = 'formData_'.$contentType.'_'.$this->view->language;
  238. if (!($formData = $cache->load($formDataCacheTag) ) || $relatesToId != 0 || true) {
  239. // Creating array for form data
  240. $formData = array();
  241. // Adding data to formData
  242. $formData['content_type'] = $contentTypeId;
  243. $formData['content_relatesto_id'] = $relatesToId;
  244. // Content classifications
  245. $modelFutureinfoClasses = new Default_Model_FutureinfoClasses();
  246. $futureinfoClasses = $modelFutureinfoClasses->getAllNamesAndIds();
  247. $formData['FutureinfoClasses'] = array();
  248. $formData['FutureinfoClasses'][0] = $this->view->translate("content-add-select-finfo-classification");
  249. foreach($futureinfoClasses as $fic) {
  250. $formData['FutureinfoClasses'][$fic['id_fic']] = $fic['name_fic'];
  251. } // end foreach
  252. if(empty($formData['FutureinfoClasses'])) {
  253. $formData['FutureinfoClasses'] = array(0 => '----');
  254. }
  255. $modelInnovationTypes = new Default_Model_InnovationTypes();
  256. $innovationTypes = $modelInnovationTypes->getAllNamesAndIds();
  257. $formData['InnovationTypes'] = array();
  258. $formData['InnovationTypes'][0] =
  259. $this->view->translate("content-add-select-innovation");
  260. foreach($innovationTypes as $ivt) {
  261. $formData['InnovationTypes'][$ivt['id_ivt']] =
  262. $ivt['name_ivt'];
  263. } // end foreach
  264. if(empty($formData['InnovationTypes'])) {
  265. $formData['InnovationTypes'] = array(0 => '----');
  266. }
  267. $languages = New Default_Model_Languages();
  268. $idLngInd = $languages->getLangIdByLangName($this->view->language);
  269. $allLanguages = $languages->getAllNamesAndIds();
  270. $formData['languages'] = array();
  271. $formData['languages'][0] = $this->view->translate("content-add-select-language");
  272. foreach($allLanguages as $lng) {
  273. $formData['languages'][$lng['id_lng']] = $lng['name_lng'];
  274. }
  275. $modelIndustries = new Default_Model_Industries();
  276. $industries = $modelIndustries->getNamesAndIdsById(0, $idLngInd);
  277. $formData['Industries'] = array();
  278. $formData['Industries'][0] =
  279. $this->view->translate("content-add-select-industry");
  280. foreach($industries as $ind) {
  281. $formData['Industries'][$ind['id_ind']] = $ind['name_ind'];
  282. } // end foreach
  283. if(empty($formData['Industries'])) {
  284. $formData['Industries'] = array(0 => '----');
  285. }
  286. // The id of first industry listed is needed when listing the
  287. // divisions for the first time
  288. $firstIndustryId = $modelIndustries->getIndustryId();
  289. $divisions = $modelIndustries->getNamesAndIdsById(
  290. $firstIndustryId, $idLngInd
  291. );
  292. $formData['Divisions'] = array();
  293. $formData['Divisions'][0] = $this->view->translate("content-add-select-division-no-industry");
  294. $formData['Groups'] = array();
  295. $formData['Groups'][0] = $this->view->translate("content-add-select-group-no-division");
  296. $formData['Classes'] = array();
  297. $formData['Classes'][0] = $this->view->translate("content-add-select-class-no-group");
  298. $cache->save($formData, $formDataCacheTag);
  299. }
  300. $formCacheTag = 'form_'.$contentType.'_'.$this->view->language;
  301. // Form for content adding, cacheing if not cached.
  302. // Generate new form if is post because cache will save post parameters and fail
  303. if ($this->getRequest()->isPost()) {
  304. $form = new Default_Form_AddContentForm(null, $formData, $this->view->language, $contentType);
  305. }
  306. elseif (!($form = $cache->load($formCacheTag)) ) {
  307. $form = new Default_Form_AddContentForm(null, $formData, $this->view->language, $contentType);
  308. $cache->save($form, $formCacheTag);
  309. }
  310. $this->view->form = $form;
  311. // Get requests
  312. if($this->getRequest()->isPost()) {
  313. // Get content data
  314. $data = $this->getRequest()->getPost();
  315. // If form data is valid, handle database insertions
  316. $validForm = $form->isValid($data) ? true : (isset($data['content_save']) && $data['content_save'] != '');
  317. if ($validForm) {
  318. // If form data is going to be published
  319. if(isset($data['content_publish']) && $data['content_publish'] != '') {
  320. $data['publish'] = 1;
  321. $message_error = 'content-publish-not-successful';
  322. }
  323. // If form data is going to be saved
  324. elseif(isset($data['content_save']) && $data['content_save'] != '') {
  325. $data['publish'] = 0;
  326. $message_error = 'content-save-not-successful';
  327. }
  328. // Content keywords
  329. /* FIXED: split() is deprecated in PHP 5.3.0 -> and removed in
  330. * PHP 6.0, so changed to explode(). Also trim(array) doesn't
  331. * trim array values, so this is done with foreach now.
  332. */
  333. $keywords = array();
  334. foreach(explode(',', $data['content_keywords']) as $keyword) {
  335. if(trim($keyword) != "") {
  336. $keywords[] = strip_tags(trim($keyword));
  337. }
  338. }
  339. $data['content_keywords'] = array_unique($keywords);
  340. // Related companies
  341. $relatedCompanies = array();
  342. foreach(explode(',', $data['content_related_companies']) as $relatedCompany) {
  343. if(trim($relatedCompany) != "") {
  344. $relatedCompanies[] = strip_tags(trim($relatedCompany));
  345. }
  346. }
  347. $data['content_related_companies'] = array_unique($relatedCompanies);
  348. // Get user id
  349. $data['User']['id_usr'] = $auth->getIdentity()->user_id;
  350. if($data['content_division'] == 0) {
  351. $data['content_industry_id'] = $data['content_industry'];
  352. } elseif($data['content_group'] == 0) {
  353. $data['content_industry_id'] = $data['content_division'];
  354. } elseif($data['content_class'] == 0) {
  355. $data['content_industry_id'] = $data['content_group'];
  356. } elseif($data['content_class'] != 0) {
  357. $data['content_industry_id'] = $data['content_class'];
  358. }
  359. $languages = new Default_Model_Languages();
  360. if($data['content_language'] == 0) {
  361. $data['content_language'] = $this->view->language;
  362. }
  363. else {
  364. $data['content_language'] = $languages->getLangNameByLangId($data['content_language']);
  365. }
  366. $data['files'] = $_FILES['content_file_upload'];
  367. // Add a new content
  368. $content = new Default_Model_Content();
  369. $add = $content->addContent($data);
  370. if(!$add) {
  371. $add_successful = false;
  372. } else {
  373. $add_successful = true;
  374. } // end if
  375. $url = $this->_urlHelper->url(array('controller' => 'msg',
  376. 'action' => 'index',
  377. 'language' => $this->view->language),
  378. 'lang_default', true);
  379. if($add_successful) {
  380. // Get cache from registry
  381. $cache = Zend_Registry::get('cache');
  382. // Load most popular tags from cache
  383. $output = md5(time());
  384. $cache->save($output, 'LatestPostHash');
  385. // Force refresh to tags on front page
  386. $cache->remove('IndexTags');
  387. if($data['publish'] == 1) {
  388. $url = $this->_urlHelper->url(array('content_id' => $add,
  389. 'language' => $this->view->language),
  390. 'content_shortview', true);
  391. $this->_redirect($url);
  392. }
  393. else {
  394. /*$userpage = $this->_urlHelper->url(array('controller' => 'account',
  395. 'action' => 'view',
  396. 'user' => $auth->getIdentity()->username,
  397. 'language' => $this->view->language),
  398. 'lang_default', true);
  399. $savedTab = $this->_urlHelper->url(array('controller' => 'account',
  400. 'action' => 'view',
  401. 'user' => $auth->getIdentity()->username,
  402. 'type' => 'saved',
  403. 'language' => $this->view->language),
  404. 'lang_default', true);
  405. $message_ok = $this->view->translate('content-save-successful');
  406. $message_ok .= ' ('.$content->getContentHeaderByContentId($add).')';
  407. $message_ok .= '<br /><br />' . $this->view->translate('content-save-successful2');
  408. $message_ok .= ' <a href="'.$userpage.'">'.$this->view->translate('content-save-successful3').'</a>';
  409. $message_ok .= ' ' . $this->view->translate('content-save-successful4');
  410. $message_ok .= ' <a href="'.$savedTab.'">'.$this->view->translate('content-save-successful5').'</a>.';
  411. $this->flash($message_ok, $url);*/
  412. $url = $this->_urlHelper->url(array('controller' => 'account',
  413. 'action' => 'view',
  414. 'language' => $this->view->language,
  415. 'user' => $auth->getIdentity()->username),
  416. 'lang_default', true);
  417. $this->_redirect($url);
  418. }
  419. }
  420. else {
  421. $this->flash($message_error, $url);
  422. }
  423. }
  424. } // end if
  425. } else {
  426. // If not logged, redirecting to system message page
  427. $message = 'content-add-not-logged';
  428. $url = $this->_urlHelper->url(array('controller' => 'msg',
  429. 'action' => 'index',
  430. 'language' => $this->view->language),
  431. 'lang_default', true);
  432. $this->flash($message, $url);
  433. } // end if
  434. } // end of addAction()
  435. /**
  436. * makelinksAction
  437. *
  438. * Make content link to content.
  439. *
  440. */
  441. public function makelinksAction() {
  442. // Get authentication
  443. $auth = Zend_Auth::getInstance();
  444. $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) .
  445. '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl();
  446. // If user has identity
  447. if ($auth->hasIdentity())
  448. {
  449. // Get requests
  450. $params = $this->getRequest()->getParams();
  451. // Get content type
  452. $contenttype = isset($params['contenttype']) ? $params['contenttype'] : '';
  453. $relatestoid = isset($params['parentid']) ? $params['parentid'] : '';
  454. $linkedcontentid = isset($params['childid']) ? $params['childid'] : '';
  455. if($this->validateLinking($contenttype, $relatestoid, $linkedcontentid)) {
  456. $model_cnt_has_cnt = new Default_Model_ContentHasContent();
  457. $model_cnt_has_cnt->addContentToContent($relatestoid, $linkedcontentid);
  458. // Send email to owner of content about a new link
  459. // if user allows linking notifications
  460. $userModel = new Default_Model_User();
  461. $owner = $userModel->getContentOwner($relatestoid);
  462. $notificationsModel = new Default_Model_Notifications();
  463. $notifications = $notificationsModel->getNotificationsById($owner['id_usr']);
  464. if (in_array('link', $notifications)) {
  465. $cntModel = new Default_Model_Content();
  466. $originalHeader = $cntModel->getContentHeaderByContentId($relatestoid);
  467. $linkedHeader = $cntModel->getContentHeaderByContentId($linkedcontentid);
  468. $senderId = $auth->getIdentity()->user_id;
  469. $senderName = $auth->getIdentity()->username;
  470. $emailNotification = new Oibs_Controller_Plugin_Email();
  471. $emailNotification->setNotificationType('link')
  472. ->setSenderId($auth->getIdentity()->user_id)
  473. ->setReceiverId($owner['id_usr'])
  474. ->setParameter('URL', $absoluteBaseUrl."/en")
  475. ->setParameter('SENDER-NAME', $senderName)
  476. ->setParameter('LINKED-ID', $linkedcontentid)
  477. ->setParameter('LINKED-TITLE', $linkedHeader)
  478. ->setParameter('ORIGINAL-ID', $relatestoid)
  479. ->setParameter('ORIGINAL-TITLE', $originalHeader);
  480. if ($emailNotification->isValid()) {
  481. $emailNotification->send();
  482. } else {
  483. //echo $emailNotification->getErrorMessage(); die;
  484. }
  485. }
  486. $url = $this->_urlHelper->url(array('controller' => 'view',
  487. 'action' => $relatestoid,
  488. 'language' => $this->view->language),
  489. 'lang_default', true);
  490. $message = "content-linked-successfully";
  491. $this->flash($message, $url);
  492. }
  493. }
  494. else {
  495. // If not logged, redirecting to system message page
  496. $message = 'content-link-not-logged';
  497. $url = $this->_urlHelper->url(array('controller' => 'msg',
  498. 'action' => 'index',
  499. 'language' => $this->view->language),
  500. 'lang_default', true);
  501. $this->flash($message, $url);
  502. }
  503. }
  504. /**
  505. * removelinksAction
  506. *
  507. * Remove content link from content.
  508. *
  509. * @author Mikko Korpinen
  510. */
  511. public function removelinksAction() {
  512. // Get authentication
  513. $auth = Zend_Auth::getInstance();
  514. // If user has identity
  515. if ($auth->hasIdentity())
  516. {
  517. // Get requests
  518. $params = $this->getRequest()->getParams();
  519. // Get content type
  520. $contenttype = isset($params['contenttype'])
  521. ? $params['contenttype'] : '';
  522. $relatestoid = isset($params['parentid'])
  523. ? $params['parentid'] : '';
  524. $linkedcontentid = isset($params['childid'])
  525. ? $params['childid'] : '';
  526. $id_usr = $auth->getIdentity()->user_id;
  527. $model_content = new Default_Model_Content();
  528. $isOwner = $model_content->checkIfUserIsOwner($relatestoid,$id_usr);
  529. if($isOwner) {
  530. $model_cnt_has_cnt = new Default_Model_ContentHasContent();
  531. $model_cnt_has_cnt->removeContentFromContent($relatestoid, $linkedcontentid);
  532. }
  533. //$message = 'content-unlink-successful';
  534. // TODO:
  535. // Tell the user that the unlink was created.
  536. // Redirect back to the user page
  537. $redirectUrl = $this->_urlHelper->url(array('controller' => 'content',
  538. 'action' => 'unlink',
  539. 'relatestoid' => $relatestoid,
  540. 'language' => $this->view->language),
  541. 'unlinkcontent', true);
  542. $this->_redirector->gotoUrl($redirectUrl);
  543. /*
  544. $url = $this->_urlHelper->url(array('controller' => 'msg',
  545. 'action' => 'index',
  546. 'language' => $this->view->language),
  547. 'lang_default', true);
  548. $this->flash($message, $url); */
  549. } else {
  550. // If not logged, redirecting to system message page
  551. $message = 'content-link-not-logged';
  552. $url = $this->_urlHelper->url(array('controller' => 'msg',
  553. 'action' => 'index',
  554. 'language' => $this->view->language),
  555. 'lang_default', true);
  556. $this->flash($message, $url);
  557. }
  558. }
  559. /**
  560. * linkAction
  561. *
  562. * Get user contents which are related to particular content type
  563. *
  564. * @author ???
  565. * @author 2010 Mikko Korpinen
  566. *
  567. */
  568. public function linkAction() {
  569. // Get authentication
  570. $auth = Zend_Auth::getInstance();
  571. // If user has identity
  572. if ($auth->hasIdentity())
  573. {
  574. // Get requests
  575. $params = $this->getRequest()->getParams();
  576. // Get content type
  577. $contenttype = isset($params['contenttype']) ? $params['contenttype'] : '';
  578. $relatestoid = isset($params['relatestoid']) ? $params['relatestoid'] : '';
  579. if($this->validateLinking($contenttype, $relatestoid, -1)) {
  580. $model_content_types = new Default_Model_ContentTypes();
  581. $model_cnt_has_cnt = new Default_Model_ContentHasContent();
  582. $id_usr = $auth->getIdentity()->user_id;
  583. $id_cty = $model_content_types->getIdByType($contenttype);
  584. $userModel = new Default_Model_User();
  585. $userContents = $userModel->getUserContent($id_usr);
  586. $contents = array();
  587. // If user have not this types content then set false
  588. $hasUserContents = true;
  589. if(!$this->checkIfArrayHasKeyWithValue($userContents, "id_cty_cnt", $id_cty)) {
  590. $this->view->linkingContentType = $contenttype;
  591. $hasUserContents = false;
  592. } else {
  593. foreach($userContents as $content) {
  594. if(!$model_cnt_has_cnt->checkIfContentHasContent($relatestoid, $content['id_cnt']) &&
  595. !$model_cnt_has_cnt->checkIfContentHasContent($content['id_cnt'], $relatestoid)) {
  596. if($content['id_cty_cnt'] == $id_cty && $content['id_cnt'] != $relatestoid) {
  597. $contents[] = $content;
  598. }
  599. }
  600. }
  601. $this->view->relatesToId = $relatestoid;
  602. $this->view->linkingContentType = $contenttype;
  603. $this->view->contents = $contents;
  604. $this->view->hasUserContents = $hasUserContents;
  605. }
  606. }
  607. } else {
  608. // If not logged, redirecting to system message page
  609. $message = 'content-link-not-logged';
  610. $url = $this->_urlHelper->url(array('controller' => 'msg',
  611. 'action' => 'index',
  612. 'language' => $this->view->language),
  613. 'lang_default', true);
  614. $this->flash($message, $url);
  615. }
  616. }
  617. /**
  618. * unlinkAction
  619. *
  620. * Get user contents which are related to particular content
  621. *
  622. * @author 2010 Mikko Korpinen
  623. *
  624. */
  625. public function unlinkAction() {
  626. // Get authentication
  627. $auth = Zend_Auth::getInstance();
  628. // If user has identity
  629. if ($auth->hasIdentity())
  630. {
  631. // Get requests
  632. $params = $this->getRequest()->getParams();
  633. $relatestoid = isset($params['relatestoid'])
  634. ? $params['relatestoid'] : '';
  635. $id_usr = $auth->getIdentity()->user_id;
  636. $contenttype = '';
  637. $contents = array();
  638. $model_content = new Default_Model_Content();
  639. $contentexists = $model_content->checkIfContentExists($relatestoid);
  640. $isOwner = $model_content->checkIfUserIsOwner($relatestoid,$id_usr);
  641. if ($contentexists && $isOwner) {
  642. $relatesToContent = $model_content->getDataAsSimpleArray($relatestoid);
  643. $this->view->relatesToContentTitle = $relatesToContent['title_cnt'];
  644. $model_content_types = new Default_Model_ContentTypes();
  645. $model_cnt_has_cnt = new Default_Model_ContentHasContent();
  646. $contenttype = $model_content_types->getTypeById($relatesToContent['id_cty_cnt']);
  647. $contentContents = $model_cnt_has_cnt->getContentContents($relatestoid);
  648. }
  649. if(!$isOwner) $contentexists = false;
  650. $this->view->contentexists = $contentexists;
  651. $this->view->relatesToId = $relatestoid;
  652. $this->view->linkingContentType = $contenttype;
  653. $this->view->contents = $contentContents;
  654. } else {
  655. // If not logged, redirecting to system message page
  656. $message = 'content-link-not-logged';
  657. $url = $this->_urlHelper->url(array('controller' => 'msg',
  658. 'action' => 'index',
  659. 'language' => $this->view->language),
  660. 'lang_default', true);
  661. $this->flash($message, $url);
  662. }
  663. }
  664. /**
  665. * This function validates linking before linking is made
  666. *
  667. */
  668. public function validateLinking($contenttype, $relatestoid, $linkedcontentid = -1) {
  669. // Get all content types from the database
  670. $model_content_types = new Default_Model_ContentTypes();
  671. $model_content = new Default_Model_Content();
  672. $model_cnt_has_usr = new Default_Model_ContentHasUser();
  673. $model_cnt_has_cnt = new Default_Model_ContentHasContent();
  674. $content_types = $model_content_types->getAllNamesAndIds();
  675. // Setting the variable first to be true
  676. $invalid_contenttype = true;
  677. // If set content type exists in database, invalid_contenttype
  678. // is set to false
  679. foreach($content_types as $cty){
  680. if($contenttype == $cty['key_cty']) {
  681. $invalid_contenttype = false;
  682. }
  683. }
  684. // Setting the variable first to be true
  685. $invalid_relatestoid = true;
  686. // If related content exists in the database, invalid_relatestoid
  687. // is set to false
  688. if($model_content->checkIfContentExists($relatestoid)) {
  689. $invalid_relatestoid = false;
  690. $relatesToContent = $model_content->getDataAsSimpleArray($relatestoid);
  691. $this->view->relatesToContentTitle = $relatesToContent['title_cnt'];
  692. $this->view->relatesToContentTitle = $relatesToContent['title_cnt'];
  693. $this->view->relatesToContentContentType = $model_content_types->getTypeById($relatesToContent['id_cty_cnt']);
  694. }
  695. if(!$invalid_contenttype && !$invalid_relatestoid) {
  696. if($linkedcontentid == -1) {
  697. return true;
  698. } else {
  699. $linkedContent = $model_content->getContentRow($linkedcontentid);
  700. if($linkedContent['published_cnt'] != 0) {
  701. if($model_content->checkIfContentExists($linkedcontentid)) {
  702. // User can not link content with themselves
  703. if ($relatestoid == $linkedcontentid) {
  704. $message = 'content-link-themselves';
  705. $url = $this->_urlHelper->url(array('controller' => 'msg',
  706. 'action' => 'index',
  707. 'language' => $this->view->language),
  708. 'lang_default', true);
  709. $this->flash($message, $url);
  710. }
  711. $auth = Zend_Auth::getInstance();
  712. $id_usr = $auth->getIdentity()->user_id;
  713. // If user owns the content that is going to be linked, returning true
  714. if($model_cnt_has_usr->contentHasOwner($id_usr, $linkedcontentid)) {
  715. return true;
  716. } else {
  717. $message = 'content-link-not-content-owner';
  718. $url = $this->_urlHelper->url(array('controller' => 'msg',
  719. 'action' => 'index',
  720. 'language' => $this->view->language),
  721. 'lang_default', true);
  722. $this->flash($message, $url);
  723. }
  724. } else {
  725. $message = 'content-link-linked-content-not-exist';
  726. $url = $this->_urlHelper->url(array('controller' => 'msg',
  727. 'action' => 'index',
  728. 'language' => $this->view->language),
  729. 'lang_default', true);
  730. $this->flash($message, $url);
  731. }
  732. } else {
  733. $message = 'content-link-not-published';
  734. $url = $this->_urlHelper->url(array('controller' => 'msg',
  735. 'action' => 'index',
  736. 'language' => $this->view->language),
  737. 'lang_default', true);
  738. $this->flash($message, $url);
  739. }
  740. }
  741. } else {
  742. if($invalid_contenttype) {
  743. $message = 'content-link-invalid-contenttype';
  744. $url = $this->_urlHelper->url(array('controller' => 'msg',
  745. 'action' => 'index',
  746. 'language' => $this->view->language),
  747. 'lang_default', true);
  748. $this->flash($message, $url);
  749. } elseif($invalid_relatestoid) {
  750. $message = 'content-link-invalid-relatestoid';
  751. $url = $this->_urlHelper->url(array('controller' => 'msg',
  752. 'action' => 'index',
  753. 'language' => $this->view->language),
  754. 'lang_default', true);
  755. $this->flash($message, $url);
  756. }
  757. }
  758. }
  759. public function previewAction()
  760. {
  761. // Get authentication
  762. $auth = Zend_Auth::getInstance();
  763. // Disable layout to be rendered
  764. $this->_helper->layout->disableLayout();
  765. // If user has authenticated
  766. if($auth->hasIdentity())
  767. {
  768. // Get user data
  769. $userId = $auth->getIdentity()->user_id;
  770. $userName = $auth->getIdentity()->username;
  771. $userModel = new Default_Model_User();
  772. $userData = $userModel->getSimpleUserDataById($userId);
  773. // Get requests
  774. if($this->getRequest()->isPost())
  775. {
  776. // Get POST data and convert it to UTF-8 compatible html entities
  777. $rawpostData = $this->getRequest()->getPost();
  778. foreach($rawpostData as $key => $value)
  779. $postData[$key] = htmlentities($value, ENT_QUOTES, "UTF-8");
  780. // Set today's date and time
  781. $today = date('Y-m-d H:i:m');
  782. // Get content type of the specific content viewed
  783. $contentTypesModel = New Default_Model_ContentTypes();
  784. $contentType = $contentTypesModel->getTypeById($postData['content_type']);
  785. // Reformat preview data
  786. $contentData =
  787. array('id_cnt' => 'preview',
  788. 'id_cty_cnt' => $postData['content_type'],
  789. 'title_cnt' => (isset($postData['content_header'])) ? $postData['content_header'] : '',
  790. 'lead_cnt' => (isset($postData['content_textlead'])) ? $postData['content_textlead'] : '',
  791. 'language_cnt' => (isset($postData['content_language'])) ? $postData['content_language'] : '',
  792. 'body_cnt' => (isset($postData['content_text'])) ? $postData['content_text'] : '',
  793. 'research_question_cnt' => (isset($postData['content_research'])) ? $postData['content_research'] : '',
  794. 'opportunity_cnt' => (isset($postData['content_opportunity'])) ? $postData['content_opportunity'] : '',
  795. 'threat_cnt' => (isset($postData['content_threat'])) ? $postData['content_threat'] : '',
  796. 'solution_cnt' => (isset($postData['content_solution'])) ? $postData['content_solution'] : '',
  797. 'references_cnt' => (isset($postData['content_references'])) ? $postData['content_references'] : '',
  798. 'views_cnt' => 0,
  799. 'published_cnt' => 1,
  800. 'created_cnt' => $today,
  801. 'modified_cnt' => $today,
  802. 'id_usr' => $userId,
  803. 'login_name_usr' => $userName,
  804. 'key_cty' => $postData['content_type'],
  805. 'name_cty' => $contentType
  806. );
  807. // Reformat tags
  808. $rawtags = explode(",", $postData['content_keywords']);
  809. $tags = null;
  810. foreach($rawtags as $rawtag)
  811. $tags[count($tags)]['name_tag'] = $rawtag;
  812. // Get form
  813. $form = new Default_Form_PreviewContentForm();
  814. // Inject previewdata to view
  815. $this->view->previewMode = 1;
  816. $this->view->files = null;
  817. $this->view->id = 'preview';
  818. //$this->view->industries = $industries;
  819. //$this->view->userImage = $userImage;
  820. //$this->view->commentPaginator = $paginator;
  821. //$this->view->commentData = $commentsSorted;
  822. //$this->view->user_can_comment = $user_can_comment;
  823. $this->view->contentData = $contentData;
  824. //$this->view->modified = $contentData['modified_cnt'];
  825. $this->view->userData = $userData;
  826. //$this->view->moreFromUser = $moreFromUser;
  827. $this->view->views = $contentData['views_cnt'];
  828. //$this->view->rating = $rating;
  829. $this->view->tags = $tags;
  830. //$this->view->links = $links;
  831. //$this->view->parents = $parents;
  832. //$this->view->parent_siblings = $parent_siblings;
  833. //$this->view->children = $children;
  834. //$this->view->children_siblings = $children_siblings;
  835. //$this->view->rivals = $rivals;
  836. //$this->view->comments = $commentCount;
  837. $this->view->contentType = $contentType;
  838. //$this->view->count = $count;
  839. $this->view->form = $form;
  840. //$this->view->favourite = $favourite;
  841. // Inject title to view
  842. $this->view->title = $this->view->translate('index-home') . " - " . $contentData['title_cnt'];
  843. }
  844. }
  845. else
  846. {
  847. $message = 'content-preview-not-logged-in';
  848. $url = $this->_urlHelper->url(array('controller' => 'msg',
  849. 'action' => 'index',
  850. 'language' => $this->view->language),
  851. 'lang_default', true);
  852. $this->flash($message, $url);
  853. }
  854. }
  855. /**
  856. * editAction
  857. *
  858. * Edit content
  859. *
  860. */
  861. public function editAction()
  862. {
  863. // Get authentication
  864. $auth = Zend_Auth::getInstance();
  865. // If user has identity
  866. if ($auth->hasIdentity()) {
  867. // Get requests
  868. $params = $this->getRequest()->getParams();
  869. // Get session data
  870. $previewSession = new Zend_Session_Namespace('contentpreview');
  871. // If preview
  872. $backFromPreview = isset($previewSession->backFromPreview) ? $previewSession->backFromPreview : 0;
  873. $preview = isset($params['preview']) ? 1:0;
  874. if($preview)
  875. {
  876. $previewSession->unsetAll();
  877. $previewSession->previewData = $params;
  878. $backToUrl = $this->getRequest()->getRequestUri();
  879. $previewSession->backToUrl = $backToUrl;
  880. $url = $this->_urlHelper->url(array('controller' => 'content',
  881. 'action' => 'preview',
  882. 'language' => $this->view->language),
  883. 'lang_default', true);
  884. $this->_redirect($url);
  885. }
  886. // Get content type
  887. $contentId = isset($params['content_id'])
  888. ? $params['content_id'] : 0;
  889. $userId = $auth->getIdentity()->user_id;
  890. $cntHasUsr = New Default_Model_ContentHasUser();
  891. $userIsOwner = $cntHasUsr->contentHasOwner($userId, $contentId);
  892. if($userIsOwner) {
  893. if($contentId != 0) {
  894. $content = New Default_Model_Content();
  895. $data = $content->getDataAsSimpleArray($contentId);
  896. // Creating array for form data
  897. $formData = array();
  898. // Adding content type to form
  899. $formData['content_type'] = $data['id_cty_cnt'];
  900. // Adding content id to form
  901. $formData['content_id'] = $contentId;
  902. $formData['content_header'] = stripslashes($data['title_cnt']);
  903. $modelCntHasTag = New Default_Model_ContentHasTag();
  904. $keywords = $modelCntHasTag->getContentTags($data['id_cnt']);
  905. $tags = "";
  906. $tagCount = count($keywords);
  907. for($i = 0; $i < $tagCount; $i++) {
  908. $tags .= $keywords[$i]['name_tag'];
  909. if ($i != $tagCount - 1) {
  910. $tags .= ', ';
  911. }
  912. }
  913. $formData['content_keywords'] = stripslashes($tags);
  914. $formData['content_textlead'] = stripslashes($data['lead_cnt']);
  915. $formData['content_text'] = stripslashes($data['body_cnt']);
  916. $modelCntHasRec = New Default_Model_ContentHasRelatedCompany();
  917. $relComps = $modelCntHasRec->getContentRelComps($data['id_cnt']);
  918. $recs = "";
  919. $recCount = count($relComps);
  920. for($i = 0; $i < $recCount; $i++) {
  921. $recs .= $relComps[$i]['name_rec'];
  922. if ($i != $recCount - 1) {
  923. $recs .= ', ';
  924. }
  925. }
  926. $formData['content_related_companies'] = stripslashes($recs);
  927. $formData['content_research'] = $data['research_question_cnt'];
  928. $formData['content_opportunity'] = $data['opportunity_cnt'];
  929. $formData['content_threat'] = $data['threat_cnt'];
  930. $formData['content_solution'] = $data['solution_cnt'];
  931. $formData['published_cnt'] = $data['published_cnt'];
  932. $formData['content_references'] = $data['references_cnt'];
  933. $languages = New Default_Model_Languages();
  934. $idLngInd = $languages->getLangIdByLangName($this->view->language);
  935. $allLanguages = $languages->getAllNamesAndIds();
  936. $formData['languages'] = array();
  937. $formData['languages'][0] = $this->view->translate("content-add-select-language");
  938. foreach($allLanguages as $lng) {
  939. $formData['languages'][$lng['id_lng']] = $lng['name_lng'];
  940. }
  941. $finfoClasses = new Default_Model_FutureinfoClasses();
  942. $allClasses = $finfoClasses->getAllNamesAndIds();
  943. $formData['FutureinfoClasses'] = array();
  944. $formData['FutureinfoClasses'][0] = $this->view->translate("content-add-select-finfo-classification");
  945. foreach($allClasses as $class) {
  946. $formData['FutureinfoClasses'][$class['id_fic']] = $class['name_fic'];
  947. }
  948. // Getting innovation types from the database
  949. $modelInnovationTypes = new Default_Model_InnovationTypes();
  950. $innovationTypes = $modelInnovationTypes->getAllNamesAndIds();
  951. // Getting the innovation type of the content
  952. $modelCntHasIvt = new Default_Model_ContentHasInnovationTypes();
  953. $formData['selected_ivt'] =
  954. $modelCntHasIvt->getInnovationTypeIdOfContent($data['id_cnt']);
  955. // Adding all innovation types to form
  956. $formData['InnovationTypes'] = array();
  957. $formData['InnovationTypes'][0] =
  958. $this->view->translate("content-add-select-innovation");
  959. foreach($innovationTypes as $ivt) {
  960. $formData['InnovationTypes'][$ivt['id_ivt']] =
  961. $ivt['name_ivt'];
  962. } // end foreach
  963. if(empty($formData['InnovationTypes'])) {
  964. $formData['InnovationTypes'] = array(0 => '----');
  965. }
  966. $languages = New Default_Model_Languages();
  967. $idLngInd = $languages->getLangIdByLangName($this->view->language);
  968. // Getting language of the content
  969. $formData['content_language'] = $languages->getLangIdByLangName($data['language_cnt']);
  970. // Getting the industry of the content
  971. $modelCntHasInd = new Default_Model_ContentHasIndustries();
  972. $cntInd = $modelCntHasInd->getIndustryIdOfContent($data['id_cnt']);
  973. // Getting industries from the database
  974. $modelIndustries = new Default_Model_Industries();
  975. $industries = $modelIndustries->getNamesAndIdsById(0, $idLngInd);
  976. // Getting all industries of the content
  977. $industryIds = $modelIndustries->getAllContentIndustryIds($cntInd);
  978. $formData['industryIds'] = $industryIds;
  979. // Adding all industries of the content to form
  980. $formData['selected_industry'] = $industryIds[0];
  981. $formData['selected_division'] = $industryIds[1];
  982. $formData['selected_group'] = $industryIds[2];
  983. $formData['selected_class'] = $industryIds[3];
  984. // Adding all industries to form
  985. $formData['Industries'] = array();
  986. $formData['Industries'][0] =
  987. $this->view->translate("content-add-select-industry");
  988. foreach($industries as $ind) {
  989. $formData['Industries'][$ind['id_ind']] = $ind['name_ind'];
  990. } // end foreach
  991. if(empty($formData['Industries'])) {
  992. $formData['Industries'] = array(0 => '----');
  993. }
  994. // Adding all divisions to form
  995. $formData['Divisions'] = array();
  996. $formData['Divisions'][0] = $this->view->translate("content-add-select-division-no-industry");
  997. if($industryIds[0] != 0) {
  998. $divisions = $modelIndustries
  999. ->getNamesAndIdsById($industryIds[0], $idLngInd);
  1000. foreach($divisions as $div) {
  1001. $formData['Divisions'][$div['id_ind']] = $div['name_ind'];
  1002. } // end foreach
  1003. }
  1004. // Adding all groups to form
  1005. $formData['Groups'] = array();
  1006. $formData['Groups'][0] = $this->view->translate("content-add-select-group-no-division");
  1007. if($industryIds[1] != 0) {
  1008. $groups = $modelIndustries->getNamesAndIdsById($industryIds[1], $idLngInd);
  1009. foreach($groups as $grp) {
  1010. $formData['Groups'][$grp['id_ind']] = $grp['name_ind'];
  1011. } // end foreach
  1012. }
  1013. $formData['Classes'] = array();
  1014. $formData['Classes'][0] = $this->view->translate("content-add-select-class-no-group");
  1015. // If there's no group selected
  1016. if($industryIds[2] != 0) {
  1017. $classes = $modelIndustries->getNamesAndIdsById($industryIds[2], $idLngInd);
  1018. foreach($classes as $class) {
  1019. $formData['Classes'][$class['id_ind']] = $class['name_ind'];
  1020. } // end foreach
  1021. }
  1022. $modelContentTypes = new Default_Model_ContentTypes();
  1023. $contentType = $modelContentTypes->getTypeById($data['id_cty_cnt']);
  1024. $this->view->short_contenttype = $contentType;
  1025. $title_cnt = $content->getContentHeaderByContentId($data['id_cnt']);
  1026. $this->view->contentHeader = $title_cnt;
  1027. // Get contents filenames from database
  1028. $filesModel = new Default_Model_Files();
  1029. $filenames = $filesModel->getFilenamesByCntId($contentId);
  1030. $formData['filenames'] = $filenames;
  1031. // Form for content adding
  1032. $form = new Default_Form_EditContentForm(null, $formData, $contentId, $contentType, $this->view->language);
  1033. $form->populate($formData);
  1034. $this->view->form = $form;
  1035. $url = $this->_urlHelper->url(array('controller' => 'msg',
  1036. 'action' => 'index',
  1037. 'language' => $this->view->language),
  1038. 'lang_default', true);
  1039. // populate form
  1040. if($backFromPreview)
  1041. {
  1042. // Get previewdata and populate it to form
  1043. $previewData = $previewSession->previewData;
  1044. $form->populate($previewData);
  1045. // Delete session data
  1046. $previewSession->unsetAll();
  1047. }
  1048. // If posted
  1049. if($this->getRequest()->isPost()) {
  1050. // Get content data
  1051. $data = $this->getRequest()->getPost();
  1052. // Content id
  1053. $data['content_id'] = $contentId;
  1054. // If form data is valid, handle database insertions
  1055. $validForm = $form->isValid($data) ? true : (isset($data['content_save']) && $data['content_save'] != '');
  1056. if($validForm) {
  1057. // If form data is going to be published
  1058. if(isset($data['content_publish']) && $data['content_publish'] == 1) {
  1059. $data['publish'] = 1;
  1060. $message_error = 'content-publish-not-successful';
  1061. }
  1062. // If form data is going to be saved
  1063. elseif(isset($data['content_save']) && $data['content_save'] == 1) {
  1064. $data['publish'] = 0;
  1065. $message_error = 'content-save-not-successful';
  1066. }
  1067. // Content keywords
  1068. /* FIXED: split() is deprecated in PHP 5.3.0 -> and removed in
  1069. * PHP 6.0, so changed to explode(). Also trim(array) doesn't
  1070. * trim array values, so this is done with foreach now.
  1071. */
  1072. $keywords = array();
  1073. foreach(explode(',', $data['content_keywords']) as $keyword) {
  1074. if(trim($keyword) != "") {
  1075. $keywords[] = strip_tags(trim($keyword));
  1076. }
  1077. }
  1078. $data['content_keywords'] = array_unique($keywords);
  1079. // Related companies
  1080. $relatedCompanies = array();
  1081. foreach(explode(',', $data['content_related_companies']) as $relatedCompany) {
  1082. if(trim($relatedCompany) != "") {
  1083. $relatedCompanies[] = strip_tags(trim($relatedCompany));
  1084. }
  1085. }
  1086. $data['content_related_companies'] = array_unique($relatedCompanies);
  1087. // Get user id
  1088. $data['User']['id_usr'] = $auth->getIdentity()->user_id;
  1089. /*
  1090. if($data['content_division'] == 0) {
  1091. $data['content_industry_id'] = $data['content_industry'];
  1092. } elseif($data['content_group'] == 0) {
  1093. $data['content_industry_id'] = $data['content_division'];
  1094. } elseif($data['content_class'] == 0) {
  1095. $data['content_industry_id'] = $data['content_group'];
  1096. } elseif($data['content_class'] != 0) {
  1097. $data['content_industry_id'] = $data['content_class'];
  1098. }*/
  1099. if($data['content_language'] == 0) {
  1100. $data['content_language'] = $this->view->language;
  1101. } else {
  1102. $data['content_language'] = $languages->getLangNameByLangId($data['content_language']);
  1103. }
  1104. //echo "<pre>"; print_r($data); echo "</pre>"; die();
  1105. $data['files'] = $_FILES['content_file_upload'];
  1106. // Edit content
  1107. $content = new Default_Model_Content();
  1108. $oldData = $content->getContentRow($contentId);
  1109. $edit = $content->editContent($data);
  1110. $url = $this->_urlHelper->url(array('controller' => 'msg',
  1111. 'action' => 'index',
  1112. 'language' => $this->view->language),
  1113. 'lang_default', true);
  1114. if($edit) {
  1115. //$favourite = new Default_Model_UserHasFavourites();
  1116. //$favouriteEdited = $favourite->setFavouriteModifiedTrue($edit);
  1117. if($oldData['published_cnt'] == 1 || (isset($data['content_publish']) && $data['content_publish'] == 1)) {
  1118. $url = $this->_urlHelper->url(array('content_id' => $edit,
  1119. 'language' => $this->view->language),
  1120. 'content_shortview', true);
  1121. $this->_redirect($url);
  1122. } else {
  1123. /*$message_ok = $this->view->translate('content-save-succes…

Large files files are truncated, but you can click here to view the full file