Esempio n. 1
0
 function rss2_builder($items = array(), $channel_options = array(), $item_options = array())
 {
     $return = array();
     $default_channel_options = array('title' => 'Please put your custom channel title in $channel_options[title]', 'description' => 'Please put your custom channel description in $channel_options[description]', 'link' => 'http://example.com/put/your/custom/link/here', 'language' => Ak::base_lang());
     $channel_parameters = array('available_options' => array('title', 'description', 'link', 'language'));
     Ak::parseOptions($channel_options, $default_channel_options, $channel_parameters);
     $default_item_options = array('title' => 'name', 'description' => 'description', 'date' => 'created_at', 'author' => false, 'link' => true, 'guid' => false);
     $item_parameters = array('available_options' => array('title', 'description', 'link', 'date', 'author', 'guid', 'content:encoded'));
     Ak::parseOptions($item_options, $default_item_options, $item_parameters);
     $return[] = $this->xml_instruct('xml', array('version' => '1.0'));
     $return[] = $this->xml_rss_open(array('version' => "2.0", 'xmlns' => array('dc' => "http://purl.org/dc/elements/1.1/", 'atom' => "http://www.w3.org/2005/Atom", 'content' => 'http://purl.org/rss/1.0/modules/content/')));
     $return[] = $this->xml_channel_open();
     $return[] = $this->xml_title($channel_options['title']);
     $return[] = $this->xml_description($channel_options['description']);
     $return[] = $this->xml_link(htmlentities($channel_options['link']));
     $return[] = $this->xml_language($channel_options['language']);
     $items = Ak::toArray($items);
     foreach ($items as $item) {
         $return[] = $this->xml_item_open();
         if (!empty($item_options['title'])) {
             $title = $this->_getValue($item, $item_options['title']);
             !empty($title) ? $return[] = $this->xml_title($title) : null;
         }
         if (!empty($item_options['link'])) {
             $item_link = $this->_getValue($item, $item_options['link']);
             !empty($item_link) ? $return[] = $this->xml_link($item_link) : null;
         }
         if (!empty($item_options['guid'])) {
             $guid = $this->_getValue($item, $item_options['guid']);
             !empty($guid) ? $return[] = $this->xml_guid($guid, strstr($guid, 'http://') ? array() : array('isPermaLink' => 'false')) : (!empty($item_link) ? $return[] = $this->xml_guid($item_link, strstr($item_link, 'http://') ? array() : array('isPermaLink' => 'false')) : null);
         }
         if (!empty($item_options['content:encoded'])) {
             $encoded = $this->_getValue($item, $item_options['content:encoded']);
             !empty($encoded) ? $return[] = $this->xml_content__encoded('<![CDATA[' . $encoded . ']]>') : null;
         }
         if (!empty($item_options['description'])) {
             $description = $this->_getValue($item, $item_options['description']);
             !empty($description) ? $return[] = $this->xml_description('<![CDATA[' . $description . ']]>') : null;
         }
         if (!empty($item_options['date'])) {
             $created_at = $this->_getValue($item, $item_options['date']);
             !empty($created_at) ? $return[] = $this->xml_dc__date($this->_generate_date($created_at)) : null;
         }
         if (!empty($item_options['author'])) {
             $author = $this->_getValue($item, $item_options['author']);
             !empty($author) ? $return[] = $this->xml_dc__author($author) : null;
         }
         $return[] = $this->xml_item_close();
     }
     $return[] = $this->xml_channel_close();
     $return[] = $this->xml_rss_close();
     return implode("\n", $return);
 }
Esempio n. 2
0
File: Ak.php Progetto: joeymetal/v1
 /**
  * Translate strings to the current locale.
  *
  * When using Ak::t(), try to put entire sentences and strings
  * in one Ak::t() call.
  * This makes it easier for translators. HTML markup within
  * translation strings
  * is acceptable, if necessary. The suggested syntax for a
  * link embedded
  * within a translation string is:
  *
  * @access public
  * @static
  * @param    string    $string    A string containing the English string to
  * translate.
  * @param    array    $args    An associative array of replacements to make after
  * translation. Incidences of any key in this array
  * are replaced with the corresponding value.
  * @return string The translated string.
  */
 function t($string, $args = null, $controller = null)
 {
     static $framework_dictionary = array(), $lang, $_dev_shutdown = true;
     if (AK_AUTOMATICALLY_UPDATE_LANGUAGE_FILES && !empty($string) && is_string($string)) {
         require_once AK_LIB_DIR . DS . 'AkLocaleManager.php';
         // This adds used strings to a stack for storing new entries on the locale file after shutdown
         AkLocaleManager::getUsedLanguageEntries($string, $controller);
         if ($_dev_shutdown) {
             register_shutdown_function(array('AkLocaleManager', 'updateLocaleFiles'));
             $_dev_shutdown = false;
         }
     }
     if (!isset($lang)) {
         if (!empty($_SESSION['lang'])) {
             $lang = $_SESSION['lang'];
         } else {
             $lang = Ak::lang();
         }
         if (is_file(AK_CONFIG_DIR . DS . 'locales' . DS . $lang . '.php')) {
             require AK_CONFIG_DIR . DS . 'locales' . DS . $lang . '.php';
             $framework_dictionary = array_merge($framework_dictionary, $dictionary);
         }
         if (!defined('AK_LOCALE')) {
             define('AK_LOCALE', $lang);
         }
         if (!empty($locale) && is_array($locale)) {
             Ak::locale(null, $lang, $locale);
         }
     }
     if (!empty($string) && is_array($string)) {
         if (!empty($string[$lang])) {
             return $string[$lang];
         }
         $try_whith_lang = $args !== false && empty($string[$lang]) ? Ak::base_lang() : $lang;
         if (empty($string[$try_whith_lang]) && $args !== false) {
             foreach (Ak::langs() as $try_whith_lang) {
                 if (!empty($string[$try_whith_lang])) {
                     return $string[$try_whith_lang];
                 }
             }
         }
         return @$string[$try_whith_lang];
     }
     if (isset($controller) && !isset($framework_dictionary[$controller . '_dictionary']) && is_file(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . $lang . '.php')) {
         require AK_APP_DIR . DS . 'locales' . DS . $controller . DS . $lang . '.php';
         $framework_dictionary[$controller . '_dictionary'] = (array) $dictionary;
     }
     if (isset($controller) && isset($framework_dictionary[$controller . '_dictionary'][$string])) {
         $string = $framework_dictionary[$controller . '_dictionary'][$string];
     } else {
         $string = isset($framework_dictionary[$string]) ? $framework_dictionary[$string] : $string;
     }
     if (isset($args) && is_array($args)) {
         $string = @str_replace(array_keys($args), array_values($args), $string);
     }
     /**
      * @todo Prepare for multiple locales by inspecting AK_DEFAULT_LOCALE
      */
     return $string;
 }
Esempio n. 3
0
File: Ak.php Progetto: joeymetal/v1
    /**
    * Translate strings to the current locale.
    *
    * When using Ak::t(), try to put entire sentences and strings
    * in one Ak::t() call.
    * This makes it easier for translators. HTML markup within
    * translation strings
    * is acceptable, if necessary. The suggested syntax for a
    * link embedded
    * within a translation string is:
    *
    * @access public
    * @static
    * @param    string    $string    A string containing the English string to
    * translate.
    * @param    array    $args    An associative array of replacements to make after
    * translation. Incidences of any key in this array
    * are replaced with the corresponding value.
    * @return string The translated string.
    */
    function t($string, $args = null, $controller = null)
    {
        static $framework_dictionary = array(),$required=false, $lang, $_dev_shutdown = true, $locale_manager_class = false, $_custom_dev_shutdown = false;
        if(!$required) {
            $required=true;
            require_once(AK_LIB_DIR.DS.'AkLocaleManager.php');
        }
        if(AK_AUTOMATICALLY_UPDATE_LANGUAGE_FILES && ($locale_manager_class == false || $locale_manager_class == 'AkLocaleManager')) {
            if(!$_custom_dev_shutdown && defined('AK_LOCALE_MANAGER') && class_exists(AK_LOCALE_MANAGER) && in_array('AkLocaleManager',class_parents(AK_LOCALE_MANAGER))) {
                $locale_manager_class = AK_LOCALE_MANAGER;
                $_custom_dev_shutdown=true;
                register_shutdown_function(array($locale_manager_class,'updateLocaleFiles'));
            } else {
                $locale_manager_class = 'AkLocaleManager';
            }
            
        } else {
            $locale_manager_class = 'AkLocaleManager';
        }
        if((AK_AUTOMATICALLY_UPDATE_LANGUAGE_FILES || (defined('AK_TEST_TRANSLATIONS') && AK_TEST_TRANSLATIONS)) && !empty($string) && is_string($string)){
            
            // This adds used strings to a stack for storing new entries on the locale file after shutdown
            call_user_func_array(array($locale_manager_class,'getUsedLanguageEntries'),array($string,$controller));
            if($_dev_shutdown && (!defined('AK_TEST_TRANSLATIONS') || !AK_TEST_TRANSLATIONS)){
                register_shutdown_function(array($locale_manager_class,'updateLocaleFiles'));
                $_dev_shutdown = false;
            }
        }

        if(!isset($lang)){
            if(!empty($_SESSION['lang'])){
                $lang =  $_SESSION['lang'];
            }else{
                $lang = Ak::lang();
            }
           
            $dictionary=call_user_func_array(array($locale_manager_class,'getCoreDictionary'),array($lang));
            $framework_dictionary = array_merge((array)$framework_dictionary,(array)$dictionary);
            
            if(!defined('AK_LOCALE')){
                define('AK_LOCALE', $lang);
            }
            if(!empty($locale) && is_array($locale)){
                Ak::locale(null, $lang, $locale);
            }
        }

        if(!empty($string) && is_array($string)){
            if(!empty($string[$lang])){
                return $string[$lang];
            }
            $try_whith_lang = $args !== false && empty($string[$lang]) ? Ak::base_lang() : $lang;
            if(empty($string[$try_whith_lang]) && $args !== false){
                foreach (Ak::langs() as $try_whith_lang){
                    if(!empty($string[$try_whith_lang])){
                        return $string[$try_whith_lang];
                    }
                }
            }
            return @$string[$try_whith_lang];
        }

        if(isset($controller) && !isset($framework_dictionary[$controller.'_dictionary'])) { // && is_file(AK_APP_DIR.DS.'locales'.DS.$controller.DS.$lang.'.php')){
             $framework_dictionary[$controller.'_dictionary'] = call_user_func_array(array($locale_manager_class,'getDictionary'),array($lang,$controller));
        }
        
        if(isset($controller) && isset($framework_dictionary[$controller.'_dictionary'][$string])){
            $string = !empty($framework_dictionary[$controller.'_dictionary'][$string])?$framework_dictionary[$controller.'_dictionary'][$string]:$string;
        }else {
            $string = !empty($framework_dictionary[$string]) ? $framework_dictionary[$string] : $string;
        }

        if(isset($args) && is_array($args)){
            $string = @str_replace(array_keys($args), array_values($args),$string);
        }
        /**
        * @todo Prepare for multiple locales by inspecting AK_DEFAULT_LOCALE
        */

        return $string;
    }