コード例 #1
0
ファイル: session.php プロジェクト: tareqy/Caracal
 /**
  * Start a new session. This function is called
  * once by main initialization script and should not
  * be used in other parts of the system.
  *
  * @note: When session is set to TYPE_NORMAL some
  * versions of IE will create new session on each page
  * load. This is due to bug in IE which accepts
  * cookies in GMT but checks for their validity in
  * local time zone. Since our cookies are set to
  * expire in 15 minutes, they are expired before they
  * are stored. Using TYPE_BROWSER solves this issue.
  */
 public static function start()
 {
     global $session_type;
     $type = $session_type;
     $normal_duration = null;
     // get current session type
     if (isset($_COOKIE[Session::COOKIE_TYPE])) {
         $type = fix_id($_COOKIE[Session::COOKIE_TYPE]);
     }
     // configure default duration
     switch ($type) {
         case Session::TYPE_BROWSER:
             session_set_cookie_params(0, Session::get_path());
             break;
         case Session::TYPE_NORMAL:
         default:
             $normal_duration = Session::DEFAULT_DURATION * 60;
             session_set_cookie_params($normal_duration, Session::get_path());
             break;
     }
     // start session
     session_name(Session::COOKIE_ID);
     session_start();
     // extend expiration for normal type
     if ($type == Session::TYPE_NORMAL) {
         setcookie(Session::COOKIE_ID, session_id(), time() + $normal_duration, Session::get_path());
         setcookie(Session::COOKIE_TYPE, Session::TYPE_NORMAL, time() + $normal_duration, Session::get_path());
     }
 }
コード例 #2
0
ファイル: page_info.php プロジェクト: tareqy/Caracal
 /**
  * Transfers control to module functions
  *
  * @param array $params
  * @param array $children
  */
 public function transferControl($params, $children)
 {
     // global control actions
     if (isset($params['action'])) {
         switch ($params['action']) {
             case 'set_omit_elements':
                 $this->omit_elements = fix_chars(explode(',', $params['elements']));
                 break;
             case 'set_optimizer_page':
                 $this->optimizer_page = fix_chars($params['page']);
                 if (isset($params['show_control'])) {
                     $this->optimizer_show_control = fix_id($params['show_control']) == 0 ? false : true;
                 }
                 break;
             case 'set_description':
                 $this->setDescription($params, $children);
                 break;
             default:
                 break;
         }
     }
     // backend control actions
     if (isset($params['backend_action'])) {
         switch ($params['backend_action']) {
             case 'show':
                 $this->showSettings();
                 break;
             case 'save':
                 $this->saveSettings();
                 break;
             default:
                 break;
         }
     }
 }
コード例 #3
0
ファイル: page_switch.php プロジェクト: tareqy/Caracal
 /**
  * Constructor
  *
  * @param string $param_name
  */
 public function __construct($param_name = null)
 {
     if (!is_null($param_name)) {
         $this->param_name = $param_name;
     }
     if (isset($_REQUEST[$this->param_name])) {
         $this->current_page = fix_id($_REQUEST[$this->param_name]);
     }
 }
コード例 #4
0
ファイル: search.php プロジェクト: tareqy/Caracal
 /**
  * Handle printing search results
  *
  * Modules need to return results in following format:
  * array(
  *			array(
  * 				'score'			=> 0..100	// score for this result
  * 				'title'			=> '',		// title to be shown in list
  *				'description'	=> '',		// short description, if exists
  *				'id'			=> 0,		// id of containing item
  *				'type'			=> '',		// type of item
  *				'module'		=> ''		// module name
  *			),
  *			...
  * 		);
  * 
  * Resulting array doesn't need to be sorted.
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_ResultList($tag_params, $children)
 {
     // get search query
     $query_string = null;
     $threshold = 25;
     $limit = 30;
     // get query
     if (isset($tag_params['query'])) {
         $query_string = mb_strtolower(fix_chars($tag_params['query']));
     }
     if (isset($_REQUEST['query']) && is_null($query_string)) {
         $query_string = mb_strtolower(fix_chars($_REQUEST['query']));
     }
     if (is_null($query_string)) {
         return;
     }
     // get threshold
     if (isset($tag_params['threshold'])) {
         $threshold = fix_chars($tag_params['threshold']);
     }
     if (isset($_REQUEST['threshold']) && is_null($threshold)) {
         $threshold = fix_chars($_REQUEST['threshold']);
     }
     // get limit
     if (isset($tag_params['limit'])) {
         $limit = fix_id($tag_params['limit']);
     }
     // get list of modules to search on
     $module_list = null;
     if (isset($tag_params['module_list'])) {
         $module_list = fix_chars(split(',', $tag_params['module_list']));
     }
     if (isset($_REQUEST['module_list']) && is_null($module_list)) {
         $module_list = fix_chars(split(',', $_REQUEST['module_list']));
     }
     if (is_null($module_list)) {
         $module_list = array_keys($this->modules);
     }
     // get intersection of available and specified modules
     $available_modules = array_keys($this->modules);
     $module_list = array_intersect($available_modules, $module_list);
     // get results from modules
     $results = array();
     if (count($module_list) > 0) {
         foreach ($module_list as $name) {
             $module = $this->modules[$name];
             $results = array_merge($results, $module->getSearchResults($query_string, $threshold));
         }
     }
     // sort results
     usort($results, array($this, 'sortResults'));
     // apply limit
     if ($limit > 0) {
         $results = array_slice($results, 0, $limit);
     }
     // load template
     $template = $this->loadTemplate($tag_params, 'result.xml');
     // parse results
     if (count($results) > 0) {
         foreach ($results as $params) {
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }
コード例 #5
0
/**
 * Apply whatever escaping is requested to the given value.
 *
 * @param  array			A list of escaping to do
 * @param  string			The string to apply the escapings to
 * @return string			Output string
 */
function apply_tempcode_escaping_inline($escaped, $value)
{
    global $HTML_ESCAPE_1_STRREP, $HTML_ESCAPE_2;
    foreach (array_reverse($escaped) as $escape) {
        if ($escape == ENTITY_ESCAPED) {
            $value = str_replace($HTML_ESCAPE_1_STRREP, $HTML_ESCAPE_2, $value);
        } elseif ($escape == FORCIBLY_ENTITY_ESCAPED) {
            $value = str_replace($HTML_ESCAPE_1_STRREP, $HTML_ESCAPE_2, $value);
        } elseif ($escape == SQ_ESCAPED) {
            $value = str_replace(''', '\\'', str_replace('\'', '\\\'', str_replace('\\', '\\\\', $value)));
        } elseif ($escape == DQ_ESCAPED) {
            $value = str_replace('"', '\\"', str_replace('"', '\\"', str_replace('\\', '\\\\', $value)));
        } elseif ($escape == NL_ESCAPED) {
            $value = str_replace(chr(13), '', str_replace(chr(10), '', $value));
        } elseif ($escape == NL2_ESCAPED) {
            $value = str_replace(chr(13), '', str_replace(chr(10), '\\n', $value));
        } elseif ($escape == CC_ESCAPED) {
            $value = str_replace('[', '\\[', str_replace('\\', '\\\\', $value));
        } elseif ($escape == UL_ESCAPED) {
            $value = ocp_url_encode($value);
        } elseif ($escape == UL2_ESCAPED) {
            $value = rawurlencode($value);
        } elseif ($escape == JSHTML_ESCAPED) {
            $value = str_replace(']]>', ']]\'+\'>', str_replace('</', '<\\/', $value));
        } elseif ($escape == ID_ESCAPED) {
            $value = fix_id($value);
        } elseif ($escape == CSS_ESCAPED) {
            $value = preg_replace('#[^\\w\\#\\.\\-\\%]#', '_', $value);
        } elseif ($escape == NAUGHTY_ESCAPED) {
            $value = filter_naughty_harsh($value, true);
        }
    }
    if ($GLOBALS['XSS_DETECT'] && $escaped != array()) {
        ocp_mark_as_escaped($value);
    }
    return $value;
}
コード例 #6
0
ファイル: feedback.php プロジェクト: erico-deh/ocPortal
/**
 * Add comments to the specified resource.
 *
 * @param  boolean		Whether this resource allows comments (if not, this function does nothing - but it's nice to move out this common logic into the shared function)
 * @param  ID_TEXT		The type (download, etc) that this commenting is for
 * @param  ID_TEXT		The ID of the type that this commenting is for
 * @param  mixed			The URL to where the commenting will pass back to (to put into the comment topic header) (URLPATH or Tempcode)
 * @param  ?string		The title to where the commenting will pass back to (to put into the comment topic header) (NULL: don't know, but not first post so not important)
 * @param  ?string		The name of the forum to use (NULL: default comment forum)
 * @param  boolean		Whether to not require a captcha
 * @param  ?BINARY		Whether the post is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). This only works with the OCF driver (hence is the last parameter).
 * @param  boolean		Whether to force allowance
 * @param  boolean		Whether to skip a success message
 * @param  boolean		Whether posts made should not be shared
 * @return boolean		Whether a hidden post has been made
 */
function actualise_post_comment($allow_comments, $content_type, $content_id, $content_url, $content_title, $forum = NULL, $avoid_captcha = false, $validated = NULL, $explicit_allow = false, $no_success_message = false, $private = false)
{
    if (!$explicit_allow) {
        if (get_option('is_on_comments') == '0' || !$allow_comments) {
            return false;
        }
        if (!has_specific_permission(get_member(), 'comment', get_page_name())) {
            return false;
        }
    }
    if (running_script('preview')) {
        return false;
    }
    $forum_tie = get_option('is_on_strong_forum_tie') == '1';
    if (addon_installed('captcha')) {
        if (array_key_exists('post', $_POST) && $_POST['post'] != '' && !$avoid_captcha) {
            require_code('captcha');
            enforce_captcha();
        }
    }
    $post_title = post_param('title', NULL);
    if (is_null($post_title) && !$forum_tie) {
        return false;
    }
    $post = post_param('post', NULL);
    if ($post == do_lang('POST_WARNING')) {
        $post = '';
    }
    if ($post == do_lang('THREADED_REPLY_NOTICE', do_lang('POST_WARNING'))) {
        $post = '';
    }
    if ($post == '' && $post_title !== '') {
        $post = $post_title;
        $post_title = '';
    }
    if ($post === '') {
        warn_exit(do_lang_tempcode('NO_PARAMETER_SENT', 'post'));
    }
    if (is_null($post)) {
        $post = '';
    }
    $email = trim(post_param('email', ''));
    if ($email != '') {
        $body = '> ' . str_replace(chr(10), chr(10) . '> ', $post);
        if (substr($body, -2) == '> ') {
            $body = substr($body, 0, strlen($body) - 2);
        }
        if (get_page_name() != 'tickets') {
            $post .= '[staff_note]';
        }
        $post .= "\n\n" . '[email subject="Re: ' . comcode_escape($post_title) . ' [' . get_site_name() . ']" body="' . comcode_escape($body) . '"]' . $email . '[/email]' . "\n\n";
        if (get_page_name() != 'tickets') {
            $post .= '[/staff_note]';
        }
    }
    $content_title = strip_comcode($content_title);
    if (is_null($forum)) {
        $forum = get_option('comments_forum_name');
    }
    $content_url_flat = is_object($content_url) ? $content_url->evaluate() : $content_url;
    $_parent_id = post_param('parent_id', '');
    $parent_id = $_parent_id == '' ? NULL : intval($_parent_id);
    $poster_name_if_guest = post_param('poster_name_if_guest', '');
    list($topic_id, $is_hidden) = $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum, $content_type . '_' . $content_id, get_member(), $post_title, $post, $content_title, do_lang('COMMENT'), $content_url_flat, NULL, NULL, $validated, $explicit_allow ? 1 : NULL, $explicit_allow, $poster_name_if_guest, $parent_id, false, !$private && $post != '' ? 'comment_posted' : NULL, !$private && $post != '' ? $content_type . '_' . $content_id : NULL);
    if (!is_null($topic_id)) {
        if (!is_integer($forum)) {
            $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum);
        } else {
            $forum_id = (int) $forum;
        }
        if (get_forum_type() == 'ocf' && !is_null($GLOBALS['LAST_POST_ID'])) {
            $extra_review_ratings = array();
            global $REVIEWS_STRUCTURE;
            if (array_key_exists($content_type, $REVIEWS_STRUCTURE)) {
                $reviews_rating_criteria = $REVIEWS_STRUCTURE[$content_type];
            } else {
                $reviews_rating_criteria[] = '';
            }
            foreach ($reviews_rating_criteria as $rating_type) {
                // Has there actually been any rating?
                $rating = post_param_integer('review_rating__' . fix_id($rating_type), NULL);
                if (!is_null($rating)) {
                    if ($rating > 10 || $rating < 1) {
                        log_hack_attack_and_exit('VOTE_CHEAT');
                    }
                    $GLOBALS['SITE_DB']->query_insert('review_supplement', array('r_topic_id' => $GLOBALS['LAST_TOPIC_ID'], 'r_post_id' => $GLOBALS['LAST_POST_ID'], 'r_rating_type' => $rating_type, 'r_rating_for_type' => $content_type, 'r_rating_for_id' => $content_id, 'r_rating' => $rating));
                }
            }
        }
    }
    if (!$private && $post != '') {
        list(, $submitter, , $safe_content_url, $cma_info) = get_details_behind_feedback_code($content_type, $content_id);
        $content_type_title = $content_type;
        if (!is_null($cma_info) && isset($cma_info['content_type_label'])) {
            $content_type_title = do_lang($cma_info['content_type_label']);
        }
        // Notification
        require_code('notifications');
        $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $subject = do_lang('NEW_COMMENT_SUBJECT', get_site_name(), $content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title, array($post_title, $username), get_site_default_lang());
        $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $message_raw = do_lang('NEW_COMMENT_BODY', comcode_escape(get_site_name()), comcode_escape($content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title), array($post_title == '' ? do_lang('NO_SUBJECT') : $post_title, post_param('post'), comcode_escape($content_url_flat), comcode_escape($username)), get_site_default_lang());
        dispatch_notification('comment_posted', $content_type . '_' . $content_id, $subject, $message_raw);
        // Is the user gonna automatically enable notifications for this?
        if (get_forum_type() == 'ocf') {
            $auto_monitor_contrib_content = $GLOBALS['OCF_DRIVER']->get_member_row_field(get_member(), 'm_auto_monitor_contrib_content');
            if ($auto_monitor_contrib_content == 1) {
                enable_notifications('comment_posted', $content_type . '_' . $content_id);
            }
        }
        // Activity
        $real_content_type = convert_ocportal_type_codes('feedback_type_code', $content_type, 'cma_hook');
        if (may_view_content_behind_feedback_code($GLOBALS['FORUM_DRIVER']->get_guest_id(), $real_content_type, $content_id)) {
            if (is_null($submitter)) {
                $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id();
            }
            $activity_type = is_null($submitter) || is_guest($submitter) ? '_ADDED_COMMENT_ON' : 'ADDED_COMMENT_ON';
            if ($content_title == '') {
                syndicate_described_activity($activity_type . '_UNTITLED', ocp_mb_strtolower($content_type_title), $content_type_title, '', url_to_pagelink(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), '', '', convert_ocportal_type_codes('feedback_type_code', $content_type, 'addon_name'), 1, NULL, false, $submitter);
            } else {
                syndicate_described_activity($activity_type, $content_title, ocp_mb_strtolower($content_type_title), $content_type_title, url_to_pagelink(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), '', '', convert_ocportal_type_codes('feedback_type_code', $content_type, 'addon_name'), 1, NULL, false, $submitter);
            }
        }
    }
    if ($post != '' && $forum_tie && !$no_success_message) {
        require_code('site2');
        assign_refresh($GLOBALS['FORUM_DRIVER']->topic_url($GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier($forum, $content_type . '_' . $content_id), $forum), 0.0);
    }
    if ($post != '' && !$no_success_message) {
        attach_message(do_lang_tempcode('SUCCESS'));
    }
    return $is_hidden;
}
コード例 #7
0
 /**
  * Handle item size values tag
  * 
  * @param array $tag_params
  * @param array $childen
  */
 public function tag_ValueList($tag_params, $children)
 {
     $manager = ShopItemSizeValuesManager::getInstance();
     $conditions = array();
     // create conditions
     if (isset($tag_params['definition'])) {
         $conditions['definition'] = fix_id($tag_params['definition']);
     }
     // get items from database
     $items = $manager->getItems($manager->getFieldNames(), $conditions);
     // create template
     $template = $this->_parent->loadTemplate($tag_params, 'values_list_item.xml');
     $template->setMappedModule($this->name);
     // parse template
     if (count($items) > 0) {
         foreach ($items as $item) {
             $params = array('id' => $item->id, 'value' => $item->value, 'item_change' => url_MakeHyperlink($this->_parent->getLanguageConstant('change'), window_Open('shop_item_size_values_change', 370, $this->_parent->getLanguageConstant('title_size_value_change'), true, true, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'sizes'), array('sub_action', 'value_change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->_parent->getLanguageConstant('delete'), window_Open('shop_item_size_values_delete', 400, $this->_parent->getLanguageConstant('title_size_value_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'sizes'), array('sub_action', 'value_delete'), array('id', $item->id)))));
             $template->restoreXML();
             $template->setLocalParams($params);
             $template->parse();
         }
     }
 }
コード例 #8
0
ファイル: user_manager.php プロジェクト: tareqy/Caracal
 /**
  * Perform user removal
  */
 private function deleteUser_Commit()
 {
     $id = fix_id($_REQUEST['id']);
     $manager = UserManager::getInstance();
     // trigger event
     $user = $manager->getSingleItem($manager->getFieldNames(), array('id' => $id));
     Events::trigger('backend', 'user-delete', $user);
     // remove user from database
     $manager->deleteData(array('id' => $id));
     $template = new TemplateHandler('message.xml', $this->parent->path . 'templates/');
     $template->setMappedModule($this->parent->name);
     $params = array('message' => $this->parent->getLanguageConstant('message_users_deleted'), 'button' => $this->parent->getLanguageConstant('close'), 'action' => window_Close('system_users_delete') . ';' . window_ReloadContent('system_users'));
     $template->restoreXML();
     $template->setLocalParams($params);
     $template->parse();
 }
コード例 #9
0
ファイル: delivery.php プロジェクト: Way2CU/Bali-Shuk-Store
 /**
  * Handle drawing time list.
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_Times($tag_params, $children)
 {
     $manager = IntervalTimeManager::getInstance();
     $conditions = array();
     $order_by = array('start');
     if (isset($tag_params['interval'])) {
         $conditions['interval'] = fix_id($tag_params['interval']);
     } else {
         $conditions['interval'] = -1;
     }
     // get all times
     $times = $manager->getItems($manager->getFieldNames(), $conditions, $order_by, True);
     // load template
     $template = $this->loadTemplate($tag_params, 'time.xml');
     if (count($times) > 0) {
         foreach ($times as $time) {
             $params = array('start' => $time->start, 'end' => $time->end, 'price' => $time->amount);
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }
コード例 #10
0
ファイル: comments.php プロジェクト: tareqy/Caracal
 /**
  * Print JSON object containing all the comments
  * 
  * @param boolean $only_visible
  */
 private function printCommentData($only_visible = true)
 {
     $module = isset($_REQUEST['module']) && !empty($_REQUEST['module']) ? fix_chars($_REQUEST['module']) : null;
     $comment_section = isset($_REQUEST['comment_section']) && !empty($_REQUEST['comment_section']) ? fix_chars($_REQUEST['comment_section']) : null;
     $result = array();
     if (!is_null($module) || !is_null($comment_section)) {
         $result['error'] = 0;
         $result['error_message'] = '';
         $starting_with = isset($_REQUEST['starting_with']) ? fix_id($_REQUEST['starting_with']) : null;
         $manager = CommentManager::getInstance();
         $conditions = array('module' => $module, 'section' => $comment_section);
         if (!is_null($starting_with)) {
             $conditions['id'] = array('operator' => '>', 'value' => $starting_with);
         }
         if ($only_visible) {
             $conditions['visible'] = 1;
         }
         $items = $manager->getItems(array('id', 'user', 'message', 'timestamp'), $conditions);
         $result['last_id'] = 0;
         $result['comments'] = array();
         if (count($items) > 0) {
             foreach ($items as $item) {
                 $timestamp = strtotime($item->timestamp);
                 $date = date($this->getLanguageConstant('format_date_short'), $timestamp);
                 $time = date($this->getLanguageConstant('format_time_short'), $timestamp);
                 $result['comments'][] = array('id' => $item->id, 'user' => empty($item->user) ? 'Anonymous' : $item->user, 'content' => $item->message, 'date' => $date, 'time' => $time);
             }
             $result['last_id'] = end($items)->id;
         }
     } else {
         // no comments_section and/or module specified
         $result['error'] = 1;
         $result['error_message'] = $this->getLanguageConstant('message_error_data');
     }
     print json_encode($result);
 }
コード例 #11
0
 /**
  * Tag handler for category list
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_CategoryList($tag_params, $children)
 {
     global $language;
     $manager = ShopCategoryManager::getInstance();
     $conditions = array();
     $order_by = array();
     $order_asc = true;
     $item_category_ids = array();
     $item_id = isset($tag_params['item_id']) ? fix_id($tag_params['item_id']) : null;
     // create conditions
     if (isset($tag_params['parent_id'])) {
         // set parent from tag parameter
         $conditions['parent'] = fix_id($tag_params['parent_id']);
     } else {
         if (isset($tag_params['parent'])) {
             // get parent id from specified text id
             $text_id = fix_chars($tag_params['parent']);
             $parent = $manager->getSingleItem(array('id'), array('text_id' => $text_id));
             if (is_object($parent)) {
                 $conditions['parent'] = $parent->id;
             } else {
                 $conditions['parent'] = -1;
             }
         } else {
             if (!isset($tag_params['show_all'])) {
                 $conditions['parent'] = 0;
             }
         }
     }
     if (isset($tag_params['level'])) {
         $level = fix_id($tag_params['level']);
     } else {
         $level = 0;
     }
     if (isset($tag_params['exclude'])) {
         $list = fix_id(explode(',', $tag_params['exclude']));
         $conditions['id'] = array('operator' => 'NOT IN', 'value' => $list);
     }
     if (!is_null($item_id)) {
         $membership_manager = ShopItemMembershipManager::getInstance();
         $membership_items = $membership_manager->getItems(array('category'), array('item' => $item_id));
         if (count($membership_items) > 0) {
             foreach ($membership_items as $membership) {
                 $item_category_ids[] = $membership->category;
             }
         }
     }
     // get order list
     if (isset($tag_params['order_by'])) {
         $order_by = fix_chars(split(',', $tag_params['order_by']));
     } else {
         $order_by = array('title_' . $language);
     }
     if (isset($tag_params['order_ascending'])) {
         $order_asc = $tag_params['order_asc'] == '1' or $tag_params['order_asc'] == 'yes';
     } else {
         // get items from database
         $items = $manager->getItems($manager->getFieldNames(), $conditions, $order_by, $order_asc);
     }
     // create template handler
     $template = $this->_parent->loadTemplate($tag_params, 'category_list_item.xml');
     $template->registerTagHandler('_children', $this, 'tag_CategoryList');
     // initialize index
     $index = 0;
     // parse template
     if (count($items) > 0) {
         foreach ($items as $item) {
             $image_url = '';
             $thumbnail_url = '';
             if (class_exists('gallery')) {
                 $gallery = gallery::getInstance();
                 $gallery_manager = GalleryManager::getInstance();
                 $image = $gallery_manager->getSingleItem(array('filename'), array('id' => $item->image));
                 if (!is_null($image)) {
                     $image_url = $gallery->getImageURL($image);
                     $thumbnail_url = $gallery->getThumbnailURL($image);
                 }
             }
             $params = array('id' => $item->id, 'index' => $index++, 'item_id' => $item_id, 'parent' => $item->parent, 'image_id' => $item->image, 'image' => $image_url, 'thumbnail' => $thumbnail_url, 'text_id' => $item->text_id, 'title' => $item->title, 'description' => $item->description, 'level' => $level, 'in_category' => in_array($item->id, $item_category_ids) ? 1 : 0, 'selected' => isset($tag_params['selected']) ? fix_id($tag_params['selected']) : 0, 'item_change' => url_MakeHyperlink($this->_parent->getLanguageConstant('change'), window_Open('shop_category_change', 400, $this->_parent->getLanguageConstant('title_category_change'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'categories'), array('sub_action', 'change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->_parent->getLanguageConstant('delete'), window_Open('shop_category_delete', 270, $this->_parent->getLanguageConstant('title_category_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'categories'), array('sub_action', 'delete'), array('id', $item->id)))), 'item_add' => url_MakeHyperlink($this->_parent->getLanguageConstant('add'), window_Open('shop_category_add', 400, $this->_parent->getLanguageConstant('title_category_add'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'categories'), array('sub_action', 'add'), array('parent', $item->id)))));
             $template->restoreXML();
             $template->setLocalParams($params);
             $template->parse();
         }
     }
 }
コード例 #12
0
 /**
  * Handle displaying list of stored currencies
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_CurrencyList($tag_params, $children)
 {
     $manager = ShopCurrenciesManager::getInstance();
     $conditions = array();
     $items = $manager->getItems($manager->getFieldNames(), $conditions);
     // create template
     $template = $this->_parent->loadTemplate($tag_params, 'currency_list_item.xml');
     $template->setMappedModule($this->name);
     $selected = isset($tag_params['selected']) ? fix_id($tag_params['selected']) : -1;
     // parse template
     if (count($items) > 0) {
         foreach ($items as $item) {
             $params = $this->getCurrencyForCode($item->currency);
             $params['selected'] = $selected;
             // add delete link to params
             $params['item_delete'] = url_MakeHyperlink($this->_parent->getLanguageConstant('delete'), window_Open('shop_currencies_delete', 270, $this->_parent->getLanguageConstant('title_currencies_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'currencies'), array('sub_action', 'delete'), array('id', $item->id))));
             $template->restoreXML();
             $template->setLocalParams($params);
             $template->parse();
         }
     }
 }
コード例 #13
0
ファイル: links.php プロジェクト: tareqy/Caracal
 /**
  * Create JSON object containing group items
  */
 private function json_GroupList()
 {
     define('_OMIT_STATS', 1);
     $groups = array();
     $conditions = array();
     $limit = isset($tag_params['limit']) ? fix_id($tag_params['limit']) : null;
     $order_by = isset($tag_params['order_by']) ? explode(',', fix_chars($tag_params['order_by'])) : array('id');
     $order_asc = isset($tag_params['order_asc']) && $tag_params['order_asc'] == 'yes' ? true : false;
     $manager = LinkGroupsManager::getInstance();
     $items = $manager->getItems($manager->getFieldNames(), $conditions, $order_by, $order_asc, $limit);
     $result = array('error' => false, 'error_message' => '', 'items' => array());
     if (count($items) > 0) {
         foreach ($items as $item) {
             $result['items'][] = array('id' => $item->id, 'name' => $item->name);
         }
     } else {
     }
     print json_encode($result);
 }
コード例 #14
0
 /**
  * Handle updating transaction status through AJAX request
  */
 public function json_UpdateTransactionStatus()
 {
     $manager = ShopTransactionsManager::getInstance();
     $id = fix_id($_REQUEST['id']);
     $status = fix_id($_REQUEST['status']);
     $result = false;
     $transaction = null;
     if ($_SESSION['logged']) {
         // get transaction
         $transaction = $manager->getSingleItem(array('id'), array('id' => $id));
         // update status
         if (is_object($transaction)) {
             $manager->updateData(array('status' => $status), array('id' => $id));
             $result = true;
         }
     }
     print json_encode($result);
 }
コード例 #15
0
ファイル: shop.php プロジェクト: tareqy/Caracal
 /**
  * Handle drawing recurring payment cycle units.
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_CycleUnit($tag_params, $children)
 {
     $units = array(RecurringPayment::DAY => $this->getLanguageConstant('cycle_day'), RecurringPayment::WEEK => $this->getLanguageConstant('cycle_week'), RecurringPayment::MONTH => $this->getLanguageConstant('cycle_month'), RecurringPayment::YEAR => $this->getLanguageConstant('cycle_year'));
     $selected = isset($tag_params['selected']) ? fix_id($tag_params['selected']) : null;
     $template = $this->loadTemplate($tag_params, 'cycle_unit_option.xml');
     foreach ($units as $id => $text) {
         $params = array('id' => $id, 'text' => $text, 'selected' => $id == $selected);
         $template->restoreXML();
         $template->setLocalParams($params);
         $template->parse();
     }
 }
コード例 #16
0
ファイル: contact_form.php プロジェクト: tareqy/Caracal
 /**
  * Show submission data.
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_SubmissionFields($tag_params, $children)
 {
     global $language;
     $conditions = array();
     $form_field_manager = ContactForm_FormFieldManager::getInstance();
     $submission_manager = ContactForm_SubmissionManager::getInstance();
     $submission_field_manager = ContactForm_SubmissionFieldManager::getInstance();
     // get conditional parameters
     $submission_id = null;
     if (isset($tag_params['submission'])) {
         $submission_id = fix_id($tag_params['submission']);
     }
     // we require submission to be specified
     if (is_null($submission_id)) {
         trigger_error('Submission fields tag: No submission id specified.', E_USER_NOTICE);
         return;
     }
     // get submission for specified id
     $submission = $submission_manager->getSingleItem($submission_manager->getFieldNames(), array('id' => $submission_id));
     if (!is_object($submission)) {
         trigger_error('Submission fields tag: Unknown submission.', E_USER_NOTICE);
         return;
     }
     // get form fields
     $raw_fields = $form_field_manager->getItems($form_field_manager->getFieldNames(), array('form' => $submission->form));
     $fields = array();
     foreach ($raw_fields as $field) {
         $fields[$field->id] = $field;
     }
     // load submission data
     $items = $submission_field_manager->getItems($submission_field_manager->getFieldNames(), array('submission' => $submission->id));
     // load template
     $template = $this->loadTemplate($tag_params, 'submission_field.xml');
     if (count($items) > 0) {
         foreach ($items as $item) {
             $field = $fields[$item->field];
             $text = $field->name;
             if (!empty($field->placeholder[$language])) {
                 $text = $field->placeholder[$language];
             }
             if (!empty($field->label[$language])) {
                 $text = $field->label[$language];
             }
             $params = array('submission' => $submission->id, 'form' => $submission->form, 'field' => $item->field, 'value' => $item->value, 'label' => $field->label, 'placeholder' => $field->placeholder, 'text' => $text, 'type' => $field->type, 'name' => $field->name);
             $template->restoreXML();
             $template->setLocalParams($params);
             $template->parse();
         }
     }
 }
コード例 #17
0
ファイル: code_project.php プロジェクト: tareqy/Caracal
 /**
  * Remove specified `code` object and inform user about operation status
  */
 private function deleteCode_Commit()
 {
     $id = fix_id(fix_chars($_REQUEST['id']));
     $manager = CodeManager::getInstance();
     $manager->deleteData(array('id' => $id));
     $template = new TemplateHandler('message.xml', $this->path . 'templates/');
     $template->setMappedModule($this->name);
     $params = array('message' => $this->getLanguageConstant("message_code_deleted"), 'button' => $this->getLanguageConstant("close"), 'action' => window_Close('codes_delete') . ";" . window_ReloadContent('codes_manage'));
     $template->restoreXML();
     $template->setLocalParams($params);
     $template->parse();
 }
コード例 #18
0
ファイル: downloads.php プロジェクト: tareqy/Caracal
 /**
  * Record download count and redirect to existing file
  */
 private function redirectDownload()
 {
     $id = isset($_REQUEST['id']) ? fix_id($_REQUEST['id']) : null;
     $manager = DownloadsManager::getInstance();
     if (!is_null($id)) {
         $item = $manager->getSingleItem(array('count', 'filename'), array('id' => $id));
         // update count
         $manager->updateData(array('count' => $item->count + 1), array('id' => $id));
         // redirect
         $url = $this->_getDownloadURL($item);
         header("Location: {$url}");
     } else {
         die('Invalid download ID!');
     }
 }
コード例 #19
0
ファイル: tips.php プロジェクト: tareqy/Caracal
 /**
  * Return JSON list of tips.
  */
 public function json_TipList()
 {
     global $language;
     $conditions = array();
     $limit = null;
     $order_by = isset($_REQUEST['random']) && $_REQUEST['random'] == 'yes' ? 'RAND()' : 'id';
     $order_asc = isset($_REQUEST['order_asc']) && $_REQUEST['order_asc'] == 'yes';
     $all_languages = isset($_REQUEST['all_languages']) && $_REQUEST['all_languages'] == 'yes';
     if (isset($_REQUEST['id'])) {
         $conditions['id'] = fix_id(explode(',', $_REQUEST['id']));
     }
     if (isset($_REQUEST['only_visible']) && $_REQUEST['only_visible'] == 'yes') {
         $conditions['visible'] = 1;
     }
     if (isset($_REQUEST['limit'])) {
         $limit = fix_id($_REQUEST['limit']);
     }
     $manager = TipManager::getInstance();
     $items = $manager->getItems($manager->getFieldNames(), $conditions, array($order_by), $order_asc, $limit);
     $result = array('error' => false, 'error_message' => '', 'items' => array());
     if (count($items) > 0) {
         foreach ($items as $item) {
             $result['items'][] = array('id' => $item->id, 'content' => $all_languages ? $item->content : $item->content[$language], 'visible' => $item->visible);
         }
     }
     print json_encode($result);
 }
コード例 #20
0
ファイル: articles.php プロジェクト: tareqy/Caracal
 /**
  * Function to record vote from AJAX call
  */
 private function json_Vote()
 {
     $id = fix_id($_REQUEST['id']);
     $value = $_REQUEST['value'];
     $manager = ArticleManager::getInstance();
     $vote_manager = ArticleVoteManager::getInstance();
     $vote = $vote_manager->getSingleItem(array('id'), array('article' => $id, 'address' => $_SERVER['REMOTE_ADDR']));
     $result = array('error' => false, 'error_message' => '');
     if (is_object($vote)) {
         // that address already voted
         $result['error'] = true;
         $result['error_message'] = $this->getLanguageConstant('message_vote_already');
     } else {
         // stupid but we need to make sure article exists
         $article = $manager->getSingleItem(array('id', 'votes_up', 'votes_down'), array('id' => $id));
         if (is_object($article)) {
             $vote_manager->insertData(array('article' => $article->id, 'address' => $_SERVER['REMOTE_ADDR']));
             if (is_numeric($value)) {
                 $data = array('votes_up' => $article->votes_up, 'votes_down' => $article->votes_down);
                 if ($value == -1) {
                     $data['votes_down']++;
                 }
                 if ($value == 1) {
                     $data['votes_up']++;
                 }
                 $manager->updateData($data, array('id' => $article->id));
             }
             $article = $manager->getSingleItem(array('id', 'votes_up', 'votes_down'), array('id' => $id));
             $result['rating'] = $this->getArticleRating($article, 10);
         } else {
             $result['error'] = true;
             $result['error_message'] = $this->getLanguageConstant('message_vote_error');
         }
     }
     print json_encode($result);
 }
コード例 #21
0
 /**
  * Handle drawing list of Sapphire Waves users.
  *
  * @param array $tag_params
  * @param array $children
  * @return void
  */
 public function tag_UserList($tag_params, $children)
 {
     $manager = SapphireWavesManager::getInstance();
     $conditions = array();
     if (array_key_exists('referral', $tag_params)) {
         $conditions['referral'] = fix_id($tag_params['referral']);
     }
     // load template
     $template = $this->loadTemplate($tag_params, 'user.xml');
     // get user data from the database
     $items = $manager->getItems($manager->getFieldNames(), $conditions);
     if (count($items) > 0) {
         foreach ($items as $item) {
             $params = array('id' => $item->id, 'type' => $item->type, 'user' => $item->user, 'referral' => $item->referral, 'remaining_time' => $item->remaining_time, 'total_time' => $item->total_time, 'timestamp' => $item->timestamp);
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }
コード例 #22
0
ファイル: shop_item_handler.php プロジェクト: tareqy/Caracal
 /**
  * Handle printing colors for specified item
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_ColorList($tag_params, $children)
 {
     $id = null;
     $manager = ShopItemManager::getInstance();
     if (isset($tag_params['id'])) {
         $id = fix_id($tag_params['id']);
     }
     if (is_null($id)) {
         return;
     }
     // get specified item
     $item = $manager->getSingleItem($manager->getFieldNames(), array('id' => $id));
     if (!is_object($item)) {
         return;
     }
     // load template
     $template = $this->_parent->loadTemplate($tag_params, 'color_preview.xml');
     if (empty($item->colors)) {
         return;
     }
     $colors = explode(',', $item->colors);
     if (count($colors) > 0) {
         foreach ($colors as $color) {
             $data = explode(':', $color);
             $params = array('name' => $data[0], 'value' => $data[1]);
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }
コード例 #23
0
 /**
  * Handle drawing list of manufacturers tag
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_ManufacturerList($tag_params, $children)
 {
     $manager = ShopManufacturerManager::getInstance();
     $conditions = array();
     $selected = -1;
     if (class_exists('gallery')) {
         $use_images = true;
         $gallery = gallery::getInstance();
         $gallery_manager = GalleryManager::getInstance();
     } else {
         $use_images = false;
     }
     if (isset($tag_params['selected'])) {
         $selected = fix_id($tag_params['selected']);
     }
     $items = $manager->getItems($manager->getFieldNames(), $conditions);
     $template = $this->_parent->loadTemplate($tag_params, 'manufacturer_list_item.xml');
     if (count($items) > 0) {
         foreach ($items as $item) {
             // get image
             $image = '';
             if ($use_images && !empty($item->logo)) {
                 $image_item = $gallery_manager->getSingleItem($gallery_manager->getFieldNames(), array('id' => $item->logo));
                 if (is_object($image_item)) {
                     $image = $gallery->getImageURL($image_item);
                 }
             }
             // prepare parameters
             $params = array('id' => $item->id, 'name' => $item->name, 'web_site' => $item->web_site, 'logo' => $image, 'selected' => $selected == $item->id ? 1 : 0, 'item_change' => url_MakeHyperlink($this->_parent->getLanguageConstant('change'), window_Open('shop_manufacturer_change', 360, $this->_parent->getLanguageConstant('title_manufacturer_change'), true, true, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'manufacturers'), array('sub_action', 'change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->_parent->getLanguageConstant('delete'), window_Open('shop_manufacturer_delete', 400, $this->_parent->getLanguageConstant('title_manufacturer_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'manufacturers'), array('sub_action', 'delete'), array('id', $item->id)))));
             // parse template
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }
コード例 #24
0
 /**
  * Handle drawing list of delivery method prices
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_DeliveryPricesList($tag_params, $children)
 {
     $manager = ShopDeliveryMethodPricesManager::getInstance();
     $conditions = array();
     $relations = array();
     // prepare filtering conditions
     if (isset($tag_params['method'])) {
         $conditions['method'] = fix_id($tag_params['method']);
     }
     if (isset($_REQUEST['method'])) {
         $conditions['method'] = fix_id($_REQUEST['method']);
     }
     // get relations with shop item
     if (isset($tag_params['item'])) {
         $relations_manager = ShopDeliveryItemRelationsManager::getInstance();
         $item_id = fix_id($tag_params['item']);
         $raw_relations = $relations_manager->getItems(array('price'), array('item' => $item_id));
         if (count($raw_relations) > 0) {
             foreach ($raw_relations as $relation) {
                 $relations[] = $relation->price;
             }
         }
     }
     // get template
     $template = $this->_parent->loadTemplate($tag_params, 'delivery_method_prices_list_item.xml');
     // get items from database
     $items = $manager->getItems($manager->getFieldNames(), $conditions);
     if (count($items) > 0) {
         foreach ($items as $item) {
             $params = array('id' => $item->id, 'value' => $item->value, 'method' => isset($conditions['method']) ? $conditions['method'] : 0, 'selected' => in_array($item->id, $relations) ? 1 : 0, 'item_change' => url_MakeHyperlink($this->_parent->getLanguageConstant('change'), window_Open('shop_delivery_price_change', 370, $this->_parent->getLanguageConstant('title_delivery_method_price_change'), true, true, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'delivery_methods'), array('sub_action', 'change_price'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->_parent->getLanguageConstant('delete'), window_Open('shop_delivery_price_delete', 400, $this->_parent->getLanguageConstant('title_delivery_method_price_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'delivery_methods'), array('sub_action', 'delete_price'), array('id', $item->id)))));
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }
コード例 #25
0
ファイル: user_page.php プロジェクト: tareqy/Caracal
 /**
  * Display list of items associated with page and of specified type
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_ItemList($tag_params, $children, $type)
 {
     $manager = UserPageItemsManager::getInstance();
     $page_id = isset($tag_params['page']) ? fix_id($tag_params['page']) : null;
     // create query conditions
     $conditions = array();
     if (!is_null($page_id)) {
         $conditions['page'] = $page_id;
     }
     $conditions['type'] = $type;
     // get items from database
     $items = $manager->getItems(array('id', 'item'), $conditions);
     if ($type == user_page::VIDEO) {
         // create template
         $template = $this->loadTemplate($tag_params, 'page_items_video.xml');
         // connect tag handlers
         if (class_exists('youtube')) {
             $module = youtube::getInstance();
             $template->registerTagHandler('_video', $module, 'tag_Video');
         }
     } else {
         // create template
         $template = $this->loadTemplate($tag_params, 'page_items_gallery.xml');
         // connect tag handlers
         if (class_exists('gallery')) {
             $module = gallery::getInstance();
             $template->registerTagHandler('_gallery', $module, 'tag_Group');
         }
     }
     // parse items
     if (count($items) > 0) {
         foreach ($items as $item) {
             $params = array('item' => $item->item, 'item_delete' => url_MakeHyperlink($this->getLanguageConstant('delete'), window_Open('user_pages_items_delete', 400, $this->getLanguageConstant('title_delete_page'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'page_items_delete'), array('id', $item->id)))));
             $template->restoreXML();
             $template->setLocalParams($params);
             $template->parse();
         }
     }
 }
コード例 #26
0
ファイル: affiliates.php プロジェクト: tareqy/Caracal
 /**
  * Perform affiliate removal.
  */
 private function deleteAffiliate_Commit()
 {
     if ($_SESSION['level'] < 10) {
         die('Access denied!');
     }
     $id = fix_id($_REQUEST['id']);
     $manager = AffiliatesManager::getInstance();
     $referrals_manager = AffiliateReferralsManager::getInstance();
     $manager->deleteData(array('id' => $id));
     $referrals_manager->deleteData(array('affiliate' => $id));
     // show message
     $template = new TemplateHandler('message.xml', $this->path . 'templates/');
     $template->setMappedModule($this->name);
     $params = array('message' => $this->getLanguageConstant("message_affiliate_deleted"), 'button' => $this->getLanguageConstant("close"), 'action' => window_Close('affiliates_delete') . ";" . window_ReloadContent('affiliates'));
     $template->restoreXML();
     $template->setLocalParams($params);
     $template->parse();
 }
コード例 #27
0
ファイル: template.php プロジェクト: tareqy/Caracal
 /**
  * Parse loaded template
  *
  * @param integer $level Current level of parsing
  * @param array $tags Leave blank, used for recursion
  * @param boolean $parent_block If parent tag is block element
  */
 public function parse($tags = array())
 {
     global $section, $action, $language, $template_path, $system_template_path;
     if (!$this->active && empty($tags)) {
         return;
     }
     // get language handler for later
     $language_handler = MainLanguageHandler::getInstance();
     // take the tag list for parsing
     $tag_array = empty($tags) ? $this->engine->document->tagChildren : $tags;
     // start parsing tags
     $count = count($tag_array);
     for ($i = 0; $i < $count; $i++) {
         $tag = $tag_array[$i];
         // if tag has eval set
         if (isset($tag->tagAttrs['cms:eval']) || isset($tag->tagAttrs['eval'])) {
             // get evaluation values
             if (isset($tag->tagAttrs['eval'])) {
                 $value = $tag->tagAttrs['eval'];
             } else {
                 $value = $tag->tagAttrs['cms:eval'];
             }
             $eval_params = explode(',', $value);
             foreach ($eval_params as $param) {
                 // prepare module includes for evaluation
                 $settings = array();
                 if (!is_null($this->module)) {
                     $settings = $this->module->settings;
                 }
                 $params = $this->params;
                 $to_eval = $tag->tagAttrs[$param];
                 $tag->tagAttrs[$param] = eval('global $section, $action, $language, $language_rtl, $language_handler; return ' . $to_eval . ';');
             }
             // unset param
             unset($tag->tagAttrs['cms:eval']);
         }
         if (isset($tag->tagAttrs['cms:optional'])) {
             // get evaluation values
             $optional_params = explode(',', $tag->tagAttrs['cms:optional']);
             foreach ($optional_params as $param) {
                 // prepare module includes for evaluation
                 $settings = array();
                 if (!is_null($this->module)) {
                     $settings = $this->module->settings;
                 }
                 $params = $this->params;
                 $to_eval = $tag->tagAttrs[$param];
                 $value = eval('global $section, $action, $language, $language_rtl, $language_handler; return ' . $to_eval . ';');
                 if ($value == false) {
                     unset($tag->tagAttrs[$param]);
                 } else {
                     $tag->tagAttrs[$param] = $value;
                 }
             }
             // unset param
             unset($tag->tagAttrs['cms:optional']);
         }
         // implement tooltip
         if (isset($tag->tagAttrs['cms:tooltip'])) {
             if (!is_null($this->module)) {
                 $value = $this->module->getLanguageConstant($tag->tagAttrs['cms:tooltip']);
             } else {
                 $value = $language_handler->getText($tag->tagAttrs['cms:tooltip']);
             }
             $tag->tagAttrs['data-tooltip'] = $value;
             unset($tag->tagAttrs['cms:tooltip']);
         }
         // implement constants
         if (isset($tag->tagAttrs['cms:constant'])) {
             $params = explode(',', $tag->tagAttrs['cms:constant']);
             if (count($params) > 0) {
                 foreach ($params as $param) {
                     if (!is_null($this->module)) {
                         $tag->tagAttrs[$param] = $this->module->getLanguageConstant($tag->tagAttrs[$param]);
                     } else {
                         $tag->tagAttrs[$param] = $language_handler->getText($tag->tagAttrs[$param]);
                     }
                 }
             }
             unset($tag->tagAttrs['cms:constant']);
         }
         // check if specified tag shouldn't be cached
         $skip_cache = false;
         if (isset($tag->tagAttrs['skip_cache'])) {
             // unset param
             unset($tag->tagAttrs['skip_cache']);
             // get cache handler
             $cache = CacheHandler::getInstance();
             // only if current URL is being cached, we start dirty area
             if ($cache->isCaching()) {
                 $cache->startDirtyArea();
                 $skip_cache = true;
                 // reconstruct template for cache,
                 // ugly but we are not doing it a lot
                 $data = $this->getDataForCache($tag);
                 $cache->setCacheForDirtyArea($data);
             }
         }
         // now parse the tag
         switch ($tag->tagName) {
             // handle tag used for setting session variable
             case '_session':
             case 'cms:session':
                 $name = $tag->tagAttrs['name'];
                 // allow setting referral only once per seesion
                 if (isset($tag->tagAttrs['once'])) {
                     $only_once = in_array($tag->tagAttrs['once'], array(1, 'yes'));
                 } else {
                     $only_once = false;
                 }
                 $should_set = $only_once && !isset($_SESSION[$name]) || !$only_once;
                 // store value
                 if (!in_array($name, $this->protected_variables) && $should_set) {
                     $_SESSION[$name] = $tag->tagAttrs['value'];
                 }
                 break;
                 // transfer control to module
             // transfer control to module
             case '_module':
             case 'cms:module':
                 if (class_exists($tag->tagAttrs['name'])) {
                     $module = call_user_func(array($tag->tagAttrs['name'], 'getInstance'));
                     $module->transferControl($tag->tagAttrs, $tag->tagChildren);
                 }
                 break;
                 // load other template
             // load other template
             case '_template':
             case 'cms:template':
                 $file = $tag->tagAttrs['file'];
                 $path = key_exists('path', $tag->tagAttrs) ? $tag->tagAttrs['path'] : '';
                 if (!is_null($this->module)) {
                     $path = preg_replace('/^%module%/i', $this->module->path, $path);
                     $path = preg_replace('/^%templates%/i', $template_path, $path);
                 }
                 $new = new TemplateHandler($file, $path);
                 $new->setLocalParams($this->params);
                 $new->parse();
                 break;
                 // raw text copy
             // raw text copy
             case '_raw':
             case 'cms:raw':
                 if (key_exists('file', $tag->tagAttrs)) {
                     // if file attribute is specified
                     $file = $tag->tagAttrs['file'];
                     $path = key_exists('path', $tag->tagAttrs) ? $tag->tagAttrs['path'] : $template_path;
                     $text = file_get_contents($path . $file);
                 } elseif (key_exists('text', $tag->tagAttrs)) {
                     // if text attribute is specified
                     $text = $tag->tagAttrs['text'];
                 } else {
                     // in any other case we display data inside tag
                     $text = $tag->tagData;
                 }
                 echo $text;
                 break;
                 // multi language constants
             // multi language constants
             case '_text':
             case 'cms:text':
                 $constant = $tag->tagAttrs['constant'];
                 $language = key_exists('language', $tag->tagAttrs) ? $tag->tagAttrs['language'] : $language;
                 $text = "";
                 // check if constant is module based
                 if (key_exists('module', $tag->tagAttrs)) {
                     if (class_exists($tag->tagAttrs['module'])) {
                         $module = call_user_func(array($tag->tagAttrs['module'], 'getInstance'));
                         $text = $module->getLanguageConstant($constant, $language);
                     }
                 } else {
                     // use default language handler
                     $text = MainLanguageHandler::getInstance()->getText($constant, $language);
                 }
                 echo $text;
                 break;
                 // support for markdown
             // support for markdown
             case 'cms:markdown':
                 $char_count = isset($tag->tagAttrs['chars']) ? fix_id($tag->tagAttrs['chars']) : null;
                 $end_with = isset($tag->tagAttrs['end_with']) ? fix_id($tag->tagAttrs['end_with']) : null;
                 $name = isset($tag->tagAttrs['param']) ? $tag->tagAttrs['param'] : null;
                 $multilanguage = isset($tag->tagAttrs['multilanguage']) ? $tag->tagAttrs['multilanguage'] == 'yes' : false;
                 // get content for parsing
                 if (is_null($name)) {
                     $content = $tag->tagData;
                 }
                 $content = $multilanguage ? $this->params[$name][$language] : $this->params[$name];
                 // convert to HTML
                 $content = Markdown($content);
                 // limit words if specified
                 if (!is_null($char_count)) {
                     if (is_null($end_with)) {
                         $content = limit_words($content, $char_count);
                     } else {
                         $content = limit_words($content, $char_count, $end_with);
                     }
                 }
                 echo $content;
                 break;
                 // call section specific data
             // call section specific data
             case '_section_data':
             case 'cms:section_data':
                 if (!is_null($this->module)) {
                     $file = $this->module->getSectionFile($section, $action, $language);
                     $new = new TemplateHandler(basename($file), dirname($file) . '/');
                     $new->setLocalParams($this->params);
                     $new->setMappedModule($this->module);
                     $new->parse();
                 } else {
                     // log error
                     trigger_error('Mapped module is not loaded! File: ' . $this->file, E_USER_WARNING);
                 }
                 break;
                 // print multilanguage data
             // print multilanguage data
             case '_language_data':
             case 'cms:language_data':
                 $name = isset($tag->tagAttrs['param']) ? $tag->tagAttrs['param'] : null;
                 if (!isset($this->params[$name]) || !is_array($this->params[$name]) || is_null($name)) {
                     break;
                 }
                 $template = new TemplateHandler('language_data.xml', $system_template_path);
                 $template->setMappedModule($this->module);
                 foreach ($this->params[$name] as $lang => $data) {
                     $params = array('param' => $name, 'language' => $lang, 'data' => $data);
                     $template->restoreXML();
                     $template->setLocalParams($params);
                     $template->parse();
                 }
                 break;
                 // replace tag data string with matching params
             // replace tag data string with matching params
             case '_replace':
             case 'cms:replace':
                 $pool = isset($tag->tagAttrs['param']) ? $this->params[$tag->tagAttrs['param']] : $this->params;
                 $keys = array_keys($pool);
                 $values = array_values($pool);
                 foreach ($keys as $i => $key) {
                     $keys[$i] = "%{$key}%";
                 }
                 // we can't replact string with array, only matching data types
                 foreach ($values as $i => $value) {
                     if (is_array($value)) {
                         unset($keys[$i]);
                         unset($values[$i]);
                     }
                 }
                 echo str_replace($keys, $values, $tag->tagData);
                 break;
                 // conditional tag
             // conditional tag
             case '_if':
             case 'cms:if':
                 $settings = !is_null($this->module) ? $this->module->settings : array();
                 $params = $this->params;
                 $condition = true;
                 // check if section is specified and matches
                 if (isset($tag->tagAttrs['section'])) {
                     $condition &= $tag->tagAttrs['section'] == $section;
                 }
                 // check if action is specified and matches
                 if (isset($tag->tagAttrs['action'])) {
                     $condition &= $tag->tagAttrs['action'] == $action;
                 }
                 // check custom condition
                 if (isset($tag->tagAttrs['condition'])) {
                     $to_eval = $tag->tagAttrs['condition'];
                     $eval_result = eval('global $section, $action, $language, $language_rtl, $language_handler; return ' . $to_eval . ';') == true;
                     $condition &= $eval_result;
                 }
                 // parse children
                 if ($condition) {
                     $this->parse($tag->tagChildren);
                 }
                 break;
                 // conditional tag parsed for desktop version
             // conditional tag parsed for desktop version
             case 'cms:desktop':
                 if (_DESKTOP_VERSION) {
                     $this->parse($tag->tagChildren);
                 }
                 break;
                 // conditional tag parsed for mobile version
             // conditional tag parsed for mobile version
             case 'cms:mobile':
                 if (_MOBILE_VERSION) {
                     $this->parse($tag->tagChildren);
                 }
                 break;
                 // conditional tag parsed for users that are logged in
             // conditional tag parsed for users that are logged in
             case 'cms:user':
                 if ($_SESSION['logged']) {
                     $this->parse($tag->tagChildren);
                 }
                 break;
                 // conditional tag parsed for guests
             // conditional tag parsed for guests
             case 'cms:guest':
                 if (!$_SESSION['logged']) {
                     $this->parse($tag->tagChildren);
                 }
                 break;
                 // variable
             // variable
             case '_var':
             case 'cms:var':
                 $settings = array();
                 if (!is_null($this->module)) {
                     $settings = $this->module->settings;
                 }
                 $params = $this->params;
                 $to_eval = $tag->tagAttrs['name'];
                 echo eval('global $section, $action, $language, $language_rtl, $language_handler; return ' . $to_eval . ';');
                 break;
                 // support for script tag
             // support for script tag
             case 'cms:script':
                 if (class_exists('head_tag')) {
                     $head_tag = head_tag::getInstance();
                     $head_tag->addTag('script', $tag->tagAttrs);
                 }
                 break;
                 // support for collection module
             // support for collection module
             case 'cms:collection':
                 if (array_key_exists('include', $tag->tagAttrs) && class_exists('collection')) {
                     $scripts = fix_chars(explode(',', $tag->tagAttrs['include']));
                     $collection = collection::getInstance();
                     $collection->includeScript($scripts);
                 }
                 break;
                 // support for link tag
             // support for link tag
             case 'cms:link':
                 if (class_exists('head_tag')) {
                     $head_tag = head_tag::getInstance();
                     $head_tag->addTag('link', $tag->tagAttrs);
                 }
                 break;
                 // support for parameter based choice
             // support for parameter based choice
             case 'cms:choice':
                 $param_value = null;
                 if (array_key_exists('param', $tag->tagAttrs)) {
                     // grap param value from GET or POST parameters
                     $param_name = fix_chars($tag->tagAttrs['param']);
                     $param_value = isset($_REQUEST[$param_name]) ? fix_chars($_REQUEST[$param_name]) : null;
                 } else {
                     if (array_key_exists('value', $tag->tagAttrs)) {
                         // use param value specified
                         $param_value = fix_chars($tag->tagAttrs['value']);
                     }
                 }
                 // parse only option
                 foreach ($tag->tagChildren as $option) {
                     if (!$option->tagName == 'option') {
                         continue;
                     }
                     $option_value = isset($option->tagAttrs['value']) ? $option->tagAttrs['value'] : null;
                     $option_default = isset($option->tagAttrs['default']) ? $option->tagAttrs['default'] == 1 : false;
                     // values match or option is default, parse its content
                     if ($option_value == $param_value || $option_default) {
                         $this->parse($option->tagChildren);
                         break;
                     }
                 }
                 break;
                 // default action for parser, draw tag
             // default action for parser, draw tag
             default:
                 if (in_array($tag->tagName, array_keys($this->handlers))) {
                     // custom tag handler is set...
                     $handle = $this->handlers[$tag->tagName];
                     $obj = $handle['object'];
                     $function = $handle['function'];
                     $obj->{$function}($tag->tagAttrs, $tag->tagChildren);
                 } else {
                     // default tag handler
                     echo '<' . $tag->tagName . $this->getTagParams($tag->tagAttrs) . '>';
                     if (count($tag->tagChildren) > 0) {
                         $this->parse($tag->tagChildren);
                     }
                     if (count($tag->tagData) > 0) {
                         echo $tag->tagData;
                     }
                     $close_tag = $this->close_all_tags ? true : !in_array($tag->tagName, $this->tags_without_end);
                     if ($close_tag) {
                         echo '</' . $tag->tagName . '>';
                     }
                 }
                 break;
         }
         // end cache dirty area if initialized
         if ($skip_cache) {
             $cache->endDirtyArea();
         }
     }
 }
コード例 #28
0
ファイル: faq.php プロジェクト: tareqy/Caracal
 /**
  * Tag handler for single question.
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_Question($tag_params, $children)
 {
     $id = isset($_REQUEST['id']) ? fix_id($_REQUEST['id']) : null;
     $manager = QuestionManager::getInstance();
     if (is_null($id)) {
         return;
     }
     // get item from database
     $item = $manager->getSingleItem($manager->getFieldNames(), array('id' => $id));
     if (is_object($id)) {
         $template = $this->loadTemplate($tag_params, 'list_item.xml');
         $params = array('id' => $item->id, 'question' => $item->question, 'answer' => $item->answer);
         $template->restoreXML();
         $template->setLocalParams($params);
         $template->parse();
     }
 }
コード例 #29
0
ファイル: aley_dafna.php プロジェクト: Way2CU/AleyDafna-Shop
 /**
  * Show page for printing all attached cards with selected text.
  */
 private function print_card()
 {
     $id = fix_id($_REQUEST['transaction']);
     $manager = ShopTransactionsManager::getInstance();
     $item_manager = ShopItemManager::getInstance();
     $transaction_item_manager = ShopTransactionItemsManager::getInstance();
     // get transaction with specified id
     $transaction = $manager->getSingleItem(array('id'), array('id' => $id));
     // ensure transaction is a valid one
     if (!is_object($transaction)) {
         return;
     }
     // get items associated with transaction
     $transaction_items = $transaction_item_manager->getItems(array('item', 'description'), array('transaction' => $transaction->id));
     if (count($transaction_items) == 0) {
         return;
     }
     $id_list = array();
     $description_list = array();
     foreach ($transaction_items as $item) {
         $id_list[] = $item->item;
         $description_list[$item->item] = $item->description;
     }
     // get unique id and gallery
     $shop_items = $item_manager->getItems(array('id', 'uid', 'gallery'), array('id' => $id_list));
     if (count($shop_items) == 0) {
         return;
     }
     // prepare final list and only include items that are actually known cards
     $items = array();
     foreach ($shop_items as $item) {
         if (!array_key_exists($item->uid, $this->text_position)) {
             continue;
         }
         $position = $this->text_position[$item->uid];
         $description = unserialize($description_list[$item->id]);
         $data = array('text' => $description['text'], 'top' => $position[0] . '%', 'left' => $position[1] . '%', 'bottom' => $position[2] . '%', 'right' => $position[3] . '%', 'image' => gallery::getGroupImageById($item->gallery));
         $items[] = $data;
     }
     // prepare template
     $template = new TemplateHandler('print_card.xml', $this->path . 'templates/');
     if (count($items) > 0) {
         foreach ($items as $item) {
             $template->setLocalParams($item);
             $template->restoreXML();
             $template->parse();
         }
     }
 }
コード例 #30
0
ファイル: news.php プロジェクト: tareqy/Caracal
 /**
  * Print json object for specified news
  */
 private function json_News()
 {
     define('_OMIT_STATS', 1);
     $manager = NewsManager::getInstance();
     $admin_manager = UserManager::getInstance();
     if (isset($_REQUEST['id'])) {
         // id was specified, fetch the news
         $item = $manager->getSingleItem($manager->getFieldNames(), array('id' => fix_id($_REQUEST['id'])));
     } else {
         // no news id has been specified, grab the latest
         $item = $manager->getSingleItem($manager->getFieldNames(), array(), array('id'), False);
     }
     if (is_object($item)) {
         $timestamp = strtotime($item->timestamp);
         $date = date($this->getLanguageConstant('format_date_short'), $timestamp);
         $time = date($this->getLanguageConstant('format_time_short'), $timestamp);
         $result = array('id' => $item->id, 'time' => $time, 'date' => $date, 'author' => $admin_manager->getItemValue('fullname', array('id' => $item->author)), 'title' => $item->title, 'content' => $item->content, 'visible' => $item->visible, 'error' => false, 'error_message' => '');
     } else {
         $result = array('error' => true, 'error_message' => $this->getLanguageConstant('message_json_error_object'));
     }
     print json_encode($result);
 }