function display($tpl = null) { $app = JFactory::getApplication(); $document = JFactory::getDocument(); $uri = JFactory::getURI(); JHTML::stylesheet('media/com_phocagallery/css/administrator/phocagallery.css'); $this->field = JRequest::getVar('field'); $this->fce = 'phocaSelectFbAlbum_' . $this->field; //$eName = JRequest::getVar('e_name'); //$eName = preg_replace( '#[^A-Z0-9\-\_\[\]]#i', '', $eName ); $uid = JRequest::getVar('uid', 0, '', 'int'); $db = JFactory::getDBO(); $query = 'SELECT a.*' . ' FROM #__phocagallery_fb_users AS a' . ' WHERE a.published = 1' . ' AND a.id = ' . (int) $uid . ' ORDER BY a.ordering'; $db->setQuery($query); $user = $db->loadObject(); if (!isset($user->uid)) { $this->userInfo = 0; } else { $session = PhocaGalleryFbSystem::setSessionData($user); $this->albums = PhocaGalleryFb::getFbAlbums($user->appid, $user->fanpageid, $user->appsid, $session); $this->userInfo = 1; } //$this->assignRef('tmpl', $tmpl); parent::display($tpl); }
public function loadExtImagesFb($idCat, $data, &$message) { // PAGINATION $paramsC = JComponentHelper::getParams('com_phocagallery'); $fb_load_pagination = $paramsC->get('fb_load_pagination', 25); //FIRST $fbAfter = ''; // Variable transfered in GET when pagination is used //Start variable, this variable is empty but when we first get images from facebook // then we get info, there is more images and we get variable "after" which we use for pagination // There will be more images on Facebook until variable after is empty $fbCount = 0; // Variable transfered in GET when pagination is used // In variable fbAfter we transfer the string which says - there is some after, there are images on FB yet to import // In variable fbCount we store the infromation about that we redirecting the page and do a pagination loop if (JRequest::getVar('fbcount', 0, 'get', 'int') > 0) { // Category is saved - use this id and don't save it again $fbAfter = JRequest::getVar('fbafter', '', 'get'); $fbCount = JRequest::getVar('fbcount', 0, 'get'); $data['extfbuid'] = JRequest::getVar('fbuser', '', 'get'); $data['extfbcatid'] = JRequest::getVar('fbalbum', '', 'get'); $data['language'] = JRequest::getVar('fblang', '', 'get'); } // Preventing from Loop if ($fbCount > 40) { $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_FB_IMAGE_NOT_ALL_LOADED'), $message); return false; } // Store behaviour // If there is count = 0, it means, we are beginning with the import, so we delete all previous data from category // if there is count > 0, we are in pagination loop, and we should not empty the data if ((int) $fbCount > 0) { $storeBehaviour = 'facebookpagination'; // NOT empty data } else { $storeBehaviour = 'facebook'; // Empty data } $lw = $paramsC->get('large_image_width', 640); $mw = $paramsC->get('medium_image_width', 100); $sw = $paramsC->get('small_image_width', 50); $dataImg = array(); if (isset($data['extfbuid']) && $data['extfbuid'] > 0 && isset($data['extfbcatid']) && $data['extfbcatid'] != '') { $user = PhocaGalleryFbSystem::getFbUserInfo($data['extfbuid']); if (!empty($user)) { $session = PhocaGalleryFbSystem::setSessionData($user); $albumName = PhocaGalleryFb::getFbAlbumName($user->appid, $user->appsid, $session, $data['extfbcatid'], '', $fb_load_pagination); // SECOND // If we have fbAfter and fbCount values, we are in pagination process // $fbAfter - when this is active, it means, there are images on Facebook still so we loop the pagination // if there is new $fbAfter (returned by reference), the pagination goes again $images = PhocaGalleryFb::getFbImages($user->appid, $user->appsid, $session, $fbAfter, $data['extfbcatid'], $fb_load_pagination); if (!empty($images)) { $i = 0; foreach ($images as $key => $value) { $noImageTitle = 'Image ' . str_pad($i + 1 + (int) $fbCount * (int) $fb_load_pagination, 3, '0', STR_PAD_LEFT); // Possible two methods - by AID or ID $dataImg[$i]['extid'] = $value['id']; // BY ID //$dataImg[$i]['extid'] = $value['object_id']; //if (isset($value['caption']) && $value['caption'] != '') { if (isset($value['name']) && $value['name'] != '') { $dataImg[$i]['title'] = PhocaGalleryText::wordDeleteWhole($value['name'], 30, ''); } else { $dataImg[$i]['title'] = $noImageTitle; } //if (isset($value['caption']) && $value['caption'] != '') { if (isset($value['name']) && $value['name'] != '') { $dataImg[$i]['description'] = $albumName . ' ' . $value['name']; } else { $dataImg[$i]['description'] = $albumName . ' ' . $noImageTitle; } $dataImg[$i]['extl'] = $value['source']; //set later thr right value // BY ID $dataImg[$i]['exto'] = $value['source']; // BY ID //$dataImg[$i]['extl'] = $value['src_big'];//set later thr right value // $dataImg[$i]['exto'] = $value['src_big']; $dataImg[$i]['exts'] = $value['picture']; //set later thr right value // BY ID $dataImg[$i]['extm'] = $value['picture']; //set later thr right value // BY ID //$dataImg[$i]['exts'] = $value['src'];//set later thr right value //$dataImg[$i]['extm'] = $value['src'];//set later thr right value //$dataImg[$i]['date'] = date("Y-m-d H:i:s", $value['created_time']); // BY ID if (isset($value['created_time']) && $value['created_time'] == '') { $dataImg[$i]['date'] = date("Y-m-d H:i:s", $value['created_time']); } else { if (isset($value['created']) && $value['created'] == '') { $dataImg[$i]['date'] = date("Y-m-d H:i:s", $value['created']); } else { $dataImg[$i]['date'] = date("Y-m-d H:i:s"); } } /* // Try to find original and a or s(sometimes facebook returns it, sometimes not) :-( // Should the medium be larger $c = 1; //(1 ... original, +1 = 2 ... medium, +1 = 3 ... small) $m = false; if((int)$mw > (int)$dataImg[$i]['extw'][1]) { $m = true;//check for larger size of medium image $c++;// count; } $s = false; if((int)$sw > (int)$dataImg[$i]['extw'][2]) { $s = true;//check for larger size of medium image $c++;// count; } */ if (isset($value['images'])) { $imagesArray = $value['images']; $dataImg[$i]['extl'] = $imagesArray[0]['source']; $dataImg[$i]['extm'] = $imagesArray[1]['source']; $dataImg[$i]['exts'] = $imagesArray[2]['source']; // Large $dataImg[$i]['extw'][0] = $imagesArray[0]['width']; $dataImg[$i]['exth'][0] = $imagesArray[0]['height']; //Medium $dataImg[$i]['extw'][1] = $imagesArray[1]['width']; $dataImg[$i]['exth'][1] = $imagesArray[1]['height']; // Small $dataImg[$i]['extw'][2] = $imagesArray[2]['width']; $dataImg[$i]['exth'][2] = $imagesArray[2]['height']; /* $f = 0; foreach ($value['images'] as $key2 => $value2) { // Original if(strpos($value2['source'], '_o.') === false) { } else { $dataImg[$i]['exto'] = $value2['source']; $f++; } // Change from _s to _a if ($m) { if(strpos($value2['source'], '_a.') === false) { } else { $dataImg[$i]['extm'] = $value2['source']; //Medium $dataImg[$i]['extw'][1] = $value2['width']; $dataImg[$i]['exth'][1] = $value2['height']; $f++; } } // Change from _t to _s if ($s) { if(strpos($value2['source'], '_s.') === false) { } else { $dataImg[$i]['exts'] = $value2['source']; //Small $dataImg[$i]['extw'][2] = $value2['width']; $dataImg[$i]['exth'][2] = $value2['height']; $f++; } } if ($f==$c){break;}//break this foreach (we found all checked images, don't look it again) } */ } // - - - - - :-( $dataImg[$i]['extw'] = implode(',', $dataImg[$i]['extw']); $dataImg[$i]['exth'] = implode(',', $dataImg[$i]['exth']); $dataImg[$i]['exttype'] = 1; $dataImg[$i]['published'] = 1; $dataImg[$i]['approved'] = 1; $dataImg[$i]['catid'] = (int) $idCat; $dataImg[$i]['language'] = $data['language']; $i++; } // THIRD if ($fbAfter != '') { $fbCount = $fbCount + 1; $refreshUrl = 'index.php?option=com_phocagallery&task=phocagalleryc.loadextimgpgnfb&id=' . $idCat . '&fbalbum=' . $data['extfbcatid'] . '&fbuser='******'extfbuid'] . '&fblang=' . $data['language'] . '&fbafter=' . $fbAfter . '&fbcount=' . $fbCount . '&' . JSession::getFormToken() . '=1'; $fbImageFrom = (int) $fbCount * (int) $fb_load_pagination + 1; $fbImageTo = (int) $fbImageFrom + (int) $fb_load_pagination - 1; $countInfo = '<div>' . JText::sprintf('COM_PHOCAGALLERY_FB_IMPORTING_IMAGES', '<b>' . $fbImageFrom . '</b>', '<b>' . $fbImageTo . '</b> ') . '</div>'; // Store images while pagination is working, we know "fbafter" exists, there are still images, don't empty table if (count($dataImg) > 0) { if ($this->storeImage($dataImg, (int) $idCat, $storeBehaviour)) { //return true; don't return anything because we will be redirected } else { $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_FACEBOOK_IMAGE_SAVE_ERROR'), $message); return false; } } else { $message = JText::_('COM_PHOCAGALLERY_FACEBOOK_NOT_LOADED_IMAGE'); return false; } PhocaGalleryFbSystem::renderProcessPage($idCat, $refreshUrl, $countInfo, 1); exit; } } } else { $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_ERROR_LOADING_DATA_DB') . ': (Facebook User Info)', $message); return false; } } else { $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_ERROR_LOADING_DATA_DB') . ' ' . JText::_('COM_PHOCAGALLERY_ERROR_CHECK_FB_FORM_FIELDS'), $message); return false; } if (count($dataImg) > 0) { if ($this->storeImage($dataImg, (int) $idCat, $storeBehaviour)) { $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_FB_IMAGE_LOADED'), $message); return true; } else { $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_FACEBOOK_IMAGE_SAVE_ERROR'), $message); return false; } } else { $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_FACEBOOK_NOT_LOADED_IMAGE'), $message); return false; } }
</a></div> <div class="clr"></div> </fieldset> <?php if (isset($this->item->appid) && $this->item->appid != '' && isset($this->item->appsid) && $this->item->appsid != '') { ?> <fieldset class="adminform"> <legend><?php echo JText::_('COM_PHOCAGALLERY_FB_USER_SETTINGS'); ?> </legend> <?php $status = PhocaGalleryFb::getFbStatus($this->item->appid, $this->item->appsid); echo $status['html']; if ($status['session']['uid'] != '' && $status['session']['secret'] != '' && $status['session']['session_key'] != '' && $status['session']['access_token'] != '' && $status['session']['sig'] != '' && $status['u']['name'] != '') { /*$this->form->setValue('uid', '', $status['session']['uid']); $this->form->setValue('base_domain', '', $status['session']['base_domain']); $this->form->setValue('secret', '', $status['session']['secret']); $this->form->setValue('session_key', '', $status['session']['session_key']); $this->form->setValue('access_token', '', $status['session']['access_token']); $this->form->setValue('sig', '', $status['session']['sig']); if ($status['u']['name'] != '') { $this->form->setValue('name', '', $status['u']['name']); } */ $div[] = array(); $script = array(); $fields = array('uid', 'base_domain', 'secret', 'session_key', 'access_token', 'sig');
public function loadExtImagesFb($idCat, $data, &$errorMsg) { $paramsC = JComponentHelper::getParams('com_phocagallery'); $lw = $paramsC->get('large_image_width', 640); $mw = $paramsC->get('medium_image_width', 100); $sw = $paramsC->get('small_image_width', 50); $dataImg = array(); if (isset($data['extfbuid']) && $data['extfbuid'] > 0 && isset($data['extfbcatid']) && $data['extfbcatid'] != '') { $user = PhocaGalleryFbSystem::getFbUserInfo($data['extfbuid']); if (!empty($user)) { $session = PhocaGalleryFbSystem::setSessionData($user); $albumName = PhocaGalleryFb::getFbAlbumName($user->appid, $user->appsid, $session, $data['extfbcatid']); $images = PhocaGalleryFb::getFbImages($user->appid, $user->appsid, $session, $data['extfbcatid']); if (!empty($images)) { $i = 0; foreach ($images as $key => $value) { $noImageTitle = 'Image ' . str_pad($i + 1, 3, '0', STR_PAD_LEFT); // Possible two methods - by AID or ID //$dataImg[$i]['extid'] = $value['id']; // BY ID $dataImg[$i]['extid'] = $value['object_id']; $dataImg[$i]['title'] = $value['caption'] == '' ? $noImageTitle : PhocaGalleryText::wordDeleteWhole($value['caption'], 30, ''); $dataImg[$i]['description'] = $albumName . ' ' . ($value['caption'] == '' ? $noImageTitle : $value['caption']); //$dataImg[$i]['extl'] = $value['source'];//set later thr right value // BY ID //$dataImg[$i]['exto'] = $value['source']; // BY ID $dataImg[$i]['extl'] = $value['src_big']; //set later thr right value $dataImg[$i]['exto'] = $value['src_big']; //$dataImg[$i]['exts'] = $value['picture'];//set later thr right value // BY ID //$dataImg[$i]['extm'] = $value['picture'];//set later thr right value // BY ID $dataImg[$i]['exts'] = $value['src']; //set later thr right value $dataImg[$i]['extm'] = $value['src']; //set later thr right value //$dataImg[$i]['date'] = date("Y-m-d H:i:s", $value['created_time']); // BY ID $dataImg[$i]['date'] = date("Y-m-d H:i:s", $value['created']); /* // Try to find original and a or s(sometimes facebook returns it, sometimes not) :-( // Should the medium be larger $c = 1; //(1 ... original, +1 = 2 ... medium, +1 = 3 ... small) $m = false; if((int)$mw > (int)$dataImg[$i]['extw'][1]) { $m = true;//check for larger size of medium image $c++;// count; } $s = false; if((int)$sw > (int)$dataImg[$i]['extw'][2]) { $s = true;//check for larger size of medium image $c++;// count; } */ if (isset($value['images'])) { $imagesArray = $value['images']; $dataImg[$i]['extl'] = $imagesArray[0]['source']; $dataImg[$i]['extm'] = $imagesArray[1]['source']; $dataImg[$i]['exts'] = $imagesArray[2]['source']; // Large $dataImg[$i]['extw'][0] = $imagesArray[0]['width']; $dataImg[$i]['exth'][0] = $imagesArray[0]['height']; //Medium $dataImg[$i]['extw'][1] = $imagesArray[1]['width']; $dataImg[$i]['exth'][1] = $imagesArray[1]['height']; // Small $dataImg[$i]['extw'][2] = $imagesArray[2]['width']; $dataImg[$i]['exth'][2] = $imagesArray[2]['height']; /* $f = 0; foreach ($value['images'] as $key2 => $value2) { // Original if(strpos($value2['source'], '_o.') === false) { } else { $dataImg[$i]['exto'] = $value2['source']; $f++; } // Change from _s to _a if ($m) { if(strpos($value2['source'], '_a.') === false) { } else { $dataImg[$i]['extm'] = $value2['source']; //Medium $dataImg[$i]['extw'][1] = $value2['width']; $dataImg[$i]['exth'][1] = $value2['height']; $f++; } } // Change from _t to _s if ($s) { if(strpos($value2['source'], '_s.') === false) { } else { $dataImg[$i]['exts'] = $value2['source']; //Small $dataImg[$i]['extw'][2] = $value2['width']; $dataImg[$i]['exth'][2] = $value2['height']; $f++; } } if ($f==$c){break;}//break this foreach (we found all checked images, don't look it again) } */ } // - - - - - :-( $dataImg[$i]['extw'] = implode(',', $dataImg[$i]['extw']); $dataImg[$i]['exth'] = implode(',', $dataImg[$i]['exth']); $dataImg[$i]['exttype'] = 1; $dataImg[$i]['published'] = 1; $dataImg[$i]['approved'] = 1; $dataImg[$i]['catid'] = (int) $idCat; $dataImg[$i]['language'] = $data['language']; $i++; } } } else { $errorMsg = JText::_('COM_PHOCAGALLERY_ERROR_LOADING_DATA_DB') . ': (Facebook User Info)'; return false; } } else { $errorMsg = JText::_('COM_PHOCAGALLERY_ERROR_LOADING_DATA_DB') . ' ' . JText::_('COM_PHOCAGALLERY_ERROR_CHECK_FB_FORM_FIELDS'); return false; } if (count($dataImg) > 0) { if ($this->storeImage($dataImg, (int) $idCat, 'facebook')) { return true; } else { $errorMsg = JText::_('COM_PHOCAGALLERY_FACEBOOK_IMAGE_SAVE_ERROR'); return false; } } else { $errorMsg = JText::_('COM_PHOCAGALLERY_FACEBOOK_NOT_LOADED_IMAGE'); return false; } }