Advertisement
nlozovan

Untitled

Mar 7th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.79 KB | None | 0 0
  1. <?php
  2. define('_LIMIT_' , 10 );
  3. define('BLOCK_TITLE_LEN' , 50 );
  4.  
  5. define('DEFAULT_AVATAR' , get_template_directory_uri()."/images/default_avatar.jpg" );
  6. define('DEFAULT_AVATAR_100' , get_template_directory_uri()."/images/default_avatar_100.jpg" );
  7. define('DEFAULT_AVATAR_LOGIN' , get_template_directory_uri()."/images/default_avatar_login.png" );
  8. define( '_TN_' , wp_get_theme() );
  9. define('BRAND' , '' );
  10. define('ZIP_NAME' , 'prikoke' );
  11.  
  12. $content_width = 600;
  13.  
  14. add_action('admin_bar_menu', 'de_cosmotheme');
  15.  
  16. get_template_part('/lib/php/aq_resizer');
  17. include 'lib/php/main.php';
  18. include 'lib/php/localize-js.php';
  19.  
  20.  
  21. include 'lib/php/actions.register.php';
  22. include 'lib/php/menu.register.php';
  23.  
  24. if( function_exists( 'add_theme_support' ) ){
  25. add_theme_support( 'automatic-feed-links' );
  26. add_theme_support( 'post-thumbnails' );
  27. }
  28.  
  29. //image::add_size();
  30.  
  31. add_theme_support( 'custom-background' ); /*requires WP v >= 3.4 */
  32.  
  33. add_theme_support( 'post-formats' , array( 'image' , 'video' , 'audio','gallery', 'quote' ) );
  34. add_editor_style('editor-style.css');
  35.  
  36.  
  37.  
  38. /* Localization */
  39. load_theme_textdomain( 'cosmotheme' );
  40. load_theme_textdomain( 'cosmotheme' , get_template_directory() . '/languages' );
  41.  
  42. if ( function_exists( 'load_child_theme_textdomain' ) ){
  43. load_child_theme_textdomain( 'cosmotheme' );
  44. }
  45.  
  46.  
  47. if(is_admin() && ini_get('allow_url_fopen') == '1'){
  48.  
  49. /*Cosmo news*/
  50. if( options::logic( 'cosmothemes' , 'show_cosmo_news' ) && !isset($_GET['post_id']) && !isset($_GET['post'])){
  51. function doCosmoNews(){
  52. echo api_call::getCosmoNews();
  53. }
  54.  
  55. // Add hook for admin <head></head>
  56. add_action('admin_head', 'doCosmoNews');
  57. }
  58. }
  59.  
  60. /* Cosmothemes Backend link */
  61. function de_cosmotheme() {
  62. global $wp_admin_bar;
  63. if ( !is_super_admin() || !is_admin_bar_showing() ){
  64. return;
  65. }
  66. $wp_admin_bar -> add_menu( array(
  67. 'id' => 'cosmothemes',
  68. 'parent' => '',
  69. 'title' => _TN_,
  70. 'href' => admin_url( 'admin.php?page=cosmothemes__general' )
  71. ) );
  72. }
  73.  
  74. add_filter('excerpt_length', 'cosmo_excerpt_length');
  75. function cosmo_excerpt_length($length) {
  76. return 70; /* Or whatever you want the length to be. */
  77. }
  78.  
  79. if( !options::logic( 'general' , 'show_admin_bar' ) ){
  80. add_filter( 'show_admin_bar', '__return_false' );
  81. }
  82.  
  83. /*Default pages creation*/
  84. //delete_option('first-install-settings-'.ZIP_NAME);
  85. if(!get_option( 'first-install-settings-'.ZIP_NAME ) ){
  86.  
  87.  
  88. include get_template_directory() . '/lib/templates/init_templates.php';
  89.  
  90. //create wishlist page
  91. $default_custom_pages = array('Wishlist', 'New products', 'Products', 'Portfolios', 'Blog with grid-view', 'Blog with large thumbs list-view');
  92.  
  93. /*create wishlist and new products pages only ones */
  94. foreach($default_custom_pages as $page){
  95. $default_page = get_page_by_title( $page );
  96. if( !($default_page && isset($default_page->ID)) ){
  97. $pages = array(
  98. 'post_status' => 'publish',
  99. 'post_type' => 'page',
  100. 'post_author' => 1,
  101. 'post_name' => $page,
  102. 'post_title' => $page,
  103. 'post_content' => '',
  104. 'comment_status' => 'closed'
  105. );
  106. $def_page = wp_insert_post($pages);
  107.  
  108. if( is_numeric($def_page) && $def_page > 0){
  109. //assign page template (for example for 'My bookmarks' page -> 'my_bookmarks.php' template will be assigned)
  110. update_post_meta($def_page, '_wp_page_template', str_replace(' ','-', strtolower($page)).'.php');
  111. }
  112.  
  113. if('Products' == $page){ // for products page we want to assing a different template
  114. assign_template_to_post( $def_page, 'products_list123' );
  115. }
  116. if('Portfolios' == $page){ // for blog page we want to assing a different template
  117. assign_template_to_post( $def_page, 'portfolios123' );
  118. }
  119. if('Blog with grid-view' == $page){ // for blog page we want to assing a different template
  120. assign_template_to_post( $def_page, 'blog_grid123' );
  121. }
  122. if('Blog with large thumbs list-view' == $page){ // for blog page we want to assing a different template
  123. assign_template_to_post( $def_page, 'blog_list_large_thumb123' );
  124. }
  125.  
  126. }
  127. }
  128.  
  129. add_option( 'first-install-settings-'.ZIP_NAME, 'pages created' );
  130. }
  131.  
  132. add_editor_style('editor-style.css');
  133.  
  134. /*exclude wishlist page from search result*/
  135. function filter_where($where = '') {
  136. if ( is_search() ) {
  137.  
  138. $def_pages = array(options::get_value( 'blog_post' , 'wish_page' )
  139. );
  140. $ids = array();
  141. foreach($def_pages as $pag){
  142.  
  143. if( is_numeric($pag) ){
  144. $ids[] = $pag;
  145. }
  146. }
  147. $exclude = $ids;
  148.  
  149. for($x=0;$x<count($exclude);$x++){
  150. $where .= " AND ID != ".$exclude[$x];
  151. }
  152. }
  153. return $where;
  154. }
  155. add_filter('posts_where', 'filter_where');
  156.  
  157.  
  158. function cosmo_load_css() {
  159.  
  160. wp_register_style( 'default_stylesheet',get_stylesheet_directory_uri() . '/style.css' );
  161. wp_enqueue_style( 'default_stylesheet' );
  162.  
  163. $files = scandir( get_template_directory()."/css/autoinclude" );
  164. foreach( $files as $file ){
  165. if( is_file( get_template_directory()."/css/autoinclude/$file" ) ){
  166. wp_register_style( $file.'-style',get_template_directory_uri() . '/css/autoinclude/'.$file );
  167. wp_enqueue_style( $file.'-style' );
  168. }
  169. }
  170.  
  171. if(get_option( 'woocommerce_frontend_css' ) != 'yes'){
  172. wp_register_style( 'woostyles',get_template_directory_uri() . '/css/wooshop.css' );
  173. wp_enqueue_style( 'woostyles' );
  174. }
  175.  
  176.  
  177. if(options::logic( 'blog_post' , 'enb_lightbox' )){
  178. wp_register_style( 'prettyPhoto',get_template_directory_uri() . '/css/prettyPhoto.css' );
  179. wp_enqueue_style( 'prettyPhoto' );
  180. }
  181.  
  182.  
  183.  
  184.  
  185. wp_enqueue_script( 'flexslider' , get_template_directory_uri() . '/js/jquery.flexslider-min.js' , array( 'jquery' ),false,true );
  186. wp_enqueue_script( 'pageslide' , get_template_directory_uri() . '/js/jquery.pageslide.min.js' , array( 'jquery' ),false,true ); /*for showing/hide mobile menu*/
  187. wp_enqueue_script( 'hoverintent' , get_template_directory_uri() . '/js/jquery.hoverIntent.js' , array( 'jquery' , 'functions' ),false,true );
  188. wp_enqueue_script( 'superfish' , get_template_directory_uri() . '/js/jquery.superfish.js' , array( 'jquery' ),false,true );
  189. wp_enqueue_script( 'supersubs' , get_template_directory_uri() . '/js/jquery.supersubs.js' , array( 'jquery' ),false,true );
  190. wp_enqueue_script( 'tour' , get_template_directory_uri() . '/js/tour.js' , array( 'jquery' ),false,true );
  191. wp_enqueue_script( 'tabs' , get_template_directory_uri() . '/js/jquery.tabs.pack.js' , array( 'jquery' ),false,true );
  192. wp_enqueue_script( 'scrollto' , get_template_directory_uri() . '/js/jquery.scrollTo-1.4.2-min.js' , array( 'jquery' ),false,true );
  193. wp_enqueue_script( 'masonry' , get_template_directory_uri() . '/js/jquery.isotope.min.js' , array( 'jquery' ),false,true );
  194. wp_enqueue_script( 'chosen' , get_template_directory_uri() . '/js/chosen.jquery.min.js' , array( 'jquery' ),false,true );
  195. wp_enqueue_script( 'functions' , get_template_directory_uri() . '/js/functions.js' , array( 'jquery' , 'tabs' , 'scrollto' ),false,true );
  196. wp_enqueue_script( 'jquery-cookie' , get_template_directory_uri() . '/js/jquery.cookie.js' , array( 'jquery' ),false,true );
  197.  
  198. global $enb_lightbox;
  199. if(options::logic( 'blog_post' , 'enb_lightbox' )){
  200. $enb_lightbox = true;
  201. wp_enqueue_script( 'prettyPhoto' , get_template_directory_uri() . '/js/jquery.prettyPhoto.js' , array( 'jquery' ),false,true );
  202. } else { $enb_lightbox = false; }
  203. wp_localize_script( 'functions', 'prettyPhoto_enb', array(
  204. 'enb_lightbox' => $enb_lightbox
  205. )
  206. );
  207.  
  208. if(options::logic( 'blog_post' , 'set_fixed_meta' )){
  209. $set_fixed_meta = true;
  210. } else {
  211. $set_fixed_meta = false;
  212. }
  213. wp_localize_script( 'functions', 'fixedMeta_set', array(
  214. 'set_fixed_meta' => $set_fixed_meta
  215. )
  216. );
  217.  
  218. $logo_font_family = explode('&',options::get_value('styling' , 'logo_font_family'));
  219. $logo_font_family = $logo_font_family[0];
  220. $logo_font_family = str_replace( '+',' ',$logo_font_family );
  221.  
  222. wp_localize_script( 'functions', 'logo_font', $logo_font_family);
  223.  
  224.  
  225. /*call this only on front page*/
  226. wp_enqueue_script( 'easing' , get_template_directory_uri() . '/js/jquery.easing.js' , array( 'jquery' ),false,true );
  227. wp_enqueue_script( 'jscroll' , get_template_directory_uri() . '/js/jquery.jscroll.js' , array( 'jquery' ),false,true );
  228. wp_enqueue_script( 'waitforimages' , get_template_directory_uri() . '/js/jquery.waitforimages.js' , array( 'jquery' ),false,true );
  229.  
  230. if ( is_singular() ){
  231. wp_enqueue_script( "comment-reply" );
  232. }
  233.  
  234. // embed the javascript file that makes the AJAX request
  235. wp_register_script( 'actions', get_template_directory_uri().'/lib/js/actions.js' , array('jquery') );
  236.  
  237. wp_enqueue_script( 'actions' );
  238.  
  239. if(is_page() ) {
  240. wp_enqueue_script('media-upload');
  241. wp_enqueue_script('thickbox');
  242.  
  243. wp_enqueue_style( 'ui-lightness');
  244. wp_enqueue_style('thickbox');
  245. }
  246.  
  247. global $wp_query;
  248. wp_localize_script( 'actions', 'MyAjax', array(
  249. // URL to wp-admin/admin-ajax.php to process the request
  250. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  251. 'wpargs' => array( 'wpargs' => $wp_query -> query ),
  252.  
  253. // generate a nonce with a unique ID "myajax-post-comment-nonce"
  254. // so that you can check it later when an AJAX request is sent
  255. 'getMoreNonce' => wp_create_nonce( 'myajax-getMore-nonce' ),
  256. )
  257. );
  258.  
  259. /* demo auto login for users*/
  260. if( defined('IS_FOR_DEMO') && !is_user_logged_in() ){
  261. $creds = array();
  262. $creds['user_login'] = 'demo';
  263. $creds['user_password'] = 'demo';
  264. $creds['remember'] = true;
  265. $user = wp_signon( $creds, false );
  266. if ( is_wp_error($user) )
  267. echo $user->get_error_message();
  268. }
  269.  
  270. wp_localize_script( 'login', 'MyAjax', array(
  271. // URL to wp-admin/admin-ajax.php to process the request
  272. 'ajaxurl' => admin_url( 'admin-ajax.php' )
  273. )
  274. );
  275.  
  276. /*deregister shosen scripts from WC, we are using ours*/
  277. wp_deregister_style( 'woocommerce_chosen_styles' );
  278. }
  279.  
  280. add_action('wp_enqueue_scripts', 'cosmo_load_css',99);
  281.  
  282. add_action('wp_enqueue_scripts', 'load_google_fonts');
  283. //load_google_fonts();
  284.  
  285.  
  286. if (!is_admin()) {
  287. add_action('wp_head', 'get_custom_css');
  288. }
  289.  
  290. /*autoset_featured function to set automatically first attached image as featured image on image format post*/
  291. add_action('draft_to_publish', 'autoset_featured');
  292. add_action('new_to_publish', 'autoset_featured');
  293. add_action('pending_to_publish', 'autoset_featured');
  294. add_action('future_to_publish', 'autoset_featured');
  295.  
  296. /*filter to modify the output of wp_get_attachment_link*/
  297. add_filter( 'wp_get_attachment_link', 'modify_attachment_link', 10, 4 );
  298.  
  299. /*enable shortcodes in excerpts*/
  300. add_filter( 'the_excerpt', 'shortcode_unautop');
  301. add_filter( 'the_excerpt', 'do_shortcode');
  302.  
  303. /*make shortcodes work in text widgets*/
  304. add_filter( 'widget_text', 'shortcode_unautop');
  305. add_filter( 'widget_text', 'do_shortcode');
  306.  
  307.  
  308. /*Make Archives.php Include Custom Post Types, this function is used in archived.php*/
  309. function cosmo_namespace_add_custom_types( $query ) {
  310. /*make sure we run this only in front end for post format archives.*/
  311. if( is_tax( 'post_format' ) && empty( $query->query_vars['suppress_filters'] ) && !is_admin() ) {
  312. $query->set( 'post_type', array(
  313. 'post', 'portfolio'
  314. ));
  315. return $query;
  316. }
  317. }
  318. add_post_type_support( 'portfolio', 'post-formats' );
  319.  
  320. add_action('draft_to_publish_portfolio', 'autoset_featured');
  321. add_action('new_to_publish_portfolio', 'autoset_featured');
  322. add_action('pending_to_publish_portfolio', 'autoset_featured');
  323. add_action('future_to_publish_portfolio', 'autoset_featured');
  324.  
  325. /* action for color picker*/
  326. add_action( 'admin_enqueue_scripts', 'cosmo_mw_enqueue_color_picker' );
  327. function cosmo_mw_enqueue_color_picker( $hook_suffix ) {
  328. // first check that $hook_suffix is appropriate for your admin page
  329. wp_enqueue_style( 'wp-color-picker' );
  330. wp_enqueue_script( 'wp-color-picker' );
  331. }
  332.  
  333. /**********************************************/
  334. /************ Plugin recommendations **********/
  335. /**********************************************/
  336. require_once ('lib/php/plugin-recommendations.php');
  337.  
  338.  
  339. /**********************************************/
  340. /************ to keep functions.php not too big, all the functions and hooks and actions **********/
  341. /************ related to woocommerce are relocated to /woocustomtemplates/woo-commerce-custom-functions.php **********/
  342. /**********************************************/
  343. get_template_part('/woocustomtemplates/woo-commerce-custom-functions');
  344.  
  345. add_action('admin_notices', 'woo_styles_enabled_warning');
  346.  
  347. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement