public function indexAction()
 {
     // Users
     $userTable = Engine_Api::_()->getItemTable('user');
     $select = new Zend_Db_Select($userTable->getAdapter());
     $select->from($userTable->info('name'), 'COUNT(user_id) as count');
     $data = $select->query()->fetch();
     $this->view->userCount = (int) $data['count'];
     // Reports
     $reportTable = Engine_Api::_()->getDbtable('reports', 'core');
     $select = new Zend_Db_Select($reportTable->getAdapter());
     $select->from($reportTable->info('name'), 'COUNT(report_id) as count')->where('`read` = ?', 0);
     $data = $select->query()->fetch();
     $this->view->reportCount = (int) $data['count'];
     // Plugins
     $moduleTable = Engine_Api::_()->getDbtable('modules', 'core');
     $select = new Zend_Db_Select($moduleTable->getAdapter());
     $select->from($moduleTable->info('name'), 'COUNT(TRUE) as count')->where('type = ?', 'extra');
     $data = $select->query()->fetch();
     $this->view->pluginCount = (int) $data['count'];
     // Notifications
     // Hook-based
     $event = Engine_Hooks_Dispatcher::_()->callEvent('getAdminNotifications');
     $this->view->notifications = $event->getResponses();
     // Database-based
     $select = Engine_Api::_()->getDbtable('log', 'core')->select()->where('domain = ?', 'admin')->order('timestamp DESC');
     $this->view->paginator = $paginator = Zend_Paginator::factory($select);
     $paginator->setItemCountPerPage(4);
 }
 public function indexAction()
 {
     $allowedHosts = array();
     // self
     $host = $_SERVER['HTTP_HOST'];
     if (preg_match('/\\d+\\.\\d+\\.\\d+\\.\\d+/', $host)) {
         $allowedHosts[] = $host;
     } else {
         $allowedHosts[] = '*.' . $host;
         $allowedHosts[] = $host;
     }
     // For static base url
     $staticBaseUrl = Zend_Registry::get('StaticBaseUrl');
     $parts = parse_url($staticBaseUrl);
     if (!empty($parts['host'])) {
         $host = $parts['host'];
         if (preg_match('/\\d+\\.\\d+\\.\\d+\\.\\d+/', $host)) {
             $allowedHosts[] = $host;
         } else {
             $allowedHosts[] = '*.' . $host;
             $allowedHosts[] = $host;
         }
     }
     // hooks
     $event = Engine_Hooks_Dispatcher::_()->callEvent('onGenerateCrossDomain');
     if (($r = $event->getResponses()) && is_array($r)) {
         $allowedHosts += $r;
     }
     $this->view->allowedHosts = $allowedHosts;
     // options
     $this->_helper->layout()->disableLayout();
     $this->getResponse()->setHeader('Content-Type', 'application/xml');
 }
Beispiel #3
0
 public function indexAction()
 {
     // Notifications
     $event = Engine_Hooks_Dispatcher::_()->callEvent('getAdminNotifications');
     $this->view->notifications = $event->getResponses();
     // Users
     $userTable = Engine_Api::_()->getItemTable('user');
     $select = new Zend_Db_Select($userTable->getAdapter());
     $select->from($userTable->info('name'), 'COUNT(user_id) as count');
     $data = $select->query()->fetch();
     $this->view->userCount = (int) $data['count'];
     // Reports
     $reportTable = Engine_Api::_()->getDbtable('reports', 'core');
     $select = new Zend_Db_Select($reportTable->getAdapter());
     $select->from($reportTable->info('name'), 'COUNT(report_id) as count')->where('`read` = ?', 0);
     $data = $select->query()->fetch();
     $this->view->reportCount = (int) $data['count'];
     // Plugins
     $moduleTable = Engine_Api::_()->getDbtable('modules', 'core');
     $select = new Zend_Db_Select($moduleTable->getAdapter());
     $select->from($moduleTable->info('name'), 'COUNT(TRUE) as count')->where('type = ?', 'extra');
     $data = $select->query()->fetch();
     $this->view->pluginCount = (int) $data['count'];
 }
 public function externalPhotoAction()
 {
     if (!$this->_helper->requireSubject()->isValid()) {
         return;
     }
     $user = Engine_Api::_()->core()->getSubject();
     // Get photo
     $photo = Engine_Api::_()->getItemByGuid($this->_getParam('photo'));
     if (!$photo || !$photo instanceof Core_Model_Item_Abstract || empty($photo->photo_id)) {
         $this->_forward('requiresubject', 'error', 'core');
         return;
     }
     if (!$photo->authorization()->isAllowed(null, 'view')) {
         $this->_forward('requireauth', 'error', 'core');
         return;
     }
     // Make form
     $this->view->form = $form = new User_Form_Edit_ExternalPhoto();
     $this->view->photo = $photo;
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $db = $user->getTable()->getAdapter();
     $db->beginTransaction();
     try {
         // Get the owner of the photo
         $photoOwnerId = null;
         if (isset($photo->user_id)) {
             $photoOwnerId = $photo->user_id;
         } else {
             if (isset($photo->owner_id) && (!isset($photo->owner_type) || $photo->owner_type == 'user')) {
                 $photoOwnerId = $photo->owner_id;
             }
         }
         // if it is from your own profile album do not make copies of the image
         if ($photo instanceof Album_Model_Photo && ($photoParent = $photo->getParent()) instanceof Album_Model_Album && $photoParent->owner_id == $photoOwnerId && $photoParent->type == 'profile') {
             // ensure thumb.icon and thumb.profile exist
             $newStorageFile = Engine_Api::_()->getItem('storage_file', $photo->file_id);
             $filesTable = Engine_Api::_()->getDbtable('files', 'storage');
             if ($photo->file_id == $filesTable->lookupFile($photo->file_id, 'thumb.profile')) {
                 try {
                     $tmpFile = $newStorageFile->temporary();
                     $image = Engine_Image::factory();
                     $image->open($tmpFile)->resize(200, 400)->write($tmpFile)->destroy();
                     $iProfile = $filesTable->createFile($tmpFile, array('parent_type' => $user->getType(), 'parent_id' => $user->getIdentity(), 'user_id' => $user->getIdentity(), 'name' => basename($tmpFile)));
                     $newStorageFile->bridge($iProfile, 'thumb.profile');
                     @unlink($tmpFile);
                 } catch (Exception $e) {
                     echo $e;
                     die;
                 }
             }
             if ($photo->file_id == $filesTable->lookupFile($photo->file_id, 'thumb.icon')) {
                 try {
                     $tmpFile = $newStorageFile->temporary();
                     $image = Engine_Image::factory();
                     $image->open($tmpFile);
                     $size = min($image->height, $image->width);
                     $x = ($image->width - $size) / 2;
                     $y = ($image->height - $size) / 2;
                     $image->resample($x, $y, $size, $size, 48, 48)->write($tmpFile)->destroy();
                     $iSquare = $filesTable->createFile($tmpFile, array('parent_type' => $user->getType(), 'parent_id' => $user->getIdentity(), 'user_id' => $user->getIdentity(), 'name' => basename($tmpFile)));
                     $newStorageFile->bridge($iSquare, 'thumb.icon');
                     @unlink($tmpFile);
                 } catch (Exception $e) {
                     echo $e;
                     die;
                 }
             }
             // Set it
             $user->photo_id = $photo->file_id;
             $user->save();
             // Insert activity
             // @todo maybe it should read "changed their profile photo" ?
             $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($user, $user, 'profile_photo_update', '{item:$subject} changed their profile photo.');
             if ($action) {
                 // We have to attach the user himself w/o album plugin
                 Engine_Api::_()->getDbtable('actions', 'activity')->attachActivity($action, $photo);
             }
         } else {
             $user->setPhoto($photo);
             // Insert activity
             $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($user, $user, 'profile_photo_update', '{item:$subject} added a new profile photo.');
             // Hooks to enable albums to work
             $newStorageFile = Engine_Api::_()->getItem('storage_file', $user->photo_id);
             $event = Engine_Hooks_Dispatcher::_()->callEvent('onUserProfilePhotoUpload', array('user' => $user, 'file' => $newStorageFile));
             $attachment = $event->getResponse();
             if (!$attachment) {
                 $attachment = $newStorageFile;
             }
             if ($action) {
                 // We have to attach the user himself w/o album plugin
                 Engine_Api::_()->getDbtable('actions', 'activity')->attachActivity($action, $attachment);
             }
         }
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     return $this->_forward('success', 'utility', 'core', array('messages' => array(Zend_Registry::get('Zend_Translate')->_('Set as profile photo')), 'smoothboxClose' => true));
 }
Beispiel #5
0
 public function externalPhotoAction()
 {
     if (!$this->_helper->requireSubject()->isValid()) {
         return;
     }
     $user = Engine_Api::_()->core()->getSubject();
     // Get photo
     $photo = Engine_Api::_()->getItemByGuid($this->_getParam('photo'));
     if (!$photo || !$photo instanceof Core_Model_Item_Collectible || empty($photo->photo_id)) {
         $this->_forward('requiresubject', 'error', 'core');
         return;
     }
     if (!$photo->getCollection()->authorization()->isAllowed(null, 'view')) {
         $this->_forward('requireauth', 'error', 'core');
         return;
     }
     // Make form
     $this->view->form = $form = new User_Form_Edit_ExternalPhoto();
     $this->view->photo = $photo;
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $db = $user->getTable()->getAdapter();
     $db->beginTransaction();
     $photo_id;
     try {
         $photo_id = $photo->owner_id;
     } catch (Exception $e) {
         $photo_id = $photo->user_id;
     }
     try {
         if ($photo_id == $user->user_id) {
             // if it is your own album do not make copies of the image
             $user->photo_id = $photo->file_id;
             $user->save();
             $newStorageFile = Engine_Api::_()->getItem('storage_file', $user->photo_id);
         } else {
             // else copy the photo into your own collection
             $user->setPhoto($photo);
             $newStorageFile = Engine_Api::_()->getItem('storage_file', $user->photo_id);
             // Insert activity
             $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($user, $user, 'profile_photo_update', '{item:$subject} added a new profile photo.');
             // Hooks to enable albums to work
             $event = Engine_Hooks_Dispatcher::_()->callEvent('onUserProfilePhotoUpload', array('user' => $user, 'file' => $newStorageFile));
             $attachment = $event->getResponse();
             if (!$attachment) {
                 $attachment = $newStorageFile;
             }
             // We have to attach the user himself w/o album plugin
             Engine_Api::_()->getDbtable('actions', 'activity')->attachActivity($action, $attachment);
         }
         $db->commit();
         return $this->_forward('success', 'utility', 'core', array('messages' => array(Zend_Registry::get('Zend_Translate')->_('Set as profile photo')), 'smoothboxClose' => true));
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
 }
Beispiel #6
0
 public function photoPopupAction()
 {
     // In smoothbox
     $this->_helper->layout->setLayout('default-simple');
     $this->view->user = $user = Engine_Api::_()->core()->getSubject();
     $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
     // Get form
     $this->view->form = $form = new User_Form_Edit_PhotoPopup();
     if (empty($user->photo_id)) {
         $form->removeElement('remove');
     }
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     $values = $form->getValues();
     $isClose = true;
     if (!empty($values['url'])) {
         $isClose = false;
         $filename = $this->copyImg($this->getImageURL($values['url']), md5($values['url']));
         if ($filename) {
             $user->setPhoto($filename);
             @unlink($filename);
             $iMain = Engine_Api::_()->getItem('storage_file', $user->photo_id);
             // Insert activity
             $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($user, $user, 'profile_photo_update', '{item:$subject} added a new profile photo.');
             // Hooks to enable albums to work
             if ($action) {
                 $event = Engine_Hooks_Dispatcher::_()->callEvent('onUserProfilePhotoUpload', array('user' => $user, 'file' => $iMain));
                 $attachment = $event->getResponse();
                 if (!$attachment) {
                     $attachment = $iMain;
                 }
                 // We have to attach the user himself w/o album plugin
                 Engine_Api::_()->getDbtable('actions', 'activity')->attachActivity($action, $attachment);
             }
         }
     }
     // Uploading a new photo
     if ($form->Filedata->getValue() !== null) {
         $isClose = false;
         $db = $user->getTable()->getAdapter();
         $db->beginTransaction();
         try {
             $fileElement = $form->Filedata;
             $user->setPhoto($fileElement);
             $iMain = Engine_Api::_()->getItem('storage_file', $user->photo_id);
             // Insert activity
             $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($user, $user, 'profile_photo_update', '{item:$subject} added a new profile photo.');
             // Hooks to enable albums to work
             if ($action) {
                 $event = Engine_Hooks_Dispatcher::_()->callEvent('onUserProfilePhotoUpload', array('user' => $user, 'file' => $iMain));
                 $attachment = $event->getResponse();
                 if (!$attachment) {
                     $attachment = $iMain;
                 }
                 // We have to attach the user himself w/o album plugin
                 Engine_Api::_()->getDbtable('actions', 'activity')->attachActivity($action, $attachment);
             }
             $db->commit();
         } catch (Engine_Image_Adapter_Exception $e) {
             $db->rollBack();
             $form->addError(Zend_Registry::get('Zend_Translate')->_('The uploaded file is not supported or is corrupt.'));
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
     } else {
         if ($form->getValue('coordinates') !== '') {
             $storage = Engine_Api::_()->storage();
             $iMain = $storage->get($user->photo_id, 'thumb.main');
             $iProfile = $storage->get($user->photo_id, 'thumb.profile');
             $iSquare = $storage->get($user->photo_id, 'thumb.icon');
             // Read into tmp file
             $mName = $iMain->getStorageService()->temporary($iMain);
             $pName = dirname($mName) . '/p_' . basename($mName);
             $iName = dirname($mName) . '/nis_' . basename($mName);
             list($x, $y, $w, $h) = explode(':', $form->getValue('coordinates'));
             $image = Engine_Image::factory();
             $image->open($mName)->resample($x + 0.1, $y + 0.1, $w - 0.1, $h - 0.1, 48, 48)->write($iName)->destroy();
             $iSquare->store($iName);
             $image->open($mName)->resample($x + 0.1, $y + 0.1, $w - 0.1, $h - 0.1, 200, 200)->write($pName)->destroy();
             $iProfile->store($pName);
             // Remove temp files
             @unlink($pName);
             @unlink($iName);
         }
     }
     $form->reset();
     if ($isClose) {
         return $this->_forward('success', 'utility', 'core', array('messages' => array(Zend_Registry::get('Zend_Translate')->_('Closed!')), 'format' => 'smoothbox', 'smoothboxClose' => true, 'parentRefresh' => true));
     }
 }