diff --git a/assets/google-sheets-fetcher.php b/assets/google-sheets-fetcher.php index 8b4b23a..b474d49 100644 --- a/assets/google-sheets-fetcher.php +++ b/assets/google-sheets-fetcher.php @@ -83,8 +83,16 @@ function fetchSheetData($sheetCSVURL, $dataCoordinates) { return "ERR"; } + $column = $coordinates[0]; + $row = $coordinates[1]; + + $numColumns = count($data[0]); + $numRows = count($data); + + //return $column . "," . $row . " " . $numColumns . "," . $numRows; + // if the coordinate input is outside of the range, throw an error - if($coordinates[1] > count($data) || $coordinates[0] < 0 || $coordinates[0] > count($data[$coordinates[1]]) || $coordinates[1] < 0) { + if($column > $numColumns - 1 || $column < 0 || $row > $numRows - 1 || $row < 0) { error_log('Google Sheet Integration Error: Coordinate Input outside of Sheet Range'); return "ERR"; } diff --git a/src/render.php b/src/render.php index 97e31be..6c8313c 100644 --- a/src/render.php +++ b/src/render.php @@ -27,58 +27,95 @@ function pullDescription($attributes) { return fetchSheetData($attributes["sheetCSVURL"], $attributes["descriptionLocation"]); } -// renders the block -function create_block_google_sheets_block_render($attributes, $content, $block) { - $wrapper_attributes = get_block_wrapper_attributes(); +// creates a new description element +function createDescriptionElement($attributes) { + $descriptionSize = $attributes["descriptionSize"]; + $descriptionAlignment = $attributes["descriptionAlignment"]; + $descriptionColor = $attributes["descriptionColor"]; + + $flipPositions = $attributes["flipPositions"]; + + $enableManualDescription = !array_key_exists("descriptionLocation", $attributes) || $attributes["descriptionLocation"] == ""; + $descriptionValue = $enableManualDescription ? esc_html($attributes["description"]) : esc_html(pullDescription($attributes)); + + $description = "
"; + + return $description; +} + +// creates the data element +function createDataElement($attributes) { + $dataValue = esc_html(pullData($attributes)); + + $dataSize = $attributes["dataSize"]; + $dataAlignment = $attributes["dataAlignment"]; + $dataColor = $attributes["dataColor"]; - // whether or not the user has set a description manually - $manualDescription = !array_key_exists("descriptionLocation", $attributes) || $attributes["descriptionLocation"] == ""; + $flipPositions = $attributes["flipPositions"]; - $dataValue = pullData($attributes); + $enableAnimatedCounting = $attributes["animatedCounting"]; + $animatedCountDuration = $attributes["countDuration"]; + + $dataPrefix = esc_html($attributes["dataPrefix"]); + $enableDataPrefix = $dataPrefix && $dataPrefix != ""; + + $dataSuffix = esc_html($attributes["dataSuffix"]); + $enableDataSuffix = $dataSuffix && $dataSuffix != ""; $data = "
"; + // if animated counting is enabled, make it start at 0. + if($enableAnimatedCounting) { + $data .= ">" . $dataPrefix . "0" . $dataSuffix . "
"; } else { - $data .= ">" . $attributes["dataPrefix"] . $dataValue . $attributes["dataSuffix"] . ""; + $data .= ">" . $dataPrefix . $dataValue . $dataSuffix . ""; } - - $description = ""; + + return $data; +} + +// renders the block +function create_block_google_sheets_block_render($attributes, $content, $block) { + $wrapper_attributes = get_block_wrapper_attributes(); + + $flipPositions = $attributes["flipPositions"]; + + $description = createDescriptionElement($attributes); + $data = createDataElement($attributes); return "