Ejemplo n.º 1
0
 /**
  * Filling the gaps in marker groups
  *
  * @return	array	If returns TRUE, upgrader will proceed to next step. If it returns any other value, it will set this as the value of the 'extra' GET parameter and rerun this step (useful for loops)
  */
 public function step2()
 {
     $order = 2;
     foreach (\IPS\Db::i()->select('*', 'membermap_markers_groups') as $group) {
         $group = \IPS\membermap\Markers\Groups::constructFromData($group);
         \IPS\Lang::saveCustom('membermap', "membermap_marker_group_{$group->id}", trim($group->name));
         \IPS\Lang::saveCustom('membermap', "membermap_marker_group_{$group->id}_JS", trim($group->name), 1);
         $group->name_seo = \IPS\Http\Url::seoTitle(trim($group->name));
         if ($group->type == 'custom') {
             $group->position = $order;
             $group->moderate = 1;
             $order++;
         }
         try {
             $latestMarker = \IPS\Db::i()->select('*', 'membermap_markers', array('marker_open=? and marker_parent_id=?', 1, $group->id), 'marker_updated DESC, marker_added DESC', array(0, 1))->first();
             $group->last_marker_id = $latestMarker['marker_id'];
             $group->last_marker_date = $latestMarker['marker_added'];
         } catch (\UnderflowException $e) {
             $group->last_marker_id = 0;
             $group->last_marker_date = 0;
         }
         $group->save();
         /* Reset permissions */
         $perms = $group->permissions();
         \IPS\Db::i()->update('core_permission_index', array('perm_view' => '*', 'perm_2' => '*', 'perm_3' => \IPS\Settings::i()->admin_group, 'perm_4' => \IPS\Settings::i()->admin_group), array('perm_id=?', $perms['perm_id']));
     }
     return TRUE;
 }
Ejemplo n.º 2
0
 /**
  * Do formatation to the array of markers
  * 
  * @param 		array 	Markers
  * @return		array	Markers
  */
 public function formatMemberMarkers(array $markers)
 {
     $markersToKeep = array();
     $groupCache = \IPS\Data\Store::i()->groups;
     if (is_array($markers) and count($markers)) {
         foreach ($markers as $marker) {
             /* Member don't exists or lat/lon == 0 (Middle of the ocean) */
             if ($marker['member_id'] === NULL or $marker['marker_lat'] == 0 and $marker['marker_lon'] == 0) {
                 \IPS\Db::i()->delete('membermap_markers', array('marker_id=?', $marker['marker_id']));
                 continue;
             }
             $photo = \IPS\Member::photoUrl($marker);
             try {
                 $groupName = \IPS\Lang::load(\IPS\Lang::defaultLanguage())->get('core_group_' . $marker['member_group_id']);
             } catch (\UnderflowException $e) {
                 $groupName = '';
             }
             if (isset($groupCache[$marker['member_group_id']]['g_membermap_markerColour'])) {
                 $markerColour = $groupCache[$marker['member_group_id']]['g_membermap_markerColour'];
             } else {
                 $markerColour = 'darkblue';
             }
             $markersToKeep[] = array('type' => "member", 'lat' => round((double) $marker['marker_lat'], 5), 'lon' => round((double) $marker['marker_lon'], 5), 'member_id' => $marker['marker_member_id'], 'parent_id' => $marker['member_group_id'], 'parent_name' => $groupName, 'popup' => \IPS\Theme::i()->getTemplate('map', 'membermap', 'front')->popupContent($marker, $photo), 'markerColour' => $markerColour);
         }
     }
     return $markersToKeep;
 }
Ejemplo n.º 3
0
 public static function create($item, $comment, $first = FALSE, $guestName = NULL, $incrementPostCount = NULL, $member = NULL, \IPS\DateTime $time = NULL)
 {
     $topic = $item;
     if ($member === NULL) {
         $member = \IPS\Member::loggedIn();
     }
     if (isset($_POST['topic_title'])) {
         $comment = $_POST['topic_title'] . "\n" . $comment;
     }
     $access_key = \IPS\Settings::i()->access_key;
     if (isset($member) && !$member->isAdmin() && $member->member_posts <= 10 && \IPS\Settings::i()->moderate_new == 1) {
         require_once dirname($_SERVER['SCRIPT_FILENAME']) . "/uploads/cleantalk.class.php";
         require_once dirname($_SERVER['SCRIPT_FILENAME']) . "/uploads/JSON.php";
         session_name('cleantalksession');
         if (!isset($_SESSION)) {
             session_start();
         }
         if (array_key_exists('formtime', $_SESSION)) {
             $submit_time = time() - (int) $_SESSION['formtime'];
         } else {
             $submit_time = NULL;
         }
         $_SESSION['formtime'] = time();
         $post_info = '';
         $lang = \IPS\Lang::getEnabledLanguages();
         $locale = $lang[\IPS\Lang::defaultLanguage()]->short;
         if (function_exists('json_encode')) {
             $arr = array('cms_lang' => $locale, 'REFFERRER' => $_SERVER['HTTP_REFERER'], 'USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
             $post_info = json_encode($arr);
         }
         if ($post_info === FALSE) {
             $post_info = '';
         }
         $ct_url = 'http://moderate.cleantalk.ru';
         $config_work_url = $ct_url;
         $config_ttl = 43200;
         $config_changed = 1349162987;
         $config_key = $access_key;
         $ct = new \Cleantalk();
         $ct->work_url = $config_work_url;
         $ct->server_url = $ct_url;
         $ct->server_ttl = $config_ttl;
         $ct->server_changed = $config_changed;
         $sender_email = filter_var($member->email, FILTER_SANITIZE_EMAIL);
         $sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
         $ct_request = new \CleantalkRequest();
         $ct_request->auth_key = $config_key;
         if (isset($_POST['guest_name'])) {
             $ct_request->sender_nickname = $_POST['guest_name'];
         } else {
             $ct_request->sender_nickname = $member->name;
         }
         $ct_request->sender_ip = $sender_ip;
         $ct_request->sender_email = $sender_email;
         $ct_request->sender_info = $post_info;
         $ct_request->agent = 'ipboard4-18';
         $js_keys = array();
         for ($i = -5; $i <= 1; $i++) {
             $js_keys[] = md5(\IPS\Settings::i()->access_key . '+' . \IPS\Settings::i()->email_in . date("Ymd", time() + 86400 * $i));
         }
         $ct_request->js_on = in_array($_COOKIE['ct_checkjs'], $js_keys) ? 1 : 0;
         $ct_request->submit_time = $submit_time;
         $ct_request->message = $comment;
         $ct_result = $ct->isAllowMessage($ct_request);
         if (isset($ct_result->errno) && $ct_result->errno > 0) {
             //sendErrorMessage("CleanTalk has some problems, errno is ".$ct_result->errno.", errstr is '".$ct_result->errstr."'")
         }
         if ($ct_result->allow == 1) {
             // Not spammer.
             //call_user_func_array( 'parent::save', func_get_args() );
             return call_user_func_array('parent::create', func_get_args());
         } else {
             if (isset($_POST['topic_title'])) {
                 $topic->delete();
             }
             if (\IPS\Request::i()->isAjax()) {
                 $result = array("type" => "error", "message" => $ct_result->comment);
                 $result = json_encode($result);
                 \IPS\Output::i()->sendOutput($result, 200, "application/json");
             } else {
                 \IPS\Output::i()->sidebar['enabled'] = FALSE;
                 \IPS\Output::i()->sendOutput(\IPS\Theme::i()->getTemplate('global', 'core')->globalTemplate("Forbidden", \IPS\Theme::i()->getTemplate('global', 'core')->error("Forbidden", $ct_result->comment, 1, ""), array('app' => \IPS\Dispatcher::i()->application ? \IPS\Dispatcher::i()->application->directory : NULL, 'module' => \IPS\Dispatcher::i()->module ? \IPS\Dispatcher::i()->module->key : NULL, 'controller' => \IPS\Dispatcher::i()->controller)), 200, 'text/html', array(), FALSE, FALSE);
             }
             die;
             return call_user_func_array('parent::create', func_get_args());
         }
     }
     return call_user_func_array('parent::create', func_get_args());
 }
Ejemplo n.º 4
0
 /**
  * [Node] Format form values from add/edit form for save
  *
  * @param	array	$values	Values from the form
  * @return	array
  */
 public function formatFormValues($values)
 {
     if (!$this->id) {
         $this->save();
     }
     if (isset($values['group_name'])) {
         \IPS\Lang::saveCustom('membermap', "membermap_marker_group_{$this->id}", $values['group_name']);
         \IPS\Lang::saveCustom('membermap', "membermap_marker_group_{$this->id}_JS", $values['group_name'], 1);
         $this->name_seo = \IPS\Http\Url::seoTitle($values['group_name'][\IPS\Lang::defaultLanguage()]);
         unset($values['group_name']);
     }
     foreach (array('group_pin_icon', 'group_pin_colour', 'group_pin_bg_colour') as $val) {
         if (isset($values[$val])) {
             $key = str_replace('group_', '', $val);
             $values[$key] = $values[$val];
             unset($values[$val]);
         }
     }
     return $values;
 }
Ejemplo n.º 5
0
 /**
  * [ActiveRecord] Save Changed Columns
  *
  * @return	void
  * @note	We have to be careful when upgrading in case we are coming from an older version
  */
 public function save()
 {
     $new = $this->_new;
     $enabled = \IPS\Settings::i()->plugin_enabled;
     $access_key = \IPS\Settings::i()->access_key;
     if ($enabled == 1 && $new) {
         require_once dirname($_SERVER['SCRIPT_FILENAME']) . "/uploads/cleantalk.class.php";
         require_once dirname($_SERVER['SCRIPT_FILENAME']) . "/uploads/JSON.php";
         session_name('cleantalksession');
         if (!isset($_SESSION)) {
             session_start();
         }
         if (array_key_exists('formtime', $_SESSION)) {
             $submit_time = time() - (int) $_SESSION['formtime'];
         } else {
             $submit_time = NULL;
         }
         $_SESSION['formtime'] = time();
         $post_info = '';
         $lang = \IPS\Lang::getEnabledLanguages();
         $locale = $lang[\IPS\Lang::defaultLanguage()]->short;
         if (function_exists('json_encode')) {
             $arr = array('cms_lang' => $locale, 'REFFERRER' => $_SERVER['HTTP_REFERER'], 'USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
             $post_info = json_encode($arr);
         }
         if ($post_info === FALSE) {
             $post_info = '';
         }
         $ct_url = 'http://moderate.cleantalk.ru';
         $config_work_url = $ct_url;
         $config_ttl = 43200;
         $config_changed = 1349162987;
         $config_key = $access_key;
         $ct = new \Cleantalk();
         $ct->work_url = $config_work_url;
         $ct->server_url = $ct_url;
         $ct->server_ttl = $config_ttl;
         $ct->server_changed = $config_changed;
         $sender_email = filter_var($_POST['email_address'], FILTER_SANITIZE_EMAIL);
         $sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
         $ct_request = new \CleantalkRequest();
         $ct_request->auth_key = $config_key;
         $ct_request->sender_nickname = $_POST['username'];
         $ct_request->sender_ip = $sender_ip;
         $ct_request->sender_email = $sender_email;
         $ct_request->sender_info = $post_info;
         $ct_request->agent = 'ipboard4-18';
         //$ct_request->js_on = $_COOKIE['ct_checkjs'] == md5(\IPS\Settings::i()->access_key . '+' . \IPS\Settings::i()->email_in) ? 1 : 0;
         $ct_request->js_on = in_array($_COOKIE['ct_checkjs'], self::getCheckJSArray()) ? 1 : 0;
         $ct_request->submit_time = $submit_time;
         $ct_result = $ct->isAllowUser($ct_request);
         if (isset($ct_result->errno) && $ct_result->errno > 0) {
             //sendErrorMessage("CleanTalk has some problems, errno is ".$ct_result->errno.", errstr is '".$ct_result->errstr."'")
         }
         if ($ct_result->allow == 1) {
             // Not spammer.
             call_user_func_array('parent::save', func_get_args());
         } else {
             // Spammer - display message and exit.
             if (\IPS\Request::i()->isAjax()) {
                 $err_str = '<span style="color:#ab1f39;">' . $ct_result->comment . '</span><script>setTimeout("history.back()", 5000);</script>';
                 print $err_str;
             } else {
                 \IPS\Output::i()->sidebar['enabled'] = FALSE;
                 \IPS\Output::i()->sendOutput(\IPS\Theme::i()->getTemplate('global', 'core')->globalTemplate("Forbidden", \IPS\Theme::i()->getTemplate('global', 'core')->error("Forbidden", $ct_result->comment, 1, ""), array('app' => \IPS\Dispatcher::i()->application ? \IPS\Dispatcher::i()->application->directory : NULL, 'module' => \IPS\Dispatcher::i()->module ? \IPS\Dispatcher::i()->module->key : NULL, 'controller' => \IPS\Dispatcher::i()->controller)), 200, 'text/html', array(), FALSE, FALSE);
             }
             die;
         }
     }
     return call_user_func_array('parent::save', func_get_args());
 }
Ejemplo n.º 6
0
 public function import()
 {
     $id = isset(\IPS\Request::i()->id) ? intval(\IPS\Request::i()->id) : 0;
     /* Build form */
     $form = new \IPS\Helpers\Form(NULL, 'import');
     if (isset(\IPS\Request::i()->id)) {
         $group = \IPS\membermap\Markers\Groups::load(intval(\IPS\Request::i()->id));
         if ($group->type == 'member') {
             \IPS\Output::i()->error('generic_error', '1MM4/1', 403, '');
         }
     }
     $form->add(new \IPS\Helpers\Form\Upload('import_upload', NULL, TRUE, array('allowedFileTypes' => array('kml'), 'temporary' => TRUE)));
     $form->add(new \IPS\Helpers\Form\YesNo('import_creategroups', FALSE, FALSE, array('togglesOff' => array('import_group'))));
     $form->add(new \IPS\Helpers\Form\Node('import_group', $id ?: 0, FALSE, array('class' => '\\IPS\\membermap\\Markers\\Groups', 'permissionCheck' => 'add', 'subnodes' => false, 'where' => array('group_type != ?', 'member')), NULL, NULL, NULL, 'import_group'));
     if ($values = $form->values()) {
         try {
             $xml = \IPS\Xml\SimpleXML::loadFile($values['import_upload']);
         } catch (\InvalidArgumentException $e) {
             $form->error = \IPS\Member::loggedIn()->language()->addToStack('xml_upload_invalid');
             \IPS\Output::i()->output = $form;
             return;
         }
         /* No group selected, and don't create groups?! */
         if ($values['import_creategroups'] == FALSE and !$values['import_group']) {
             $form->error = \IPS\Member::loggedIn()->language()->addToStack('membermap_error_no_id_no_create');
             \IPS\Output::i()->output = $form;
             return;
         }
         $markers = array();
         $groupOrder = NULL;
         $imported = 0;
         foreach ($xml->Document->Folder as $folder) {
             if (!isset($folder->Placemark)) {
                 continue;
             }
             $folderName = (string) $folder->name;
             foreach ($folder->Placemark as $placemark) {
                 if (!isset($placemark->Point->coordinates)) {
                     continue;
                 }
                 list($lon, $lat, $elev) = explode(',', $placemark->Point->coordinates);
                 $markers[] = array('marker_name' => (string) $placemark->name, 'marker_name_seo' => \IPS\Http\Url::seoTitle((string) $placemark->name), 'marker_description' => (string) $placemark->description, 'marker_lat' => $lat, 'marker_lon' => $lon, 'marker_member_id' => \IPS\Member::loggedIn()->member_id, 'marker_added' => time(), 'marker_open' => 1, 'marker_parent_id' => isset($values['import_group']) ? $values['import_group']->id : NULL);
             }
             /* Create a new group per "folder" */
             if ($values['import_creategroups'] == TRUE and count($markers) > 0) {
                 if ($groupOrder === NULL) {
                     $groupOrder = \IPS\Db::i()->select(array("MAX( `group_position` ) as position"), 'membermap_markers_groups')->first();
                 }
                 $groupOrder = $groupOrder + 1;
                 $group = new \IPS\membermap\Markers\Groups();
                 $group->name = $folderName;
                 $group->name_seo = \IPS\Http\Url::seoTitle($folderName);
                 $group->type = 'custom';
                 $group->pin_colour = '#FFFFFF';
                 $group->pin_bg_colour = 'red';
                 $group->pin_icon = 'fa-globe';
                 $group->position = $groupOrder;
                 $group->save();
                 \IPS\Lang::saveCustom('membermap', "membermap_marker_group_{$group->id}", trim($folderName));
                 \IPS\Lang::saveCustom('membermap', "membermap_marker_group_{$group->id}_JS", trim($folderName), 1);
                 // Add group id to all elements of the array
                 array_walk($markers, function (&$v, $k) use($group) {
                     $v['marker_parent_id'] = $group->id;
                 });
                 // Insert
                 \IPS\Db::i()->insert('membermap_markers', $markers);
                 $group->setLastComment();
                 $group->save();
                 // Set default permissions
                 $perms = $group->permissions();
                 \IPS\Db::i()->update('core_permission_index', array('perm_view' => '*', 'perm_2' => '*', 'perm_3' => \IPS\Settings::i()->admin_group, 'perm_4' => \IPS\Settings::i()->admin_group), array('perm_id=?', $perms['perm_id']));
                 // Reset
                 $imported += count($markers);
                 $markers = array();
             }
         }
         /* If we still got markers here, it's all pushed to one group, probably */
         if (is_array($markers) and count($markers) > 0) {
             \IPS\Db::i()->insert('membermap_markers', $markers);
             $group = $values['import_group'];
             $group->setLastComment();
             $group->save();
             $imported += count($markers);
         }
         \IPS\membermap\Map::i()->invalidateJsonCache();
         $message = \IPS\Member::loggedIn()->language()->addToStack('membermap_import_thumbup', FALSE, array('sprintf' => array($imported)));
         \IPS\Output::i()->redirect(\IPS\Http\Url::internal("app=membermap&module=membermap&controller=markers"), $message);
     }
     /* Display */
     \IPS\Output::i()->output = $form;
 }