diff options
-rw-r--r-- | lang/en.php | 9 | ||||
-rw-r--r-- | plugins/API/API.php | 2 | ||||
-rw-r--r-- | plugins/Feedback/Feedback.php | 2 | ||||
-rw-r--r-- | plugins/MultiSites/MultiSites.php | 2 | ||||
-rw-r--r-- | plugins/PDFReports/PDFReports.php | 2 | ||||
-rw-r--r-- | plugins/SegmentEditor/API.php | 49 | ||||
-rw-r--r-- | plugins/SegmentEditor/Controller.php | 1 | ||||
-rw-r--r-- | plugins/SegmentEditor/templates/Segmentation.css | 5 | ||||
-rw-r--r-- | plugins/SegmentEditor/templates/Segmentation.js | 115 | ||||
-rw-r--r-- | plugins/SegmentEditor/templates/selector.tpl | 27 | ||||
-rw-r--r-- | plugins/Widgetize/Widgetize.php | 2 |
11 files changed, 146 insertions, 70 deletions
diff --git a/lang/en.php b/lang/en.php index 7188e90952..8f0d7d3b55 100644 --- a/lang/en.php +++ b/lang/en.php @@ -42,6 +42,7 @@ $translations = array( 'General_Close' => 'Close', 'General_Cancel' => 'Cancel', 'General_OrCancel' => 'or %s Cancel %s', + 'General_And' => 'and', 'General_Logout' => 'Sign out', 'General_Username' => 'Username', 'General_Description' => 'Description', @@ -2297,7 +2298,7 @@ And thank you for using Piwik!', 'SegmentEditor_AddNewSegment' => 'Add new segment', 'SegmentEditor_NewSegment' => 'New segment', 'SegmentEditor_SelectSegmentOfVisitors' => 'Select a segment of visitors:', - 'SegmentEditor_YouMustBeLoggedInToCreateSegments' => 'You must be logged in to create and apply custom visitor segments.', + 'SegmentEditor_YouMustBeLoggedInToCreateSegments' => 'You must be logged in to create and edit custom visitor segments.', 'SegmentEditor_DragDropCondition' => 'Drag & Drop condition', 'SegmentEditor_OperatorAND' => 'AND', 'SegmentEditor_OperatorOR' => 'OR', @@ -2305,12 +2306,14 @@ And thank you for using Piwik!', 'SegmentEditor_AddANDorORCondition' => 'Add %s condition', 'SegmentEditor_ThisSegmentIsVisibleTo' => 'This segment is visible to:', 'SegmentEditor_VisibleToMe' => 'me', - 'SegmentEditor_VisibleToAllUsers' => 'All users', + 'SegmentEditor_VisibleToAllUsers' => 'all users', 'SegmentEditor_SegmentIsDisplayedForWebsite' => 'and displayed for', 'SegmentEditor_SegmentDisplayedThisWebsiteOnly' => 'this website only', 'SegmentEditor_SegmentDisplayedAllWebsites' => 'all websites', 'SegmentEditor_SaveAndApply' => 'Save & Apply', 'SegmentEditor_AreYouSureDeleteSegment' => 'Are you sure you want to delete this segment?', 'SegmentEditor_ChooseASegment' => 'Choose a segment', - 'SegmentEditor_LoadingSegmentedDataMayTakeSomeTime' => 'Processing segmented visitors\' data may take a few minutes...', + 'SegmentEditor_LoadingSegmentedDataMayTakeSomeTime' => 'Processing segmented visitor data may take a few minutes...', + 'SegmentEditor_AutoArchiveRealTime' => 'segmented reports are processed in real time', + 'SegmentEditor_AutoArchivePreProcessed' => 'segmented reports are pre-processed (faster, requires archive.php cron)', ); diff --git a/plugins/API/API.php b/plugins/API/API.php index 025d8fd886..df0e786697 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -36,7 +36,7 @@ class Piwik_API extends Piwik_Plugin public function addTopMenu() { - $apiUrlParams = array('module' => 'API', 'action' => 'listAllAPI'); + $apiUrlParams = array('module' => 'API', 'action' => 'listAllAPI', 'segment' => false); $tooltip = Piwik_Translate('API_TopLinkTooltip'); Piwik_AddTopMenu('General_API', $apiUrlParams, true, 7, $isHTML = false, $tooltip); diff --git a/plugins/Feedback/Feedback.php b/plugins/Feedback/Feedback.php index d0094578ed..9d19d80640 100644 --- a/plugins/Feedback/Feedback.php +++ b/plugins/Feedback/Feedback.php @@ -38,7 +38,7 @@ class Piwik_Feedback extends Piwik_Plugin { Piwik_AddTopMenu( 'General_GiveUsYourFeedback', - array('module' => 'Feedback', 'action' => 'index'), + array('module' => 'Feedback', 'action' => 'index', 'segment' => false), true, $order = 20, $isHTML = false, diff --git a/plugins/MultiSites/MultiSites.php b/plugins/MultiSites/MultiSites.php index 43797132c7..d68db8d8ca 100644 --- a/plugins/MultiSites/MultiSites.php +++ b/plugins/MultiSites/MultiSites.php @@ -77,7 +77,7 @@ class Piwik_MultiSites extends Piwik_Plugin public function addTopMenu() { - $urlParams = array('module' => 'MultiSites', 'action' => 'index'); + $urlParams = array('module' => 'MultiSites', 'action' => 'index', 'segment' => false); $tooltip = Piwik_Translate('MultiSites_TopLinkTooltip'); Piwik_AddTopMenu('General_MultiSitesSummary', $urlParams, true, 3, $isHTML = false, $tooltip); } diff --git a/plugins/PDFReports/PDFReports.php b/plugins/PDFReports/PDFReports.php index a6f0b1d572..7c8075c172 100644 --- a/plugins/PDFReports/PDFReports.php +++ b/plugins/PDFReports/PDFReports.php @@ -491,7 +491,7 @@ class Piwik_PDFReports extends Piwik_Plugin { Piwik_AddTopMenu( $this->getTopMenuTranslationKey(), - array('module' => 'PDFReports', 'action' => 'index'), + array('module' => 'PDFReports', 'action' => 'index', 'segment' => false), true, 13, $isHTML = false, diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php index 39c204ea18..cacd742ae6 100644 --- a/plugins/SegmentEditor/API.php +++ b/plugins/SegmentEditor/API.php @@ -81,6 +81,8 @@ class Piwik_SegmentEditor_API } Piwik::checkUserHasViewAccess($idSite); } + $idSite = (int)$idSite; + return $idSite; } protected function checkAutoArchive($autoArchive, $idSite) @@ -115,8 +117,16 @@ class Piwik_SegmentEditor_API return $segment; } + protected function checkUserIsNotAnonymous() + { + if(Piwik::isUserIsAnonymous()) { + throw new Exception("To create, edit or delete Custom Segments, please sign in first."); + } + } + public function delete($idSegment) { + $this->checkUserIsNotAnonymous(); $segment = $this->getSegmentOrFail($idSegment); $db = Zend_Registry::get('db'); $db->delete(Piwik_Common::prefixTable('segment'), 'idsegment = ' . $idSegment); @@ -125,9 +135,10 @@ class Piwik_SegmentEditor_API public function update($idSegment, $name, $definition, $idSite = false, $autoArchive = false, $enabledAllUsers = false) { + $this->checkUserIsNotAnonymous(); $segment = $this->getSegmentOrFail($idSegment); - $this->checkIdSite($idSite); + $idSite = $this->checkIdSite($idSite); $this->checkSegmentName($name); $definition = $this->checkSegmentValue($definition, $idSite); $enabledAllUsers = $this->checkEnabledAllUsers($enabledAllUsers); @@ -153,8 +164,8 @@ class Piwik_SegmentEditor_API public function add($name, $definition, $idSite = false, $autoArchive = false, $enabledAllUsers = false) { - Piwik::checkUserIsNotAnonymous(); - $this->checkIdSite($idSite); + $this->checkUserIsNotAnonymous(); + $idSite = $this->checkIdSite($idSite); $this->checkSegmentName($name); $definition = $this->checkSegmentValue($definition, $idSite); $enabledAllUsers = $this->checkEnabledAllUsers($enabledAllUsers); @@ -201,33 +212,37 @@ class Piwik_SegmentEditor_API return $segment; } - public function getAll($idSite = false, $returnAutoArchived = false) + public function getAll($idSite = false, $returnOnlyAutoArchived = false) { if(!empty($idSite) ) { Piwik::checkUserHasViewAccess($idSite); } else { Piwik::checkUserHasSomeViewAccess(); } + $bind = array(); - $extraWhere = ''; - if($returnAutoArchived) { - $extraWhere = ' AND auto_archive = 1'; - } - + // Build basic segment filtering $whereIdSite = ''; - $bind = array(Piwik::getCurrentUserLogin()); if(!empty($idSite)) { $whereIdSite = 'enable_only_idsite = ? OR '; - $bind = array($idSite, Piwik::getCurrentUserLogin()); + $bind[] = $idSite; + } + + $bind[] = Piwik::getCurrentUserLogin(); + + $extraWhere = ''; + if($returnOnlyAutoArchived) { + $extraWhere = ' AND auto_archive = 1'; } + // Query $sql = "SELECT * " . - " FROM " . Piwik_Common::prefixTable("segment") . - " WHERE ($whereIdSite enable_only_idsite IS NULL) - AND (enable_all_users = 1 OR login = ?) - AND deleted = 0 - $extraWhere - ORDER BY name ASC"; + " FROM " . Piwik_Common::prefixTable("segment") . + " WHERE ($whereIdSite enable_only_idsite = 0) + AND (enable_all_users = 1 OR login = ?) + AND deleted = 0 + $extraWhere + ORDER BY name ASC"; $segments = Zend_Registry::get('db')->fetchAll($sql, $bind); return $segments; diff --git a/plugins/SegmentEditor/Controller.php b/plugins/SegmentEditor/Controller.php index d402f442c7..a540ce4a72 100644 --- a/plugins/SegmentEditor/Controller.php +++ b/plugins/SegmentEditor/Controller.php @@ -41,7 +41,6 @@ class Piwik_SegmentEditor_Controller extends Piwik_Controller $view->savedSegmentsJson = Piwik_Common::json_encode($savedSegments); $view->authorizedToCreateSegments = !Piwik::isUserIsAnonymous(); - $view->segmentTranslations = Piwik_Common::json_encode($this->getTranslations()); $out = $view->render(); echo $out; diff --git a/plugins/SegmentEditor/templates/Segmentation.css b/plugins/SegmentEditor/templates/Segmentation.css index bffe989623..fa5e61346e 100644 --- a/plugins/SegmentEditor/templates/Segmentation.css +++ b/plugins/SegmentEditor/templates/Segmentation.css @@ -1,4 +1,9 @@ /* ADDITIONAL STYLES*/ +.youMustBeLoggedIn { + font-size:8pt; + font-style: italic; + +} .loadingSegment { color: grey; display: block; diff --git a/plugins/SegmentEditor/templates/Segmentation.js b/plugins/SegmentEditor/templates/Segmentation.js index c22a4d3949..6b8bfc7ee7 100644 --- a/plugins/SegmentEditor/templates/Segmentation.js +++ b/plugins/SegmentEditor/templates/Segmentation.js @@ -14,7 +14,7 @@ Segmentation = (function($) { self.currentSegmentStr = ""; self.targetId = "segmentEditorPanel"; self.segmentAccess = "read"; - self.segmentList = []; + self.availableSegments = []; for(var item in config) { @@ -182,7 +182,20 @@ Segmentation = (function($) { $(self.form).find(".segment-content").append(getInitialStateRowsHtml()); doDragDropBindings(); } - + + var getSegmentFromId = function (id) { + if(self.availableSegments.length > 0) { + for(var key in self.availableSegments) + { + segment = self.availableSegments[key]; + if(segment.idsegment == id) { + return segment; + } + } + } + return false; + } + var getListHtml = function() { var html = $("#SegmentEditor > .listHtml").clone(); var segment, injClass; @@ -192,10 +205,10 @@ Segmentation = (function($) { + ' data-definition=""><span class="segname">' + self.translations['SegmentEditor_DefaultAllVisits'] + ' ' + self.translations['General_DefaultAppended'] + '</span></li> '; - if(self.segmentList.length > 0) { - for(var key in self.segmentList) + if(self.availableSegments.length > 0) { + for(var key in self.availableSegments) { - segment = self.segmentList[key]; + segment = self.availableSegments[key]; injClass = ""; if( segment.definition == self.currentSegmentStr){ injClass = 'class="segmentSelected"'; @@ -234,9 +247,9 @@ Segmentation = (function($) { + '">' + self.translations['SegmentEditor_AddNewSegment'] + '</option>'; segmentsDropdown.append(newOption); - for(var key in self.segmentList) + for(var key in self.availableSegments) { - segment = self.segmentList[key]; + segment = self.availableSegments[key]; newOption = '<option data-idsegment="'+segment.idsegment+'" data-definition="'+(segment.definition)+'" title="'+segment.name+'">'+self.shortenSegmentName(segment.name)+'</option>'; segmentsDropdown.append(newOption); } @@ -325,11 +338,15 @@ Segmentation = (function($) { } var openEditForm = function(segment){ - addForm(); + addForm("edit", segment); + $(self.form).find(".segment-content > h3 > span").text(segment.name); $(self.form).find('#available_segments_select > option[data-idsegment="'+segment.idsegment+'"]').prop("selected",true); + $(self.form).find('#available_segments a.dropList').html(self.shortenSegmentName(segment.name, 16)); - + + + if(segment.definition != ""){ revokeInitialStateRows(); var blocks = parseSegmentStr(segment.definition); @@ -368,11 +385,8 @@ Segmentation = (function($) { $(self.content).off("click",".editSegment").on("click", ".editSegment", function(e){ $(this).parents(".segmentationContainer").trigger("click"); var target = $(this).parent("li"); - var segment = {}; - segment.idsegment = target.attr("data-idsegment"); - segment.definition = target.data("definition"); - segment.name = target.attr("title"); - openEditForm(segment); + + openEditFormGivenSegment(target); e.stopPropagation(); e.preventDefault(); }); @@ -492,6 +506,22 @@ Segmentation = (function($) { }); } + function openEditFormGivenSegment(option) { + var segment = {}; + segment.idsegment = option.attr("data-idsegment"); + + + var segmentExtra = getSegmentFromId(segment.idsegment); + for(var item in segmentExtra) + { + segment[item] = segmentExtra[item]; + } + segment.name = option.attr("title"); + segment.definition = option.data("definition"); + + openEditForm(segment); + } + var bindFormEvents = function(){ $(self.form).on("click", "a", function(e){ @@ -518,9 +548,11 @@ Segmentation = (function($) { $(self.form).off("blur", "input#edit_segment_name").on("blur", "input#edit_segment_name", function(e){ var newName = $(this).val(); - $(e.currentTarget).parents("h3").find("span").text(newName).show(); - $(self.form).find("a.editSegmentName").show(); - $(this).remove(); + if(newName.trim() != '') { + $(e.currentTarget).parents("h3").find("span").text(newName).show(); + $(self.form).find("a.editSegmentName").show(); + $(this).remove(); + } }); $(self.form).on("click", '.segment-element', function(event) { @@ -530,12 +562,7 @@ Segmentation = (function($) { $(self.form).find("#available_segments_select").bind("change", function(e){ var option = $(e.currentTarget).find('option:selected'); - var segment = {}; - segment.idsegment = option.attr("data-idsegment"); - segment.name = option.attr("title"); - segment.definition = option.data("definition"); - openEditForm(segment); - + openEditFormGivenSegment(option); }); // attach event that shows/hides child elements of each metric category @@ -777,7 +804,8 @@ Segmentation = (function($) { }); } - var addForm = function(mode){ + // Mode = 'new' or 'edit' + var addForm = function(mode, segment){ $("#segmentEditorPanel").find(".segment-element:visible").unbind().remove(); if(typeof self.form !== "undefined") @@ -792,8 +820,17 @@ Segmentation = (function($) { setLeftMargin('#segmentEditorPanel > .segment-element'); bindFormEvents(); bindSegmentManipulationEvents(); - makeDropList("#enabledAllUsers" , "#enabledAllUsers_select"); + + if(mode == "edit") { + $(self.form).find('#enable_all_users_select > option[value="'+segment.enable_all_users+'"]').prop("selected",true); + $(self.form).find('#visible_to_website_select > option[value="'+segment.enable_only_idsite+'"]').prop("selected",true); + $(self.form).find('#auto_archive_select > option[value="'+segment.auto_archive+'"]').prop("selected",true); + + } + + makeDropList("#enable_all_users" , "#enable_all_users_select"); makeDropList("#visible_to_website" , "#visible_to_website_select"); + makeDropList("#auto_archive" , "#auto_archive_select"); makeDropList("#available_segments" , "#available_segments_select"); $(self.form).find(".saveAndApply").bind("click", function(e){ e.preventDefault(); @@ -809,7 +846,6 @@ Segmentation = (function($) { if(typeof mode !== "undefined" && mode == "new") { $(self.form).find(".editSegmentName").trigger('click'); - $(self.form).find("#edit_segment_name").val(""); } $("#segmentList").hide(); @@ -844,13 +880,16 @@ Segmentation = (function($) { var segmentName = $(self.form).find(".segment-content > h3 >span").text(); var segmentStr = parseForm(); var segmentId = $(self.form).find('#available_segments_select > option:selected').attr("data-idsegment"); - var user = $(self.form).find("#enabledAllUsers_select option:selected").val(); + var user = $(self.form).find("#enable_all_users_select option:selected").val(); + var autoArchive = $(self.form).find("#auto_archive_select option:selected").val() || 0; var params = { "name": segmentName, "definition": segmentStr, "enabledAllUsers": user, - "idSite": $('#visible_to_website').find('option:selected').attr('value') + "autoArchive": autoArchive, + "idSite": $(self.form).find("#visible_to_website_select option:selected").val() }; + // determine if save or update should be performed if(segmentId === ""){ self.addMethod(params); @@ -885,10 +924,10 @@ Segmentation = (function($) { select: function( event, ui ) { event.preventDefault(); ui.item.option.selected = true; - if(ui.item.value) { - dropList.text(ui.item.label); - $(self.form).find(selectId).trigger("change"); - } + // Mark original select>option + $('#SegmentEditor ' + spanId + ' option[value="' + ui.item.value + '"]').prop('selected', true); + dropList.text(ui.item.label); + $(self.form).find(selectId).trigger("change"); } }) .click(function() { @@ -1020,15 +1059,23 @@ $(document).ready( function(){ }, 'POST'); // ajaxHandler.redirectOnSuccess(); ajaxHandler.setLoadingElement(); + ajaxHandler.useCallbackInCaseOfError(); + ajaxHandler.setCallback(function (response) { + if (response && response.result == 'error') { + alert(response.message); + } else { + return broadcast.propagateNewPage('segment='); + } + }); + ajaxHandler.send(true); - return broadcast.propagateNewPage('segment='); }; var segmentFromHash = broadcast.getParamValue('segment', location.hash); var segmentationFtw = new Segmentation({ "targetId" : "segmentList", "segmentAccess" : "write", - "segmentList" : availableSegments, + "availableSegments" : availableSegments, "addMethod": addSegment, "updateMethod": updateSegment, "deleteMethod": deleteSegment, diff --git a/plugins/SegmentEditor/templates/selector.tpl b/plugins/SegmentEditor/templates/selector.tpl index 0179aaef38..f4802d8db3 100644 --- a/plugins/SegmentEditor/templates/selector.tpl +++ b/plugins/SegmentEditor/templates/selector.tpl @@ -1,7 +1,7 @@ <div id="SegmentEditor" style="display:none;"> <div class="segmentationContainer listHtml"> - {if $authorizedToCreateSegments} - <span class="segmentationTitle"><b>{'SegmentEditor_AddNewSegment'}</b></span> + <span class="segmentationTitle"></span> + <ul class="submenu"> <li>{'SegmentEditor_SelectSegmentOfVisitors'|translate} <div class="segmentList"> @@ -10,12 +10,12 @@ </div> </li> </ul> - <a class="add_new_segment">{'SegmentEditor_AddNewSegment'|translate}</a> + {if $authorizedToCreateSegments} + <a class="add_new_segment">{'SegmentEditor_AddNewSegment'|translate}</a> {else} - <span class="segmentationTitle"><b>{'SegmentEditor_AddNewSegment'|translate}</b></span> <ul class="submenu"> - <li> {'SegmentEditor_YouMustBeLoggedInToCreateSegments'|translate} - <br/>› <a href='index.php?module={$loginModule}'>{'Login_LogIn'|translate}</a></strong> + <li> <span class='youMustBeLoggedIn'>{'SegmentEditor_YouMustBeLoggedInToCreateSegments'|translate} + <br/>› <a href='index.php?module={$loginModule}'>{'Login_LogIn'|translate}</a> </span></strong> </li> </ul> {/if} @@ -103,9 +103,9 @@ <div class="segment-content"> {if $isSuperUser} <div class="segment-top"> - {'SegmentEditor_ThisSegmentIsVisibleTo'|translate} <span id="enabledAllUsers"><strong> - <select id="enabledAllUsers_select"> - <option selected="" value="0">{'SegmentEditor_VisibleToMe'|translate}</option> + {'SegmentEditor_ThisSegmentIsVisibleTo'|translate} <span id="enable_all_users"><strong> + <select id="enable_all_users_select"> + <option selected="1" value="0">{'SegmentEditor_VisibleToMe'|translate}</option> <option value="1">{'SegmentEditor_VisibleToAllUsers'|translate}</option> </select> </strong></span> @@ -116,9 +116,16 @@ <option value="0">{'SegmentEditor_SegmentDisplayedAllWebsites'|translate}</option> </select> </strong></span> + {'General_And'|translate} <span id="auto_archive"><strong> + <select id="auto_archive_select"> + <option selected="1" value="0">{'SegmentEditor_AutoArchiveRealTime'|translate} {'General_DefaultAppended'|translate}</option> + <option value="1">{'SegmentEditor_AutoArchivePreProcessed'|translate} </option> + </select> + </strong></span> + </div> {/if} - <h3>{'General_Name'|translate}: <span class="segmentName">{'SegmentEditor_NewSegment'|translate}</span> <a class="editSegmentName" href="#">{'General_Edit'|translate|strtolower}</a></h3> + <h3>{'General_Name'|translate}: <span class="segmentName"></span> <a class="editSegmentName" href="#">{'General_Edit'|translate|strtolower}</a></h3> </div> <div class="segment-footer"> <span class="segmentFooterNote">The Segment Editor was <a href='http://crowdfunding.piwik.org/custom-segments-editor/' target='_blank'>crowdfunded</a> with the awesome support of 80 companies and Piwik users worldwide!</span> diff --git a/plugins/Widgetize/Widgetize.php b/plugins/Widgetize/Widgetize.php index 4de1afe86d..ddb2a2eb45 100644 --- a/plugins/Widgetize/Widgetize.php +++ b/plugins/Widgetize/Widgetize.php @@ -39,7 +39,7 @@ class Piwik_Widgetize extends Piwik_Plugin public function addTopMenu() { $tooltip = Piwik_Translate('Widgetize_TopLinkTooltip'); - $urlParams = array('module' => 'Widgetize', 'action' => 'index'); + $urlParams = array('module' => 'Widgetize', 'action' => 'index', 'segment' => false); Piwik_AddTopMenu('General_Widgets', $urlParams, true, 5, $isHTML = false, $tooltip); } |