/**
  * Add post submit
  */
 public function submitAddPostForm($form)
 {
     $Profiles = new Application_Model_Profiles();
     $current_user_id = Zend_Auth::getInstance()->getIdentity()->id;
     // default user wall
     $profile = Zend_Auth::getInstance()->getIdentity();
     // writing on other user wall?
     if ($this->request->getParam('name')) {
         $profile = $Profiles->getProfile($this->request->getParam('name'));
     }
     if (!$this->canPostHere($current_user_id, $profile->type, $profile->id, $profile->owner)) {
         return false;
     }
     // submit?
     if (isset($_POST['identifier']) && $_POST['identifier'] == 'AddPost' && $form->isValid($_POST)) {
         $content = $form->getValue('content');
         $content = Application_Plugin_Common::preparePost($content);
         $Posts = new Application_Model_Posts();
         // save received filename to session form_unique_key
         $form_unique_key = (int) $_POST['form_unique_key'];
         $attached_files = @glob(TMP_PATH . '/post_' . Zend_Auth::getInstance()->getIdentity()->name . '_' . $form_unique_key . '*');
         if ($this->show_privacy) {
             $Posts->addPost($content, $profile->id, Zend_Registry::get('default_privacy'), $attached_files);
         } else {
             // most restrictive, for groups and pages privacy is controlled when fetching posts
             $Posts->addPost($content, $profile->id, 'friends', $attached_files);
         }
         // flush content
         $form->getElement('content')->setValue('');
         $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
         $redirector->gotoUrl($this->callbackurl);
     }
     return $form;
 }
Esempio n. 2
0
 /**
  * add image
  *
  * albums: 1 - posts
  */
 public function addImage($file_name, $file_size, $owner_id, $uploaded_by, $post_id, $album_id, $original = '')
 {
     $random = Application_Plugin_Common::getRandomString();
     $data = array('uid' => $random, 'file_name' => $file_name, 'original' => $original, 'owner_id' => $owner_id, 'uploaded_by' => $uploaded_by, 'post_id' => $post_id, 'album_id' => $album_id, 'size' => $file_size, 'created_on' => Application_Plugin_Common::now(), 'is_hidden' => 0);
     $ret = $this->insert($data);
     return $ret;
 }
Esempio n. 3
0
function autocomplete_search_users($term, $storage_url)
{
    $Profiles = new Application_Model_Profiles();
    // quote
    $search_term = $Profiles->getDefaultAdapter()->quote("%{$term}%");
    if (Zend_Auth::getInstance()->hasIdentity()) {
        $user_id = (int) Zend_Auth::getInstance()->getIdentity()->id;
        $join = "LEFT JOIN connections c ON c.follow_id = p.id AND c.user_id = " . $user_id;
        $order = "ORDER BY c.created_on DESC, p.type DESC";
    } else {
        $join = "";
        $order = "ORDER BY p.type DESC";
    }
    $sql = "\n\tSELECT\n\tp.name AS label,\n\tp.screen_name AS name,\n\tp.avatar as avatar\n\t\n\tFROM profiles p\n\t{$join}\n\t\n\tWHERE p.is_hidden = 0\n\tAND (p.activationkey = 'activated' OR p.type != 'user')\n\tAND (p.name like {$search_term} OR p.screen_name like {$search_term})\n\t\n\t{$order}\n\t\n\tLIMIT 5\n\t";
    $result = $Profiles->getDefaultAdapter()->fetchAll($sql);
    if (!$result) {
        die;
    }
    foreach ($result as &$user) {
        $user['link'] = Application_Plugin_Common::getFullBaseUrl() . '/' . $user['label'];
        $user['avatar'] = $storage_url . $user['avatar'];
    }
    echo json_encode($result);
    // stop view render
    die;
}
Esempio n. 4
0
 /**
  * Create an album
  */
 public function createAlbum($album_name, $description)
 {
     // protected names
     if ($album_name == 'cover' || $album_name == 'avatar') {
         return false;
     }
     $user_id = Zend_Auth::getInstance()->getIdentity()->id;
     $data = array('user_id' => $user_id, 'name' => $album_name, 'description' => $description, 'cover_image' => '', 'created_on' => Application_Plugin_Common::now());
     return $this->insert($data);
 }
Esempio n. 5
0
 /**
  * Send message
  */
 public function sendMessage($to_user_id, $content, $message_type = 'pm')
 {
     if (!Zend_Auth::getInstance()->hasIdentity() || strlen($content) < 1) {
         return false;
     }
     $from_user_id = Zend_Auth::getInstance()->getIdentity()->id;
     if (!$to_user_id || $from_user_id == $to_user_id) {
         return false;
     }
     $ret = $this->insert(array('type' => $message_type, 'from_user_id' => $from_user_id, 'to_user_id' => $to_user_id, 'content' => $content, 'is_new' => 1, 'is_hidden' => 0, 'sent_on' => Application_Plugin_Common::now()));
     $Notifications = new Application_Model_Notifications();
     $Notifications->pushNotification(array($to_user_id), 8, 'profile', $from_user_id, false);
     return $ret;
 }
 /**
  * move file from temp to storage
  */
 public function moveFileToStorage($source_file_name, $context, $delete_tmp = true)
 {
     $extension = strtolower(pathinfo($source_file_name, PATHINFO_EXTENSION));
     $random_string = Application_Plugin_Common::getRandomString();
     $new_filename = $random_string . '.' . $extension;
     $source = TMP_PATH . '/' . $source_file_name;
     $folder = $this->getResourceFolder($context);
     $destination = $folder . $new_filename;
     if ($delete_tmp) {
         rename($source, PUBLIC_PATH . $destination);
     } else {
         copy($source, PUBLIC_PATH . $destination);
     }
     return $new_filename;
 }
 public function errorAction()
 {
     $this->_helper->_layout->setLayout('layout_errors');
     $this->_helper->viewRenderer->setNoRender(true);
     // default application error
     $this->getResponse()->setHttpResponseCode(500);
     $this->view->message = $this->view->translate('Application error');
     // log errors
     $logtext = "\n------------------------------------------------------------\n";
     $errors = $this->_getParam('error_handler');
     if (isset($errors->type)) {
         switch ($errors->type) {
             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                 // 404 error -- controller or action not found
                 $this->getResponse()->setHttpResponseCode(404);
                 $this->view->message = $this->view->translate('Error 404 - Page not found');
                 break;
         }
     }
     $logtext .= $this->view->message;
     $logtext .= "\n";
     if (isset($errors->exception)) {
         $logtext .= isset($errors->exception->information) ? $errors->exception->information : '';
         $logtext .= "\n";
         $logtext .= $errors->exception->getMessage();
         $logtext .= "\n";
         $logtext .= $errors->exception->getTraceAsString();
     }
     // conditionally display exceptions
     if (APPLICATION_ENV != 'production' && isset($errors->exception) && $this->getResponse()->getHttpResponseCode() != 404) {
         $this->view->exception = $errors->exception;
     }
     if (APPLICATION_ENV != 'production' && isset($errors->request) && $this->getResponse()->getHttpResponseCode() != 404) {
         $this->view->request = $errors->request;
     }
     if (isset($errors->request)) {
         $logtext .= var_export($errors->request->getParams(), true);
         $logtext .= "\n";
     } else {
         $this->view->request = '';
     }
     // log errors but not 404s
     if ($this->getResponse()->getHttpResponseCode() != 404) {
         Application_Plugin_Common::log($logtext);
     }
 }
Esempio n. 8
0
 /**
  * Like toggle
  */
 public function toggleLike($resource_id, $resource_type)
 {
     if (!Zend_Auth::getInstance()->hasIdentity() || !$resource_id || !$resource_type) {
         return null;
     }
     $user_id = Zend_Auth::getInstance()->getIdentity()->id;
     if ($this->isLiked($resource_id, $resource_type)) {
         $result = $this->delete(array('resource_id = ?' => (int) $resource_id, 'resource_type = ?' => $resource_type, 'user_id = ?' => (int) $user_id));
         $state = 0;
     } else {
         $data = array('user_id' => (int) $user_id, 'resource_type' => $resource_type, 'resource_id' => (int) $resource_id, 'created_on' => Application_Plugin_Common::now());
         $ret = $this->insert($data);
         $state = 1;
     }
     $likes_count = $this->getLikesCount($resource_id, $resource_type);
     // notify author
     $Notifications = new Application_Model_Notifications();
     if ($state == 1) {
         // find resource author
         switch ($resource_type) {
             case 'post':
                 $Posts = new Application_Model_Posts();
                 $resource_author = array($Posts->getPostAuthorId($resource_id));
                 break;
             case 'comment':
                 $Comments = new Application_Model_Comments();
                 $resource_author = array($Comments->getCommentAuthorId($resource_id));
                 break;
             case 'image':
                 $Images = new Application_Model_Images();
                 $resource_author = array($Images->getImageOwnerId($resource_id));
                 break;
             default:
                 $resource_author = false;
                 break;
         }
         if ($resource_author) {
             // notify resource owner
             $Notifications->pushNotification($resource_author, 2, 'like', $ret);
         }
     }
     return array('count' => $likes_count, 'state' => $state);
 }
Esempio n. 9
0
 /**
  *
  * General settings
  *
  */
 public function init()
 {
     $cname = explode('_', get_class());
     $this->preInit(end($cname));
     // use template file
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/Settings.phtml'))));
     // load settings
     $AppOptions = new Application_Model_AppOptions();
     $all_meta = $AppOptions->getAllOptions();
     // fields
     $php_post_max_size = Application_Plugin_Common::returnBytes(ini_get('post_max_size'));
     $php_upload_max_filesize = Application_Plugin_Common::returnBytes(ini_get('upload_max_filesize'));
     $info_class = '';
     if ($all_meta['max_file_upload_size'] > $php_post_max_size || $all_meta['max_file_upload_size'] > $php_upload_max_filesize) {
         $info_class = 'warning';
     }
     $filesize_php_info = '<span class="' . $info_class . '">(' . $this->translator->translate('php ini settings:') . ' post_max_size = ' . $php_post_max_size . ', upload_max_filesize = ' . $php_upload_max_filesize . ')</span>';
     $max_file_upload_size = new Zend_Form_Element_Text('max_file_upload_size');
     $max_file_upload_size->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Max file upload size in bytes') . ' ' . $filesize_php_info)->setValidators(array('digits'))->setRequired(true)->setValue(isset($all_meta['max_file_upload_size']) ? $all_meta['max_file_upload_size'] : '1048576')->setAttrib('class', 'form-control');
     $max_images_per_post = new Zend_Form_Element_Text('max_images_per_post');
     $max_images_per_post->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Max images per post'))->setValidators(array('digits'))->setRequired(true)->setValue(isset($all_meta['max_images_per_post']) ? $all_meta['max_images_per_post'] : '5')->setAttrib('class', 'form-control');
     $max_files_per_user = new Zend_Form_Element_Text('max_files_per_user');
     $max_files_per_user->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Max files per user'))->setValidators(array('digits'))->setRequired(true)->setValue(isset($all_meta['max_files_per_user']) ? $all_meta['max_files_per_user'] : '******')->setAttrib('class', 'form-control');
     $max_storage_per_user = new Zend_Form_Element_Text('max_storage_per_user');
     $max_storage_per_user->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Max storage space per user (in bytes)'))->setValidators(array('digits'))->setRequired(true)->setValue(isset($all_meta['max_storage_per_user']) ? $all_meta['max_storage_per_user'] : '******')->setAttrib('class', 'form-control');
     $resample_images = new Zend_Form_Element_Checkbox('resample_images');
     $resample_images->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($all_meta['resample_images']) && $all_meta['resample_images'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Resample uploaded images'))->setCheckedValue("1")->setUncheckedValue("0");
     $keep_original = new Zend_Form_Element_Checkbox('keep_original');
     $keep_original->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($all_meta['keep_original']) && $all_meta['keep_original'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Keep original file'))->setCheckedValue("1")->setUncheckedValue("0");
     $resample_maxwidth = new Zend_Form_Element_Text('resample_maxwidth');
     $resample_maxwidth->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Resample image max width'))->setValidators(array('digits'))->setRequired(true)->setValue(isset($all_meta['resample_maxwidth']) ? $all_meta['resample_maxwidth'] : '400')->setAttrib('class', 'form-control');
     $resample_maxheight = new Zend_Form_Element_Text('resample_maxheight');
     $resample_maxheight->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Resample image max height'))->setValidators(array('digits'))->setRequired(true)->setValue(isset($all_meta['resample_maxwidth']) ? $all_meta['resample_maxheight'] : '400')->setAttrib('class', 'form-control');
     $submit = new Zend_Form_Element_Submit('submitbtn');
     $submit->setDecorators(array('ViewHelper'))->setLabel($this->translator->translate('Update'))->setAttrib('class', 'submit btn btn-default');
     $this->addElements(array($max_file_upload_size, $max_images_per_post, $max_files_per_user, $max_storage_per_user, $resample_images, $keep_original, $resample_maxwidth, $resample_maxheight, $submit));
     $this->postInit();
 }
Esempio n. 10
0
 /**
  * Report resource
  */
 public function report($resource_id, $resource_type, $reason)
 {
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         return null;
     }
     $user_id = Zend_Auth::getInstance()->getIdentity()->id;
     if ($this->isReported($resource_id, $resource_type)) {
         return false;
     }
     $data = array('user_id' => $user_id, 'resource_type' => $resource_type, 'resource_id' => $resource_id, 'reason' => $reason, 'created_on' => Application_Plugin_Common::now(), 'reviewed_by' => 0, 'is_accepted' => 0);
     // new report email notification
     if (Zend_Registry::get('config')->get('report_notify_email')) {
         $to = Zend_Registry::get('config')->get('report_notify_email');
         $subject = 'New report';
         // prepare phtml email template
         $mail_template_path = APPLICATION_PATH . '/views/emails/';
         $view = new Zend_View();
         $view->setScriptPath($mail_template_path);
         $body = $view->render('newreport.phtml');
         $ret = Application_Plugin_Common::sendEmail($to, $subject, $body, true);
     }
     return $this->insert($data);
 }
Esempio n. 11
0
/**
 *
 * Load & submit invitation form
 *
*/
function getBetterInvitaionForm()
{
    require_once 'InviteForm.php';
    $form = new Addon_Form_BetterInvite();
    $translator = Zend_Registry::get('Zend_Translate');
    // form is submitted and valid?
    if (isset($_POST['identifier']) && $_POST['identifier'] == 'Invite') {
        if ($form->isValid($_POST)) {
            $to = $form->getValue('email');
            $subject = $translator->translate('Invitation');
            $base_url = Application_Plugin_Common::getFullBaseUrl();
            $user_id = Zend_Auth::getInstance()->getIdentity()->id;
            $user_name = Zend_Auth::getInstance()->getIdentity()->name;
            $user_screenname = Zend_Auth::getInstance()->getIdentity()->screen_name;
            $invitation_link = $base_url . '/?ref=' . $user_id;
            $profile_link = $base_url . '/' . $user_name . '/?ref=' . $user_id;
            // prepare phtml email template
            $view = new Zend_View();
            $view->setScriptPath(realpath(dirname(__FILE__)));
            $view->assign('invitation_link', $invitation_link);
            $body = $view->render('email.phtml');
            $body = str_replace("NETWORK_NAME", Zend_Registry::get('config')->get('network_name'), $body);
            $body = str_replace("INVITATION_LINK", $invitation_link, $body);
            $body = str_replace("INVITED_BY_SCREENNAME", $user_screenname, $body);
            $body = str_replace("INVITED_BY_PROFILE_LINK", $profile_link, $body);
            // send email
            $ret = Application_Plugin_Common::sendEmail($to, $subject, $body, true);
            // show info message
            if ($ret) {
                Application_Plugin_Alerts::success(Zend_Registry::get('Zend_Translate')->translate('Invitation has been sent'), 'on');
            }
        }
        // flush field
        $form->getElement('email')->setValue('');
    }
    return $form;
}
Esempio n. 12
0
 /**
  * Lost password
  */
 public function submitLostPasswordForm($form)
 {
     $front = Zend_Controller_Front::getInstance();
     if ($form->isValid($_POST)) {
         $name = $form->getValue('name');
         $Profiles = new Application_Model_Profiles();
         $nameRow = $Profiles->getProfileByField('name', $name);
         // maybe user is entering email?
         $nameRow_byEmail = $Profiles->getProfileByField('email', $name);
         if ($nameRow_byEmail) {
             $nameRow = $Profiles->getProfileByField('name', $nameRow_byEmail->name);
         }
         if ($nameRow && $Profiles->isActivated($nameRow->name) && $nameRow->is_hidden == 0) {
             $resetPasswordKey = $Profiles->generateActivationKey($nameRow->email);
             $ProfilesMeta = new Application_Model_ProfilesMeta();
             $profile = $ProfilesMeta->metaUpdate('password_reset', $resetPasswordKey, $nameRow->id);
             // password recovery email
             $ret = Application_Plugin_Common::sendRecoveryEmail($nameRow->email, $name, $resetPasswordKey);
             // show info message
             if ($ret) {
                 Application_Plugin_Alerts::success(Zend_Registry::get('Zend_Translate')->translate('We have sent an email to your registered email address. Follow the instructions and you will be able to enter a new password.'), 'off');
             }
             // flush url
             Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl('');
         } else {
             sleep(2);
             $form->getElement('name')->setErrors(array(Zend_Registry::get('Zend_Translate')->translate('Username does not exists')));
         }
     }
     return $form;
 }
Esempio n. 13
0
/**
 * Register with facebook
 */
function registerWithFacebook()
{
    // flush if already logged in
    Zend_Auth::getInstance()->clearIdentity();
    $session = new Zend_Session_Namespace('Default');
    $email = $session->fb_user_email;
    $avatar = $session->fb_avatar;
    // do not allow direct access - without fb_user_email inside session
    if (!$session->fb_user_email) {
        Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl('');
    }
    require_once 'Form.php';
    $registerwithfacebook_form = new Addon_FacebookRegisterForm();
    $Profiles = new Application_Model_Profiles();
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        if ($registerwithfacebook_form->isValid($_POST)) {
            $name = $registerwithfacebook_form->getValue('name');
            $user = $Profiles->createRow();
            $user->name = $name;
            $user->email = $email;
            $user->password = '';
            $user->activationkey = 'activated';
            $user->language = Zend_Registry::get('config')->get('default_language');
            $user = $Profiles->createNewUser($user, 'facebook');
            // update last login date
            $ProfilesMeta = new Application_Model_ProfilesMeta();
            $ProfilesMeta->metaUpdate('last_login', Application_Plugin_Common::now(), $user->id);
            $Storage = new Application_Model_Storage();
            $StorageAdapter = $Storage->getAdapter();
            $defaultres = 64;
            $bigres = Zend_Registry::get('config')->get('avatar_size') ? Zend_Registry::get('config')->get('avatar_size') : $defaultres;
            // get the image
            $c = new Zend_Http_Client();
            $c->setUri($avatar);
            $result = $c->request('GET');
            $img = imagecreatefromstring($result->getBody());
            // create regular avatar image, resample and store
            $imgname = 'profileimage_' . $name . '.jpg';
            imagejpeg($img, TMP_PATH . '/' . $imgname);
            Application_Plugin_ImageLib::resample(TMP_PATH . '/' . $imgname, TMP_PATH . '/' . $imgname, $defaultres, $defaultres, false);
            $new_filename = $StorageAdapter->moveFileToStorage($imgname, 'avatar');
            $Profiles->updateField($name, 'avatar', $new_filename);
            // create big avatar image, resample and store
            $imgname = 'bigprofileimage_' . $name . '.jpg';
            imagejpeg($img, TMP_PATH . '/' . $imgname);
            Application_Plugin_ImageLib::resample(TMP_PATH . '/' . $imgname, TMP_PATH . '/' . $imgname, $bigres, $bigres, false);
            $big_avatar = $StorageAdapter->moveFileToStorage($imgname, 'avatar');
            $ProfilesMeta->metaUpdate('big_avatar', $big_avatar, $user->id);
            // free img resource
            imagedestroy($img);
            // login user
            $emailAuthAdapter = Application_Plugin_Common::getEmailAuthAdapter($email);
            $auth = Zend_Auth::getInstance();
            $auth->authenticate($emailAuthAdapter);
            $identity = $emailAuthAdapter->getResultRowObject();
            $authStorage = $auth->getStorage();
            $authStorage->write($identity);
            // clear session data
            $session->fb_user_email = '';
            $session->fb_user_display_name = '';
            $session->fb_avatar = '';
            $user_id = $user->id;
            // trigger hooks
            Zend_Registry::get('hooks')->trigger('hook_firsttimelogin', $user_id);
            // show welcome message
            Application_Plugin_Alerts::success(Zend_Registry::get('Zend_Translate')->translate('Welcome to the network.'), 'on');
            Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl('');
        }
    }
    echo $registerwithfacebook_form;
}
Esempio n. 14
0
 * @author Milos Stojanovic
 * @copyright 2013 interactive32.com
 */
$this->attach('hook_data_renderoutput', 10, function (&$data) {
    $content =& $data['content'];
    $content = ' ' . $content;
    //simple: $content = preg_replace("#([\t\r\n ])([a-z0-9]+?){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i", '\1<a target="_blank" href="\2://\3">\3</a>', $content);
    $content = preg_replace_callback("#([\t\r\n ])([a-z0-9]+?){1}://([\\w\\-]+\\.([\\w\\-]+\\.)*[\\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i", function ($matches) {
        $baseUrl = Application_Plugin_Common::getFullBaseUrl();
        $matched_url = $matches[2] . '://' . $matches[3];
        $new_windown = '';
        // open in new window if the target is outsite this domain
        if (strpos($matched_url, $baseUrl) === false) {
            $new_windown = 'target="_blank"';
        }
        return $matches[1] . '<a ' . $new_windown . ' href="' . $matched_url . '">' . $matched_url . '</a>';
    }, $content);
    //simple: $content = preg_replace("#([\t\r\n ])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i", '\1<a target="_blank" href="http://\2.\3">\2.\3</a>', $content);
    $content = preg_replace_callback("#([\t\r\n ])(www|ftp)\\.(([\\w\\-]+\\.)*[\\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i", function ($matches) {
        $baseUrl = Application_Plugin_Common::getFullBaseUrl();
        $matched_url = 'http://' . $matches[2] . '.' . $matches[3];
        $new_windown = '';
        // open in new window if the target is outsite this domain
        if (strpos($matched_url, $baseUrl) === false) {
            $new_windown = 'target="_blank"';
        }
        return $matches[1] . '<a ' . $new_windown . ' href="' . $matched_url . '">' . $matched_url . '</a>';
    }, $content);
    $content = preg_replace("#([\n ])([a-z0-9\\-_.]+?)@([\\w\\-]+\\.([\\w\\-\\.]+\\.)*[\\w]+)#i", "\\1<a target=\"_blank\" href=\"mailto:\\2@\\3\">\\2@\\3</a>", $content);
    $content = substr($content, 1);
});
 /**
  * Edit comment
  */
 public function editcommentAction()
 {
     $Reports = new Application_Model_Reports();
     $total_counts = $Reports->getTotalCount();
     $this->buildMenu($total_counts);
     $request = $this->getRequest();
     $page = (int) $request->getParam('page');
     $comment_id = (int) $request->getParam('comment');
     $Comments = new Application_Model_Comments();
     $comment = $Comments->getComment($comment_id);
     // load and fill up form
     $edit_comment_form = new Application_Form_EditComment();
     $edit_comment_form->getElement('comment')->setValue($comment['content']);
     $this->view->edit_comment_form = $edit_comment_form;
     if ($request->isPost() && $edit_comment_form->isValid($_POST)) {
         $comment_content = $edit_comment_form->getElement('comment')->getValue();
         $comment_content = Application_Plugin_Common::prepareComment($comment_content);
         // drop on false
         if ($comment_content === false) {
             return;
         }
         $Comments->updateComment($comment_id, $comment_content);
         Application_Plugin_Alerts::success($this->view->translate('Comment updated'));
         if ($page > 0) {
             $this->redirect('reports/reviewcomments/page/' . $page);
         }
     }
 }
Esempio n. 16
0
 public function GetRandomNum()
 {
     return Application_Plugin_Common::getRandomNum();
 }
 /**
  */
 public function setImage()
 {
     // Form Submitted...
     if ($this->request->isPost() && $this->form->isValid($_POST)) {
         // file uploaded?
         if ($this->form->{$this->file_element}->isUploaded()) {
             $this->form->{$this->file_element}->receive();
             // must have
             $receive_path = $this->form->{$this->file_element}->getFileName();
             $filename = $this->form->{$this->file_element}->getValue();
             $extension = strtolower(pathinfo($receive_path, PATHINFO_EXTENSION));
             if ($this->profile_name) {
                 // delete old tmp image files
                 $Storage = new Application_Model_Storage();
                 $StorageAdapter = $Storage->getAdapter();
                 $StorageAdapter->deleteOldTmpFiles(0, 'profileimage_' . $this->profile_name);
                 $tmp_filename = 'profileimage_' . $this->profile_name . '.' . $extension;
                 // move new file to tmp folder
                 rename($receive_path, TMP_PATH . '/' . $tmp_filename);
                 // check if valid image
                 if (!Application_Plugin_ImageLib::isValidImage(TMP_PATH . '/' . $tmp_filename)) {
                     unlink(TMP_PATH . '/' . $tmp_filename);
                     Application_Plugin_Alerts::error($this->translator->translate('Server-side error'), 'off');
                     $this->redirector->gotoUrl();
                     return;
                 }
                 Application_Plugin_Alerts::success($this->translator->translate('You can adjust the picture here'), 'off');
                 // go back to current page after editing
                 $base_url = Application_Plugin_Common::getFullBaseUrl(false);
                 $callback_url = $base_url . $this->request->getRequestUri() . '/edit_done/1';
                 // save params to session and redirect to edit page
                 $session = new Zend_Session_Namespace('Default');
                 $pass_params = array('tmp_image' => $tmp_filename, 'image_type' => $this->image_type, 'callback' => $callback_url, 'profile_name' => $this->profile_name);
                 $session->pass_params = $pass_params;
                 $this->redirector->gotoUrl('images/edit');
             } else {
                 // here we store site settings images
                 // i.e. network background image
                 $this->form->{$this->file_element}->receive();
                 // must have
                 $receive_path = $this->form->{$this->file_element}->getFileName();
                 $filename = $this->form->{$this->file_element}->getValue();
                 $extension = strtolower(pathinfo($receive_path, PATHINFO_EXTENSION));
                 $file_name = $this->image_type . '.' . $extension;
                 // move new file to public image folder
                 rename($receive_path, PUBLIC_PATH . '/images/' . $file_name);
                 // store to app settings & refresh
                 $app_option_key = $this->image_type;
                 $AppOptions = new Application_Model_AppOptions();
                 $AppOptions->updateOption($app_option_key, $file_name);
                 $current_config = Zend_Registry::get('config');
                 $current_config->{$app_option_key} = $file_name;
                 Zend_Registry::set('config', $current_config);
                 Application_Plugin_Alerts::success($this->translator->translate('Image uploaded'), 'off');
                 $base_url = Application_Plugin_Common::getFullBaseUrl(false);
                 $callback_url = $base_url . $this->request->getRequestUri();
                 // flush url
                 $this->redirector->gotoUrl($callback_url);
             }
         } else {
             if ($this->is_requiered) {
                 // nothing to upload
                 Application_Plugin_Alerts::error($this->translator->translate('Please choose a picture'), 'off');
             }
         }
     }
     // somethig went wrong, image too big?
     if ($this->request->isPost() && !$this->form->isValid($_POST)) {
         Application_Plugin_Alerts::error($this->translator->translate('File not allowed or too big'), 'off');
     }
 }
Esempio n. 18
0
 /**
  * Create new page - add defaults & save
  */
 public function createNewPage(Application_Model_Profiles_Row $profile)
 {
     $profile->type = 'page';
     $profile->avatar = 'default/pages.jpg';
     $profile->cover = 'default/' . rand(1, 3) . '.jpg';
     $profile->is_hidden = 0;
     try {
         $created_id = $profile->save();
     } catch (Zend_Db_Exception $e) {
         Application_Plugin_Common::log($e->getMessage());
     }
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $ProfilesMeta->metaUpdate('date_created', Application_Plugin_Common::now(), $created_id);
     $user_id = Zend_Auth::getInstance()->getIdentity()->id;
     return $profile;
 }
Esempio n. 19
0
 /**
  * Send recovery email
  */
 public static function sendRecoveryEmail($email, $name, $key)
 {
     // password recovery email
     $subject = Zend_Registry::get('Zend_Translate')->translate('New Password:'******'/editprofile/recoverpassword/key/' . $key;
     // prepare phtml email template
     $mail_template_path = APPLICATION_PATH . '/views/emails/';
     $view = new Zend_View();
     $view->setScriptPath($mail_template_path);
     $view->assign('recovery_link', $pw_recovery_url);
     $body = $view->render('resetpassword.phtml');
     $ret = Application_Plugin_Common::sendEmail($email, $subject, $body, true);
     return $ret;
 }
Esempio n. 20
0
 public function fixData($data, $override_language = false)
 {
     $baseURL = Application_Plugin_Common::getFullBaseUrl();
     $transl = Zend_Registry::get('Zend_Translate');
     // set default language to network default
     $transl_default = Zend_Registry::get('Zend_Translate');
     if ($override_language) {
         $transl_default->setLocale(Zend_Registry::get('config')->get('default_language'));
     }
     foreach ($data as &$row) {
         $row['bulk_notifications'] = json_decode($row['bulk_notifications'], true);
         $row['html_link'] = '';
         $row['do_send_email'] = true;
         // default, can be overriden
         $row['view_from_name'] = $row['profile_name'];
         $row['view_from_screen_name'] = $row['profile_screen_name'];
         $row['view_from_avatar'] = $row['profile_avatar'];
         switch ($row['notification_type']) {
             // new comment on post/image (inform all users included in this discussion)
             case 1:
                 $row['subject'] = $transl->translate('New comment');
                 $row['subject_email'] = $transl_default->translate('New comment');
                 if ($row['comment_resource_type'] == 'post') {
                     $row['html_link'] .= '<a href="' . $baseURL . '/profiles/showpost/name/' . $row['commented_post_on_wall'] . '/post/' . $row['commented_post_id'] . '">';
                 } elseif ($row['comment_resource_type'] == 'image') {
                     $row['html_link'] .= '<a href="' . $baseURL . '/index/index/showimage/' . $row['commented_image_uid'] . '">';
                 } else {
                     $row['html_link'] .= $transl->translate('Resource not available');
                     $row['view_from_avatar'] = 'default/generic.jpg';
                     break;
                 }
                 $row['html_link'] .= sprintf($transl->translate('%s posted a new comment'), $row['comment_author_screen_name']);
                 $row['html_link'] .= '</a>';
                 $row['html_link'] .= '<p>';
                 $row['html_link'] .= strlen($row['comment_content']) > 150 ? Application_Plugin_Common::mbsubstr($row['comment_content'], 0, 150, 'utf-8') : $row['comment_content'];
                 $row['html_link'] .= '</p>';
                 $row['view_from_name'] = $row['comment_author_name'];
                 $row['view_from_screen_name'] = $row['comment_author_screen_name'];
                 $row['view_from_avatar'] = $row['comment_author_avatar'];
                 break;
                 // 2 - new like on post/comment/image
             // 2 - new like on post/comment/image
             case 2:
                 $row['subject'] = $transl->translate('New like');
                 $row['subject_email'] = $transl_default->translate('New like');
                 $row['html_link'] .= '<a href="' . $baseURL . '/likes/show/like/' . $row['like_id'] . '">';
                 $row['html_link'] .= sprintf($transl->translate('%s likes your %s'), $row['like_user_screen_name'], $transl->translate($row['like_resource_type']));
                 $row['html_link'] .= '</a>';
                 $row['view_from_name'] = $row['like_user_name'];
                 $row['view_from_screen_name'] = $row['like_user_screen_name'];
                 $row['view_from_avatar'] = $row['like_user_avatar'];
                 break;
                 // 3 - new follower
             // 3 - new follower
             case 3:
                 $row['subject'] = $transl->translate('You have new followers');
                 $row['subject_email'] = $transl_default->translate('You have new followers');
                 $row['html_link'] .= '<a href="' . $baseURL . '/' . $row['profile_name'] . '">';
                 $row['html_link'] .= sprintf($transl->translate('%s is now following you'), $row['profile_screen_name']);
                 $row['html_link'] .= '</a>';
                 break;
                 // 4 - new friend
             // 4 - new friend
             case 4:
                 $row['subject'] = $transl->translate('New comment');
                 $row['subject_email'] = $transl_default->translate('New comment');
                 $row['html_link'] .= '<a href="' . $baseURL . '/' . $row['profile_name'] . '">';
                 $row['html_link'] .= sprintf($transl->translate('%s and you are now friends'), $row['profile_screen_name']);
                 $row['html_link'] .= '</a>';
                 break;
                 // 6 - lost a follower
             // 6 - lost a follower
             case 6:
                 $row['subject'] = $transl->translate('You have lost a follower');
                 $row['subject_email'] = $transl_default->translate('You have lost a follower');
                 $row['html_link'] .= '<a href="' . $baseURL . '/' . $row['profile_name'] . '">';
                 $row['html_link'] .= sprintf($transl->translate('%s has stopped following you'), $row['profile_screen_name']);
                 $row['html_link'] .= '</a>';
                 break;
                 // 7 - posted on your wall
             // 7 - posted on your wall
             case 7:
                 if (!$row['post_author_name']) {
                     $row['html_link'] .= $transl->translate('Resource not available');
                     $row['view_from_avatar'] = 'default/generic.jpg';
                     break;
                 }
                 $row['subject'] = $transl->translate('New post on your wall');
                 $row['subject_email'] = $transl_default->translate('New post on your wall');
                 $row['html_link'] .= '<a href="' . $baseURL . '/profiles/showpost/name/' . $row['to_name'] . '/post/' . $row['post_id'] . '">';
                 $row['html_link'] .= sprintf($transl->translate('%s posted on your wall'), $row['post_author_screen_name']);
                 $row['html_link'] .= '</a>';
                 $row['html_link'] .= '<p>';
                 $row['html_link'] .= strlen($row['post_content']) > 150 ? Application_Plugin_Common::mbsubstr($row['comment_content'], 0, 150, 'utf-8') : $row['post_content'];
                 $row['html_link'] .= '</p>';
                 $row['view_from_name'] = $row['post_author_name'];
                 $row['view_from_screen_name'] = $row['post_author_screen_name'];
                 $row['view_from_avatar'] = $row['post_author_avatar'];
                 break;
                 // 8 - new message (send email to notify)
             // 8 - new message (send email to notify)
             case 8:
                 $row['subject'] = $transl->translate('You have a new private message');
                 $row['subject_email'] = $transl_default->translate('You have a new private message');
                 $row['html_link'] .= '<a href="' . $baseURL . '/messages/inbox/user/' . $row['profile_name'] . '">';
                 $row['html_link'] .= sprintf($transl->translate('%s sent you a new private message'), $row['profile_screen_name']);
                 $row['html_link'] .= '</a>';
                 break;
                 // 10 - group membership accepted
             // 10 - group membership accepted
             case 10:
                 $row['do_send_email'] = false;
                 $row['html_link'] .= '<a href="' . $baseURL . '/' . $row['profile_name'] . '">';
                 $row['html_link'] .= $transl->translate('Group membership accepted');
                 $row['html_link'] .= '</a>';
                 break;
                 // 11 - group membership rejected
             // 11 - group membership rejected
             case 11:
                 // no email
                 $row['do_send_email'] = false;
                 $row['html_link'] .= '<a href="' . $baseURL . '/' . $row['profile_name'] . '">';
                 $row['html_link'] .= $transl->translate('Group membership rejected');
                 $row['html_link'] .= '</a>';
                 break;
                 // 12 - request for group membership sent
             // 12 - request for group membership sent
             case 12:
                 $row['do_send_email'] = false;
                 $row['html_link'] .= '<a href="' . $baseURL . '/' . $row['profile_name'] . '">';
                 $row['html_link'] .= $transl->translate('New group membership request');
                 $row['html_link'] .= '</a>';
                 break;
             default:
                 break;
         }
     }
     // trigger hooks
     Zend_Registry::get('hooks')->trigger('hook_data_notificationsfix', $data);
     return $data;
 }
Esempio n. 21
0
<?php

/**
 * Facebook login & register add-on
 *
 * @package SocialStrap add-on
 * @author Milos Stojanovic
 * @copyright 2014 interactive32.com
 */
require_once 'include/autoload.php';
$this->attach('view_body', 10, function ($view) {
    $fb_appid = Zend_Registry::get('config')->get('facebook_appid');
    $fb_secret = Zend_Registry::get('config')->get('facebook_secret');
    $fb = new Facebook\Facebook(['app_id' => $fb_appid, 'app_secret' => $fb_secret, 'default_graph_version' => 'v2.4']);
    $helper = $fb->getRedirectLoginHelper();
    $permissions = ['email'];
    // Optional permissions
    $reload_url = Application_Plugin_Common::getFullBaseUrl() . '/addons/' . basename(__DIR__) . '/?fb-login';
    $loginUrl = $helper->getLoginUrl($reload_url, $permissions);
    echo '<div id="fb-root"></div>';
    echo '<script type="text/javascript">var php_addonName = "' . basename(__DIR__) . '"; var php_fbloginurl = "' . $loginUrl . '"</script>';
    require_once 'script.js';
});
 /**
  * Close account
  */
 public function closeaccountAction()
 {
     $this->buildMenu();
     $form = new Application_Form_Confirm();
     $this->view->form = $form;
     $request = $this->getRequest();
     // Form Submitted...
     if ($request->isPost() && $form->isValid($_POST)) {
         Application_Plugin_Common::redirectOnDemoAccount();
         $Profiles = new Application_Model_Profiles();
         $Profiles->updateField(Zend_Auth::getInstance()->getIdentity()->name, 'is_hidden', 1);
         Application_Plugin_Alerts::success($this->view->translate('Your account is now closed'), 'off');
         // redirect to logout
         $this->redirect('index/logout');
     }
 }
Esempio n. 23
0
 /**
  * Finds a view script from the available directories.
  *
  * @param string $name The base name of the script.
  * @return void
  */
 protected function _script($name)
 {
     if ($this->isLfiProtectionOn() && preg_match('#\\.\\.[\\\\/]#', $name)) {
         require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('Requested scripts may not include parent directory traversal ("../", "..\\" notation)');
         $e->setView($this);
         throw $e;
     }
     if (0 == count($this->_path['script'])) {
         require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('no view script directory set; unable to determine location for view script');
         $e->setView($this);
         throw $e;
     }
     /* original
        foreach ($this->_path['script'] as $dir) {
            if (is_readable($dir . $name)) {
                return $dir . $name;
            }
        }
        */
     // alcalbg: layout conflict detector
     $count = 0;
     $ret = $ret_log = false;
     foreach ($this->_path['script'] as $dir) {
         if (is_readable($dir . $name)) {
             if ($ret === false) {
                 $ret = $dir . $name;
             }
             $ret_log = $dir . $name;
             ++$count;
         }
     }
     if ($count > 2) {
         foreach ($this->_path['script'] as $dir) {
             if ($dir . $name != $ret_log && is_readable($dir . $name)) {
                 $message = 'Possible layout conflict: ' . $dir . $name;
                 Application_Plugin_Common::log($message);
             }
         }
     }
     if ($ret) {
         return $ret;
     }
     // alcalbg: end
     require_once 'Zend/View/Exception.php';
     $message = "script '{$name}' not found in path (" . implode(PATH_SEPARATOR, $this->_path['script']) . ")";
     $e = new Zend_View_Exception($message);
     $e->setView($this);
     throw $e;
 }
Esempio n. 24
0
 /**
  * Init main Cache mechanism
  */
 protected function _initCache()
 {
     if (!defined('CACHE_PATH')) {
         die("Error: Cache directory not defined, check index.php file.");
     }
     if ($this->_appConfig->cache_frontend_options) {
         $frontendOptions = json_decode($this->_appConfig->cache_frontend_options, true);
     } else {
         $frontendOptions = array('automatic_serialization' => true, 'lifetime' => 600);
     }
     $backend_fallback = 'File';
     $backendOptions_fallback = array('cache_dir' => CACHE_PATH);
     if ($this->_appConfig->cache_backend) {
         $backend = $this->_appConfig->cache_backend;
         $backendOptions = json_decode($this->_appConfig->cache_backend_options, true);
     } else {
         $backend = $backend_fallback;
         $backendOptions = $backendOptions_fallback;
     }
     try {
         $cache = Zend_Cache::factory('Core', $backend, $frontendOptions, $backendOptions);
     } catch (Zend_Exception $e) {
         $message = 'ERROR: Cannot start cache - ' . $e->getMessage();
         Application_Plugin_Common::log($message);
         // fallback cache
         try {
             $cache = Zend_Cache::factory('Core', $backend_fallback, $frontendOptions, $backendOptions_fallback);
         } catch (Zend_Exception $e) {
             $message = 'ERROR: Cannot start fallback cache - ' . $e->getMessage();
             Application_Plugin_Common::log($message);
             die($message);
         }
     }
     // Set the cache to be used with all table objects
     Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
     // Save all-purpose cache to the registry
     Zend_Registry::set('cache', $cache);
 }
Esempio n. 25
0
        if ($protocol == 'https://') {
            $oembedURL .= '&scheme=https';
        }
        $client = new Zend_Http_Client($oembedURL, array('timeout' => 5));
        try {
            $response = $client->request();
            if ($response->isSuccessful()) {
                // return html with iframe
                $ret = $response->getBody();
                $rich_content = array('type' => 'youtube', 'data' => $ret);
                // update meta
                $post['meta'] = array('rich_content' => json_encode($rich_content));
                return;
            }
        } catch (Zend_Http_Client_Adapter_Exception $e) {
            Application_Plugin_Common::log(array($e->getMessage()));
        }
    }, $content);
});
$this->attach('hook_data_postcontent', 10, function (&$post) {
    // fix rich data
    if (isset($post['rich_content_json'])) {
        $rich_content = json_decode($post['rich_content_json']);
        if ($rich_content->type == 'youtube' && !empty($rich_content->data)) {
            $youtube_data = json_decode($rich_content->data);
            // add autoplay to src
            $youtube_data->html = preg_replace('#\\<iframe(.*?)\\ssrc\\=\\"(.*?)\\"(.*?)\\>#i', '<iframe$1 src="$2&autoplay=1"$3>', $youtube_data->html);
            $play_url = htmlentities(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? str_replace("http://", "https://", $youtube_data->html) : $youtube_data->html);
            $youtube_html = '
			<div class="youtube-video-box">
			<div>
 /**
  * Edit comment (ajax)
  */
 public function editAction()
 {
     $request = $this->getRequest();
     $user_role = Zend_Auth::getInstance()->getIdentity()->role;
     $comment_id = (int) $request->getParam('id', false);
     $Comments = new Application_Model_Comments();
     $comment = $Comments->getComment($comment_id);
     if (!$comment && !isset($comment['content'])) {
         $this->getHelper('json')->sendJson($this->view->translate('Resource not available'));
         return;
     }
     // check if my comment or an admin
     if ($Comments->getCommentAuthorId($comment_id) != Zend_Auth::getInstance()->getIdentity()->id && ($user_role != 'admin' && $user_role != 'reviewer')) {
         $this->getHelper('json')->sendJson($this->view->translate('Error - not permitted'));
         return;
     }
     // load and fill up form
     $edit_comment_form = new Application_Form_EditComment();
     $edit_comment_form->getElement('comment')->setValue($comment['content']);
     // get and render form only
     if ($request->isPost() && $request->getParam('form_render')) {
         $edit_comment_form->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . '/comments/edit/id/' . $comment_id);
         $this->getHelper('json')->sendJson($edit_comment_form->render());
         return;
     }
     if ($request->isPost() && $edit_comment_form->isValid($_POST)) {
         $comment_content = $edit_comment_form->getElement('comment')->getValue();
         $comment_content = Application_Plugin_Common::prepareComment($comment_content);
         // drop on false
         if ($comment_content === false) {
             $this->getHelper('json')->sendJson($this->view->translate('Error - not permitted'));
             return;
         }
         $ret = $Comments->updateComment($comment_id, $comment_content);
         $this->getHelper('json')->sendJson($this->view->RenderOutput($comment_content, 'comment'));
         return;
     }
     $this->getHelper('json')->sendJson($this->view->translate('Error - not permitted'));
     return;
 }
 public function GetTimeElapsedString($resource)
 {
     return Application_Plugin_Common::getTimeElapsedString(strtotime($resource));
 }
 /**
  * Change logo picture
  */
 public function logoAction()
 {
     $this->buildSettingsMenu();
     $request = $this->getRequest();
     $form = new Application_Form_SettingsLogo();
     $this->view->image = Application_Plugin_Common::getFullBaseUrl() . '/images/' . Zend_Registry::get('config')->get('logo_image');
     $this->view->form = $form;
     // image processing helper
     $this->_helper->imageProcessing('logo_image', false, $form, 'logo_image', false);
     if ($request->isPost() && $form->isValid($_POST)) {
         if ($form->getValue('logo_noimage')) {
             $AppOptions = new Application_Model_AppOptions();
             $AppOptions->removeMeta('logo_image');
         }
         Application_Plugin_Alerts::success($this->view->translate('Settings updated, please clear your browser cache'), 'off');
         // flush url
         $this->redirect('admin/logo/section/logo/');
     }
 }
Esempio n. 29
0
 /**
  * Follow User
  */
 public function followUser($user_id, $follow_id)
 {
     if ($this->areFriends($user_id, $follow_id) || $this->isFollowing($follow_id, $user_id)) {
         return false;
     }
     $data = array('user_id' => $user_id, 'follow_id' => $follow_id, 'created_on' => Application_Plugin_Common::now());
     try {
         $ret = $this->insert($data);
     } catch (Zend_Db_Exception $e) {
         Application_Plugin_Common::log($e->getMessage());
     }
     if ($ret === null) {
         return false;
     }
     return true;
 }
 /**
  * Change language
  */
 public function languageAction()
 {
     Application_Plugin_Common::redirectOnDemoAccount();
     $request = $this->getRequest();
     $session = new Zend_Session_Namespace('Default');
     $new_lang = $request->getParam('code');
     $translate = Zend_Registry::get('Zend_Translate');
     // change current language
     if ($new_lang && in_array($new_lang, $translate->getList())) {
         $session->language = $new_lang;
         if (Zend_Auth::getInstance()->hasIdentity()) {
             // update user's default language
             $Profiles = new Application_Model_Profiles();
             $Profiles->updateField(Zend_Auth::getInstance()->getIdentity()->name, 'language', $new_lang);
         }
     }
     $this->redirect('');
 }