diff --git a/application/config/autoload.php b/application/config/autoload.php index 0ebf20d..5980c5c 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -76,7 +76,7 @@ $autoload['libraries'] = array('database', 'session'); | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array('url', 'file'); +$autoload['helper'] = array('url', 'file', 'text', 'directory', 'ecards'); /* diff --git a/application/config/constants.php b/application/config/constants.php index d58b401..14c93ca 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -41,6 +41,14 @@ define('FOPEN_WRITE_CREATE_STRICT', 'xb'); define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b'); +define('FONTPATH', APPPATH . 'fonts/'); +define('HEADERTEXT', FONTPATH . 'Open_Sans/OpenSans-Bold.ttf'); +define('BODYTEXT', FONTPATH . 'Open_Sans/OpenSans-Regular.ttf'); + +define('ASSETSPATH', FCPATH . 'assets/'); + +define('BASECARDS', ASSETSPATH . 'basecards/'); +define('CARDPATH', ASSETSPATH . 'cards/'); /* End of file constants.php */ diff --git a/application/config/routes.php b/application/config/routes.php index aa08896..a554521 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -49,10 +49,12 @@ $route['default_controller'] = "welcome"; $route['404_override'] = 'welcome/error404'; $route['uusi'] = $route['default_controller']."/newCard"; +$route['tallenna'] = $route['default_controller']."/saveCard"; $route['kaikki'] = $route['default_controller']."/ecards"; $route['ecards'] = $route['default_controller']."/ecards"; $route['ecards/(:any)'] = $route['default_controller']."/ecards/$1"; $route['info'] = $route['default_controller']."/info"; +$route['preview/(:any)'] = $route['default_controller']."/preview/$1"; /* End of file routes.php */ /* Location: ./application/config/routes.php */ diff --git a/application/controllers/welcome.php b/application/controllers/welcome.php index 8b91950..08ac08c 100644 --- a/application/controllers/welcome.php +++ b/application/controllers/welcome.php @@ -2,11 +2,17 @@ class Welcome extends CI_Controller { + private $user; + public $card_count; public function __construct() { parent::__construct(); $this->load->model('ecard_model', 'ecard'); + $this->load->model('erkanaauth_model', 'erkana'); + + $this->user = $this->erkana->getUser(); + $this->card_count = $this->ecard->countStatuses(); } public function index() @@ -14,7 +20,9 @@ class Welcome extends CI_Controller $data = array( 'page_title' => array( 'Etusivu', 'Ystäväkylä eKortti' ), - 'page_classes' => array( 'frontpage' ) + 'page_classes' => array( 'frontpage' ), + 'count' => $this->card_count, + 'user' => $this->user ); $this->load->view('_header', $data); @@ -26,7 +34,9 @@ class Welcome extends CI_Controller { $data = array( 'page_title' => array( 'Tietoa', 'Ystäväkylä eKortti' ), - 'page_classes' => array( 'info' ) + 'page_classes' => array( 'info' ), + 'count' => $this->card_count, + 'user' => $this->user ); $this->load->view('_header', $data); @@ -40,15 +50,9 @@ class Welcome extends CI_Controller $data = array( 'page_title' => array( 'Uusi eKortti', 'Ystäväkylä eKortti' ), 'page_classes' => array( 'new_card' ), - - 'images' => array( - "http://placekitten.com/800/550", - "http://placekitten.com/g/800/550", - "http://placekitten.com/800/551", - "http://placekitten.com/g/800/551", - "http://placekitten.com/800/552", - "http://placekitten.com/g/800/552" - ) + 'count' => $this->card_count, + 'images' => fetchBaseCards(), + 'user' => $this->user ); $this->load->view('_header', $data); @@ -59,7 +63,9 @@ class Welcome extends CI_Controller public function ecards($card_id = null) { $data = array( - 'page_classes' => array( 'ecards' ) + 'page_classes' => array( 'ecards' ), + 'count' => $this->card_count, + 'user' => $this->user ); if (empty($card_id)) { @@ -85,6 +91,8 @@ class Welcome extends CI_Controller $data['ecard']->id = $card_id; $data['ecard']->response = "error"; $data['ecard']->response_text = "No card found with that id"; + } else { + $data['ecard']->response = 200; } $data['page_classes'][] = 'show_one'; @@ -97,11 +105,85 @@ class Welcome extends CI_Controller return false; } + + public function preview($urldata = null) + { + if (empty($urldata)) { + return false; + } + + $data = array(); + $rawdata = explode(",", urldecode($urldata)); + foreach ($rawdata as $dataline) { + list($key, $value) = explode("=", $dataline); + + $value = str_replace(";-;", "\r", $value); + $value = str_replace(";:;", "\n", $value); + $data[$key] = urldecode($value); + } + + $opts = parseImageOptions($data); + + $imgresource = $this->ecard->createCard( + $opts['cardPath'], + $opts['cardHead'], + $opts['cardText'], + $opts['cardHeadPlace'], + $opts['cardTextPlace'], + $opts['cardHeadSize'], + $opts['cardTextSize'], + $opts['cardSize'] + ); + + $this->ecard->showCard($imgresource); } - public function upload() + public function saveCard() { - # code... + $image = $this->input->post(); + + if (empty($image)) { + redirect("uusi"); + } + + $opts = parseImageOptions($image); + $entry = parseCardEntryValues($image); + + $imgresource = $this->ecard->createCard( + $opts['cardPath'], + $opts['cardHead'], + $opts['cardText'], + $opts['cardHeadPlace'], + $opts['cardTextPlace'], + $opts['cardHeadSize'], + $opts['cardTextSize'], + $opts['cardSize'] + ); + + if (empty($imgresource)) { + $this->session->flash_data('message', 'Virhe luodessa kuvaa'); + redirect("uusi"); + } + + if (empty($entry)) { + $this->session->flash_data('message', 'Virhe tiedoissa'); + redirect("uusi"); + } + + if ($this->ecard->get_by('hash', $entry['hash'])) { + redirect("ecards/" . $entry['hash']); + } + + if (($card = $this->ecard->savecard($imgresource, $entry['hash']))) { + + if ($card != $entry['hash']) { + log_message('debug', "card: {$card} != hash: {$entry['hash']}"); + } + + $this->ecard->insert($entry); + + redirect(site_url('ecards/' . $entry['hash'])); + } } } diff --git a/application/controllers/yllapito.php b/application/controllers/yllapito.php index 0a1848b..fd83ff3 100644 --- a/application/controllers/yllapito.php +++ b/application/controllers/yllapito.php @@ -3,6 +3,7 @@ class Yllapito extends CI_Controller { private $user; + public $card_count; public function __construct() { @@ -11,6 +12,10 @@ class Yllapito extends CI_Controller $this->load->model('erkanaauth_model', 'erkana'); $this->user = $this->erkana->getUser(); + + if (!empty($this->user)) { + $this->card_count = $this->ecard->countStatuses(); + } } public function index() @@ -23,6 +28,7 @@ class Yllapito extends CI_Controller 'page_title' => array( 'Etusivu', 'Ystäväkylä eKortti' ), 'page_classes' => array( 'frontpage' ), 'user' => $this->user, + 'count' => $this->card_count, 'messages' => $this->session->flashdata('messages') ); diff --git a/application/fonts/Open_Sans/LICENSE.txt b/application/fonts/Open_Sans/LICENSE.txt new file mode 100755 index 0000000..75b5248 --- /dev/null +++ b/application/fonts/Open_Sans/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/application/fonts/Open_Sans/OpenSans-Bold.ttf b/application/fonts/Open_Sans/OpenSans-Bold.ttf new file mode 100755 index 0000000..fd79d43 Binary files /dev/null and b/application/fonts/Open_Sans/OpenSans-Bold.ttf differ diff --git a/application/fonts/Open_Sans/OpenSans-BoldItalic.ttf b/application/fonts/Open_Sans/OpenSans-BoldItalic.ttf new file mode 100755 index 0000000..9bc8009 Binary files /dev/null and b/application/fonts/Open_Sans/OpenSans-BoldItalic.ttf differ diff --git a/application/fonts/Open_Sans/OpenSans-ExtraBold.ttf b/application/fonts/Open_Sans/OpenSans-ExtraBold.ttf new file mode 100755 index 0000000..21f6f84 Binary files /dev/null and b/application/fonts/Open_Sans/OpenSans-ExtraBold.ttf differ diff --git a/application/fonts/Open_Sans/OpenSans-ExtraBoldItalic.ttf b/application/fonts/Open_Sans/OpenSans-ExtraBoldItalic.ttf new file mode 100755 index 0000000..31cb688 Binary files /dev/null and b/application/fonts/Open_Sans/OpenSans-ExtraBoldItalic.ttf differ diff --git a/application/fonts/Open_Sans/OpenSans-Italic.ttf b/application/fonts/Open_Sans/OpenSans-Italic.ttf new file mode 100755 index 0000000..c90da48 Binary files /dev/null and b/application/fonts/Open_Sans/OpenSans-Italic.ttf differ diff --git a/application/fonts/Open_Sans/OpenSans-Light.ttf b/application/fonts/Open_Sans/OpenSans-Light.ttf new file mode 100755 index 0000000..0d38189 Binary files /dev/null and b/application/fonts/Open_Sans/OpenSans-Light.ttf differ diff --git a/application/fonts/Open_Sans/OpenSans-LightItalic.ttf b/application/fonts/Open_Sans/OpenSans-LightItalic.ttf new file mode 100755 index 0000000..68299c4 Binary files /dev/null and b/application/fonts/Open_Sans/OpenSans-LightItalic.ttf differ diff --git a/application/fonts/Open_Sans/OpenSans-Regular.ttf b/application/fonts/Open_Sans/OpenSans-Regular.ttf new file mode 100755 index 0000000..db43334 Binary files /dev/null and b/application/fonts/Open_Sans/OpenSans-Regular.ttf differ diff --git a/application/fonts/Open_Sans/OpenSans-Semibold.ttf b/application/fonts/Open_Sans/OpenSans-Semibold.ttf new file mode 100755 index 0000000..1a7679e Binary files /dev/null and b/application/fonts/Open_Sans/OpenSans-Semibold.ttf differ diff --git a/application/fonts/Open_Sans/OpenSans-SemiboldItalic.ttf b/application/fonts/Open_Sans/OpenSans-SemiboldItalic.ttf new file mode 100755 index 0000000..59b6d16 Binary files /dev/null and b/application/fonts/Open_Sans/OpenSans-SemiboldItalic.ttf differ diff --git a/application/helpers/ecards_helper.php b/application/helpers/ecards_helper.php index afb4efe..c446e88 100644 --- a/application/helpers/ecards_helper.php +++ b/application/helpers/ecards_helper.php @@ -75,3 +75,228 @@ function checkboxed( return $string; } + +function fetchBaseCards($from = null) +{ + if (empty($from)) { + $from = APPPATH . '../assets/basecards/'; + } + $map = directory_map($from, 1); + + if (! empty($map)) { + $images = array(); + foreach ($map as $image) { + $images[] = site_url('assets/basecards/' . $image); + } + } else { + return false; + } + + return $images; +} + +function footerAssets() +{ + $assets = array( + 'jquery.min.js', + 'custom.modernizr.min.js', // Foundation flavored Modernizr + 'foundation.min.js', // Foundation 1.4.1 + 'image-picker.min.js', // Image Picker 0.1.4 + 'jquery.validate.min.js', // jQuery Validation Plugin 1.11.1 + 'additional-methods.min.js',// jQuery Validation Methods + 'messages_fi.js', // jQuery Validation Plugin Finnish translation + 'jquery-ui.min.js', // jQuery UI 1.10.3 + 'scripts.js' // Our scripts + ); + + if (ENVIRONMENT == 'development') { + $assets[] = 'dev.js'; + } + + return $assets; +} + +function calculateTextBox($text = '', $fontFile = null, $fontSize = null, $fontAngle = 0) +{ + /************ + simple function that calculates the *exact* bounding box (single pixel precision). + The function returns an associative array with these keys: + left, top: coordinates you will pass to imagettftext + width, height: dimension of the image you have to create + *************/ + $rect = imagettfbbox($fontSize, $fontAngle, $fontFile, $text); + $minX = min(array($rect[0], $rect[2], $rect[4], $rect[6])); + $maxX = max(array($rect[0], $rect[2], $rect[4], $rect[6])); + $minY = min(array($rect[1], $rect[3], $rect[5], $rect[7])); + $maxY = max(array($rect[1], $rect[3], $rect[5], $rect[7])); + + return array( + "left" => abs($minX) - 1, + "top" => abs($minY) - 1, + "width" => $maxX - $minX, + "height" => $maxY - $minY, + "box" => $rect + ); +} + +function cardSizeRatio($full_w = 0, $full_h = 0, $prev_w = 0, $prev_h = 0) +{ + $ratio_w = ($full_w/$prev_w); + $ratio_h = ($full_h/$prev_h); + + $results = array( + 'w' => $ratio_w, + 'h' => $ratio_h + ); + + return $results; +} + +function parseImageOptions($post) +{ + /* + $cardPath = null, + $cardHead = null, + $cardText = null, + $cardHeadPlace = array(), + $cardTextPlace = array(), + $cardHeadSize = array(), + $cardTextSize = 0 + */ + + /* + sender_name=Ismo + sender_email=ismo%40ma.com + receiver_name=ismo + receiver_email=ismo%40me.com + message_title=Moikka+täältä + message_text=aöslkdjföalkjsdfölakjsdföljk + sizeOf_message_text_w=381 + sizeOf_message_text_h=18 + sizeOf_message_title_w=381 + sizeOf_message_title_h=30 + placeOf_message_text_y=72 + placeOf_message_text_x=10 + placeOf_message_title_y=20 + placeOf_message_title_x=10 + participate=yes + publiccard=yes + submit=Lähetä+eKorttisi%21 + submit=Lähetä+eKorttisi%21 + */ + + $message_title = (empty($post['message_title'])) ? '' : $post['message_title']; + $message_text = (empty($post['message_text'])) ? '' : $post['message_text']; + + $image_url = str_replace("-:-", "/", $post['select_image']); + + $card = str_replace(site_url(), FCPATH, $image_url); + + $headerTextFix = -3; + //$headerTextFix = 40*(72/96); // 72dpi -> 96dpi, + 5 padding + $messageTextFix = 28*(72/96) +3; // 72dpi -> 96dpi, + 5 padding + + $opts = array( + 'cardPath' => $card, + 'cardHead' => $message_title, + 'cardText' => $message_text, + 'cardHeadPlace' => array( + 'x' => $post['placeOf_message_title_x'] + 3, + 'y' => $post['placeOf_message_title_y'] + $headerTextFix //20 + ), + 'cardTextPlace' => array( + 'x' => $post['placeOf_message_text_x'] + 3, + 'y' => $post['placeOf_message_text_y'] + $messageTextFix //40 + ), + 'cardHeadSize' => array( + 'w' => $post['sizeOf_message_title_w'], + 'h' => $post['sizeOf_message_title_h'] + ), + 'cardTextSize' => array( + 'w' => $post['sizeOf_message_text_w'], + 'h' => $post['sizeOf_message_text_h'] + ), + 'cardSize' => array( + 'w' => $post['sizeOf_image_w'], + 'h' => $post['sizeOf_image_h'] + ) + ); + + return $opts; +} + +function parseCardEntryValues($post) +{ + if (empty($post)) { + return false; + } + /* + sender_name=Ismo + sender_email=ismo%40ma.com + receiver_name=ismo + receiver_email=ismo%40me.com + message_title=Moikka+täältä + message_text=aöslkdjföalkjsdfölakjsdföljk + sizeOf_message_text_w=381 + sizeOf_message_text_h=18 + sizeOf_message_title_w=381 + sizeOf_message_title_h=30 + placeOf_message_text_y=72 + placeOf_message_text_x=10 + placeOf_message_title_y=20 + placeOf_message_title_x=10 + participate=yes + publiccard=yes + submit=Lähetä+eKorttisi%21 + submit=Lähetä+eKorttisi%21 + */ + unset($post['submit']); + + $card = str_replace(site_url(), FCPATH, $post['select_image']); + + if ($post['publiccard'] == 'yes') { + $private = 'no'; + } else { + $private = 'yes'; + } + + if ($post['participate'] == 'yes') { + $participate = 'yes'; + } else { + $participate = 'no'; + } + + $hash = md5( + $post['sender_name'] . + $post['sender_email'] . + $post['message_title'] . + $post['message_text'] + ); + + $values = array( + // Sender and receiver details + 'uploader_name' => $post['sender_name'], + 'uploader_email' => $post['sender_email'], + 'receiver_name' => $post['receiver_name'], + 'receiver_email' => $post['receiver_email'], + // The message on card + 'message_title' => $post['message_title'], + 'message_content' => $post['message_text'], + // Card and message placement details + 'base_card' => $card, + 'sizeof_message_title_w' => $post['sizeOf_message_title_w'], + 'sizeof_message_title_h' => $post['sizeOf_message_title_h'], + 'sizeof_message_text_w' => $post['sizeOf_message_text_w'], + 'sizeof_message_text_h' => $post['sizeOf_message_text_h'], + 'placeof_message_title_x' => $post['placeOf_message_title_x'], + 'placeof_message_title_y' => $post['placeOf_message_title_y'] + 30 + 5, + 'placeof_message_text_x' => $post['placeOf_message_text_x'], + 'placeof_message_text_y' => $post['placeOf_message_text_y'] + 32 + 25, + 'participate' => $participate, + 'private' => $private, + 'card_status' => 'queue', + 'hash' => $hash + ); + + return $values; +} diff --git a/application/models/ecard_model.php b/application/models/ecard_model.php index 573ae9d..9e1986a 100644 --- a/application/models/ecard_model.php +++ b/application/models/ecard_model.php @@ -12,9 +12,202 @@ class Ecard_model extends MY_Model parent::__construct(); } - protected function timestamps($book) + public function formatPost($data = null) { - $book['created_at'] = $book['updated_at'] = date('Y-m-d H:i:s'); - return $book; + $format = $data; + unset( + $format['from_page'], + $format['page'] + ); + + $format = $format['data']; + + if (empty($format)) { + return false; + } else { + foreach ($format as $card_id => $item) { + unset($card_id, $item); + } + + } + return $format; + } + + public function createCard( + $cardPath = null, + $cardHead = '', + $cardText = '', + $cardHeadPlace = array(), + $cardTextPlace = array(), + $cardHeadSize = array(), + $cardTextSize = array(), + $cardSize = array() + ) { + + if (empty($cardSize)) { + $cardSize["w"] = 800; + $cardSize["h"] = 600; + } + + if (empty($cardHeadSize)) { + $cardHeadSize["w"] = 600; + $cardHeadSize["h"] = 200; + } + + if (empty($cardTextSize)) { + $cardTextSize["w"] = 600; + $cardTextSize["h"] = 200; + } + + // If we don't have card, use default + if (empty($cardPath) || ! is_readable($cardPath)) { + $cardPath = FCPATH . 'assets/basecards/1.jpg'; + } + + // Header text place, 5x5 from top left corner + if (empty($cardHeadPlace)) { + $cardHeadPlace["x"] = 5; + $cardHeadPlace["y"] = 35; + } + + // Text place defaults, x 30 px lower than header text + if (empty($cardTextPlace)) { + $cardTextPlace["x"] = 5; + $cardTextPlace["y"] = 65; + } + + // Create image resource and allocate background as white + $rImg = ImageCreateFromJPEG($cardPath); + + // Image size + $img_w = imagesx($rImg); + $img_h = imagesy($rImg); + + $ratio = cardSizeRatio( + $img_w, + $img_h, + $cardSize['w'], + $cardSize['h'] + ); + + // Calculate difference between preview and real + $head_x = $cardHeadPlace['x'] * $ratio['w']; + $head_y = $cardHeadPlace['y'] * $ratio['h']; + $text_x = $cardTextPlace['x'] * $ratio['w']; + $text_y = $cardTextPlace['y'] * $ratio['h']; + + // Set white color to white + $white = imagecolorallocate($rImg, 255, 255, 255); + + // Header text + // resource, text size, angle, x, y, color, font file, text + if (! empty($cardHead)) { + imagettftext( + $rImg, + 40, + 0, + $head_x, //$cardHeadPlace["x"], + $head_y, //$cardHeadPlace["y"], + $white, + HEADERTEXT, + $cardHead + ); + } + + // Content text + // resource, text size, angle, x, y, color, font file, text + if (! empty($cardText)) { + imagettftext( + $rImg, + 28, + 0, + $text_x, //$cardTextPlace["x"], + $text_y, //$cardTextPlace["y"], + $white, + BODYTEXT, + $cardText + ); + } + + // Return our image as png + return $rImg; + } + + public function showCard($rImg = null) + { + if (empty($rImg) || ! is_resource($rImg)) { + return false; + } + + header('Content-Type: image/png'); + imagepng($rImg, null, 9, PNG_FILTER_PAETH); + imagedestroy($rImg); + } + + public function saveCard($rImg = null, $name = null) + { + if (empty($rImg) || ! is_resource($rImg)) { + return false; + } + + $image = imagepng($rImg, CARDPATH . $name . '.png', 9, PNG_FILTER_PAETH); + imagedestroy($rImg); + + if ($image) { + return $name; + } else { + return false; + } + } + + public function saveCards($cardData = null) + { + if (empty($cardData)) { + return false; + } + + foreach ($cardData as $id => $data) { + try { + $this->ecard->update($id, $data); + } catch (Exception $e) { + return $e->getMessage(); + } + } + return true; + } + + public function countStatuses() + { + $return = new stdClass(); + + // Our type counts, default to zero amount + $return->all = 0; + $return->queue = 0; + $return->private = 0; + $return->public = 0; + $return->hidden = 0; + + // Count amounts + $result = $this->db->select("COUNT(*) num, card_status") + ->group_by("card_status") + ->get($this->_table) + ->result_object(); + + // Make easier to use + if (!empty($result)) { + foreach ($result as $count) { + $return->{$count->card_status} = $count->num; + $return->all += $count->num; + } + } + + // Return our defaults, or our counts + return $return; + } + + protected function timestamps($ecard) + { + $ecard['created_at'] = $ecard['updated_at'] = date('Y-m-d H:i:s'); + return $ecard; } } diff --git a/application/views/_footer.php b/application/views/_footer.php index e835312..e706fe9 100644 --- a/application/views/_footer.php +++ b/application/views/_footer.php @@ -1,30 +1,25 @@ -