Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.03 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. * Set Proper Parent/Child theme paths for inclusion
  5. */
  6. @define( 'PARENT_DIR', get_template_directory() );
  7. @define( 'CHILD_DIR', get_stylesheet_directory() );
  8.  
  9. @define( 'PARENT_URL', get_template_directory_uri() );
  10. @define( 'CHILD_URL', get_stylesheet_directory_uri() );
  11.  
  12. @define( 'CURRENT_THEME', getCurrentTheme() );
  13. @define( 'FILE_WRITEABLE', is_writeable(PARENT_DIR.'/style.css'));
  14. /*
  15. * Variables array init
  16. *
  17. */
  18. $variablesArray = array(
  19. 'textColor' => '#000000',
  20. 'bodyBackground' => '#000000',
  21. 'baseFontFamily' => '#000000',
  22. 'baseFontSize' => '#000000',
  23. 'baseLineHeight' => '#000000',
  24. 'linkColor' => '#000000',
  25. 'linkColorHover' => '#000000'
  26. );
  27.  
  28. /*
  29. * Definition current theme
  30. *
  31. */
  32. function getCurrentTheme() {
  33. if ( function_exists('wp_get_theme') ) {
  34. $theme = wp_get_theme();
  35. if ( $theme->exists() ) {
  36. $theme_name = $theme->Name;
  37. }
  38. } else {
  39. $theme_name = get_current_theme();
  40. }
  41. $theme_name = preg_replace("/\W/", "_", strtolower($theme_name) );
  42. return $theme_name;
  43. }
  44.  
  45.  
  46. /*
  47. * Comment some value from variables.less
  48. *
  49. */
  50. if ( CURRENT_THEME != 'cherry' )
  51. add_action('cherry_activation_hook', 'comment_child_var');
  52.  
  53. function comment_child_var() {
  54. global $variablesArray;
  55.  
  56. $file = CHILD_DIR .'/bootstrap/less/variables.less';
  57.  
  58. if ( file_exists($file) ) {
  59. $allVariablessArray = file($file);
  60.  
  61. foreach ($variablesArray as $key => $value) {
  62. foreach ($allVariablessArray as $k => $v) {
  63. $pos = strpos($v, $key);
  64. if ( $pos!==false && $pos == 1 ) {
  65. $allVariablessArray[$k] = '// ' . $v;
  66. break;
  67. }
  68. }
  69. }
  70. file_put_contents($file, $allVariablessArray);
  71. }
  72. }
  73.  
  74. /*
  75. * Helper function to return the theme option value.
  76. * If no value has been saved, it returns $default.
  77. * Needed because options are saved as serialized strings.
  78. */
  79. if ( !function_exists( 'of_get_option' ) ) {
  80. function of_get_option($name, $default = false) {
  81.  
  82. $optionsframework_settings = get_option('optionsframework');
  83.  
  84. // Gets the unique option id
  85. $option_name = $optionsframework_settings['id'];
  86.  
  87. if ( get_option($option_name) ) {
  88. $options = get_option($option_name);
  89. }
  90.  
  91. if ( isset($options[$name]) ) {
  92. return $options[$name];
  93. } else {
  94. return $default;
  95. }
  96. }
  97. }
  98.  
  99. /*
  100. * Unlink less cache files
  101. */
  102. add_action('cherry_activation_hook', 'clean_less_cache');
  103.  
  104. function clean_less_cache() {
  105. if ( CURRENT_THEME == 'cherry' ) {
  106. $bootstrapInput = PARENT_DIR .'/less/bootstrap.less';
  107. $themeInput = PARENT_DIR .'/less/style.less';
  108. } else {
  109. $bootstrapInput = CHILD_DIR .'/bootstrap/less/bootstrap.less';
  110. $themeInput = CHILD_DIR .'/style.less';
  111. }
  112.  
  113. $cacheFile1 = $bootstrapInput.".cache";
  114. $cacheFile2 = $themeInput.".cache";
  115. if (file_exists($cacheFile1)) unlink($cacheFile1);
  116. if (file_exists($cacheFile2)) unlink($cacheFile2);
  117. }
  118.  
  119. if ( (is_admin() && ($pagenow == "themes.php")) && FILE_WRITEABLE ) {
  120. do_action('cherry_activation_hook');
  121. }
  122.  
  123. /*
  124. * Loading theme textdomain
  125. */
  126. if ( !function_exists('cherry_theme_setup')) {
  127. function cherry_theme_setup() {
  128. load_theme_textdomain( CURRENT_THEME, PARENT_DIR . '/languages' );
  129. }
  130. add_action('after_setup_theme', 'cherry_theme_setup');
  131. }
  132. include_once (PARENT_DIR . '/includes/locals.php');
  133.  
  134. // WPML compatibility
  135. // WPML filter for correct posts IDs for the current language Solution
  136. if ( function_exists( 'wpml_get_language_information' )) {
  137. update_option('suppress_filters', 0);
  138. } else {
  139. update_option('suppress_filters', 1);
  140. }
  141. // Register Flickr and recent posts widgets link label for translation
  142. function wpml_link_text_filter( $link_text, $widget_title ) {
  143. icl_translate( 'cherry', 'link_text_' . $widget_title, $link_text );
  144. }
  145. // Check if WPML is activated
  146. if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
  147. add_filter( 'widget_linktext', 'wpml_link_text_filter', 10, 2 );
  148. }
  149.  
  150. //Loading Custom function
  151. include_once (CHILD_DIR . '/includes/custom-function.php');
  152.  
  153. //Loading jQuery and Scripts
  154. include_once (PARENT_DIR . '/includes/theme-scripts.php');
  155.  
  156. //Widget and Sidebar
  157. include_once (CHILD_DIR . '/includes/sidebar-init.php');
  158. include_once (PARENT_DIR . '/includes/register-widgets.php');
  159. include_once (PARENT_DIR . '/includes/widgets/widgets-manager.php');
  160.  
  161. //Theme initialization
  162. include_once (CHILD_DIR . '/includes/theme-init.php');
  163.  
  164. //Additional function
  165. include_once (PARENT_DIR . '/includes/theme-function.php');
  166.  
  167. //Shortcodes
  168. include_once (PARENT_DIR . '/includes/theme_shortcodes/columns.php');
  169. include_once (PARENT_DIR . '/includes/theme_shortcodes/shortcodes.php');
  170. include_once (PARENT_DIR . '/includes/theme_shortcodes/posts_grid.php');
  171. include_once (PARENT_DIR . '/includes/theme_shortcodes/posts_list.php');
  172. include_once (PARENT_DIR . '/includes/theme_shortcodes/mini_posts_list.php');
  173. include_once (PARENT_DIR . '/includes/theme_shortcodes/mini_posts_grid.php');
  174. include_once (PARENT_DIR . '/includes/theme_shortcodes/alert.php');
  175. include_once (PARENT_DIR . '/includes/theme_shortcodes/tabs.php');
  176. include_once (PARENT_DIR . '/includes/theme_shortcodes/toggle.php');
  177. include_once (PARENT_DIR . '/includes/theme_shortcodes/html.php');
  178. include_once (PARENT_DIR . '/includes/theme_shortcodes/misc.php');
  179. include_once (PARENT_DIR . '/includes/theme_shortcodes/service_box.php');
  180. include_once (PARENT_DIR . '/includes/theme_shortcodes/post_cycle.php');
  181. include_once (PARENT_DIR . '/includes/theme_shortcodes/carousel.php');
  182. include_once (PARENT_DIR . '/includes/theme_shortcodes/progressbar.php');
  183. include_once (PARENT_DIR . '/includes/theme_shortcodes/banner.php');
  184. include_once (PARENT_DIR . '/includes/theme_shortcodes/table.php');
  185. include_once (PARENT_DIR . '/includes/theme_shortcodes/hero_unit.php');
  186. include_once (PARENT_DIR . '/includes/theme_shortcodes/roundabout.php');
  187. include_once (PARENT_DIR . '/includes/theme_shortcodes/categories.php');
  188. include_once (PARENT_DIR . '/includes/theme_shortcodes/media.php');
  189.  
  190. //tinyMCE includes
  191. include_once (PARENT_DIR . '/includes/theme_shortcodes/tinymce/tinymce_shortcodes.php');
  192.  
  193. //Aqua Resizer for image cropping and resizing on the fly
  194. include_once (PARENT_DIR . '/includes/aq_resizer.php');
  195.  
  196. // Add the pagemeta
  197. include_once (PARENT_DIR . '/includes/theme-pagemeta.php');
  198.  
  199. // Add the postmeta
  200. include_once (PARENT_DIR . '/includes/theme-postmeta.php');
  201.  
  202. // Add the postmeta to Portfolio posts
  203. include_once (PARENT_DIR . '/includes/theme-portfoliometa.php');
  204.  
  205. // Add the postmeta to Slider posts
  206. include_once (PARENT_DIR . '/includes/theme-slidermeta.php');
  207.  
  208. // Add the postmeta to Testimonials
  209. include_once (PARENT_DIR . '/includes/theme-testimeta.php');
  210.  
  211. // Add the postmeta to Our Team posts
  212. include_once (PARENT_DIR . '/includes/theme-teammeta.php');
  213.  
  214. //Loading options.php for theme customizer
  215. include_once (CHILD_DIR . '/options.php');
  216. include_once (PARENT_DIR . '/framework_options.php');
  217.  
  218. //Plugin Activation
  219. include_once (CHILD_DIR . '/includes/class-tgm-plugin-activation.php');
  220. include_once (CHILD_DIR . '/includes/register-plugins.php');
  221.  
  222. // Framework Data Management
  223. include_once (PARENT_DIR . '/admin/data_management/data_management_interface.php');
  224.  
  225. // SEO Settings
  226. include_once (PARENT_DIR . '/admin/seo/seo_settings_page.php');
  227.  
  228. // WP Pointers
  229. include_once (PARENT_DIR . '/includes/class.wp-help-pointers.php');
  230.  
  231. // Embedding LESS compile
  232. if ( !class_exists('lessc') ) {
  233. include_once (PARENT_DIR .'/includes/lessc.inc.php');
  234. }
  235. include_once (PARENT_DIR .'/includes/less-compile.php');
  236.  
  237. // include shop
  238. function include_shop(){
  239. if ( file_exists(get_stylesheet_directory().'/shop.php') ) {
  240. include_once (CHILD_DIR . '/shop.php');
  241. }
  242. }
  243. add_action('after_setup_theme', 'include_shop');
  244.  
  245. // removes detailed login error information for security
  246. add_filter('login_errors',create_function('$a', "return null;"));
  247.  
  248. /*
  249. * Loads the Options Panel
  250. *
  251. * If you're loading from a child theme use stylesheet_directory
  252. * instead of template_directory
  253. */
  254. if ( !function_exists( 'optionsframework_init' ) ) {
  255. define( 'OPTIONS_FRAMEWORK_DIRECTORY', PARENT_URL . '/admin/' );
  256. include_once dirname( __FILE__ ) . '/admin/options-framework.php';
  257. }
  258.  
  259. /*
  260. * Removes Trackbacks from the comment cout
  261. *
  262. */
  263. if (!function_exists('comment_count')) {
  264. add_filter('get_comments_number', 'comment_count', 0);
  265.  
  266. function comment_count( $count ) {
  267. if ( ! is_admin() ) {
  268. global $id;
  269. $comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
  270. return count($comments_by_type['comment']);
  271. } else {
  272. return $count;
  273. }
  274. }
  275. }
  276.  
  277. /*
  278. * Post Formats
  279. *
  280. */
  281. $formats = array(
  282. 'aside',
  283. 'gallery',
  284. 'link',
  285. 'image',
  286. 'quote',
  287. 'audio',
  288. 'video');
  289. add_theme_support( 'post-formats', $formats );
  290. add_post_type_support( 'post', 'post-formats' );
  291.  
  292. /*
  293. * Custom excpert length
  294. *
  295. */
  296. if(!function_exists('new_excerpt_length')) {
  297.  
  298. function new_excerpt_length($length) {
  299. return 60;
  300. }
  301. add_filter('excerpt_length', 'new_excerpt_length');
  302. }
  303.  
  304. // enable shortcodes in sidebar
  305. add_filter('widget_text', 'do_shortcode');
  306. }
  307.  
  308. // custom excerpt ellipses for 2.9+
  309. if(!function_exists('custom_excerpt_more')) {
  310.  
  311. function custom_excerpt_more($more) {
  312. return theme_locals("read_more").' &raquo;';
  313. }
  314. add_filter('excerpt_more', 'custom_excerpt_more');
  315. }
  316.  
  317. // no more jumping for read more link
  318. if(!function_exists('no_more_jumping')) {
  319.  
  320. function no_more_jumping($post) {
  321. return '&nbsp;<a href="'.get_permalink().'" class="read-more">'.theme_locals("continue_reading").'</a>';
  322. }
  323. add_filter('excerpt_more', 'no_more_jumping');
  324. }
  325.  
  326. // category id in body and post class
  327. if(!function_exists('category_id_class')) {
  328.  
  329. function category_id_class($classes) {
  330. global $post;
  331. foreach((get_the_category()) as $category)
  332. $classes [] = 'cat-' . $category->cat_ID . '-id';
  333. return $classes;
  334. }
  335. add_filter('post_class', 'category_id_class');
  336. add_filter('body_class', 'category_id_class');
  337. }
  338.  
  339.  
  340. // Threaded Comments
  341. if(!function_exists('enable_threaded_comments')) {
  342. function enable_threaded_comments() {
  343. if (!is_admin()) {
  344. if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) {
  345. wp_enqueue_script('comment-reply');
  346. }
  347. }
  348. }
  349. add_action('get_header', 'enable_threaded_comments');
  350. }
  351.  
  352. //remove auto loading rel=next post link in header
  353. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
  354.  
  355. /*
  356. * Navigation with description
  357. *
  358. */
  359. if (! class_exists('description_walker')) {
  360. class description_walker extends Walker_Nav_Menu {
  361. function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
  362. global $wp_query;
  363. $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  364.  
  365. $class_names = $value = '';
  366.  
  367. $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  368.  
  369. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
  370. $class_names = ' class="'. esc_attr( $class_names ) . '"';
  371.  
  372. $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
  373.  
  374. $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
  375. $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
  376. $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
  377. $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
  378.  
  379. $description = ! empty( $item->description ) ? '<span class="desc">'.esc_attr( $item->description ).'</span>' : '';
  380.  
  381. if($depth != 0) {
  382. $description = $append = $prepend = "";
  383. }
  384.  
  385. $item_output = $args->before;
  386. $item_output .= '<a'. $attributes .'>';
  387. $item_output .= $args->link_before;
  388.  
  389. if (isset($prepend))
  390. $item_output .= $prepend;
  391.  
  392. $item_output .= apply_filters( 'the_title', $item->title, $item->ID );
  393.  
  394. if (isset($append))
  395. $item_output .= $append;
  396.  
  397. $item_output .= $description.$args->link_after;
  398. $item_output .= '</a>';
  399. $item_output .= $args->after;
  400.  
  401. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  402. }
  403. }
  404. }
  405.  
  406. /*
  407. * Cherry update
  408. */
  409. $cherryTemplates = array(
  410. '404.php',
  411. 'archive.php',
  412. 'author.php',
  413. 'category.php',
  414. 'index.php',
  415. 'page.php',
  416. 'page-archives.php',
  417. 'page-faq.php',
  418. 'page-fullwidth.php',
  419. 'page-home.php',
  420. 'page-Portfolio2Cols-filterable.php',
  421. 'page-Portfolio3Cols-filterable.php',
  422. 'page-Portfolio4Cols-filterable.php',
  423. 'page-testi.php',
  424. 'search.php',
  425. 'single.php',
  426. 'single-portfolio.php',
  427. 'single-team.php',
  428. 'single-testi.php',
  429. 'tag.php'
  430. );
  431.  
  432. $headerFooterPattern = '/(\<header.*?\>.*?\<\/header\>|\<footer.*?\>.*?\<\/footer\>)/is';
  433.  
  434. if (is_user_logged_in() && current_user_can('update_themes')) {
  435. $updateErrors = array();
  436.  
  437. $oldCherryVersion = get_option('cherry_version', '1.0');
  438. $currentCherryVersion = getCherryVersion($updateErrors);
  439. $cherryV2 = '2.0';
  440. $cherryForceUpdate = (bool) get_option('cherry_force_update', false);
  441.  
  442. if (version_compare($oldCherryVersion, $cherryV2) == -1 || $cherryForceUpdate) {
  443. writeLog(PHP_EOL . date('Y-m-d H:i:s'));
  444. writeLog('Old CherryFramework version: ' . $oldCherryVersion);
  445. writeLog('Current CherryFramework version: ' . $currentCherryVersion);
  446. writeLog('Force update: ' . (int) $cherryForceUpdate);
  447.  
  448. cherryUpdate($cherryTemplates, $headerFooterPattern, $updateErrors);
  449. //changeChildTheme
  450. changeChildTheme($updateErrors);
  451. //end changeChildTheme
  452. if (empty($updateErrors)) {
  453. update_option('cherry_version', $currentCherryVersion);
  454. update_option('cherry_force_update', 0);
  455. }
  456. }
  457. }
  458.  
  459. function getCherryVersion(&$updateErrors) {
  460. $style = TEMPLATEPATH . '/style.css';
  461. $themeVersion = 0;
  462.  
  463. if (function_exists('wp_get_theme')) {
  464. $theme = wp_get_theme(get_option('template', 'CherryFramework'));
  465. if (file_exists($style) && $theme->exists()) {
  466. $themeVersion = $theme->Version;
  467. } else {
  468. $updateErrors[] = $style . ' does not exist';
  469. writeLog($style . ' does not exist');
  470. }
  471. } elseif (function_exists('get_theme_data')) {
  472. if (file_exists($style)) {
  473. $theme = get_theme_data($style);
  474. $themeVersion = $theme['Version'];
  475. } else {
  476. $updateErrors[] = $style . ' does not exist';
  477. writeLog($style . ' does not exist');
  478. }
  479. } else {
  480. if (file_exists($style)) {
  481. $content = file_get_contents($style);
  482. if ($content) {
  483. $pattern = '/\s*version\s*:\s*([^\n]+)\s*/is';
  484. preg_match($pattern, $content, $matches);
  485. if (!empty($matches[1])) {
  486. $themeVersion = trim($matches[1]);
  487. }
  488. } else {
  489. $updateErrors[] = 'Failed to read ' . $style;
  490. writeLog('Failed to read ' . $style);
  491. }
  492. } else {
  493. $updateErrors[] = $style . ' does not exist';
  494. writeLog($style . ' does not exist');
  495. }
  496. }
  497. return $themeVersion;
  498. }
  499.  
  500. function isCherryChildTheme($themePath, $name, &$updateErrors) {
  501. $style = $themePath . '/style.css';
  502. $themeTemplate = false;
  503.  
  504. if (function_exists('wp_get_theme')) {
  505. $theme = wp_get_theme($name);
  506. if ($theme->exists()) {
  507. if ($theme->Stylesheet != $theme->Template) {
  508. $themeTemplate = $theme->Template;
  509. }
  510. } else {
  511. $updateErrors[] = 'Theme ' . $theme->Name . ' does not exist';
  512. writeLog('Theme ' . $theme->Name . ' does not exist');
  513. }
  514. } elseif (function_exists('get_theme_data')) {
  515. $theme = get_theme_data($style);
  516. $themeTemplate = $theme['Template'];
  517. } else {
  518. $content = file_get_contents($style);
  519. if ($content) {
  520. $pattern = '/\s*template\s*:\s*([^\n]+)\s*/is';
  521. preg_match($pattern, $content, $matches);
  522. if (!empty($matches[1])) {
  523. $themeTemplate = trim($matches[1]);
  524. }
  525. } else {
  526. $updateErrors[] = 'Failed to read ' . $style;
  527. writeLog('Failed to read ' . $style);
  528. }
  529. }
  530. return ($themeTemplate == 'CherryFramework') ? true : false;
  531. }
  532.  
  533. function getHeaderFooterCode($headerFooterPattern) {
  534. $headerFooter = array('header', 'footer');
  535. $headerFooterCode = array('header' => null, 'footer' => null);
  536.  
  537. foreach ($headerFooter as $name) {
  538. $filePath = TEMPLATEPATH . '/' . $name . '.php';
  539. if (file_exists($filePath)) {
  540. $content = file_get_contents($filePath);
  541. if ($content) {
  542. $matchesCount = preg_match($headerFooterPattern, $content, $matches);
  543. if ($matchesCount == 1 && !empty($matches[0])) {
  544. $headerFooterCode[$name] = $matches[0];
  545. } else {
  546. $updateErrors[] = 'header|footer code not found in ' . $filePath;
  547. writeLog('header|footer code not found in ' . $filePath);
  548. }
  549. } else {
  550. $updateErrors[] = 'Failed to read ' . $filePath;
  551. writeLog('Failed to read ' . $filePath);
  552. }
  553. } else {
  554. $updateErrors[] = $filePath . ' does not exist';
  555. writeLog($filePath . ' does not exist');
  556. }
  557. }
  558.  
  559. return $headerFooterCode;
  560. }
  561.  
  562. function backupFile($templatePath) {
  563. return copy($templatePath, $templatePath . '.bak');
  564. }
  565.  
  566. function writeLog($message) {
  567. $logFile = TEMPLATEPATH . '/update.log';
  568. if (is_writable(TEMPLATEPATH)) {
  569. file_put_contents($logFile, $message . PHP_EOL, FILE_APPEND);
  570. }
  571. }
  572.  
  573. function cherryUpdate($cherryTemplates, $headerFooterPattern, &$updateErrors) {
  574. $themesPath = get_theme_root();
  575.  
  576. $skip = array('.', '..', 'CherryFramework', 'twentytwelve', 'twentyeleven', 'twentyten', 'index.php');
  577. $themes = array_diff(scandir($themesPath), $skip);
  578.  
  579. if (!empty($themes)) {
  580. foreach ($themes as $theme) {
  581. $themePath = $themesPath . '/' . $theme;
  582. if (is_dir($themePath) && file_exists($themePath . '/style.css')) {
  583.  
  584. $isCherryChildTheme = isCherryChildTheme($themePath, $theme, $updateErrors);
  585.  
  586. if ($isCherryChildTheme) {
  587. if (is_writable($themePath)) {
  588. writeLog(PHP_EOL . 'Child theme: ' . $themePath);
  589. $files = scandir($themePath);
  590. $themeTemplates = array_intersect($files, $cherryTemplates);
  591. if (!empty($themeTemplates)) {
  592. foreach ($themeTemplates as $template) {
  593. $templatePath = $themePath . '/' . $template;
  594. if (is_writable($templatePath)) {
  595. $content = file_get_contents($templatePath);
  596. if ($content) {
  597. $headerFooterMatchesCount = preg_match_all($headerFooterPattern, $content, $headerFooterMatches);
  598. if ($headerFooterMatchesCount > 0) {
  599. $backupFile = backupFile($templatePath);
  600. if ($backupFile) {
  601. writeLog('Backup ' . $templatePath);
  602.  
  603. $content = preg_replace($headerFooterPattern, '', $content, -1, $headerFooterReplaceCount);
  604. if (!is_null($content) && $headerFooterReplaceCount > 0) {
  605. writeLog('Replace ' . $headerFooterReplaceCount . ' header|footer');
  606.  
  607. if (file_put_contents($templatePath, $content)) {
  608. writeLog('Save ' . $templatePath);
  609. } else {
  610. $updateErrors[] = 'Failed to save ' . $templatePath;
  611. writeLog('Failed to save ' . $templatePath);
  612. }
  613. }
  614. } else {
  615. $updateErrors[] = 'Failed to backup ' . $templatePath;
  616. writeLog('Failed to backup ' . $templatePath);
  617. }
  618. }
  619. } else {
  620. $updateErrors[] = 'Failed to read ' . $templatePath;
  621. writeLog('Failed to read ' . $templatePath);
  622. }
  623. } else {
  624. $updateErrors[] = $templatePath . ' is not writable';
  625. writeLog($templatePath . ' is not writable');
  626. }
  627. }
  628. }
  629.  
  630. $headerFooter = array_intersect($files, array('header.php', 'footer.php'));
  631. if (!empty($headerFooter)) {
  632. $headerFooterCode = getHeaderFooterCode($headerFooterPattern);
  633. if (!is_null($headerFooterCode['header']) && !is_null($headerFooterCode['footer'])) {
  634. foreach ($headerFooter as $file) {
  635. $filePath = $themePath . '/' . $file;
  636. if (is_writable($filePath)) {
  637. $content = file_get_contents($filePath);
  638. if ($content) {
  639. $headerFooterMatchesCount = preg_match_all($headerFooterPattern, $content, $headerFooterMatches);
  640. if ($headerFooterMatchesCount === 0) {
  641. $backupFile = backupFile($filePath);
  642. if ($backupFile) {
  643. writeLog('Backup ' . $filePath);
  644.  
  645. if ($file == 'header.php') {
  646. $content .= $headerFooterCode['header'];
  647. } elseif ($file == 'footer.php') {
  648. $content = $headerFooterCode['footer'] . $content;
  649. }
  650.  
  651. writeLog('Add header|footer code in ' . $filePath);
  652.  
  653. if (file_put_contents($filePath, $content)) {
  654. writeLog('Save ' . $filePath);
  655. } else {
  656. $updateErrors[] = 'Failed to save ' . $filePath;
  657. writeLog('Failed to save ' . $filePath);
  658. }
  659. } else {
  660. $updateErrors[] = 'Failed to backup ' . $filePath;
  661. writeLog('Failed to backup ' . $filePath);
  662. }
  663. }
  664. } else {
  665. $updateErrors[] = 'Failed to read ' . $filePath;
  666. writeLog('Failed to read ' . $filePath);
  667. }
  668. } else {
  669. $updateErrors[] = $filePath . ' is not writable';
  670. writeLog($filePath . ' is not writable');
  671. }
  672. }
  673. }
  674. }
  675. } else {
  676. $updateErrors[] = $themePath . ' is not writable';
  677. writeLog($themePath . ' is not writable');
  678. }
  679. }
  680. }
  681. }
  682. }
  683. }
  684. //changeChildTheme
  685. function changeChildTheme(&$updateErrors){
  686. $themesPath = get_theme_root();
  687.  
  688. $skip = array('.', '..', 'CherryFramework', 'twentytwelve', 'twentyeleven', 'twentyten', 'index.php');
  689. $themes = array_diff(scandir($themesPath), $skip);
  690.  
  691. if (!empty($themes)) {
  692. foreach ($themes as $theme) {
  693. $themePath = $themesPath . '/' . $theme;
  694. if (is_dir($themePath) && file_exists($themePath . '/style.css')) {
  695.  
  696. $isCherryChildTheme = isCherryChildTheme($themePath, $theme, $updateErrors);
  697.  
  698. if ($isCherryChildTheme) {
  699. if (is_writable($themePath)) {
  700. unset($slider_in_header, $slider_in_page_home, $pahe_home_content);
  701. writeLog(PHP_EOL . 'Child theme: ' . $themePath);
  702. $files = scandir($themePath);
  703. $header_php = array_intersect($files, array('header.php'));
  704. if (!empty($header_php)) {
  705. $templatePath = $themePath . '/header.php';
  706. $content = file_get_contents($templatePath);
  707. if (stripos($content, '"static/static-slider"')!==false) {
  708. $slider_in_header = true;
  709. }
  710. }
  711. if(!isset($slider_in_header)){
  712. if (is_dir($themePath."/wrapper")){
  713. $nestedFiles = scandir($themePath."/wrapper");
  714. $header_wrapper_php = array_intersect($nestedFiles, array('wrapper-header.php'));
  715. if (!empty($header_wrapper_php)) {
  716. $header_wrapper_php_path = $themePath . '/wrapper/wrapper-header.php';
  717. $content = file_get_contents($header_wrapper_php_path);
  718. if (stripos($content, '"static/static-slider"')!==false) {
  719. $slider_in_header = true;
  720. }
  721. }
  722. }
  723. }
  724. if(!isset($slider_in_header)){
  725. $page_home_php = array_intersect($files, array('page-home.php'));
  726. if (!empty($page_home_php)) {
  727. $templatePath = $themePath . '/page-home.php';
  728. $content = file($templatePath);
  729. for ($i=0, $arrayCount = count($content); $i < $arrayCount ; $i++) {
  730. if(stripos($content[$i], '"static/static-slider"')!==false){
  731. $slider_in_page_home = $i;
  732. }
  733. if(stripos($content[$i], '"page-home.php"')!==false){
  734. $pahe_home_content = $i;
  735. }
  736. }
  737. if(!isset($slider_in_page_home)){
  738. array_splice($content, $pahe_home_content+1, 0, "\t<div class=\"row\">\n\t\t<div class=\"span12\" data-motopress-type=\"static\" data-motopress-static-file=\"static/static-slider.php\">\n\t\t\t<?php get_template_part(\"static/static-slider\"); ?>\n\t\t</div>\n\t</div>\n");
  739. writeLog('Change page-home.php');
  740. if (file_put_contents($templatePath, $content)) {
  741. writeLog('Save ' . $templatePath);
  742. } else {
  743. $updateErrors[] = 'Failed to save ' . $templatePath;
  744. writeLog('Failed to save ' . $templatePath);
  745. }
  746. }
  747. }
  748. }
  749. $stylesheet = array_intersect($files, array('style.css'));
  750. $stylePath = $themePath . '/style.css';
  751. if (!empty($stylesheet)) {
  752. $styleContent = file($stylePath);
  753. if ($styleContent) {
  754. for ($i=0, $arrayCount = count($styleContent); $i < $arrayCount ; $i++) {
  755. if(stripos($styleContent[$i], "/*--")!==false){
  756. $styleContentChange = array();
  757. }
  758. if(isset($styleContentChange)){
  759. $styleContentChange[$i] = $styleContent[$i];
  760. }
  761. if(stripos($styleContent[$i], "--*/")!==false){
  762. break;
  763. }
  764. }
  765. array_push($styleContentChange, '@import url("main-style.css");');
  766. if (file_put_contents($stylePath, $styleContentChange)) {
  767. writeLog('Save ' . $stylePath);
  768. } else {
  769. $updateErrors[] = 'Failed to save ' . $stylePath;
  770. writeLog('Failed to save ' . $stylePath);
  771. }
  772. } else {
  773. $updateErrors[] = 'Failed to read ' . $stylesheet;
  774. writeLog('Failed to read ' . $stylesheet);
  775. }
  776. }
  777. if (is_dir($themePath."/static")){
  778. $nestedFiles = scandir($themePath."/static");
  779. $staticSlider = array_intersect($nestedFiles, array('static-slider.php'));
  780. $staticSliderPath = $themePath . '/static/static-slider.php';
  781. unset($sliderStatic, $new_function);
  782. if (!empty($staticSlider)) {
  783. $backupFileStatic = backupFile($staticSliderPath);
  784. if ($backupFileStatic) {
  785. $staticSliderContent = file($staticSliderPath);
  786. if ($staticSliderContent) {
  787. $static_slider_dom_1 = "<?php if(of_get_option('slider_type') != 'none_slider'){ ?>\n";
  788. $static_slider_dom_2 = "\t<?php get_slider_template_part(); ?>\n";
  789. $static_slider_dom_3 = "\n<?php }else{ ?>\n\t<div class=\"slider_off\"></div>\n<?php } ?>\n";
  790. for ($i=0, $arrayCount = count($staticSliderContent); $i < $arrayCount ; $i++) {
  791. if(stripos($staticSliderContent[$i], "get_template_part('slider')")!==false){
  792. $sliderStatic = $i;
  793. }
  794. if(stripos($staticSliderContent[$i], "get_slider_template_part")!==false){
  795. $new_function = $i;
  796. }
  797. }
  798. if(!isset($sliderStatic) && !isset($new_function)){
  799. $staticSliderContent = "<?php /* Static Name: Slider */ ?>\n<?php if(of_get_option('slider_type') != 'none_slider'){ ?>\n\t<div id=\"slider-wrapper\" class=\"slider\">\n\t\t<div class=\"container\">\n\t\t\t<?php get_slider_template_part(); ?>\n\t\t</div>\n\t</div><!-- .slider -->\n<?php }else{ ?>\n\t<div class=\"slider_off\"><!--slider off--></div>\n<?php } ?>";
  800. }else{
  801. if(!isset($new_function)){
  802. $staticSliderContent[$sliderStatic] = $static_slider_dom_2;
  803. array_splice($staticSliderContent, 1, 0, $static_slider_dom_1);
  804. array_push($staticSliderContent, $static_slider_dom_3);
  805. }
  806. }
  807. if (file_put_contents($staticSliderPath, $staticSliderContent)) {
  808. writeLog('Save ' . $staticSliderPath);
  809. } else {
  810. $updateErrors[] = 'Failed to save ' . $staticSliderPath;
  811. writeLog('Failed to save ' . $staticSliderPath);
  812. }
  813. } else {
  814. $updateErrors[] = 'Failed to read ' . $staticSlider;
  815. writeLog('Failed to read ' . $staticSlider);
  816. }
  817.  
  818. }else {
  819. $updateErrors[] = 'Failed to backup ' . $staticSliderPath;
  820. writeLog('Failed to backup ' . $staticSliderPath);
  821. }
  822. }
  823. }
  824. } else {
  825. $updateErrors[] = $themePath . ' is not writable';
  826. writeLog($themePath . ' is not writable');
  827. }
  828. }
  829. }
  830. }
  831. }
  832. };
  833. //end changeChildTheme
  834. if (has_action('after_switch_theme')) {
  835. add_action('after_switch_theme', 'activateCherryForceUpdate', 10, 0);
  836. } else {
  837. if (is_admin() && isset($_GET['activated']) && $pagenow == 'themes.php') {
  838. activateCherryForceUpdate();
  839. }
  840. }
  841.  
  842. function activateCherryForceUpdate() {
  843. global $cherryTemplates;
  844. global $headerFooterPattern;
  845.  
  846. $style = STYLESHEETPATH . '/style.css';
  847. $themeTemplate = false;
  848.  
  849. if (function_exists('wp_get_theme')) {
  850. $theme = wp_get_theme();
  851. if (file_exists($style) && $theme->exists()) {
  852. if ($theme->Stylesheet != $theme->Template) {
  853. $themeTemplate = $theme->Template;
  854. }
  855. } else {
  856. writeLog($style . ' does not exist');
  857. }
  858. } elseif (function_exists('get_theme_data')) {
  859. if (file_exists($style)) {
  860. $theme = get_theme_data($style);
  861. $themeTemplate = $theme['Template'];
  862. } else {
  863. writeLog($style . ' does not exist');
  864. }
  865. } else {
  866. if (file_exists($style)) {
  867. $content = file_get_contents($style);
  868. if ($content) {
  869. $pattern = '/\s*template\s*:\s*([^\n]+)\s*/is';
  870. preg_match($pattern, $content, $matches);
  871. if (!empty($matches[1])) {
  872. $themeTemplate = trim($matches[1]);
  873. }
  874. } else {
  875. writeLog('Failed to read ' . $style);
  876. }
  877. } else {
  878. writeLog($style . ' does not exist');
  879. }
  880. }
  881.  
  882. if ($themeTemplate == 'CherryFramework') {
  883. $themePath = get_stylesheet_directory();
  884. $files = scandir($themePath);
  885. $themeTemplates = array_intersect($files, $cherryTemplates);
  886.  
  887. $cherryForceUpdate = false;
  888.  
  889. if (!empty($themeTemplates)) {
  890. foreach ($themeTemplates as $template) {
  891. $templatePath = $themePath . '/' . $template;
  892. $content = file_get_contents($templatePath);
  893. if ($content) {
  894. $headerFooterMatchesCount = preg_match($headerFooterPattern, $content);
  895. if ($headerFooterMatchesCount == 1) {
  896. $cherryForceUpdate = true;
  897. break;
  898. }
  899. } else {
  900. writeLog('Failed to read ' . $templatePath);
  901. }
  902. }
  903. }
  904.  
  905. if ($cherryForceUpdate) {
  906. update_option('cherry_force_update', 1);
  907. } else {
  908. update_option('cherry_force_update', 0);
  909. }
  910. }
  911. }
  912. //------------------------------------------------------
  913. // slider function
  914. //------------------------------------------------------
  915. if (!function_exists("my_post_type_slider")) {
  916. function my_post_type_slider() {
  917. register_post_type( 'slider',
  918. array(
  919. 'label' => theme_locals("slides"),
  920. 'singular_label' => theme_locals("slides"),
  921. '_builtin' => false,
  922. 'exclude_from_search' => true, // Exclude from Search Results
  923. 'capability_type' => 'page',
  924. 'public' => true,
  925. 'show_ui' => true,
  926. 'show_in_nav_menus' => false,
  927. 'rewrite' => array(
  928. 'slug' => 'slide-view',
  929. 'with_front' => FALSE,
  930. ),
  931. 'query_var' => "slide", // This goes to the WP_Query schema
  932. 'menu_icon' => get_template_directory_uri() . '/includes/images/icon_slides.png',
  933. 'supports' => array(
  934. 'title',
  935. // 'custom-fields',
  936. 'thumbnail'
  937. )
  938. )
  939. );
  940. }
  941. add_action('init', 'my_post_type_slider');
  942. }
  943. if (!function_exists("get_slider_template_part")) {
  944. function get_slider_template_part() {
  945. switch (of_get_option('slider_type')) {
  946. case "accordion_slider":
  947. $slider_type = "accordion";
  948. break;
  949. default:
  950. $slider_type = "slider";
  951. }
  952. return get_template_part($slider_type);
  953. }
  954. }
  955. //------------------------------------------------------
  956. // Warning notice
  957. //------------------------------------------------------
  958. add_action( 'admin_notices', 'warning_notice' );
  959. function warning_notice() {
  960. global $pagenow;
  961. $pageHidden = array('admin.php');
  962. if (!get_user_meta(get_current_user_id(), '_wp_hide_notice', true) && is_admin() && !FILE_WRITEABLE && !in_array($pagenow, $pageHidden)) {
  963. printf('<div class="updated"><strong><p>'.theme_locals('warning_notice_2').'</p><p>'.theme_locals('warning_notice_3').'</p><p><a href="'.esc_url(add_query_arg( 'wp_nag', wp_create_nonce( 'wp_nag' ))).'">'.theme_locals('dismiss_notice').'</a></p></strong></div>');
  964. }
  965. }
  966. //------------------------------------------------------
  967. // Post Meta
  968. //------------------------------------------------------
  969. $global_meta_elements = array();
  970. function get_post_metadata( $args = array() ) {
  971. global $global_meta_elements;
  972. if(array_key_exists('meta_elements', $args)){
  973. $global_meta_elements = array_unique(array_merge($global_meta_elements, $args['meta_elements']));
  974. }
  975.  
  976. $meta_elements_empty = isset($args['meta_elements']) ? false : true ;
  977. $defaults = array(
  978. 'meta_elements' => array('start_unite', 'date', 'author', 'permalink', 'end_unite', 'start_unite', 'categories', 'tags', 'end_unite', 'start_unite', 'comment', 'views', 'like', 'dislike', 'end_unite'),
  979. 'meta_class' => 'post_meta',
  980. 'meta_before' => '',
  981. 'meta_after' => ''
  982. );
  983. $args = wp_parse_args( $args, $defaults );
  984. $post_meta_type = (of_get_option('post_meta') == 'true' || of_get_option('post_meta') == '') ? 'line' : of_get_option('post_meta');
  985. if($meta_elements_empty){
  986. foreach ($global_meta_elements as $key) {
  987. if($key != 'end_unite || start_unite'){
  988. unset($args['meta_elements'][array_search($key, $args['meta_elements'])]);
  989. }
  990. }
  991. }
  992.  
  993.  
  994. if($post_meta_type!='false'){
  995. $post_ID = get_the_ID();
  996. $post_type = get_post_type($post_ID);
  997. $icon_tips_before = ($post_meta_type == 'icon') ? '<div class="tips">' : '';
  998. $icon_tips_after = ($post_meta_type == 'icon') ? '</div>' : '';
  999.  
  1000. $user_login = is_user_logged_in() ? true : false;
  1001. $user_id = $user_login ? get_current_user_id() : "";
  1002. $voting_class = $user_login ? 'ajax_voting ' : 'not_voting ';
  1003. $voting_url = PARENT_URL.'/includes/voting.php?post_ID='.$post_ID.'&amp;get_user_ID='.$user_id;
  1004. $get_voting_array = cherry_getPostVoting($post_ID, $user_id);
  1005. $user_voting = $get_voting_array['user_voting'];
  1006.  
  1007. echo $args['meta_before'].'<div class="'.$args['meta_class'].' meta_type_'.$post_meta_type.'">';
  1008. foreach ($args['meta_elements'] as $value) {
  1009. switch ($value) {
  1010. case 'date':
  1011. if(of_get_option('post_date') != 'no'){ ?>
  1012. <div class="post_date">
  1013. <i class="icon-calendar"></i>
  1014. <?php echo $icon_tips_before . '<time datetime="' . get_the_time('Y-m-d\TH:i:s') . '">' . get_the_date() . '</time>' . $icon_tips_after; ?>
  1015. </div>
  1016. <?php
  1017. }
  1018. break;
  1019. case 'author':
  1020. if(of_get_option('post_author') != 'no'){ ?>
  1021. <div class="post_author">
  1022. <i class="icon-user"></i>
  1023. <?php
  1024. echo $icon_tips_before;
  1025. the_author_posts_link();
  1026. echo $icon_tips_after;
  1027. ?>
  1028. </div>
  1029. <?php
  1030. }
  1031. break;
  1032. case 'permalink':
  1033. if(of_get_option('post_permalink') != 'no'){ ?>
  1034. <div class="post_permalink">
  1035. <i class="icon-link"></i>
  1036. <?php echo $icon_tips_before.'<a href="'.get_permalink().'" title="'.get_the_title().'">'.theme_locals('permalink_to').'</a>'.$icon_tips_after; ?>
  1037. </div>
  1038. <?php
  1039. }
  1040. break;
  1041. case 'categories':
  1042. if(of_get_option('post_category') != 'no'){ ?>
  1043. <div class="post_category">
  1044. <i class="icon-bookmark"></i>
  1045. <?php
  1046. echo $icon_tips_before;
  1047. ($post_type != 'post') ? the_terms($post_ID, $post_type.'_category','',', ') : the_category(', ');
  1048. echo $icon_tips_after;
  1049. ?>
  1050. </div>
  1051. <?php
  1052. }
  1053. break;
  1054. case 'tags':
  1055. if(of_get_option('post_tag') != 'no'){ ?>
  1056. <div class="post_tag">
  1057. <i class="icon-tag"></i>
  1058. <?php
  1059. echo $icon_tips_before;
  1060. if(get_the_tags() || has_term('', $post_type.'_tag', $post_ID)){
  1061. echo ($post_type != 'post') ? the_terms($post_ID, $post_type.'_tag','',', ') : the_tags('', ', ');
  1062. } else {
  1063. echo theme_locals('has_not_tags');
  1064. }
  1065. echo $icon_tips_after;
  1066. ?>
  1067. </div>
  1068. <?php
  1069. }
  1070. break;
  1071. case 'comment':
  1072. if(of_get_option('post_comment') != 'no'){ ?>
  1073. <div class="post_comment">
  1074. <i class="icon-comments"></i>
  1075. <?php
  1076. echo $icon_tips_before;
  1077. comments_popup_link(theme_locals('no_comments'), theme_locals('comment'), '% '.theme_locals('comments'), theme_locals('comments_link'), theme_locals('comments_closed'));
  1078. echo $icon_tips_after;
  1079. ?>
  1080. </div>
  1081. <?php
  1082. }
  1083. break;
  1084. case 'views':
  1085. if(of_get_option('post_views') != 'no'){ ?>
  1086. <div class="post_views" title="<?php echo theme_locals('number_views'); ?>">
  1087. <i class="icon-eye-open"></i>
  1088. <?php echo $icon_tips_before.cherry_getPostViews($post_ID).$icon_tips_after; ?>
  1089. </div>
  1090. <?php
  1091. }
  1092. break;
  1093. case 'dislike':
  1094. if(of_get_option('post_dislike') != 'no'){
  1095. $dislike_url = ($user_login && $user_voting=='none') ? 'href="'.$voting_url.'&amp;voting=dislike"' : '';
  1096. $dislike_count = $get_voting_array['dislike_count'];
  1097. $dislike_title = $user_login ? theme_locals('dislike') : theme_locals('not_voting');
  1098. $dislike_class = ($user_voting == 'dislike') ? 'user_dislike ' : '';
  1099. if($user_voting!='none'){
  1100. $voting_class = "user_voting ";
  1101. }
  1102. ?>
  1103. <div class="post_dislike">
  1104. <a <?php echo $dislike_url; ?> class="<?php echo $voting_class.$dislike_class; ?>" title="<?php echo $dislike_title; ?>" date-type="dislike" >
  1105. <i class="icon-thumbs-down"></i>
  1106. <?php echo $icon_tips_before.'<span class="voting_count">'.$dislike_count.'</span>'.$icon_tips_after; ?>
  1107. </a>
  1108. </div>
  1109. <?php
  1110. }
  1111. break;
  1112. case 'like':
  1113. if(of_get_option('post_like') != 'no'){
  1114. $like_url = ($user_login && $user_voting=='none') ? 'href="'.$voting_url.'&amp;voting=like"' : '';
  1115. $like_count = $get_voting_array['like_count'];
  1116. $like_title = $user_login ? theme_locals('like') : theme_locals('not_voting');
  1117. $like_class = ($user_voting == 'like') ? 'user_like ' : '';
  1118. if($user_voting!='none'){
  1119. $voting_class = "user_voting ";
  1120. }
  1121. ?>
  1122. <div class="post_like">
  1123. <a <?php echo $like_url; ?> class="<?php echo $voting_class.$like_class; ?>" title="<?php echo $like_title; ?>" date-type="like" >
  1124. <i class="icon-thumbs-up"></i>
  1125. <?php echo $icon_tips_before.'<span class="voting_count">'.$like_count.'</span>'.$icon_tips_after; ?>
  1126. </a>
  1127. </div>
  1128. <?php
  1129. }
  1130. break;
  1131. case 'start_unite':
  1132. echo '<div class="post_meta_unite clearfix">';
  1133. break;
  1134. case 'end_unite':
  1135. echo '</div>';
  1136. break;
  1137. }
  1138. }
  1139. echo '</div>'.$args['meta_after'];
  1140. }
  1141. }
  1142. //------------------------------------------------------
  1143. // Post Views
  1144. //------------------------------------------------------
  1145. function cherry_getPostViews($postID){
  1146. return (get_post_meta($postID, 'post_views_count', true) == '') ? "0" : get_post_meta($postID, 'post_views_count', true);
  1147. }
  1148. function cherry_setPostViews($postID){
  1149. $count_key = 'post_views_count';
  1150. $count = get_post_meta($postID, $count_key, true);
  1151. if($count==''){
  1152. $count = 1;
  1153. }else{
  1154. $count++;
  1155. }
  1156. update_post_meta($postID, $count_key, $count);
  1157. }
  1158. //------------------------------------------------------
  1159. // Post voting
  1160. //------------------------------------------------------
  1161. function cherry_getPostVoting($postID, $user_id){
  1162. $like_count = (get_post_meta($postID, 'post_like', true) == false) ? "0" : get_post_meta($postID, 'post_like', true);
  1163. $dislike_count = (get_post_meta($postID, 'post_dislike', true) == false) ? "0" : get_post_meta($postID, 'post_dislike', true);
  1164. $user_like_array = get_post_meta($postID, 'user_like');
  1165. $user_dislike_array = get_post_meta($postID, 'user_dislike');
  1166. $user_voting = 'none';
  1167. if(in_array($user_id, $user_like_array)){
  1168. $user_voting = 'like';
  1169. }else if(in_array($user_id, $user_dislike_array)){
  1170. $user_voting = 'dislike';
  1171. }
  1172. return array('like_count' => $like_count, 'dislike_count' => $dislike_count, 'user_voting' => $user_voting);
  1173. }
  1174. //------------------------------------------------------
  1175. // Get team social networks
  1176. //------------------------------------------------------
  1177. function cherry_get_post_networks($args = array()){
  1178. global $post;
  1179. extract(
  1180. wp_parse_args(
  1181. $args,
  1182. array(
  1183. 'post_id' => get_the_ID(),
  1184. 'class' => 'post_networks',
  1185. 'before_title' => '<h4>',
  1186. 'after_title' => '</h4>',
  1187. 'display_title' => true,
  1188. 'output_type' => 'echo'
  1189. )
  1190. )
  1191. );
  1192. $networks_array = explode(" ", get_option('fields_id_value'.$post_id, ''));
  1193.  
  1194. if($networks_array[0]!=''){
  1195. $count = 0;
  1196. $network_title = get_post_meta($post_id, 'network_title', true);
  1197.  
  1198. $output = '<div class="'.$class.'">';
  1199. $output .= $network_title && $display_title ? $before_title.$network_title.$after_title : '';
  1200. $output .= '<ul class="clearfix unstyled">';
  1201. foreach ($networks_array as $networks_id) {
  1202. $network_array = explode(";", get_option('network_'.$post_id.'_'.$networks_id, array('','','')));
  1203. $output .= '<li class="network_'.$count.'">';
  1204. $output .= $network_array[2] ? '<a href="'.$network_array[2].'" title="'.$network_array[1].'">' : '' ;
  1205. $output .= $network_array[0] ? '<span class="'.$network_array[0].'"></span>' :'';
  1206. $output .= $network_array[1] ? '<span class="network_title">'.$network_array[1].'</span>' : '' ;
  1207. $output .= $network_array[2] ? '</a>' : '' ;
  1208. $output .= '</li>';
  1209. ++$count;
  1210. }
  1211. $output .= '</ul></div>';
  1212. if($output_type == 'echo'){
  1213. echo $output;
  1214. }else{
  1215. return $output;
  1216. }
  1217. }
  1218. }
  1219. ?>
  1220.  
  1221. <?php
  1222. /**
  1223. * Register Widget Area.
  1224. *
  1225. */
  1226. function wpgyan_widgets_init() {
  1227.  
  1228. register_sidebar( array(
  1229. 'name' => 'Header Sidebar',
  1230. 'id' => 'header_sidebar',
  1231. 'before_widget' => '<div>',
  1232. 'after_widget' => '</div>',
  1233. 'before_title' => '<h2 class="rounded">',
  1234. 'after_title' => '</h2>',
  1235. ) );
  1236. }
  1237. add_action( 'widgets_init', 'wpgyan_widgets_init' );
  1238. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement