PageRenderTime 68ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_phocagallery/models/phocagalleryc.php

https://github.com/J2MTecnologia/joomla-3.x
PHP | 1924 lines | 1117 code | 338 blank | 469 comment | 304 complexity | 3c5248494dca3d39249fcee228244362 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause

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

  1. <?php
  2. /*
  3. * @package Joomla.Framework
  4. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. *
  7. * @component Phoca Component
  8. * @copyright Copyright (C) Jan Pavelka www.phoca.cz
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License version 2 or later;
  10. */
  11. defined( '_JEXEC' ) or die();
  12. jimport('joomla.application.component.modeladmin');
  13. phocagalleryimport( 'phocagallery.utils.utils' );
  14. phocagalleryimport( 'phocagallery.picasa.picasa' );
  15. phocagalleryimport( 'phocagallery.facebook.fb' );
  16. phocagalleryimport( 'phocagallery.facebook.fbsystem' );
  17. class PhocaGalleryCpModelPhocaGalleryC extends JModelAdmin
  18. {
  19. //protected $_XMLFile;
  20. //protected $_id;
  21. //protected $_data;
  22. protected $option = 'com_phocagallery';
  23. protected $text_prefix = 'com_phocagallery';
  24. protected function canDelete($record)
  25. {
  26. $user = JFactory::getUser();
  27. if (!empty($record->catid)) {
  28. return $user->authorise('core.delete', 'com_phocagallery.phocagalleryc.'.(int) $record->catid);
  29. } else {
  30. return parent::canDelete($record);
  31. }
  32. }
  33. protected function canEditState($record)
  34. {
  35. $user = JFactory::getUser();
  36. if (!empty($record->catid)) {
  37. return $user->authorise('core.edit.state', 'com_phocagallery.phocagalleryc.'.(int) $record->catid);
  38. } else {
  39. return parent::canEditState($record);
  40. }
  41. }
  42. public function getTable($type = 'PhocaGalleryc', $prefix = 'Table', $config = array())
  43. {
  44. return JTable::getInstance($type, $prefix, $config);
  45. }
  46. public function getForm($data = array(), $loadData = true) {
  47. $app = JFactory::getApplication();
  48. $form = $this->loadForm('com_phocagallery.phocagalleryc', 'phocagalleryc', array('control' => 'jform', 'load_data' => $loadData));
  49. if (empty($form)) {
  50. return false;
  51. }
  52. return $form;
  53. }
  54. protected function loadFormData()
  55. {
  56. // Check the session for previously entered form data.
  57. $data = JFactory::getApplication()->getUserState('com_phocagallery.edit.phocagalleryc.data', array());
  58. if (empty($data)) {
  59. $data = $this->getItem();
  60. }
  61. return $data;
  62. }
  63. public function getItem($pk = null)
  64. {
  65. if ($item = parent::getItem($pk)) {
  66. // Convert the params field to an array.
  67. $registry = new JRegistry;
  68. $registry->loadString($item->metadata);
  69. $item->metadata = $registry->toArray();
  70. }
  71. return $item;
  72. }
  73. protected function prepareTable(&$table)
  74. {
  75. jimport('joomla.filter.output');
  76. $date = JFactory::getDate();
  77. $user = JFactory::getUser();
  78. $table->title = htmlspecialchars_decode($table->title, ENT_QUOTES);
  79. $table->alias = JApplication::stringURLSafe($table->alias);
  80. if (empty($table->alias)) {
  81. $table->alias = JApplication::stringURLSafe($table->title);
  82. }
  83. if (empty($table->id)) {
  84. // Set the values
  85. //$table->created = $date->toSql();
  86. // Set ordering to the last item if not set
  87. if (empty($table->ordering)) {
  88. $db = JFactory::getDbo();
  89. $db->setQuery('SELECT MAX(ordering) FROM #__phocagallery_categories WHERE parent_id = '. (int) $table->parent_id);
  90. $max = $db->loadResult();
  91. $table->ordering = $max+1;
  92. }
  93. }
  94. else {
  95. // Set the values
  96. //$table->modified = $date->toSql();
  97. //$table->modified_by = $user->get('id');
  98. }
  99. }
  100. protected function getReorderConditions($table = null)
  101. {
  102. $condition = array();
  103. $condition[] = 'parent_id = '. (int) $table->parent_id;
  104. //$condition[] = 'state >= 0';
  105. return $condition;
  106. }
  107. function approve(&$pks, $value = 1)
  108. {
  109. // Initialise variables.
  110. $dispatcher = JDispatcher::getInstance();
  111. $user = JFactory::getUser();
  112. $table = $this->getTable('phocagalleryc');
  113. $pks = (array) $pks;
  114. // Include the content plugins for the change of state event.
  115. JPluginHelper::importPlugin('content');
  116. // Access checks.
  117. foreach ($pks as $i => $pk) {
  118. if ($table->load($pk)) {
  119. if (!$this->canEditState($table)) {
  120. // Prune items that you can't change.
  121. unset($pks[$i]);
  122. JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_EDIT_STATE_NOT_PERMITTED'));
  123. }
  124. }
  125. }
  126. // Attempt to change the state of the records.
  127. if (!$table->approve($pks, $value, $user->get('id'))) {
  128. $this->setError($table->getError());
  129. return false;
  130. }
  131. $context = $this->option.'.'.$this->name;
  132. // Trigger the onContentChangeState event.
  133. /*$result = $dispatcher->trigger($this->event_change_state, array($context, $pks, $value));
  134. if (in_array(false, $result, true)) {
  135. $this->setError($table->getError());
  136. return false;
  137. }*/
  138. return true;
  139. }
  140. /*
  141. protected function canEditState($record)
  142. {
  143. $user = JFactory::getUser();
  144. return $user->authorise('core.edit.state', $this->option);
  145. }
  146. */
  147. /*
  148. * Custom Save method - libraries/joomla/application/component/modeladmin.php
  149. */
  150. public function save($data, &$extImgError = false)
  151. {
  152. // = = = = = = = = = =
  153. // Default VALUES FOR Rights in FRONTEND
  154. // ACCESS - 0: all users can see the category (registered or not registered)
  155. // if registered or not registered it will be set in ACCESS LEVEL not here)
  156. // if -1 - user was not selected so every registered or special users can see category
  157. // UPLOAD - -2: nobody can upload or add images in front (if 0 - every users can do it)
  158. // DELETE - -2: nobody can upload or add images in front (if 0 - every users can do it)
  159. if(!isset($data['accessuserid'])) { $data['accessuserid'] = array();}
  160. if(!isset($data['uploaduserid'])) { $data['uploaduserid'] = array();}
  161. if(!isset($data['deleteuserid'])) { $data['deleteuserid'] = array();}
  162. $accessUserIdArray = PhocaGalleryUtils::toArray($data['accessuserid']);
  163. $uploadUserIdArray = PhocaGalleryUtils::toArray($data['uploaduserid']);
  164. $deleteUserIdArray = PhocaGalleryUtils::toArray($data['deleteuserid']);
  165. if (isset($data['access']) && (int)$data['access'] > 0 && (int)$accessUserIdArray[0] == 0) {
  166. $accessUserId[0] = -1;
  167. }
  168. $data['accessuserid'] = implode(',',$accessUserIdArray);
  169. $data['uploaduserid'] = implode(',',$uploadUserIdArray);
  170. $data['deleteuserid'] = implode(',',$deleteUserIdArray);
  171. //TODO - return message
  172. if(!isset($data['owner_id'])) { $data['owner_id'] = 0;}
  173. // Owner can have only one main category - check it
  174. $errorMsgOwner = '';
  175. $ownerMainCategory = $this->getOwnerMainCategory($data['owner_id'], $data['id'], $data['parent_id'], $errorMsgOwner);
  176. if($errorMsgOwner != '') {
  177. $data['owner_id'] = 0;
  178. $this->setError($errorMsgOwner);
  179. return false;
  180. }
  181. // = = = = = = = = = =
  182. // Initialise variables;
  183. $dispatcher = JDispatcher::getInstance();
  184. $table = $this->getTable();
  185. $pk = (!empty($data['id'])) ? $data['id'] : (int)$this->getState($this->getName().'.id');
  186. $isNew = true;
  187. // Include the content plugins for the on save events.
  188. JPluginHelper::importPlugin('content');
  189. // Load the row if saving an existing record.
  190. if ($pk > 0) {
  191. $table->load($pk);
  192. $isNew = false;
  193. }
  194. // Bind the data.
  195. if (!$table->bind($data)) {
  196. $this->setError($table->getError());
  197. return false;
  198. }
  199. if(intval($table->date) == 0) {
  200. $table->date = JFactory::getDate()->toSql();
  201. }
  202. // Prepare the row for saving
  203. $this->prepareTable($table);
  204. // Check the data.
  205. if (!$table->check()) {
  206. $this->setError($table->getError());
  207. return false;
  208. }
  209. // Trigger the onContentBeforeSave event.
  210. /*$result = $dispatcher->trigger($this->event_before_save, array($this->option.'.'.$this->name, $table, $isNew));
  211. if (in_array(false, $result, true)) {
  212. $this->setError($table->getError());
  213. return false;
  214. }*/
  215. // Store the data.
  216. if (!$table->store()) {
  217. $this->setError($table->getError());
  218. return false;
  219. }
  220. // Clean the cache.
  221. $cache = JFactory::getCache($this->option);
  222. $cache->clean();
  223. // Trigger the onContentAfterSave event.
  224. //$dispatcher->trigger($this->event_after_save, array($this->option.'.'.$this->name, $table, $isNew));
  225. $pkName = $table->getKeyName();
  226. if (isset($table->$pkName)) {
  227. $this->setState($this->getName().'.id', $table->$pkName);
  228. }
  229. $this->setState($this->getName().'.new', $isNew);
  230. $subTask = JRequest::getVar('subtask');
  231. // TODO
  232. if ((string)$subTask == 'loadextimgp') {
  233. if (isset($table->$pkName)) {
  234. $errorMsg = '';
  235. if(!$this->loadExtImages($table->$pkName, $data, $message)) {
  236. $this->setError($message, 'error');
  237. // Be aware the category is stored yet
  238. //return false;
  239. $extImgError = true;
  240. return true;//but with error message
  241. }
  242. }
  243. }
  244. if ((string)$subTask == 'loadextimgf') {
  245. if (isset($table->$pkName)) {
  246. $errorMsg = '';
  247. if(!$this->loadExtImagesFb($table->$pkName, $data, $message)) {
  248. $this->setError($message, 'error');
  249. // Be aware the category is stored yet
  250. //return false;
  251. $extImgError = true;
  252. return true;//but with error message
  253. }
  254. }
  255. }
  256. // Stored - set Owner
  257. if (isset($table->$pkName) && isset($data['owner_id']) && (int)$data['owner_id'] > 0) {
  258. if(!$this->setOwnerOfCategory($data)) {
  259. $this->setError($message);
  260. return false;
  261. }
  262. }
  263. return true;
  264. }
  265. protected function setOwnerOfCategory($data) {
  266. $dataUser['userid'] = (int)$data['owner_id'];
  267. //$data['catid'] = $id;
  268. $dataUser['avatar'] = '';
  269. $dataUser['published'] = 1;
  270. $dataUser['approved'] = 0;
  271. $dataOwnerCategory = $this->getOwnerCategoryData($dataUser['userid']);
  272. if ($dataOwnerCategory) {
  273. // Owner is set in user table
  274. $userCategoryId = $this->storeOwnerCategory($dataOwnerCategory);
  275. } else {
  276. // Owner is not set in user table
  277. $userCategoryId = $this->storeOwnerCategory($dataUser);
  278. }
  279. if (!$userCategoryId) {
  280. $this->setError(JText::_( 'COM_PHOCAGALLERY_ERROR_SAVING_CATEGORY' ) . ' - ' . JText('COM_PHOCAGALLERY_OWNER'));
  281. return false;
  282. }
  283. return true;
  284. }
  285. /*
  286. * Owner
  287. * Store information about Owner (if administrator add a category to some Owner)
  288. */
  289. protected function storeOwnerCategory($data) {
  290. $row =& $this->getTable('phocagalleryuser');
  291. // Bind the form fields to the table
  292. if (!$row->bind($data)) {
  293. $this->setError($this->_db->getErrorMsg());
  294. return false;
  295. }
  296. // if new item, order last in appropriate group
  297. if (!$row->id) {
  298. $row->ordering = $row->getNextOrder( );
  299. }
  300. // Make sure the table is valid
  301. if (!$row->check()) {
  302. $this->setError($this->_db->getErrorMsg());
  303. return false;
  304. }
  305. // Store the table to the database
  306. if (!$row->store()) {
  307. $this->setError($this->_db->getErrorMsg());
  308. return false;
  309. }
  310. return $row->id;
  311. }
  312. /*
  313. * Owner
  314. * Get information about author's category
  315. */
  316. protected function getOwnerCategoryData($userId) {
  317. $query = 'SELECT uc.*'
  318. . ' FROM #__phocagallery_user AS uc'
  319. . ' WHERE uc.userid = '.(int)$userId;
  320. $this->_db->setQuery( $query );
  321. $userCategoryData = $this->_db->loadObject();
  322. if (isset($userCategoryData->id)) {
  323. return $userCategoryData;
  324. }
  325. return false;
  326. }
  327. public function uploadExtImagesFb($idCat, $data, &$errorMsg) {
  328. $idImg = 0;
  329. if (JRequest::getVar( 'fbimg', 0, 'get', 'int' ) > 0) {
  330. $data['extfbcatid'] = JRequest::getVar( 'fbalbum', '', 'get' );
  331. $data['extfbuid'] = JRequest::getVar( 'fbuser', '', 'get' );
  332. $data['language'] = JRequest::getVar( 'fblang', '', 'get' );
  333. $idImg = JRequest::getVar( 'fbimg', '', 'get' );
  334. }
  335. $user = PhocaGalleryFbSystem::getFbUserInfo($data['extfbuid']);
  336. if (!empty($user)) {
  337. $session = PhocaGalleryFbSystem::setSessionData($user);
  338. $image = PhocaGalleryFbSystem::getImageFromCat($idCat, $idImg);
  339. if(isset($image['end']) && $image['end'] == 1) {
  340. $errorMsg = JText::_('COM_PHOCAGALLERY_FB_END_EXPORT');
  341. return true;
  342. }
  343. if(!empty($image)) {
  344. // Don't export external image
  345. if(isset($image['extid']) && $image['extid'] != '') {
  346. $exportMsg = '<b style="color:#fc0000">'.JText::_( 'COM_PHOCAGALLERY_NOT_EXPORTED' ).'</b> ('.JText::_('COM_PHOCAGALLERY_ERROR_EXT_IMG_NOT_EXPORTED').')';
  347. } else {
  348. $export = PhocaGalleryFb::exportFbImage ($user->appid, $user->fanpageid, $user->appsid, $session, $image, $data['extfbcatid']);
  349. if(isset($export['id']) && $export['id'] != '') {
  350. $exportMsg = '<b style="color:#009900">'.JText::_( 'COM_PHOCAGALLERY_EXPORTED' ).'</b>';
  351. } else {
  352. $exportMsg = '<b style="color:#fc0000">'.JText::_( 'COM_PHOCAGALLERY_NOT_EXPORTED' ).'</b> ('.JText::_('COM_PHOCAGALLERY_ERROR_FB_EXPORTING').')';
  353. }
  354. }
  355. $refreshUrl = 'index.php?option=com_phocagallery&task=phocagalleryc.uploadextimgfpgn&id='.$idCat.'&fbalbum='.$data['extfbcatid'].'&fbuser='.$data['extfbuid'].'&fblang='.$data['language'].'&fbimg='.(int)$image['id'] .'&amp;'. JSession::getFormToken().'=1';
  356. $imageFileName = '';
  357. if(isset($image['filename']) && $image['filename'] != '') {
  358. $imageFileName = ' ('.$image['filename'].')';
  359. }
  360. $countInfo = '<div><span style="color:#0066cc;">'. $image['title'] .$imageFileName . '</span>'
  361. . ' '.$exportMsg.'<br />'
  362. . '<span>' . JText::_('COM_PHOCAGALLERY_EXPORT_NEXT_IMG_EXPORT') . ' ...</span></div>';
  363. PhocaGalleryFbSystem::renderProcessPage($idCat, $refreshUrl, $countInfo);
  364. exit;
  365. } else {
  366. $errorMsg = JText::_('COM_PHOCAGALLERY_ERROR_LOADING_DATA_DB'). ': (Facebook Images From Category)';
  367. return false;
  368. }
  369. } else {
  370. $errorMsg = JText::_('COM_PHOCAGALLERY_ERROR_LOADING_DATA_DB'). ': (Facebook User Info)';
  371. return false;
  372. }
  373. }
  374. public function loadExtImagesFb($idCat, $data, &$message) {
  375. // PAGINATION
  376. $paramsC = JComponentHelper::getParams('com_phocagallery');
  377. $fb_load_pagination = $paramsC->get( 'fb_load_pagination', 25 );
  378. //FIRST
  379. $fbAfter = ''; // Variable transfered in GET when pagination is used
  380. //Start variable, this variable is empty but when we first get images from facebook
  381. // then we get info, there is more images and we get variable "after" which we use for pagination
  382. // There will be more images on Facebook until variable after is empty
  383. $fbCount = 0; // Variable transfered in GET when pagination is used
  384. // In variable fbAfter we transfer the string which says - there is some after, there are images on FB yet to import
  385. // In variable fbCount we store the infromation about that we redirecting the page and do a pagination loop
  386. if (JRequest::getVar( 'fbcount', 0, 'get', 'int' ) > 0) {
  387. // Category is saved - use this id and don't save it again
  388. $fbAfter = JRequest::getVar( 'fbafter', '', 'get' );
  389. $fbCount = JRequest::getVar( 'fbcount', 0, 'get' );
  390. $data['extfbuid'] = JRequest::getVar( 'fbuser', '', 'get' );
  391. $data['extfbcatid'] = JRequest::getVar( 'fbalbum', '', 'get' );
  392. $data['language'] = JRequest::getVar( 'fblang', '', 'get' );
  393. }
  394. // Preventing from Loop
  395. if ($fbCount > 40) {
  396. $message = PhocaGalleryUtils::setMessage(JText::_( 'COM_PHOCAGALLERY_FB_IMAGE_NOT_ALL_LOADED' ), $message);
  397. return false;
  398. }
  399. // Store behaviour
  400. // If there is count = 0, it means, we are beginning with the import, so we delete all previous data from category
  401. // if there is count > 0, we are in pagination loop, and we should not empty the data
  402. if ((int)$fbCount > 0) {
  403. $storeBehaviour = 'facebookpagination';// NOT empty data
  404. } else {
  405. $storeBehaviour = 'facebook';// Empty data
  406. }
  407. $lw = $paramsC->get( 'large_image_width', 640 );
  408. $mw = $paramsC->get( 'medium_image_width', 100 );
  409. $sw = $paramsC->get( 'small_image_width', 50 );
  410. $dataImg = array();
  411. if (isset($data['extfbuid']) && $data['extfbuid'] > 0 && isset($data['extfbcatid']) && $data['extfbcatid'] != '' ) {
  412. $user = PhocaGalleryFbSystem::getFbUserInfo($data['extfbuid']);
  413. if (!empty($user)) {
  414. $session = PhocaGalleryFbSystem::setSessionData($user);
  415. $albumName = PhocaGalleryFb::getFbAlbumName($user->appid, $user->appsid, $session, $data['extfbcatid'], '', $fb_load_pagination);
  416. // SECOND
  417. // If we have fbAfter and fbCount values, we are in pagination process
  418. // $fbAfter - when this is active, it means, there are images on Facebook still so we loop the pagination
  419. // if there is new $fbAfter (returned by reference), the pagination goes again
  420. $images = PhocaGalleryFb::getFbImages($user->appid, $user->appsid, $session, $fbAfter, $data['extfbcatid'], $fb_load_pagination);
  421. if(!empty($images)) {
  422. $i = 0;
  423. foreach ($images as $key => $value) {
  424. $noImageTitle = 'Image ' . str_pad($i + 1 + ((int)$fbCount * (int)$fb_load_pagination), 3 ,'0', STR_PAD_LEFT);
  425. // Possible two methods - by AID or ID
  426. $dataImg[$i]['extid'] = $value['id']; // BY ID
  427. //$dataImg[$i]['extid'] = $value['object_id'];
  428. //if (isset($value['caption']) && $value['caption'] != '') {
  429. if (isset($value['name']) && $value['name'] != '') {
  430. $dataImg[$i]['title'] = PhocaGalleryText::wordDeleteWhole($value['name'], 30, '');
  431. } else {
  432. $dataImg[$i]['title'] = $noImageTitle;
  433. }
  434. //if (isset($value['caption']) && $value['caption'] != '') {
  435. if (isset($value['name']) && $value['name'] != '') {
  436. $dataImg[$i]['description'] = $albumName . ' ' . $value['name'];
  437. } else {
  438. $dataImg[$i]['description'] = $albumName . ' ' . $noImageTitle;
  439. }
  440. $dataImg[$i]['extl'] = $value['source'];//set later thr right value // BY ID
  441. $dataImg[$i]['exto'] = $value['source']; // BY ID
  442. //$dataImg[$i]['extl'] = $value['src_big'];//set later thr right value
  443. // $dataImg[$i]['exto'] = $value['src_big'];
  444. $dataImg[$i]['exts'] = $value['picture'];//set later thr right value // BY ID
  445. $dataImg[$i]['extm'] = $value['picture'];//set later thr right value // BY ID
  446. //$dataImg[$i]['exts'] = $value['src'];//set later thr right value
  447. //$dataImg[$i]['extm'] = $value['src'];//set later thr right value
  448. //$dataImg[$i]['date'] = date("Y-m-d H:i:s", $value['created_time']); // BY ID
  449. if (isset($value['created_time']) && $value['created_time'] == '') {
  450. $dataImg[$i]['date'] = date("Y-m-d H:i:s", $value['created_time']);
  451. } else if (isset($value['created']) && $value['created'] == '') {
  452. $dataImg[$i]['date'] = date("Y-m-d H:i:s", $value['created']);
  453. } else {
  454. $dataImg[$i]['date'] = date("Y-m-d H:i:s");
  455. }
  456. /*
  457. // Try to find original and a or s(sometimes facebook returns it, sometimes not) :-(
  458. // Should the medium be larger
  459. $c = 1; //(1 ... original, +1 = 2 ... medium, +1 = 3 ... small)
  460. $m = false;
  461. if((int)$mw > (int)$dataImg[$i]['extw'][1]) {
  462. $m = true;//check for larger size of medium image
  463. $c++;// count;
  464. }
  465. $s = false;
  466. if((int)$sw > (int)$dataImg[$i]['extw'][2]) {
  467. $s = true;//check for larger size of medium image
  468. $c++;// count;
  469. }
  470. */
  471. if(isset($value['images'])) {
  472. $imagesArray = $value['images'];
  473. $dataImg[$i]['extl'] = $imagesArray[0]['source'];
  474. $dataImg[$i]['extm'] = $imagesArray[1]['source'];
  475. $dataImg[$i]['exts'] = $imagesArray[2]['source'];
  476. // Large
  477. $dataImg[$i]['extw'][0] = $imagesArray[0]['width'];
  478. $dataImg[$i]['exth'][0] = $imagesArray[0]['height'];
  479. //Medium
  480. $dataImg[$i]['extw'][1] = $imagesArray[1]['width'];
  481. $dataImg[$i]['exth'][1] = $imagesArray[1]['height'];
  482. // Small
  483. $dataImg[$i]['extw'][2] = $imagesArray[2]['width'];
  484. $dataImg[$i]['exth'][2] = $imagesArray[2]['height'];
  485. /*
  486. $f = 0;
  487. foreach ($value['images'] as $key2 => $value2) {
  488. // Original
  489. if(strpos($value2['source'], '_o.') === false) {
  490. } else {
  491. $dataImg[$i]['exto'] = $value2['source'];
  492. $f++;
  493. }
  494. // Change from _s to _a
  495. if ($m) {
  496. if(strpos($value2['source'], '_a.') === false) {
  497. } else {
  498. $dataImg[$i]['extm'] = $value2['source'];
  499. //Medium
  500. $dataImg[$i]['extw'][1] = $value2['width'];
  501. $dataImg[$i]['exth'][1] = $value2['height'];
  502. $f++;
  503. }
  504. }
  505. // Change from _t to _s
  506. if ($s) {
  507. if(strpos($value2['source'], '_s.') === false) {
  508. } else {
  509. $dataImg[$i]['exts'] = $value2['source'];
  510. //Small
  511. $dataImg[$i]['extw'][2] = $value2['width'];
  512. $dataImg[$i]['exth'][2] = $value2['height'];
  513. $f++;
  514. }
  515. }
  516. if ($f==$c){break;}//break this foreach (we found all checked images, don't look it again)
  517. }
  518. */
  519. }
  520. // - - - - - :-(
  521. $dataImg[$i]['extw'] = implode( ',', $dataImg[$i]['extw']);
  522. $dataImg[$i]['exth'] = implode( ',', $dataImg[$i]['exth']);
  523. $dataImg[$i]['exttype'] = 1;
  524. $dataImg[$i]['published'] = 1;
  525. $dataImg[$i]['approved'] = 1;
  526. $dataImg[$i]['catid'] = (int)$idCat;
  527. $dataImg[$i]['language'] = $data['language'];
  528. $i++;
  529. }
  530. // THIRD
  531. if ($fbAfter != '') {
  532. $fbCount = $fbCount + 1;
  533. $refreshUrl = 'index.php?option=com_phocagallery&task=phocagalleryc.loadextimgpgnfb&id='.$idCat.'&fbalbum='.$data['extfbcatid'].'&fbuser='.$data['extfbuid'].'&fblang='.$data['language'].'&fbafter='.$fbAfter .'&fbcount='.$fbCount.'&'. JSession::getFormToken().'=1';
  534. $fbImageFrom = ((int)$fbCount * (int)$fb_load_pagination) + 1;
  535. $fbImageTo = (int)$fbImageFrom + (int)$fb_load_pagination - 1;
  536. $countInfo = '<div>'. JText::sprintf('COM_PHOCAGALLERY_FB_IMPORTING_IMAGES' ,'<b>'.$fbImageFrom. '</b>', '<b>'. $fbImageTo . '</b> ') .'</div>';
  537. // Store images while pagination is working, we know "fbafter" exists, there are still images, don't empty table
  538. if(count($dataImg) > 0) {
  539. if($this->storeImage($dataImg, (int)$idCat, $storeBehaviour)) {
  540. //return true; don't return anything because we will be redirected
  541. } else {
  542. $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_FACEBOOK_IMAGE_SAVE_ERROR'), $message);
  543. return false;
  544. }
  545. } else {
  546. $message = JText::_('COM_PHOCAGALLERY_FACEBOOK_NOT_LOADED_IMAGE');
  547. return false;
  548. }
  549. PhocaGalleryFbSystem::renderProcessPage($idCat, $refreshUrl, $countInfo, 1);
  550. exit;
  551. }
  552. }
  553. } else {
  554. $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_ERROR_LOADING_DATA_DB'). ': (Facebook User Info)', $message);
  555. return false;
  556. }
  557. } else {
  558. $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_ERROR_LOADING_DATA_DB') . ' ' .JText::_('COM_PHOCAGALLERY_ERROR_CHECK_FB_FORM_FIELDS'), $message);
  559. return false;
  560. }
  561. if(count($dataImg) > 0) {
  562. if($this->storeImage($dataImg, (int)$idCat, $storeBehaviour)) {
  563. $message = PhocaGalleryUtils::setMessage(JText::_( 'COM_PHOCAGALLERY_FB_IMAGE_LOADED' ), $message);
  564. return true;
  565. } else {
  566. $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_FACEBOOK_IMAGE_SAVE_ERROR'), $message);
  567. return false;
  568. }
  569. } else {
  570. $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_FACEBOOK_NOT_LOADED_IMAGE'), $message);
  571. return false;
  572. }
  573. }
  574. /*
  575. public function loadExtImagesFb($idCat, $data, &$errorMsg) {
  576. $paramsC = JComponentHelper::getParams('com_phocagallery');
  577. $lw = $paramsC->get( 'large_image_width', 640 );
  578. $mw = $paramsC->get( 'medium_image_width', 100 );
  579. $sw = $paramsC->get( 'small_image_width', 50 );
  580. $dataImg = array();
  581. if (isset($data['extfbuid']) && $data['extfbuid'] > 0 && isset($data['extfbcatid']) && $data['extfbcatid'] != '' ) {
  582. $user = PhocaGalleryFbSystem::getFbUserInfo($data['extfbuid']);
  583. if (!empty($user)) {
  584. $session = PhocaGalleryFbSystem::setSessionData($user);
  585. $images = PhocaGalleryFb::getFbImages($user->appid, $user->appsid, $session, $data['extfbcatid']);
  586. if(!empty($images)) {
  587. $i = 0;
  588. foreach ($images as $key => $value) {
  589. $dataImg[$i]['extid'] = $value['pid'];
  590. $dataImg[$i]['title'] = PhocaGalleryText::wordDeleteWhole($value['caption'], 30, '');
  591. $dataImg[$i]['description'] = $value['caption'];
  592. $dataImg[$i]['extl'] = $value['src_big'];
  593. $dataImg[$i]['exto'] = $value['src_big'];
  594. $dataImg[$i]['exts'] = $value['src_small'];
  595. $dataImg[$i]['extm'] = $value['src'];
  596. $dataImg[$i]['date'] = date("Y-m-d H:i:s", $value['created']);
  597. // Large
  598. $dataImg[$i]['extw'][0] = $value['src_big_width'];
  599. $dataImg[$i]['exth'][0] = $value['src_big_height'];
  600. //Medium
  601. $dataImg[$i]['extw'][1] = $value['src_width'];
  602. $dataImg[$i]['exth'][1] = $value['src_height'];
  603. // Small
  604. $dataImg[$i]['extw'][2] = $value['src_small_width'];
  605. $dataImg[$i]['exth'][2] = $value['src_small_height'];
  606. // Try to find original and a or s(sometimes facebook returns it, sometimes not) :-(
  607. // Should the medium be larger
  608. $c = 1; //(1 ... original, +1 = 2 ... medium, +1 = 3 ... small)
  609. $m = false;
  610. if((int)$mw > (int)$dataImg[$i]['extw'][1]) {
  611. $m = true;//check for larger size of medium image
  612. $c++;// count;
  613. }
  614. $s = false;
  615. if((int)$sw > (int)$dataImg[$i]['extw'][2]) {
  616. $s = true;//check for larger size of medium image
  617. $c++;// count;
  618. }
  619. if(isset($value['images'])) {
  620. $f = 0;
  621. foreach ($value['images'] as $key2 => $value2) {
  622. // Original
  623. if(strpos($value2['source'], '_o.') === false) {
  624. } else {
  625. $dataImg[$i]['exto'] = $value2['source'];
  626. $f++;
  627. }
  628. // Change from _s to _a
  629. if ($m) {
  630. if(strpos($value2['source'], '_a.') === false) {
  631. } else {
  632. $dataImg[$i]['extm'] = $value2['source'];
  633. //Medium
  634. $dataImg[$i]['extw'][1] = $value2['width'];
  635. $dataImg[$i]['exth'][1] = $value2['height'];
  636. $f++;
  637. }
  638. }
  639. // Change from _t to _s
  640. if ($s) {
  641. if(strpos($value2['source'], '_s.') === false) {
  642. } else {
  643. $dataImg[$i]['exts'] = $value2['source'];
  644. //Small
  645. $dataImg[$i]['extw'][2] = $value2['width'];
  646. $dataImg[$i]['exth'][2] = $value2['height'];
  647. $f++;
  648. }
  649. }
  650. if ($f==$c){break;}//break this foreach (we found all checked images, don't look it again)
  651. }
  652. }
  653. // - - - - - :-(
  654. $dataImg[$i]['extw'] = implode( ',', $dataImg[$i]['extw']);
  655. $dataImg[$i]['exth'] = implode( ',', $dataImg[$i]['exth']);
  656. $dataImg[$i]['exttype'] = 1;
  657. $dataImg[$i]['published'] = 1;
  658. $dataImg[$i]['approved'] = 1;
  659. $dataImg[$i]['catid'] = (int)$idCat;
  660. $dataImg[$i]['language'] = $data['language'];
  661. $i++;
  662. }
  663. }
  664. } else {
  665. $errorMsg = JText::_('COM_PHOCAGALLERY_ERROR_LOADING_DATA_DB'). ': (Facebook User Info)';
  666. return false;
  667. }
  668. } else {
  669. $errorMsg = JText::_('COM_PHOCAGALLERY_ERROR_LOADING_DATA_DB') . ' ' .JText::_('COM_PHOCAGALLERY_ERROR_CHECK_FB_FORM_FIELDS');
  670. return false;
  671. }
  672. if(count($dataImg) > 0) {
  673. if($this->storeImage($dataImg, (int)$idCat, 'facebook')) {
  674. return true;
  675. } else {
  676. $errorMsg = JText::_('COM_PHOCAGALLERY_FACEBOOK_IMAGE_SAVE_ERROR');
  677. return false;
  678. }
  679. } else {
  680. $errorMsg = JText::_('COM_PHOCAGALLERY_FACEBOOK_NOT_LOADED_IMAGE');
  681. return false;
  682. }
  683. } */
  684. public function loadExtImages($idCat, $data, &$message) {
  685. $paramsC = JComponentHelper::getParams('com_phocagallery');
  686. $picasa_load_pagination = $paramsC->get( 'picasa_load_pagination', 20 );
  687. // First get Album ID from PICASA
  688. // Second - Get id (from saved category) OR from GET (if pagination is used)
  689. // Third save images with ID of category
  690. $errorMsgA = $errorMsgI = '';
  691. //FIRST
  692. if (JRequest::getVar( 'picstart', 0, 'get', 'int' ) > 0) {
  693. // Category is saved - use this id and don't save it again
  694. $data['exta'] = JRequest::getVar( 'picalbum', '', 'get' );
  695. $data['extu'] = JRequest::getVar( 'picuser', '', 'get' );
  696. $data['extauth'] = JRequest::getVar( 'picauth', '', 'get' );
  697. $data['language'] = JRequest::getVar( 'piclang', '', 'get' );
  698. }
  699. $album = $this->picasaAlbum($data['extu'], $data['extauth'], $data['exta'], $errorMsgA);
  700. if (!$album) {
  701. $message = PhocaGalleryUtils::setMessage($errorMsgA, $message);
  702. return false;
  703. } else {
  704. $data['extid'] = $album['id'];
  705. }
  706. // SECOND
  707. if (JRequest::getVar( 'picstart', 0, 'get', 'int' ) > 0) {
  708. // Category is saved - use this id and don't save it again
  709. $id = JRequest::getVar( 'id', 0, 'get', 'int' );
  710. } else {
  711. $id = $idCat;//you get id and you store the table data
  712. }
  713. if ($id && $id > 0) {
  714. // THIRD
  715. if ($album && (int)$album['id'] > 0) {
  716. // PAGINATION
  717. $start = JRequest::getVar( 'picstart', 1, 'get', 'int' );
  718. $max = $picasa_load_pagination;
  719. $pagination = '&start-index='.(int)$start.'&max-results='.(int)$max;
  720. $picImg = $this->picasaImages($data['extu'],$data['extauth'], $album['id'], $id, $data['language'], $pagination, $errorMsgI);
  721. if (!$picImg) {
  722. $message = PhocaGalleryUtils::setMessage($errorMsgI, $message);
  723. return false;
  724. } else {
  725. if (isset($album['num']) && (int)$album['num'] > 0) {
  726. $newStart = (int)$start + (int)$max;
  727. $newStartIf = (int)$newStart - 1;
  728. // Sec - - - -
  729. $loop = (int)$album['num'] / (int)$max;
  730. $maxCount = (int)$max;
  731. // - - - - - -
  732. if ((int)$loop > 50 || $maxCount < 20) {
  733. $message = PhocaGalleryUtils::setMessage(JText::_( 'COM_PHOCAGALLERY_PICASA_IMAGE_NOT_ALL_LOADED' ), $message);
  734. return false;
  735. } else {
  736. if ((int)$album['num'] > (int)$newStartIf) {
  737. $refreshUrl = 'index.php?option=com_phocagallery&task=phocagalleryc.loadextimgpgn&id='.$id.'&picalbum='.$data['exta'].'&picuser='.$data['extu'].'&picauth='.$data['extauth'].'&piclang='.$data['language'].'&picstart='.(int)$newStart .'&amp;'. JSession::getFormToken().'=1';
  738. $countImg = $newStartIf + $max;
  739. if ($countImg > $album['num']) {
  740. $countImg = $album['num'];
  741. }
  742. //$countInfo = '<div><b>'.$newStart. '</b> - <b>'. $countImg . '</b> ' .JText::_('COM_PHOCAGALLERY_FROM'). ' <b>' . $album['num'].'</b></div>';
  743. $countInfo = '<div>'. JText::sprintf('COM_PHOCAGALLERY_FROM_ALBUM' ,'<b>'.$newStart. '</b>', '<b>'. $countImg . '</b> ', ' <b>' . $album['num'].'</b>') .'</div>';
  744. PhocaGalleryPicasa::renderProcessPage($id, $refreshUrl, $countInfo);
  745. exit;
  746. }
  747. }
  748. }
  749. // The extid is not a part of post data, so we must store it after
  750. $query = $this->_db->getQuery(true);
  751. $query->update('`#__phocagallery_categories`');
  752. $query->set('`extid` = '.$this->_db->quote($album['id']));
  753. $query->where('`id` = '.(int)$id);
  754. $this->_db->setQuery( (string)$query );
  755. if (!$this->_db->query()) {
  756. $this->setError($this->_db->getErrorMsg());
  757. return false;
  758. }
  759. $message = PhocaGalleryUtils::setMessage(JText::_( 'COM_PHOCAGALLERY_PICASA_IMAGE_LOADED' ), $message);
  760. return true;
  761. }
  762. }
  763. } else {
  764. $message = PhocaGalleryUtils::setMessage(JText::_( 'COM_PHOCAGALLERY_ERROR_SAVING_CATEGORY' ), $message);
  765. return true;
  766. }
  767. }
  768. /*
  769. * AUTHOR - OWNER
  770. * Get information about owner's category
  771. */
  772. public function getOwnerMainCategory($userId, $categoryId, $parentId, &$errorMsgOwner) {
  773. $db =& JFactory::getDBO();
  774. // It is new subcategory, check if parent category has the same owner
  775. // If not don't assing the owner
  776. if ($parentId > 0) {
  777. $query = 'SELECT cc.id, cc.owner_id'
  778. . ' FROM #__phocagallery_categories AS cc'
  779. . ' WHERE cc.id = '.(int)$parentId;
  780. $db->setQuery( $query );
  781. $parentCatOwnerId = $db->loadObject();
  782. if (isset($parentCatOwnerId->owner_id) ) {
  783. if (($userId < 1) || $userId == $parentCatOwnerId->owner_id) {
  784. return true;
  785. } else {
  786. $errorMsgOwner .= '<br />'. JText::_('COM_PHOCAGALLERY_PARENT_CATEGORY_NOT_ASSIGNED_TO_SAME_USER');
  787. return false;
  788. }
  789. }
  790. } else {
  791. // It is not subcategory
  792. // If there is owner for other root category, don't assign it
  793. $query = 'SELECT cc.id, cc.title'
  794. . ' FROM #__phocagallery_categories AS cc'
  795. . ' WHERE cc.owner_id = '.(int)$userId
  796. . ' AND cc.id <> '.(int)$categoryId // Check other categories
  797. . ' AND cc.owner_id > 0' // Ignore -1
  798. . ' AND cc.parent_id = 0';// TODO
  799. $db->setQuery( $query );
  800. $ownerMainCategoryId = $db->loadObject();
  801. if (isset($ownerMainCategoryId->title)) {
  802. $errorMsgOwner .= '<br />'. JText::_('COM_PHOCAGALLERY_SELECTED_USER_CAN_BE_ASSIGNED_TO_ONE_MAIN_CATEGORY_ONLY')
  803. .'<br />'. JText::_('COM_PHOCAGALLERY_USER_ASSIGNED_TO_CATEGORY') . ': ' . $ownerMainCategoryId->title;
  804. return false;
  805. }
  806. }
  807. return true;
  808. }
  809. /*
  810. function accessmenu($id, $access) {
  811. $app = JFactory::getApplication();
  812. $row =& $this->getTable();
  813. if (!$row->load($id)) {
  814. $this->setError($this->_db->getErrorMsg());
  815. return false;
  816. }
  817. $row->id = $id;
  818. $row->access = $access;
  819. if ( !$row->check() ) {
  820. $this->setError($this->_db->getErrorMsg());
  821. return false;
  822. }
  823. if ( !$row->store() ) {
  824. $this->setError($this->_db->getErrorMsg());
  825. return false;
  826. }
  827. }*/
  828. function delete($cid = array()) {
  829. $app = JFactory::getApplication();
  830. $db = JFactory::getDBO();
  831. $result = false;
  832. if (count( $cid )) {
  833. JArrayHelper::toInteger($cid);
  834. $cids = implode( ',', $cid );
  835. // FIRST - if there are subcategories - - - - -
  836. $query = 'SELECT c.id, c.name, c.title, COUNT( s.parent_id ) AS numcat'
  837. . ' FROM #__phocagallery_categories AS c'
  838. . ' LEFT JOIN #__phocagallery_categories AS s ON s.parent_id = c.id'
  839. . ' WHERE c.id IN ( '.$cids.' )'
  840. . ' GROUP BY c.id'
  841. ;
  842. $db->setQuery( $query );
  843. if (!($rows2 = $db->loadObjectList())) {
  844. JError::raiseError( 500, $db->stderr('Load Data Problem') );
  845. return false;
  846. }
  847. // Add new CID without categories which have subcategories (we don't delete categories with subcat)
  848. $err_cat = array();
  849. $cid = array();
  850. foreach ($rows2 as $row) {
  851. if ($row->numcat == 0) {
  852. $cid[] = (int) $row->id;
  853. } else {
  854. $err_cat[] = $row->title;
  855. }
  856. }
  857. // - - - - - - - - - - - - - - -
  858. // Images with new cid - - - - -
  859. if (count( $cid )) {
  860. JArrayHelper::toInteger($cid);
  861. $cids = implode( ',', $cid );
  862. // Select id's from phocagallery tables. If the category has some images, don't delete it
  863. $query = 'SELECT c.id, c.name, c.title, COUNT( s.catid ) AS numcat'
  864. . ' FROM #__phocagallery_categories AS c'
  865. . ' LEFT JOIN #__phocagallery AS s ON s.catid = c.id'
  866. . ' WHERE c.id IN ( '.$cids.' )'
  867. . ' GROUP BY c.id';
  868. $db->setQuery( $query );
  869. if (!($rows = $db->loadObjectList())) {
  870. JError::raiseError( 500, $db->stderr('Load Data Problem') );
  871. return false;
  872. }
  873. $err_img = array();
  874. $cid = array();
  875. foreach ($rows as $row) {
  876. if ($row->numcat == 0) {
  877. $cid[] = (int) $row->id;
  878. } else {
  879. $err_img[] = $row->title;
  880. }
  881. }
  882. if (count( $cid )) {
  883. $cids = implode( ',', $cid );
  884. $query = 'DELETE FROM #__phocagallery_categories'
  885. . ' WHERE id IN ( '.$cids.' )';
  886. $db->setQuery( $query );
  887. if (!$db->query()) {
  888. $this->setError($this->_db->getErrorMsg());
  889. return false;
  890. }
  891. // Delete items in phocagallery_user_category
  892. /* $query = 'DELETE FROM #__phocagallery_user_category'
  893. . ' WHERE catid IN ( '.$cids.' )';
  894. $db->setQuery( $query );
  895. if (!$db->query()) {
  896. $this->setError($this->_db->getErrorMsg());
  897. return false;
  898. }*/
  899. }
  900. }
  901. // There are some images in the category - don't delete it
  902. $msg = '';
  903. if (count( $err_cat ) || count( $err_img )) {
  904. if (count( $err_cat )) {
  905. $cids_cat = implode( ", ", $err_cat );
  906. $msg .= JText::plural( 'COM_PHOCAGALLERY_ERROR_DELETE_CONTAIN_CAT', $cids_cat );
  907. }
  908. if (count( $err_img )) {
  909. $cids_img = implode( ", ", $err_img );
  910. $msg .= JText::plural( 'COM_PHOCAGALLERY_ERROR_DELETE_CONTAIN_IMG', $cids_img );
  911. }
  912. $link = 'index.php?option=com_phocagallery&view=phocagallerycs';
  913. $app->redirect($link, $msg);
  914. }
  915. }
  916. return true;
  917. }
  918. function cooliris($cids, &$message) {
  919. $db = JFactory::getDBO();
  920. $path = PhocaGalleryPath::getPath();
  921. $piclensImg = $path->image_rel_front.'icon-phocagallery.png';
  922. $paramsC = JComponentHelper::getParams('com_phocagallery') ;
  923. jimport('joomla.filesystem.file');
  924. jimport('joomla.filesystem.folder');
  925. // PARAMS
  926. // original 0, thumbnail 1
  927. $cooliris_image = $paramsC->get( 'piclens_image', 1);
  928. if (JFolder::exists($path->image_abs)) {
  929. foreach ($cids as $kcid =>$vcid) {
  930. $xml = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>'. "\n";
  931. $xml .= '<rss xmlns:media="http://search.yahoo.com/mrss" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">'. "\n";
  932. $xml .= ' <channel>'. "\n";
  933. $xml .= ' <atom:icon>'.JURI::root() . $piclensImg. '</atom:icon>'. "\n\n";
  934. $xml .= ' <title>Phoca Gallery</title>'. "\n";
  935. $xml .= ' <link>http://www.phoca.cz/</link>'. "\n";
  936. $xml .= ' <description>Phoca Gallery</description>'. "\n";
  937. $query = 'SELECT a.id, a.title, a.filename, a.description, a.extid, a.extl, a.exto'
  938. . ' FROM #__phocagallery AS a'
  939. . ' WHERE a.catid = '.(int)$vcid
  940. . ' AND a.published = 1'
  941. . ' ORDER BY a.catid, a.ordering';
  942. $db->setQuery($query);
  943. $rows = $db->loadObjectList();
  944. foreach ($rows as $krow => $vrow) {
  945. $file = PhocaGalleryFileThumbnail::getOrCreateThumbnail($vrow->filename, '');
  946. $thumbFile = str_replace( "administrator", "", $file['thumb_name_l_no_rel']);
  947. $origFile = str_replace( "administrator", "", $file['name_original_rel']);
  948. $xml .= ' <item>'. "\n";
  949. $xml .= ' <title>' . $vrow->title . '</title>'. "\n";
  950. if ($vrow->extid != '') {
  951. $xml .= '<link>' .$vrow->extl . '</link>'. "\n";
  952. } else {
  953. $xml .= ' <link>' .JURI::root().$thumbFile . '</link>'. "\n";
  954. }
  955. $xml .= ' <description>' . JFilterOutput::cleanText(strip_tags($vrow->description )) . '</description>'. "\n";
  956. if ($vrow->extid != '') {
  957. $xml .= ' <media:thumbnail url="' .$vrow->extl .'" />'. "\n";
  958. if ($cooliris_image == 1) {
  959. $xml .= ' <media:content url="' .$vrow->extl .'" />'. "\n";
  960. } else {
  961. $xml .= ' <media:content url="' .$vrow->exto .'" />'. "\n";
  962. }
  963. } else {
  964. $xml .= ' <media:thumbnail url="' .JURI::root().$thumbFile .'" />'. "\n";
  965. if ($cooliris_image == 1) {
  966. $xml .= ' <media:content url="' .JURI::root().$thumbFile .'" />'. "\n";
  967. } else {
  968. $xml .= ' <media:content url="' .JURI::root().$origFile .'" />'. "\n";
  969. }
  970. }
  971. if ($vrow->extid != '') {
  972. $xml .= ' <guid isPermaLink="false">' . $vcid .'-phocagallerypiclenscode-'.$vrow->extid . '</guid>'. "\n";
  973. } else {
  974. $xml .= ' <guid isPermaLink="false">' . $vcid .'-phocagallerypiclenscode-'.$vrow->filename . '</guid>'. "\n";
  975. }
  976. $xml .= ' </item>'. "\n\n";
  977. }
  978. $xml .= ' </channel>'. "\n";
  979. $xml .= '</rss>'. "\n";
  980. ob_start();
  981. echo $xml;
  982. $xmlToWrite = ob_get_contents();
  983. ob_end_clean();
  984. if(!JFile::write( $path->image_abs . DS . $vcid.'.rss', $xmlToWrite)) {
  985. $message = 'COM_PHOCAGALLERY_ERROR_SAVING_RSS';
  986. return false;
  987. }
  988. }
  989. return true;
  990. } else {
  991. $message = 'COM_PHOCAGALLERY_ERROR_IMAGE_FOLDER_NOT_EXIST';
  992. return false;
  993. }
  994. }
  995. protected function picasaAlbum($user, $authkey, $album, &$errorMsg) {
  996. $paramsC = JComponentHelper::getParams('com_phocagallery');
  997. $enable_picasa_loading = $paramsC->get( 'enable_picasa_loading', 1 );
  998. if($enable_picasa_loading == 0){
  999. $errorMsg = JText::_('COM_PHOCAGALLERY_PICASA_NOT_ENABLED');
  1000. return false;
  1001. }
  1002. if(!function_exists("json_decode")){
  1003. $errorMsg = JText::_('COM_PHOCAGALLERY_PICASA_NOT_LOADED_JSON');
  1004. return false;
  1005. }
  1006. // PUBLIC OR UNLISTED ALBUM
  1007. if ($authkey == ''){
  1008. // PUBLIC ALBUM
  1009. $userAddress = 'http://picasaweb.google.com/data/feed/api/user/'.htmlentities($user).'?kind=album&access=public&alt=json';
  1010. $dataUser = PhocaGalleryPicasa::loadDataByAddress($userAddress, 'user', $errorMsg);
  1011. if($dataUser == '') {
  1012. $errorMsg = JText::_('COM_PHOCAGALLERY_PICASA_NOT_LOADED_USER');
  1013. return false;
  1014. }
  1015. $dataUser = json_decode($dataUser);
  1016. $albumInfo = false;
  1017. $OgphotoId = 'gphoto$id';
  1018. $OgphotoName = 'gphoto$name';
  1019. $OgphotoNum = 'gphoto$numphotos';
  1020. $Ot = '$t';
  1021. if (isset($dataUser->feed->entry) && count($dataUser->feed->entry) > 0) {
  1022. foreach ($dataUser->feed->entry as $key => $value) {
  1023. if (str_replace(' ', '', $album) == $value->{$OgphotoName}->{$Ot}) {
  1024. //Try to find by Name
  1025. $albumInfo['id'] = $value->{$OgphotoId}->{$Ot};
  1026. $albumInfo['num'] = $value->{$OgphotoNum}->{$Ot};
  1027. return $albumInfo;
  1028. } else if ($album == $value->{$OgphotoId}->{$Ot}) {
  1029. // Try to find by ID
  1030. $albumInfo['id'] = $value->{$OgphotoId}->{$Ot};
  1031. $albumInfo['num'] = $value->{$OgphotoNum}->{$Ot};
  1032. return $albumInfo;
  1033. }
  1034. }
  1035. // Album not found
  1036. $errorMsg = JText::_('COM_PHOCAGALLERY_PICASA_NOT_LOADED_ALBUM');
  1037. return false;
  1038. } else {
  1039. $errorMsg = JText::_('COM_PHOCAGALLERY_PICASA_NOT_LOADED_USER');
  1040. return false;
  1041. }
  1042. } else {
  1043. // UNLISTED ALBUM
  1044. // First try the name
  1045. $userAddress = 'http://picasaweb.google.com/data/feed/api/user/'.htmlentities($user).'/album/'.htmlentities($album).'?authkey='.htmlentities($authkey).'&alt=json';
  1046. $dataUser = PhocaGalleryPicasa::loadDataByAddress($userAddress, 'user', $errorMsg);
  1047. $dataUser = json_decode($dataUser);
  1048. // Second try the ID
  1049. if (!isset($dataUser->feed->entry)) {
  1050. $userAddress = 'http://picasaweb.google.com/data/feed/api/user/'.htmlentities($user).'/albumid/'.htmlentities($album).'?authkey='.htmlentities($authkey).'&alt=json';
  1051. $dataUser = PhocaGalleryPicasa::loadDataByAddress($userAddress, 'user', $errorMsg);
  1052. $dataUser = json_decode($dataUser);
  1053. }
  1054. if($dataUser == '') {
  1055. $errorMsg = JText::_('COM_PHOCAGALLERY_PICASA_NOT_LOADED_ALBUM');
  1056. return false;
  1057. }
  1058. //$dataUser = json_decode($dataUser);
  1059. $albumInfo = false;
  1060. $OgphotoId = 'gphoto$id';
  1061. $OgphotoName = 'gphoto$name';
  1062. $OgphotoNum = 'gphoto$numphotos';
  1063. $Ot = '$t';
  1064. if (isset($dataUser->feed->entry) && count($dataUser->feed->entry) > 0) {
  1065. if ($album == $dataUser->feed->{$OgphotoName}->{$Ot}) {
  1066. $albumInfo['id'] = $dataUser->feed->{$OgphotoId}->{$Ot};
  1067. $albumInfo['num'] = $dataUser->feed->{$OgphotoNum}->{$Ot};
  1068. return $albumInfo;
  1069. } else if ($album == $dataUser->feed->{$OgphotoId}->{$Ot}) {
  1070. $albumInfo['id'] = $dataUser->feed->{$OgphotoId}->{$Ot};
  1071. $albumInfo['num'] = $dataUser->feed->{$OgphotoNum}->{$Ot};
  1072. return $albumInfo;
  1073. }
  1074. // Album not found
  1075. $errorMsg = JText::_('COM_PHOCAGALLERY_PICASA_NOT_LOADED_ALBUM');
  1076. return false;
  1077. } else {
  1078. $errorMsg = JText::_('COM_PHOCAGALLERY_PICASA_NOT_LOADED_USER');
  1079. return false;
  1080. }
  1081. }
  1082. }
  1083. function picasaImages($user, $authkey, $albumId, $catid, $language, $pagination, &$errorMsg) {
  1084. // Large image - is taken as original
  1085. // Medium - can be taken as original (if Picasat thumbs are too small or as thumbnail)
  1086. // Small - is taken as thumbnail
  1087. // In getSize we decide if the mediumT will be 0 or 1
  1088. // mediumT = 1 - thumbnail, mediumT = 0 - original
  1089. $mediumT = 0;
  1090. phocagalleryimport('phocagallery.picasa.picasa');
  1091. $size = PhocaGalleryPicasa::getSize($mediumT);
  1092. $Ot = '$t';
  1093. $OgeorssWhere = 'georss$where';
  1094. $OgmlPoint = 'gml$Point';
  1095. $OgmlPos = 'gml$pos';
  1096. $OmediaGroup = 'media$group';
  1097. $OmediaContent = 'media$content';
  1098. $OmediaThumbnail= 'media$thumbnail';
  1099. $OgphotoId = 'gphoto$id';
  1100. $OgphotoName = 'gphoto$name';
  1101. $OgphotoWidth = 'gphoto$width';// New Feature in Picasa
  1102. $Ot = '$t';
  1103. // LARGE AND SMALL( AND MEDIUM) - will be the same everywhere so we take them in one
  1104. if ($authkey == ''){
  1105. $albumAddressLSM = 'http://picasaweb.google.com/data/feed/api/user/'.htmlentities($user).'/albumid/'.$albumId.'?alt=json&kind=photo'.$size['lsm'].$pagination;
  1106. } else {
  1107. $albumAddressLSM = 'http://picasaweb.google.com/data/feed/api/user/'.htmlentities($user).'/albumid/'.$albumId.'?alt=json&kind=photo'.$size['lsm'].$pagination.'&authkey='.htmlentities($authkey);
  1108. }
  1109. $dataAlbumLSM = PhocaGalleryPicasa::loadDataByAddress($albumAddressLSM, 'album', $errorMsg);
  1110. if(!$dataAlbumLSM) {
  1111. return false;
  1112. }
  1113. $dataAlbumLSM = json_decode($dataAlbumLSM);
  1114. $dataImg = array();
  1115. // LARGE AND SMALL (AND MEDIUM)
  1116. if (isset($dataAlbumLSM->feed->entry) && count($dataAlbumLSM->feed->entry) > 0) {
  1117. $i = 0;
  1118. foreach ($dataAlbumLSM->feed->entry as $key => $value) {
  1119. //$row->date = gmdate('Y-m-d H:i:s');
  1120. $dataImg[$i]['extid'] = $value->{$OgphotoId}->{$Ot};
  1121. //$dataImg[$i]['title'] = $value->summary->{$Ot};
  1122. $dataImg[$i]['title'] = $value->title->{$Ot};
  1123. $dataImg[$i]['description'] = $value->summary->{$Ot};
  1124. $dataImg[$i]['extl'] = $value->content->src;
  1125. // New Feature in Picasa
  1126. //$dataImg[$i]['exto'] = str_replace('/s'.$size['ls'].'/', '/', $value->content->src);
  1127. //$dataImg[$i]['exto'] = str_replace('/s'.$size['ls'].'/', '/s'.$value->{$OgphotoWidth}->{$Ot}.'/', $value->content->src);
  1128. $dataImg[$i]['exto'] = str_replace('/s'.$size['ls'].'/', '/s0/', $value->content->src);
  1129. $dataImg[$i]['exts'] = $value->{$OmediaGroup}->{$OmediaThumbnail}[0]->url;
  1130. if ($mediumT == 1) {
  1131. $dataImg[$i]['extm'] = $value->{$OmediaGroup}->{$OmediaThumbnail}[1]->url;
  1132. }
  1133. $dataImg[$i]['date'] = substr(str_replace('T', ' ',$value->updated->{$Ot}), 0, 19);
  1134. $dataImg[$i]['language'] = $language;
  1135. /*if (isset($value->{$OgeorssWhere}->{$OgmlPoint}->{$OgmlPos}->{$Ot})) {
  1136. $dataImg[$i]['latitude'] = substr($value->{$OgeorssWhere}->{$OgmlPoint}->{$OgmlPos}->{$Ot}, 0, 10);
  1137. $dataImg[$i]['longitude'] = substr($value->{$OgeorssWhere}->{$OgmlPoint}->{$OgmlPos}->{$Ot}, 11, 10);
  1138. $dataImg[$i]['zoom'] = 10;
  1139. //$data['geotitle'] = $data['title'];
  1140. }*/
  1141. if (isset($value->{$OgeorssWhere}->{$OgmlPoint}->{$OgmlPos}->{$Ot})) {
  1142. //$dataImg[$i]['latitude'] = substr($value->{$OgeorssWhere}->{$OgmlPoint}->{$OgmlPos}->{$Ot}, 0, 10);
  1143. //$dataImg[$i]['longitude'] = substr($value->{$OgeorssWhere}->{$OgmlPoint}->{$OgmlPos}->{$Ot}, 11, 10);
  1144. $geoArray = explode (' ', $value->{$OgeorssWhere}->{$OgmlPoint}->{$OgmlPos}->{$Ot});
  1145. if (isset($geoArray[0])) {
  1146. $dataImg[$i]['latitude'] = $geoArray[0];
  1147. }
  1148. if (isset($geoArray[1])) {
  1149. $dataImg[$i]['longitude'] = $geoArray[1];
  1150. }
  1151. $dataImg[$i]['zoom'] = 10;
  1152. //$data['geotitle'] = $data['title'];
  1153. }
  1154. // Large
  1155. $dataImg[$i]['extw'][0] = $value->{$OmediaGroup}->{$OmediaContent}[0]->width;
  1156. $dataImg[$i]['exth'][0] = $value->{$OmediaGroup}->{$OmediaContent}[0]->height;
  1157. if ($mediumT == 1) {
  1158. // Medium
  1159. $dataImg[$i]['extw'][1] = $value->{$OmediaGroup}->{$OmediaThumbnail}[1]->width;
  1160. $dataImg[$i]['exth'][1] = $value->{$OmediaGroup}->{$OmediaThumbnail}[1]->height;
  1161. }
  1162. // Small
  1163. $dataImg[$i]['extw'][2] = $value->{$OmediaGroup}->{$OmediaThumbnail}[0]->width;
  1164. $dataImg[$i]['exth'][2] = $value->{$OmediaGroup}->{$OmediaThumbnail}[0]->height;
  1165. if (isset($dataImg[$i]['extw'][0]) && isset($dataImg[$i]['exth'][0])
  1166. && (int)$dataImg[$i]['exth'][0] > (int)$dataImg[$i]['extw'][0]) {
  1167. $dataImg[$i]['format'] = 2;
  1168. } else {
  1169. $dataImg[$i]['format'] = 1;
  1170. }
  1171. // Complete the width and height here as all data large, small, medium are available
  1172. // ksort is not needed here if $mediumT == 1 (medium is taken as thumbnail)
  1173. if ($mediumT == 1) {
  1174. $dataImg[$i]['extw'] = implode( ',', $dataImg[$i]['extw']);
  1175. $dataImg[$i]['exth'] = implode( ',', $dataImg[$i]['exth']);
  1176. }
  1177. $dataImg[$i]['exttype'] = 0;
  1178. $dataImg[$i]['published'] = 1;
  1179. $dataImg[$i]['approved'] = 1;
  1180. $dataImg[$i]['catid'] = $catid;
  1181. $i++;
  1182. }
  1183. }
  1184. // Only in case the medium image cannot be taken from Picasa thumbnails
  1185. // MEDIUM
  1186. if ($mediumT == 0) {
  1187. if ($authkey == ''){
  1188. $albumAddressM = 'http://picasaweb.google.com/data/feed/api/user/'.htmlentities($user).'/albumid/'.$albumId.'?alt=js…

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