private static function getFB() { $permisitos = 'email, user_birthday, user_location, publish_stream, manage_pages, offline_access'; if (self::$fb) { return self::$fb; } $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap'); $options = $bootstrap->getOptions(); $fb = new Facebook_Facebook(array('appId' => $options['facebook']['appid'], 'secret' => $options['facebook']['appsecret'], 'cookie' => true, 'req_perms' => $permisitos)); self::$fb = $fb; return self::$fb; }
public function agregarpublicacionAction() { $idUsuario = Zend_Registry::get('id_usuario'); $form = new Application_Form_Agregarpublicidad(); if ($this->getRequest()->isPost()) { if ($form->isValid($this->_getAllParams())) { $model = new Application_Model_DbTable_Publicaciones(); /* Traer Datos desde Formulario */ $titulo = $form->getValue('titulo'); $contenido = $form->getValue('contenido'); $idPublicacion = $form->getValue('tipopublicacion'); $fecha_publicacion = new Zend_Db_Expr('NOW()'); $fecha_vigencia = $form->getValue('datepicker'); // cambiar //Transformacion $fecha_vigencia2 = date('Y-m-d H:i:s', strtotime($fecha_vigencia)); $nueva_foto = $form->getValue('element'); if ($nueva_foto != NULL) { $foto = strtolower($nueva_foto); $upload = new Zend_File_Transfer_Adapter_Http(); $upload->setDestination(APPLICATION_PATH . '/../public/images/publicaciones/'); $upload->addFilter('rename', array('target' => APPLICATION_PATH . '/../public/images/publicaciones/' . $foto, 'overwrite' => true)); try { $upload->receive(); } catch (Zend_File_Transfer_Exception $e) { $e->getMessage(); } } else { $foto = 'default_publicacion.jpg'; } /* * ******************************** */ $model->save($titulo, $contenido, $foto, $fecha_vigencia2, $idUsuario, $idPublicacion, $fecha_publicacion); // Posteo hacia Facebook /* Datos Facebook * * mail: capicua.contacto@gmail.com * pass: capicuarestobar */ $user = Capicua_Facebook::getUser(); if ($user) { try { $post_url = '/452679718153572/feed'; $userMessage = $titulo; $msg_body = array('message' => $userMessage, 'name' => $userMessage, 'caption' => 'Capicua Restobar', 'description' => $contenido, 'picture' => 'http://capicua-restobar.cl/images/publicaciones/' . $foto, 'actions' => array(array('name' => 'Capicua Restobar', 'link' => 'http://capicua-restobar.cl'))); $postResult = Capicua_Facebook::api($post_url, 'post', $msg_body); } catch (FacebookApiException $e) { echo $e->getMessage(); } if ($postResult) { return $this->_redirect('/publicaciones'); } } return $this->_redirect('/publicaciones'); } } $this->view->form = $form; }