├── INSTALLING.txt ├── README.textile ├── changelog.txt └── system └── expressionengine └── third_party └── snippetssync ├── config └── snippetssync.php ├── ext.snippetssync.php ├── language └── english │ └── snippetssync_lang.php ├── libraries ├── ab │ ├── ab_common.php │ ├── ab_extbase.php │ ├── ab_libbase.php │ ├── ab_mcpbase.php │ ├── ab_modbase.php │ └── ab_updbase.php └── snippetslib.php ├── mcp.snippetssync.php ├── mod.snippetssync.php ├── upd.snippetssync.php └── views ├── _wrapper.php ├── index.php └── synced.php /INSTALLING.txt: -------------------------------------------------------------------------------- 1 | How to install 2 | ============== 3 | * Copy both the "/system/expressionengine/third_party/libraries/" and the "/system/expressionengine/third_party/snippetssync/" folders into /system/expressionengine/third_party/ 4 | * Navigate to Addons -> Extensions -> Enable SnippetsSync 5 | 6 | That's it. 7 | 8 | Read more here for how to actually use it: 9 | http://www.addonbakery.com/expressionengine-addons/snippetssync.html -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | h1. SnippetsSync 2 | 3 | This is an extension that lets you save your global variables and snippets as files, keeping them in-sync during the development. It should only be enabled as you develop (that is, on your dev server only, or turn it off when going in production). 4 | 5 | Read more about it here: "SnippetsSync for ExpressionEngine":http://wedoaddons.com/addon/snippetssync -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | Changelog for SnippetsSync 2 | ========================== 3 | The dates in this changelog use international date format: YYYY-MM-DD (ISO8601) 4 | 5 | 1.2 - 2015-03-11 6 | ------------------ 7 | * Feature: Generate unique URL to run SnippetsSync over HTTP. Use case – post-deploy hook. Also returns JSON response via AJAX call. (@elliotlewis) 8 | * Bug fix: mk_perms, even on successful creation of folder, error logged in CP. 9 | 10 | 1.1.4 - 2014-08-06 11 | ------------------ 12 | * SnippetsSync donesn't check for 'save_tmpl_files' anymore. The reason for this is that one might not want to save templates as files on production, and still be able to have snippetssync installed and sync manually ((without it throwing an error) - see https://github.com/bjornbjorn/snippetssync.ee2_addon/issues/13 13 | 14 | 1.1.3 - 2014-04-25 15 | ------------------ 16 | * Support for setting config vars in master config (local ones won't be used then) 17 | 18 | 1.1.2 - 2014-03-27 19 | ------------------ 20 | * Support for prefixing snippets / global variables (have a look in the config file) 21 | 22 | 1.1.1 - 2014-01-03 23 | ------------------ 24 | * Fixed db issue with site_id being required 25 | 26 | 1.1 - 2013-12-09 27 | ------------------ 28 | * Moved libraries into snippetssync folder + use developer log for errors instead of show_error 29 | 30 | 1.0.7 - 2013-05-20 31 | ------------------ 32 | * Modified add-on folder structure for DevDemon Updater compatibility 33 | 34 | 1.0.6 - 2013-04-15 35 | ------------------ 36 | * Fixed bug where global variables were not allowed to be saved w/.html extension 37 | 38 | 1.0.5 - 2013-01-29 39 | ------------------ 40 | * SnippetsSync will now ignore invalid filenames instead of converting them to valid global variable/snipppet names. A manual sync in the CP will list the files that are ignored. 41 | * Added changelog.txt 42 | -------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/config/snippetssync.php: -------------------------------------------------------------------------------- 1 | modules -> snippetssync you can click to do a manual sync. 7 | */ 8 | $config['snippetssync_production_mode'] = FALSE; 9 | $config['snippetssync_snippet_prefix'] = ''; // for example: 'sn_' 10 | $config['snippetssync_global_variable_prefix'] = ''; // for example: 'gv_' 11 | $config['snippetssync_sync_var'] = 'CHANGEME'; // any random string to pass through on a URL sync 12 | 13 | // NOTE: if you set these variables in your master config those will be used instead of these :-) -------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/ext.snippetssync.php: -------------------------------------------------------------------------------- 1 | 'on_sessions_start', 28 | ); 29 | 30 | /** 31 | * Constructor 32 | * 33 | * @paramarray of settings 34 | */ 35 | public function __construct($settings='') 36 | { 37 | parent::__construct($settings); 38 | } 39 | 40 | public function activate_extension() 41 | { 42 | $this->EE->load->library('snippetslib'); 43 | if(!$this->EE->snippetslib->verify_settings()) 44 | { 45 | show_error($this->EE->snippetslib->error_message.". Please fix this before enabling the extension."); 46 | } 47 | else 48 | { 49 | parent::activate_extension(); 50 | } 51 | } 52 | 53 | // 54 | // HOOKS GO HERE 55 | // 56 | 57 | public function on_sessions_start($ref) 58 | { 59 | // load local config if none of these values aren't already specified in a master config 60 | if(!isset($this->EE->config->config['snippetssync_production_mode']) 61 | && !isset($this->EE->config->config['snippetssync_snippet_prefix']) 62 | && !isset($this->EE->config->config['snippetssync_global_variable_prefix'])) { 63 | $this->EE->load->config('snippetssync'); 64 | } 65 | 66 | // snippetssync_production_mode_override for backwards compatibility 67 | if(!$this->EE->config->item('snippetssync_production_mode_override') && !$this->EE->config->item('snippetssync_production_mode')) 68 | { 69 | $this->EE->load->library('snippetslib'); 70 | $success = $this->EE->snippetslib->sync_all(); 71 | } 72 | } 73 | 74 | } 75 | 76 | /* End of file ext.extended_ee.php */ 77 | /* Location: ./system/expressionengine/third_party/extended_ee/ext.extended_ee.php */ 78 | -------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/language/english/snippetssync_lang.php: -------------------------------------------------------------------------------- 1 | EE =& $this->get_ee_instance(); 20 | $this->EE->load->add_package_path(PATH_THIRD); // add common lib folder to package path 21 | } 22 | 23 | /** 24 | * @return Devkit_code_completion 25 | */ 26 | private function get_ee_instance() 27 | { 28 | return get_instance(); 29 | } 30 | } -------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/libraries/ab/ab_extbase.php: -------------------------------------------------------------------------------- 1 | methods to register 13 | 14 | public function __construct($settings='') 15 | { 16 | parent::__construct(); // run constructor which will handle get_instance() etc. 17 | $this->settings = $settings; 18 | } 19 | 20 | /** 21 | * Activate the extension 22 | * 23 | * This funciton is run on install and will register all hooks and 24 | * add custom member fields. 25 | * 26 | */ 27 | public function activate_extension() 28 | { 29 | // ------------------------------------------------- 30 | // Register the hooks needed for this extension 31 | // ------------------------------------------------- 32 | 33 | $class_name = get_class($this); 34 | foreach($this->register_hooks as $hook => $method) 35 | { 36 | $data = array( 37 | 'class' => $class_name, 38 | 'method' => $method, 39 | 'hook' => $hook, 40 | 'settings' => "", 41 | 'priority' => 10, 42 | 'version' => $this->version, 43 | 'enabled' => "y" 44 | ); 45 | $this->EE->db->insert('extensions', $data); 46 | } 47 | } 48 | 49 | /** 50 | * Update the extension 51 | * 52 | * @param $current current version number 53 | * @return boolean indicating whether or not the extension was updated 54 | */ 55 | public function update_extension($current='') 56 | { 57 | if ($current == '' OR $current == $this->version) 58 | { 59 | return FALSE; 60 | } 61 | 62 | return FALSE; 63 | // update code if version differs here 64 | } 65 | 66 | /** 67 | * Settings 68 | */ 69 | public function settings() 70 | { 71 | 72 | } 73 | 74 | /** 75 | * Disable the extention 76 | * 77 | * @return unknown_type 78 | */ 79 | public function disable_extension() 80 | { 81 | $this->EE->db->delete('extensions', array('class'=>get_class($this))); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/libraries/ab/ab_libbase.php: -------------------------------------------------------------------------------- 1 | method_access[$internal_method_name])) 30 | { 31 | $this->EE->output->show_user_error('submission', array('no_access')); // not defined in access array, throw no access error 32 | } 33 | 34 | $role_needed = $this->method_access[$internal_method_name]; 35 | $member_id = $this->EE->session->userdata('member_id'); 36 | $access_allowed = FALSE; 37 | switch($role_needed) 38 | { 39 | case Ab_LibBase::LOGGED_IN_USER: 40 | $access_allowed = ($member_id > 0); 41 | break; 42 | case Ab_LibBase::ANYONE_NO_XID_CHECK: 43 | case Ab_LibBase::ANYONE: 44 | $access_allowed = TRUE; 45 | break; 46 | } 47 | 48 | if(!$access_allowed) 49 | { 50 | $this->EE->output->show_user_error('submission', array('no_access')); 51 | } 52 | 53 | // @todo looks like EE is already checking the XID now - but then ANYONE_NO_XID_CHECK won't work anymore. Fix. 54 | 55 | // XID check - we use EE's new security lib for this now 56 | /*if($role_needed != Ab_LibBase::ANYONE_NO_XID_CHECK && $this->EE->security->check_xid($this->EE->input->post('XID')) == FALSE) 57 | { 58 | $this->EE->output->show_user_error('submission', array(lang('timed_out'))); 59 | }*/ 60 | 61 | // if we get this far we're allowed to call the function at least 62 | $this->$internal_method_name($arguments); 63 | } 64 | else 65 | { 66 | show_error('No such method', 'That action does not seem to exist'); 67 | } 68 | } 69 | 70 | 71 | } -------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/libraries/ab/ab_mcpbase.php: -------------------------------------------------------------------------------- 1 | EE->session->set_flashdata($message_type, $message); 30 | $this->EE->functions->redirect($url); 31 | } 32 | } -------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/libraries/ab/ab_modbase.php: -------------------------------------------------------------------------------- 1 | EE->TMPL->fetch_param($key); 24 | if(!$val) 25 | { 26 | $val = $this->EE->TMPL->fetch_param($backup_key); 27 | } 28 | 29 | if(!$val) { 30 | return $default_value; 31 | } 32 | return $val; 33 | } 34 | 35 | /** 36 | * Will parse a boolean if {if statement} 37 | * 38 | * @param $cond_name the conditional name, e.g. in {if has_completed} this would be 'has_completed' 39 | * @param $cond_value boolean value (TRUE/FALSE) 40 | * @param $tagdata the tagdata to work with 41 | * @returns new tagdata with if parsed ready for the EE Template Engine 42 | */ 43 | function parse_if($cond_name, $cond_value, $tagdata) 44 | { 45 | if($cond_value) 46 | { 47 | $cond_value = 'TRUE'; 48 | } 49 | else 50 | { 51 | $cond_value = 'FALSE'; 52 | } 53 | return preg_replace("/\{if\s+".$cond_name."\}/si", "{if $cond_value}", $tagdata); 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/libraries/ab/ab_updbase.php: -------------------------------------------------------------------------------- 1 | tmpl_basepath = $this->EE->config->slash_item('tmpl_file_basepath') . $this->EE->config->slash_item('site_short_name'); 36 | $this->sn_path = $this->tmpl_basepath . ( $this->EE->config->slash_item('snippetssync_sn_folder') ? $this->EE->config->slash_item('snippetssync_sn_folder') : "snippets/" ); 37 | $this->gv_path = $this->tmpl_basepath . ( $this->EE->config->slash_item('snippetssync_gv_folder') ? $this->EE->config->slash_item('snippetssync_gv_folder') : "global_variables/" ); 38 | } 39 | 40 | private function log_error($msg) 41 | { 42 | $this->EE->load->library('logger'); 43 | $this->EE->logger->developer('SnippetsSync: '.$msg, TRUE); 44 | } 45 | 46 | public function verify_settings() 47 | { 48 | 49 | if(!($this->tmpl_basepath != $this->EE->config->slash_item('site_short_name') && file_exists($this->tmpl_basepath))) 50 | { 51 | $this->error_message = 'Template basepath not defined - or not found ('.$this->tmpl_basepath.')'; 52 | return FALSE; 53 | } 54 | 55 | // check that parent dir is writeable. 56 | if ( substr(sprintf('%o', fileperms( $this->tmpl_basepath )) , -4) < DIR_WRITE_MODE ) 57 | { 58 | ( "Your template directory (".$this->tmpl_basepath.") needs to be writable." ); 59 | } 60 | 61 | // check if the global_vars and snippets dirs exists, else create them now. 62 | // check global vars dir 63 | if ( !file_exists($this->gv_path) ) 64 | { 65 | @mkdir( $this->gv_path ); 66 | } 67 | if ( !$this->mk_perms( $this->gv_path ) ) 68 | { 69 | $this->log_error( "Could not make the global variables directory writeable." ); 70 | } 71 | 72 | // check snippets dir 73 | if ( !file_exists($this->sn_path) ) 74 | { 75 | @mkdir( $this->sn_path ); 76 | } 77 | if ( !$this->mk_perms( $this->sn_path ) ) 78 | { 79 | $this->log_error( "Could not make the snippets directory writeable." ); 80 | } 81 | 82 | //check for prefixes set on EECMS config.php 83 | if ( is_string($this->EE->config->item('snippetssync_snippet_prefix')) ) 84 | { 85 | $this->sn_prefix = $this->EE->config->item('snippetssync_snippet_prefix'); 86 | } 87 | if ( is_string($this->EE->config->item('snippetssync_global_variable_prefix')) ) 88 | { 89 | $this->gv_prefix = $this->EE->config->item('snippetssync_global_variable_prefix'); 90 | } 91 | 92 | return TRUE; // everything OK 93 | } 94 | 95 | public function sync_all() 96 | { 97 | $this->last_sync_log['globals'] = array(); 98 | $this->last_sync_log['snippets'] = array(); 99 | $this->last_sync_log['ignored'] = array(); 100 | 101 | if($this->verify_settings()) 102 | { 103 | 104 | $global_variables = $this->get_files($this->gv_path); 105 | $snippets = $this->get_files($this->sn_path); 106 | 107 | // regex arrays, used to create valid snippet and global variable names. 108 | $search = array( 109 | "/\..*$/ui", //strips extension. 110 | ); 111 | $replace= array( 112 | "", // replace extension with nothing 113 | ); 114 | 115 | foreach($global_variables as $global_variable_filename) 116 | { 117 | $global_variable_name = $this->gv_prefix.preg_replace( $search , $replace , $global_variable_filename ); 118 | 119 | if($this->is_legal_global_var_name($global_variable_name)) { 120 | $this->EE->db->where('variable_name', $global_variable_name); 121 | $this->EE->db->from('global_variables'); 122 | 123 | $global_variable_data = file_get_contents($this->gv_path.$global_variable_filename); 124 | 125 | if($this->EE->db->count_all_results() == 0) 126 | { 127 | $this->EE->db->insert('global_variables', array( 128 | 'site_id' => $this->EE->config->item('site_id'), 129 | 'variable_name' => $global_variable_name, 130 | 'variable_data' => $global_variable_data, 131 | )); 132 | } 133 | else 134 | { 135 | $this->EE->db->where('variable_name', $global_variable_name); 136 | $this->EE->db->update('global_variables', array('variable_data' => $global_variable_data)); 137 | } 138 | 139 | $this->last_sync_log['globals'][] = $global_variable_name; 140 | } else { 141 | $this->last_sync_log['ignored'][] = '/global_variables/'.$global_variable_filename; 142 | } 143 | } 144 | 145 | foreach($snippets as $snippet_filename) 146 | { 147 | $snippet_name = $this->sn_prefix.preg_replace( $search , $replace , $snippet_filename ); 148 | 149 | if($this->is_legal_global_var_name($snippet_name)) { 150 | $this->EE->db->where('snippet_name', $snippet_name); 151 | $this->EE->db->from('snippets'); 152 | $snippet_data = file_get_contents($this->sn_path.$snippet_filename); 153 | 154 | if($this->EE->db->count_all_results() == 0) 155 | { 156 | $this->EE->db->insert('snippets', array( 157 | 'site_id' => $this->EE->config->item('site_id'), 158 | 'snippet_name' => $snippet_name, 159 | 'snippet_contents' => $snippet_data, 160 | )); 161 | 162 | } 163 | else 164 | { 165 | $this->EE->db->where('snippet_name', $snippet_name); 166 | $this->EE->db->update('snippets', array('snippet_contents' => $snippet_data)); 167 | } 168 | 169 | $this->last_sync_log['snippets'][] = $snippet_name; 170 | 171 | } else { 172 | $this->last_sync_log['ignored'][] = '/snippets/'.$snippet_filename; 173 | } 174 | 175 | } 176 | 177 | return TRUE; 178 | } 179 | else 180 | { 181 | return FALSE; 182 | } 183 | } 184 | 185 | /** 186 | * Check if a string is a legal global var name 187 | * 188 | * @param $str 189 | */ 190 | private function is_legal_global_var_name($str) 191 | { 192 | if($str == '') { 193 | return FALSE; 194 | } 195 | return (preg_match("#^[a-zA-Z0-9_\-/]+$#i", $str)); 196 | } 197 | 198 | 199 | /** 200 | * Get dirs/files from a source_dir 201 | * 202 | * @param $source_dir 203 | */ 204 | private function get_files($source_dir) 205 | { 206 | $files = array(); 207 | 208 | $fp = @opendir($source_dir); 209 | 210 | if ($fp) 211 | { 212 | while (FALSE !== ($file = readdir($fp))) 213 | { 214 | if (is_file($source_dir.$file)) 215 | { 216 | if (strpos($file, '.') !== 0) { 217 | $files[] = $file; 218 | } 219 | } 220 | } 221 | closedir($fp); 222 | } 223 | else 224 | { 225 | $this->log_error("Could not open dir: " . $source_dir); 226 | } 227 | 228 | return $files; 229 | } 230 | 231 | /** 232 | * Check permissions of dir/file for desired permissions. 233 | * If perms differ then set dir/file to desired perms. 234 | * 235 | * @param $dir 236 | * @param $perms (default: 0777) 237 | */ 238 | private function mk_perms( $dir , $perms = DIR_WRITE_MODE ) 239 | { 240 | clearstatcache(); 241 | 242 | if ( is_dir($dir) && octdec(substr(sprintf('%o', @fileperms( $dir )), -4)) < $perms ) 243 | { 244 | if( @chmod( $dir , $perms ) ) 245 | { 246 | return TRUE; 247 | } 248 | else 249 | { 250 | return FALSE; 251 | } 252 | } 253 | 254 | return TRUE; 255 | } 256 | 257 | } 258 | -------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/mcp.snippetssync.php: -------------------------------------------------------------------------------- 1 | EE =& get_instance(); 25 | $this->base = BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module='.$this->module_name; 26 | $this->form_base = 'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module='.$this->module_name; 27 | 28 | // load local config if none of these values aren't already specified in a master config 29 | if(!isset($this->EE->config->config['snippetssync_production_mode']) 30 | && !isset($this->EE->config->config['snippetssync_snippet_prefix']) 31 | && !isset($this->EE->config->config['snippetssync_global_variable_prefix'])) { 32 | $this->EE->load->config('snippetssync'); 33 | } 34 | } 35 | 36 | public function index() 37 | { 38 | $snippetssync_sync_var = $this->EE->config->item('snippetssync_sync_var'); 39 | 40 | // snippetssync_production_mode_override for backwards compatibility 41 | $vars = array( 42 | 'production_mode' => $this->EE->config->item('snippetssync_production_mode_override') || $this->EE->config->item('snippetssync_production_mode'), 43 | 'sync_var' => $snippetssync_sync_var, 44 | 'sync_url' => $this->EE->functions->fetch_site_index(0, 0).QUERY_MARKER.'ACT='.$this->EE->cp->fetch_action_id($this->module_name, 'url_sync').'&sync='.$snippetssync_sync_var, 45 | ); 46 | return $this->content_wrapper('index', 'snippetssync_welcome', $vars); 47 | } 48 | 49 | public function manual_sync() 50 | { 51 | $this->EE->load->library('snippetslib'); 52 | $success = $this->EE->snippetslib->sync_all(); 53 | $global_variables = $this->EE->snippetslib->last_sync_log['globals']; 54 | $snippets = $this->EE->snippetslib->last_sync_log['snippets']; 55 | 56 | if (version_compare(APP_VER, '2.6', '>=')) { 57 | $sync_time = $this->EE->localize->human_time(NULL, TRUE, TRUE); 58 | } else { 59 | $sync_time = $this->EE->localize->set_human_time('', TRUE, TRUE); // #eecms - the cms where get functions are prefixed with set! :-p 60 | } 61 | 62 | $vars = array( 63 | 'success' => $success, 64 | 'error_message' => $this->EE->snippetslib->error_message, 65 | 'sync_time' => $sync_time, 66 | 'global_variables' => $global_variables, 67 | 'snippets' => $snippets, 68 | 'global_variables_count' => count($global_variables), 69 | 'snippets_count' => count($snippets), 70 | 'ignored_count' => isset($this->EE->snippetslib->last_sync_log['ignored']) ? count($this->EE->snippetslib->last_sync_log['ignored']) : 0, 71 | 'ignored' => isset($this->EE->snippetslib->last_sync_log['ignored']) ? $this->EE->snippetslib->last_sync_log['ignored'] : FALSE, 72 | ); 73 | 74 | return $this->content_wrapper('synced', 'snippetssync_synced', $vars); 75 | } 76 | 77 | public function content_wrapper($content_view, $lang_key, $vars = array()) 78 | { 79 | $vars['content_view'] = $content_view; 80 | $vars['_base'] = $this->base; 81 | $vars['_form_base'] = $this->form_base; 82 | 83 | // $this->EE->cp->set_variable was deprecated in 2.6 84 | if (version_compare(APP_VER, '2.6', '>=')) { 85 | $this->EE->view->cp_page_title = lang($lang_key); 86 | } else { 87 | $this->EE->cp->set_variable('cp_page_title', lang($lang_key)); 88 | } 89 | 90 | $this->EE->cp->set_breadcrumb($this->base, lang('snippetssync_module_name')); 91 | 92 | return $this->EE->load->view('_wrapper', $vars, TRUE); 93 | } 94 | } 95 | 96 | /* End of file mcp.snippetssync.php */ 97 | /* Location: ./system/expressionengine/third_party/snippetssync/mcp.snippetssync.php */ 98 | /* Generated by DevKit for EE - develop addons faster! */ -------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/mod.snippetssync.php: -------------------------------------------------------------------------------- 1 | EE =& get_instance(); 22 | } 23 | 24 | public function url_sync() 25 | { 26 | 27 | $output = ''; 28 | $ajax_output= []; 29 | 30 | $ajax = FALSE; 31 | if( !empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest') $ajax = TRUE; 32 | 33 | // Check for unique var in URL, error if not present 34 | // Check if matches config, error if not 35 | $snippetssync_sync_var = $this->EE->config->item('snippetssync_sync_var'); 36 | $sync_var = $this->EE->input->get('sync', TRUE); 37 | 38 | if (!$sync_var || $sync_var == '' || $sync_var == 'CHANGEME' || $sync_var != $snippetssync_sync_var) 39 | { 40 | if ($ajax) 41 | { 42 | $ajax_output['success'] = FALSE; 43 | $ajax_output['error'] = 'URL incorrect, check the config folder in '.$this->module_name.'.'; 44 | echo json_encode($ajax_output); 45 | exit; 46 | } 47 | else 48 | { 49 | $this->EE->output->show_user_error('submission', 'Check the config folder in '.$this->module_name.'.', 'Unique URL error'); 50 | } 51 | } 52 | else 53 | { 54 | // run sync 55 | $this->EE->load->library('snippetslib'); 56 | $success = $this->EE->snippetslib->sync_all(); 57 | 58 | if(!$success) 59 | { 60 | if ($ajax) 61 | { 62 | $ajax_output['success'] = FALSE; 63 | $ajax_output['error'] = 'Sync failed: ' . $this->EE->snippetslib->error_message; 64 | echo json_encode($ajax_output); 65 | exit; 66 | } 67 | else 68 | { 69 | $this->EE->output->show_user_error('submission', 'Sync failed: ' . $this->EE->snippetslib->error_message, 'Sync error'); 70 | } 71 | } 72 | else 73 | { 74 | if ($ajax) 75 | { 76 | $ajax_output['success'] = TRUE; 77 | echo json_encode($ajax_output); 78 | exit; 79 | } 80 | else 81 | { 82 | $this->EE->output->show_message( 83 | array( 84 | 'title' => $this->module_name, 85 | 'heading' => 'Snippets Sync via URL', 86 | 'content' => 'Success' 87 | ) 88 | ); 89 | } 90 | } 91 | } 92 | 93 | return $output; 94 | } 95 | 96 | } 97 | /* End of file mod.snippetssync.php */ 98 | /* Location: ./system/expressionengine/third_party/download/mod.snippetssync.php */ -------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/upd.snippetssync.php: -------------------------------------------------------------------------------- 1 | EE =& get_instance(); 23 | } 24 | 25 | /** 26 | * Installer for the Snippetssync module 27 | */ 28 | function install() 29 | { 30 | 31 | $data = array( 32 | 'module_name' => $this->module_name, 33 | 'module_version' => $this->version, 34 | 'has_cp_backend' => 'y' 35 | ); 36 | 37 | $this->EE->db->insert('modules', $data); 38 | 39 | $this->EE->db->insert('actions', array( 40 | 'class' => $this->module_name, 41 | 'method' => 'url_sync' 42 | )); 43 | 44 | return TRUE; 45 | } 46 | 47 | 48 | /** 49 | * Uninstall the Snippetssync module 50 | */ 51 | function uninstall() 52 | { 53 | 54 | $this->EE->db->select('module_id'); 55 | $query = $this->EE->db->get_where('modules', array('module_name' => $this->module_name)); 56 | 57 | $this->EE->db->where('module_id', $query->row('module_id')); 58 | $this->EE->db->delete('module_member_groups'); 59 | 60 | $this->EE->db->where('module_name', $this->module_name); 61 | $this->EE->db->delete('modules'); 62 | 63 | $this->EE->db->where('class', $this->module_name); 64 | $this->EE->db->delete('actions'); 65 | 66 | $this->EE->db->where('class', $this->module_name.'_mcp'); 67 | $this->EE->db->delete('actions'); 68 | 69 | return TRUE; 70 | } 71 | 72 | /** 73 | * Update the Snippetssync module 74 | * 75 | * @param $current current version number 76 | * @return boolean indicating whether or not the module was updated 77 | */ 78 | 79 | function update($current = '') 80 | { 81 | if ($current < '1.0.8') { 82 | $this->EE->db->delete('extensions', array('class' => 'Snippetssync_ext', 'method' => 'on_cp_js_end')); 83 | } 84 | 85 | if ($current < '1.2') 86 | { 87 | $this->EE->db->insert('actions', array( 88 | 'class' => $this->module_name, 89 | 'method' => 'url_sync' 90 | )); 91 | } 92 | 93 | return TRUE; 94 | } 95 | 96 | /** @return Devkit_code_completion_helper */ function EE() {if(!isset($this->EE)){$this->EE =& get_instance();}return $this->EE;} 97 | } 98 | 99 | /* End of file upd.snippetssync.php */ 100 | /* Location: ./system/expressionengine/third_party/snippetssync/upd.snippetssync.php */ 101 | /* Generated by DevKit for EE - develop addons faster! */ 102 | -------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/views/_wrapper.php: -------------------------------------------------------------------------------- 1 |
2 | load->view($content_view)?> 3 |
-------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/views/index.php: -------------------------------------------------------------------------------- 1 |

2 | 5 | SnippetsSync is currently in production mode. Snippets are only synced when you click the button below. 6 | 10 | SnippetsSync is in development mode. Snippets are always synced. 11 | 14 | To switch between dev/production mode, edit config/snippetssync.php 15 |

16 |
17 |

18 | 19 | 20 | 21 |

22 | 23 |

Sync via URL

24 | 25 |

Unique URL when sync’ing over HTTP.

26 |

This can be used as a post-deploy hook to sync snippets on a production server.

27 | 28 | 29 | 30 |

Please change ‘snippetssync_sync_var’ in config/snippetssync.php to generate a unique URL.

31 | 32 | 33 | 34 |

35 | 43 |

44 | 45 | -------------------------------------------------------------------------------- /system/expressionengine/third_party/snippetssync/views/synced.php: -------------------------------------------------------------------------------- 1 | 5 |

Error

6 |

7 | 0) 12 | { 13 | ?> 14 |

Global Variables Synced

15 | 16 | 17 | 21 | 22 | 25 |
26 | 0) 30 | { 31 | ?> 32 |

Snippets Synced

33 |

43 | 0) { 48 | ?> 49 |

Files Ignored

50 |

These files were ignored because their filename is not a legal snippet/global variable name (may only contain alpha-numeric characters, underscores, and dashes)

51 |

62 | 65 |
66 | 67 |

Last synced at:

68 | 69 |

70 | 71 | 72 | 73 |

74 | 75 | --------------------------------------------------------------------------------