0 * and log errors with CakeLog when debug = 0. * * Options: * * - `handler` - callback - The callback to handle errors. You can set this to any callable type, * including anonymous functions. * - `level` - int - The level of errors you are interested in capturing. * - `trace` - boolean - Include stack traces for errors in log files. * * @see ErrorHandler for more information on error handling and configuration. */ Configure::write('Error', array( 'handler' => 'ErrorHandler::handleError', 'level' => E_ALL & ~E_DEPRECATED & ~E_STRICT, 'trace' => true )); /** * Configure the Exception handler used for uncaught exceptions. By default, * ErrorHandler::handleException() is used. It will display a HTML page for the exception, and * while debug > 0, framework errors like Missing Controller will be displayed. When debug = 0, * framework errors will be coerced into generic HTTP errors. * * Options: * * - `handler` - callback - The callback to handle exceptions. You can set this to any callback type, * including anonymous functions. * - `renderer` - string - The class responsible for rendering uncaught exceptions. If you choose a custom class you * should place the file for that class in app/Lib/Error. This class needs to implement a render method. * - `log` - boolean - Should Exceptions be logged? * * @see ErrorHandler for more information on exception handling and configuration. */ Configure::write('Exception', array( 'handler' => 'ErrorHandler::handleException', 'renderer' => 'ExceptionRenderer', 'log' => true )); /** * Application wide charset encoding */ Configure::write('App.encoding', 'UTF-8'); /** * To configure CakePHP *not* to use mod_rewrite and to * use CakePHP pretty URLs, remove these .htaccess * files: * * /.htaccess * /app/.htaccess * /app/webroot/.htaccess * * And uncomment the App.baseUrl below: */ //Configure::write('App.baseUrl', env('SCRIPT_NAME')); /** * Uncomment the define below to use CakePHP prefix routes. * * The value of the define determines the names of the routes * and their associated controller actions: * * Set to an array of prefixes you want to use in your application. Use for * admin or other prefixed routes. * * Routing.prefixes = array('admin', 'manager'); * * Enables: * `admin_index()` and `/admin/controller/index` * `manager_index()` and `/manager/controller/index` * */ //Configure::write('Routing.prefixes', array('admin')); /** * Turn off all caching application-wide. * */ //Configure::write('Cache.disable', true); /** * Enable cache checking. * * If set to true, for view caching you must still use the controller * public $cacheAction inside your controllers to define caching settings. * You can either set it controller-wide by setting public $cacheAction = true, * or in each action using $this->cacheAction = true. * */ Configure::write('Cache.check', false); /** * Defines the default error type when using the log() function. Used for * differentiating error logging and debugging. Currently PHP supports LOG_DEBUG. */ define('LOG_ERROR', LOG_ERR); /** * Session configuration. * * Contains an array of settings to use for session configuration. The defaults key is * used to define a default preset to use for sessions, any settings declared here will override * the settings of the default config. * * ## Options * * - `Session.cookie` - The name of the cookie to use. Defaults to 'CAKEPHP' * - `Session.timeout` - The number of minutes you want sessions to live for. This timeout is handled by CakePHP * - `Session.cookieTimeout` - The number of minutes you want session cookies to live for. * - `Session.checkAgent` - Do you want the user agent to be checked when starting sessions? You might want to set the * value to false, when dealing with older versions of IE, Chrome Frame or certain web-browsing devices and AJAX * - `Session.defaults` - The default configuration set to use as a basis for your session. * There are four builtins: php, cake, cache, database. * - `Session.handler` - Can be used to enable a custom session handler. Expects an array of of callables, * that can be used with `session_save_handler`. Using this option will automatically add `session.save_handler` * to the ini array. * - `Session.autoRegenerate` - Enabling this setting, turns on automatic renewal of sessions, and * sessionids that change frequently. See CakeSession::$requestCountdown. * - `Session.ini` - An associative array of additional ini values to set. * * The built in defaults are: * * - 'php' - Uses settings defined in your php.ini. * - 'cake' - Saves session files in CakePHP's /tmp directory. * - 'database' - Uses CakePHP's database sessions. * - 'cache' - Use the Cache class to save sessions. * * To define a custom session handler, save it at /app/Model/Datasource/Session/.php. * Make sure the class implements `CakeSessionHandlerInterface` and set Session.handler to * * To use database sessions, run the app/Config/Schema/sessions.php schema using * the cake shell command: cake schema create Sessions * */ Configure::write('Session', array( 'defaults' => 'php', 'timeout' => 1440, //24 hours )); /** * The level of CakePHP security. */ Configure::write('Security.level', 'medium'); /** * A random string used in security hashing methods. */ Configure::write('Security.salt', 'EconoWebExpress10172012'); /** * A random numeric string (digits only) used to encrypt/decrypt strings. */ Configure::write('Security.cipherSeed', '1357924680'); /** * Apply timestamps with the last modified time to static assets (js, css, images). * Will append a querystring parameter containing the time the file was modified. This is * useful for invalidating browser caches. * * Set to `true` to apply timestamps when debug > 0. Set to 'force' to always enable * timestamping regardless of debug value. */ //Configure::write('Asset.timestamp', true); /** * Compress CSS output by removing comments, whitespace, repeating tags, etc. * This requires a/var/cache directory to be writable by the web server for caching. * and /vendors/csspp/csspp.php * * To use, prefix the CSS link URL with '/ccss/' instead of '/css/' or use HtmlHelper::css(). */ //Configure::write('Asset.filter.css', 'css.php'); /** * Plug in your own custom JavaScript compressor by dropping a script in your webroot to handle the * output, and setting the config below to the name of the script. * * To use, prefix your JavaScript link URLs with '/cjs/' instead of '/js/' or use JavaScriptHelper::link(). */ //Configure::write('Asset.filter.js', 'custom_javascript_output_filter.php'); /** * The classname and database used in CakePHP's * access control lists. */ Configure::write('Acl.classname', 'DbAcl'); Configure::write('Acl.database', 'default'); /** * Uncomment this line and correct your server timezone to fix * any date & time related errors. */ //date_default_timezone_set('UTC'); /** * Pick the caching engine to use. If APC is enabled use it. * If running via cli - apc is disabled by default. ensure it's available and enabled in this case * * Note: 'default' and other application caches should be configured in app/Config/bootstrap.php. * Please check the comments in boostrap.php for more info on the cache engines available * and their setttings. */ $engine = 'File'; /* // IMPORTANT: ALWAYS USE FILE ENGINE // APC might cause problems on servers with multiple installations if (extension_loaded('apc') && function_exists('apc_dec') && (php_sapi_name() !== 'cli' || ini_get('apc.enable_cli'))) { //$engine = 'Apc'; } */ // In development mode, caches should expire quickly. $duration = '+999 days'; if (Configure::read('debug') >= 1) { $duration = '+10 seconds'; } // Prefix each application on the same server with a different string, to avoid Memcache and APC conflicts. // get root folder name and use as prefix $xpath = explode('/app/webroot/index.php', $_SERVER["SCRIPT_FILENAME"]); $xpath = explode('/', $xpath[0]); $prefix = $xpath[count($xpath)-1] . '_'; /** * Configure the cache used for general framework caching. Path information, * object listings, and translation cache files are stored with this configuration. */ Cache::config('_cake_core_', array( 'engine' => $engine, 'prefix' => $prefix . 'cake_core_', 'path' => CACHE . 'persistent' . DS, 'serialize' => ($engine === 'File'), 'duration' => $duration )); /** * Configure the cache for model and datasource caches. This cache configuration * is used to store schema descriptions, and table listings in connections. */ Cache::config('_cake_model_', array( 'engine' => $engine, 'prefix' => $prefix . 'cake_model_', 'path' => CACHE . 'models' . DS, 'serialize' => ($engine === 'File'), 'duration' => $duration )); /* app config */ Cache::config('1hour', array( 'engine' => 'File', 'prefix' => $prefix . 'cake_misc_', 'path' => CACHE . 'misc' . DS, 'serialize' => true, 'duration' => '+1 hours' )); // generic cms cache (for pages, etc) Cache::config('page_cache', array( 'engine' => 'File', 'prefix' => $prefix . 'page_', 'path' => CACHE . 'views' . DS, 'duration' => '+999 days', )); Cache::config('db_cache', array( 'engine' => 'File', 'prefix' => $prefix . 'db_', 'path' => CACHE . 'views' . DS, 'duration' => '+999 days', )); // static page caching for pages, content groups, etc Configure::write('Cms.enable_page_cache', false); // db query caching used on the store (and other places) Configure::write('Cms.enable_db_cache', false); // this will log all sql queries on tmp/logs/sql.log // it is also good for debugging query caching Configure::write('Cms.enable_sql_log', false); require_once APP.'Vendor/PageCache.php'; require_once APP.'Vendor/DbCache.php'; # note: # new site specific configs can be added here since config.php should not be overwritten on upgrades # but check first if it does not exist yet # eg. # if(is_null(Configure::read('Cms.some_new_config') { # Configure::write('Cms.some_new_config', 'some_value'); # } Configure::write('Routing.prefixes', array('admin')); // todo: clean up these constants and use Configure::write instead define('WEB_EXPRESS_VERSION', '5.0'); define('FCMS_UPLOADS_FILES', WWW_ROOT.'uploads'.DS.'files'.DS); define('FCMS_UPLOADS_IMAGES', WWW_ROOT.'uploads'.DS.'images'.DS); define('FCMS_CSS_VERSION', '?5'); Configure::write('Cms.private_uploads_path', APP . 'private_uploads' . DS); Configure::write('Cms.content_group_uploads_path', WWW_ROOT . 'uploads' . DS . 'content_group_files' . DS); // default image sizes Configure::write('Cms.image_large_w', 1000); Configure::write('Cms.image_large_h', 1000); Configure::write('Cms.image_small_w', 300); Configure::write('Cms.image_small_h', 300); # site specific settings to be included on core.php # start app specific configs Configure::write('Cms.Store.require_ssl', true); Configure::write('Cms.Store.test_mode', false); # authorizenet (default) or paypal Configure::write('Cms.Store.payment_processor', 'authorizenet'); #Configure::write('Cms.Store.payment_processor', 'paypal'); #Configure::write('Cms.Store.payment_processor', 'stripe'); #Configure::write('Cms.Store.payment_processor', 'dummy'); // live Fat Cats auth.net credentials //Configure::write('Cms.Store.authorizenet_loginid', '9Yy6pLTeX8zz'); //Configure::write('Cms.Store.authorizenet_trankey', '5N6EExD2z5az246Z'); // authorizenet test account # 1 (new) //Configure::write('Cms.Store.authorizenet_loginid', '52e7Cn7Lny'); //Configure::write('Cms.Store.authorizenet_trankey', '5v952as65YWp6FT4'); // authorizenet test account # 2 (old) //Configure::write('Cms.Store.authorizenet_loginid', '5DD42Vfr2'); //Configure::write('Cms.Store.authorizenet_trankey', '2Kfg5GC3dDP2p45e'); # paypal settings Configure::write('Cms.Store.paypal_username', 'xtimes_pro_api1.gmail.com'); Configure::write('Cms.Store.paypal_password', 'LDSY7323RHWZATNN'); Configure::write('Cms.Store.paypal_signature', 'APB2lJ16uWmSX3QIk5xum-mLWTnBAHHDlLnkS7uDAktlARE-a9HD5HuG'); # stripe settings if (Configure::read('Cms.Store.test_mode')) { Configure::write('Stripe.mode', 'Test'); } else { Configure::write('Stripe.mode', 'Live'); } Configure::write('Stripe.TestSecret', 'yourStripeTestingAPIKeyHere'); Configure::write('Stripe.LiveSecret', 'yourStripeLiveAPIKeyHere'); Configure::write('Stripe.currency', 'usd'); Configure::write('Google.client_id', '503713898598-d6u7n8m9u3b8l16ehpdgul2iknpih5e2.apps.googleusercontent.com'); Configure::write('Google.client_secret', 'CG4185mEYvBHQt2OtK8tDjPa'); Configure::write('Google.developer_key', 'AIzaSyA_RvsabtvazymjORmM6QvRY-Y2rD6G17o'); # this recaptcha key will work on any domain Configure::write('Cms.Recaptcha.public_key', '6LdLNggAAAAAAASv954GRARnV-_CaykQSSKLLQYa'); Configure::write('Cms.Recaptcha.private_key', '6LdLNggAAAAAAGp2Y-C8Uo8fGS1EgFYg26DzKDaz'); # default embedded album num thumbs Configure::write('Cms.Albums.embedded_num_thumbs', 5); # unsubscribe link text Configure::write('Cms.Newsletters.unsubscribe_text', 'To unsubscribe from this mailing list, click this link:'); // email config // this will be replaced by the from_email setting Configure::write('Cms.from_email', 'noreply@fatcatsfun.com'); // this will be replaced by the from_name setting Configure::write('Cms.from_name', 'EconoWeb Express 5.0'); Configure::write('Cms.sender_email', 'sender@fatcatsfun.com'); Configure::write('Cms.sender_name', 'EconoWeb Express 5.0 Mail Sender'); Configure::write('Cms.vimeo_consumer_key', '23015af67e0065c3ed56558b627f3a16abc3f3bd'); Configure::write('Cms.vimeo_consumer_secret', 'fe5ccdb85374e10b3a24e8702b01d60d1338017c'); Configure::write('Cms.vimeo_access_token', 'e700331f337adbe80dc202bf196f8e06'); Configure::write('Cms.vimeo_access_token_secret', 'f99cf2a2496ab014a257a5924b286866cea80e29'); Configure::write('Cms.usps_tracking_url', 'http://production.shippingapis.com/ShippingAPITest.dll?API=TrackV2&XML='); Configure::write('Cms.usps_rate_url', 'http://production.shippingapis.com/ShippingAPI.dll?API=RateV4&XML='); Configure::write('Cms.usps_user_id', '535FIFTY5911'); Configure::write('Cms.ups_tracking_url', 'https://www.ups.com/ups.app/xml/Track'); Configure::write('Cms.ups_rate_url', 'https://wwwcie.ups.com/ups.app/xml/Rate'); Configure::write('Cms.ups_user_id', 'fiftystudio'); Configure::write('Cms.ups_password', 'Superman1'); Configure::write('Cms.ups_access_key', '7CB2F8D91C3FB74A'); Configure::write('Cms.fedex_url', 'https://wsbeta.fedex.com:443/web-services'); Configure::write('Cms.fedex_key', 'FBN3NjlyKlQCAczE'); Configure::write('Cms.fedex_password', 'RDbjIqIUzCwjKbW5KtsH0gfCb'); Configure::write('Cms.fedex_account_number', '510087100'); Configure::write('Cms.fedex_meter_number', '118578721'); // used as prefix for discussion identifiers - this should be unique per site Configure::write('Cms.disqus_prefix', 'test'); // from antoniosibal@gmail.com dropbox account Configure::write('Cms.dropbox_app_key', 'dxeg3zeeyal88bm'); Configure::write('Cms.smtp_host', 'smtp.mandrillapp.com'); Configure::write('Cms.smtp_port', '587'); // load environment specifc config and overrides.. if (is_file(APP.'Config/my_core.php')) { require_once(APP.'Config/my_core.php'); } // load classes.. App::uses('Sanitize', 'Utility'); App::uses('CakeEmail', 'Network/Email'); App::uses('Validation', 'Utility'); require_once(APP.'Vendor/util.php'); require_once APP.'Vendor/CmsLog.php'; 'pages_edit', 'admin_upload_image'=> 'media_edit', ); function beforeFilter() { AppController::beforeFilter(); $this->loadModel('Row'); $this->loadModel('PagesRow'); $this->loadModel('Column'); $this->loadModel('Content'); } /*public function test() { } */ public function citygrocheck () { $this->autoRender = false; $this->layout = 'test_email'; //$location = $this->passedArgs['location']; //$email = $this->passedArgs['email']; $location = $this->getParam('named.location'); $email = $this->getParam('named.email'); //configure::write('debug',2); $token = ''; if ($location == 'rexburg') { $token = 'v9uBTN8snUi8BDNaTBoweGG7e39HlAs6vQzSE8Icu3nXRAsnCaBXc9uLQZnNQUaMRAQ2O8KPmW60jbb3zH2DjwwHrzDeFqljwsMX'; } else { $token = '8EXFNGNDPr5iqyV8bngas1wTnKOOcEMLWOqaOUeXaGLb98yEfkPeMRRTN0JtjGLbR91gwNiIU7znuYCZ9am4xifRMXG2UVI3QF9N'; } $api_request_url = 'https://api.citygro.com/v1/contacts'; $api_request_parameters = array( 'token' => $token, 'primary_key' => 'email', 'email' => $email ); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $api_request_url .= '?' . http_build_query($api_request_parameters); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); curl_setopt($ch, CURLOPT_URL, $api_request_url); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $api_response = curl_exec($ch); $api_response_info = curl_getinfo($ch); curl_close($ch); $api_response_header = trim(substr($api_response, 0, $api_response_info['header_size'])); $api_response_body = substr($api_response, $api_response_info['header_size']); $result = json_decode($api_response_body, true); // Response HTTP Status Code //echo 'Response HTTP Status Code:'.$api_response_info['http_code']; // Response Header //echo 'Response Header:'.$api_response_header; // Response Body //echo 'Response Body: '.$api_response_body; // create new, no record if ( $api_response_info['http_code'] == 200 && $result['total'] == 0 ) { $status = $this->_citygroadd($token, $email); if ($status == true) { echo json_encode(array('result'=>2)); // email added } else { echo json_encode(array('result'=>0)); // error } } else { echo json_encode(array('result'=>1)); //email already registered. } } //add new one public function _citygroadd ($token, $email) { //configure::write('debug',2); $api_request_url = 'https://api.citygro.com/v1/contacts?token='.$token; $api_request_parameters = array( 'email_on' => 'on', 'email' => $email, 'freepopcorn'=> true ); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($api_request_parameters)); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); curl_setopt($ch, CURLOPT_URL, $api_request_url); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $api_response = curl_exec($ch); $api_response_info = curl_getinfo($ch); curl_close($ch); $api_response_header = trim(substr($api_response, 0, $api_response_info['header_size'])); $api_response_body = substr($api_response, $api_response_info['header_size']); $result = json_decode($api_response_body, true); //print_r($result); // create new, no record if ( $api_response_info['http_code'] == 200 && $result['_id'] != "" && $result['_id'] != 0) { return true; } else { return false; } } public function admin_index() { $this->Page->bindModel(array('belongsTo' => array('Location'))); $this->Paginator->settings = array_merge($this->paginate, $this->paginate_contain_tag, array( 'fields'=> array('Page.id', 'Page.name', 'Page.title', 'Page.slug', 'Page.published', 'Page.modified_since_published', 'Page.created', 'Page.location_id', 'Location.name'), 'conditions'=> array(), 'contain'=> array( 'Location', 'Tag'=> array( 'fields'=> array('Tag.id', 'Tag.name') ) ), 'order'=> 'Page.created desc', )); $location_filter = $this->getParam('named.location'); if ($location_filter) { $this->Paginator->settings['conditions']['Page.location_id'] = $location_filter; } $this->set('location_filter', $location_filter); $items = $this->Paginator->paginate('Page'); $this->set('items', $items); $modified_count = $this->Page->find('count', array( 'conditions'=> array( 'modified_since_published'=>true, ) )); $this->set('modified_count', $modified_count); $this->loadModel('PagesTag'); $tags = $this->PagesTag->find('all', array( 'fields'=> array('distinct(PagesTag.tag_id)', 'Tag.name'), 'contain'=> array('Tag'), 'order'=> 'Tag.name asc', )); $this->set('tags', $tags); $this->_enableAddToMenu(); $this->loadModel('Location'); $locations = $this->Location->find('list', array('fields' => array('Location.id', 'Location.name'))); $this->set('locations', $locations); } public function admin_duplicate($id) { $this->loadModel('Row'); $this->loadModel('Column'); $this->loadModel('Content'); $page_name = $this->getParam('url.page_name'); $item = $this->Page->find('first', array( 'conditions'=> array( 'Page.id'=> $id, ), 'contain'=> array( 'Column'=> array( 'Content' ), 'Row'=> array( 'Column'=> array( 'Content', ), ) ), )); if ( ! $item) { $this->error(); } //debug($item);die; $slug = Util::slug($page_name); $existing = $this->Page->find('first', array( 'conditions'=> array( 'slug'=> $slug, ) )); if ($existing) { $slug = $slug . '-' . uniqid(); } $data = $item['Page']; unset($data['id']); $data['name'] = $page_name; $data['title'] = $page_name; $data['slug'] = $slug; $data['published'] = 0; $data['published_content'] = ''; $data['social_image'] = ''; //debug($data); $this->Page->create(); $this->Page->save($data); $page_id = $this->Page->id; foreach ($item['Row'] as $row) { $data = array( 'style'=> $row['style'], ); //debug($data); $this->Row->create(); $this->Row->save($data); $row_id = $this->Row->id; $data = array( 'page_id'=> $page_id, 'row_id'=> $row_id, 'order'=> $row['PagesRow']['order'], ); //debug($data); $this->Row->PagesRow->create(); $this->Row->PagesRow->save($data); foreach ($row['Column'] as $column) { $data = $column; unset($data['id']); unset($data['Content']); $data['row_id'] = $row_id; //debug($data); $this->Column->create(); $this->Column->save($data); $column_id = $this->Column->id; foreach ($column['Content'] as $content) { $data = $content; unset($data['id']); unset($data['ColumnsContent']); //debug($data); $this->Content->create(); $this->Content->save($data); $content_id = $this->Content->id; $data = array( 'content_id'=> $content_id, 'column_id'=> $column_id, 'order'=> $content['ColumnsContent']['order'], ); //debug($data); $this->Content->ColumnsContent->create(); $this->Content->ColumnsContent->save($data); } //foreach content } //foreach column } //foreach row // sidebars foreach ($item['Column'] as $column) { $data = $column; unset($data['id']); unset($data['Content']); $data['page_id'] = $page_id; //debug($data); $this->Column->create(); $this->Column->save($data); $column_id = $this->Column->id; foreach ($column['Content'] as $content) { $data = $content; unset($data['id']); unset($data['ColumnsContent']); //debug($data); $this->Content->create(); $this->Content->save($data); $content_id = $this->Content->id; $data = array( 'content_id'=> $content_id, 'column_id'=> $column_id, 'order'=> $content['ColumnsContent']['order'], ); //debug($data); $this->Content->ColumnsContent->create(); $this->Content->ColumnsContent->save($data); } //foreach content } //foreach column // end sidebars $this->Session->setFlash('Page duplicated'); $this->goBack(); } public function admin_filter() { $location_filter = $this->getParam('named.location'); if (!$location_filter) { return $this->redirect('/admin/pages'); } else { return $this->redirect('/admin/pages/index/location:' . $location_filter); } } public function admin_edit($id=false) { $doc = $this->Page->getPageDoc($id); if ( ! $doc) { $this->redirect(array('action'=>'index')); } $this->_setPageLayout($doc['Page']['custom_layout']); $this->set('doc', $doc); $this->set('show_sidebar', false); $this->set('page_title', $doc['Page']['title']); $this->loadModel('Location'); $locations = $this->Location->find('list', array('fields' => array('Location.id', 'Location.name'), 'order' => 'Location.name ASC')); $this->set('locations', $locations); $this->set('location_id', null); } function _editPage($page_id) { $this->loadModel('Page'); $this->Page->modifiedSincePublished($page_id); $last_edit_id = $this->Session->read('last_edit_id'); $last_edit_timestamp = intval($this->Session->read('last_edit_timestamp')); $new_edit_timestamp = time(); // skip if same page is edited within 1hr if ($last_edit_id && $last_edit_timestamp) { if ($last_edit_id == $page_id && (($new_edit_timestamp-$last_edit_timestamp) < HOUR)) { return false; } } $page = $this->Page->findById($page_id); if ( ! $page) { return false; } $this->Session->write('last_edit_id', $page_id); $this->Session->write('last_edit_timestamp', $new_edit_timestamp); CmsLog::getInstance()->write("Page.edit.{$page_id}", $page['Page']['title']); return true; } function admin_edit_name() { $this->layout = 'modal'; if ($this->request->data) { $id = $this->getParam('url.page_id'); $name = $this->request->data['Page']['name']; $save = $this->Page->save(array( 'id'=> $id, 'name'=> $name, 'title'=> $name, 'slug'=> $name, )); if ( ! $save) { // if slug is not unique, just save name and title $save = $this->Page->save(array( 'id'=> $id, 'name'=> $name, 'title'=> $name, 'slug'=> null, ), array( 'validate'=>false, )); } return $this->_renderModalSave(); } } public function admin_add_row() { $page_id = $this->getParam('url.page_id'); $page = $this->Page->find('first', array( 'conditions'=> array( 'Page.id'=> $page_id, ))); $data = array(); $this->Row->create(); $this->Row->save($data); $row_id = $this->Row->id; $this->set('new_row_id', $row_id); $order = 0; // get max PagesRow order $max = $this->Page->PagesRow->find('first', array( 'conditions'=> array( 'page_id'=> $page_id, ), 'order'=> 'order desc', )); if ($max) { $order = intval($max['PagesRow']['order']) + 1; } $this->Page->PagesRow->create(); $save = $this->Page->PagesRow->save(array( 'page_id'=> $page_id, 'row_id'=> $row_id, 'order'=> $order, )); $pages_row_id = $this->Page->PagesRow->id; $column_id = $this->_addColumn($row_id); $this->_editPage($page_id); $this->page_id = $page_id; $this->_renderPageEditor(); } public function admin_image() { $this->layout = 'modal'; $this->loadModel('Image'); $column_id = $this->getParam('url.column_id'); $page_id = $this->getParam('url.page_id'); $content_id = $this->getParam('url.content_id'); $selected = explode(',', $this->getData('Extra.selected')); if ($content_id) { $content = $this->Content->find('first', array( 'conditions'=> array( 'Content.id'=> $content_id, ))); if ( ! $content) { $this->error(); } $this->set('content', $content); } if ($this->request->data) { $content_type = ''; $linked_content_id = ''; if (count($selected) == 1) { $content_type = 'image'; $linked_content_id = $selected[0]; } else { $content_type = 'gallery'; // fix captions $gallery = array(); foreach ($selected as $image_id) { $gallery[$image_id] = array( 'caption'=> Set::classicExtract($this->request->data, "Extra.gallery.{$image_id}.caption"), 'class'=> Set::classicExtract($this->request->data, "Extra.gallery.{$image_id}.class"), 'url'=> Set::classicExtract($this->request->data, "Extra.gallery.{$image_id}.url"), ); } $this->request->data['Extra']['gallery'] = $gallery; } if ( ! $content_id) { $content_id = $this->_addContentType(array( 'page_id'=> $page_id, 'column_id'=> $column_id, 'content_type'=> $content_type, 'linked_content_id'=> $linked_content_id, )); if ( ! $content_id) { $this->error(); } } if ($content_id) { $this->Content->save(array( 'id'=> $content_id, 'type'=> $content_type, 'linked_content_id'=> $linked_content_id, 'data'=> serialize($this->request->data['Extra']), )); } $this->_editPage($page_id); $this->_renderModalSave(); return; } if ( ! $this->request->data) { $this->request->data = array(); $this->request->data['Extra'] = @unserialize($content['Content']['data']); } // from AppController $this->_setImageItems(); } public function admin_media_dialog_images() { $this->layout = 'modal'; // from AppController $this->_setImageItems(); } function _getYoutubeIdFromUrl($url) { $matches = array(); $is_url = preg_match('/[\?\&]v\=([^\&]+)/', $url, $matches); if ($is_url && isset($matches[1])) { return $matches[1]; } else { return false; } } function _getDataFromYoutubeEntry($i) { $data = array( 'id'=> $i['media$group']['yt$videoid']['$t'], 'title'=> $i['title']['$t'], 'url'=> $i['link'][0]['href'], 'thumbnail'=> $i['media$group']['media$thumbnail'][1]['url'], ); return $data; } function _getVimeoIdFromUrl($url) { $matches = array(); $is_url = preg_match('/\.com\/([0-9]+)/', $url, $matches); if ($is_url && isset($matches[1])) { return $matches[1]; } else { return false; } } function admin_media_dialog_files() { $this->layout = 'modal'; $this->loadModel('Upload'); $this->Paginator->settings = array( 'contain'=> array('Tag'), 'order'=> 'Upload.title asc ', 'limit'=> $this->paginate_limit, ); $items = $this->Paginator->paginate('Upload'); $this->set('items', $items); $this->loadModel('UploadsTag'); $tags = $this->UploadsTag->find('all', array( 'fields'=> array('distinct(UploadsTag.tag_id)', 'Tag.name'), 'contain'=> array('Tag'), 'order'=> 'Tag.name asc', )); $this->set('tags', $tags); } public function admin_upload_image() { require(APP.'Vendor/UploadHandler.php'); $options = array( 'upload_dir'=> APP. 'webroot/uploads/images/temp/', 'upload_url'=> '', 'image_versions'=> array(), ); $upload_handler = new UploadHandler($options); exit; } public function admin_row_options() { $this->layout = 'modal'; $page_id = $this->getParam('url.page_id'); $row_id = $this->getParam('url.row_id'); $row = $this->Row->find('first', array( 'conditions'=> array( 'id'=> $row_id, ))); $this->set('row', $row); if ($this->request->data) { $extra = Page::fixStyles($this->request->data['Extra']); $this->Row->save(array( 'id'=> $row_id, 'style'=> serialize($extra), )); $this->_editPage($page_id); $this->_renderModalSave(); } if ( ! $this->request->data) { $this->request->data = array(); $style = @unserialize($row['Row']['style']); if ($style) { $this->request->data['Extra'] = $style; } } } public function admin_column_options() { $this->layout = 'modal'; $page_id = $this->getParam('url.page_id'); $column_id = $this->getParam('url.column_id'); $column = $this->Column->find('first', array( 'conditions'=> array( 'id'=> $column_id, ))); $this->set('column', $column); if ($this->request->data) { $extra = Page::fixStyles($this->request->data['Extra']); $this->Column->save(array( 'id'=> $column_id, 'style'=> serialize($extra), )); $this->_editPage($page_id); $this->page_id = $page_id; $this->_renderModalSave(); } if ( ! $this->request->data) { $this->request->data = array(); $style = @unserialize($column['Column']['style']); if ($style) { $this->request->data['Extra'] = $style; } } } public function admin_content_options() { $this->layout = 'modal'; $page_id = $this->getParam('url.page_id'); $content_id = $this->getParam('url.content_id'); if ($this->request->data) { $extra = Page::fixStyles($this->request->data['Extra']); $this->Content->save(array( 'id'=> $content_id, 'style'=> serialize($extra), )); $this->_editPage($page_id); $this->page_id = $page_id; $this->_renderModalSave(); } if ( ! $this->request->data) { $content = $this->Content->find('first', array( 'conditions'=> array( 'id'=> $content_id, ))); $style = @unserialize($content['Content']['style']); if ($style) { $this->request->data = array( 'Extra'=> $style ); } } } function admin_update_contents() { $contents = $this->getData('contents'); $page_id = $this->getData('page_id'); if (is_array($contents)) { foreach($contents as $content_id => $content_data) { $content = $this->Content->findById($content_id); if ($content) { $this->Content->save(array( 'id'=> $content_id, 'content'=> $content_data, )); } } } $this->_editPage($page_id); $this->page_id = $page_id; $this->_renderPageEditor(); } public function admin_delete_content() { $content_id = $this->getParam('url.content_id'); $page_id = $this->getParam('url.page_id'); $content = $this->Content->find('first', array( 'conditions'=> array( 'id'=> $content_id, ), )); if ( ! $content) { $this->error(); } $this->Content->delete($content_id); $this->_editPage($page_id); $this->page_id = $page_id; $this->_renderPageEditor(); } public function admin_delete_row() { $page_id = $this->getParam('url.page_id'); $row_id = $this->getParam('url.row_id'); $item = $this->Row->find('first', array( 'conditions'=> array( 'id'=> $row_id, ), )); if ( ! $item) { $this->error(); } $this->Row->delete($row_id); $this->_editPage($page_id); $this->page_id = $page_id; $this->_renderPageEditor(); } function admin_add_column() { $row_id = $this->getParam('url.row_id'); $page_id = $this->getParam('url.page_id'); $column_id = $this->_addColumn($row_id); $this->_editPage($page_id); $this->page_id = $page_id; $this->_renderPageEditor(); } function _addColumn($row_id) { $row = $this->Page->Row->find('first', array( 'conditions'=> array( 'Row.id'=> $row_id, ), 'contain'=> array('Column'), )); if ( ! $row) { return false; } $new_size = 12; $new_order = 0; if (count($row['Column'])) { // get last column $last_column = $row['Column'][count($row['Column'])-1]; if ($last_column['size'] <= 1) { return false; } $new_size = floor($last_column['size']/2); $last_column_new_size = ceil($last_column['size']/2); $new_order = $last_column['order']+1; $this->Page->Row->Column->save(array( 'id'=> $last_column['id'], 'size'=> $last_column_new_size, )); } $this->Page->Row->Column->create(); $this->Page->Row->Column->save(array( 'row_id'=> $row_id, 'size'=> $new_size, 'order'=> $new_order, )); $new_column_id = $this->Page->Row->Column->id; return $new_column_id; } function admin_delete_column() { $column_id = $this->getParam('url.column_id'); $page_id = $this->getParam('url.page_id'); $this->_deleteColumn($column_id); $this->_editPage($page_id); $this->page_id = $page_id; $this->_renderPageEditor(); } function _deleteColumn($column_id) { $this->loadModel('Column'); $column = $this->Column->find('first', array( 'conditions'=> array( 'Column.id'=> $column_id, ), )); if ( ! $column) { return false; } $all_columns = $this->Column->find('all', array( 'conditions'=> array( 'Column.row_id'=> $column['Column']['row_id'], ), 'order'=> 'Column.order asc' )); if (count($all_columns) > 1) { if ($all_columns[0]['Column']['id'] == $column_id) { // first, add to next $this->Column->save(array( 'id'=> $all_columns[1]['Column']['id'], 'size'=> $all_columns[1]['Column']['size'] + $column['Column']['size'], )); } else { foreach($all_columns as $k=> $v) { if ($v['Column']['id'] == $column_id) { $this->Column->save(array( 'id'=> $all_columns[$k-1]['Column']['id'], 'size'=> $all_columns[$k-1]['Column']['size'] + $column['Column']['size'], )); } } } } $this->Column->delete($column_id); return true; } public function admin_save_column_sizes() { $column_data = $this->getParam('url.column_data'); $page_id = $this->getParam('url.page_id'); foreach($column_data as $column_id=> $row) { $column = $this->Column->findById($column_id); if ($column) { $this->Column->save(array( 'id'=> $column_id, 'size'=> $row['column_size'], 'order'=> $row['column_order'], )); } } $this->_editPage($page_id); die('ok'); } public function admin_save_row_sorting() { $pages_rows = $this->getParam('url.pages_rows'); $page_id = $this->getParam('url.page_id'); foreach($pages_rows as $order=> $id) { $ps = $this->Row->PagesRow->findById($id); if ($ps) { $this->Row->PagesRow->save(array( 'id'=> $id, 'order'=> $order, )); } } $this->_editPage($page_id); die('ok'); } public function admin_save_content_sorting() { $this->loadModel('Content'); $columns_contents = $this->getParam('url.columns_contents'); $page_id = $this->getParam('url.page_id'); foreach($columns_contents as $order=> $id) { $bc = $this->Content->ColumnsContent->findById($id); if ($bc) { $this->Content->ColumnsContent->save(array( 'id'=> $id, 'order'=> $order, )); } } $this->_editPage($page_id); die('ok'); } function admin_get_page_editor($page_id) { $this->page_id = $page_id; $this->_renderPageEditor(); } function _renderPageEditor() { $doc = $this->Page->getPageDoc($this->page_id); $this->set('doc', $doc); $this->_setMenus(); $this->layout = 'ajax'; $this->render("../page_editor"); } public function admin_add_video_content() { $page_id = $this->getParam('url.page_id'); $column_id = $this->getParam('url.column_id'); $source = $this->getParam('url.source'); $code = $this->getParam('url.code'); $content = array( 'source'=> $source, 'code'=> $code, ); $content_id = $this->_addContentType(array( 'page_id'=> $page_id, 'column_id'=> $column_id, 'content_type'=> 'video', 'content'=> $content, )); $this->_editPage($page_id); $this->page_id = $page_id; $this->_renderPageEditor(); } public function admin_add_file_content() { $page_id = $this->getParam('url.page_id'); $column_id = $this->getParam('url.column_id'); $upload_id = $this->getParam('url.upload_id'); $content_id = $this->_addContentType(array( 'page_id'=> $page_id, 'column_id'=> $column_id, 'content_type'=> 'file', 'linked_content_id'=> $upload_id, )); $this->_editPage($page_id); $this->page_id = $page_id; $this->_renderPageEditor(); } public function admin_add_content() { $page_id = $this->getParam('url.page_id'); $column_id = $this->getParam('url.column_id'); $source = $this->getParam('url.source'); $code = $this->getParam('url.code'); $content = $this->getParam('url.content'); $content_type = $this->getData('Extra.content_type'); $linked_content_id = ''; // manual override for now.. $content_type = 'text'; // all content types except 'existing' and 'page_content' should be here $allowed_content_types = array('text', 'image', 'gallery', 'video', 'input', 'file'); if ($content_type == 'video') { $content = array( 'source'=> $source, 'code'=> $code, ); } if (in_array($content_type, $allowed_content_types)) { $content_id = $this->_addContentType(array( 'page_id'=> $page_id, 'column_id'=> $column_id, 'content_type'=> $content_type, 'linked_content_id'=> $linked_content_id, 'content'=> $content, )); $this->set('new_content_id', $content_id); } $this->_editPage($page_id); $this->page_id = $page_id; $this->_renderPageEditor(); } // params: // page_id, column_id, above_columns_content_id, // content_type, linked_content_id, widget_type public function _addContentType($params) { $content = ''; if (isset($params['content'])) { if ($params['content_type'] == 'text') { $content = $params['content']; } else { if ($params['content']) { $content = serialize($params['content']); } } } $data = array( 'name'=> $params['content_type'], 'content'=> $content, 'type'=> $params['content_type'], 'linked_content_id'=> isset($params['linked_content_id']) ? $params['linked_content_id'] : '', ); $this->Content->save($data); $content_id = $this->Content->id; $this->_addContentToColumn($params['page_id'], $params['column_id'], $content_id); return $content_id; } public function _addContentToColumn($page_id, $column_id, $content_id) { $content = $this->Content->findById($content_id); if ( ! $content) { $this->error(); } $column = $this->Column->findById($column_id); if ( ! $column) { $this->error(); } $page = $this->Page->findById($page_id); if ( ! $page) { $this->error(); } $order = 0; $max = $this->Content->ColumnsContent->find('first', array( 'conditions'=> array( 'column_id'=> $column_id, ), 'order'=> 'order desc', )); if ($max) { $order = intval($max['ColumnsContent']['order']) + 1; } $data = array( 'column_id'=> $column_id, 'content_id'=> $content_id, 'order'=> $order, ); $this->Content->ColumnsContent->save($data); $columns_content_id = $this->Content->ColumnsContent->id; return true; } public function admin_publish_all() { $pages = $this->Page->find('all', array( 'conditions'=> array( 'or'=> array( 'published'=> false, 'modified_since_published'=> true, ) ) )); foreach($pages as $page) { $this->Page->publish($page['Page']['id']); } $this->Session->setFlash("Published all changes."); $this->redirect(array('action'=>'index')); } public function admin_publish($page_id=false) { if ($page_id) { $this->Page->publish($page_id); } if ($this->request->data) { $page_ids = Set::classicExtract($this->request->data, 'Extra.publish'); if (is_array($page_ids)) { foreach($page_ids as $id=> $v) { if ($v === '1') { $this->Page->publish($id); // first item is where the page will redirect if ( ! $page_id) { $page_id = $id; } } } } } $this->Session->setFlash("Published changes"); $this->redirect(array('action'=>'edit', $page_id)); } public function admin_add() { $this->Page->create(); $this->Page->save(array( 'name'=> '', 'published'=> false, ), array( 'validate'=> false, )); $page_id = $this->Page->id; CmsLog::getInstance()->write("Page.add.{$page_id}"); $this->redirect(array('action'=>'edit', $page_id)); } public function admin_delete($id) { $item = $this->Page->findById($id); if ( ! $item) { $this->error(); } $this->Page->delete($id); CmsLog::getInstance()->write("Page.delete.{$id}", $item['Page']['title']); $this->Session->setFlash("Page deleted."); $this->redirect(array('action'=>'index')); } public function admin_settings($id) { $this->layout = 'modal'; $return = $this->getParam('named.return'); $item = $this->Page->find('first', array( 'conditions'=> array( 'Page.id'=> $id, ), )); if ( ! $item) { $this->error(); } $item['Page']['form_settings'] = Page::getFormSettings($item['Page']['form_settings']); $this->set('item', $item); if ($this->request->data) { if ( ! $this->request->data['Page']['title']) { $this->request->data['Page']['title'] = $this->request->data['Page']['name']; } if ($this->request->data['Page']['enable_form']) { // remove prototype field unset($this->request->data['form_settings']['steps'][0]); $this->request->data['Page']['form_settings'] = serialize($this->request->data['form_settings']); } else { $this->request->data['Page']['form_settings'] = ''; } $extra = array(); foreach (Page::$extraFields as $field=> $default) { $v = Set::classicExtract($this->request->data, "Extra.{$field}"); if (is_null($v)) { $v = $default; } $extra[$field] = $v; } $this->request->data['Page']['extra'] = serialize($extra); $save = $this->Page->save($this->request->data); if ($save) { $this->Page->setTags($this->request->data['Extra']['tags']); if ($item['Page']['slug'] != $this->request->data['Page']['slug']) { $this->loadModel('Link'); $this->Link->updateUrl($item['Page']['id'], 'Page'); } $image_options = array( 'src'=> $this->request->data['Extra']['social_image'], 'id'=> $id, 'field'=> 'page_id', 'type'=> 'social', ); if (Set::classicExtract($this->request->data, 'Extra.delete_social_image')) { $this->Page->Image->deleteAttachedImage($image_options); $this->Page->save(array( 'id'=> $id, 'social_image'=> '', )); } $image = $this->Page->Image->attachImage($image_options); if ($image) { $this->Page->save(array( 'id'=> $id, 'social_image'=> $image['Image']['src'], )); } $this->_editPage($id); CmsLog::getInstance()->write("Page.settings.{$id}", $item['Page']['title']); $this->Session->setFlash('Page settings updated.'); return $this->_renderModalSave(); /* if ($return == 'page') { $this->redirect(array('action'=>'edit', $id)); } else { $this->redirect(array('action'=>'index')); } */ } } if ( ! $this->request->data) { $this->request->data = $item; $this->request->data['Extra'] = @unserialize($item['Page']['extra']); } $pages = $this->Page->find('list', array( 'fields'=> array('id', 'title'), 'conditions'=> array( 'id <>'=> $id, ), 'order'=>'Page.title asc', )); $this->set('pages', $pages); // layouts $custom_layouts = Util::arrayToOptions(Page::getCustomLayouts()); $this->set('custom_layouts', $custom_layouts); // locations $this->loadModel('Location'); $locations = $this->Location->find('list', array('fields' => array('Location.id', 'Location.name'), 'order' => 'Location.name ASC')); $this->set('locations', $locations); } public function admin_input() { $this->layout = 'modal'; $this->loadModel('Field'); $content_id = $this->getParam('url.content_id'); $page_id = $this->getParam('url.page_id'); $column_id = $this->getParam('url.column_id'); if ($content_id) { $content = $this->Content->find('first', array( 'conditions'=> array( 'id'=> $content_id, ))); } $db_fields = $this->Field->find('all', array( 'order'=> 'native desc, name asc', )); $fields = array(); foreach ($db_fields as $f) { $name = $f['Field']['name']; if ($f['Field']['native']) { $name = $name . " (native)"; } $fields[$f['Field']['id']] = $name; } $this->set('fields', $fields); if ($this->request->data) { if ($this->request->data['Extra']['field_id'] == 'new' && $this->request->data['Extra']['type'] != 'submit') { $this->Field->create(); $this->Field->save(array( 'name'=> $this->request->data['Extra']['label'], 'native'=> 0, )); $field_id = $this->Field->id; $this->request->data['Extra']['field_id'] = $field_id; } if ( ! $content_id) { $content_id = $this->_addContentType(array( 'page_id'=> $page_id, 'column_id'=> $column_id, 'content_type'=> 'input', 'linked_content_id'=> '', )); if ( ! $content_id) { $this->error(); } } if ($content_id) { $this->Content->save(array( 'id'=> $content_id, 'content'=> serialize($this->request->data['Extra']), )); } $this->_editPage($page_id); $this->_renderModalSave(); return; } if ( ! $this->request->data) { if ($content_id) { $this->request->data = array(); $this->request->data['Extra'] = @unserialize($content['Content']['content']); } } } public function admin_file() { $this->layout = 'modal'; $this->loadModel('Upload'); $content_id = $this->getParam('url.content_id'); $page_id = $this->getParam('url.page_id'); $column_id = $this->getParam('url.column_id'); $this->Paginator->settings = array( 'contain'=> array('Tag'), 'order'=> 'Upload.title asc ', 'limit'=> $this->paginate_limit, ); $items = $this->Paginator->paginate('Upload'); $this->set('items', $items); $this->loadModel('UploadsTag'); $tags = $this->UploadsTag->find('all', array( 'fields'=> array('distinct(UploadsTag.tag_id)', 'Tag.name'), 'contain'=> array('Tag'), 'order'=> 'Tag.name asc', )); $this->set('tags', $tags); } public function admin_custom() { $this->layout = 'modal'; $this->loadModel('Field'); $content_id = $this->getParam('url.content_id'); $page_id = $this->getParam('url.page_id'); $column_id = $this->getParam('url.column_id'); if ($content_id) { $content = $this->Content->find('first', array( 'conditions'=> array( 'id'=> $content_id, ))); } if ($this->request->data) { if ( ! $content_id) { $content_id = $this->_addContentType(array( 'page_id'=> $page_id, 'column_id'=> $column_id, 'content_type'=> 'custom', 'linked_content_id'=> '', )); if ( ! $content_id) { $this->error(); } } if ($content_id) { $this->Content->save(array( 'id'=> $content_id, 'content'=> serialize($this->request->data['Extra']), )); } $this->_editPage($page_id); $this->_renderModalSave(); return; } if ( ! $this->request->data) { if ($content_id) { $this->request->data = array(); $this->request->data['Extra'] = @unserialize($content['Content']['content']); } } } /* frontend */ public function display() { PageCache::getInstance()->enable(); $this->set('frontend_mode', true); $no_assets = $this->getParam('url.no_assets'); $this->set('no_assets', $no_assets); $slug = $this->request->params['slug']; $item = $this->Page->getPublishedPage($slug, $this->location_id); if ( ! $item) { $this->error('This page is not yet published'); } $this->_setPageLayout($item['Page']['custom_layout']); $this->set('doc', $item); $this->set('page_title', $item['Page']['title']); $this->set('enable_social', $item['Page']['enable_social']); $this->set('page_keywords', $item['Page']['keywords']); $this->set('page_description', $item['Page']['description']); $this->set('page_social_image', $item['Page']['social_image']); // set form session if first form page if ($item['Page']['enable_form'] && ! $this->request->data) { $form_session = array( 'page_id'=> $item['Page']['id'], 'form_settings'=> $item['Page']['form_settings'], 'data'=> array(), ); $this->Session->write('form_session', $form_session); } if ($this->request->data) { // disable cache to show possible errors PageCache::getInstance()->disable(); $form_session = $this->Session->read('form_session'); if ( ! $form_session) { $this->error("Form session not found"); } // form validation is only in JS, dont use _validateForm() for now to prevent duplicate logic $form_session['data'][$item['Page']['id']] = $this->request->data; $this->Session->write('form_session', $form_session); $result = $this->_processForm($item['Page']['id']); return; } } function _validateForm($data, $page) { $errors = array(); $inputs = array(); foreach ($page['Row'] as $row) { foreach ($row['Column'] as $column) { foreach ($column['Content'] as $content) { if ($content['type'] == 'input') { $content['content'] = Content::getInputContentFields($content['content']); $inputs[] = $content; } } } } foreach ($inputs as $input) { $this->loadModel('Extra'); if ($input['content']['validation']) { $field_id = $input['content']['field_id']; $value = Set::classicExtract($data, "Extra.{$field_id}"); $valid = true; if ($input['content']['validation'] == 'email') { $valid = Validation::email($value); } else if ($input['content']['validation'] == 'numeric') { $valid = Validation::numeric($value); } else if ($input['content']['validation'] == 'notEmpty') { $valid = Validation::notEmpty($value); } if ( ! $valid) { $message = $input['content']['validation_message']; $errors[$field_id] = $message; $this->Extra->invalidate($field_id, $message); } } } return $errors; } function _processForm($page_id) { $form_session = $this->Session->read('form_session'); $flow = array(); $flow[] = $form_session['page_id']; foreach($form_session['form_settings']['steps'] as $step_page_id) { $flow[] = $step_page_id; } $flow[] = $form_session['form_settings']['confirmation_page_id']; $next_page_id = false; $get_next = false; foreach($flow as $flow_page_id) { if ($get_next) { $next_page_id = $flow_page_id; break; } if ($page_id == $flow_page_id) { $get_next = true; } } // save lead if next page is last (confirmation page) if ($next_page_id == $flow[count($flow)-1]) { $this->Session->write('form_session', ''); $lead_id = $this->_saveLead($form_session); } $page = $this->Page->findById($next_page_id); $this->redirect("/{$page['Page']['slug']}"); return true; } function _saveLead($form_session) { $this->loadModel('Lead'); $this->loadModel('Field'); $this->loadModel('Blacklist'); // combine data $first = true; $data = array(); foreach($form_session['data'] as $form_data) { if ($first) { $first = false; $data = $form_data; } else { foreach($form_data['Extra'] as $k=> $v) { $data['Extra'][$k] = $v; } } } $ip = $this->request->clientIp(); $spam = $this->Blacklist->checkSpam($data, $ip); $lead = array( 'page_id'=> $form_session['page_id'], 'ip'=> $ip, 'spam'=> $spam, ); $leadvalue = array(); $order = 0; foreach($data['Extra'] as $field_id=> $value) { $order++; $field = $this->Field->find('first', array( 'conditions'=> array( 'id'=> $field_id, ) )); if (is_array($value)) { $value = implode(', ', $value); } if ($field['Field']['native']) { $native_field = $field['Field']['native_field']; $lead[$native_field] = $value; } else { $leadvalue[] = array( 'field_id'=> $field_id, 'value'=> $value, ); } } $data = array( 'Lead'=> $lead, 'Leadvalue'=> $leadvalue, ); $this->Lead->create(); $this->Lead->saveAll($data); $lead_id = $this->Lead->id; $this->_emailNewLeadNotification($lead_id); $lead_name = isset($data['Lead']['name']) ? $data['Lead']['name'] : ''; CmsLog::getInstance()->write("Lead.add_frontend.{$lead_id}", $lead_name); return $lead_id; } /* function admin_email($lead_id) { $this->_emailNewLeadNotification($lead_id); die('x'); } */ function _emailNewLeadNotification($lead_id) { $this->loadModel('Lead'); $to = Util::setting('lead_email_notification'); if ( ! $to) { return false; } $lead = $this->Lead->find('first', array( 'conditions'=> array( 'Lead.id'=> $lead_id, 'Lead.spam'=> false, ), 'contain'=> array( 'Leadvalue'=> 'Field', 'Page', ), )); if ( ! $lead) { return false; } $to = Util::setting('lead_email_notification'); $form_settings = Set::classicExtract($lead, 'Page.form_settings'); if ($form_settings) { $form_settings = Page::getFormSettings($form_settings); if ($form_settings['email_notification']) { $email_notification = $form_settings['email_notification']; if ($to) { $to = $to . ', ' . $email_notification; } else { $to = $email_notification; } } } if ( ! $to) { return false; } $native_fields = array( 'name'=> 'Name', 'first_name'=> 'First Name', 'last_name'=> 'Last Name', 'email'=> 'Email', ); $email_message = ''; foreach ($native_fields as $field=> $label) { $value = $lead['Lead'][$field]; if ($value) { $email_message .= "{$label}: {$value}
"; } } foreach ($lead['Leadvalue'] as $lv) { $field = Set::classicExtract($lv, 'Field.name'); if ( ! $field) { $field = "Field {$lv['field_id']}"; } $email_message .= "{$field}: {$lv['value']}
"; } $email_to = explode(',', $to); foreach($email_to as $k=> $v) { $email_to[$k] = trim($v); } if (count($email_to)) { $this->_sendEmail(array( 'to'=> $email_to, 'subject'=> "New Lead: {$lead['Lead']['name']}", 'viewVars'=> array( 'email_message'=> $email_message, ), )); } return true; } function _checkSpam($data) { $this->loadModel('Blacklist'); $result = false; // honeypot check $name = Set::classicExtract($data, 'name'); // if name is not submitted (null), also consider as spam if (is_null($name) || $data['name'] !== "") { $result = true; } $item = $this->Blacklist->find('first', array( 'conditions'=> array( 'ip'=> $this->request->clientIp(), ) )); if ($item) { $result = true; $this->Blacklist->save(array( 'id'=> $item['Blacklist']['id'], 'count'=> intval($item['Blacklist']['count'])+1, )); } return $result; } // this is only used for testing large lists /* function admin_generate_pages() { die('x'); $sample = "Published software should be free software. To make it free software, you need to release it under a free software license. We normally use the GNU General Public License (GNU GPL), but occasionally we use other free software licenses. We use only licenses that are compatible with the GNU GPL for GNU software. Documentation for free software should be free documentation, so that people can redistribute it and improve it along with the software it describes. To make it free documentation, you need to release it under a free documentation license. We normally use the GNU Free Documentation License (GNU FDL), but occasionally we use other free documentation licenses. If you've started a new project and you're not sure what license to use, How to choose a license for your own work details our recommendations in an easy-to-follow guide. If you just want a quick list reference, we have a page that names our recommended copyleft licenses. We also have a page that discusses the BSD License Problem. Our documentation licenses are currently being revised, and we welcome your comments on the proposed texts. Please visit our license update site to read the current drafts and participate in the process."; $sample = explode(' ', $sample); $sample_length = count($sample); $min_words = 3; $max_words = 5; $items = 500; $titles = array(); foreach(range(0, $items-1) as $i) { $words = array(); $num_words = rand($min_words, $max_words); foreach(range(1, $num_words) as $word_i) { $sample_i = rand(0, $sample_length-1); $words[] = $sample[$sample_i]; } $titles[] = ucfirst(implode(' ', $words)); } //debug($titles); $now = time(); $data = array(); foreach($titles as $title) { $now = $now - 3600; $data[] = array( 'name'=> $title, 'title'=> $title, 'published'=> 1, 'created'=> date(MYSQL_DATETIME_FORMAT, $now), ); } $this->Page->saveAll($data); debug($data); die('x'); } */ } array( 'links', 'pages', 'snippets', 'images', 'videos', 'uploads', 'forms', 'newsletters', 'blogs', 'posts', 'events', ), 'store'=> array( 'store', 'categories', 'products', 'attributes', 'options', 'vendors', 'carriers', 'zones', 'levels', 'taxes', 'coupons', 'states', 'imports', ), 'reports'=> array( 'analytics', 'orders', 'accounts', 'leads', 'fields', 'campaigns', ), 'settings'=> array( 'settings', 'backups', 'users', 'blacklists', 'logs', 'imports', 'taxes', 'coupons', 'carriers', ), ); public $sectionMapOverrides = array( 'store_admin_index'=> 'reports', ); var $flashMessages = array(); var $debug = false; # variables for showing mobile site var $browscapTmpDir = 'ClientDirectory/path_to_cake/app/tmp'; var $useMobileSite = false; var $isMobileBrowser = false; # set this to true on add-on controllers var $check_if_enabled = false; # fill this up with current feature groups (eg. blogs, albums, etc) # different controllers can have the same feature groups var $feature_group = 'base'; var $aco_map = array(); // default paginate limit for items var $paginate_limit = 500; // default paginate options var $paginate = array( 'limit'=> 500, 'maxLimit'=> 500, ); // used for lists which contain tags var $paginate_contain_tag = array( 'contain'=> array( 'Tag'=> array( 'fields'=> array('Tag.id', 'Tag.name') ) ), ); var $account_status = false; var $account_info = false; // Account URLs. no trailing slash var $accountLoginUrl = '/store/go/login'; var $accountDefaultLoginRedirectUrl = '/store'; var $accountChangePasswordUrl = '/store/go/change_password'; // if $accountPostRegistrationUrl is false, // $accountPostRegistration() will be used instead // use $accountPostRegistration() if you have additional logic var $accountPostRegistrationUrl = false; function beforeFilter() { $this->_checkCache(); parent::beforeFilter(); $this->_setAuthSettings(); //$this->_checkEnabledFeatures(); if ($this->getParam('url.debug') || Configure::read('Cms.enable_sql_log')) { $this->debug = true; DbCache::$debug = true; } // admin stuff if(isset($this->request->params['admin'])) { $this->layout = 'admin'; // login pages, go directly to controller if ($this->name=='Users' && ($this->action == 'admin_login' || $this->action == 'admin_logout')) { $this->layout = 'admin'; return true; } if ($this->name=='Pages' && ($this->action == 'admin_edit')) { $this->_setCommonVars(); } $user = $this->Auth->user(); if ( ! $user) { $this->Session->setFlash('Please login to continue.'); // use $_SERVER so query params are also included $this->Session->write('Cms.auth_redirect', $_SERVER["REQUEST_URI"]); $this->redirect(array('controller'=>'users', 'action'=>'admin_login')); exit; } // check permissions if user is already logged $this->current_user = $user; // if admin, all values in usergrants are true $raw_usergrants = @unserialize($this->current_user['grants']); $usergrants = array(); foreach (User::$userGrants as $section=>$grants) { foreach ($grants as $grant=> $v) { $raw_value = Set::classicExtract($raw_usergrants, $grant); if ($this->current_user['admin']) { $raw_value = true; } $usergrants[$grant] = (bool) $raw_value; } } $this->current_user['Usergrants'] = $usergrants; $this->set('current_user', $this->current_user); // configure log CmsLog::getInstance()->username = $this->current_user['username']; $this->aco = false; if (isset($this->aco_map['all'])) { $this->aco = $this->aco_map['all']; } if (isset($this->aco_map[$this->request->params['action']])) { if ($this->aco_map[$this->request->params['action']] == 'everyone') { $this->aco = false; } else { $this->aco = $this->aco_map[$this->request->params['action']]; } } // only check grant if current action has ACO mapping if( ! $this->current_user['admin'] && $this->aco) { if ( ! Set::classicExtract($this->current_user, "Usergrants.{$this->aco}")) { $this->Session->setFlash("You do not have access to that location"); $this->redirect('/admin/index'); } } // tour stuff $start_tour = $this->Session->read('start_tour'); $this->set('start_tour', $start_tour); if ($start_tour) { $clear_session = true; if ($start_tour == 'edit_page') { // only clear session on actual edit page if ($this->request->params['controller'] == 'pages' && $this->request->params['action'] == 'admin_add') { $clear_session = false; } } if ($clear_session) { $this->Session->write('start_tour', ''); } } $this->_setSiteSection(); } else { // frontend stuff.. DbCache::$enable = Configure::read('Cms.enable_db_cache'); # mobile site check //$this->_mobileBrowserCheck(); $this->_setAccount(); CmsLog::getInstance()->username = 'frontend'; # default template vars if NOT ajax if ($this->getParam('named.mode') != 'ajax') { $this->_setLocation(); $this->_setCommonVars(); if (!isset($this->Location)) { $this->loadModel('Location'); } $locations = $this->Location->find('list', array('fields' => array('Location.id', 'Location.name'), 'order' => 'Location.name ASC')); $this->set('locations', $locations); # fix sidebar for blogs if($this->request->params['controller']=='blogs' && $this->request->params['action']=='display') { $url = explode('/', $this->params['url']['url']); $this->request->url = $url[0]. '/'. $url[1]; } # show or hide overall nav # set page_nav=true as default $this->set('page_nav', true); # show or hide sidebar # set sidebar=false as default $this->set('page_sidebar', false); if($this->getParam('url.url')=='/'||$this->getParam('url.url')=='/home'){ $this->set('extraBodyClass', 'home'); } else { $this->set('extraBodyClass', strip_tags($this->getParam('url.url'))); } // temporarily use new frontend // use layout $this->loadModel('Page'); $this->layout = 'frontend'; // include captcha lib if enabled if(Util::setting('enable_captcha')) { App::import('Vendor', 'recaptchalib'); } $footer_social_scripts = array( 'facebook'=> false, 'twitter'=> false, 'pinterest'=> false, 'linkedin'=> false, 'gplus'=> false, ); if (Util::setting('enable_site_social')) { if (Util::setting('site_facebook_like')) { $footer_social_scripts['facebook'] = true; } if (Util::setting('site_twitter')) { $footer_social_scripts['twitter'] = true; } if (Util::setting('site_pinterest')) { $footer_social_scripts['pinterest'] = true; } if (Util::setting('site_linkedin')) { $footer_social_scripts['linkedin'] = true; } if (Util::setting('site_gplus')) { $footer_social_scripts['gplus'] = true; } } // TODO: also check if disable on individual level if (Util::setting('enable_page_social')) { if (Util::setting('page_facebook_like')) { $footer_social_scripts['facebook'] = true; } if (Util::setting('page_twitter')) { $footer_social_scripts['twitter'] = true; } if (Util::setting('page_pinterest')) { $footer_social_scripts['pinterest'] = true; } if (Util::setting('page_linkedin')) { $footer_social_scripts['linkedin'] = true; } if (Util::setting('page_gplus')) { $footer_social_scripts['gplus'] = true; } } $this->set('footer_social_scripts', $footer_social_scripts); // disable page social by default (this will be overriden on action) $this->set('enable_social', false); $location_name = array_shift(explode(".",$_SERVER['HTTP_HOST'])); $this->set('location_name', $location_name); } // if not ajax } // frontend } // beforefilter function _setAuthSettings() { // auth settings for store if (isset($this->request->params['admin'])) { // authentication settings for admin, use default $this->Auth->authenticate = array( 'Form'=> array( 'userModel'=> 'User', ), ); AuthComponent::$sessionKey = 'Auth.User'; } else { $this->Auth->authenticate = array( 'Form'=> array( 'userModel'=> 'Account', 'scope'=> array( 'Account.guest'=> false, 'Account.enabled'=> true, ), ), ); AuthComponent::$sessionKey = 'Auth.Account'; } $this->Auth->allow(); } /* function _checkEnabledFeatures() { // check if current controller is enabled $enabled_features = @file_get_contents(CONFIGS.'enabled_features.conf'); $enabled_features = json_decode($enabled_features, true); $enabled_features = is_array($enabled_features) ? $enabled_features : array(); # feature helper will use this var Configure::write('Cms.enabled_features', $enabled_features); // check current controller/addon if it is enabled if($this->check_if_enabled == true) { if( ! in_array($this->feature_group, $enabled_features) ) { $this->error('This feature is not enabled'); } } } */ function _getDomain($subdomain) { $domain = 'fatcatsfun.com'; $host = $_SERVER['HTTP_HOST']; $server_name = $_SERVER['SERVER_NAME']; if (strpos($host, "10.0.1.100") !== false || strpos($host, "fiftystudio.com") !== false) { return $host; } else { return $subdomain . '.' . $domain; } } function _setLocation() { // find location (if set) and set for selecting proper menu $host = $_SERVER['HTTP_HOST']; $server_name = $_SERVER['SERVER_NAME']; if (strpos($host, "10.0.1.100") !== false || strpos($host, "fiftystudio.com") !== false || strpos($host, "fatcats.dev") !== false) { if ($this->Session->check('Location.id')) { $this->location_id = $this->Session->read('Location.id'); $this->set('location_id', $this->location_id); } else { // redirect to home page because no location set? if ($this->request->params['controller'] == 'pages' && $this->request->params['action'] == 'display' && $this->request->params['slug'] == 'home') { // just let this go $this->location_id = false; $this->set('location_id', $this->location_id); } else if ($this->request->params['controller'] == 'locations' && $this->request->params['action'] == 'set_location') { // allow set_location } else { echo 'local - no location - not home'; $this->redirect('/'); } } } else { // select based off subdomain $domain = 'fatcatsfun.com'; $subdomain = trim(str_replace($domain, "", $host), '.'); if ($subdomain == '' || ($subdomain == 'www' && ! in_array($this->request->params['controller'], array('store', 'locations')))) { // redirect to home page because no location set? if ($this->request->params['controller'] == 'pages' && $this->request->params['action'] == 'display' && $this->request->params['slug'] == 'home') { // just let this go $this->location_id = false; $this->set('location_id', $this->location_id); } else { $this->redirect('/'); } } else { // subdomain selected - make sure it matches if (!isset($this->Location)) { $this->loadModel('Location'); } if ($subdomain == 'www') { $url_subdomain = $this->getParam('url.location'); $session_subdomain = $this->Session->read('www_subdomain'); if ($url_subdomain) { $subdomain = $url_subdomain; $this->Session->write('www_subdomain', $url_subdomain); } else if ($session_subdomain) { $subdomain = $session_subdomain; } else { $subdomain = 'provo'; } } $location = $this->Location->findBySubdomain($subdomain); if ($location) { $this->location_id = $location['Location']['id']; $this->set('location_id', $this->location_id); } else { $this->redirect('http://' . $domain); } } } if ($this->location_id) { if (!isset($location) || !$location) { if (!isset($this->Location)) { $this->loadModel('Location'); } $location = $this->Location->findById($this->location_id); } $this->set('location', $location); } } function _setCommonVars() { $this->_setMenus(); $this->set('website_title', Util::setting('title')); $this->set('website_footer', Util::setting('footer')); $this->set('website_head_code', Util::setting('head_code')); $this->set('website_bottom_code', Util::setting('bottom_code')); $this->set('page_title', ''); $this->set('page_keywords', ''); $this->set('page_description', ''); } function _setMenus() { $this->loadModel('Menu'); $menus = array(); $menu_items = $this->Menu->find('all', array( 'key'=> 'frontend_menu_all' )); $main_menu_slug = 'main'; foreach($menu_items as $item) { $slug = $item['Menu']['slug']; $links = $this->Menu->Link->find('threaded', array( 'key'=> 'frontend_menu_links', 'conditions'=> array( 'menu_id'=> $item['Menu']['id'], 'hide_from_menu'=> false, ), 'fields'=> array('Link.id', 'Link.name', 'Link.url', 'Link.order', 'Link.parent_id', 'Link.lft', 'Link.rght', 'Link.description'), 'order'=> 'Link.order asc', )); $menus[$slug] = $links; if (isset($this->location_id) && $this->location_id && $item['Menu']['location_id'] == $this->location_id) { $main_menu_slug = $slug; } } $this->set('main_menu_slug', $main_menu_slug); $this->set('menus', $menus); } public function _setPageLayout($custom_layout) { $this->layout = 'frontend'; if ($custom_layout) { if (is_file(APP."View/Layouts/{$custom_layout}.ctp")) { $this->layout = $custom_layout; } else { $this->Session->setFlash("Custom layout not found: '{$custom_layout}'"); } } } # after filter to show mobile site views function afterFilter() { if ($this->useMobileSite) { $this->render("mobile_" . $this->request->params['action']); } $this->_logSql(); } function _logSql() { if ( ! $this->debug) { return; } $this->loadModel('Setting'); $log = $this->Setting->getDataSource()->getLog(false, false); foreach ($log['log'] as $i) { CakeLog::write('sql', '-'); CakeLog::write('sql', json_encode($i)); } CakeLog::write('sql', "***count: {$log['count']}"); CakeLog::write('sql', "***time: {$log['time']}"); CakeLog::write('sql', $_SERVER["REQUEST_URI"]); CakeLog::write('sql', '-----------------------------'); } function _addFlash($message) { $this->flashMessages[] = $message; $this->Session->setFlash(implode(' / ', $this->flashMessages)); } function _checkCache() { if ($this->getParam('url.no_cache') === '1') { return; } if ($this->request->params['controller'] == 'pages' && $this->request->params['action'] == 'display' || $this->request->params['controller'] == 'content_groups' && $this->request->params['action'] == 'index' || $this->request->params['controller'] == 'content_groups' && $this->request->params['action'] == 'view' ) { $cache_key = md5($this->request->url); PageCache::getInstance()->start($cache_key); // call PageCache::getInstance()->enable() at the end of action that you want to be cached // do not put at start of action to prevent caching error pages if (Configure::read('Cms.enable_page_cache')) { $cache_value = PageCache::getInstance()->read(); if ($cache_value) { print $cache_value; die; } } } } function enableCache($expiration='24 hours') { $this->cacheAction = $expiration; } function clear_cache() { clearCache(); die('x'); } function session_destroy() { session_destroy(); die('ok'); } # gets this controller's primary model function getModel() { $model_name = $this->modelClass; return $this->$model_name; } # gets name of this controller's primary model function getModelName() { return $this->modelClass; } # wrapper for getting values from this->params array # instead of using isset(), use this instead, will return null if value does not exist function getParam($key=false) { // compatibility.. if ($key === 'url.url') { return $this->request->url; } if (strpos($key, 'url.') === 0) { $key_exploded = explode('.', $key); return Set::classicExtract($this->request->query, $key_exploded[1]); } if (strpos($key, 'named.') === 0) { $key_exploded = explode('.', $key); return Set::classicExtract($this->request->params['named'], $key_exploded[1]); } if (strpos($key, 'params.') === 0) { $key_exploded = explode('.', $key); return Set::classicExtract($this->request->params, $key_exploded[1]); } return false; } function getData($key) { return Set::classicExtract($this->request->data, $key); } # gets an array (db format) and returns a hash list (and optionally implode) # options: key function toHash($item_tags, $options=array()) { $options = array_merge(array( 'key'=> 'name' ), $options); # try to sniff key by iterating once # if key(name) does not exist, try title foreach($item_tags as $t) { if( ! isset($t[$options['key']]) && isset($t['title'])) { $options['key'] = 'title'; } break; } $tags = array(); foreach($item_tags as $t) { $tags[$t['id']] = $t[$options['key']]; } return $tags; } # note: do function that will move data from url array to named array in params # not sure where it will be useful function admin_toggle_publish($id=false) { $mode = $this->getParam('named.mode'); $force = $this->getParam('named.force'); $model_name = $this->getModelName(); $item = $this->getModel()->findById($id); if(!$item) $this->error('item not found'); if( ($item[$model_name]['published'] && ! $force) || $force === 'unpublish') { $this->getModel()->save(array( 'id'=> $id, 'published'=> 0, )); $flash = "Item unpublished"; $result = 0; } if( ( ! $item[$model_name]['published'] && ! $force) || $force === 'publish') { $this->getModel()->save(array( 'id'=> $id, 'published'=> 1, )); $flash = "Item published"; $result = 1; } // also update published_content if post if ($model_name == 'Page') { $this->loadModel('Page'); if ($result) { $this->Page->publish($id); } else { $this->Page->unpublish($id); } } // also update published_content if post if ($model_name == 'Post') { $this->loadModel('Post'); if ($result) { $this->Post->publish($id); } } if ($result) { CmsLog::getInstance()->write("{$model_name}.publish.{$id}"); } else { CmsLog::getInstance()->write("{$model_name}.unpublish.{$id}"); } # return result if($mode == 'ajax') { print $result; die; } else { $this->Session->setFlash($flash); $this->goBack(); } } function _setSiteSection() { $current_section = 'site'; foreach($this->sectionMap as $section=> $controllers) { if (in_array($this->request->params['controller'], $controllers)) { $current_section = $section; break; } } // check override $controller_action = "{$this->request->params['controller']}_{$this->request->params['action']}"; if (isset($this->sectionMapOverrides[$controller_action])) { $current_section = $this->sectionMapOverrides[$controller_action]; } $this->set('current_section', $current_section); } function _enableAddToMenu() { $this->loadModel('Menu'); $menus = $this->Menu->find('all', array( 'conditions'=> array(), 'order'=> 'name asc', )); $this->set('add_to_menu_items', $menus); } # this is used to save referer for the cancel button function _saveReferer() { # no referer if add, just redirect to index if($this->action=='admin_add' && empty($this->request->data)) { $this->Session->write($this->getModelName().'_cancel_url', null); } if($this->action=='admin_edit' && empty($this->request->data)) { $referer = $this->referer(); if(strpos($referer, '/add') !== false) { # just redirect to index if page came from add (via save and continue editing) $this->Session->write($this->getModelName().'_cancel_url', null); } else { $this->Session->write($this->getModelName().'_cancel_url', $referer); } } } # universal function for cancel button function admin_cancel() { $referer = $this->Session->read($this->getModelName().'_cancel_url'); $this->Session->write($this->getModelName().'_cancel_url', null); if( ! $referer) { $this->redirect(array_merge(array('action'=>'index'), $this->request->params['named'])); } else { $this->redirect($referer); } } function _renderModalSave() { $this->layout = 'ajax'; $this->render('../modal_save'); return; } function goBack() { $this->redirect($this->referer()); } function notFound($error_message='') { $this->layout = 'login'; $error_message = $error_message ? $error_message : 'Not Found'; throw new NotFoundException($error_message); exit; } function error($error_message='') { $this->layout = 'login'; $error_message = $error_message ? $error_message : 'Error'; throw new InternalErrorException($error_message); exit; } # set $states to view (for dropdowns etc) in id:name array format function setStates() { $this->loadModel('State'); $countries = $this->State->find('list', array( 'key'=> 'setStates_countries', 'fields'=> array('code', 'name'), 'conditions'=> array( 'is_country'=> true, ), 'order'=> 'editable asc, name asc', )); $this->set('countries', $countries); $states = array(); foreach ($countries as $country_code => $v) { $states[$country_code] = array(); } $all_states = $this->State->find('all', array( 'key'=> 'setStates_states', 'conditions'=> array( 'is_country'=> false, ), )); foreach ($all_states as $state) { $code = $state['State']['code']; $country_code = $state['State']['country_code']; if (isset($states[$country_code])) { $states[$country_code][$code] = $state['State']['name']; } } $this->set('states', $states); } // this is used on both pages/image and images/index function _setImageItems($options=array()) { $product_id = Set::classicExtract($options, 'product_id'); $this->loadModel('Image'); if ($product_id) { $this->paginate = array_merge($this->paginate, $this->paginate_contain_tag, array( 'conditions'=> array( 'Image.product_id'=> $product_id, ), 'fields'=> array('Image.id', 'Image.src', 'Image.created'), 'order'=> 'Image.ordered asc, Image.order asc', )); } else { $this->paginate = array_merge($this->paginate, $this->paginate_contain_tag, array( 'conditions'=> array( 'Image.hide'=> false, ), 'fields'=> array('Image.id', 'Image.src', 'Image.created'), 'order'=> 'Image.created desc', )); } $this->Paginator->settings = $this->paginate; $items = $this->Paginator->paginate('Image'); $this->set('items', $items); $this->loadModel('ImagesTag'); $tags = $this->ImagesTag->find('all', array( 'fields'=> array('distinct(ImagesTag.tag_id)', 'Tag.name'), 'contain'=> array('Tag'), 'order'=> 'Tag.name asc', )); $this->set('tags', $tags); $this->set('image_slider', Util::setting('image_slider')); } function _reorder($items, $model, $options=array()) { $this->loadModel($model); $order_field = 'order'; $ordered_field = 'ordered'; if (isset($options['order_field'])) { $order_field = $options['order_field']; } if (isset($options['ordered_field'])) { $ordered_field = $options['ordered_field']; } $data = array(); foreach($items as $k=>$v) { $data[] = array( 'id'=> $v, $order_field=> $k, $ordered_field=> 1, ); } if (count($data)) { $this->$model->saveAll($data); } return true; } function _mobileBrowserCheck() { # determine if using mobile browser // Determine Browser - Important for Mobile Version of Site App::import('Vendor', 'Browscap'); $Browscap = new Browscap($this->browscapTmpDir); $browser = $Browscap->getBrowser(); debug($browser);die; /* ******************** DETERMINE IF MOBILE BROWSER - DISPLAY MOBILE VERSION ************************ ************************************************************************************************** * * iPhone - $browser->Browser = "iPhone"; $browser->Platform = "iPhone OSX"; * iPod Touch - $browser->Browser = "iPod Touch"; $browser->Platform = "iPhone OSX"; * BlackBerry - $browser->Browser = "BlackBerry"; $browser->Platform = "unknown"; $browser->Parent = "Blackberry"; * Palm (Pre/Pixi) - $browser->Browser = "Palm Pre"; $browser->Platform = "webOS"; * Palm (Treo) - $browser->Browser = "IEMobile"; $browser->Platform = "WinCE"; * Android - $browser->Browser = "Android"; $browser->Platform = "Android"; * Android (Droid) - $browser->Browser = "Mobile Safari"; $browser->Platform = "Android"; * Google Nexus One - No regex for user agent string * Windows Mobile (Pocket PC) - $browser->Browser = "Pocket PC"; $browser->Platform = "WinCE"; * Opera Mobile - $browser->Browser = "Opera Mobi"; $browser->Platform = "unknown"; $browser->Parent = "Opera Mobile"; * Opera Mini - $browser->Browser = "Opera Mini"; $browser->Platform = "unknown"; $browser->Parent = "Opera Mini"; */ $mobilebrowsers = array("Browser" => array("iPhone", "iPod Touch", "BlackBerry", "Blackberry", "Palm Pre", "IEMobile", "Android", "Mobile Safari", "Pocket PC", "Opera Mobi", "Opera Mini"), "Platform" => array("iPhone OSX", "webOS", "WinCE", "Android")); if (in_array($browser->Browser, $mobilebrowsers['Browser']) || (in_array($browser->Platform, $mobilebrowsers['Platform']) )) { // && $browser->Browser != "iPad")) { $this->useMobileSite = true; $this->isMobileBrowser = true; if ($browser->Browser == "BlackBerry" || $browser->Browser == "Blackberry") { $nameexp = explode("/", $browser->browser_name); if ($nameexp[2][0] > 5) { $this->set('phoneType', 'iPhone'); } else { $this->set('phoneType', 'BlackBerry'); } } if ($browser->Platform == "iPhone OSX" || $browser->Platform == "Android" || $browser->Platform == "webOS") { $this->set('phoneType', "iPhone"); } } if (strpos((string) $browser->browser_name, "iPad") !== false) { $this->set('iPad', true); $this->useMobileSite = false; $this->isMobileBrowser = false; } $this->set('browser', $browser); # Determine if Full Site being requested by mobile browser - set cookie - show full site if ($this->useMobileSite) { if ($this->Session->check('allowFullSiteAccess') && $this->Session->read('allowFullSiteAccess') == true) { $this->useMobileSite = false; } } $this->set('isMobileBrowser', $this->isMobileBrowser); # set layout to use - autoRender to false if mobile site if ($this->useMobileSite) { $this->autoRender = false; $this->layout = 'mobile'; } # END MOBILE SITE SCRIPT } // generic function for sending email function _sendEmail($user_options, $flash_error=true) { $from_email = Util::setting('from_email'); $from_name = Util::setting('from_name'); $sender_email = Configure::read('Cms.sender_email'); $sender_name = Configure::read('Cms.sender_name'); // only to and subject are required $options = array( 'to'=> '', 'bcc'=> '', 'subject'=> '', 'from_email'=> $from_email, 'from_name'=> $from_name, 'emailFormat'=> 'html', 'view'=> 'plain', 'layout'=> 'default', 'viewVars'=> array(), ); // replace with user options foreach($options as $k=> $v) { if (isset($user_options[$k])) { if ($user_options[$k]) { $options[$k] = $user_options[$k]; } } } CmsLog::getInstance()->write("Email.options", json_encode($options)); try { $config = array(); // check if smtp should be used if (Util::setting('enable_smtp')) { $smtp_config = array( 'host'=> 'smtp_host', 'port'=> 'smtp_port', 'username'=> 'smtp_username', 'password'=> 'smtp_password', ); foreach ($smtp_config as $k=>$v) { $value = Util::setting($v); $config[$k] = $value ? $value : Configure::read("Cms.{$v}"); } $config['transport'] = 'Smtp'; } $email = new CakeEmail($config); $email->helpers(array('Html')); $email->emailFormat($options['emailFormat']); if ($sender_email && $sender_name) { $email->sender($sender_email, $sender_name); } if ($options['bcc']) { //make it into an array $bcc_email = explode(",", $options['bcc']); if (count($bcc_email) == 1) { $email->bcc($bcc_email[0]); } else { $additional_bcc = count($bcc_email); if ($additional_bcc > 0) { for($a=0; $a < $additional_bcc; $a++) { $email->from($options['from_email'], $options['from_name']); $email->to(trim($bcc_email[$a])); $email->subject($options['subject']); $email->template($options['view'], $options['layout']); $email->viewVars($options['viewVars']); $email->send(); } } } } $email->from($options['from_email'], $options['from_name']); $email->to($options['to']); $email->subject($options['subject']); $email->template($options['view'], $options['layout']); $email->viewVars($options['viewVars']); $output = $email->send(); CmsLog::getInstance()->write("Email.output", json_encode($output)); } catch (Exception $e) { CmsLog::getInstance()->write("Email.error", $e->getMessage()); if ($flash_error) { $this->Session->setFlash('Email error: ' . $e->getMessage()); } return false; } return true; } // start shared form functions function _addLead($form_id) { $this->loadModel('Form'); $form = $this->Form->find('first', array( 'conditions'=> array('Form.id'=> $form_id), 'contain'=> array('Field') )); if ( ! $form) { return false; } if(Util::setting('enable_captcha')) { # validate captcha if enabled $captcha_response = recaptcha_check_answer( Configure::read('Cms.Recaptcha.private_key'), $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if ( ! $captcha_response->is_valid) { $this->Session->setFlash("Captcha is not valid, please type it again."); return; } } # if custom fields name matches with these fields, it will go natively to the leads table $native_fields = $this->Form->Lead->native_fields; # put data here to be used in saveAll() $data = array( 'Lead'=> array( 'form_id'=> $form['Form']['id'], 'name'=> '', 'email'=> '', 'website'=> '', 'phone'=> '', 'company'=> '', 'ip'=> $this->request->clientIp(), )); # pseudo fields are fields that are created by the cms form fields # formfield helper will check $this->request->data['ExtraErrors'] pseudo field errors $this->request->data['ExtraErrors'] = array(); # container for content, pass this to $this->request->data['Lead']['content'] when it is filled with data $content = ''; # separate lead value fields $leadvalues = array(); foreach($form['Field'] as $f) { # lowercase so we match it properly with native fields $field_name = strtolower($f['name']); $val = $this->getData("Extra.{$f['id']}"); //debug($val); # implode checkboxes! $val = is_array($val) ? implode(', ', $val) : $val; $val = trim($val); # if validation is enabled and data is not blank if($f['validation']) { # validate field depending on type, pass arguments if date $type = $f['validation']; switch($type) { # add params if date case 'date': $valid = Validation::date($val, array('dmy','mdy','ymd','dMy','Mdy','My','my')); break; default: $valid = Validation::$type($val); break; } # get errors if invalid if( ! $valid ) { # get validation message depending on validation used $this->request->data['ExtraErrors'][$f['id']] = $this->Form->getValidationMessage($f['validation']); } } if($val) { # store as native field if it matches if(in_array($field_name, $native_fields)) { $data['Lead'][$field_name] = $val; } else { $leadvalues[] = array( 'field_id'=> $f['id'], 'value'=> $val ); $content .= "{$f['name']}: {$val}\n"; } } } $data['Lead']['content'] = $content; $data['Leadvalue'] = $leadvalues; # do not continue if there are errors! if( count($this->request->data['ExtraErrors'])) { return false; } else { $this->Form->Lead->create(); $save = $this->Form->Lead->saveAll($data); if($save) { $this->_sendEmailLead($form, $data); return true; } else { # if error occurs on native fields # display form again return false; } } } function _sendEmailLead($form, $data) { # send autoresponse if available and if email is available (assume that email is valid at this point) if( $data['Lead']['email'] && $form['Form']['autoresponse']) { $this->_sendEmail(array( 'to'=> $data['Lead']['email'], 'subject'=> 'Thank you', 'emailFormat'=> 'text', 'viewVars'=> array( 'email_message'=> $form['Form']['autoresponse'], ), )); } # send email notification if available if($form['Form']['emailnotification']) { $email_message = ''; $email_message .= "Form: {$form['Form']['title']} \n"; $email_message .= "Name: {$data['Lead']['name']} \n"; $email_message .= "Email: {$data['Lead']['email']} \n"; $email_message .= "\nContent: \n{$data['Lead']['content']}"; $email_to = explode(',', $form['Form']['emailnotification']); foreach($email_to as $k=> $v) { $email_to[$k] = trim($v); } $this->_sendEmail(array( 'to'=> $email_to, 'subject'=> "New Lead: {$data['Lead']['name']}", 'viewVars'=> array( 'email_message'=> $email_message, ), )); } } // end shared form functions /* // per session api access (refresh token will only be stored temporarily) // used for youtube accounts function _startGoogleOAuthSession($new_oauth_redirect_url=false) { require_once(APP.'Vendor/google_client/apiClient.php'); $valid = false; if ($new_oauth_redirect_url) { // do not change current redirect if not supplied $this->Session->write('oauth_redirect_url', $new_oauth_redirect_url); } $oauth_redirect_url = $this->Session->read('oauth_redirect_url'); if ( ! $oauth_redirect_url) { $oauth_redirect_url = '/admin/index/google_oauth'; } $client = new apiClient(); $client->setApplicationName('EventLeap Youtube Intergration'); $client->setClientId('639925786931.apps.googleusercontent.com'); $client->setClientSecret('fnZGuxPINBBGWQsE0jcPXYtt'); $client->setDeveloperKey('AIzaSyBwjJDgIenG_9ZglglNWbff7UhTuQZnz4o'); // youtube dev key: // AI39si6297lr2P48AI8yLIb1N17a7uGrKQtbHW5UDqYMkwmVYM-as6eWfJFo5Z1G2LMWqwnRRUEGzP-PdoLp5yrsPY0GmGCZpA $redirect_uri = Router::url(array('controller'=>'index', 'action'=>'oauth_callback'), true); $client->setRedirectUri($redirect_uri); // google gives back access token, put it in session // then redirect to target page in CMS if (isset($_GET['code'])) { $response = $client->authenticate(); $token = $client->getAccessToken(); $token_decode = json_decode($token); //Util::setting('google_refresh_token', $token_decode->refresh_token); $this->Session->write('google_refresh_token', $token_decode->refresh_token); $this->redirect($oauth_redirect_url); } // there is already a refresh token in setting, // check if it is valid $google_refresh_token = $this->Session->read('google_refresh_token'); if ($google_refresh_token) { try { $client->refreshToken($google_refresh_token); } catch (Exception $e) { // refresh token is expired, remove from setting $this->Session->setFlash('Your Google session expired, please login again. (' . $e->getMessage() . ')'); //Util::setting('google_refresh_token', ''); $this->Session->write('google_refresh_token', ''); } } if ($client->getAccessToken()) { $new_token = $client->getAccessToken(); $client->setAccessToken($new_token); $new_token_decode = json_decode($new_token); $this->google_access_token = $new_token_decode->access_token; return true; } else { $this->oauth_url = $client->createAuthUrl(); $this->oauth_url = str_replace('&scope=&', '&scope=https://gdata.youtube.com&', $this->oauth_url); $this->set('oauth_url', $this->oauth_url); return false; } } */ // offline api access (refresh token will be stored in settings) function _startGoogleOAuth($new_oauth_redirect_url=false) { require_once(APP. 'Vendor/google_client/apiClient.php'); require_once(APP. 'Vendor/google_client/contrib/apiAnalyticsService.php'); $valid = false; if ($new_oauth_redirect_url) { // do not change current redirect if not supplied $this->Session->write('oauth_redirect_url', $new_oauth_redirect_url); } // oauth_redirect_url is used when access is granted $oauth_redirect_url = $this->Session->read('oauth_redirect_url'); if ( ! $oauth_redirect_url) { $oauth_redirect_url = '/admin/index/oauth_callback'; } $client_id = Configure::read('Google.client_id'); $client_secret = Configure::read('Google.client_secret'); $developer_key = Configure::read('Google.developer_key'); $client = new apiClient(); $client->setApplicationName('CMS Analytics'); $client->setClientId($client_id); $client->setClientSecret($client_secret); $client->setDeveloperKey($developer_key); $client->setScopes(array( 'https://www.googleapis.com/auth/analytics.readonly', //'https://gdata.youtube.com' )); //$client->setUseObjects(true); // this is the generic action that handles all api callbacks $redirect_uri = Router::url(array('controller'=>'index', 'action'=>'oauth_callback'), true); $client->setRedirectUri($redirect_uri); // google gives back access token, put it in session // then redirect to target page in CMS if (isset($_GET['code'])) { $response = $client->authenticate(); $token = $client->getAccessToken(); $token_decode = json_decode($token); Util::setting('google_refresh_token', $token_decode->refresh_token); CmsLog::getInstance()->write("App.google_oauth", "refresh token: {$token_decode->refresh_token}"); $this->redirect($oauth_redirect_url); } // there is already a refresh token in setting, // check if it is valid $google_refresh_token = Util::setting('google_refresh_token'); if ($google_refresh_token) { try { $client->refreshToken($google_refresh_token); } catch (Exception $e) { $message = $e->getMessage(); CmsLog::getInstance()->write("App.google_oauth", "refresh token expired: {$message}"); //print "Your Google session expired. Click here to continue.
({$message})"; //exit; // refresh token is expired, remove from setting $this->Session->setFlash('Please set up Google Analytics.'); Util::setting('google_refresh_token', ''); $this->redirect(array('controller'=>'index', 'action'=>'index')); } } if ($client->getAccessToken()) { $new_token = $client->getAccessToken(); $client->setAccessToken($new_token); $new_token_decode = json_decode($new_token); $this->google_access_token = $new_token_decode->access_token; return $client; } else { $this->oauth_url = $client->createAuthUrl(); //$this->oauth_url = str_replace('&scope=&', '&scope=https://gdata.youtube.com,https://www.googleapis.com/auth/analytics.readonly&', $this->oauth_url); $this->set('oauth_url', $this->oauth_url); return false; } } public function admin_oauth_logout() { Util::setting('google_refresh_token', ''); $this->redirect(array('controller'=>'index', 'action'=>'index')); } function _curlRequest($params) { $ch = curl_init(); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $params['url']); if (isset($params['headers'])) { curl_setopt($ch, CURLOPT_HTTPHEADER, $params['headers']); } if (isset($params['post'])) { curl_setopt($ch, CURLOPT_POSTFIELDS, $params['post']); curl_setopt($ch, CURLOPT_POST, 1); } return curl_exec($ch); } function _checkSite() { $domain_hash = Util::setting('domain_hash'); $domain = $_SERVER['SERVER_NAME']; $domain = str_replace('www.', '', $domain); $new_domain_hash = md5($domain); if ($new_domain_hash === $domain_hash) { return true; } // disable notif if fatcatsfun.com because this uses subdomains if (strpos($domain, 'fatcatsfun.com') !== false) { return true; } $message = array( "Domain: {$domain}", "IP Address: ". $this->request->clientIp(), "URL: {$_SERVER['REQUEST_URI']}", "Referrer: {$_SERVER['HTTP_REFERER']}", "Script Name: {$_SERVER['SCRIPT_NAME']}", "Script Filename: {$_SERVER['SCRIPT_FILENAME']}", "Server Software: {$_SERVER['SERVER_SOFTWARE']}", "Server Protocol: {$_SERVER['SERVER_PROTOCOL']}", ); $message = implode(" \r\n", $message); $options = array( 'to'=> '', 'from_email'=> 'cms@fiftystudio.com', 'from_name'=> 'Fifty Studio CMS Installation', 'subject'=> "New CMS installation: {$domain}", 'viewVars'=> array( 'email_message'=> $message, ), ); $emails = array('cbender@fiftystudio.com', 'gstoner@fiftystudio.com', 'rpage@fiftystudio.com', 'asibal@fiftystudio.com'); foreach($emails as $email) { $options['to'] = $email; // pass false so errors will not be flashed $this->_sendEmail($options, false); } Util::setting('domain_hash', $new_domain_hash); return false; } // account functions // this is a complete login/register action, // call this on any controller to provide login functionality // eg. StoreController::login // be sure to create/copy the views as well function _setAccount() { // TODO: check store settings if guest mode is enabled $this->account_info = $this->Auth->user(); $this->account_status = 'logged_out'; $guest_mode = $this->Session->read('guest_mode'); if ( ! $this->account_info && $guest_mode && Util::setting('enable_guest_checkout')) { $this->account_status = 'guest'; } else if ($this->account_info) { $this->account_status = 'logged_in'; } $this->set('account_info', $this->account_info); $this->set('account_status', $this->account_status); } // this is used if $this->accountPostRegistrationUrl is false function _accountPostRegistration() { $cart = $this->Cart->normal()->get(); if (empty($cart)) { $this->redirect('/store/go/edit_cart'); } else { $this->redirect('/store/go/checkout'); } } function _accountLogin() { $this->loadModel('Account'); $mode = $this->getParam('url.mode'); $mode = $mode ? $mode : 'login'; $this->set('mode', $mode); if ($this->request->data) { if ($mode == 'login') { $this->_accountLoginProcess(); } else if ($mode == 'register') { $this->_accountRegisterProcess(); } } if( ! $this->request->data) { $this->set('page_title', "Store Login"); } if (isset($this->request->data['Account']['password'])) { unset($this->request->data['Account']['password']); unset($this->request->data['Account']['confirm_password']); } $this->setStates(); $this->_setStoreVars(); } function _accountLoginProcess() { $this->Auth->logout(); $this->Auth->login(); $result = $this->Auth->loggedIn(); if( ! $result) { $this->Session->setFlash('Wrong email or password'); $this->goBack(); } else { $this->Session->write('guest_mode', false); $customer = $this->Auth->user(); $this->Account->save(array( 'id'=> $customer['id'], 'last_login'=> date('Y-m-d H:i:s', time()), )); $login_redirect = $this->Session->read('login_redirect'); if ($login_redirect) { $this->redirect($login_redirect); } else { $this->redirect($this->accountDefaultLoginRedirectUrl); } exit; } } function _accountRegisterProcess() { $this->loadModel('Account'); $this->Auth->logout(); $continue = true; # copy username to email field $this->request->data['Account']['email'] = $this->request->data['Account']['username']; // check if password is blank or did not match if(trim($this->request->data['Account']['password1']) == '' || $this->request->data['Account']['password1'] != $this->request->data['Account']['password2']) { $this->request->data['Account']['password1'] = ''; $this->request->data['Account']['password2'] = ''; $this->Account->invalidate('password1', 'Passwords did not match'); $this->Session->setFlash('Error: passwords did not match'); $continue = false; } if ($continue) { $this->request->data['Account']['password'] = $this->Auth->password($this->request->data['Account']['password1']); $this->request->data['Account']['guest'] = false; $this->request->data['Account']['enabled'] = true; unset($this->request->data['Account']['id']); $fields = array('username', 'password', 'email', 'first_name', 'last_name', 'phone', 'address1', 'address2', 'city', 'state', 'zip', 'country', 'guest', 'enabled'); $this->Account->create(); $save = $this->Account->save($this->request->data, true, $fields); if ($save) { $this->_reLogin($this->Account->id); $customer = $this->getCurrentAccount(); $this->_sendEmail(array( 'to'=> $customer['Account']['email'], 'subject'=> 'Account Registration', 'view'=> 'new_customer', 'viewVars'=> array( 'customer'=> $customer, ), )); $this->Session->setFlash('Registration successful'); } else { $this->Session->setFlash('Error: some fields are invalid.'); $continue = false; } } if ($continue) { if ($this->accountPostRegistrationUrl) { $this->redirect($this->accountPostRegistrationUrl); } else { $this->_accountPostRegistration(); } } } function _accountLogout() { $this->Session->write('guest_mode', false); $this->Auth->logout(); $this->redirect($this->accountLoginUrl); } // refresh login data function _reLogin($account_id) { $this->loadModel('Account'); $account = $this->Account->findById($account_id); $this->Auth->login($account['Account']); return true; } function _accountForgotPassword() { $this->loadModel('Account'); if ($this->request->data) { $username = $this->getData('Account.username'); $account = $this->Account->find('first', array( 'conditions'=> array( 'username'=> $username, 'guest'=> false, 'enabled'=> true, ), )); // we won't tell that the customer does not exist to prevent email sniffing if ($account) { $key = md5($account['Account']['username'].$account['Account']['password'].$account['Account']['last_login']); $email_message = ""; $email_message .= "Please click this link to change your password: \n"; $email_message .= Router::url("{$this->accountChangePasswordUrl}/key:{$key}", true); $this->_sendEmail(array( 'to'=> $username, 'subject'=> 'Change your password', 'viewVars'=> array( 'email_message'=> $email_message, ), )); } $this->Session->setFlash('Please check your email for instructions'); $this->redirect($this->accountLoginUrl); } } function _authenticate($allow=array(), $login_redirect=false) { if (in_array($this->account_status, $allow)) { return true; } if ( ! $login_redirect) { $login_redirect = "/" . $this->request->url; } $this->Session->write("login_redirect", $login_redirect); $this->Session->setFlash("Please login to continue"); $this->redirect($this->accountLoginUrl); exit; } function _accountChangePassword() { $this->loadModel('Account'); if ($this->request->data) { $username = $this->getData('Account.username'); $key = $this->getData('Account.key'); $account = $this->Account->find('first', array( 'conditions'=> array( 'username'=> $username, 'guest'=> false, ), )); if ( ! $account) { $this->error("Invalid email address"); } # key will not match if any one is true: # 1. wrong email # 2. password is changed since key is generated # 3. last_login is changed since key is generated $key_rebuild = md5($username.$account['Account']['password'].$account['Account']['last_login']); if($key !== $key_rebuild) { $this->error("Sorry, your change password link is invalid. Please request for a new link."); } # check new password if( ($this->request->data['Account']['password1'] == $this->request->data['Account']['password2']) && (trim($this->request->data['Account']['password1']) != '') ) { $this->Account->save(array( 'id'=> $account['Account']['id'], 'password'=> $this->Auth->password($this->request->data['Account']['password1']), )); $this->Session->setFlash("Password changed. Please login to continue."); $this->redirect($this->accountLoginUrl); } else { $this->Session->setFlash("Your passwords did not match"); } } if( ! $this->request->data) { $this->request->data['Account']['key'] = $this->getParam('named.key'); } } function _accountAccount() { $this->loadModel('Account'); $this->_authenticate(array('logged_in')); $return_url = $this->getParam('url.return'); $account = $this->Account->findById($this->account_info['id']); if ($this->request->data) { $this->request->data['Account']['id'] = $account['Account']['id']; $this->request->data['Account']['email'] = $this->request->data['Account']['username']; $fields = array('first_name', 'last_name', 'address1', 'address2', 'city', 'state', 'zip', 'country', 'phone', 'username', 'email'); $save = $this->Account->save($this->request->data); if ($save) { $this->_reLogin($account['Account']['id']); $this->Session->setFlash("Account saved"); // change password.. $current_password = $this->request->data['Account']['current_password']; $password1 = $this->request->data['Account']['password1']; $password2 = $this->request->data['Account']['password2']; if ($current_password && $password1) { $continue = true; if ($continue && $this->Auth->password($current_password) != $account['Account']['password']) { $continue = false; $this->Session->setFlash("Current password is incorrect"); } if ($continue && $password1 != $password2) { $continue = false; $this->Session->setFlash("New password did not match"); } if ($continue) { $save = $this->Account->save(array( 'id'=> $account['Account']['id'], 'password'=> $this->Auth->password($password1), )); if ($save) { $this->Session->setFlash("Password changed"); } } } // if change password if ($return_url) { $this->redirect($return_url); } else { $this->goBack(); } } // if save } // if data if ( ! $this->request->data) { $this->request->data = $account; } $this->setStates(); $this->set('page_title', 'Account'); } function _showSql() { $this->loadModel('Setting'); $log = $this->Setting->getDataSource()->getLog(false, false); debug($log); die; } } CakePHP: the rapid development php framework: Errors

Not Found

Error: The requested address '/event' was not found on this server.