Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.15 KB | None | 0 0
  1. <?php
  2.     define('infinity_THEME_VERSION', '1.0');
  3.     if( !osc_get_preference('keyword_placeholder', 'infinity_theme') ) {
  4.         osc_set_preference('keyword_placeholder', __('ie. PHP Programmer', 'infinity'), 'infinity_theme');
  5.     }
  6.     osc_register_script('fancybox', osc_current_web_theme_url('js/fancybox/jquery.fancybox.pack.js'), array('jquery'));
  7.     osc_enqueue_style('fancybox', osc_current_web_theme_url('js/fancybox/jquery.fancybox.css'));
  8.     osc_enqueue_script('fancybox');
  9.     osc_enqueue_script('php-date');
  10.    
  11.     if( !function_exists('infinityBodyClass_theme_install') ) {
  12.         function infinity_theme_install() {
  13.             osc_set_preference('keyword_placeholder', Params::getParam('keyword_placeholder'), 'infinity_theme');
  14.             osc_set_preference('version', infinity_THEME_VERSION, 'infinity_theme');
  15.             osc_set_preference('footer_link', '1', 'infinity_theme');
  16.             osc_set_preference('donation', '0', 'infinity_theme');
  17.             osc_set_preference('default_logo', '1', 'infinity_theme');
  18.             osc_set_preference('defaultShowAs@all', 'list', 'infinity_theme');
  19.             osc_set_preference('defaultShowAs@search', 'list');
  20.             osc_reset_preferences();
  21.         }
  22.     }
  23.  
  24.     if(!function_exists('check_install_infinity_theme')) {
  25.         function check_install_infinity_theme() {
  26.             $current_version = osc_get_preference('version', 'infinity_theme');
  27.             if( !$current_version ) {
  28.                 infinity_theme_install();
  29.             }
  30.         }
  31.     }
  32.  
  33.     if(!function_exists('infinity_add_body_class_construct')) {
  34.         function infinity_add_body_class_construct($classes){
  35.             $infinityBodyClass = infinityBodyClass::newInstance();
  36.             $classes = array_merge($classes, $infinityBodyClass->get());
  37.             return $classes;
  38.         }
  39.     }
  40.     if(!function_exists('infinity_body_class')) {
  41.         function infinity_body_class($echo = true){
  42.             osc_add_filter('infinity_bodyClass','infinity_add_body_class_construct');
  43.             $classes = osc_apply_filter('infinity_bodyClass', array());
  44.             if($echo && count($classes)){
  45.                 echo 'class="'.implode(' ',$classes).'"';
  46.             } else {
  47.                 return $classes;
  48.             }
  49.         }
  50.     }
  51.     if(!function_exists('infinity_add_body_class')) {
  52.         function infinity_add_body_class($class){
  53.             $infinityBodyClass = infinityBodyClass::newInstance();
  54.             $infinityBodyClass->add($class);
  55.         }
  56.     }
  57.     if(!function_exists('infinity_nofollow_construct')) {
  58.         function infinity_nofollow_construct() {
  59.             echo '<meta name="robots" content="noindex, nofollow, noarchive" />' . PHP_EOL;
  60.             echo '<meta name="googlebot" content="noindex, nofollow, noarchive" />' . PHP_EOL;
  61.  
  62.         }
  63.     }
  64.     if( !function_exists('infinity_follow_construct') ) {
  65.         function infinity_follow_construct() {
  66.             echo '<meta name="robots" content="index, follow" />' . PHP_EOL;
  67.             echo '<meta name="googlebot" content="index, follow" />' . PHP_EOL;
  68.  
  69.         }
  70.     }
  71.     if( !function_exists('logo_header') ) {
  72.         function logo_header() {
  73.              $html = '<a href="'.osc_base_url().'"><img border="0" alt="' . osc_page_title() . '" src="' . osc_current_web_theme_url('images/logo.jpg') . '"></a>';
  74.              if( file_exists( WebThemes::newInstance()->getCurrentThemePath() . 'images/logo.jpg' ) ) {
  75.                 return $html;
  76.              } else {
  77.                 return '<a href="'.osc_base_url().'">'.osc_page_title().'</a>';
  78.             }
  79.         }
  80.     }
  81.      if( !function_exists('infinity_draw_item') ) {
  82.         function infinity_draw_item($class = false,$admin = false, $premium = false) {
  83.             $filename = 'loop-single';
  84.             if($premium){
  85.                 $filename .='-premium';
  86.             }
  87.             require WebThemes::newInstance()->getCurrentThemePath().$filename.'.php';
  88.         }
  89.     }
  90.     if( !function_exists('infinity_show_as') ){
  91.         function infinity_show_as(){
  92.  
  93.             $p_sShowAs    = Params::getParam('sShowAs');
  94.             $aValidShowAsValues = array('list', 'gallery');
  95.             if (!in_array($p_sShowAs, $aValidShowAsValues)) {
  96.                 $p_sShowAs = infinity_default_show_as();
  97.             }
  98.  
  99.             return $p_sShowAs;
  100.         }
  101.     }
  102.     if( !function_exists('infinity_default_show_as') ){
  103.         function infinity_default_show_as(){
  104.             return getPreference('defaultShowAs@all','infinity_theme');
  105.         }
  106.     }
  107.     if( !function_exists('infinity_draw_categories_list') ) {
  108.         function infinity_draw_categories_list(){ ?>
  109.         <?php if(!osc_is_home_page()){ echo '<div class="resp-wrapper">'; } ?>
  110.          <?php
  111.         $total_categories   = osc_count_categories();
  112.         $col1_max_cat       = ceil($total_categories/3);
  113.  
  114.          osc_goto_first_category();
  115.          $i      = 0;
  116.  
  117.          while ( osc_has_categories() ) {
  118.          ?>
  119.         <?php
  120.             if($i%$col1_max_cat == 0){
  121.                 if($i > 0) { echo '</div>'; }
  122.                 if($i == 0) {
  123.                    echo '<div class="cell_3 first_cel">';
  124.                 } else {
  125.                     echo '<div class="cell_3">';
  126.                 }
  127.             }
  128.         ?>
  129.         <ul class="r-list">
  130.              <li>
  131.                  <h1><a class="category <?php echo osc_category_slug() ; ?>" href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name() ; ?></a> <span>(<?php echo osc_category_total_items() ; ?>)</span></h1>
  132.                  <?php /**/if ( osc_count_subcategories() > 0 ) { ?>
  133.                    <ul>
  134.                          <?php while ( osc_has_subcategories() ) { ?>
  135.                              <li>
  136.                              <?php if( osc_category_total_items() > 0 ) { ?><a class="category <?php echo osc_category_slug() ; ?>" href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name() ; ?></a> <span>(<?php echo osc_category_total_items() ; ?>)</span>
  137.                              <?php } else { ?><span><?php echo osc_category_name() ; ?> (<?php echo osc_category_total_items() ; ?>)</span></li>
  138.                              <?php } ?>
  139.                          <?php } ?>
  140.                    </ul>
  141.                  <?php } ?>
  142.              </li>
  143.         </ul>
  144.         <?php
  145.                 $i++;
  146.             }
  147.             echo '</div>';
  148.         ?>
  149.         <?php if(!osc_is_home_page()){ echo '</div>'; } ?>
  150.         <?php
  151.         }
  152.     }
  153.     if( !function_exists('infinity_search_number') ) {
  154.         function infinity_search_number() {
  155.             $search_from = ((osc_search_page() * osc_default_results_per_page_at_search()) + 1);
  156.             $search_to   = ((osc_search_page() + 1) * osc_default_results_per_page_at_search());
  157.             if( $search_to > osc_search_total_items() ) {
  158.                 $search_to = osc_search_total_items();
  159.             }
  160.  
  161.             return array(
  162.                 'from' => $search_from,
  163.                 'to'   => $search_to,
  164.                 'of'   => osc_search_total_items()
  165.             );
  166.         }
  167.     }
  168.     if( !function_exists('infinity_item_title') ) {
  169.         function infinity_item_title() {
  170.             $title = osc_item_title();
  171.             foreach( osc_get_locales() as $locale ) {
  172.                 if( Session::newInstance()->_getForm('title') != "" ) {
  173.                     $title_ = Session::newInstance()->_getForm('title');
  174.                     if( @$title_[$locale['pk_c_code']] != "" ){
  175.                         $title = $title_[$locale['pk_c_code']];
  176.                     }
  177.                 }
  178.             }
  179.             return $title;
  180.         }
  181.     }
  182.     if( !function_exists('infinity_item_description') ) {
  183.         function infinity_item_description() {
  184.             $description = osc_item_description();
  185.             foreach( osc_get_locales() as $locale ) {
  186.                 if( Session::newInstance()->_getForm('description') != "" ) {
  187.                     $description_ = Session::newInstance()->_getForm('description');
  188.                     if( @$description_[$locale['pk_c_code']] != "" ){
  189.                         $description = $description_[$locale['pk_c_code']];
  190.                     }
  191.                 }
  192.             }
  193.             return $description;
  194.         }
  195.     }
  196.     if( !function_exists('related_listings') ) {
  197.         function related_listings() {
  198.             View::newInstance()->_exportVariableToView('items', array());
  199.  
  200.             $mSearch = new Search();
  201.             $mSearch->addCategory(osc_item_category_id());
  202.             $mSearch->addRegion(osc_item_region());
  203.             $mSearch->addItemConditions(sprintf("%st_item.pk_i_id < %s ", DB_TABLE_PREFIX, osc_item_id()));
  204.             $mSearch->limit('0', '3');
  205.  
  206.             $aItems      = $mSearch->doSearch();
  207.             $iTotalItems = count($aItems);
  208.             if( $iTotalItems == 3 ) {
  209.                 View::newInstance()->_exportVariableToView('items', $aItems);
  210.                 return $iTotalItems;
  211.             }
  212.             unset($mSearch);
  213.  
  214.             $mSearch = new Search();
  215.             $mSearch->addCategory(osc_item_category_id());
  216.             $mSearch->addItemConditions(sprintf("%st_item.pk_i_id != %s ", DB_TABLE_PREFIX, osc_item_id()));
  217.             $mSearch->limit('0', '3');
  218.  
  219.             $aItems = $mSearch->doSearch();
  220.             $iTotalItems = count($aItems);
  221.             if( $iTotalItems > 0 ) {
  222.                 View::newInstance()->_exportVariableToView('items', $aItems);
  223.                 return $iTotalItems;
  224.             }
  225.             unset($mSearch);
  226.  
  227.             return 0;
  228.         }
  229.     }
  230.  
  231.     if( !function_exists('osc_is_contact_page') ) {
  232.         function osc_is_contact_page() {
  233.             if( Rewrite::newInstance()->get_location() === 'contact' ) {
  234.                 return true;
  235.             }
  236.  
  237.             return false;
  238.         }
  239.     }
  240.  
  241.     if( !function_exists('get_breadcrumb_lang') ) {
  242.         function get_breadcrumb_lang() {
  243.             $lang = array();
  244.             $lang['item_add']               = __('Publish a listing', 'infinity');
  245.             $lang['item_edit']              = __('Edit your listing', 'infinity');
  246.             $lang['item_send_friend']       = __('Send to a friend', 'infinity');
  247.             $lang['item_contact']           = __('Contact publisher', 'infinity');
  248.             $lang['search']                 = __('Search results', 'infinity');
  249.             $lang['search_pattern']         = __('Search results: %s', 'infinity');
  250.             $lang['user_dashboard']         = __('Dashboard', 'infinity');
  251.             $lang['user_dashboard_profile'] = __("%s's profile", 'infinity');
  252.             $lang['user_account']           = __('Account', 'infinity');
  253.             $lang['user_items']             = __('Listings', 'infinity');
  254.             $lang['user_alerts']            = __('Alerts', 'infinity');
  255.             $lang['user_profile']           = __('Update account', 'infinity');
  256.             $lang['user_change_email']      = __('Change email', 'infinity');
  257.             $lang['user_change_username']   = __('Change username', 'infinity');
  258.             $lang['user_change_password']   = __('Change password', 'infinity');
  259.             $lang['login']                  = __('Login', 'infinity');
  260.             $lang['login_recover']          = __('Recover password', 'infinity');
  261.             $lang['login_forgot']           = __('Change password', 'infinity');
  262.             $lang['register']               = __('Create a new account', 'infinity');
  263.             $lang['contact']                = __('Contact', 'infinity');
  264.             return $lang;
  265.         }
  266.     }
  267.  
  268.     if(!function_exists('user_dashboard_redirect')) {
  269.         function user_dashboard_redirect() {
  270.             $page   = Params::getParam('page');
  271.             $action = Params::getParam('action');
  272.             if($page=='user' && $action=='dashboard') {
  273.                 if(ob_get_length()>0) {
  274.                     ob_end_flush();
  275.                 }
  276.                 header("Location: ".osc_user_list_items_url(), TRUE,301);
  277.             }
  278.         }
  279.         osc_add_hook('init', 'user_dashboard_redirect');
  280.     }
  281.  
  282.     if( !function_exists('get_user_menu') ) {
  283.         function get_user_menu() {
  284.             $options   = array();
  285.             $options[] = array(
  286.                 'name'  => __('Listings', 'infinity'),
  287.                 'url'   => osc_user_list_items_url(),
  288.                 'class' => 'opt_items'
  289.             );
  290.             $options[] = array(
  291.                 'name' => __('Alerts', 'infinity'),
  292.                 'url' => osc_user_alerts_url(),
  293.                 'class' => 'opt_alerts'
  294.             );
  295.             $options[] = array(
  296.                 'name'  => __('Account', 'infinity'),
  297.                 'url'   => osc_user_profile_url(),
  298.                 'class' => 'opt_account'
  299.             );
  300.             $options[] = array(
  301.                 'name'  => __('Change email', 'infinity'),
  302.                 'url'   => osc_change_user_email_url(),
  303.                 'class' => 'opt_change_email'
  304.             );
  305.             $options[] = array(
  306.                 'name'  => __('Change username', 'infinity'),
  307.                 'url'   => osc_change_user_username_url(),
  308.                 'class' => 'opt_change_username'
  309.             );
  310.             $options[] = array(
  311.                 'name'  => __('Change password', 'infinity'),
  312.                 'url'   => osc_change_user_password_url(),
  313.                 'class' => 'opt_change_password'
  314.             );
  315.             $options[] = array(
  316.                 'name'  => __('Delete account', 'infinity'),
  317.                 'url'   => '#',
  318.                 'class' => 'opt_delete_account'
  319.             );
  320.  
  321.             return $options;
  322.         }
  323.     }
  324.  
  325.     if( !function_exists('delete_user_js') ) {
  326.         function delete_user_js() {
  327.             $location = Rewrite::newInstance()->get_location();
  328.             $section  = Rewrite::newInstance()->get_section();
  329.             if( ($location === 'user' && in_array($section, array('dashboard', 'profile', 'alerts', 'change_email', 'change_username',  'change_password', 'items'))) || (Params::getParam('page') ==='custom' && Params::getParam('in_user_menu')==true ) ) {
  330.                 osc_enqueue_script('delete-user-js');
  331.             }
  332.         }
  333.         osc_add_hook('header', 'delete_user_js', 1);
  334.     }
  335.  
  336.     if( !function_exists('user_info_js') ) {
  337.         function user_info_js() {
  338.             $location = Rewrite::newInstance()->get_location();
  339.             $section  = Rewrite::newInstance()->get_section();
  340.  
  341.             if( $location === 'user' && in_array($section, array('dashboard', 'profile', 'alerts', 'change_email', 'change_username',  'change_password', 'items')) ) {
  342.                 $user = User::newInstance()->findByPrimaryKey( Session::newInstance()->_get('userId') );
  343.                 View::newInstance()->_exportVariableToView('user', $user);
  344.                 ?>
  345. <script type="text/javascript">
  346.     infinity.user = {};
  347.     infinity.user.id = '<?php echo osc_user_id(); ?>';
  348.     infinity.user.secret = '<?php echo osc_user_field("s_secret"); ?>';
  349. </script>
  350.             <?php }
  351.         }
  352.         osc_add_hook('header', 'user_info_js');
  353.     }
  354.  
  355.     function theme_infinity_actions_admin() {
  356.         if( Params::getParam('file') == 'oc-content/themes/infinity/admin/settings.php' ) {
  357.             if( Params::getParam('donation') == 'successful' ) {
  358.                 osc_set_preference('donation', '1', 'infinity_theme');
  359.                 osc_reset_preferences();
  360.             }
  361.         }
  362.  
  363.         switch( Params::getParam('action_specific') ) {
  364.             case('settings'):
  365.                 $footerLink  = Params::getParam('footer_link');
  366.                 $defaultLogo = Params::getParam('default_logo');
  367.  
  368.                 osc_set_preference('keyword_placeholder', Params::getParam('keyword_placeholder'), 'infinity_theme');
  369.                 osc_set_preference('footer_link', ($footerLink ? '1' : '0'), 'infinity_theme');
  370.                 osc_set_preference('default_logo', ($defaultLogo ? '1' : '0'), 'infinity_theme');
  371.                 osc_set_preference('defaultShowAs@all', Params::getParam('defaultShowAs@all'), 'infinity_theme');
  372.                 osc_set_preference('defaultShowAs@search', Params::getParam('defaultShowAs@all'));
  373.  
  374.                 osc_add_flash_ok_message(__('Theme settings updated correctly', 'infinity'), 'admin');
  375.                 osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/infinity/admin/settings.php'));
  376.             break;
  377.             case('upload_logo'):
  378.                 $package = Params::getFiles('logo');
  379.                 if( $package['error'] == UPLOAD_ERR_OK ) {
  380.                     if( move_uploaded_file($package['tmp_name'], WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg" ) ) {
  381.                         osc_add_flash_ok_message(__('The logo image has been uploaded correctly', 'infinity'), 'admin');
  382.                     } else {
  383.                         osc_add_flash_error_message(__("An error has occurred, please try again", 'infinity'), 'admin');
  384.                     }
  385.                 } else {
  386.                     osc_add_flash_error_message(__("An error has occurred, please try again", 'infinity'), 'admin');
  387.                 }
  388.                 osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/infinity/admin/header.php'));
  389.             break;
  390.             case('remove'):
  391.                 if(file_exists( WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg" ) ) {
  392.                     @unlink( WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg" );
  393.                     osc_add_flash_ok_message(__('The logo image has been removed', 'infinity'), 'admin');
  394.                 } else {
  395.                     osc_add_flash_error_message(__("Image not found", 'infinity'), 'admin');
  396.                 }
  397.                 osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/infinity/admin/header.php'));
  398.             break;
  399.         }
  400.     }
  401.  
  402.     function infinity_redirect_user_dashboard()
  403.     {
  404.         if( (Rewrite::newInstance()->get_location() === 'user') && (Rewrite::newInstance()->get_section() === 'dashboard') ) {
  405.             header('Location: ' .osc_user_list_items_url());
  406.             exit;
  407.         }
  408.     }
  409.     osc_add_hook('init', 'infinity_redirect_user_dashboard', 2);
  410.     osc_add_hook('init_admin', 'theme_infinity_actions_admin');
  411.     osc_admin_menu_appearance(__('Header logo', 'infinity'), osc_admin_render_theme_url('oc-content/themes/infinity/admin/header.php'), 'header_infinity');
  412.     osc_admin_menu_appearance(__('Theme settings', 'infinity'), osc_admin_render_theme_url('oc-content/themes/infinity/admin/settings.php'), 'settings_infinity');
  413.    
  414. check_install_infinity_theme();
  415. if(osc_is_home_page()){
  416.     osc_add_hook('inside-main','infinity_draw_categories_list');
  417. } else if( osc_is_static_page() || osc_is_contact_page() ){
  418.     osc_add_hook('before-content','infinity_draw_categories_list');
  419. }
  420.  
  421. if(osc_is_home_page() || osc_is_search_page()){
  422.     infinity_add_body_class('has-searchbox');
  423. }
  424.  
  425.  
  426. function infinity_sidebar_category_search($catId = null)
  427. {
  428.     $aCategories = array();
  429.     if($catId==null) {
  430.         $aCategories[] = Category::newInstance()->findRootCategoriesEnabled();
  431.     } else {
  432.         $aCategories = Category::newInstance()->toRootTree($catId);
  433.         end($aCategories);
  434.         $cat = current($aCategories);
  435.         $childCategories = Category::newInstance()->findSubcategories($cat['pk_i_id']);
  436.         if(count($childCategories) > 0) {
  437.             $aCategories[] = $childCategories;
  438.         }
  439.     }
  440.  
  441.     if(count($aCategories) == 0) {
  442.         return "";
  443.     }
  444.  
  445.     infinity_print_sidebar_category_search($aCategories, $catId);
  446. }
  447.  
  448. function infinity_print_sidebar_category_search($aCategories, $current_category = null, $i = 0)
  449. {
  450.     $class = '';
  451.     if(!isset($aCategories[$i])) {
  452.         return null;
  453.     }
  454.  
  455.     if($i===0) {
  456.         $class = 'class="category"';
  457.     }
  458.  
  459.     $c   = $aCategories[$i];
  460.     $i++;
  461.     if(!isset($c['pk_i_id'])) {
  462.         echo '<ul '.$class.'>';
  463.         if($i==1) {
  464.             echo '<li><a href="'.osc_esc_html(osc_update_search_url(array('sCategory'=>null))).'">'.__('Toutes les catégories')."</a></li>";
  465.         }
  466.         foreach($c as $key => $value) {
  467.     ?>
  468.             <li>
  469.                 <a id="cat_<?php echo osc_esc_html($value['pk_i_id']);?>" href="<?php echo osc_esc_html(osc_update_search_url(array('sCategory'=> $value['pk_i_id']))); ?>">
  470.                 <?php if(isset($current_category) && $current_category == $value['pk_i_id']){ echo '<strong>'.$value['s_name'].'</strong>'; }
  471.                 else{ echo $value['s_name']; } ?>
  472.                 </a>
  473.  
  474.             </li>
  475.     <?php
  476.         }
  477.         if($i==1) {
  478.         echo "</ul>";
  479.         } else {
  480.         echo "</ul>";
  481.         }
  482.     } else {
  483.     ?>
  484.     <ul <?php echo $class;?>>
  485.         <?php if($i==1) { ?>
  486.         <li><a href="<?php echo osc_esc_html(osc_update_search_url(array('sCategory'=>null))); ?>"><?php _e('Toutes les catégories'); ?></a></li>
  487.         <?php } ?>
  488.             <li>
  489.                 <a id="cat_<?php echo osc_esc_html($c['pk_i_id']);?>" href="<?php echo osc_esc_html(osc_update_search_url(array('sCategory'=> $c['pk_i_id']))); ?>">
  490.                 <?php if(isset($current_category) && $current_category == $c['pk_i_id']){ echo '<strong>'.$c['s_name'].'</strong>'; }
  491.                       else{ echo $c['s_name']; } ?>
  492.                 </a>
  493.                 <?php infinity_print_sidebar_category_search($aCategories, $current_category, $i); ?>
  494.             </li>
  495.         <?php if($i==1) { ?>
  496.         <?php } ?>
  497.     </ul>
  498. <?php
  499.     }
  500. }
  501. class infinityBodyClass
  502. {
  503.     private static $instance;
  504.     private $class;
  505.  
  506.     private function __construct()
  507.     {
  508.         $this->class = array();
  509.     }
  510.  
  511.     public static function newInstance()
  512.     {
  513.         if (  !self::$instance instanceof self)
  514.         {
  515.             self::$instance = new self;
  516.         }
  517.         return self::$instance;
  518.     }
  519.  
  520.     public function add($class)
  521.     {
  522.         $this->class[] = $class;
  523.     }
  524.     public function get()
  525.     {
  526.         return $this->class;
  527.     }
  528. }
  529. ?>
  530. <?php include('images/social.png'); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement