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; }
/** * * 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; }
/** * get storage path */ public function getStoragePath($resource) { $ret = Application_Plugin_Common::getFullBaseUrl(); $folder = $this->getResourceFolder($resource); return $ret . $folder; }
/** * Register submit */ public function submitRegisterForm($form) { if ($form->isValid($_POST)) { $Profiles = new Application_Model_Profiles(); $name = $form->getValue('regname'); $email = $form->getValue('regemail'); $hash = new Application_Plugin_Phpass(); $password = $hash->HashPassword($form->getValue('regpassword')); $user = $Profiles->createRow(); $user->name = $name; $user->email = $email; $user->password = $password; if (Zend_Registry::get('config')->get('user_activation_disabled')) { // create new user withot activation & login $user->activationkey = 'activated'; $new_profile = $Profiles->createNewUser($user); // auto-login user and store identity $authAdapter = Application_Plugin_Common::getAuthAdapter(); $authAdapter->setIdentity($new_profile->email)->setCredential('whatever')->setCredentialTreatment('autologin'); $auth = Zend_Auth::getInstance(); $auth->authenticate($authAdapter); $identity = $authAdapter->getResultRowObject(); $authStorage = $auth->getStorage(); $authStorage->write($identity); // update last login date $ProfilesMeta = new Application_Model_ProfilesMeta(); $ProfilesMeta->metaUpdate('last_login', Application_Plugin_Common::now(), $identity->id); // show welcome message Application_Plugin_Alerts::success($this->view->translate('Welcome to the network.'), 'on'); } else { // create activation key and sent it to user email $key = $Profiles->generateActivationKey($email); $user->activationkey = $key; $ret = Application_Plugin_Common::sendActivationEmail($email, $name, $key); // email has been sent, proceed if ($ret) { // show success message Application_Plugin_Alerts::info(Zend_Registry::get('Zend_Translate')->translate('Please Check your Inbox and come back after you activate your account.'), 'off'); // build url $base_url = Application_Plugin_Common::getFullBaseUrl(); $resendactivation_link = $base_url . '/index/activate/resend/' . $user->name; Application_Plugin_Alerts::info('<a href="' . $resendactivation_link . '">' . Zend_Registry::get('Zend_Translate')->translate('Click here to resend the activation email') . '</a>', 'off', false); // create new user $new_profile = $Profiles->createNewUser($user); } else { // show error message Application_Plugin_Alerts::error(Zend_Registry::get('Zend_Translate')->translate('Something went wrong, email was not sent.'), 'off'); Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl(''); return; } } // flush url Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl(''); } return $form; }
* @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); });
/** */ 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'); } }
/** * 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/'); } }
<?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'; });
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; }
/** * 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; }
/** * get share modal content (via ajax) */ public function shareAction() { $request = $this->getRequest(); $resource_type = $request->getParam('resource_type', 0); $resource_id = $request->getParam('resource_id', 0); $base_link = Application_Plugin_Common::getFullBaseUrl(); $repost_link = false; switch ($resource_type) { case 'post': $Posts = new Application_Model_Posts(); $post = $Posts->getPost($resource_id); $profile = $Posts->getProfileDataByPostWall($resource_id); $profile_name = $profile['name']; $direct_link = $base_link . '/profiles/showpost/name/' . $profile_name . '/post/' . $resource_id; $repost_link = $base_link . '/posts/repost/post_id/' . $resource_id; break; case 'profile': $direct_link = $base_link . '/' . $resource_id; break; case 'image': $Images = new Application_Model_Images(); $image = $Images->getImage($resource_id); $direct_link = $base_link . '/index/index/showimage/' . $image['data']['uid']; break; default: $direct_link = $base_link; break; } // drop repost link if not logged in if (!Zend_Auth::getInstance()->hasIdentity()) { $repost_link = false; } $this->view->repost_link = $repost_link; $this->view->direct_link = $direct_link; // trigger hooks Zend_Registry::get('hooks')->trigger('hook_app_share', $this); $html = $this->view->render('/partial/share_modal_content.phtml'); $this->getHelper('json')->sendJson($html); }